proxy

package
v0.14.4-dev.26 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const WebSocketProtocolHeader = "responses_websockets=2026-02-06"

Variables

View Source
var AllowedModels = []string{"gpt-5.2", "gpt-5.3-codex", "gpt-5.3-codex-spark", "gpt-5.4", "gpt-5.4-mini", "gpt-5.5"}

Functions

func AccumulateCodex

func AccumulateCodex(input []byte, messageID, model string) (map[string]any, error)

func CodexToAnthropicSSE

func CodexToAnthropicSSE(input []byte, messageID, model string) ([][]byte, error)

func EncodeSSE

func EncodeSSE(event string, data any) []byte

func ReduceCodexSSE

func ReduceCodexSSE(input []byte) ([]map[string]any, error)

func Snippet

func Snippet(value string, maxBytes int) string

func TranslateAnthropic

func TranslateAnthropic(request map[string]any, options TranslateOptions) (map[string]any, error)

func WebSocketHeaders

func WebSocketHeaders(input http.Header) http.Header

func WebSocketPayload

func WebSocketPayload(body map[string]any) []byte

func WebSocketURL

func WebSocketURL(raw string) (string, error)

Types

type AuthManager

type AuthManager interface {
	Snapshot() (AuthSnapshot, error)
	RefreshAfterUnauthorized() (bool, error)
}

type AuthSnapshot

type AuthSnapshot struct{ AccessToken, AccountID, EndpointURL string }

type Config

type Config struct {
	Port                                                 int
	ClientToken                                          string
	Transport                                            Transport
	RequestTimeout, ConnectTimeout, WebSocketIdleTimeout time.Duration
	Models                                               ModelMap
	Diagnostics                                          DiagnosticsConfig
}

func ConfigFromEnvironment

func ConfigFromEnvironment(token string) Config

type Diagnostics

type Diagnostics struct {
	// contains filtered or unexported fields
}

func NewDiagnostics

func NewDiagnostics(config DiagnosticsConfig) (*Diagnostics, error)

func (*Diagnostics) Close

func (diagnostics *Diagnostics) Close()

func (*Diagnostics) Event

func (diagnostics *Diagnostics) Event(kind string, fields map[string]any)

type DiagnosticsConfig

type DiagnosticsConfig struct {
	LogDirectory string
	LogPayloads  bool
	MaxBodyBytes int
}

type ModelMap

type ModelMap struct{ Big, Middle, Small string }

func DefaultModelMap

func DefaultModelMap() ModelMap

func ModelMapFromEnvironment

func ModelMapFromEnvironment() ModelMap

func (ModelMap) List

func (models ModelMap) List() map[string]any

func (ModelMap) Resolve

func (models ModelMap) Resolve(requested string) ProxyModel

type ProxyModel

type ProxyModel struct{ Requested, Upstream, ServiceTier string }

type Running

type Running struct {
	Server *Server
	Done   <-chan error
	Token  string
}

func Start

func Start(projectRoot string) (*Running, error)

func (*Running) Apply

func (running *Running) Apply(command *exec.Cmd)

func (*Running) Shutdown

func (running *Running) Shutdown()

type SSEEvent

type SSEEvent struct{ Event, Data string }

func ParseSSE

func ParseSSE(input []byte) ([]SSEEvent, error)

type Server

type Server struct {
	// contains filtered or unexported fields
}

func NewServer

func NewServer(config Config, auth AuthManager) (*Server, error)

func (*Server) BaseURL

func (server *Server) BaseURL() string

func (*Server) Run

func (server *Server) Run() error

func (*Server) Shutdown

func (server *Server) Shutdown(ctx context.Context) error

func (*Server) Start

func (server *Server) Start() <-chan error

type TranslateOptions

type TranslateOptions struct {
	SessionID, ServiceTier, ServiceTierOverride, EffortOverride string
}

type Transport

type Transport string
const (
	TransportHTTP      Transport = "http"
	TransportWebSocket Transport = "websocket"
	TransportAuto      Transport = "auto"
)

type UpstreamAuth

type UpstreamAuth struct {
	// contains filtered or unexported fields
}

func LoadUpstreamAuth

func LoadUpstreamAuth() (*UpstreamAuth, error)

func (*UpstreamAuth) DefaultTransport

func (auth *UpstreamAuth) DefaultTransport() Transport

func (*UpstreamAuth) RefreshAfterUnauthorized

func (auth *UpstreamAuth) RefreshAfterUnauthorized() (bool, error)

func (*UpstreamAuth) Snapshot

func (auth *UpstreamAuth) Snapshot() (AuthSnapshot, error)

type WebSocketSetupError

type WebSocketSetupError struct {
	Message          string
	Status           int
	Code, RetryAfter string
	RequestSent      bool
}

func (*WebSocketSetupError) Error

func (err *WebSocketSetupError) Error() string

Jump to

Keyboard shortcuts

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