Add a `browser` bridge: real browser automation behind the standard
token-guarded localhost JSON surface, so a codegen-authored skill body never
bundles a browser stack. It opens a URL, reads a page's text or links, takes a
screenshot, and clicks/fills/presses/selects to complete a flow.
Unlike the stdlib-only Nextcloud/Outlook bridges this one owns a browser and
needs a heavy optional dependency, so it is disabled by default and installed
with `scripts/bootstrap.sh --browser` (Playwright pinned in
requirements/browser.txt; the browser binary lands under the checkout's
.runtime/browser, which the driver points PLAYWRIGHT_BROWSERS_PATH at).
- `BrowserBridge` (`bridges/browser.py`) + `BrowserDriver`
(`bridges/browser_client.py`). A real navigation/timeout/selector failure is a
502, a missing package/browser a 503 install hint, bad input a 400 -- never a
fabricated success.
- `check_requirements()` deliberately never blocks: `run_bridges()` aborts all
bridges when one fails, and this dependency is optional, so a missing
Playwright must degrade to a per-call 503, not take down the others.
- Playwright's sync API is bound to its creating thread while the bridge serves
each request on a new one, so the driver runs the async API on one dedicated
event-loop thread and serializes whole operations behind an asyncio.Lock
(submitted with run_coroutine_threadsafe).
- Persistent profile under .runtime/browser/profile so logins/cookies survive
across calls and restarts; POST /reset with purge=true wipes it, and
headless=false shows the window for a first sign-in. Route set: /health,
/state, /content, /text, /links, /screenshot, /goto, /click, /fill, /press,
/select, /wait, /back, /forward, /reset. No arbitrary JS evaluate (out of
scope for this cut).
- Seeds: `seeds/browser/{open_page,read_page,screenshot}`, each hermetically
tested against a loopback bridge. A `browser` category description is seeded
so the leaf softmax has signal.
- `tests/test_browser_bridge.py` exercises the routes over a loopback HTTP
server with an injected fake driver (no browser or Playwright needed). The
live browser is a provisioned-host concern: this box could not reach the
Playwright CDN, so no real-browser run backs it yet.
47 lines
1.7 KiB
Python
47 lines
1.7 KiB
Python
"""Third-party API bridges: a secure local layer between skills and services.
|
|
|
|
A **bridge service** is a standalone process that exposes one third-party system
|
|
(SimpleX, the local language model, Nextcloud, Microsoft Graph / Outlook, a real
|
|
web browser via Playwright) to
|
|
codegen-authored skill bodies
|
|
over a local, token-guarded HTTP API. It exists so a generated body never speaks
|
|
a system's native protocol (WebSocket, SMTP, CalDAV, an OpenAI-compatible chat
|
|
API, a CLI's private flags) directly: it calls a small, documented, uniform HTTP
|
|
surface instead, and the bridge owns the messy integration details and
|
|
credentials.
|
|
|
|
Two boundaries matter:
|
|
|
|
- **Bridges are not the gateway.** The command gateway only takes commands and
|
|
replies; it must never grow read/send/invite endpoints. Bridges run as their
|
|
own processes (`python -m semif_agent.cli bridge`) against their own service
|
|
daemons/profiles. This isolation is non-negotiable (see AGENTS.md).
|
|
- **The catalog is visible to codegen.** `describe_bridges()` is injected into
|
|
every code-generation prompt (body, retry, regen, testgen) and is
|
|
the single source of bridge specifics: the model learns which real services it
|
|
may build against, each one's base-URL config var, auth header/token var,
|
|
config-var docs, and its endpoints with request/response/error shapes. CODEGEN.md
|
|
and TESTGEN.md carry only the generic pattern.
|
|
"""
|
|
|
|
from .base import BridgeInfo, BridgeService
|
|
from .inbox import MessagingInbox
|
|
from .registry import (
|
|
build_bridge,
|
|
derived_config_vars,
|
|
describe_bridges,
|
|
known_infos,
|
|
run_bridges,
|
|
)
|
|
|
|
__all__ = [
|
|
"BridgeInfo",
|
|
"BridgeService",
|
|
"MessagingInbox",
|
|
"build_bridge",
|
|
"derived_config_vars",
|
|
"describe_bridges",
|
|
"known_infos",
|
|
"run_bridges",
|
|
]
|