Relay request path
This page walks through a single chat message from the browser to the ArcFlow engine and back. Sequence assumes mode: "relay" in @arcflow/static and a site provisioned via admin API.
Sequence
Step 1: Browser create run
The static SDK posts to Relay with the site token (not the server master key):
HTTP equivalent:
Payload uses workflow_ref so agent definitions stay on the server registry, not in the JS bundle.
Step 2: Relay middleware
- Site lookup from in-memory store (loaded from Postgres-backed admin or
ARCFLOW_RELAY_SITES_JSON). - Token verify against configured site token hash.
- Origin check against
allowed_origins(see origin-and-rate-limiting.md). - Rate limit token bucket per site (
429when exceeded).
Step 3: Upstream proxy
Relay forwards to ARCFLOW_UPSTREAM_URL (default http://arcflow-server:8080):
- Path rewritten from
/v1/sites/{id}/runsto/v1/runs - Auth header replaced with site's
upstream_runtime_key(must exist inARCFLOW_STATIC_RUNTIME_KEYSor match master key policy) Idempotency-Keyforwarded if present
Step 4: Poll status
The static SDK polls until terminal status. Each poll hits Relay, which proxies GET /v1/runs/{run_id}.
Step 5: Trace for streaming UX
For progressive UI, poll trace and read TokenEmitted events (byte/token counts only, trace data policy). No server SSE until streaming ships.
See guides/streaming/streaming-in-the-browser.md.
HITL through Relay
When a run returns Interrupted, the static SDK throws WorkflowInterruptedError with approvalKey. Approval may go through server API from a trusted backend; Relay approve proxy depends on scoped key configuration.