server

package
v0.0.0-...-e9f67e9 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2026 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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"`
}

type ChatMessage

type ChatMessage struct {
	Role    string `json:"role"`
	Content string `json:"content"`
}

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 Option

type Option func(*Server)

func WithDeviceAuth

func WithDeviceAuth(store DeviceAuthStore) 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) 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