new AgentClient<Create a client and start connecting immediately. ParametersTStub,TState>(url,opts?):AgentClient<TStub,TState>
Returns
AgentClient<TStub, TState>
Throws
If no global WebSocket exists and none was injected via
opts.WebSocketCtor.
Type Parameters
The Address
Theurl is the address of one instance. mountAgents serves every instance it mounts at an address of this shape.
/agentsis the mount’s default base path.<mount>is a key of the mount map.<name>is the instance’s routing name.
Attach Mode
Attach mode opens every connection, reconnects included, with anattach frame. The frame carries the token, the requested streams and, with resume, the cursors. The server answers with the granted claims and the accepted streams. claims holds the claims.
Without token, subscribe or resume, the client speaks the plain protocol. Each connection opens with snapshots of the state and the messages, followed by hello. The plain protocol works with servers that speak nothing else.
Reconnects
The client reconnects on its own whenever the link drops. Onlyclose stops it. A heartbeat detects a link that died without closing. The client replaces such a link as it does a dropped one. The backoff and heartbeat options in AgentClientOptions set the timing.
AgentClientOptions
Options for AgentClient. Setting any oftoken / subscribe / resume switches the client into
attach mode (see the AgentClient class docs); the connection and
heartbeat options apply in both modes.
Properties
pingIntervalMs?
Heartbeat: send aoptionalpingIntervalMs?:number
ping every pingIntervalMs (default 30_000).
pingTimeoutMs?
Reconnect if aoptionalpingTimeoutMs?:number
ping goes unanswered for pingTimeoutMs (default 10_000).
reconnectBackoffMs?
Base reconnect backoff in ms. Delays grow exponentially (factor 2, ±20% jitter) from this base up tooptionalreconnectBackoffMs?:number
reconnectMaxBackoffMs.
Default Value
reconnectMaxBackoffMs?
Upper bound on the reconnect backoff delay, in ms. Default ValueoptionalreconnectMaxBackoffMs?:number
resume?
Resume across reconnects: re-attach with the last-seenoptionalresume?:boolean
messages/events
cursors so the server replays exactly what was missed — no full
re-snapshot, no duplicates. The first connection carries no cursors (a
normal snapshot bootstrap is expected).
subscribe?
Streams to subscribe to. Omitted = the server’s default set.optionalsubscribe?: readonlyStream[]
token?
Opaque credential presented in theoptionaltoken?:string
attach frame; the server derives this connection’s grants from it.
WebSocketCtor?
WebSocket constructor (defaults to the platformoptionalWebSocketCtor?:AgentWebSocketCtor
globalThis.WebSocket).
Inject one for environments without a global, or for tests.
Stream
Stream =The pushable streams a v2 client can subscribe to."state"|"messages"|"events"