Expand description
Connection-level Copilot request handler — intercept and replace the model-layer HTTP and WebSocket traffic the runtime issues for both CAPI and BYOK sessions. Connection-level interception of the model-layer HTTP and WebSocket traffic the runtime issues — for both CAPI and BYOK sessions.
When ClientOptions::request_handler
is set, the SDK registers itself as the runtime’s request handler on
Client::start. From then on, whenever the runtime
would issue a model-layer request (inference, /models, /policy, …) it
asks the registered CopilotRequestHandler to service it instead of making
the call itself.
CopilotRequestHandler is the single seam consumers implement: one HTTP
send method and one WebSocket factory, each defaulting to transparent
pass-through to the real upstream. Override
send_request to mutate / replace HTTP
requests, or open_websocket to
mutate the handshake or return a custom CopilotWebSocketHandler.
§Cancellation
CopilotRequestContext::cancel fires when the runtime cancels the
in-flight request (for example because the agent turn was aborted). Forward
it to the upstream call so it is torn down too, and stop writing the response.
Structs§
- Copilot
Http Request - A buffered HTTP request handed to
CopilotRequestHandler::send_request. - Copilot
Http Response - A streaming HTTP response returned by
CopilotRequestHandler::send_request. - Copilot
Request Context - Context describing an intercepted request, shared by the HTTP and WebSocket seams.
- Copilot
WebSocket Forwarder - The default WebSocket handler: forwards each runtime message to the real upstream and each upstream message back to the runtime. Mutate by supplying transforms on the builder.
- Copilot
WebSocket Forwarder Builder - Builder for a
CopilotWebSocketForwarder. - Copilot
WebSocket Message - A single WebSocket message flowing through a
CopilotWebSocketHandler. - Copilot
WebSocket Response - The runtime-facing side of a WebSocket: a
CopilotWebSocketHandlerwrites upstream→runtime messages here.
Enums§
- Copilot
Request Error - Error returned by a
CopilotRequestHandlerhook or the response stream. - Copilot
Request Transport - Transport the runtime would otherwise use for an intercepted request.
Traits§
- Copilot
Request Handler - The connection-level Copilot request seam.
- Copilot
WebSocket Handler - A per-connection WebSocket handler. The default implementation
(
CopilotWebSocketForwarder) bridges to the real upstream; overrideCopilotRequestHandler::open_websocketto supply a custom one.
Functions§
- forward_
http - Forward an HTTP request to its real upstream and stream the response back.
Type Aliases§
- Copilot
Http Response Body - Streaming response body: a sequence of byte chunks or a terminal error.
- WebSocket
Transform - Transform applied to a WebSocket message; return
Noneto drop it.