Rationale
Frontends talking to an actor backend today hand-roll WebSocket protocols (see the chat example's six frontends). A typed client — define the protocol once as kind-discriminated unions, get typed tell/ask/subscribe in the browser — brings tRPC-grade DX to actor systems and is the on-ramp to the isomorphic-actors program (#215).
Scope
DefineProtocol<{ asks, tells, topics }> type helper — shared between server and browser; end-to-end type inference.
- Browser client: typed
tell/ask (correlation ids, timeouts) and subscribe (topics) over Websocket (server side: WebsocketServerActor / the websocket() directive), HTTP fallback for ask; reconnect with backoff; auth hooks (token provider).
- Zero dependencies in the client core (native WebSocket/fetch only — dependency policy); shipped as subpath export
"./client".
- Server-side glue: route a protocol onto an ActorRef/ShardRegion with schema validation at the boundary.
// shared/protocol.ts — imported by server AND browser
export type CounterProtocol = DefineProtocol<{
asks: { get: { request: { kind: 'get' }; response: number } };
tells: { increment: { kind: 'increment' } };
topics: { changed: number };
}>;
// browser:
const client = actorClient<CounterProtocol>({ url: 'wss://api.example.com/actors' });
client.tell('counter-1', { kind: 'increment' });
const n = await client.ask('counter-1', { kind: 'get' }); // n: number — end-to-end typed
Documentation
Own docs chapter (quickstart, protocol design, auth, reconnect semantics — EN + DE); JSDoc; CHANGELOG.
Acceptance
- End-to-end test browser-fixture ↔ WebsocketServerActor: typed ask round-trip, topic subscription, reconnect resumes subscriptions; type-level tests (expect-type) for protocol inference.
Non-goals
Framework bindings (React/Vue/Svelte — follow-up issue); browser-side ActorSystem (#210); optimistic updates/caching.
Relates
#187 (typed WS server wrapper — server half), #166 (cross-node RPC), #215 (browser in cluster). Improvement program M7. Dependency policy #419.
Rationale
Frontends talking to an actor backend today hand-roll WebSocket protocols (see the chat example's six frontends). A typed client — define the protocol once as
kind-discriminated unions, get typedtell/ask/subscribein the browser — brings tRPC-grade DX to actor systems and is the on-ramp to the isomorphic-actors program (#215).Scope
DefineProtocol<{ asks, tells, topics }>type helper — shared between server and browser; end-to-end type inference.tell/ask(correlation ids, timeouts) andsubscribe(topics) over Websocket (server side:WebsocketServerActor/ thewebsocket()directive), HTTP fallback for ask; reconnect with backoff; auth hooks (token provider)."./client".Documentation
Own docs chapter (quickstart, protocol design, auth, reconnect semantics — EN + DE); JSDoc; CHANGELOG.
Acceptance
Non-goals
Framework bindings (React/Vue/Svelte — follow-up issue); browser-side ActorSystem (#210); optimistic updates/caching.
Relates
#187 (typed WS server wrapper — server half), #166 (cross-node RPC), #215 (browser in cluster). Improvement program M7. Dependency policy #419.