completion_api

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2026 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

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"`
	Tools    []cursor_api_sdk.OpenAIToolDef `json:"tools,omitempty"`
}

ChatCompletionRequest is the OpenAI chat completions body we accept.

type CompletionsRequest

type CompletionsRequest struct {
	Model  string `json:"model"`
	Prompt any    `json:"prompt"`
	Stream bool   `json:"stream"`
}

CompletionsRequest is the legacy OpenAI text completions shape.

type Handler

type Handler struct {
	Server *Server
}

Handler serves OpenAI-compatible endpoints.

func (*Handler) Mount

func (h *Handler) Mount(mux *http.ServeMux)

Mount registers routes on mux (paths under /v1/...).

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

func (s *Server) ListModels(ctx context.Context) ([]cursor_api_sdk.Model, error)

ListModels returns the cached catalog when fresh; otherwise fetches via the account pool.

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.

Jump to

Keyboard shortcuts

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