Documentation
¶
Overview ¶
Package relay forwards Codex HTTP, SSE, and WebSocket traffic without replaying model work or retaining request and response content. It changes only the Authorization and ChatGPT account request headers.
Index ¶
- func ClaudeProxyCAPath(dataDirectory string) string
- func ClaudeProxyURL(address, capability string) string
- func CreateClaudeProxyCertificate(dataDirectory string) (tls.Certificate, error)
- func NewUpstreamTransport() http.RoundTripper
- type ClaudeAccountObserver
- type ClaudeForwardProxy
- type CompletionLedger
- type ModelRequestCounters
- type RelayHandlerOptions
- type TaskRouter
- type TrafficRelayHandler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ClaudeProxyCAPath ¶
ClaudeProxyCAPath is trusted only by clients configured with NODE_EXTRA_CA_CERTS.
func ClaudeProxyURL ¶
ClaudeProxyURL carries the same private capability as the API entry point.
func CreateClaudeProxyCertificate ¶
func CreateClaudeProxyCertificate(dataDirectory string) (tls.Certificate, error)
CreateClaudeProxyCertificate retains one authority across process generations. Its certificate and private key share a private file so they cannot diverge.
func NewUpstreamTransport ¶
func NewUpstreamTransport() http.RoundTripper
NewUpstreamTransport is the one way this process reaches providers: account reads, the deployment provider check and client traffic all use it, so the check proves the path that serves traffic.
Types ¶
type ClaudeAccountObserver ¶
type ClaudeForwardProxy ¶
type ClaudeForwardProxy struct {
// contains filtered or unexported fields
}
ClaudeForwardProxy handles CONNECT on the same listener as the private API. Only Anthropic model POSTs enter the account pool; all other traffic keeps the client's credentials. Tunnel lifetime is part of the relay's drain.
func CreateClaudeForwardProxy ¶
func CreateClaudeForwardProxy(dataDirectory, capability string, trafficRelay *TrafficRelayHandler, next http.Handler) (*ClaudeForwardProxy, error)
func (*ClaudeForwardProxy) DrainConnections ¶
func (proxy *ClaudeForwardProxy) DrainConnections()
DrainConnections gives connections doing no work one grace period. HTTP shutdown closes idle connections now and model connections after their reply.
func (*ClaudeForwardProxy) ServeHTTP ¶
func (proxy *ClaudeForwardProxy) ServeHTTP(writer http.ResponseWriter, request *http.Request)
func (*ClaudeForwardProxy) SetConnectionDrainGrace ¶ added in v0.1.7
func (proxy *ClaudeForwardProxy) SetConnectionDrainGrace(grace time.Duration)
SetConnectionDrainGrace changes the grace DrainConnections gives.
type CompletionLedger ¶
type CompletionLedger interface {
RecordCompletedResponse(store.CompletedResponseRecord) error
}
CompletionLedger is the only response fact the relay persists.
type ModelRequestCounters ¶
type ModelRequestCounters interface {
RecordModelRequestOutcome(store.AccountName, time.Time, store.ModelRequestOutcome) error
}
type RelayHandlerOptions ¶
type RelayHandlerOptions struct {
UpstreamOrigin *url.URL
ClaudeUpstreamOrigin *url.URL
AccountObserver ClaudeAccountObserver
CacheAffinity *store.StoreDatabase
ClientCapability string
TaskRouter TaskRouter
CompletionLedger CompletionLedger
RequestCounters ModelRequestCounters
HTTPTransport http.RoundTripper
OnFailure func()
OnModelRequest func()
}
RelayHandlerOptions keeps listener and signal ownership outside the transport package.
type TaskRouter ¶
type TaskRouter interface {
RouteForModelCatalogue() (routing.RouteDecision, error)
RouteForTask(id store.TaskID, kind store.WorkKind, modelSlug string) (routing.RouteDecision, error)
RouteForProviderTask(store.TaskID, store.WorkKind, string, accounts.Provider, store.TaskID) (routing.RouteDecision, error)
ReportUnsupportedModel(id store.TaskID, served store.AccountName, modelSlug string) bool
ReportExhaustedTurn(id store.TaskID, served store.AccountName, resetsAt time.Time) string
ClaudePoolCapacity(modelSlug string) (accountFree bool, availableAgainAt time.Time, limitClaim string, err error)
}
TaskRouter keeps transport code independent of pin selection and movement.
type TrafficRelayHandler ¶
type TrafficRelayHandler struct {
// contains filtered or unexported fields
}
TrafficRelayHandler stays alive with admitted streams so deployment does not cut off model work.
func CreateTrafficRelayHandler ¶
func CreateTrafficRelayHandler(options RelayHandlerOptions) (*TrafficRelayHandler, error)
CreateTrafficRelayHandler leaves listener ownership and signal handling with the command layer.
func (*TrafficRelayHandler) BeginRelayDrain ¶
func (handler *TrafficRelayHandler) BeginRelayDrain()
BeginRelayDrain closes idle upstream keep-alives after the command layer stops admission.
func (*TrafficRelayHandler) CloseWebSocketsOnceIdle ¶
func (handler *TrafficRelayHandler) CloseWebSocketsOnceIdle()
CloseWebSocketsOnceIdle starts an update. Responses in progress finish on this process. Each WebSocket, including any upgraded later, closes once it has had no response in progress for the quiet period; a request arriving before then closes it unforwarded. Codex and Pi then send their next request on a new connection, which reaches the new process.
func (*TrafficRelayHandler) ServeHTTP ¶
func (handler *TrafficRelayHandler) ServeHTTP(response http.ResponseWriter, request *http.Request)
ServeHTTP authenticates the private client path before any account credential is selected.
func (*TrafficRelayHandler) WaitForRelayDrain ¶
func (handler *TrafficRelayHandler) WaitForRelayDrain(ctx context.Context) error
WaitForRelayDrain returns once every admitted request has finished.
Source Files
¶
- byte_preserving_response_observer.go
- claude_forward_proxy.go
- claude_provider_relay.go
- claude_proxy_authority.go
- claude_request_identity.go
- doc.go
- in_flight_request_drain.go
- model_request_accounting.go
- relay_collaborator_contracts.go
- request_task_identity.go
- server_sent_event_observer.go
- stream_event_type.go
- terminal_response_recognition.go
- traffic_relay_handler.go
- upstream_rejection.go
- upstream_transport.go
- websocket_frame_observer.go