Skip to main content

Module copilot_request_handler

Module copilot_request_handler 

Source
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§

CopilotHttpRequest
A buffered HTTP request handed to CopilotRequestHandler::send_request.
CopilotHttpResponse
A streaming HTTP response returned by CopilotRequestHandler::send_request.
CopilotRequestContext
Context describing an intercepted request, shared by the HTTP and WebSocket seams.
CopilotWebSocketForwarder
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.
CopilotWebSocketForwarderBuilder
Builder for a CopilotWebSocketForwarder.
CopilotWebSocketMessage
A single WebSocket message flowing through a CopilotWebSocketHandler.
CopilotWebSocketResponse
The runtime-facing side of a WebSocket: a CopilotWebSocketHandler writes upstream→runtime messages here.

Enums§

CopilotRequestError
Error returned by a CopilotRequestHandler hook or the response stream.
CopilotRequestTransport
Transport the runtime would otherwise use for an intercepted request.

Traits§

CopilotRequestHandler
The connection-level Copilot request seam.
CopilotWebSocketHandler
A per-connection WebSocket handler. The default implementation (CopilotWebSocketForwarder) bridges to the real upstream; override CopilotRequestHandler::open_websocket to supply a custom one.

Functions§

forward_http
Forward an HTTP request to its real upstream and stream the response back.

Type Aliases§

CopilotHttpResponseBody
Streaming response body: a sequence of byte chunks or a terminal error.
WebSocketTransform
Transform applied to a WebSocket message; return None to drop it.