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 ¶
const ( DefaultChatID = "chatcmpl-fake" DefaultResponseID = "resp_fake" DefaultCreated = 1700000000 DefaultNoul = 0.75 )
Fixed values of the default answers, so tests can assert on them.
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.
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}.
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.
const DefaultChatJSONContent = `{"answer":"` + DefaultChatContent + `"}`
DefaultChatJSONContent is the default chat answer when the request asks for a JSON response_format.
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.
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.
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.