UNPKG

agents

Version:

A home for your AI agents

25 lines (24 loc) 1.29 kB
//#region src/websockets/transport-protocol.ts /** Query parameter selecting the Cap'n Web connection transport. */ const CAPNWEB_TRANSPORT_QUERY = "__agents_transport"; const CAPNWEB_TRANSPORT_VALUE = "capnweb"; /** * The single method on the host's session root: the frame pipe from the * client to the host. Every Agent protocol frame travels through it. */ const CAPNWEB_TRANSPORT_SEND = "__cf_agent_send"; /** Rewrite a host URL to select the Cap'n Web transport over `ws(s)`. */ function capnWebTransportUrl(url) { const resolved = new URL(url); if (resolved.protocol === "http:") resolved.protocol = "ws:"; if (resolved.protocol === "https:") resolved.protocol = "wss:"; resolved.searchParams.set(CAPNWEB_TRANSPORT_QUERY, CAPNWEB_TRANSPORT_VALUE); return resolved.toString(); } /** Whether a request is a WebSocket upgrade selecting the transport. */ function isCapnWebTransportUpgrade(request) { return request.headers.get("Upgrade")?.toLowerCase() === "websocket" && new URL(request.url).searchParams.get("__agents_transport") === "capnweb"; } //#endregion export { isCapnWebTransportUpgrade as a, capnWebTransportUrl as i, CAPNWEB_TRANSPORT_SEND as n, CAPNWEB_TRANSPORT_VALUE as r, CAPNWEB_TRANSPORT_QUERY as t }; //# sourceMappingURL=transport-protocol-BxyngQ_R.js.map