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. connectionEngineis the engine the defaultwebSocket()runs every socket through, so both transports serve the same streams under the sameauthorize.- 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().
tokenis the credential the caller presented, orundefinedwithout one.reqis 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@rpcmethods. - The runtime’s own default returns
["read"], which admits the streams and no RPC.
webSocket() to answer calls: an upgrade whose address carries ?media=call is a call’s media, as The Call Webhook shows, and any other upgrade is the agent socket protocol, as here.