Documentation
¶
Index ¶
- func CompleteResponsesSSEStream(r io.Reader, w io.Writer) (bool, error)
- func PassThroughSSEStream(r io.Reader, w io.Writer) error
- func RewriteSSEStream(r io.Reader, w io.Writer, model string) error
- func RewriteSSEStreamWithCallback(r io.Reader, w io.Writer, model string, ...) error
- func TransformSSELine(in []byte) (out []byte, done bool, err error)
- type ChatCompletionChoice
- type ChatCompletionRequest
- type ChatCompletionResponse
- type ChatFunctionCall
- type ChatMessage
- type ChatToolCall
- type DeviceAuth
- type DeviceAuthError
- type DeviceAuthStore
- type HTTPClient
- type ModelsCacheStore
- type Option
- type SSETransformer
- type Server
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CompleteResponsesSSEStream ¶
CompleteResponsesSSEStream fills an empty final output from completed stream items.
func PassThroughSSEStream ¶
PassThroughSSEStream copies upstream SSE events directly to the downstream writer without any transformation.
func RewriteSSEStream ¶
RewriteSSEStream reads an upstream SSE stream and writes a transformed SSE stream to w. It expects lines in the form 'data: <json>\n' and blank lines separating events. The provided model is used when emitting OpenAI chunks. The function emits transformed lines preserving SSE framing and a terminal 'data: [DONE]\n\n'.
func RewriteSSEStreamWithCallback ¶
func RewriteSSEStreamWithCallback(r io.Reader, w io.Writer, model string, onEvent func(raw []byte, out []byte, done bool)) error
RewriteSSEStreamWithCallback aggregates multi-line data: blocks per SSE event, transforms each event, writes it out, and invokes onEvent for debug if set.
func TransformSSELine ¶
TransformSSELine transforms a single SSE data payload line. - If payload is "[DONE]", returns done=true. - If payload is an OpenAI chat chunk (object == chat.completion.chunk), pass through unchanged. - Otherwise, interpret as Codex event and convert via SSETransformer.
Types ¶
type ChatCompletionChoice ¶
type ChatCompletionChoice struct {
Index int `json:"index"`
Message ChatMessage `json:"message"`
FinishReason string `json:"finish_reason"`
}
type ChatCompletionRequest ¶
type ChatCompletionRequest struct {
Model string `json:"model"`
Messages []ChatMessage `json:"messages"`
Temperature *float64 `json:"temperature,omitempty"`
TopP *float64 `json:"top_p,omitempty"`
N *int `json:"n,omitempty"`
Stream *bool `json:"stream,omitempty"`
User *string `json:"user,omitempty"`
OtherParams map[string]interface{} `json:"-"`
}
func (*ChatCompletionRequest) UnmarshalJSON ¶
func (r *ChatCompletionRequest) UnmarshalJSON(data []byte) error
type ChatCompletionResponse ¶
type ChatCompletionResponse struct {
ID string `json:"id"`
Object string `json:"object"`
Created int64 `json:"created"`
Model string `json:"model"`
Choices []ChatCompletionChoice `json:"choices"`
Usage json.RawMessage `json:"usage,omitempty"`
}
type ChatFunctionCall ¶
type ChatMessage ¶
type ChatMessage struct {
Role string `json:"role"`
Content *string `json:"content"`
ToolCalls []ChatToolCall `json:"tool_calls,omitempty"`
}
type ChatToolCall ¶
type ChatToolCall struct {
ID string `json:"id"`
Type string `json:"type"`
Function ChatFunctionCall `json:"function"`
}
type DeviceAuth ¶
type DeviceAuth struct {
// contains filtered or unexported fields
}
func (*DeviceAuth) Start ¶
func (a *DeviceAuth) Start(ctx context.Context) (deviceAuthStatus, error)
func (*DeviceAuth) Status ¶
func (a *DeviceAuth) Status() (deviceAuthStatus, error)
type DeviceAuthError ¶
type DeviceAuthError struct {
// contains filtered or unexported fields
}
func (*DeviceAuthError) Error ¶
func (e *DeviceAuthError) Error() string
type DeviceAuthStore ¶
type HTTPClient ¶
HTTPClient is an interface for making HTTP requests
func NewHTTPClient ¶
func NewHTTPClient() HTTPClient
NewHTTPClient creates a new HTTP client for regular environments
type ModelsCacheStore ¶
type ModelsCacheStore interface {
LoadModelsCache() ([]byte, error)
SaveModelsCache(data []byte, ttl time.Duration) error
ClearModelsCache() error
}
ModelsCacheStore persists the upstream model listing across stateless runtimes such as Cloudflare Workers.
type Option ¶
type Option func(*Server)
func WithDeviceAuth ¶
func WithDeviceAuth(store DeviceAuthStore) Option
func WithModelsCache ¶
func WithModelsCache(store ModelsCacheStore) Option
type SSETransformer ¶
type SSETransformer struct {
// contains filtered or unexported fields
}
func NewSSETransformer ¶
func NewSSETransformer(model string) *SSETransformer
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
func New ¶
func New(logger zerolog.Logger, credsFetcher credentials.CredentialsFetcher, options ...Option) *Server
func (*Server) PrefetchModels ¶
PrefetchModels fills the model cache so the first requests don't wait on the upstream listing. A failure logs a warning and starts the lookup backoff.
Source Files
¶
- admin.go
- chat_completions_buffered.go
- client.go
- device_auth.go
- device_auth_handlers.go
- mcp_handler.go
- models.go
- prompts.go
- realtime_transcription.go
- responses_buffered.go
- responses_sse.go
- responses_sse_stats.go
- server.go
- transform.go
- transform_responses.go
- types.go
- upstream_models.go
- upstream_selector.go
- upstream_websocket.go