Most UIs should not touch this. Reach for the React bindings in
/reference/gateway-react, which hold one client
for you and expose live hooks. Drop down to the client only for non-React hosts,
custom transports, or scripts.smithers-orchestrator/gateway-client, not on the bare
smithers-orchestrator facade. Import from the subpath or the build fails.
SmithersGatewayClient
The typed client. Construct it with a base URL (and optional auth token); call a named RPC method, or open a WebSocket and subscribe to a run’s event stream.RPC methods
Each method is a thin typed wrapper overrpc(method, params), which POSTs to
/v1/rpc/<method> and unwraps the response frame. Params and return shapes come
from the method catalog; see /rpc/launch-run for one method
in full.
launchRun, resumeRun, cancelRun, hijackRun, rewindRun.submitApproval, submitSignal, listApprovals.getRun, listRuns, listWorkflows, getNodeOutput, getNodeDiff.cronList, cronCreate, cronDelete, cronRun.rpc(method, params, { signal? }) for any typed method, rpcRaw(method, params?, { signal? }) for an untyped one, and extensionRpc(namespace, key, params?) / streamExtension(namespace, key, params?) for gateway extensions.Subscribing to events
connect() opens a SmithersGatewayConnection. The higher-level generators
filter and yield frames for you, so most callers iterate one of those instead of
driving the connection directly.
Subscribes to one run and yields its
run.* frames (run.event,
run.gap_resync, run.heartbeat, run.error). Pass afterSeq to resume.
Closes the socket when iteration ends.Same frames, but reconnects with backoff + jitter on a silent drop and resumes
from the last observed
seq. Stops on terminal completion or abort. Options:
signal, backoff (GatewayBackoffOptions),
healthyAfterMs, and onReconnect(event).Subscribes to a run’s DevTools snapshot stream.
Opens the WebSocket, performs the
connect handshake (protocol + auth), and
returns the live connection. Use this only when you need request/response over
the socket or raw event frames.SmithersGatewayConnection
A single open WebSocket. RPC over the socket viarequest / requestRaw, and a
single in-order async stream of server event frames via events(signal?). One
consumer per connection; the generators above own a connection each.
Typed request/response over the socket.
Untyped request/response over the socket.
In-order server event frames. Ends on close; throws on an error or invalid
frame.
Closes the socket, rejects pending requests, and ends
events().SmithersGatewayClient.ts · SmithersGatewayConnection.ts · Tests SmithersGatewayClient.test.ts · See also /rpc/launch-run, Gateway integration
GatewayRpcError
The error every RPC rejects with on a failed frame or HTTP error. Inspectcode
to branch (for example, requiredScope is set on an authorization failure).
The RPC method that failed (or
"websocket" for a malformed socket frame).Machine-readable error code, e.g.
HTTP_ERROR, INVALID_GATEWAY_RESPONSE, or
the gateway’s own code from the response frame.HTTP status when the failure came over HTTP RPC.
The scope the call needed, on an authorization failure.
Set when the gateway asks the client to refresh credentials.
Extra context attached by the gateway.
GatewayRpcError.ts · Tests gateway-client.test.ts
createSmithersGatewayTransport
Adapts aSmithersGatewayClient into the narrow SyncTransport that
createGatewayCollection and the React provider consume. RPC is
wired straight through; streamRunEvents uses the resilient generator,
streamDevTools the plain one. Unknown stream scopes throw, so a typo surfaces
loudly instead of stalling.
The client whose RPC and streams the transport forwards.
{ rpc(method, params, options?), stream(scope, params, options) }. scope is
"streamRunEvents" or "streamDevTools"; both require params.runId.createSmithersGatewayTransport.ts · Tests sync
gatewayBackoffDelay
Exponential backoff with full jitter for one 0-based attempt. The resilient stream uses it internally; call it directly when you write your own reconnect loop.0-based attempt index. The base delay grows by
factor ** attempt, capped at
maxMs.Milliseconds to wait, never negative.
gatewayBackoffDelay.ts · Tests gatewayBackoffDelay.test.ts
Collections
createGatewayCollection builds a TanStack DB CollectionConfig backed by a
SyncTransport: it loads an initial RPC payload, then keeps the collection live
off a stream (or by refetching on each frame). gatewayKeys produces the stable
cache keys so two consumers of the same data never disagree on the key.
A config to hand to TanStack DB’s
createCollection. Its id is the
fingerprint of key.gatewayKeys
Typed cache-key factories for the known gateway reads and streams. Each returns areadonly SyncKey tuple.
Factories include
workflows, runs, run, approvals, nodeOutput,
nodeDiff, cronList, memoryFacts, prompts, scores, tickets,
devtoolsSnapshot, runEvents, and devtools.createGatewayCollection.ts · gatewayKeys.ts · Tests sync
Sync internals
The subpath also exports lower-level building blocks used to assemble the
collections above:
electricCollectionDefs / gatewayCollectionDefs (the
registry of known collections), flattenGatewayRunNode /
snapshotToGatewayRunNode / reconcileSnapshotNodes (run-tree shaping),
syncKeyFingerprint / syncKeyMatches (key hashing + prefix match),
syncBackoffDelay, the Electric source (createElectricCollection), and the row
types (GatewayRunRow, GatewayRunNode, GatewayApprovalRow, …). They are
implementation surface for custom transports and rarely needed directly. See the
package source.Source
index.ts · Tests packages/gateway-client/tests · See also Gateway React API, Gateway integration, /rpc/launch-run