Abstract seeds into modular skill packs + split config
Group committed starter skills into packs (semif_agent/packs.py) that bind a
concern to its categories, bridge(s), requirements, and config schema:
- seeds/ -> packs/<name>/ with a pack.json manifest + skills/<category>/<leaf>/.
Shipped: nextcloud, simplex, outlook, browser (each owning its bridge) and
essentials (time + calculator, no bridge).
- PackRegistry discovers packs (a root with no manifest is one implicit pack);
merge_packs loads every enabled pack. Pack enable is one switch
(packs.<name>.enabled -> bridges.<bridge>.enabled -> enabled_by_default);
disabling a pack drops its categories (incl. generated bodies) and its bridge.
- CATEGORY_DESCRIPTIONS now comes from the pack manifests (built-ins stay).
Adopt a Home-Assistant-style layered config (semif_agent/config.py):
- config.json is a thin index ({"include": [...]}) over config/core.json,
config/gateway.json, config/bridges.json, config/packs/*.json, deep-merged.
- Secrets live in the gitignored secrets.json, referenced as "!secret <key>";
api_key_env is removed.
- CORE_SCHEMA + each pack's config schema own defaults and GENERATE the
committed config.example.json; new `check-config` (validate + --write-example)
and `config-init` (seed the split layout) commands.
- scripts/config_merge.py (stdlib) lets bootstrap read the merged config.
Tests: tests/test_packs.py (renamed from test_seed_skills, +enable/merge),
new tests/test_config.py. All unit tests pass (772).
This commit is contained in:
commit
6b5f79eca9
13 files changed
+1958
No files matched your search
@@ -0,0 +1,107 @@
|
||||
"""Show the SimpleX contact link others use to connect to this agent.
|
||||
|
||||
Real integration: the standalone SimpleX forwarding bridge
|
||||
(`simplex_bridge_url`, `simplex_bridge_token`). The bridge's own connection to
|
||||
the `simplex-chat` daemon is the only thing that can read (or create) the
|
||||
forwarding bot's *user contact address*; this body asks the bridge for it and
|
||||
reports the link honestly. It never opens a WebSocket to the daemon and never
|
||||
invents a link: if the bridge is not running or has no address, it says so.
|
||||
|
||||
`act` health-checks the bridge, then `GET /address` shows the existing link and
|
||||
creates one on first call, returning `{short_link, full_link, created}`.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import urllib.error
|
||||
import urllib.request
|
||||
|
||||
from semif_agent.skills import ActionResult
|
||||
|
||||
INTEGRATION = {
|
||||
"service": "simplex",
|
||||
"transport": "http",
|
||||
"config_vars": ["simplex_bridge_url", "simplex_bridge_token"],
|
||||
}
|
||||
|
||||
CONTRACT = {
|
||||
"simplex_bridge_url": "Base URL of the standalone SimpleX forwarding bridge, e.g. http://127.0.0.1:5227 (no trailing slash needed).",
|
||||
"simplex_bridge_token": "Shared secret for the bridge, if one is configured; sent as the X-Semif-Token header. Leave blank when the bridge requires no auth.",
|
||||
}
|
||||
|
||||
TIMEOUT_SECONDS = 30
|
||||
|
||||
|
||||
class BridgeError(Exception):
|
||||
"""The SimpleX forwarding bridge is unreachable or returned an error."""
|
||||
|
||||
|
||||
# ---- transport ----
|
||||
|
||||
|
||||
def _base(ctx):
|
||||
url = str(ctx.config.get("simplex_bridge_url", "") or "").strip().rstrip("/")
|
||||
if not url:
|
||||
raise BridgeError("simplex_bridge_url is not configured")
|
||||
return url
|
||||
|
||||
|
||||
def _headers(ctx):
|
||||
token = str(ctx.config.get("simplex_bridge_token", "") or "").strip()
|
||||
return {"X-Semif-Token": token} if token else {}
|
||||
|
||||
|
||||
def _get(ctx, path):
|
||||
request = urllib.request.Request(
|
||||
_base(ctx) + path, headers=_headers(ctx)
|
||||
)
|
||||
try:
|
||||
with urllib.request.urlopen(request, timeout=TIMEOUT_SECONDS) as response:
|
||||
return json.loads(response.read().decode("utf-8"))
|
||||
except urllib.error.HTTPError as exc:
|
||||
detail = exc.read().decode("utf-8", "replace").strip()[:200]
|
||||
raise BridgeError(f"GET {path}: HTTP {exc.code} {detail}") from exc
|
||||
except (urllib.error.URLError, TimeoutError, ValueError) as exc:
|
||||
raise BridgeError(f"GET {path}: {exc}") from exc
|
||||
|
||||
|
||||
# ---- skill phases ----
|
||||
|
||||
|
||||
def act(ctx, request):
|
||||
try:
|
||||
payload = _get(ctx, "/health")
|
||||
except BridgeError as exc:
|
||||
return ActionResult(action_log=str(exc), new_state=request.text)
|
||||
if not payload.get("ok"):
|
||||
return ActionResult(
|
||||
action_log="simplex forwarding bridge is not healthy",
|
||||
new_state=request.text,
|
||||
)
|
||||
try:
|
||||
payload = _get(ctx, "/address")
|
||||
except BridgeError as exc:
|
||||
return ActionResult(
|
||||
action_log=f"reading the contact link failed: {exc}",
|
||||
new_state=request.text,
|
||||
)
|
||||
short = str(payload.get("short_link") or "").strip()
|
||||
full = str(payload.get("full_link") or "").strip()
|
||||
if not (short or full):
|
||||
return ActionResult(
|
||||
action_log=(
|
||||
"the bridge returned no SimpleX "
|
||||
"contact link; the bot has no address yet."
|
||||
),
|
||||
new_state=request.text,
|
||||
)
|
||||
verb = "created" if payload.get("created") else "current"
|
||||
lines = [f"SimpleX contact link ({verb}): {short or full}"]
|
||||
if short and full:
|
||||
lines.append(f"Full link: {full}")
|
||||
lines.append(
|
||||
"Share this link with someone so they can add the agent and message it."
|
||||
)
|
||||
report = "\n".join(lines)
|
||||
return ActionResult(action_log=report, new_state=report)
|
||||
Reference in new issue
Block a user