server

package
v0.0.0-...-4ac60c8 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: MIT Imports: 31 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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompleteResponsesSSEStream

func CompleteResponsesSSEStream(r io.Reader, w io.Writer) (bool, error)

CompleteResponsesSSEStream fills an empty final output from completed stream items.

func PassThroughSSEStream

func PassThroughSSEStream(r io.Reader, w io.Writer) error

PassThroughSSEStream copies upstream SSE events directly to the downstream writer without any transformation.

func RewriteSSEStream

func RewriteSSEStream(r io.Reader, w io.Writer, model string) error

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

func TransformSSELine(in []byte) (out []byte, done bool, err error)

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 ChatFunctionCall struct {
	Name      string `json:"name"`
	Arguments string `json:"arguments"`
}

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) Poll

func (a *DeviceAuth) Poll(ctx context.Context) (deviceAuthStatus, error)

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 DeviceAuthStore interface {
	LoadDeviceAuthSession() ([]byte, error)
	SaveDeviceAuthSession([]byte) error
	StoreCredentials(accessToken, refreshToken string, expiresAt int64, accountID string) error
	CompleteDeviceAuth(accessToken, refreshToken string, expiresAt int64, accountID string) error
}

type HTTPClient

type HTTPClient interface {
	Do(req *http.Request) (*http.Response, error)
}

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

func (*SSETransformer) Transform

func (t *SSETransformer) Transform(dataLine []byte) (out []byte, done bool, err error)

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

func (s *Server) PrefetchModels(ctx context.Context)

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.

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

Jump to

Keyboard shortcuts

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