control

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: Apache-2.0 Imports: 11 Imported by: 1 module, 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

Overview

Package control implements the scripted fake upstreams used by the e2e tests and the control API that scripts them and reads back what they received.

Index

Constants

View Source
const (
	DefaultChatID     = "chatcmpl-fake"
	DefaultResponseID = "resp_fake"
	DefaultCreated    = 1700000000
	DefaultNoul       = 0.75
)

Fixed values of the default answers, so tests can assert on them.

View Source
const (
	DefaultQuotaAntigravitySummary = `{"groups":[` +
		`{"groupId":"gemini","displayName":"Gemini","buckets":[` +
		`{"window":"5h","remaining":{"remainingFraction":0.8,"resetTime":"2099-01-01T05:00:00Z"}},` +
		`{"window":"weekly","remaining":{"remainingFraction":0.5,"resetTime":"2099-01-07T00:00:00Z"}}]},` +
		`{"groupId":"claude-gpt","displayName":"Claude & GPT","buckets":[` +
		`{"window":"5h","remaining":{"remainingFraction":0,"resetTime":"2099-01-01T05:00:00Z"}},` +
		`{"window":"weekly","remaining":{"remainingFraction":0.25,"resetTime":"2099-01-07T00:00:00Z"}}]}]}`
	DefaultQuotaAntigravityLoad     = `{"paidTier":{"id":"g1-pro-tier","name":"Pro"}}`
	DefaultQuotaAntigravityManifest = "version: 9.9.9\n"
	DefaultQuotaCodexUsage          = `{"plan_type":"plus","rate_limit":{"limit_reached":false,` +
		`"primary_window":{"used_percent":30,"limit_window_seconds":18000,"reset_at":4070912400},` +
		`"secondary_window":{"used_percent":60,"limit_window_seconds":604800,"reset_at":4071430800}}}`
	DefaultQuotaClaudeUsage = `{"five_hour":{"utilization":10,"resets_at":"2099-01-01T05:00:00Z"},` +
		`"seven_day":{"utilization":40,"resets_at":"2099-01-07T00:00:00Z"},"seven_day_opus":null}`
)

Default answers of the providers' private quota endpoints. Resets are in 2099 so they never pass during a run.

View Source
const (
	RouteOpenAIChat           = "openai.chat"                  // POST /v1/chat/completions
	RouteOpenAIEmbeddings     = "openai.embeddings"            // POST /v1/embeddings
	RouteOpenAITranscriptions = "openai.transcriptions"        // POST /v1/audio/transcriptions
	RouteOpenAIDecisions      = "openai.decisions"             // POST /v1/decisions
	RouteOpenAIResponses      = "openai.responses"             // POST /v1/responses
	RouteModels               = "models"                       // GET  /v1/models
	RouteOpenRouterAuthKey    = "openrouter.auth_key"          // GET  /v1/auth/key
	RouteSonioxFileCreate     = "soniox.files.create"          // POST /v1/files
	RouteSonioxFileList       = "soniox.files.list"            // GET  /v1/files
	RouteSonioxFileDelete     = "soniox.files.delete"          // DELETE /v1/files/{id}
	RouteSonioxTxCreate       = "soniox.transcriptions.create" // POST /v1/transcriptions
	RouteSonioxTxList         = "soniox.transcriptions.list"   // GET  /v1/transcriptions
	RouteSonioxTxGet          = "soniox.transcriptions.get"    // GET  /v1/transcriptions/{id}
	RouteSonioxTxDelete       = "soniox.transcriptions.delete" // DELETE /v1/transcriptions/{id}
	RouteSonioxTranscript     = "soniox.transcript.get"        // GET  /v1/transcriptions/{id}/transcript
	RouteTypeSafeSystemOne    = "typesafe.systemone"           // POST /v1/systemone

	RouteQuotaAntigravitySummary  = "quota.antigravity.summary"  // POST /v1internal:retrieveUserQuotaSummary
	RouteQuotaAntigravityLoad     = "quota.antigravity.load"     // POST /v1internal:loadCodeAssist
	RouteQuotaAntigravityManifest = "quota.antigravity.manifest" // GET  /manifest/latest-arm64-mac.yml
	RouteQuotaCodexUsage          = "quota.codex.usage"          // GET  /backend-api/wham/usage
	RouteQuotaClaudeUsage         = "quota.claude.usage"         // GET  /api/oauth/usage
)

Route names, matched under /u/{upstream}.

View Source
const DefaultChatContent = "می\u200cشود و نمی\u200cخواهم"

DefaultChatContent is the assistant text of the default chat answer, streamed or not. It holds two zero-width non-joiners (U+200C) so byte-for-byte fidelity is tested even without a script.

View Source
const DefaultChatJSONContent = `{"answer":"` + DefaultChatContent + `"}`

DefaultChatJSONContent is the default chat answer when the request asks for a JSON response_format.

View Source
const DefaultEmbeddingDimensions = 8

DefaultEmbeddingDimensions is the vector length when a request sets no dimensions.

Variables

This section is empty.

Functions

func Defaults

func Defaults() map[string]http.HandlerFunc

Defaults returns the default answer of every route this plan serves: OpenAI chat (plain and streamed), Responses, embeddings and decisions, TypeSafe System One and the model listing. Each echoes the requested model.

func Embedding

func Embedding(index, dims int) []float32

Embedding is the default vector for the input at index: deterministic, non-zero, and exact in float32.

Types

type RecordedRequest

type RecordedRequest struct {
	Route  string      `json:"route"`
	Method string      `json:"method"`
	Path   string      `json:"path"`
	Header http.Header `json:"header"`
	Body   []byte      `json:"body"` // base64 in JSON
	At     time.Time   `json:"at"`
}

RecordedRequest is one request a fake upstream received.

type Script

type Script struct {
	Steps  []Step `json:"steps"`
	Repeat bool   `json:"repeat"` // after the last step: true = repeat it, false = fall back to the route default
}

Script is the ordered replies for one (upstream, route).

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server holds the scripts and recordings of every fake upstream.

func New

func New(defaults map[string]http.HandlerFunc) *Server

New returns a Server. defaults maps a route name to the handler used when the route has no script step left; a missing entry answers 501.

func (*Server) Handler

func (s *Server) Handler() http.Handler

Handler returns the HTTP handler serving the fakes and the control API.

type Step

type Step struct {
	Status  int               `json:"status"`             // default 200
	Headers map[string]string `json:"headers,omitempty"`  // Content-Type defaults to application/json
	Body    string            `json:"body,omitempty"`     // written verbatim
	DelayMS int               `json:"delay_ms,omitempty"` // before the first byte; honours request cancellation
	SSE     []string          `json:"sse,omitempty"`      // when set: text/event-stream, one flushed `data:` event each, then [DONE]
	// IntervalMS, with SSE, waits this long before every event after the first, [DONE] included; it honours request
	// cancellation. It makes a stream last as long as a test needs.
	IntervalMS int `json:"interval_ms,omitempty"`
}

Step is one scripted reply.

Jump to

Keyboard shortcuts

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