relay

package
v0.1.10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 6, 2026 License: MIT Imports: 44 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClaudeProxyCAPath

func ClaudeProxyCAPath(dataDirectory string) string

ClaudeProxyCAPath is trusted only by clients configured with NODE_EXTRA_CA_CERTS.

func ClaudeProxyURL

func ClaudeProxyURL(address, capability string) string

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 ClaudeAccountObserver interface {
	ObserveClaudeResponse(store.AccountKey, string, http.Header, int)
}

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.AccountKey, 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.AccountKey, modelSlug string) bool
	ReportExhaustedTurn(id store.TaskID, served store.AccountKey, resetsAt time.Time) string
	ReportUnauthorizedTurn(served store.AccountKey, rejected accounts.Credentials)
	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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL