Skip to main content
A WebSocket upgrade, or GET …?subscribe=state, on a conversation’s address opens the stream of its state and messages. No turn runs. mountAgents hands the upgrade to the runtime’s default webSocket(), and the GET, like an RPC’s POST, to the class’s fetch:
fetch(req) overrides the runtime SDK’s fetch() with an AgentHttpServer over connectionEngine.
  • The server answers a GET with Server-Sent Events, and a POST to …/rpc/<method> with one RPC call.
  • connectionEngine is the engine the default webSocket() runs every socket through, so both transports serve the same streams under the same authorize.
  • The server is built on the first request and kept for the activation.
authorize decides who may read the streams and who may call the @rpc methods:
authorize(token, req) overrides the runtime SDK’s authorize().
  • token is the credential the caller presented, or undefined without one.
  • req is the request, with any identity headers a front door stamped on it.
  • The returned claims are the caller’s grants, and a throw rejects the caller. The runtime acts on "rpc" alone, which admits the @rpc methods.
  • The runtime’s own default returns ["read"], which admits the streams and no RPC.
The voice class overrides webSocket() to answer calls, so on a voice agent an upgrade is a call, as The Call Webhook shows.
Beta. Without a host authorize, every caller is granted read and RPC.