Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrBodyTooLarge = errors.New("request body too large")
ErrBodyTooLarge is returned by readJSONBody when the request exceeds max bytes.
Functions ¶
This section is empty.
Types ¶
type AccountPool ¶
type AccountPool interface {
PickCandidates() []*cursor_account_sdk.Account
EnsureAccess(ctx context.Context, id string) (*cursor_account_sdk.Account, error)
MarkUsed(id string)
MarkRateLimited(id string)
}
AccountPool is the account rotation surface Server needs. *account_pool.Pool satisfies this interface.
type ChatCompletionRequest ¶
type ChatCompletionRequest struct {
Model string `json:"model"`
Messages []cursor_api_sdk.ChatMessage `json:"messages"`
Stream bool `json:"stream"`
StreamOptions *StreamOptions `json:"stream_options,omitempty"`
N *int `json:"n,omitempty"`
Tools []cursor_api_sdk.OpenAIToolDef `json:"tools,omitempty"`
ToolChoice json.RawMessage `json:"tool_choice,omitempty"`
// Sticky identity fields (otto conversation/identity.ts) — first non-empty wins.
ConversationID string `json:"conversation_id,omitempty"`
ThreadID string `json:"thread_id,omitempty"`
SessionID string `json:"session_id,omitempty"`
User string `json:"user,omitempty"`
Metadata map[string]any `json:"metadata,omitempty"`
}
ChatCompletionRequest is the OpenAI chat completions body we accept.
func (*ChatCompletionRequest) UnmarshalJSON ¶ added in v1.5.0
func (r *ChatCompletionRequest) UnmarshalJSON(data []byte) error
type CompletionsRequest ¶
type CompletionsRequest struct {
Model string `json:"model"`
Prompt json.RawMessage `json:"prompt"`
Stream bool `json:"stream"`
StreamOptions *StreamOptions `json:"stream_options,omitempty"`
N *int `json:"n,omitempty"`
}
CompletionsRequest is the legacy OpenAI text completions shape.
func (*CompletionsRequest) UnmarshalJSON ¶ added in v1.5.0
func (r *CompletionsRequest) UnmarshalJSON(data []byte) error
type Server ¶
type Server struct {
Pool AccountPool
API UpstreamAPI
Log *slog.Logger
MaxBody int64
// contains filtered or unexported fields
}
Server holds shared dependencies for OpenAI handlers.
func NewServer ¶
func NewServer(pool *account_pool.Pool, api *cursor_api_sdk.Client, log *slog.Logger) *Server
NewServer wires a concrete pool and API client for handlers / CLI reuse.
func (*Server) ListModels ¶
ListModels returns the cached catalog when fresh; otherwise fetches via the account pool.
type StreamOptions ¶ added in v1.5.0
type StreamOptions struct {
IncludeUsage bool `json:"include_usage"`
}
StreamOptions is the OpenAI stream_options object.
type UpstreamAPI ¶
type UpstreamAPI interface {
CachedModels() []cursor_api_sdk.Model
ListModels(ctx context.Context, accessToken string) ([]cursor_api_sdk.Model, error)
ResolveModelSelection(ctx context.Context, accessToken, modelID string) (cursor_api_sdk.ModelSelection, error)
StartRun(ctx context.Context, accessToken string, payload *cursor_api_sdk.RunPayload, bridgeTools bool) (*cursor_api_sdk.RunControl, error)
}
UpstreamAPI is the Cursor upstream surface Server needs. *cursor_api_sdk.Client satisfies this interface.