Documentation
¶
Overview ¶
Package ai provides provider abstractions, model definitions, and auth storage for pig.
The model catalogs are generated from the exact published Pi package pinned by extensions/sdk-ts. Run `make model-catalogs` after changing the upstream pin.
Code generated from the exact published upstream image-models.generated.js. DO NOT EDIT.
Index ¶
- Constants
- Variables
- func APIKeyProviderName(id string) string
- func AdjustMaxTokensForThinking(baseMaxTokens *int, modelMaxTokens int, reasoningLevel string, ...) (maxTokens, thinkingBudget int)
- func CalculateContextTokens(usage Usage) int
- func ClampMaxTokensToContext(model *Model, context TranscriptContext, maxTokens int) int
- func ClampOpenAIPromptCacheKey(key string) string
- func CleanupSessionResources(sessionID string) error
- func CloseOpenAICodexWebSocketSessions(sessionID ...string)
- func CodexAccountID(accessToken string) string
- func CompareThinkingLevels(a, b ThinkingLevel) int
- func ConfigureHTTPDispatcher(timeoutMs int) error
- func ConfigureProviderRetry(maxRetries, maxRetryDelayMs int) error
- func ConfiguredHTTPIdleTimeoutMs() int
- func ConfiguredProviderRetry() (maxRetries, maxRetryDelayMs int)
- func DeclarationsEqual(left, right ToolSchema) bool
- func EstimateMessageTokens(message Message) int
- func EstimateTextTokens(text string) int
- func FindEnvKeys(provider string, env map[string]string) []string
- func GetCurrentSystemPrompt(messages []Message) string
- func GetEnvAPIKey(provider string, env map[string]string) string
- func GetOverflowPatterns() []*regexp.Regexp
- func HasNonAdditiveToolChanges(messages []Message) bool
- func HasToolRedefinitions(messages []Message) bool
- func IsContextOverflow(message AssistantMessage, contextWindow int) bool
- func IsOAuthSubscriptionProvider(providerID string) bool
- func IsRecoverableLength(message AssistantMessage, desiredMaxOutput int) bool
- func IsRetryableAssistantError(message AssistantMessage) bool
- func JSONStringifyLength(value any) int
- func ListProviders() []string
- func ListRuntimeProviders() []string
- func ModelsAreEqual(a, b *Model) bool
- func NewFauxProvider(cfg FauxConfig) *fauxProvider
- func NormalizeRadiusGatewayURL(value string) string
- func OAuthErrorHTML(message, details string) string
- func OAuthSuccessHTML(message string) string
- func PiUserAgent() string
- func PollOAuthDeviceCodeFlow[T any](ctx context.Context, opts DeviceCodePollOptions[T]) (T, error)
- func ProviderHeader(value string) *string
- func ProviderMaxRetries(ctx context.Context) int
- func RegisterBuiltInImagesAPIProviders()
- func RegisterImagesAPIProvider(provider ImagesAPIProvider)
- func RegisterOAuthProvider(id string, provider OAuthProviderInterface)
- func RegisterSessionResourceCleanup(cleanup SessionResourceCleanup) func()
- func RenderSystemMessageUpdate(message SystemMessage) string
- func ResetOAuthProviders()
- func ResetOpenAICodexWebSocketDebugStats(sessionID ...string)
- func ResolveCloudflareBaseURL(providerID, baseURL string, env ProviderEnv) (string, error)
- func ResolveCopilotEnvFallback(auth *AuthStorage, envToken string) (bearer, baseURL string, err error)
- func ResolveOAuthAPIKeyFromStorage(storage *AuthStorage, providerID string) (string, error)
- func ResolveOAuthAPIKeyFromStorageContext(ctx context.Context, storage *AuthStorage, providerID string) (string, error)
- func ResolveStoredAPIKeyFromStorage(storage *AuthStorage, providerID string) (key string, ok bool, err error)
- func ResolveStoredAPIKeyFromStorageContext(ctx context.Context, storage *AuthStorage, providerID string) (key string, ok bool, err error)
- func RetryDelayMs(baseDelayMs int, maxAgentDelayMs *int, attempt int) int
- func UnregisterOAuthProvider(id string)
- func WithProviderMaxRetries(ctx context.Context, maxRetries int) context.Context
- type API
- type APIKeyAuth
- type APIKeyAuthInput
- type APIKeyProviderInfo
- type AnthropicAllowedFallbackModel
- type AnthropicConfig
- type AnthropicMessagesCompat
- type AnthropicOAuthProvider
- func (AnthropicOAuthProvider) GetAPIKey(c OAuthCredentials) string
- func (AnthropicOAuthProvider) ID() string
- func (AnthropicOAuthProvider) IsSubscription() bool
- func (a AnthropicOAuthProvider) Login(callbacks OAuthLoginCallbacks) (OAuthCredentials, error)
- func (AnthropicOAuthProvider) LoginContext(ctx context.Context, callbacks OAuthLoginCallbacks) (OAuthCredentials, error)
- func (AnthropicOAuthProvider) Name() string
- func (a AnthropicOAuthProvider) RefreshToken(creds OAuthCredentials) (OAuthCredentials, error)
- func (AnthropicOAuthProvider) RefreshTokenContext(ctx context.Context, creds OAuthCredentials) (OAuthCredentials, error)
- func (AnthropicOAuthProvider) UsesCallbackServer() bool
- type AssistantContentBlock
- type AssistantEventType
- type AssistantImages
- type AssistantMessage
- type AssistantMessageDiagnostic
- type AssistantMessageEvent
- type AssistantMessageEventStream
- type AssistantMessageFrame
- type AssistantMessageFrameEncoder
- type AssistantMessageFrameType
- type AuthCheck
- type AuthContext
- type AuthResolutionOverrides
- type AuthResult
- type AuthSource
- type AuthStatus
- type AuthStorage
- func (a *AuthStorage) Delete(provider string) error
- func (a *AuthStorage) Get(provider string) (Credential, bool, error)
- func (a *AuthStorage) GetAuthStatus(provider string) AuthStatus
- func (a *AuthStorage) GetProviderEnv(provider string) (map[string]string, error)
- func (a *AuthStorage) GetRaw(provider string) (Credential, bool, error)
- func (a *AuthStorage) List(ctx context.Context) ([]CredentialInfo, error)
- func (a *AuthStorage) Load() (map[string]Credential, error)
- func (a *AuthStorage) Modify(ctx context.Context, providerID string, ...) (*Credential, error)
- func (a *AuthStorage) Path() string
- func (a *AuthStorage) Read(ctx context.Context, providerID string) (*Credential, error)
- func (a *AuthStorage) Set(provider string, cred Credential) error
- func (a *AuthStorage) Update(provider string, mutate func(cur Credential, exists bool) (Credential, error)) error
- type AzureOpenAIResponsesConfig
- type BedrockProvider
- type CacheRetention
- type CodexOAuthProvider
- func (CodexOAuthProvider) GetAPIKey(c OAuthCredentials) string
- func (CodexOAuthProvider) ID() string
- func (CodexOAuthProvider) IsSubscription() bool
- func (c CodexOAuthProvider) Login(callbacks OAuthLoginCallbacks) (OAuthCredentials, error)
- func (c CodexOAuthProvider) LoginContext(ctx context.Context, callbacks OAuthLoginCallbacks) (OAuthCredentials, error)
- func (CodexOAuthProvider) Name() string
- func (c CodexOAuthProvider) RefreshToken(creds OAuthCredentials) (OAuthCredentials, error)
- func (CodexOAuthProvider) RefreshTokenContext(ctx context.Context, creds OAuthCredentials) (OAuthCredentials, error)
- func (CodexOAuthProvider) UsesCallbackServer() bool
- type ConstrainedSamplingConfig
- type ContentBlock
- type ContentBlocks
- type Context
- type ContextUsageEstimate
- type CopilotLoginCallbacks
- type CopilotProviderConfig
- type CostTier
- type Credential
- type CredentialInfo
- type CredentialStore
- type CredentialType
- type DeferredHandle
- type DeviceCodePollOptions
- type DeviceCodePollResult
- type DeviceCodePollStatus
- type DiagnosticErrorInfo
- type DoneEvent
- type ErrorEvent
- type FauxConfig
- type FauxContentBlock
- type FauxResponse
- type FauxResponseFactory
- type FauxResponseStep
- type FileModelsStore
- func (s *FileModelsStore) Delete(ctx context.Context, providerID string) error
- func (s *FileModelsStore) Path() string
- func (s *FileModelsStore) Read(ctx context.Context, providerID string) (*ModelsStoreEntry, error)
- func (s *FileModelsStore) Write(ctx context.Context, providerID string, entry ModelsStoreEntry) error
- type GeneratedModel
- type GoogleConfig
- type GoogleThinkingLevel
- type GoogleVertexConfig
- type GrammarFormat
- type ImageContent
- type ImagesAPI
- type ImagesAPIProvider
- type ImagesContext
- type ImagesCost
- type ImagesFunction
- type ImagesModel
- type ImagesProvider
- type ImagesStopReason
- type InMemoryAuthStorage
- type InMemoryModelsStore
- type JsonObject
- type Message
- type MistralConfig
- type Model
- type ModelAuth
- type ModelCapabilities
- type ModelCatalogProvider
- type ModelCompat
- type ModelCost
- type ModelImageInputLimits
- type ModelImageResizeOptions
- type ModelInputLimits
- type ModelPromptCache
- type ModelThinkingLevel
- type ModelsError
- type ModelsErrorCode
- type ModelsPublication
- type ModelsStore
- type ModelsStoreEntry
- type OAuthAuth
- type OAuthAuthInfo
- type OAuthCredentialStatus
- type OAuthCredentialStore
- type OAuthCredentials
- func GetOAuthAPIKey(providerID string, credentials map[string]OAuthCredentials) (*OAuthCredentials, string, error)
- func GetOAuthAPIKeyContext(ctx context.Context, providerID string, ...) (*OAuthCredentials, string, error)
- func LoginAnthropic(ctx context.Context, callbacks OAuthLoginCallbacks) (OAuthCredentials, error)
- func LoginOpenAICodex(ctx context.Context, callbacks OAuthLoginCallbacks) (OAuthCredentials, error)
- func LoginOpenAICodexDeviceCode(ctx context.Context, onDeviceCode func(OAuthDeviceCodeInfo)) (OAuthCredentials, error)
- func LoginOpenRouter(ctx context.Context, callbacks OAuthLoginCallbacks) (OAuthCredentials, error)
- func RefreshAnthropicToken(ctx context.Context, refreshToken string) (OAuthCredentials, error)
- func RefreshCodexToken(ctx context.Context, refreshToken string) (OAuthCredentials, error)
- type OAuthDeviceCodeInfo
- type OAuthLoginCallbacks
- type OAuthPrompt
- type OAuthProviderInterface
- type OAuthSelectOption
- type OAuthSelectPrompt
- type OAuthSubscriptionProvider
- type OpenAICodexResponsesConfig
- type OpenAICodexWebSocketDebugStats
- type OpenAICompat
- type OpenAIConfig
- type OpenAIResponsesCompat
- type OpenAIResponsesConfig
- type OpenRouterOAuthProvider
- func (OpenRouterOAuthProvider) GetAPIKey(c OAuthCredentials) string
- func (OpenRouterOAuthProvider) ID() string
- func (p OpenRouterOAuthProvider) Login(callbacks OAuthLoginCallbacks) (OAuthCredentials, error)
- func (OpenRouterOAuthProvider) LoginContext(ctx context.Context, callbacks OAuthLoginCallbacks) (OAuthCredentials, error)
- func (OpenRouterOAuthProvider) Name() string
- func (p OpenRouterOAuthProvider) RefreshToken(creds OAuthCredentials) (OAuthCredentials, error)
- func (OpenRouterOAuthProvider) RefreshTokenContext(_ context.Context, creds OAuthCredentials) (OAuthCredentials, error)
- func (OpenRouterOAuthProvider) UsesCallbackServer() bool
- type OrderedSections
- type PKCE
- type PiMessagesConfig
- type PiMessagesEvent
- type PiMessagesModel
- type PiMessagesResponse
- type PiMessagesResponseError
- type PiMessagesRewriteImpact
- type PromptSection
- type Provider
- func NewAnthropicProvider(cfg AnthropicConfig) Provider
- func NewAzureOpenAIResponsesProvider(cfg AzureOpenAIResponsesConfig) Provider
- func NewCopilotProvider(cfg CopilotProviderConfig) (Provider, error)
- func NewGoogleProvider(cfg GoogleConfig) Provider
- func NewGoogleVertexProvider(cfg GoogleVertexConfig) Provider
- func NewMistralProvider(cfg MistralConfig) Provider
- func NewOpenAICodexResponsesProvider(cfg OpenAICodexResponsesConfig) Provider
- func NewOpenAIProvider(cfg OpenAIConfig) Provider
- func NewOpenAIResponsesProvider(cfg OpenAIResponsesConfig) Provider
- func NewPiMessagesProvider(cfg PiMessagesConfig) Provider
- type ProviderAuth
- type ProviderEnv
- type ProviderFactory
- type ProviderHeaders
- type ProviderImagesOptions
- type ProviderMetadata
- type ProviderResponse
- type RadiusGatewayConfig
- type RadiusGatewayModel
- type RadiusModelCost
- type RadiusOAuth
- func (o *RadiusOAuth) Gateway() string
- func (o *RadiusOAuth) GetAPIKey(credentials OAuthCredentials) string
- func (o *RadiusOAuth) ID() string
- func (o *RadiusOAuth) Login(callbacks OAuthLoginCallbacks) (OAuthCredentials, error)
- func (o *RadiusOAuth) LoginContext(ctx context.Context, callbacks OAuthLoginCallbacks) (OAuthCredentials, error)
- func (o *RadiusOAuth) LoginMethodPrompt() OAuthSelectPrompt
- func (o *RadiusOAuth) Name() string
- func (o *RadiusOAuth) RefreshToken(credentials OAuthCredentials) (OAuthCredentials, error)
- func (o *RadiusOAuth) RefreshTokenContext(ctx context.Context, credentials OAuthCredentials) (OAuthCredentials, error)
- func (o *RadiusOAuth) UsesCallbackServer() bool
- type RadiusOAuthOptions
- type RadiusOAuthResponseError
- type RadiusProvider
- func (p *RadiusProvider) FindModel(id string) (PiMessagesModel, bool)
- func (p *RadiusProvider) Gateway() string
- func (p *RadiusProvider) GetModels() []PiMessagesModel
- func (p *RadiusProvider) ID() string
- func (p *RadiusProvider) Name() string
- func (p *RadiusProvider) OAuth() *RadiusOAuth
- func (p *RadiusProvider) RefreshModels(ctx context.Context, refresh RefreshModelsContext) error
- type RadiusProviderOptions
- type ReadOnlyAuthStorage
- func (s *ReadOnlyAuthStorage) List(ctx context.Context) ([]CredentialInfo, error)
- func (s *ReadOnlyAuthStorage) Modify(context.Context, string, func(*Credential) (*Credential, error)) (*Credential, error)
- func (s *ReadOnlyAuthStorage) Read(ctx context.Context, providerID string) (*Credential, error)
- type RefreshModelsContext
- type RetryCallbacks
- type RetryPolicy
- type RuntimeCredentials
- func (c *RuntimeCredentials) Delete(ctx context.Context, providerID string) error
- func (c *RuntimeCredentials) HasRuntimeAPIKey(providerID string) bool
- func (c *RuntimeCredentials) List(ctx context.Context) ([]CredentialInfo, error)
- func (c *RuntimeCredentials) Modify(ctx context.Context, providerID string, ...) (*Credential, error)
- func (c *RuntimeCredentials) Read(ctx context.Context, providerID string) (*Credential, error)
- func (c *RuntimeCredentials) RemoveRuntimeAPIKey(providerID string)
- func (c *RuntimeCredentials) RuntimeAPIKey(providerID string) (string, bool)
- func (c *RuntimeCredentials) SetRuntimeAPIKey(providerID, apiKey string)
- type SessionAffinityFormat
- type SessionResourceCleanup
- type StartEvent
- type StartFrame
- type StopReason
- type StreamOptions
- type SystemContent
- type SystemMessage
- type SystemText
- type SystemTextBlocks
- type TestFauxProvider
- type TextContent
- type TextDeltaEvent
- type TextDeltaFrame
- type TextEndEvent
- type TextEndFrame
- type TextStartEvent
- type TextStartFrame
- type ThinkingBudgets
- type ThinkingContent
- type ThinkingDeltaEvent
- type ThinkingDeltaFrame
- type ThinkingEndEvent
- type ThinkingEndFrame
- type ThinkingLevel
- type ThinkingLevelMap
- type ThinkingStartEvent
- type ThinkingStartFrame
- type TokenFailure
- type ToolCall
- type ToolCallCheckpointFrame
- type ToolCallDeltaEvent
- type ToolCallDeltaFrame
- type ToolCallEndEvent
- type ToolCallEndFrame
- type ToolCallStartEvent
- type ToolCallStartFrame
- type ToolReference
- type ToolResultMessage
- type ToolResultMessageContent
- type ToolSchema
- type ToolStateChanges
- type TranscriptContext
- type TranscriptTools
- type Transport
- type Usage
- type UsageCost
- type UserContent
- type UserContentBlock
- type UserContentBlocks
- type UserMessage
- type UserText
Constants ¶
const ( AnthropicAuthTokenEnv = "ANTHROPIC_AUTH_TOKEN" AnthropicOAuthTokenEnv = "ANTHROPIC_OAUTH_TOKEN" AnthropicAPIKeyEnv = "ANTHROPIC_API_KEY" )
Anthropic credential variables. Mirrors upstream ANTHROPIC_AUTH_TOKEN_ENV, ANTHROPIC_OAUTH_TOKEN_ENV, and ANTHROPIC_API_KEY_ENV.
const ( CloudflareWorkersAIBaseURL = "https://api.cloudflare.com/client/v4/accounts/{CLOUDFLARE_ACCOUNT_ID}/ai/v1" CloudflareAIGatewayCompatBaseURL = "https://gateway.ai.cloudflare.com/v1/{CLOUDFLARE_ACCOUNT_ID}/{CLOUDFLARE_GATEWAY_ID}/compat" CloudflareAIGatewayOpenAIBaseURL = "https://gateway.ai.cloudflare.com/v1/{CLOUDFLARE_ACCOUNT_ID}/{CLOUDFLARE_GATEWAY_ID}/openai" CloudflareAIGatewayAnthropicBaseURL = "https://gateway.ai.cloudflare.com/v1/{CLOUDFLARE_ACCOUNT_ID}/{CLOUDFLARE_GATEWAY_ID}/anthropic" )
const ( // OpenAICodexBrowserLoginMethod and OpenAICodexDeviceCodeLoginMethod are // the onSelect option ids for the two Codex login methods. Mirror // openai-codex.ts:41-42. OpenAICodexBrowserLoginMethod = "browser" OpenAICodexDeviceCodeLoginMethod = "device_code" )
const ( RadiusLoginMethodBrowser = "browser" RadiusLoginMethodDeviceCode = "device-code" )
const ( TestFauxContextWindow = 128000 TestFauxMaxTokens = 4096 )
TestFauxProvider is a deterministic, test-only provider used by the integration parity harness. It is deliberately NOT part of the normal model catalog and is only enabled when the binary is launched with the PIG_TEST_FAUX=1 environment variable.
Why this exists: live-model parity gates in tmux are prone to model/provider nondeterminism. Upstream is the source of truth, so parity gates must use a deterministic oracle when the live provider does not reliably materialize a scenario. This provider gives pig a stable scripted backend while upstream gets the same scripted behavior via a temp extension that registers an equivalent custom provider.
Supported scenario values (via PIG_TEST_FAUX_SCENARIO):
- parity-basic
Any other value returns an EventError. Test-faux model limits match the model the upstream side of the parity harness registers (parity/testdata/test-faux-provider.ts), so both sides report the same context window and output budget.
const AnthropicOAuthDisplayName = "Anthropic (Claude Pro/Max)"
AnthropicOAuthDisplayName is the OAuth method label upstream renders for Claude Pro/Max subscription login.
const DefaultHTTPIdleTimeoutMs = 300_000
const DefaultMaxAgentRetryDelayMs = 60_000
DefaultMaxAgentRetryDelayMs is the default cap for one agent retry delay.
const DefaultRadiusGateway = "https://radius.pi.dev"
DefaultRadiusGateway is the Radius gateway origin Pi uses by default.
const OpenAICodexOAuthDisplayName = "OpenAI (ChatGPT Plus/Pro)"
OpenAICodexOAuthDisplayName is the OAuth method label upstream renders for ChatGPT Plus/Pro Codex subscription login.
const RadiusProviderID = "radius"
RadiusProviderID is the built-in Radius provider ID.
const TestFauxToolStartedMarker = ".pig-faux-tool-started"
TestFauxToolStartedMarker is created in the working directory by the "Run: sleep for a while" scenario's tool as soon as it starts running, so a test can wait for the run to reach tool execution rather than sleeping for a guessed interval.
Variables ¶
var GeneratedImageModels = []ImagesModel{ {ID: "black-forest-labs/flux.2-flex", Name: "Black Forest Labs: FLUX.2 Flex", API: ImagesAPI("openrouter-images"), Provider: ImagesProvider("openrouter"), BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, Output: []string{"image"}, Cost: ImagesCost{Input: 0, Output: 0, CacheRead: 0, CacheWrite: 0}}, {ID: "black-forest-labs/flux.2-klein-4b", Name: "Black Forest Labs: FLUX.2 Klein 4B", API: ImagesAPI("openrouter-images"), Provider: ImagesProvider("openrouter"), BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, Output: []string{"image"}, Cost: ImagesCost{Input: 0, Output: 0, CacheRead: 0, CacheWrite: 0}}, {ID: "black-forest-labs/flux.2-max", Name: "Black Forest Labs: FLUX.2 Max", API: ImagesAPI("openrouter-images"), Provider: ImagesProvider("openrouter"), BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, Output: []string{"image"}, Cost: ImagesCost{Input: 0, Output: 0, CacheRead: 0, CacheWrite: 0}}, {ID: "black-forest-labs/flux.2-pro", Name: "Black Forest Labs: FLUX.2 Pro", API: ImagesAPI("openrouter-images"), Provider: ImagesProvider("openrouter"), BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, Output: []string{"image"}, Cost: ImagesCost{Input: 0, Output: 0, CacheRead: 0, CacheWrite: 0}}, {ID: "bytedance-seed/seedream-4.5", Name: "ByteDance Seed: Seedream 4.5", API: ImagesAPI("openrouter-images"), Provider: ImagesProvider("openrouter"), BaseURL: "https://openrouter.ai/api/v1", Input: []string{"image", "text"}, Output: []string{"image"}, Cost: ImagesCost{Input: 0, Output: 0, CacheRead: 0, CacheWrite: 0}}, {ID: "bytedance-seed/seedream-5-0-lite", Name: "ByteDance Seed: Seedream 5.0 Lite", API: ImagesAPI("openrouter-images"), Provider: ImagesProvider("openrouter"), BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, Output: []string{"image"}, Cost: ImagesCost{Input: 0, Output: 0, CacheRead: 0, CacheWrite: 0}}, {ID: "bytedance-seed/seedream-5-0-pro", Name: "ByteDance Seed: Seedream 5.0 Pro", API: ImagesAPI("openrouter-images"), Provider: ImagesProvider("openrouter"), BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, Output: []string{"image"}, Cost: ImagesCost{Input: 0, Output: 0, CacheRead: 0, CacheWrite: 0}}, {ID: "google/gemini-2.5-flash-image", Name: "Google: Nano Banana (Gemini 2.5 Flash Image)", API: ImagesAPI("openrouter-images"), Provider: ImagesProvider("openrouter"), BaseURL: "https://openrouter.ai/api/v1", Input: []string{"image", "text"}, Output: []string{"image", "text"}, Cost: ImagesCost{Input: 0.3, Output: 2.5, CacheRead: 0.03, CacheWrite: 0.0833333333333333}}, {ID: "google/gemini-3-pro-image", Name: "Google: Nano Banana Pro (Gemini 3 Pro Image)", API: ImagesAPI("openrouter-images"), Provider: ImagesProvider("openrouter"), BaseURL: "https://openrouter.ai/api/v1", Input: []string{"image", "text"}, Output: []string{"image", "text"}, Cost: ImagesCost{Input: 2, Output: 12, CacheRead: 0.19999999999999998, CacheWrite: 0.375}}, {ID: "google/gemini-3-pro-image-preview", Name: "Google: Nano Banana Pro (Gemini 3 Pro Image Preview)", API: ImagesAPI("openrouter-images"), Provider: ImagesProvider("openrouter"), BaseURL: "https://openrouter.ai/api/v1", Input: []string{"image", "text"}, Output: []string{"image", "text"}, Cost: ImagesCost{Input: 2, Output: 12, CacheRead: 0.19999999999999998, CacheWrite: 0.375}}, {ID: "google/gemini-3.1-flash-image", Name: "Google: Nano Banana 2 (Gemini 3.1 Flash Image)", API: ImagesAPI("openrouter-images"), Provider: ImagesProvider("openrouter"), BaseURL: "https://openrouter.ai/api/v1", Input: []string{"image", "text"}, Output: []string{"image", "text"}, Cost: ImagesCost{Input: 0.5, Output: 3, CacheRead: 0, CacheWrite: 0}}, {ID: "google/gemini-3.1-flash-image-preview", Name: "Google: Nano Banana 2 (Gemini 3.1 Flash Image Preview)", API: ImagesAPI("openrouter-images"), Provider: ImagesProvider("openrouter"), BaseURL: "https://openrouter.ai/api/v1", Input: []string{"image", "text"}, Output: []string{"image", "text"}, Cost: ImagesCost{Input: 0.5, Output: 3, CacheRead: 0, CacheWrite: 0}}, {ID: "google/gemini-3.1-flash-lite-image", Name: "Google: Nano Banana 2 Lite (Gemini 3.1 Flash Lite Image)", API: ImagesAPI("openrouter-images"), Provider: ImagesProvider("openrouter"), BaseURL: "https://openrouter.ai/api/v1", Input: []string{"image", "text"}, Output: []string{"image", "text"}, Cost: ImagesCost{Input: 0.25, Output: 1.5, CacheRead: 0, CacheWrite: 0}}, {ID: "inclusionai/ming-image-0.1-design", Name: "inclusionAI: Ming Image 0.1 Design", API: ImagesAPI("openrouter-images"), Provider: ImagesProvider("openrouter"), BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text"}, Output: []string{"image"}, Cost: ImagesCost{Input: 0, Output: 0, CacheRead: 0, CacheWrite: 0}}, {ID: "krea/krea-2-large", Name: "Krea: Krea 2 Large", API: ImagesAPI("openrouter-images"), Provider: ImagesProvider("openrouter"), BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, Output: []string{"image"}, Cost: ImagesCost{Input: 0, Output: 0, CacheRead: 0, CacheWrite: 0}}, {ID: "krea/krea-2-medium", Name: "Krea: Krea 2 Medium", API: ImagesAPI("openrouter-images"), Provider: ImagesProvider("openrouter"), BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, Output: []string{"image"}, Cost: ImagesCost{Input: 0, Output: 0, CacheRead: 0, CacheWrite: 0}}, {ID: "krea/krea-2-medium-turbo", Name: "Krea: Krea 2 Medium Turbo", API: ImagesAPI("openrouter-images"), Provider: ImagesProvider("openrouter"), BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, Output: []string{"image"}, Cost: ImagesCost{Input: 0, Output: 0, CacheRead: 0, CacheWrite: 0}}, {ID: "meta/muse-image", Name: "Meta: Muse Image", API: ImagesAPI("openrouter-images"), Provider: ImagesProvider("openrouter"), BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, Output: []string{"image"}, Cost: ImagesCost{Input: 0, Output: 0, CacheRead: 0, CacheWrite: 0}}, {ID: "microsoft/mai-image-2.5", Name: "Microsoft AI: MAI-Image-2.5", API: ImagesAPI("openrouter-images"), Provider: ImagesProvider("openrouter"), BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, Output: []string{"image"}, Cost: ImagesCost{Input: 5, Output: 0, CacheRead: 0, CacheWrite: 0}}, {ID: "microsoft/mai-image-2.5-pro", Name: "Microsoft AI: MAI-Image-2.5 Pro", API: ImagesAPI("openrouter-images"), Provider: ImagesProvider("openrouter"), BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, Output: []string{"image"}, Cost: ImagesCost{Input: 5, Output: 0, CacheRead: 0, CacheWrite: 0}}, {ID: "microsoft/mai-image-2.6", Name: "Microsoft AI: MAI-Image-2.6", API: ImagesAPI("openrouter-images"), Provider: ImagesProvider("openrouter"), BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, Output: []string{"image"}, Cost: ImagesCost{Input: 5, Output: 0, CacheRead: 0, CacheWrite: 0}}, {ID: "microsoft/mai-image-2.6-flash", Name: "Microsoft AI: MAI-Image-2.6 Flash", API: ImagesAPI("openrouter-images"), Provider: ImagesProvider("openrouter"), BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, Output: []string{"image"}, Cost: ImagesCost{Input: 1.75, Output: 0, CacheRead: 0, CacheWrite: 0}}, {ID: "openai/gpt-5-image", Name: "OpenAI: GPT-5 Image", API: ImagesAPI("openrouter-images"), Provider: ImagesProvider("openrouter"), BaseURL: "https://openrouter.ai/api/v1", Input: []string{"image", "text"}, Output: []string{"image", "text"}, Cost: ImagesCost{Input: 10, Output: 10, CacheRead: 1.25, CacheWrite: 0}}, {ID: "openai/gpt-5-image-mini", Name: "OpenAI: GPT-5 Image Mini", API: ImagesAPI("openrouter-images"), Provider: ImagesProvider("openrouter"), BaseURL: "https://openrouter.ai/api/v1", Input: []string{"image", "text"}, Output: []string{"image", "text"}, Cost: ImagesCost{Input: 2.5, Output: 2, CacheRead: 0.25, CacheWrite: 0}}, {ID: "openai/gpt-5.4-image-2", Name: "OpenAI: GPT-5.4 Image 2", API: ImagesAPI("openrouter-images"), Provider: ImagesProvider("openrouter"), BaseURL: "https://openrouter.ai/api/v1", Input: []string{"image", "text"}, Output: []string{"image", "text"}, Cost: ImagesCost{Input: 8, Output: 15, CacheRead: 2, CacheWrite: 0}}, {ID: "openai/gpt-image-1", Name: "OpenAI: GPT Image 1", API: ImagesAPI("openrouter-images"), Provider: ImagesProvider("openrouter"), BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, Output: []string{"image"}, Cost: ImagesCost{Input: 10, Output: 10, CacheRead: 1.25, CacheWrite: 0}}, {ID: "openai/gpt-image-1-mini", Name: "OpenAI: GPT Image 1 Mini", API: ImagesAPI("openrouter-images"), Provider: ImagesProvider("openrouter"), BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, Output: []string{"image"}, Cost: ImagesCost{Input: 2.5, Output: 2.5, CacheRead: 0.25, CacheWrite: 0}}, {ID: "openai/gpt-image-2", Name: "OpenAI: GPT Image 2", API: ImagesAPI("openrouter-images"), Provider: ImagesProvider("openrouter"), BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, Output: []string{"image"}, Cost: ImagesCost{Input: 8, Output: 8, CacheRead: 2, CacheWrite: 0}}, {ID: "openai/gpt-image-2.5-flare", Name: "OpenAI: GPT Image 2.5 Flare", API: ImagesAPI("openrouter-images"), Provider: ImagesProvider("openrouter"), BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, Output: []string{"image"}, Cost: ImagesCost{Input: 8, Output: 8, CacheRead: 2, CacheWrite: 0}}, {ID: "openai/gpt-image-2.5-sunburst", Name: "OpenAI: GPT Image 2.5 Sunburst", API: ImagesAPI("openrouter-images"), Provider: ImagesProvider("openrouter"), BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, Output: []string{"image"}, Cost: ImagesCost{Input: 8, Output: 8, CacheRead: 2, CacheWrite: 0}}, {ID: "openrouter/auto", Name: "Auto Router", API: ImagesAPI("openrouter-images"), Provider: ImagesProvider("openrouter"), BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, Output: []string{"text", "image"}, Cost: ImagesCost{Input: -1e+06, Output: -1e+06, CacheRead: 0, CacheWrite: 0}}, {ID: "openrouter/auto-beta", Name: "Auto Router (Beta)", API: ImagesAPI("openrouter-images"), Provider: ImagesProvider("openrouter"), BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, Output: []string{"text", "image"}, Cost: ImagesCost{Input: -1e+06, Output: -1e+06, CacheRead: 0, CacheWrite: 0}}, {ID: "qwen/qwen-image-3", Name: "Qwen: Qwen Image 3", API: ImagesAPI("openrouter-images"), Provider: ImagesProvider("openrouter"), BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, Output: []string{"image"}, Cost: ImagesCost{Input: 0, Output: 0, CacheRead: 0, CacheWrite: 0}}, {ID: "qwen/qwen-image-3-pro", Name: "Qwen: Qwen Image 3 Pro", API: ImagesAPI("openrouter-images"), Provider: ImagesProvider("openrouter"), BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, Output: []string{"image"}, Cost: ImagesCost{Input: 0, Output: 0, CacheRead: 0, CacheWrite: 0}}, {ID: "recraft/recraft-v3", Name: "Recraft: Recraft V3", API: ImagesAPI("openrouter-images"), Provider: ImagesProvider("openrouter"), BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, Output: []string{"image"}, Cost: ImagesCost{Input: 0, Output: 0, CacheRead: 0, CacheWrite: 0}}, {ID: "recraft/recraft-v4", Name: "Recraft: Recraft V4", API: ImagesAPI("openrouter-images"), Provider: ImagesProvider("openrouter"), BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, Output: []string{"image"}, Cost: ImagesCost{Input: 0, Output: 0, CacheRead: 0, CacheWrite: 0}}, {ID: "recraft/recraft-v4-pro", Name: "Recraft: Recraft V4 Pro", API: ImagesAPI("openrouter-images"), Provider: ImagesProvider("openrouter"), BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, Output: []string{"image"}, Cost: ImagesCost{Input: 0, Output: 0, CacheRead: 0, CacheWrite: 0}}, {ID: "recraft/recraft-v4-pro-vector", Name: "Recraft: Recraft V4 Pro Vector", API: ImagesAPI("openrouter-images"), Provider: ImagesProvider("openrouter"), BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, Output: []string{"image"}, Cost: ImagesCost{Input: 0, Output: 0, CacheRead: 0, CacheWrite: 0}}, {ID: "recraft/recraft-v4-styles", Name: "Recraft: Recraft V4 Styles", API: ImagesAPI("openrouter-images"), Provider: ImagesProvider("openrouter"), BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, Output: []string{"image"}, Cost: ImagesCost{Input: 0, Output: 0, CacheRead: 0, CacheWrite: 0}}, {ID: "recraft/recraft-v4-styles-pro", Name: "Recraft: Recraft V4 Styles Pro", API: ImagesAPI("openrouter-images"), Provider: ImagesProvider("openrouter"), BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, Output: []string{"image"}, Cost: ImagesCost{Input: 0, Output: 0, CacheRead: 0, CacheWrite: 0}}, {ID: "recraft/recraft-v4-styles-pro-vector", Name: "Recraft: Recraft V4 Styles Pro Vector", API: ImagesAPI("openrouter-images"), Provider: ImagesProvider("openrouter"), BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, Output: []string{"image"}, Cost: ImagesCost{Input: 0, Output: 0, CacheRead: 0, CacheWrite: 0}}, {ID: "recraft/recraft-v4-styles-vector", Name: "Recraft: Recraft V4 Styles Vector", API: ImagesAPI("openrouter-images"), Provider: ImagesProvider("openrouter"), BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, Output: []string{"image"}, Cost: ImagesCost{Input: 0, Output: 0, CacheRead: 0, CacheWrite: 0}}, {ID: "recraft/recraft-v4-vector", Name: "Recraft: Recraft V4 Vector", API: ImagesAPI("openrouter-images"), Provider: ImagesProvider("openrouter"), BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, Output: []string{"image"}, Cost: ImagesCost{Input: 0, Output: 0, CacheRead: 0, CacheWrite: 0}}, {ID: "recraft/recraft-v4.1", Name: "Recraft: Recraft V4.1", API: ImagesAPI("openrouter-images"), Provider: ImagesProvider("openrouter"), BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, Output: []string{"image"}, Cost: ImagesCost{Input: 0, Output: 0, CacheRead: 0, CacheWrite: 0}}, {ID: "recraft/recraft-v4.1-pro", Name: "Recraft: Recraft V4.1 Pro", API: ImagesAPI("openrouter-images"), Provider: ImagesProvider("openrouter"), BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, Output: []string{"image"}, Cost: ImagesCost{Input: 0, Output: 0, CacheRead: 0, CacheWrite: 0}}, {ID: "recraft/recraft-v4.1-pro-vector", Name: "Recraft: Recraft V4.1 Pro Vector", API: ImagesAPI("openrouter-images"), Provider: ImagesProvider("openrouter"), BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, Output: []string{"image"}, Cost: ImagesCost{Input: 0, Output: 0, CacheRead: 0, CacheWrite: 0}}, {ID: "recraft/recraft-v4.1-utility", Name: "Recraft: Recraft V4.1 Utility", API: ImagesAPI("openrouter-images"), Provider: ImagesProvider("openrouter"), BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, Output: []string{"image"}, Cost: ImagesCost{Input: 0, Output: 0, CacheRead: 0, CacheWrite: 0}}, {ID: "recraft/recraft-v4.1-utility-pro", Name: "Recraft: Recraft V4.1 Utility Pro", API: ImagesAPI("openrouter-images"), Provider: ImagesProvider("openrouter"), BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, Output: []string{"image"}, Cost: ImagesCost{Input: 0, Output: 0, CacheRead: 0, CacheWrite: 0}}, {ID: "recraft/recraft-v4.1-vector", Name: "Recraft: Recraft V4.1 Vector", API: ImagesAPI("openrouter-images"), Provider: ImagesProvider("openrouter"), BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, Output: []string{"image"}, Cost: ImagesCost{Input: 0, Output: 0, CacheRead: 0, CacheWrite: 0}}, {ID: "sourceful/riverflow-v2-fast", Name: "Sourceful: Riverflow V2 Fast", API: ImagesAPI("openrouter-images"), Provider: ImagesProvider("openrouter"), BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, Output: []string{"image"}, Cost: ImagesCost{Input: 0, Output: 0, CacheRead: 0, CacheWrite: 0}}, {ID: "sourceful/riverflow-v2-pro", Name: "Sourceful: Riverflow V2 Pro", API: ImagesAPI("openrouter-images"), Provider: ImagesProvider("openrouter"), BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, Output: []string{"image"}, Cost: ImagesCost{Input: 0, Output: 0, CacheRead: 0, CacheWrite: 0}}, {ID: "sourceful/riverflow-v2.5-fast", Name: "Sourceful: Riverflow V2.5 Fast", API: ImagesAPI("openrouter-images"), Provider: ImagesProvider("openrouter"), BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, Output: []string{"image"}, Cost: ImagesCost{Input: 0, Output: 0, CacheRead: 0, CacheWrite: 0}}, {ID: "sourceful/riverflow-v2.5-pro", Name: "Sourceful: Riverflow V2.5 Pro", API: ImagesAPI("openrouter-images"), Provider: ImagesProvider("openrouter"), BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, Output: []string{"image"}, Cost: ImagesCost{Input: 0, Output: 0, CacheRead: 0, CacheWrite: 0}}, {ID: "x-ai/grok-imagine-image-2.0", Name: "xAI: Grok Imagine Image 2.0", API: ImagesAPI("openrouter-images"), Provider: ImagesProvider("openrouter"), BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, Output: []string{"image"}, Cost: ImagesCost{Input: 0, Output: 0, CacheRead: 0, CacheWrite: 0}}, {ID: "x-ai/grok-imagine-image-quality", Name: "SpaceXAI: Grok Imagine Image Quality", API: ImagesAPI("openrouter-images"), Provider: ImagesProvider("openrouter"), BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, Output: []string{"image"}, Cost: ImagesCost{Input: 0, Output: 0, CacheRead: 0, CacheWrite: 0}}, }
GeneratedImageModels is the static image model catalog (55 entries).
var GeneratedModels = []GeneratedModel{}/* 1495 elements not displayed */
GeneratedModels is the static catalog (1495 entries).
var ProductVersion = pigversion.Version
ProductVersion is PiG's composite release version for outbound identifiers. It defaults to pigversion.Version because importing coding would create a cycle.
Functions ¶
func APIKeyProviderName ¶
APIKeyProviderName looks up the display name for an API-key provider id. Returns the id unchanged if no built-in match exists, mirroring the old buildAuthProviderName default branch.
func AdjustMaxTokensForThinking ¶
func AdjustMaxTokensForThinking(baseMaxTokens *int, modelMaxTokens int, reasoningLevel string, custom *ThinkingBudgets) (maxTokens, thinkingBudget int)
AdjustMaxTokensForThinking computes maxTokens and thinkingBudget given an optional caller max, model limit, thinking level, and optional custom budgets. A nil base max means "unset": use the model cap and fit the thinking budget inside it. Mirrors upstream adjustMaxTokensForThinking (simple-options.ts:24-47).
func CalculateContextTokens ¶
CalculateContextTokens returns the context size a usage block reports: the provider total, else the sum of its components.
func ClampMaxTokensToContext ¶
func ClampMaxTokensToContext(model *Model, context TranscriptContext, maxTokens int) int
ClampMaxTokensToContext reduces a requested output budget to what fits in the model's context window after the estimated request context and a safety margin, never below one token. Mirrors upstream clampMaxTokensToContext, which buildBaseOptions applies to every request.
func ClampOpenAIPromptCacheKey ¶
ClampOpenAIPromptCacheKey clamps an OpenAI prompt cache/session key to upstream's 64-Unicode-scalar limit without splitting UTF-8 sequences.
func CleanupSessionResources ¶
CleanupSessionResources invokes all registered cleanup hooks for the given session id and joins cleanup errors. Empty session ids are ignored by hooks that scope by session.
func CloseOpenAICodexWebSocketSessions ¶
func CloseOpenAICodexWebSocketSessions(sessionID ...string)
CloseOpenAICodexWebSocketSessions closes one session's cached connections, or every cached connection when no session id is supplied.
func CodexAccountID ¶
CodexAccountID extracts the chatgpt_account_id claim from a Codex access token, if present. Mirrors upstream getAccountId (openai-codex.ts:281-285). Returns "" if the token doesn't carry the expected JWT shape.
func CompareThinkingLevels ¶
func CompareThinkingLevels(a, b ThinkingLevel) int
CompareThinkingLevels returns -1, 0, or +1 comparing a and b by semantic order (off < minimal < low < medium < high < xhigh). Unknown levels sort before "off".
func ConfigureHTTPDispatcher ¶
ConfigureHTTPDispatcher updates the package-global idle timeout used by new streaming HTTP clients. Zero disables the per-read/per-write idle deadline. Mirrors upstream's configureHttpDispatcher(settingsManager.getHttpIdleTimeoutMs()).
func ConfigureProviderRetry ¶
ConfigureProviderRetry sets the package-global provider-request retry policy. It mirrors the resolution of retry.provider.maxRetries / maxRetryDelayMs from settings (sdk.ts passes both into retryProviderRequest). maxRetries<=0 leaves the retry transport inert. Mirrors ConfigureHTTPDispatcher's global-config pattern for the sibling retry.provider.timeoutMs.
func ConfiguredHTTPIdleTimeoutMs ¶
func ConfiguredHTTPIdleTimeoutMs() int
ConfiguredHTTPIdleTimeoutMs returns the currently configured package-global HTTP idle timeout used for new streaming clients.
func ConfiguredProviderRetry ¶
func ConfiguredProviderRetry() (maxRetries, maxRetryDelayMs int)
ConfiguredProviderRetry returns the currently configured provider retry policy: maxRetries and maxRetryDelayMs.
func DeclarationsEqual ¶
func DeclarationsEqual(left, right ToolSchema) bool
func EstimateMessageTokens ¶
EstimateMessageTokens estimates one transcript message: system text with its tool changes, text and image content, or assistant text, thinking, and tool calls.
func EstimateTextTokens ¶
EstimateTextTokens estimates text at four characters per token.
func FindEnvKeys ¶
FindEnvKeys returns the configured environment variables that can provide an API key for provider, in lookup order, or nil. Ambient credential sources (AWS profiles and IAM, Google ADC) are not API keys and are not reported.
func GetCurrentSystemPrompt ¶
GetCurrentSystemPrompt renders replayed instructions and nonempty sections in order.
func GetEnvAPIKey ¶
GetEnvAPIKey returns a provider's API key from its environment variables, or "<authenticated>" for Vertex ADC and AWS ambient credentials, or "".
func GetOverflowPatterns ¶
GetOverflowPatterns returns a copy of the overflow patterns. Mirrors upstream getOverflowPatterns.
func HasToolRedefinitions ¶
func IsContextOverflow ¶
func IsContextOverflow(message AssistantMessage, contextWindow int) bool
IsContextOverflow reports whether an assistant message represents a context overflow: an error whose message matches a provider overflow pattern, a successful response whose input exceeds contextWindow (z.ai silent overflow), or a length stop with no output that filled the context window (Xiaomi MiMo). contextWindow 0 disables the usage-based cases. Mirrors upstream isContextOverflow.
func IsOAuthSubscriptionProvider ¶
IsOAuthSubscriptionProvider reports whether the provider's OAuth login is a subscription login. Mirrors upstream ModelRuntime.isUsingSubscription's auth.oauth?.isSubscription === true test.
func IsRecoverableLength ¶
func IsRecoverableLength(message AssistantMessage, desiredMaxOutput int) bool
IsRecoverableLength reports whether a length stop ended below the intended output limit. desiredMaxOutput must be the limit before any context-based clamping. Mirrors upstream isRecoverableLength.
func IsRetryableAssistantError ¶
func IsRetryableAssistantError(message AssistantMessage) bool
IsRetryableAssistantError classifies whether a failed assistant message looks like a transient provider or transport error. It does not implement retry policy; callers handle context overflow first.
func JSONStringifyLength ¶
JSONStringifyLength returns the JavaScript length (UTF-16 code units) of JSON.stringify(value), or of "[unserializable]" when value cannot be encoded (estimate.ts safeJsonStringify). encoding/json escapes U+2028, U+2029, and invalid UTF-8 as \uXXXX where JSON.stringify writes one character, so each of those escapes counts as one unit.
func ListProviders ¶
func ListProviders() []string
ListProviders returns the sorted list of unique provider names from the generated static model catalog. Mirrors upstream providers/all.ts:getBuiltinProviders and compat.ts:getProviders.
func ListRuntimeProviders ¶
func ListRuntimeProviders() []string
ListRuntimeProviders returns providers with an implemented runtime API.
func ModelsAreEqual ¶
ModelsAreEqual returns true if both models share the same ID and provider. Mirrors upstream models.ts:modelsAreEqual.
func NewFauxProvider ¶
func NewFauxProvider(cfg FauxConfig) *fauxProvider
NewFauxProvider creates a mock Provider for testing.
func NormalizeRadiusGatewayURL ¶
NormalizeRadiusGatewayURL adds an https scheme when absent and strips trailing slashes. Mirrors upstream normalizeRadiusGatewayUrl.
func OAuthErrorHTML ¶
OAuthErrorHTML returns the HTML page shown on OAuth callback error.
func OAuthSuccessHTML ¶
OAuthSuccessHTML returns the HTML page shown on successful OAuth callback.
func PiUserAgent ¶
func PiUserAgent() string
pig divergence (D65): upstream getPiUserAgent (packages/ai/src/utils/pi-user-agent.ts) reports "pi (<platform> <release>; <arch>)" from Node's os module, or "pi (browser)" with no Node/Bun runtime. PiG has no browser build and always runs as a native process, so PiUserAgent reports the same platform/release/arch shape with PiG's own product name and composite version instead: "pig/<coding.Version> (<platform> <release>; <arch>)" (owner decision, delivery/OWNER-DECISIONS.md Q4).
func PollOAuthDeviceCodeFlow ¶
func PollOAuthDeviceCodeFlow[T any](ctx context.Context, opts DeviceCodePollOptions[T]) (T, error)
PollOAuthDeviceCodeFlow runs the RFC 8628 polling loop: it calls Poll, honoring pending/slow_down/failed/complete, sleeping the (possibly widened) interval between attempts, until Poll completes or the deadline/ctx fires. Mirrors upstream pollOAuthDeviceCodeFlow.
func ProviderHeader ¶
ProviderHeader returns a non-null ProviderHeaders value.
func ProviderMaxRetries ¶
ProviderMaxRetries is the retry budget for requests made with ctx: the WithProviderMaxRetries override, else retry.provider.maxRetries.
func RegisterBuiltInImagesAPIProviders ¶
func RegisterBuiltInImagesAPIProviders()
RegisterBuiltInImagesAPIProviders registers upstream's built-in image API providers. Currently upstream ships OpenRouter image generation only.
func RegisterImagesAPIProvider ¶
func RegisterImagesAPIProvider(provider ImagesAPIProvider)
RegisterImagesAPIProvider registers or replaces an image API provider.
func RegisterOAuthProvider ¶
func RegisterOAuthProvider(id string, provider OAuthProviderInterface)
RegisterOAuthProvider adds a custom OAuth provider. Mirrors upstream registerOAuthProvider (oauth/index.ts:64).
func RegisterSessionResourceCleanup ¶
func RegisterSessionResourceCleanup(cleanup SessionResourceCleanup) func()
RegisterSessionResourceCleanup registers a session-scoped cleanup hook and returns an unregister function. Mirrors upstream registerSessionResourceCleanup.
func RenderSystemMessageUpdate ¶
func RenderSystemMessageUpdate(message SystemMessage) string
RenderSystemMessageUpdate joins instruction blocks with newlines and frames section changes using literal names.
func ResetOAuthProviders ¶
func ResetOAuthProviders()
ResetOAuthProviders removes all custom providers, restoring built-ins only. Mirrors upstream resetOAuthProviders (oauth/index.ts:86).
func ResetOpenAICodexWebSocketDebugStats ¶
func ResetOpenAICodexWebSocketDebugStats(sessionID ...string)
ResetOpenAICodexWebSocketDebugStats clears one session's counters, or all counters when no session id is supplied.
func ResolveCloudflareBaseURL ¶
func ResolveCloudflareBaseURL(providerID, baseURL string, env ProviderEnv) (string, error)
ResolveCloudflareBaseURL substitutes account and gateway placeholders using only explicit provider environment values and JavaScript replacement-string semantics. Missing values retain their placeholders; empty values replace them with empty strings.
func ResolveCopilotEnvFallback ¶
func ResolveCopilotEnvFallback(auth *AuthStorage, envToken string) (bearer, baseURL string, err error)
ResolveCopilotEnvFallback resolves the github-copilot bearer and base URL via the same copilotTokenManager NewCopilotProvider uses, for an auth store with no stored credential and the given env API key. It lets the parity harness assert the env-fallback path (upstream auth-storage.getApiKey step 4) without a live network; production resolution runs through the identical manager inside the provider's stream path.
func ResolveOAuthAPIKeyFromStorage ¶
func ResolveOAuthAPIKeyFromStorage(storage *AuthStorage, providerID string) (string, error)
ResolveOAuthAPIKeyFromStorage loads a provider credential from auth.json, refreshes it if needed, persists any refresh, and returns the provider's runtime API key string.
func ResolveOAuthAPIKeyFromStorageContext ¶
func ResolveOAuthAPIKeyFromStorageContext(ctx context.Context, storage *AuthStorage, providerID string) (string, error)
ResolveOAuthAPIKeyFromStorageContext loads, refreshes, and persists a provider credential with the owning operation's cancellation.
func ResolveStoredAPIKeyFromStorage ¶
func ResolveStoredAPIKeyFromStorage(storage *AuthStorage, providerID string) (key string, ok bool, err error)
ResolveStoredAPIKeyFromStorage returns the request key a stored auth.json credential supplies for providerID. Prefer ResolveStoredAPIKeyFromStorageContext when an operation context is available.
func ResolveStoredAPIKeyFromStorageContext ¶
func ResolveStoredAPIKeyFromStorageContext(ctx context.Context, storage *AuthStorage, providerID string) (key string, ok bool, err error)
ResolveStoredAPIKeyFromStorageContext returns a refreshed OAuth key or a resolved api_key credential. A stored credential is checked before caller fallbacks, and OAuth refresh follows ctx.
func RetryDelayMs ¶
RetryDelayMs returns the capped exponential delay for a 1-based attempt. Overflowing products saturate at Number.MAX_SAFE_INTEGER before the cap.
func UnregisterOAuthProvider ¶
func UnregisterOAuthProvider(id string)
UnregisterOAuthProvider removes a custom OAuth provider. Mirrors upstream unregisterOAuthProvider (oauth/index.ts:74).
func WithProviderMaxRetries ¶
WithProviderMaxRetries returns a context whose provider requests retry at most maxRetries times, overriding retry.provider.maxRetries. It carries upstream's per-request StreamOptions.maxRetries, which the transport-level retry policy cannot see.
Types ¶
type API ¶
type API string
API identifies which provider-API protocol a model uses to talk to its backend. It mirrors upstream `@mariozechner/pi-ai`'s `Api` union type (.upstream/current/packages/ai/src/types.ts:17):
export type Api = KnownApi | (string & {});
The string base type allows forward-compatibility for new APIs added upstream without breaking the pig build, while [KnownAPIs] enumerates the values defined as of the pinned UpstreamVersion.
Use cases: model catalog (GeneratedModel.API), extension provider registration (extension.ProviderConfig.API + ProviderModelConfig.API), stream dispatch (matches one of the Stream<API> handlers).
upstream: types.ts:17 (Api), types.ts:7-15 (KnownApi)
const ( APIOpenAICompletions API = "openai-completions" APIMistralConversations API = "mistral-conversations" APIOpenAIResponses API = "openai-responses" APIAzureOpenAIResponses API = "azure-openai-responses" APIOpenAICodexResponses API = "openai-codex-responses" APIAnthropicMessages API = "anthropic-messages" APIBedrockConverseStream API = "bedrock-converse-stream" APIGoogleGenerativeAI API = "google-generative-ai" APIGoogleVertex API = "google-vertex" APIPiMessages API = "pi-messages" )
KnownAPIs enumerates the API values defined by upstream as of UpstreamVersion. Mirrors upstream `KnownApi` union (.upstream/current/packages/ai/src/types.ts:7-15).
Each constant value is the wire-format string consumed by provider dispatch. Provider extensions or generated catalog entries may carry API values not listed here (the underlying type is plain string) - this is forward-compat for new upstream additions.
upstream: types.ts:7-15
func RegisteredAPIs ¶
func RegisteredAPIs() []API
RegisteredAPIs returns the set of built-in API identifiers.
type APIKeyAuth ¶
type APIKeyAuth struct {
Name string
Check func(ctx context.Context, input APIKeyAuthInput) (*AuthCheck, error)
Resolve func(ctx context.Context, input APIKeyAuthInput) (*AuthResult, error)
}
APIKeyAuth resolves stored-key and ambient API-key auth. Check is an optional side-effect-free availability check; without it availability is checked by resolving. Resolve returns nil when auth is not configured.
func EnvAPIKeyAuth ¶
func EnvAPIKeyAuth(name string, envVars ...string) *APIKeyAuth
EnvAPIKeyAuth is standard API-key auth: a stored credential key wins, otherwise the first set environment variable resolves. Mirrors upstream envApiKeyAuth.
type APIKeyAuthInput ¶
type APIKeyAuthInput struct {
Ctx AuthContext
Credential *Credential
}
APIKeyAuthInput is the input to APIKeyAuth.Check and APIKeyAuth.Resolve. Credential is the stored api_key credential, if any.
type APIKeyProviderInfo ¶
APIKeyProviderInfo is a static description of a provider that authenticates with a raw API key (as opposed to OAuth/subscription flow).
Single source of truth for the API-key provider catalog. interactive.go's /login → "Use an API key" selector and any other surface that needs the full list MUST iterate APIKeyProviders(), not maintain a parallel slice.
func APIKeyProviders ¶
func APIKeyProviders() []APIKeyProviderInfo
APIKeyProviders returns the canonical API-key provider catalog. Callers must not mutate the returned slice; copy if you need to.
type AnthropicAllowedFallbackModel ¶
type AnthropicAllowedFallbackModel struct {
Provider string `json:"provider"`
Model string `json:"model"`
Cost ModelCost `json:"cost"`
}
AnthropicAllowedFallbackModel describes a server-side fallback accepted by Anthropic.
type AnthropicConfig ¶
type AnthropicConfig struct {
// APIKey is the Anthropic API key, sent as X-Api-Key. A subscription
// (sk-ant-oat) token is sent as an Authorization bearer token with the
// Claude Code identity instead. When APIKey is empty, the anthropic
// provider sends ANTHROPIC_AUTH_TOKEN as an Authorization bearer header.
APIKey string
// Model is the model name sent in the request (e.g. "claude-sonnet-4-20250514").
Model string
// ProviderID is the provider label (default: "anthropic").
ProviderID string
// BaseURL is the API base (default: https://api.anthropic.com).
BaseURL string
// ExtraHeaders are added to every request.
ExtraHeaders map[string]string
// Env holds provider-scoped environment overrides that take precedence over
// the process environment when resolving provider configuration such as
// PI_CACHE_RETENTION. Mirrors the upstream StreamOptions.env threaded into
// the provider.
Env ProviderEnv
// Compat controls Anthropic-API-specific capability quirks for proxied
// Anthropic-compatible providers.
Compat *AnthropicMessagesCompat
// GetAPIKey dynamically obtains the auth token. Takes precedence over
// APIKey. Called once per Stream() invocation. Used by GitHub Copilot
// to auto-refresh the bearer token.
GetAPIKey func(ctx context.Context) (string, error)
// GetBaseURL dynamically resolves the base URL. Takes precedence over
// BaseURL. Used by GitHub Copilot to extract proxy-ep from the
// refreshed token.
GetBaseURL func(ctx context.Context) (string, error)
// DynamicHeaders returns per-request headers (e.g. Copilot X-Initiator).
// They apply only with UseBearerAuth, the Copilot client.
DynamicHeaders func(transcript TranscriptContext, opts StreamOptions) map[string]string
// UseBearerAuth selects the Copilot client: the token is sent as
// Authorization: Bearer instead of X-Api-Key, with DynamicHeaders and
// without the Claude Code identity.
UseBearerAuth bool
}
AnthropicConfig configures the Anthropic Messages API provider.
type AnthropicMessagesCompat ¶
type AnthropicMessagesCompat = OpenAICompat
type AnthropicOAuthProvider ¶
type AnthropicOAuthProvider struct{}
AnthropicOAuthProvider implements OAuthProviderInterface for Anthropic.
func (AnthropicOAuthProvider) GetAPIKey ¶
func (AnthropicOAuthProvider) GetAPIKey(c OAuthCredentials) string
func (AnthropicOAuthProvider) ID ¶
func (AnthropicOAuthProvider) ID() string
func (AnthropicOAuthProvider) IsSubscription ¶
func (AnthropicOAuthProvider) IsSubscription() bool
func (AnthropicOAuthProvider) Login ¶
func (a AnthropicOAuthProvider) Login(callbacks OAuthLoginCallbacks) (OAuthCredentials, error)
func (AnthropicOAuthProvider) LoginContext ¶
func (AnthropicOAuthProvider) LoginContext(ctx context.Context, callbacks OAuthLoginCallbacks) (OAuthCredentials, error)
func (AnthropicOAuthProvider) Name ¶
func (AnthropicOAuthProvider) Name() string
func (AnthropicOAuthProvider) RefreshToken ¶
func (a AnthropicOAuthProvider) RefreshToken(creds OAuthCredentials) (OAuthCredentials, error)
func (AnthropicOAuthProvider) RefreshTokenContext ¶
func (AnthropicOAuthProvider) RefreshTokenContext(ctx context.Context, creds OAuthCredentials) (OAuthCredentials, error)
func (AnthropicOAuthProvider) UsesCallbackServer ¶
func (AnthropicOAuthProvider) UsesCallbackServer() bool
type AssistantContentBlock ¶
type AssistantContentBlock interface {
ContentBlock
// contains filtered or unexported methods
}
AssistantContentBlock is valid inside an assistant message.
type AssistantEventType ¶
type AssistantEventType string
AssistantEventType enumerates all streaming event types.
const ( EventStart AssistantEventType = "start" EventTextStart AssistantEventType = "text_start" EventTextDelta AssistantEventType = "text_delta" EventTextEnd AssistantEventType = "text_end" EventThinkingStart AssistantEventType = "thinking_start" EventThinkingDelta AssistantEventType = "thinking_delta" EventThinkingEnd AssistantEventType = "thinking_end" EventToolCallStart AssistantEventType = "toolcall_start" EventToolCallDelta AssistantEventType = "toolcall_delta" EventToolCallEnd AssistantEventType = "toolcall_end" EventDone AssistantEventType = "done" EventError AssistantEventType = "error" )
type AssistantImages ¶
type AssistantImages struct {
API ImagesAPI
Provider ImagesProvider
Model string
Output []ContentBlock
ResponseID string
Usage *Usage
StopReason ImagesStopReason
ErrorMessage string
Timestamp int64
}
AssistantImages is the final result of an image-generation request.
func GenerateImages ¶
func GenerateImages(ctx context.Context, model ImagesModel, imagesCtx ImagesContext, options ProviderImagesOptions) (AssistantImages, error)
GenerateImages dispatches an image-generation request to the model's API provider. It mirrors upstream generateImages(), returning an error only when no provider is registered for the model API.
func GenerateImagesOpenRouter ¶
func GenerateImagesOpenRouter(ctx context.Context, model ImagesModel, imagesCtx ImagesContext, options ProviderImagesOptions) AssistantImages
GenerateImagesOpenRouter implements upstream providers/images/openrouter.ts.
type AssistantMessage ¶
type AssistantMessage struct {
Content []AssistantContentBlock `json:"content"`
API API `json:"api"`
Provider string `json:"provider"`
Model string `json:"model"`
ResponseModel string `json:"responseModel,omitempty"`
ResponseID string `json:"responseId,omitempty"`
ProviderThinkingLevel string `json:"providerThinkingLevel,omitempty"`
Diagnostics []AssistantMessageDiagnostic `json:"diagnostics,omitempty"`
Usage Usage `json:"usage"`
StopReason StopReason `json:"stopReason"`
Deferred *DeferredHandle `json:"deferred,omitempty"`
ErrorMessage string `json:"errorMessage,omitempty"`
RawStopReason string `json:"rawStopReason,omitempty"`
EndTurn *bool `json:"endTurn,omitempty"`
Timestamp int64 `json:"timestamp"`
}
AssistantMessage is the authoritative complete or partial model response.
func ReduceAssistantMessageFrames ¶
func ReduceAssistantMessageFrames(frames []AssistantMessageFrame) (*AssistantMessage, error)
ReduceAssistantMessageFrames replays compact frames without mutating them. It returns a nil message when the frames contain no start frame.
func RetryAssistantCall ¶
func RetryAssistantCall(ctx context.Context, produce func() (AssistantMessage, error), policy *RetryPolicy, callbacks RetryCallbacks) (AssistantMessage, error)
RetryAssistantCall runs one assistant-producing call with bounded retry on transient errors. Successful and aborted responses return immediately; a non-retryable error or an exhausted budget returns the final error message. Cancellation during a backoff sleep returns the failed response normalized to stopReason "aborted" without its error message. A nil or disabled policy returns the first response unchanged.
func (AssistantMessage) MarshalJSON ¶
func (message AssistantMessage) MarshalJSON() ([]byte, error)
func (*AssistantMessage) UnmarshalJSON ¶
func (message *AssistantMessage) UnmarshalJSON(data []byte) error
UnmarshalJSON decodes the upstream AssistantMessage wire shape, including its closed content-block union.
type AssistantMessageDiagnostic ¶
type AssistantMessageDiagnostic struct {
Type string `json:"type"`
Timestamp int64 `json:"timestamp"`
Error *DiagnosticErrorInfo `json:"error,omitempty"`
Details map[string]any `json:"details,omitempty"`
}
AssistantMessageDiagnostic is a provider/runtime diagnostic attached to an assistant message when a recoverable failure or transport fallback occurs.
type AssistantMessageEvent ¶
type AssistantMessageEvent interface {
EventType() AssistantEventType
// contains filtered or unexported methods
}
AssistantMessageEvent is Pi's closed stream-event union. External providers can construct exported variants but cannot define additional variants.
type AssistantMessageEventStream ¶
type AssistantMessageEventStream struct {
// contains filtered or unexported fields
}
AssistantMessageEventStream is an ordered in-process event stream. Result completes independently of event iteration; unread events remain available until consumed. Subprocess transports impose their own bounded backpressure.
func NewAssistantMessageEventStream ¶
func NewAssistantMessageEventStream() *AssistantMessageEventStream
NewAssistantMessageEventStream creates an open stream.
func (*AssistantMessageEventStream) Events ¶
func (s *AssistantMessageEventStream) Events(ctx context.Context) iter.Seq[AssistantMessageEvent]
Events returns a single-pass sequence over the stream's shared FIFO. Multiple iterators divide events in waiter-registration order, matching Pi's queue. Canceling ctx removes an outstanding waiter without a delivery goroutine.
func (*AssistantMessageEventStream) Push ¶
func (s *AssistantMessageEventStream) Push(event AssistantMessageEvent) error
Push appends an event. Pushes after termination are ignored, matching Pi's EventStream. Invalid pre-terminal event sequences return an invariant error.
func (*AssistantMessageEventStream) Result ¶
func (s *AssistantMessageEventStream) Result() *AssistantMessage
Result waits for termination and returns the exact pointer carried by the terminal DoneEvent or ErrorEvent.
type AssistantMessageFrame ¶
type AssistantMessageFrame interface {
FrameType() AssistantMessageFrameType
// contains filtered or unexported methods
}
AssistantMessageFrame is compact, replayable assistant-message progress. Terminal settlement is intentionally excluded and must be persisted separately. The union is closed like AssistantMessageEvent.
func UnmarshalAssistantMessageFrame ¶
func UnmarshalAssistantMessageFrame(data []byte) (AssistantMessageFrame, error)
UnmarshalAssistantMessageFrame decodes one frame by its `type` discriminator.
type AssistantMessageFrameEncoder ¶
type AssistantMessageFrameEncoder struct {
// contains filtered or unexported fields
}
AssistantMessageFrameEncoder encodes one assistant stream. Event partials may be a shared live accumulator; the encoder uses per-block offsets to avoid replaying deltas already visible when an older queued event is consumed. The zero value is ready to use.
func (*AssistantMessageFrameEncoder) Encode ¶
func (encoder *AssistantMessageFrameEncoder) Encode(event AssistantMessageEvent) (AssistantMessageFrame, error)
Encode converts one stream event into a frame. It returns a nil frame when the event adds nothing replayable (terminal events and covered deltas).
type AssistantMessageFrameType ¶
type AssistantMessageFrameType string
AssistantMessageFrameType discriminates the compact frame union.
const ( FrameTypeStart AssistantMessageFrameType = "start" FrameTypeTextStart AssistantMessageFrameType = "text_start" FrameTypeTextDelta AssistantMessageFrameType = "text_delta" FrameTypeTextEnd AssistantMessageFrameType = "text_end" FrameTypeThinkingStart AssistantMessageFrameType = "thinking_start" FrameTypeThinkingDelta AssistantMessageFrameType = "thinking_delta" FrameTypeThinkingEnd AssistantMessageFrameType = "thinking_end" FrameTypeToolCallStart AssistantMessageFrameType = "toolcall_start" FrameTypeToolCallCheckpoint AssistantMessageFrameType = "toolcall_checkpoint" FrameTypeToolCallDelta AssistantMessageFrameType = "toolcall_delta" FrameTypeToolCallEnd AssistantMessageFrameType = "toolcall_end" )
type AuthCheck ¶
type AuthCheck struct {
Source string
Type CredentialType
}
AuthCheck reports that auth is configured without resolving it.
func CheckProviderAuth ¶
func CheckProviderAuth(ctx context.Context, providerID string, auth ProviderAuth, credentials CredentialStore, authContext AuthContext) (*AuthCheck, error)
CheckProviderAuth reports whether a provider's auth is configured without refreshing OAuth or running request-time work where a check exists. Mirrors upstream Models.checkAuth for a known provider.
type AuthContext ¶
AuthContext is environment access for auth resolution. Env reports a value only when it is set and not blank.
func DefaultProviderAuthContext ¶
func DefaultProviderAuthContext() AuthContext
DefaultProviderAuthContext reads process environment variables and checks files on disk. Mirrors upstream defaultProviderAuthContext.
type AuthResolutionOverrides ¶
type AuthResolutionOverrides struct {
APIKey *string
Env map[string]string
// MinOAuthValidityMs requires this much remaining OAuth-token validity;
// nil keeps the default five-minute refresh window without enforcing it.
MinOAuthValidityMs *float64
}
AuthResolutionOverrides mirrors upstream AuthResolutionOverrides.
type AuthResult ¶
type AuthResult struct {
Auth ModelAuth
// Env holds provider-scoped environment/config values resolved from the
// credential and ambient context.
Env map[string]string
// Source is a status label such as "OPENAI_API_KEY" or "OAuth".
Source string
}
AuthResult is the result of resolving auth for a provider or model.
func ResolveProviderAuth ¶
func ResolveProviderAuth(ctx context.Context, providerID string, auth ProviderAuth, credentials CredentialStore, authContext AuthContext, overrides AuthResolutionOverrides) (*AuthResult, error)
ResolveProviderAuth resolves request auth for a provider. A stored credential owns the provider: ambient environment is consulted only when nothing is stored, with no fallback after a failed refresh or for a credential type without a matching handler. Mirrors upstream resolveProviderAuth.
type AuthSource ¶
type AuthSource string
AuthSource reports where auth would be sourced from. Mirrors upstream AuthStatus.source union.
const ( AuthSourceStored AuthSource = "stored" AuthSourceRuntime AuthSource = "runtime" AuthSourceEnvironment AuthSource = "environment" AuthSourceFallback AuthSource = "fallback" AuthSourceModelsJSONKey AuthSource = "models_json_key" AuthSourceModelsJSONCommand AuthSource = "models_json_command" )
type AuthStatus ¶
type AuthStatus struct {
Configured bool
Source AuthSource
Label string
}
AuthStatus reports whether auth is configured and where pig would source it from, without exposing secret values.
type AuthStorage ¶
type AuthStorage struct {
// contains filtered or unexported fields
}
AuthStorage is the persistent credential store at <agentDir>/auth.json.
func NewAuthStorage ¶
func NewAuthStorage(path string) (*AuthStorage, error)
NewAuthStorage opens (or creates) the credential store at the given path. The parent directory is created with mode 0700 if it does not exist.
func (*AuthStorage) Delete ¶
func (a *AuthStorage) Delete(provider string) error
Delete removes the credential for a provider (no-op if absent).
func (*AuthStorage) Get ¶
func (a *AuthStorage) Get(provider string) (Credential, bool, error)
Get returns the credential for a provider, if present.
For API-key credentials the Key field is passed through configvalue.Resolve so that auth.json values like "$OPENAI_API_KEY" (explicit env reference) or "!op read op://Personal/openai/key" (shell command) become the runtime value. Bare names are literals (v0.78.1). Mirrors upstream auth-storage.ts which calls resolveConfigValue on the API key on the read path. The on-disk value is left untouched.
func (*AuthStorage) GetAuthStatus ¶
func (a *AuthStorage) GetAuthStatus(provider string) AuthStatus
GetAuthStatus reports whether auth is configured for provider without exposing credential values or refreshing OAuth tokens.
func (*AuthStorage) GetProviderEnv ¶
func (a *AuthStorage) GetProviderEnv(provider string) (map[string]string, error)
GetProviderEnv returns a copy of the provider-scoped environment overrides for an API-key credential, or nil when none are set. Mirrors upstream auth-storage.ts getProviderEnv.
func (*AuthStorage) GetRaw ¶
func (a *AuthStorage) GetRaw(provider string) (Credential, bool, error)
GetRaw returns the credential without applying configvalue.Resolve to the Key field. Use this when you need the on-disk value (e.g. for rewriting auth.json or for OAuth flows where Refresh/Access tokens must round-trip verbatim).
func (*AuthStorage) List ¶
func (a *AuthStorage) List(ctx context.Context) ([]CredentialInfo, error)
List implements CredentialStore without resolving configured key values.
func (*AuthStorage) Load ¶
func (a *AuthStorage) Load() (map[string]Credential, error)
Load reads all credentials. Returns an empty map if the file does not exist.
func (*AuthStorage) Modify ¶
func (a *AuthStorage) Modify(ctx context.Context, providerID string, fn func(current *Credential) (*Credential, error)) (*Credential, error)
Modify implements CredentialStore under the auth.json file lock.
func (*AuthStorage) Path ¶
func (a *AuthStorage) Path() string
Path returns the auth.json file path.
func (*AuthStorage) Read ¶
func (a *AuthStorage) Read(ctx context.Context, providerID string) (*Credential, error)
Read implements CredentialStore.
func (*AuthStorage) Set ¶
func (a *AuthStorage) Set(provider string, cred Credential) error
Set writes (or replaces) the credential for a provider. Acquires an exclusive file lock during the read-modify-write cycle so concurrent pi instances refreshing the same OAuth token don't clobber each other.
func (*AuthStorage) Update ¶
func (a *AuthStorage) Update(provider string, mutate func(cur Credential, exists bool) (Credential, error)) error
Update mutates the credential for a provider under the lock. The mutator receives the current credential (zero value if absent) and the boolean indicates whether it existed. Returning an error aborts the write.
type AzureOpenAIResponsesConfig ¶
type AzureOpenAIResponsesConfig struct {
APIKey string
Model string
ProviderID string
BaseURL string
ExtraHeaders map[string]string
SamplingParams map[string]any
AzureAPIVersion string
AzureResourceName string
AzureDeploymentName string
Env ProviderEnv
Compat *OpenAIResponsesCompat
}
AzureOpenAIResponsesConfig mirrors the upstream Azure wrapper provider while delegating transport/parsing to the shared OpenAI Responses implementation.
type BedrockProvider ¶
type BedrockProvider struct {
// contains filtered or unexported fields
}
BedrockProvider implements the Provider interface backed by AWS Bedrock's ConverseStream API.
func NewBedrockProvider ¶
func NewBedrockProvider(model, baseURL string) *BedrockProvider
NewBedrockProvider constructs a Bedrock provider for the given model id. The model id is forwarded verbatim to the ConverseStream call, supporting both base model ids (e.g. "anthropic.claude-3-5-haiku-v1") and inference-profile ARNs.
func NewBedrockProviderWithName ¶
func NewBedrockProviderWithName(model, modelName, baseURL string) *BedrockProvider
NewBedrockProviderWithName constructs a Bedrock provider with optional display/model name metadata. The additional name is used only for parity with upstream Bedrock capability detection on application inference profiles whose ARN does not reveal the underlying Claude model family.
func (*BedrockProvider) Close ¶
func (p *BedrockProvider) Close() error
Close releases any persistent resources held by the provider. The bedrockruntime client maintains no goroutines or sockets that outlive a call, so this is a no-op.
func (*BedrockProvider) ID ¶
func (p *BedrockProvider) ID() string
ID returns the provider identifier matching upstream.
func (*BedrockProvider) Stream ¶
func (p *BedrockProvider) Stream(ctx context.Context, transcript TranscriptContext, opts StreamOptions) (*AssistantMessageEventStream, error)
Stream runs ConverseStream and translates its event stream into the pig AssistantMessageEvent channel. Mirrors upstream streamBedrock.
type CacheRetention ¶
type CacheRetention string
CacheRetention selects the requested prompt-cache lifetime. Empty means the option is unset so the provider can apply its documented default.
const ( CacheRetentionNone CacheRetention = "none" CacheRetentionShort CacheRetention = "short" CacheRetentionLong CacheRetention = "long" )
type CodexOAuthProvider ¶
type CodexOAuthProvider struct{}
CodexOAuthProvider implements OAuthProviderInterface for OpenAI Codex.
func (CodexOAuthProvider) GetAPIKey ¶
func (CodexOAuthProvider) GetAPIKey(c OAuthCredentials) string
func (CodexOAuthProvider) ID ¶
func (CodexOAuthProvider) ID() string
func (CodexOAuthProvider) IsSubscription ¶
func (CodexOAuthProvider) IsSubscription() bool
func (CodexOAuthProvider) Login ¶
func (c CodexOAuthProvider) Login(callbacks OAuthLoginCallbacks) (OAuthCredentials, error)
Login presents the browser/device-code method selection, then runs the chosen flow. Mirrors upstream openaiCodexOAuthProvider.login (openai-codex.ts:568-595).
func (CodexOAuthProvider) LoginContext ¶
func (c CodexOAuthProvider) LoginContext(ctx context.Context, callbacks OAuthLoginCallbacks) (OAuthCredentials, error)
LoginContext presents the browser/device-code method selection and carries ctx through the selected flow.
func (CodexOAuthProvider) Name ¶
func (CodexOAuthProvider) Name() string
func (CodexOAuthProvider) RefreshToken ¶
func (c CodexOAuthProvider) RefreshToken(creds OAuthCredentials) (OAuthCredentials, error)
func (CodexOAuthProvider) RefreshTokenContext ¶
func (CodexOAuthProvider) RefreshTokenContext(ctx context.Context, creds OAuthCredentials) (OAuthCredentials, error)
func (CodexOAuthProvider) UsesCallbackServer ¶
func (CodexOAuthProvider) UsesCallbackServer() bool
type ConstrainedSamplingConfig ¶
type ConstrainedSamplingConfig struct {
Type string `json:"type"` // "json_schema" | "grammar"
Strict string `json:"strict,omitempty"` // json_schema: "prefer" | "require"
Variants map[GrammarFormat]string `json:"variants,omitempty"` // grammar: format → definition
}
ConstrainedSamplingConfig is the optional provider-side constrained sampling config for a tool. Type is "json_schema" (JSON-schema strict sampling) or "grammar" (Lark/regex grammar variants). Mirrors upstream ConstrainedSamplingConfig; upstream's `false` maps to a nil pointer.
type ContentBlock ¶
type ContentBlock interface {
// contains filtered or unexported methods
}
ContentBlock is the closed union of provider-facing content types.
func UnmarshalContentBlock ¶
func UnmarshalContentBlock(data []byte) (ContentBlock, error)
UnmarshalContentBlock decodes a single content-block JSON value into the appropriate concrete type. Unknown `type` values are accepted as TextContent with the JSON re-encoded as the text payload: this preserves data we don't recognise rather than silently dropping it.
type ContentBlocks ¶
type ContentBlocks []ContentBlock
ContentBlocks is a slice alias that knows how to decode the discriminated-union JSON form.
Use this when persisting/loading messages from disk:
var msg struct {
Role string `json:"role"`
Content ContentBlocks `json:"content"`
}
When you only need the slice as `[]ContentBlock` (the historical shape used by streams + tool execution), call `.Blocks()`.
func (ContentBlocks) Blocks ¶
func (cb ContentBlocks) Blocks() []ContentBlock
func (ContentBlocks) MarshalJSON ¶
func (cb ContentBlocks) MarshalJSON() ([]byte, error)
MarshalJSON delegates to the default slice encoder.
func (*ContentBlocks) UnmarshalJSON ¶
func (cb *ContentBlocks) UnmarshalJSON(data []byte) error
UnmarshalJSON sniffs each element's `type` field and decodes into the matching concrete type.
type Context ¶
type Context struct {
SystemPrompt string
Messages []Message
Tools []ToolSchema
}
Context is the public request shape accepted before provider normalization.
type ContextUsageEstimate ¶
type ContextUsageEstimate struct {
Tokens int
UsageTokens int
TrailingTokens int
LastUsageIndex int
}
ContextUsageEstimate is an estimated context size. LastUsageIndex is the index of the message whose usage the estimate starts from, or -1 for upstream's null.
func EstimateContextTokens ¶
func EstimateContextTokens(messages []Message) ContextUsageEstimate
EstimateContextTokens estimates a transcript's context size from the last applicable assistant usage plus the messages after it, or from every message when no usage applies.
type CopilotLoginCallbacks ¶
type CopilotLoginCallbacks struct {
// OnPrompt is invoked once at the start to ask for an enterprise domain.
// Return "" to use github.com.
OnPrompt func(ctx context.Context) (string, error)
// OnAuth is invoked once with the verification URL and user code that
// the user must visit and enter.
OnAuth func(verificationURL, userCode string)
// OnProgress is invoked with status messages (e.g. "Enabling models...").
OnProgress func(msg string)
}
CopilotLoginCallbacks is the user-facing surface for an interactive login. All callbacks are optional except OnAuth (we have to surface the user code somehow) and OnPrompt (only called if the caller wants to support enterprise domain entry: pass a no-op returning "" for vanilla github.com).
type CopilotProviderConfig ¶
type CopilotProviderConfig struct {
// Auth is the credential store; the provider will read and refresh
// the github-copilot entry as needed.
Auth *AuthStorage
// Model is the Copilot model id (e.g. "gpt-4o", "claude-sonnet-4").
Model string
// API selects the wire protocol. When set to APIOpenAIResponses (or
// "openai-responses"), the provider uses the Responses API instead of
// the Chat Completions API. This matters for models like gpt-5.4 that
// require the Responses endpoint when tools + reasoning are combined.
// Mirrors upstream: the model's `api` field in models.generated.ts
// determines which endpoint to hit: "openai-completions" vs
// "openai-responses".
API API
// Reasoning indicates the selected Copilot model supports reasoning.
// Required for the Responses API to include reasoning.effort/summary and
// stream thinking deltas.
Reasoning bool
// EnvToken is the env-resolved API key (COPILOT_GITHUB_TOKEN, then
// GH_TOKEN/GITHUB_TOKEN). When auth.json has no github-copilot OAuth
// credential, it is used directly as the bearer, mirroring upstream
// auth-storage.getApiKey step 4 (the env fallback returns getEnvApiKey
// verbatim). The base URL is derived from the token's proxy-ep claim.
EnvToken string
// RuntimeToken returns a non-persistent runtime key (--api-key). When it
// reports one, it is the bearer ahead of the stored credential and
// EnvToken, as upstream's RuntimeCredentials overlay masks auth.json.
RuntimeToken func() (string, bool)
}
CopilotProviderConfig configures a github-copilot provider.
type CostTier ¶
type CostTier struct {
InputTokensAbove int `json:"inputTokensAbove"`
InputCostPer1M float64 `json:"input"`
OutputCostPer1M float64 `json:"output"`
CacheReadCostPer1M float64 `json:"cacheRead"`
CacheWriteCostPer1M float64 `json:"cacheWrite"`
}
CostTier overrides the base per-1M rates for requests whose total input usage (input+cacheRead+cacheWrite) exceeds InputTokensAbove. Mirrors upstream ModelCostTier.
type Credential ¶
type Credential struct {
Type CredentialType `json:"type"`
// API-key variant. Field is "key" (matches upstream); we keep an
// alias "apiKey" on read for backwards compatibility with auth.json
// files written by older pig builds.
Key string `json:"key,omitempty"`
// Env holds provider-scoped environment overrides for an API-key
// credential. Values take precedence over the process environment when
// resolving this credential's own `$VAR` references and when the provider
// reads configuration env. Mirrors upstream auth-storage.ts
// ApiKeyCredential.env.
Env map[string]string `json:"env,omitempty"`
// OAuth variant (used by github-copilot, anthropic, etc.)
Refresh string `json:"refresh,omitempty"`
Access string `json:"access,omitempty"`
Expires int64 `json:"expires,omitempty"` // ms since epoch
ProjectID string `json:"projectId,omitempty"`
EnterpriseDomain string `json:"enterpriseUrl,omitempty"`
// Scope is the granted OAuth scope some flows (Radius) return and persist.
Scope string `json:"scope,omitempty"`
// GatewayConfig is the Radius gateway catalog that pre-ModelsStore Radius
// builds cached on the credential. It is read once to import that catalog.
GatewayConfig json.RawMessage `json:"gatewayConfig,omitempty"`
}
Credential is the on-disk shape for one provider's credentials. We use a flat struct that covers both the api-key and oauth variants - fields not relevant to the type are simply zero-valued.
JSON field names match upstream's typed surface so files are interchangeable with `pi`'s auth.json.
func LoginGitHubCopilot ¶
func LoginGitHubCopilot(ctx context.Context, cb CopilotLoginCallbacks) (Credential, error)
LoginGitHubCopilot runs the OAuth device code flow against github.com (or an enterprise domain) and returns refreshed Copilot credentials. The returned Credential has Type=CredentialOAuth and is ready to be persisted via AuthStorage.Set("github-copilot", cred).
type CredentialInfo ¶
type CredentialInfo struct {
ProviderID string
Type CredentialType
}
CredentialInfo is non-secret credential metadata for account/status enumeration. Mirrors upstream CredentialInfo.
type CredentialStore ¶
type CredentialStore interface {
// Read returns the stored credential, possibly expired, or nil when none
// is stored. API-key values are resolved as configuration values.
Read(ctx context.Context, providerID string) (*Credential, error)
// List returns stored credential metadata without resolving values.
List(ctx context.Context) ([]CredentialInfo, error)
// Modify runs fn with the current raw credential under the store's
// lock. A nil result leaves the entry unchanged. It returns the
// post-write credential.
Modify(ctx context.Context, providerID string, fn func(current *Credential) (*Credential, error)) (*Credential, error)
}
CredentialStore is app-owned credential storage keyed by provider id. Modify is the only write path used by request-auth resolution, so every OAuth refresh is a serialized read-modify-write. Mirrors upstream CredentialStore; delete is served by AuthStorage.Delete for logout.
type CredentialType ¶
type CredentialType string
CredentialType is the discriminator stored as `"type"` in auth.json.
Values match upstream pi `dist/core/auth-storage.d.ts`:
- "api_key" for raw API keys (field: "key")
- "oauth" for OAuth refresh/access tokens
Files written by pig must round-trip through upstream pi and vice versa. Earlier PiG builds wrote "type":"api" / "apiKey", which broke parity. The Load() path migrates the old shape forward in place on first read.
const ( CredentialAPIKey CredentialType = "api_key" CredentialOAuth CredentialType = "oauth" )
type DeferredHandle ¶
type DeferredHandle struct {
Provider string `json:"provider"`
ModelID string `json:"modelId"`
API API `json:"api"`
ID string `json:"id"`
ExpiresAt *int64 `json:"expiresAt,omitempty"`
PollAfterMS *int64 `json:"pollAfterMs,omitempty"`
Data any `json:"data,omitempty"`
}
DeferredHandle identifies a provider-side deferred response and the data required to retrieve it later.
type DeviceCodePollOptions ¶
type DeviceCodePollOptions[T any] struct { IntervalSeconds *float64 ExpiresInSeconds *float64 WaitBeforeFirstPoll bool Poll func() (DeviceCodePollResult[T], error) }
DeviceCodePollOptions configures PollOAuthDeviceCodeFlow. A nil IntervalSeconds defaults to 5s (RFC 8628 §3.2); a nil ExpiresInSeconds means no deadline. WaitBeforeFirstPoll sleeps one interval before the first poll. The Go API carries the upstream AbortSignal through ctx.
type DeviceCodePollResult ¶
type DeviceCodePollResult[T any] struct { Status DeviceCodePollStatus Value T Message string // IntervalSeconds is the server-provided polling interval on a slow_down // result. Nil (or a non-positive value) applies the RFC 8628 +5s rule. IntervalSeconds *float64 }
DeviceCodePollResult is one poll attempt's result. Mirrors upstream OAuthDeviceCodePollResult.
type DeviceCodePollStatus ¶
type DeviceCodePollStatus int
DeviceCodePollStatus is the outcome of one device-code poll attempt.
const ( // DevicePollPending: keep polling. DevicePollPending DeviceCodePollStatus = iota // DevicePollSlowDown: keep polling but widen the interval (RFC 8628 §3.5). DevicePollSlowDown // DevicePollFailed: stop with Message as the error. DevicePollFailed // DevicePollComplete: stop and return Value. DevicePollComplete )
type DiagnosticErrorInfo ¶
type DiagnosticErrorInfo struct {
Name string `json:"name,omitempty"`
Message string `json:"message"`
Stack string `json:"stack,omitempty"`
Code any `json:"code,omitempty"`
}
DiagnosticErrorInfo is a redacted, serializable error summary attached to assistant diagnostics.
type DoneEvent ¶
type DoneEvent struct {
Reason StopReason `json:"reason"`
Message *AssistantMessage `json:"message"`
}
func (DoneEvent) EventType ¶
func (DoneEvent) EventType() AssistantEventType
func (DoneEvent) MarshalJSON ¶
type ErrorEvent ¶
type ErrorEvent struct {
Reason StopReason `json:"reason"`
Error *AssistantMessage `json:"error"`
}
func (ErrorEvent) EventType ¶
func (ErrorEvent) EventType() AssistantEventType
func (ErrorEvent) MarshalJSON ¶
func (event ErrorEvent) MarshalJSON() ([]byte, error)
type FauxConfig ¶
type FauxConfig struct {
ProviderID string
Model string
TokensPerSecond int // 0 = instant
MinTokenSize int
MaxTokenSize int
}
FauxConfig configures the faux provider.
type FauxContentBlock ¶
type FauxContentBlock struct {
Type string `json:"type"` // "text" | "thinking" | "toolCall"
Text string `json:"text,omitempty"` // for type "text"
Thinking string `json:"thinking,omitempty"` // for type "thinking"
ID string `json:"id,omitempty"` // for type "toolCall"
Name string `json:"name,omitempty"` // for type "toolCall"
Arguments map[string]any `json:"arguments,omitempty"` // for type "toolCall"
}
FauxContentBlock is a union of content blocks for faux responses.
func FauxThinking ¶
func FauxThinking(thinking string) FauxContentBlock
FauxThinking creates a thinking content block.
func FauxToolCall ¶
func FauxToolCall(name string, args map[string]any, id string) FauxContentBlock
FauxToolCall creates a tool call content block.
type FauxResponse ¶
type FauxResponse struct {
Content []FauxContentBlock
StopReason string // "stop", "error", "length", "toolUse"
ErrorMessage string
}
FauxResponse defines a canned response for the faux provider.
type FauxResponseFactory ¶
type FauxResponseFactory func(context TranscriptContext, opts StreamOptions, callCount int) FauxResponse
FauxResponseFactory creates a response dynamically based on context.
type FauxResponseStep ¶
type FauxResponseStep struct {
Static *FauxResponse
Factory FauxResponseFactory
}
FauxResponseStep is either a static FauxResponse or a FauxResponseFactory.
func FauxFactoryStep ¶
func FauxFactoryStep(fn FauxResponseFactory) FauxResponseStep
FauxFactoryStep creates a step from a factory function.
func FauxStaticStep ¶
func FauxStaticStep(resp FauxResponse) FauxResponseStep
FauxStaticStep creates a step from a static response.
type FileModelsStore ¶
type FileModelsStore struct {
// contains filtered or unexported fields
}
FileModelsStore mirrors coding-agent core/models-store.ts FileModelsStore: locked JSON storage for dynamically refreshed provider catalogs, keyed by provider id, at <agentDir>/models-store.json by default.
func NewFileModelsStore ¶
func NewFileModelsStore(path string) *FileModelsStore
NewFileModelsStore opens the store at path.
func (*FileModelsStore) Delete ¶
func (s *FileModelsStore) Delete(ctx context.Context, providerID string) error
Delete removes the provider's stored catalog. Like upstream it rewrites the file even when the provider has no entry.
func (*FileModelsStore) Path ¶
func (s *FileModelsStore) Path() string
Path returns the store file path.
func (*FileModelsStore) Read ¶
func (s *FileModelsStore) Read(ctx context.Context, providerID string) (*ModelsStoreEntry, error)
Read returns the provider's stored catalog, or nil when none is stored.
func (*FileModelsStore) Write ¶
func (s *FileModelsStore) Write(ctx context.Context, providerID string, entry ModelsStoreEntry) error
Write replaces the provider's stored catalog.
type GeneratedModel ¶
type GeneratedModel struct {
ID string
Provider string
DisplayName string
API API
BaseURL string
Headers map[string]string
Compat *ModelCompat
ThinkingLevelMap map[ThinkingLevel]*string
SamplingParams map[string]any
PromptCache ModelPromptCache
InputLimits *ModelInputLimits
ContextWindow int
MaxOutputTokens int
InputCostPerMTokens float64
OutputCostPerMTokens float64
CacheReadCost float64
CacheWriteCost float64
Tiers []CostTier
Reasoning bool
Capabilities []string
Enabled *bool
Lab string
Providers []ModelCatalogProvider
}
GeneratedModel is a static catalog entry for one model. Lives in generated code so the registry init is just a slice copy. Field shape mirrors upstream pi-ai's `Model<api>` discriminated union reduced to the fields the pig runtime actually consumes.
func ListModels ¶
func ListModels(provider string) []GeneratedModel
ListModels returns a copy of the catalog filtered by an optional provider prefix. Empty provider returns everything.
func LookupModel ¶
func LookupModel(spec string) (*GeneratedModel, bool)
LookupModel resolves a spec like "<provider>/<model-id>" or just "<model-id>" against the generated catalog. Returns the matching model and true on success.
When only a bare model id is given and multiple providers ship a model with the same id (rare; "claude-3-5-sonnet" appears under both anthropic and copilot for example), the first match in alphabetical-provider order wins. Callers wanting deterministic resolution should pass the full "<provider>/<model-id>" form.
func LookupModelExact ¶
func LookupModelExact(spec string) (*GeneratedModel, bool)
LookupModelExact resolves only the fully-qualified "provider/id" key, without LookupModel's bare-id fallback across other providers. This is what model resolution needs so that "github-copilot/gpt-4o" yields no match when the copilot catalog lacks gpt-4o, instead of silently borrowing openai's gpt-4o capabilities. Mirrors upstream resolveCliModel, which filters candidate models by provider before matching the id.
func (*GeneratedModel) ToCapabilities ¶
func (m *GeneratedModel) ToCapabilities() ModelCapabilities
ToCapabilities lifts a GeneratedModel into the runtime ModelCapabilities consumed by status line and provider routing.
func (*GeneratedModel) ToModel ¶
func (m *GeneratedModel) ToModel() *Model
ToModel lifts a generated catalog entry into the runtime model metadata shape used by provider-specific compat helpers and tests.
type GoogleConfig ¶
type GoogleConfig struct {
// APIKey is the Google AI API key.
APIKey string
// Model is the model name (e.g. "gemini-2.5-flash").
Model string
// ProviderID is the provider label (default: "google-generative-ai").
ProviderID string
// BaseURL overrides the API base (default: https://generativelanguage.googleapis.com).
BaseURL string
// APIVersion overrides the API version path (default: "v1beta").
// Set to "" when BaseURL already includes the version path.
APIVersion string
// ExtraHeaders are added to every request.
ExtraHeaders map[string]string
}
GoogleConfig configures the Google Gemini provider.
type GoogleThinkingLevel ¶
type GoogleThinkingLevel string
GoogleThinkingLevel mirrors the upstream exported thinking-level union used by both the direct Gemini and Vertex providers.
const ( GoogleThinkingLevelUnspecified GoogleThinkingLevel = "THINKING_LEVEL_UNSPECIFIED" GoogleThinkingLevelMinimal GoogleThinkingLevel = "MINIMAL" GoogleThinkingLevelLow GoogleThinkingLevel = "LOW" GoogleThinkingLevelMedium GoogleThinkingLevel = "MEDIUM" GoogleThinkingLevelHigh GoogleThinkingLevel = "HIGH" )
type GoogleVertexConfig ¶
type GoogleVertexConfig struct {
APIKey string
Model string
ProviderID string
BaseURL string
Project string
Location string
Headers map[string]string
}
GoogleVertexConfig configures the Google Vertex AI provider. Mirrors upstream providers/google-vertex.ts. Vertex uses the same Gemini wire format but routes through a Vertex-specific endpoint that accepts either an API key or Application Default Credentials.
type GrammarFormat ¶
type GrammarFormat = string
GrammarFormat is an OpenAI grammar variant key. Mirrors upstream GrammarFormat.
const ( GrammarFormatOpenAILark GrammarFormat = "openai_lark" GrammarFormatOpenAIRegex GrammarFormat = "openai_regex" )
type ImageContent ¶
ImageContent is a base64-encoded image in a message.
func (ImageContent) MarshalJSON ¶
func (content ImageContent) MarshalJSON() ([]byte, error)
type ImagesAPI ¶
type ImagesAPI string
ImagesAPI identifies an image-generation provider API.
const APIImagesOpenRouter ImagesAPI = "openrouter-images"
type ImagesAPIProvider ¶
type ImagesAPIProvider struct {
API ImagesAPI
GenerateImages ImagesFunction
}
ImagesAPIProvider registers a provider implementation for an ImagesAPI.
func GetImagesAPIProvider ¶
func GetImagesAPIProvider(api ImagesAPI) (ImagesAPIProvider, bool)
GetImagesAPIProvider returns the registered provider for api.
type ImagesContext ¶
type ImagesContext struct {
Input []ContentBlock
}
ImagesContext is the input to an image-generation request.
type ImagesCost ¶
ImagesCost mirrors upstream image model cost fields, expressed in USD per million tokens where a provider reports token usage.
type ImagesFunction ¶
type ImagesFunction func(context.Context, ImagesModel, ImagesContext, ProviderImagesOptions) AssistantImages
ImagesFunction is an image-generation provider function.
type ImagesModel ¶
type ImagesModel struct {
ID string
Name string
API ImagesAPI
Provider ImagesProvider
BaseURL string
Headers map[string]string
Input []string
Output []string
Cost ImagesCost
}
ImagesModel describes one generated-image model catalog entry.
func GetImageModel ¶
func GetImageModel(provider ImagesProvider, modelID string) (ImagesModel, bool)
GetImageModel returns a generated image model by provider and id.
func GetImageModels ¶
func GetImageModels(provider ImagesProvider) []ImagesModel
GetImageModels returns generated image models for provider in stable ID order.
type ImagesProvider ¶
type ImagesProvider string
ImagesProvider identifies an image-generation provider.
const ProviderImagesOpenRouter ImagesProvider = "openrouter"
func GetImageProviders ¶
func GetImageProviders() []ImagesProvider
GetImageProviders returns the generated image providers in stable order.
type ImagesStopReason ¶
type ImagesStopReason string
ImagesStopReason mirrors upstream ImagesStopReason.
const ( ImagesStopReasonStop ImagesStopReason = "stop" ImagesStopReasonError ImagesStopReason = "error" ImagesStopReasonAborted ImagesStopReason = "aborted" )
type InMemoryAuthStorage ¶
type InMemoryAuthStorage struct {
// contains filtered or unexported fields
}
InMemoryAuthStorage is a process-local CredentialStore. Mirrors upstream AuthStorage.inMemory; it is a separate type because AuthStorage is bound to its auth.json path.
func NewInMemoryAuthStorage ¶
func NewInMemoryAuthStorage(data map[string]Credential) *InMemoryAuthStorage
NewInMemoryAuthStorage returns a store seeded with a copy of data.
func (*InMemoryAuthStorage) List ¶
func (s *InMemoryAuthStorage) List(ctx context.Context) ([]CredentialInfo, error)
List implements CredentialStore.
func (*InMemoryAuthStorage) Modify ¶
func (s *InMemoryAuthStorage) Modify(ctx context.Context, providerID string, fn func(current *Credential) (*Credential, error)) (*Credential, error)
Modify implements CredentialStore; calls are serialized.
func (*InMemoryAuthStorage) Read ¶
func (s *InMemoryAuthStorage) Read(ctx context.Context, providerID string) (*Credential, error)
Read implements CredentialStore.
type InMemoryModelsStore ¶
type InMemoryModelsStore struct {
// contains filtered or unexported fields
}
InMemoryModelsStore mirrors pi-ai InMemoryModelsStore (and the coding agent's InMemoryCodingAgentModelsStore): a process-local ModelsStore.
func NewInMemoryModelsStore ¶
func NewInMemoryModelsStore() *InMemoryModelsStore
NewInMemoryModelsStore returns an empty in-memory store.
func (*InMemoryModelsStore) Delete ¶
func (s *InMemoryModelsStore) Delete(ctx context.Context, providerID string) error
Delete removes the provider's catalog.
func (*InMemoryModelsStore) Read ¶
func (s *InMemoryModelsStore) Read(ctx context.Context, providerID string) (*ModelsStoreEntry, error)
Read returns a copy of the provider's catalog, or nil when none is stored.
func (*InMemoryModelsStore) Write ¶
func (s *InMemoryModelsStore) Write(ctx context.Context, providerID string, entry ModelsStoreEntry) error
Write stores a copy of the provider's catalog.
type JsonObject ¶
JSONObject is a provider-facing JSON object.
func ParseStreamingJson ¶
func ParseStreamingJson(input string) JsonObject
ParseStreamingJson incrementally reconstructs a streamed tool-argument object. Invalid or incomplete input returns the object prefix parsed so far, or an empty object when no object prefix is available.
type Message ¶
type Message interface {
// contains filtered or unexported methods
}
Message is the closed provider-facing transcript union.
type MistralConfig ¶
type MistralConfig struct {
APIKey string
Model string
ProviderID string
BaseURL string
ExtraHeaders map[string]string
// SessionID for x-affinity header (KV-cache reuse).
SessionID string
// Reasoning indicates whether the model supports extended reasoning.
Reasoning bool
}
MistralConfig configures the Mistral API provider.
type Model ¶
type Model struct {
ID string
DisplayName string
Provider Provider
Capabilities ModelCapabilities
ProviderMeta ProviderMetadata
Input []string
ThinkingLevelMap ThinkingLevelMap
SamplingParams map[string]any
PromptCache ModelPromptCache
// InputLimits mirrors upstream Model.inputLimits.
InputLimits *ModelInputLimits
}
Model pairs an identifier with a provider and capabilities.
type ModelAuth ¶
type ModelAuth struct {
APIKey string
Headers ProviderHeaders
BaseURL string
}
ModelAuth is request auth for a single model request. Mirrors upstream ModelAuth.
type ModelCapabilities ¶
type ModelCapabilities struct {
MaxThinking ThinkingLevel
SupportsImages bool
SupportsToolUse bool
ContextWindow int
MaxOutputTokens int
InputCostPer1M float64 // USD per 1M input tokens
OutputCostPer1M float64 // USD per 1M output tokens
// CacheReadCostPer1M / CacheWriteCostPer1M are the separate cache rates
// upstream models expose; the write rate is for 5m (short) writes. 1h
// writes bill at 2x base input (see CalculateCost).
CacheReadCostPer1M float64 // USD per 1M cache-read tokens
CacheWriteCostPer1M float64 // USD per 1M cache-write tokens
// CostTiers overrides the base rates for high-volume requests: the highest
// matching InputTokensAbove threshold applies to the whole request.
// Mirrors upstream ModelCost.tiers.
CostTiers []CostTier
}
ModelCapabilities describes what a model supports.
type ModelCatalogProvider ¶
type ModelCatalogProvider struct {
ID string `json:"id"`
Name string `json:"name"`
Credential string `json:"credential"`
Source string `json:"source"`
}
ModelCatalogProvider preserves provider-routing metadata carried by generated catalogs.
type ModelCompat ¶
type ModelCompat = OpenAICompat
ModelCompat is the shared compat bag used by generated model metadata, models.json overrides, and provider configs. It merges the upstream OpenAI-compatible compat fields with the newer Anthropic/OpenAI Responses flags used by specific provider families.
Package-local provider code continues to refer to the API-specific aliases below (OpenAICompat, OpenAIResponsesCompat, AnthropicMessagesCompat), but they all share the same underlying shape so generated metadata and registry merge logic can stay simple. ModelCompat is the shared compat bag used by generated model metadata, the provider configs, and the registry. It is identical to OpenAICompat.
type ModelCost ¶
type ModelCost struct {
Input float64 `json:"input"`
Output float64 `json:"output"`
CacheRead float64 `json:"cacheRead"`
CacheWrite float64 `json:"cacheWrite"`
Tiers []CostTier `json:"tiers,omitempty"`
}
ModelCost is the provider price per million tokens for one model.
type ModelImageInputLimits ¶
type ModelImageInputLimits struct {
Resize *ModelImageResizeOptions `json:"resize,omitempty"`
// MaxPerMessage is the maximum number of images in one provider message.
MaxPerMessage int `json:"maxPerMessage,omitempty"`
// MaxPerRequest is the maximum number of images across one provider request.
MaxPerRequest int `json:"maxPerRequest,omitempty"`
}
ModelImageInputLimits describes provider image limits. Zero means omitted.
type ModelImageResizeOptions ¶
type ModelImageResizeOptions struct {
MaxWidth int `json:"maxWidth,omitempty"`
MaxHeight int `json:"maxHeight,omitempty"`
// MaxBytes limits the base64-encoded image payload.
MaxBytes int `json:"maxBytes,omitempty"`
JPEGQuality int `json:"jpegQuality,omitempty"`
}
ModelImageResizeOptions is the cache-safe resize profile applied before a new image enters conversation history. Upstream values are integers of at least one, so zero means the field is omitted.
type ModelInputLimits ¶
type ModelInputLimits struct {
// MaxRequestBytes is the maximum serialized provider request size.
MaxRequestBytes int `json:"maxRequestBytes,omitempty"`
Images *ModelImageInputLimits `json:"images,omitempty"`
}
ModelInputLimits carries provider input limits and cache-safe preprocessing metadata. Zero numeric fields and nil objects are omitted fields.
func (*ModelInputLimits) Clone ¶
func (l *ModelInputLimits) Clone() *ModelInputLimits
Clone returns a deep copy so catalog, registry, and extension projections never alias mutable limit metadata.
type ModelPromptCache ¶
ModelPromptCache gives the best-effort prompt-cache lifetime in seconds for each retention tier.
type ModelThinkingLevel ¶
type ModelThinkingLevel = ThinkingLevel
type ModelsError ¶
type ModelsError struct {
Code ModelsErrorCode
Message string
Cause error
}
ModelsError is a coded model-collection failure. Its message carries the cause's detail because callers surface only the message.
func NewModelsError ¶
func NewModelsError(code ModelsErrorCode, message string, cause error) *ModelsError
NewModelsError mirrors the upstream ModelsError constructor.
func (*ModelsError) Error ¶
func (e *ModelsError) Error() string
func (*ModelsError) Unwrap ¶
func (e *ModelsError) Unwrap() error
type ModelsErrorCode ¶
type ModelsErrorCode string
ModelsErrorCode mirrors upstream ModelsErrorCode.
const ( ModelsErrorModelSource ModelsErrorCode = "model_source" ModelsErrorModelValidation ModelsErrorCode = "model_validation" ModelsErrorProvider ModelsErrorCode = "provider" ModelsErrorStream ModelsErrorCode = "stream" ModelsErrorAuth ModelsErrorCode = "auth" ModelsErrorOAuth ModelsErrorCode = "oauth" )
type ModelsPublication ¶
type ModelsPublication struct {
Persist *ModelsStoreEntry
Update func()
}
ModelsPublication is one refresh result handed to RefreshModelsContext.Publish. Persist, when non-nil, is written to the models store before Update runs.
type ModelsStore ¶
type ModelsStore interface {
Read(ctx context.Context, providerID string) (*ModelsStoreEntry, error)
Write(ctx context.Context, providerID string, entry ModelsStoreEntry) error
Delete(ctx context.Context, providerID string) error
}
ModelsStore mirrors pi-ai ModelsStore: persistent model catalogs keyed by provider ID. A cancelled ctx plays the role of options.signal.
type ModelsStoreEntry ¶
type ModelsStoreEntry struct {
Models []json.RawMessage `json:"models"`
// LastModified is the Unix timestamp from the remote catalog's
// Last-Modified header.
LastModified *float64 `json:"lastModified,omitempty"`
// CheckedAt is the Unix timestamp of the last completed remote check.
CheckedAt *float64 `json:"checkedAt,omitempty"`
// ETag is the remote catalog's opaque validator, stored verbatim.
ETag string `json:"etag,omitempty"`
}
ModelsStoreEntry mirrors pi-ai ModelsStoreEntry. Models stay raw JSON because each provider owns the shape of the catalog it persists.
func (ModelsStoreEntry) Clone ¶
func (entry ModelsStoreEntry) Clone() ModelsStoreEntry
Clone returns a deep copy, mirroring upstream's structuredClone at the store boundary.
type OAuthAuth ¶
type OAuthAuth struct {
Name string
IsSubscription bool
Refresh func(ctx context.Context, credential Credential) (Credential, error)
ToAuth func(credential Credential) (ModelAuth, error)
}
OAuthAuth refreshes stored OAuth credentials and derives request auth from them.
func OAuthProviderAuth ¶
OAuthProviderAuth returns the OAuth auth method for a provider registered in the OAuth provider registry.
type OAuthAuthInfo ¶
OAuthAuthInfo is the URL + instructions presented to the user.
type OAuthCredentialStatus ¶
OAuthCredentialStatus describes a stored credential owned by a registered OAuth provider outside auth.json. AuthType is "oauth" or "api_key" and Source is rendered by the login selector (for example "stored").
type OAuthCredentialStore ¶
type OAuthCredentialStore interface {
OAuthCredentialStatus() (OAuthCredentialStatus, bool)
StoreOAuthCredentials(creds OAuthCredentials) (path string, err error)
DeleteOAuthCredentials() (deleted bool, err error)
}
OAuthCredentialStore is an optional extension hook for OAuth providers whose credentials live outside auth.json. Built-in upstream providers do not need it; product extensions can implement it to keep their existing credential stores while still participating in the generic /login and /logout surfaces.
type OAuthCredentials ¶
type OAuthCredentials struct {
Refresh string `json:"refresh"`
Access string `json:"access"`
Expires int64 `json:"expires"` // Unix millis
// ProjectID is used by Google Cloud Code Assist / Antigravity OAuth.
// Upstream OAuthCredentials is open-ended (`[key: string]: unknown`);
// pig models the only currently-used extra field explicitly so
// auth.json round-trips the Google credential shape.
ProjectID string `json:"projectId,omitempty"`
// Scope is the granted scope returned by flows that report one (Radius).
Scope string `json:"scope,omitempty"`
}
OAuthCredentials holds the tokens returned by an OAuth flow.
func GetOAuthAPIKey ¶
func GetOAuthAPIKey(providerID string, credentials map[string]OAuthCredentials) (*OAuthCredentials, string, error)
GetOAuthAPIKey mirrors upstream getOAuthApiKey(): resolve an OAuth-backed API key, refreshing the credential if expired.
func GetOAuthAPIKeyContext ¶
func GetOAuthAPIKeyContext(ctx context.Context, providerID string, credentials map[string]OAuthCredentials) (*OAuthCredentials, string, error)
GetOAuthAPIKeyContext resolves an OAuth-backed API key with the owning operation's cancellation.
func LoginAnthropic ¶
func LoginAnthropic(ctx context.Context, callbacks OAuthLoginCallbacks) (OAuthCredentials, error)
LoginAnthropic runs the Anthropic OAuth authorization code + PKCE flow.
func LoginOpenAICodex ¶
func LoginOpenAICodex(ctx context.Context, callbacks OAuthLoginCallbacks) (OAuthCredentials, error)
LoginOpenAICodex runs the OpenAI Codex (ChatGPT) OAuth flow.
func LoginOpenAICodexDeviceCode ¶
func LoginOpenAICodexDeviceCode(ctx context.Context, onDeviceCode func(OAuthDeviceCodeInfo)) (OAuthCredentials, error)
LoginOpenAICodexDeviceCode runs the Codex device-code login: request a user code, surface it via onDeviceCode, poll for approval, then exchange the authorization code for credentials. Mirrors loginOpenAICodexDeviceCode (openai-codex.ts:433-451).
func LoginOpenRouter ¶
func LoginOpenRouter(ctx context.Context, callbacks OAuthLoginCallbacks) (OAuthCredentials, error)
LoginOpenRouter runs the OpenRouter OAuth PKCE flow: a loopback callback raced against a manual paste. A claimed browser callback always wins over a racing paste. Mirrors upstream loginOpenRouter.
func RefreshAnthropicToken ¶
func RefreshAnthropicToken(ctx context.Context, refreshToken string) (OAuthCredentials, error)
RefreshAnthropicToken refreshes an Anthropic OAuth token.
func RefreshCodexToken ¶
func RefreshCodexToken(ctx context.Context, refreshToken string) (OAuthCredentials, error)
RefreshCodexToken refreshes an OpenAI Codex OAuth token. Mirrors upstream refreshAccessToken in openai-codex.ts:133-180.
type OAuthDeviceCodeInfo ¶
type OAuthDeviceCodeInfo struct {
UserCode string
VerificationURI string
IntervalSeconds float64
ExpiresInSeconds float64
}
OAuthDeviceCodeInfo is the user code + verification URL presented during a device-code (RFC 8628) login flow. Mirrors upstream OAuthDeviceCodeInfo (types.ts:26-31).
type OAuthLoginCallbacks ¶
type OAuthLoginCallbacks struct {
OnAuth func(info OAuthAuthInfo)
OnDeviceCode func(info OAuthDeviceCodeInfo)
OnPrompt func(prompt OAuthPrompt) (string, error)
OnPromptContext func(context.Context, OAuthPrompt) (string, error)
OnProgress func(message string)
OnManualCodeInput func() (string, error)
OnManualCodeInputContext func(context.Context) (string, error)
OnSelect func(prompt OAuthSelectPrompt) (string, error)
OnSelectContext func(context.Context, OAuthSelectPrompt) (string, error)
}
OAuthLoginCallbacks groups the callbacks used during an OAuth login flow.
type OAuthPrompt ¶
OAuthPrompt describes an interactive prompt during the OAuth flow.
type OAuthProviderInterface ¶
type OAuthProviderInterface interface {
// ID returns the provider identifier (e.g. "anthropic").
ID() string
// Name returns the human-readable provider name.
Name() string
// UsesCallbackServer returns true if the flow uses a local HTTP callback.
UsesCallbackServer() bool
// Login runs the OAuth authorization flow.
Login(callbacks OAuthLoginCallbacks) (OAuthCredentials, error)
// RefreshToken refreshes expired credentials.
RefreshToken(creds OAuthCredentials) (OAuthCredentials, error)
// GetAPIKey extracts the bearer token from credentials.
GetAPIKey(creds OAuthCredentials) string
}
OAuthProviderInterface is the contract for an OAuth provider.
func GetOAuthProvider ¶
func GetOAuthProvider(id string) (OAuthProviderInterface, bool)
GetOAuthProvider returns an OAuth provider by id (custom first, then built-in).
func GetOAuthProviders ¶
func GetOAuthProviders() []OAuthProviderInterface
GetOAuthProviders returns all OAuth providers (built-in + custom).
type OAuthSelectOption ¶
OAuthSelectOption is one selectable choice in an OAuth flow.
type OAuthSelectPrompt ¶
type OAuthSelectPrompt struct {
Message string
Options []OAuthSelectOption
}
OAuthSelectPrompt describes an interactive selection prompt during the OAuth flow.
type OAuthSubscriptionProvider ¶
type OAuthSubscriptionProvider interface {
IsSubscription() bool
}
OAuthSubscriptionProvider marks an OAuth login billed by a subscription. Mirrors upstream OAuth provider isSubscription.
type OpenAICodexResponsesConfig ¶
type OpenAICodexResponsesConfig struct {
APIKey string
Model string
ProviderID string
BaseURL string
Compat *OpenAIResponsesCompat
}
OpenAICodexResponsesConfig mirrors the upstream OpenAI Codex Responses provider (providers/openai-codex-responses.ts). Codex uses the same Responses wire format as OpenAI but with a different base URL, auth scheme (Bearer JWT), and endpoint path (/codex/responses).
Codex uses SSE when explicitly selected. Its default auto transport prefers a session-scoped WebSocket and falls back to SSE before output starts.
type OpenAICodexWebSocketDebugStats ¶
type OpenAICodexWebSocketDebugStats struct {
Requests int
ConnectionsCreated int
ConnectionsReused int
CachedContextRequests int
StoreTrueRequests int
FullContextRequests int
DeltaRequests int
LastInputItems int
LastDeltaInputItems *int
LastPreviousResponseId string
WebSocketFailures int
SSEFallbacks int
WebSocketFallbackActive bool
LastWebSocketError string
}
OpenAICodexWebSocketDebugStats reports connection and continuation behavior for one logical Codex session.
func GetOpenAICodexWebSocketDebugStats ¶
func GetOpenAICodexWebSocketDebugStats(sessionID string) *OpenAICodexWebSocketDebugStats
GetOpenAICodexWebSocketDebugStats returns a copy of one session's counters.
type OpenAICompat ¶
type OpenAICompat struct {
SupportsDeveloperRole *bool `json:"supportsDeveloperRole,omitempty"`
SupportsReasoningEffort *bool `json:"supportsReasoningEffort,omitempty"`
SupportsStore *bool `json:"supportsStore,omitempty"`
SupportsUsageInStreaming *bool `json:"supportsUsageInStreaming,omitempty"`
SupportsFinishReason *bool `json:"supportsFinishReason,omitempty"`
MaxTokensField string `json:"maxTokensField,omitempty"`
RequiresToolResultName *bool `json:"requiresToolResultName,omitempty"`
RequiresAssistantAfterToolResult *bool `json:"requiresAssistantAfterToolResult,omitempty"`
RequiresThinkingAsText *bool `json:"requiresThinkingAsText,omitempty"`
RequiresReasoningContentOnAssistantMessages *bool `json:"requiresReasoningContentOnAssistantMessages,omitempty"`
SupportsOpenAIGrammarTools *bool `json:"supportsOpenAIGrammarTools,omitempty"`
SupportsExplicitPromptCacheMode *bool `json:"supportsExplicitPromptCacheMode,omitempty"`
SupportsStrictTools *bool `json:"supportsStrictTools,omitempty"`
// ThinkingFormat controls how reasoning/thinking content is sent to the provider.
// Values: "openai" (default), "deepseek", "zai", "qwen", "openrouter".
// - "openai": standard reasoning_effort parameter
// - "deepseek": thinking: {type:"enabled"|"disabled"} plus reasoning_effort
// - "zai": zai-specific thinking format
// - "qwen": QwenThinkingType with content_type: "thinking"
// - "openrouter": openrouter reasoning with include_reasoning: true
ThinkingFormat string `json:"thinkingFormat,omitempty"`
// CacheControlFormat selects cache markers on the first instruction's last text part, last tool definition, and last user/assistant/tool text part.
// Values: "" (none), "anthropic".
CacheControlFormat string `json:"cacheControlFormat,omitempty"`
SendSessionAffinityHeaders *bool `json:"sendSessionAffinityHeaders,omitempty"`
SupportsStrictMode *bool `json:"supportsStrictMode,omitempty"`
// OpenRouterRouting contains OpenRouter-specific routing config.
OpenRouterRouting map[string]any `json:"openRouterRouting,omitempty"`
ChatTemplateKwargs map[string]any `json:"chatTemplateKwargs,omitempty"`
VLLMPriority *float64 `json:"vllmPriority,omitempty"`
// VercelGatewayRouting contains Vercel gateway routing config.
VercelGatewayRouting map[string]any `json:"vercelGatewayRouting,omitempty"`
SupportsLongCacheRetention *bool `json:"supportsLongCacheRetention,omitempty"`
SendSessionIdHeader *bool `json:"sendSessionIdHeader,omitempty"`
SupportsEagerToolInputStreaming *bool `json:"supportsEagerToolInputStreaming,omitempty"`
SupportsCacheControlOnTools *bool `json:"supportsCacheControlOnTools,omitempty"`
// ForceAdaptiveThinking forces adaptive thinking (type: "adaptive"
// + output_config.effort) regardless of model ID. Built-in models
// set this in generated metadata. Custom Anthropic-compatible
// providers can set it for any model requiring adaptive format.
ForceAdaptiveThinking *bool `json:"forceAdaptiveThinking,omitempty"`
// AllowEmptySignature preserves thinking blocks with empty signatures
// instead of converting them to text. For Anthropic-compatible
// providers that return empty thinking signatures.
AllowEmptySignature *bool `json:"allowEmptySignature,omitempty"`
// SupportsTemperature indicates whether the model accepts temperature.
// Claude Opus 4.7+ rejects non-default temperature values.
SupportsTemperature *bool `json:"supportsTemperature,omitempty"`
ZaiToolStream *bool `json:"zaiToolStream,omitempty"`
// DeferredToolsMode selects provider-specific deferred-tool
// serialization on OpenAI Completions. Only "kimi" is defined
// (Moonshot Kimi). Empty = no deferred-tool handling.
DeferredToolsMode string `json:"deferredToolsMode,omitempty"`
// SessionAffinityFormat selects which session-affinity headers are sent
// from options.SessionID. "openai" sends session_id + x-client-request-id
// + x-session-affinity (Completions) / session_id + x-client-request-id
// (Responses); "openai-nosession" omits session_id; "openrouter" sends
// x-session-id. Empty = auto-detect (openrouter base URL => "openrouter",
// else "openai"). Replaces the pre-0.81 sendSessionIdHeader flag.
SessionAffinityFormat SessionAffinityFormat `json:"sessionAffinityFormat,omitempty"`
// SupportsToolSearch indicates the model supports client-executed tool
// search for deferred tools (OpenAI Responses). Default: false.
SupportsToolSearch *bool `json:"supportsToolSearch,omitempty"`
SupportsMaxOutputTokens *bool `json:"supportsMaxOutputTokens,omitempty"`
// SupportsToolReferences indicates the provider supports deferred tools
// loaded by tool_reference blocks in tool results (Anthropic Messages).
// Default: true for first-party Anthropic except Haiku / pre-Claude-4.5.
// ChatTemplateArgs are provider-specific vLLM/Baseten chat-template values.
ChatTemplateArgs map[string]any `json:"chatTemplateArgs,omitempty"`
SupportsThinkingTokenBudget *bool `json:"supportsThinkingTokenBudget,omitempty"`
SupportsAdditionalTools *bool `json:"supportsAdditionalTools,omitempty"`
SupportsMidConvoEffort *bool `json:"supportsMidConvoEffort,omitempty"`
SupportsMidConvoSystemMessages *bool `json:"supportsMidConvoSystemMessages,omitempty"`
SupportsMidConvoToolAdditions *bool `json:"supportsMidConvoToolAdditions,omitempty"`
SupportsMidConvoToolChanges *bool `json:"supportsMidConvoToolChanges,omitempty"`
AllowedFallbackModels []AnthropicAllowedFallbackModel `json:"allowedFallbackModels,omitempty"`
}
OpenAICompat controls behavior for non-standard OpenAI-compatible endpoints (Ollama, vLLM, LiteLLM, MLX, etc.). Mirrors upstream OpenAICompletionsCompat (types.ts).
func DetectCompat ¶
func DetectCompat(providerID, baseURL string) *OpenAICompat
DetectCompat is exported for use by model resolution. Returns nil for OpenAI-direct (defaults suffice).
type OpenAIConfig ¶
type OpenAIConfig struct {
// BaseURL is the API base (default: https://api.openai.com/v1).
BaseURL string
// APIKey is the bearer token. May be empty for local endpoints.
APIKey string
// Model is the model name sent in the request.
Model string
// ProviderID is the provider label (e.g. "openai", "openrouter", "ollama").
ProviderID string
// ExtraHeaders are added to every request.
ExtraHeaders map[string]string
SamplingParams map[string]any
// Env holds provider-scoped environment overrides that take precedence over
// the process environment when resolving provider configuration such as
// PI_CACHE_RETENTION and Cloudflare base-URL placeholders. Mirrors the
// upstream StreamOptions.env threaded into the provider.
Env ProviderEnv
// Compat controls behavior for non-standard OpenAI-compatible endpoints.
// Mirrors upstream OpenAICompletionsCompat.
Compat *OpenAICompat
// GetAPIKey is an optional callback for dynamically obtaining the bearer
// token (e.g. refreshing an OAuth access token). When set, takes precedence
// over APIKey. Called once per Stream() invocation.
GetAPIKey func(ctx context.Context) (string, error)
// GetBaseURL is an optional callback for dynamically resolving the base URL
// (e.g. extracting proxy-ep from a refreshed Copilot token). When set,
// takes precedence over BaseURL. Called once per Stream() invocation.
GetBaseURL func(ctx context.Context) (string, error)
// DynamicHeaders, when set, is called per-request with the StreamOptions
// and returns headers to add to that request (e.g. Copilot's X-Initiator).
DynamicHeaders func(transcript TranscriptContext, opts StreamOptions) map[string]string
// pig additive (D36): opt in to TLS without certificate verification.
Insecure bool
}
OpenAIConfig configures an OpenAI-compatible provider.
type OpenAIResponsesCompat ¶
type OpenAIResponsesCompat = OpenAICompat
ThinkingLevel controls extended-thinking depth (where supported).
type OpenAIResponsesConfig ¶
type OpenAIResponsesConfig struct {
// BaseURL is the API base (default: https://api.openai.com/v1).
BaseURL string
// APIKey is the bearer token.
APIKey string
// Model is the model name sent in the request.
Model string
// ProviderID is the provider label (e.g. "openai", "github-copilot").
ProviderID string
// ExtraHeaders are added to every request.
ExtraHeaders map[string]string
SamplingParams map[string]any
// APIKeyHeader is the header name used for the API key.
// Default: Authorization.
APIKeyHeader string
// APIKeyPrefix is prepended when APIKeyHeader is used.
// Default: Bearer . Empty string sends the raw key.
APIKeyPrefix string
// BaseURLIsEndpoint means BaseURL/GetBaseURL already resolves to the
// final Responses endpoint and should not have /responses appended.
BaseURLIsEndpoint bool
// IsReasoning indicates this model supports extended reasoning.
IsReasoning bool
// GetAPIKey dynamically obtains the bearer token. Takes precedence over APIKey.
GetAPIKey func(ctx context.Context) (string, error)
// GetBaseURL dynamically resolves the base URL. Takes precedence over BaseURL.
GetBaseURL func(ctx context.Context) (string, error)
// DynamicHeaders returns per-request headers.
DynamicHeaders func(transcript TranscriptContext, opts StreamOptions) map[string]string
// Env holds provider-scoped environment overrides that take precedence over
// the process environment for provider configuration (PI_CACHE_RETENTION,
// Cloudflare base-URL placeholders). Mirrors upstream StreamOptions.env.
Env ProviderEnv
// Compat controls Responses-API-specific compat behavior.
Compat *OpenAIResponsesCompat
// StrictModeDefault is the provider-level default for supportsStrictMode when
// the model compat does not set it. Upstream defaults false for the generic
// openai-responses path and true for azure/codex.
StrictModeDefault bool
// StrictToolNull makes a strict-mode function tool default its strict field to
// JSON null instead of false. Codex passes strict:null; other providers false.
StrictToolNull bool
// SkipServiceTierPricing leaves the response's service tier out of the
// cost. Upstream Azure passes processResponsesStream no
// applyServiceTierPricing; OpenAI and Codex apply it.
SkipServiceTierPricing bool
// Codex selects the ChatGPT Codex request and transport protocol rather
// than the generic Responses protocol.
Codex bool
// contains filtered or unexported fields
}
OpenAIResponsesConfig configures the OpenAI Responses API provider.
type OpenRouterOAuthProvider ¶
type OpenRouterOAuthProvider struct{}
OpenRouterOAuthProvider implements OAuthProviderInterface for OpenRouter.
Unlike the other built-in OAuth providers, OpenRouter is not a subscription login: its flow yields a permanent API key, and upstream openRouterOAuth leaves isSubscription unset.
func (OpenRouterOAuthProvider) GetAPIKey ¶
func (OpenRouterOAuthProvider) GetAPIKey(c OAuthCredentials) string
func (OpenRouterOAuthProvider) ID ¶
func (OpenRouterOAuthProvider) ID() string
func (OpenRouterOAuthProvider) Login ¶
func (p OpenRouterOAuthProvider) Login(callbacks OAuthLoginCallbacks) (OAuthCredentials, error)
func (OpenRouterOAuthProvider) LoginContext ¶
func (OpenRouterOAuthProvider) LoginContext(ctx context.Context, callbacks OAuthLoginCallbacks) (OAuthCredentials, error)
func (OpenRouterOAuthProvider) Name ¶
func (OpenRouterOAuthProvider) Name() string
func (OpenRouterOAuthProvider) RefreshToken ¶
func (p OpenRouterOAuthProvider) RefreshToken(creds OAuthCredentials) (OAuthCredentials, error)
RefreshToken returns the credential unchanged: an OpenRouter API key does not expire and has no refresh token. Mirrors upstream openRouterOAuth.refresh.
func (OpenRouterOAuthProvider) RefreshTokenContext ¶
func (OpenRouterOAuthProvider) RefreshTokenContext(_ context.Context, creds OAuthCredentials) (OAuthCredentials, error)
func (OpenRouterOAuthProvider) UsesCallbackServer ¶
func (OpenRouterOAuthProvider) UsesCallbackServer() bool
type OrderedSections ¶
type OrderedSections []PromptSection
OrderedSections is the ordered representation of upstream's section object.
func (OrderedSections) MarshalJSON ¶
func (s OrderedSections) MarshalJSON() ([]byte, error)
func (*OrderedSections) UnmarshalJSON ¶
func (s *OrderedSections) UnmarshalJSON(data []byte) error
type PKCE ¶
PKCE holds a code verifier and its corresponding S256 challenge.
func GeneratePKCE ¶
GeneratePKCE creates a random PKCE verifier and SHA-256 challenge.
type PiMessagesConfig ¶
type PiMessagesConfig struct {
BaseURL string
APIKey string
GetAPIKey func(context.Context) (string, error)
Model string
ProviderID string
ExtraHeaders map[string]string
// Debug asks the backend for debug metadata (?debug=1).
Debug bool
// ToolChoice is "auto", "none", "required", or {type:"function",...}.
ToolChoice any
OnResponse func(PiMessagesResponse) error
}
PiMessagesConfig configures a pi-messages provider. Debug, ToolChoice, and OnResponse carry upstream PiMessagesOptions fields that StreamOptions lacks.
type PiMessagesEvent ¶
type PiMessagesEvent struct {
Type string `json:"type"`
ContentIndex int `json:"contentIndex"`
Delta string `json:"delta"`
Content string `json:"content"`
ContentSignature string `json:"contentSignature"`
Redacted bool `json:"redacted"`
ID string `json:"id"`
ToolName string `json:"toolName"`
ToolCall *ToolCall `json:"toolCall"`
Reason StopReason `json:"reason"`
Usage Usage `json:"usage"`
ErrorMessage string `json:"errorMessage"`
ResponseID string `json:"responseId"`
ProviderThinkingLevel *string `json:"providerThinkingLevel"`
Rewrite map[string]any `json:"rewrite"`
}
PiMessagesEvent is one serialized assistant-message event sent by a pi-messages backend. Type selects which fields apply.
type PiMessagesModel ¶
type PiMessagesModel struct {
RadiusGatewayModel
API API `json:"api"`
Provider string `json:"provider"`
BaseURL string `json:"baseUrl"`
}
PiMessagesModel is Pi's Model<"pi-messages"> as served by a Radius provider: a gateway model bound to its provider ID, API, and request base URL.
func GetRadiusModels ¶
func GetRadiusModels(providerID string, credential *Credential) []PiMessagesModel
GetRadiusModels returns the legacy credential catalog bound to providerID.
func GetRadiusModelsFromConfig ¶
func GetRadiusModelsFromConfig(providerID string, config RadiusGatewayConfig) []PiMessagesModel
GetRadiusModelsFromConfig binds a gateway catalog to providerID.
type PiMessagesResponse ¶
PiMessagesResponse is the HTTP status and headers reported to OnResponse.
type PiMessagesResponseError ¶
PiMessagesResponseError is a non-2xx backend response with diagnostic details.
func (*PiMessagesResponseError) Error ¶
func (e *PiMessagesResponseError) Error() string
type PiMessagesRewriteImpact ¶
type PiMessagesRewriteImpact struct {
PolicyID string `json:"policyId"`
PolicyVersion float64 `json:"policyVersion"`
Changed bool `json:"changed"`
TokenCountChange float64 `json:"tokenCountChange"`
MessageCountChange float64 `json:"messageCountChange"`
SystemPromptChanged bool `json:"systemPromptChanged"`
}
PiMessagesRewriteImpact summarizes a server-side message rewrite (for example a gateway policy). It is recorded as a pi_messages_rewrite diagnostic.
type PromptSection ¶
PromptSection preserves the insertion order of named system-prompt sections. A nil Value is an explicit JSON null that removes the named section.
type Provider ¶
type Provider interface {
// ID returns the provider identifier (e.g. "openai", "github-copilot").
ID() string
// Stream initiates a request from an already normalized transcript.
Stream(ctx context.Context, transcript TranscriptContext, opts StreamOptions) (*AssistantMessageEventStream, error)
// Close releases any persistent connections or background resources.
io.Closer
}
Provider is the interface implemented by each LLM backend.
func NewAnthropicProvider ¶
func NewAnthropicProvider(cfg AnthropicConfig) Provider
NewAnthropicProvider creates a Provider backed by the Anthropic Messages API.
func NewAzureOpenAIResponsesProvider ¶
func NewAzureOpenAIResponsesProvider(cfg AzureOpenAIResponsesConfig) Provider
NewAzureOpenAIResponsesProvider creates an Azure OpenAI Responses provider. Mirrors upstream providers/azure-openai-responses.ts.
func NewCopilotProvider ¶
func NewCopilotProvider(cfg CopilotProviderConfig) (Provider, error)
NewCopilotProvider builds a Provider that streams via the Copilot proxy. The wire protocol (Completions vs Responses API) is selected by cfg.API. The credential is auto-refreshed transparently when within 60s of expiry.
func NewGoogleProvider ¶
func NewGoogleProvider(cfg GoogleConfig) Provider
NewGoogleProvider creates a Provider backed by the Google Gemini API.
func NewGoogleVertexProvider ¶
func NewGoogleVertexProvider(cfg GoogleVertexConfig) Provider
NewGoogleVertexProvider creates a Google Vertex AI provider. Mirrors upstream providers/google-vertex.ts.
func NewMistralProvider ¶
func NewMistralProvider(cfg MistralConfig) Provider
NewMistralProvider creates a Provider backed by the Mistral API.
func NewOpenAICodexResponsesProvider ¶
func NewOpenAICodexResponsesProvider(cfg OpenAICodexResponsesConfig) Provider
NewOpenAICodexResponsesProvider creates an OpenAI Codex Responses provider. Mirrors upstream providers/openai-codex-responses.ts.
func NewOpenAIProvider ¶
func NewOpenAIProvider(cfg OpenAIConfig) Provider
NewOpenAIProvider creates a Provider backed by the OpenAI Completions API.
func NewOpenAIResponsesProvider ¶
func NewOpenAIResponsesProvider(cfg OpenAIResponsesConfig) Provider
NewOpenAIResponsesProvider creates a Provider backed by the OpenAI Responses API.
func NewPiMessagesProvider ¶
func NewPiMessagesProvider(cfg PiMessagesConfig) Provider
NewPiMessagesProvider creates a pi-messages provider. Like upstream fetch, requests are not retried by the provider retry transport.
type ProviderAuth ¶
type ProviderAuth struct {
APIKey *APIKeyAuth
OAuth *OAuthAuth
}
ProviderAuth lists the auth methods a provider supports.
func BuiltinProviderAuth ¶
func BuiltinProviderAuth(providerID string) (ProviderAuth, error)
BuiltinProviderAuth returns a built-in provider's auth methods. The OAuth method is present when the provider's OAuth flow is ported.
func RadiusProviderAuth ¶
func RadiusProviderAuth(provider *RadiusProvider) ProviderAuth
RadiusProviderAuth mirrors the auth of upstream radiusProvider: the RADIUS_API_KEY api-key method and the provider's gateway OAuth, for the built-in provider and every models.json "oauth": "radius" gateway.
type ProviderEnv ¶
ProviderEnv holds provider-scoped environment overrides whose values take precedence over the process environment for provider configuration such as regional settings, endpoint placeholders, and proxy variables. Mirrors upstream types.ts ProviderEnv (Record<string, string>).
type ProviderFactory ¶
ProviderFactory creates a Provider from an API key and model spec. Used by the built-in provider registry to construct providers on demand.
func LookupBuiltInProvider ¶
func LookupBuiltInProvider(api API) (ProviderFactory, bool)
LookupBuiltInProvider returns the factory for a built-in API, if registered.
type ProviderHeaders ¶
ProviderHeaders mirrors Pi's request-header map. A nil value removes an existing header after configured and authentication headers are merged.
func MergeProviderHeaders ¶
func MergeProviderHeaders(base, override ProviderHeaders) ProviderHeaders
MergeProviderHeaders overlays override onto base, replacing headers case-insensitively. Mirrors upstream mergeHeaders in models.ts.
func ProviderHeadersFromStrings ¶
func ProviderHeadersFromStrings(values map[string]string) ProviderHeaders
ProviderHeadersFromStrings converts non-null configured headers to request header values.
type ProviderImagesOptions ¶
type ProviderImagesOptions struct {
APIKey string
Headers map[string]string
TimeoutMs int
MaxRetries int
OnPayload func(payload any, model ImagesModel) (any, bool, error)
OnResponse func(response ProviderResponse, model ImagesModel) error
}
ProviderImagesOptions configures image-generation provider requests.
type ProviderMetadata ¶
type ProviderMetadata struct {
ProviderID string
API API
BaseURL string
Headers map[string]string
Compat *ModelCompat
Reasoning bool
}
ProviderMetadata carries generated/registry metadata that provider adapters use for compat decisions beyond the live Provider implementation.
type ProviderResponse ¶
ProviderResponse is the provider HTTP response metadata exposed to hooks.
type RadiusGatewayConfig ¶
type RadiusGatewayConfig struct {
BaseURL string `json:"baseUrl"`
Models []RadiusGatewayModel `json:"models"`
}
RadiusGatewayConfig is the sanitized /v1/config document of a gateway.
func GetRadiusCredentialConfig ¶
func GetRadiusCredentialConfig(credential *Credential) (RadiusGatewayConfig, bool)
GetRadiusCredentialConfig returns the sanitized legacy gateway catalog that pre-ModelsStore Radius builds cached on the OAuth credential.
func LoadRadiusGatewayConfig ¶
func LoadRadiusGatewayConfig(ctx context.Context, gateway, apiKey string) (RadiusGatewayConfig, error)
LoadRadiusGatewayConfig fetches and sanitizes <gateway>/v1/config. Mirrors upstream loadRadiusGatewayConfig. PiG sets no User-Agent here, so net/http sends its default (owner question Q4 tracks Pi's User-Agent).
type RadiusGatewayModel ¶
type RadiusGatewayModel struct {
ID string `json:"id"`
Name string `json:"name"`
Reasoning bool `json:"reasoning"`
ThinkingLevelMap ThinkingLevelMap `json:"thinkingLevelMap,omitempty"`
Input []string `json:"input"`
InputLimits *ModelInputLimits `json:"inputLimits,omitempty"`
Cost RadiusModelCost `json:"cost"`
PromptCache ModelPromptCache `json:"promptCache,omitempty"`
ContextWindow int `json:"contextWindow"`
MaxTokens int `json:"maxTokens"`
SamplingParams map[string]any `json:"samplingParams,omitempty"`
Headers map[string]string `json:"headers,omitempty"`
Compat *ModelCompat `json:"compat,omitempty"`
}
RadiusGatewayModel is one model advertised by a Radius gateway's /v1/config.
type RadiusModelCost ¶
type RadiusModelCost struct {
Input float64 `json:"input"`
Output float64 `json:"output"`
CacheRead float64 `json:"cacheRead"`
CacheWrite float64 `json:"cacheWrite"`
Tiers []CostTier `json:"tiers,omitempty"`
}
RadiusModelCost is the per-million-token pricing carried by a Radius model.
type RadiusOAuth ¶
type RadiusOAuth struct {
// contains filtered or unexported fields
}
RadiusOAuth is the Radius gateway OAuth flow (browser PKCE or device code).
func CreateRadiusOAuth ¶
func CreateRadiusOAuth(options RadiusOAuthOptions) *RadiusOAuth
CreateRadiusOAuth mirrors upstream createRadiusOAuth.
func (*RadiusOAuth) Gateway ¶
func (o *RadiusOAuth) Gateway() string
Gateway returns the normalized gateway origin used for every OAuth request.
func (*RadiusOAuth) GetAPIKey ¶
func (o *RadiusOAuth) GetAPIKey(credentials OAuthCredentials) string
func (*RadiusOAuth) ID ¶
func (o *RadiusOAuth) ID() string
func (*RadiusOAuth) Login ¶
func (o *RadiusOAuth) Login(callbacks OAuthLoginCallbacks) (OAuthCredentials, error)
Login runs the flow without cancellation. Prefer LoginContext.
func (*RadiusOAuth) LoginContext ¶
func (o *RadiusOAuth) LoginContext(ctx context.Context, callbacks OAuthLoginCallbacks) (OAuthCredentials, error)
LoginContext asks for a sign-in method, then runs the browser or device flow. Cancelling ctx mirrors aborting upstream's interaction.signal.
func (*RadiusOAuth) LoginMethodPrompt ¶
func (o *RadiusOAuth) LoginMethodPrompt() OAuthSelectPrompt
LoginMethodPrompt is the sign-in method selection Pi presents before login.
func (*RadiusOAuth) Name ¶
func (o *RadiusOAuth) Name() string
func (*RadiusOAuth) RefreshToken ¶
func (o *RadiusOAuth) RefreshToken(credentials OAuthCredentials) (OAuthCredentials, error)
RefreshToken exchanges the refresh token directly at the gateway.
func (*RadiusOAuth) RefreshTokenContext ¶
func (o *RadiusOAuth) RefreshTokenContext(ctx context.Context, credentials OAuthCredentials) (OAuthCredentials, error)
RefreshTokenContext exchanges the token with the owning operation's cancellation.
func (*RadiusOAuth) UsesCallbackServer ¶
func (o *RadiusOAuth) UsesCallbackServer() bool
type RadiusOAuthOptions ¶
RadiusOAuthOptions configures CreateRadiusOAuth. ID is the provider ID the flow is registered under; Pi derives it from the owning provider.
type RadiusOAuthResponseError ¶
type RadiusOAuthResponseError struct {
Status int
OAuthError string
// contains filtered or unexported fields
}
RadiusOAuthResponseError is a non-2xx OAuth response. Mirrors upstream OAuthResponseError.
func (*RadiusOAuthResponseError) Error ¶
func (e *RadiusOAuthResponseError) Error() string
type RadiusProvider ¶
type RadiusProvider struct {
// contains filtered or unexported fields
}
RadiusProvider is the Radius gateway provider: the published static catalog for the default gateway, overlaid by a persisted, dynamically refreshed one.
func NewRadiusProvider ¶
func NewRadiusProvider(options RadiusProviderOptions) *RadiusProvider
NewRadiusProvider mirrors upstream radiusProvider.
func (*RadiusProvider) FindModel ¶
func (p *RadiusProvider) FindModel(id string) (PiMessagesModel, bool)
FindModel returns the effective model with id.
func (*RadiusProvider) Gateway ¶
func (p *RadiusProvider) Gateway() string
func (*RadiusProvider) GetModels ¶
func (p *RadiusProvider) GetModels() []PiMessagesModel
GetModels returns the static catalog with refreshed models overlaid by ID.
func (*RadiusProvider) ID ¶
func (p *RadiusProvider) ID() string
func (*RadiusProvider) Name ¶
func (p *RadiusProvider) Name() string
func (*RadiusProvider) OAuth ¶
func (p *RadiusProvider) OAuth() *RadiusOAuth
func (*RadiusProvider) RefreshModels ¶
func (p *RadiusProvider) RefreshModels(ctx context.Context, refresh RefreshModelsContext) error
RefreshModels restores the stored catalog, imports a legacy credential catalog, and, when network access is allowed, loads the gateway's current catalog with the effective credential.
type RadiusProviderOptions ¶
RadiusProviderOptions configures NewRadiusProvider. Empty fields default to the built-in "radius" provider on DefaultRadiusGateway.
type ReadOnlyAuthStorage ¶
type ReadOnlyAuthStorage struct {
// contains filtered or unexported fields
}
ReadOnlyAuthStorage reads auth.json without creating it, its directory, or its lock, and never executes configured key commands. Mirrors upstream ReadOnlyAuthStorage.
func NewReadOnlyAuthStorage ¶
func NewReadOnlyAuthStorage(path string) *ReadOnlyAuthStorage
NewReadOnlyAuthStorage returns a read-only view of the auth.json at path.
func (*ReadOnlyAuthStorage) List ¶
func (s *ReadOnlyAuthStorage) List(ctx context.Context) ([]CredentialInfo, error)
List implements CredentialStore.
func (*ReadOnlyAuthStorage) Modify ¶
func (s *ReadOnlyAuthStorage) Modify(context.Context, string, func(*Credential) (*Credential, error)) (*Credential, error)
Modify always fails: the store is read-only.
func (*ReadOnlyAuthStorage) Read ¶
func (s *ReadOnlyAuthStorage) Read(ctx context.Context, providerID string) (*Credential, error)
Read implements CredentialStore. Command-valued keys are returned unresolved, as upstream does, so a read-only check never runs them.
type RefreshModelsContext ¶
type RefreshModelsContext struct {
Credential *Credential
Stored *ModelsStoreEntry
AllowNetwork bool
Publish func(ModelsPublication) (bool, error)
}
RefreshModelsContext mirrors upstream RefreshModelsContext. Publish reports false when the refresh was superseded or cancelled; the provider then stops.
type RetryCallbacks ¶
type RetryCallbacks struct {
// OnRetryScheduled runs before the backoff sleep of each 1-indexed retry.
OnRetryScheduled func(attempt, maxAttempts, delayMs int, errorMessage string) error
// OnRetryAttemptStart runs after the backoff sleep, before the retried call.
OnRetryAttemptStart func() error
// OnRetryFinished runs once when a retried loop ends. finalError is empty
// when upstream passes no final error.
OnRetryFinished func(success bool, attempt int, finalError string) error
}
RetryCallbacks are emitted by RetryAssistantCall around each retry. A nil field is skipped; a returned error fails the retry call.
type RetryPolicy ¶
type RetryPolicy struct {
Enabled bool `json:"enabled"`
// MaxRetries is the retry budget; the initial call never counts as a retry.
MaxRetries int `json:"maxRetries"`
BaseDelayMs int `json:"baseDelayMs"`
MaxAgentDelayMs *int `json:"maxAgentDelayMs,omitempty"`
}
RetryPolicy bounds attempts with exponential backoff (baseDelayMs * 2^(attempt-1)). MaxAgentDelayMs caps each computed delay and defaults to DefaultMaxAgentRetryDelayMs when nil.
type RuntimeCredentials ¶
type RuntimeCredentials struct {
// contains filtered or unexported fields
}
RuntimeCredentials is a credential store overlay for non-persistent runtime API keys (--api-key). An override reads as an api_key credential and is never written to the base store. Mirrors upstream packages/coding-agent/src/core/runtime-credentials.ts RuntimeCredentials.
func NewRuntimeCredentials ¶
func NewRuntimeCredentials(store CredentialStore) *RuntimeCredentials
NewRuntimeCredentials overlays runtime API keys on store. A nil store holds no persistent credentials.
func (*RuntimeCredentials) Delete ¶
func (c *RuntimeCredentials) Delete(ctx context.Context, providerID string) error
Delete removes providerID's credential from the base store, then its runtime key.
func (*RuntimeCredentials) HasRuntimeAPIKey ¶
func (c *RuntimeCredentials) HasRuntimeAPIKey(providerID string) bool
HasRuntimeAPIKey reports whether providerID has a runtime key.
func (*RuntimeCredentials) List ¶
func (c *RuntimeCredentials) List(ctx context.Context) ([]CredentialInfo, error)
List implements CredentialStore: base entries, with every runtime key listed as an api_key entry.
func (*RuntimeCredentials) Modify ¶
func (c *RuntimeCredentials) Modify(ctx context.Context, providerID string, fn func(current *Credential) (*Credential, error)) (*Credential, error)
Modify implements CredentialStore by delegating to the base store; the runtime key is unaffected.
func (*RuntimeCredentials) Read ¶
func (c *RuntimeCredentials) Read(ctx context.Context, providerID string) (*Credential, error)
Read implements CredentialStore: a runtime key reads as an api_key credential ahead of the base store.
func (*RuntimeCredentials) RemoveRuntimeAPIKey ¶
func (c *RuntimeCredentials) RemoveRuntimeAPIKey(providerID string)
RemoveRuntimeAPIKey drops providerID's runtime key, revealing the base store's credential.
func (*RuntimeCredentials) RuntimeAPIKey ¶
func (c *RuntimeCredentials) RuntimeAPIKey(providerID string) (string, bool)
RuntimeAPIKey returns providerID's runtime key.
func (*RuntimeCredentials) SetRuntimeAPIKey ¶
func (c *RuntimeCredentials) SetRuntimeAPIKey(providerID, apiKey string)
SetRuntimeAPIKey installs a non-persistent API key for providerID.
type SessionAffinityFormat ¶
type SessionAffinityFormat string
SessionAffinityFormat selects which session-affinity headers a provider sends from options.SessionID. Mirrors upstream SessionAffinityFormat (types.ts). Empty string means auto-detect at the provider.
const ( // SessionAffinityOpenAI sends session_id + x-client-request-id // (+ x-session-affinity on Completions). SessionAffinityOpenAI SessionAffinityFormat = "openai" // SessionAffinityOpenAINoSession omits session_id. SessionAffinityOpenAINoSession SessionAffinityFormat = "openai-nosession" // SessionAffinityOpenRouter sends x-session-id. SessionAffinityOpenRouter SessionAffinityFormat = "openrouter" )
type SessionResourceCleanup ¶
type SessionResourceCleanup func(sessionID string)
SessionResourceCleanup releases provider resources scoped to a logical session, such as cached transport connections.
type StartEvent ¶
type StartEvent struct {
Partial *AssistantMessage `json:"partial"`
}
func (StartEvent) EventType ¶
func (StartEvent) EventType() AssistantEventType
func (StartEvent) MarshalJSON ¶
func (event StartEvent) MarshalJSON() ([]byte, error)
type StartFrame ¶
type StartFrame struct {
Partial AssistantMessage `json:"partial"`
}
func (StartFrame) FrameType ¶
func (StartFrame) FrameType() AssistantMessageFrameType
func (StartFrame) MarshalJSON ¶
func (frame StartFrame) MarshalJSON() ([]byte, error)
type StopReason ¶
type StopReason string
StopReason is the terminal state of an assistant response.
const ( StopReasonPending StopReason = "pending" StopReasonStop StopReason = "stop" StopReasonLength StopReason = "length" StopReasonToolUse StopReason = "toolUse" StopReasonError StopReason = "error" StopReasonAborted StopReason = "aborted" StopReasonDeferred StopReason = "deferred" )
type StreamOptions ¶
type StreamOptions struct {
MaxTokens int
Temperature float64
// TemperatureSet distinguishes an explicit zero temperature from omission.
// Non-zero Temperature values remain present for existing callers.
TemperatureSet bool
SamplingParams map[string]any
ThinkingBudgets *ThinkingBudgets
Thinking ThinkingLevel
// IsReasoning indicates whether the model supports extended reasoning.
// Used by providers to decide developer vs system role and reasoning_effort gating.
// Mirrors upstream model.reasoning field.
IsReasoning bool
// ModelCost is the requested model's price. Providers price Usage.Cost
// with it where upstream providers call calculateCost(model, usage).
ModelCost ModelCost
// Env contains request-specific provider environment values. Runtime-resolved
// values are merged first; request values win.
Env ProviderEnv
// TransformHeaders runs once after configured, auth, and request headers are
// merged. ModelRuntime consumes it and does not forward it to providers.
TransformHeaders func(context.Context, ProviderHeaders) (ProviderHeaders, error)
// Headers are request-specific HTTP headers. A nil value deletes a header
// supplied by configured or resolved authentication state.
Headers ProviderHeaders
// CacheRetention requests a provider-supported prompt-cache lifetime. Empty leaves the option unset.
CacheRetention CacheRetention
// SessionID is passed to the provider for prompt caching (OpenAI prompt_cache_key). When non-empty and the provider supports it, repeated calls with the same session ID can reuse cached prompt processing. Mirrors upstream openai-completions.ts:449.
SessionID string
// ToolChoice selects provider-neutral automatic/no-tool behavior or a
// provider-specific choice object. Anthropic also accepts "any" and
// {"type":"tool","name":...}.
ToolChoice any
// Metadata contains optional provider request metadata. Providers extract
// recognized fields and ignore the rest.
Metadata map[string]any
// Transport requests a provider-specific streaming transport.
// Empty lets the provider choose its default.
Transport Transport
// TimeoutMs bounds response headers and WebSocket stream idleness for
// providers that support request timeouts. Zero leaves the provider default.
TimeoutMs int
// WebSocketConnectTimeoutMs bounds only the WebSocket opening handshake.
// Zero selects the provider default.
WebSocketConnectTimeoutMs int
// OnPayload is an optional parity/debug hook invoked after the provider
// builds its wire payload and before it sends the request. Returning nil
// keeps the payload unchanged; returning a replacement asks providers that
// support replacement to send that value instead. Mirrors upstream
// StreamOptions.onPayload.
OnPayload func(payload any, model *Model) (any, error)
}
StreamOptions are the options for a streaming LLM call.
type SystemContent ¶
type SystemContent interface {
// contains filtered or unexported methods
}
SystemContent is the closed content union for system messages.
type SystemMessage ¶
type SystemMessage struct {
Content SystemContent `json:"content"`
Sections OrderedSections `json:"sections,omitempty"`
ToolsAdded []ToolSchema `json:"toolsAdded,omitempty"`
ToolsRemoved []ToolReference `json:"toolsRemoved,omitempty"`
Timestamp int64 `json:"timestamp"`
}
SystemMessage changes instructions and tool state at one transcript position.
func CreateInitialSystemMessage ¶
func CreateInitialSystemMessage(systemPrompt string, tools []ToolSchema) *SystemMessage
func GetCurrentSystemMessage ¶
func GetCurrentSystemMessage(messages []Message) *SystemMessage
func GetInitialSystemMessage ¶
func GetInitialSystemMessage(messages []Message) *SystemMessage
func (SystemMessage) MarshalJSON ¶
func (message SystemMessage) MarshalJSON() ([]byte, error)
type SystemTextBlocks ¶
type SystemTextBlocks []TextContent
SystemTextBlocks carries system instruction text blocks.
type TestFauxProvider ¶
type TestFauxProvider struct {
Scenario string
// contains filtered or unexported fields
}
Tool-call IDs use a deterministic counter per StreamOptions.SessionID. An omitted session ID shares the provider's default counter; resumed history seeds a new counter.
func (*TestFauxProvider) Close ¶
func (p *TestFauxProvider) Close() error
func (*TestFauxProvider) ID ¶
func (p *TestFauxProvider) ID() string
func (*TestFauxProvider) Stream ¶
func (p *TestFauxProvider) Stream(ctx context.Context, transcript TranscriptContext, options StreamOptions) (*AssistantMessageEventStream, error)
type TextContent ¶
type TextContent struct {
Text string `json:"text"`
TextSignature string `json:"textSignature,omitempty"`
}
TextContent is a text fragment in a message.
func (TextContent) MarshalJSON ¶
func (content TextContent) MarshalJSON() ([]byte, error)
type TextDeltaEvent ¶
type TextDeltaEvent struct {
ContentIndex int `json:"contentIndex"`
Delta string `json:"delta"`
Partial *AssistantMessage `json:"partial"`
}
func (TextDeltaEvent) EventType ¶
func (TextDeltaEvent) EventType() AssistantEventType
func (TextDeltaEvent) MarshalJSON ¶
func (event TextDeltaEvent) MarshalJSON() ([]byte, error)
type TextDeltaFrame ¶
func (TextDeltaFrame) FrameType ¶
func (TextDeltaFrame) FrameType() AssistantMessageFrameType
func (TextDeltaFrame) MarshalJSON ¶
func (frame TextDeltaFrame) MarshalJSON() ([]byte, error)
type TextEndEvent ¶
type TextEndEvent struct {
ContentIndex int `json:"contentIndex"`
Content string `json:"content"`
Partial *AssistantMessage `json:"partial"`
}
func (TextEndEvent) EventType ¶
func (TextEndEvent) EventType() AssistantEventType
func (TextEndEvent) MarshalJSON ¶
func (event TextEndEvent) MarshalJSON() ([]byte, error)
type TextEndFrame ¶
type TextEndFrame struct {
ContentIndex int `json:"contentIndex"`
Content string `json:"content"`
TextSignature string `json:"textSignature,omitempty"`
}
func (TextEndFrame) FrameType ¶
func (TextEndFrame) FrameType() AssistantMessageFrameType
func (TextEndFrame) MarshalJSON ¶
func (frame TextEndFrame) MarshalJSON() ([]byte, error)
type TextStartEvent ¶
type TextStartEvent struct {
ContentIndex int `json:"contentIndex"`
Partial *AssistantMessage `json:"partial"`
}
func (TextStartEvent) EventType ¶
func (TextStartEvent) EventType() AssistantEventType
func (TextStartEvent) MarshalJSON ¶
func (event TextStartEvent) MarshalJSON() ([]byte, error)
type TextStartFrame ¶
type TextStartFrame struct {
ContentIndex int `json:"contentIndex"`
Content TextContent `json:"content"`
}
func (TextStartFrame) FrameType ¶
func (TextStartFrame) FrameType() AssistantMessageFrameType
func (TextStartFrame) MarshalJSON ¶
func (frame TextStartFrame) MarshalJSON() ([]byte, error)
type ThinkingBudgets ¶
ThinkingBudgets maps thinking level names to token budgets.
func DefaultThinkingBudgets ¶
func DefaultThinkingBudgets() ThinkingBudgets
DefaultThinkingBudgets returns the default budget map. Mirrors upstream defaultBudgets (simple-options.ts:32-37).
type ThinkingContent ¶
type ThinkingContent struct {
Thinking string `json:"thinking"`
ThinkingSignature string `json:"thinkingSignature,omitempty"`
Redacted bool `json:"redacted,omitempty"`
}
ThinkingContent is a thinking/reasoning block.
func (ThinkingContent) MarshalJSON ¶
func (content ThinkingContent) MarshalJSON() ([]byte, error)
type ThinkingDeltaEvent ¶
type ThinkingDeltaEvent struct {
ContentIndex int `json:"contentIndex"`
Delta string `json:"delta"`
Partial *AssistantMessage `json:"partial"`
}
func (ThinkingDeltaEvent) EventType ¶
func (ThinkingDeltaEvent) EventType() AssistantEventType
func (ThinkingDeltaEvent) MarshalJSON ¶
func (event ThinkingDeltaEvent) MarshalJSON() ([]byte, error)
type ThinkingDeltaFrame ¶
type ThinkingDeltaFrame struct {
ContentIndex int `json:"contentIndex"`
Delta string `json:"delta"`
}
func (ThinkingDeltaFrame) FrameType ¶
func (ThinkingDeltaFrame) FrameType() AssistantMessageFrameType
func (ThinkingDeltaFrame) MarshalJSON ¶
func (frame ThinkingDeltaFrame) MarshalJSON() ([]byte, error)
type ThinkingEndEvent ¶
type ThinkingEndEvent struct {
ContentIndex int `json:"contentIndex"`
Content string `json:"content"`
Partial *AssistantMessage `json:"partial"`
}
func (ThinkingEndEvent) EventType ¶
func (ThinkingEndEvent) EventType() AssistantEventType
func (ThinkingEndEvent) MarshalJSON ¶
func (event ThinkingEndEvent) MarshalJSON() ([]byte, error)
type ThinkingEndFrame ¶
type ThinkingEndFrame struct {
ContentIndex int `json:"contentIndex"`
Content string `json:"content"`
ThinkingSignature string `json:"thinkingSignature,omitempty"`
Redacted bool `json:"redacted,omitempty"`
}
func (ThinkingEndFrame) FrameType ¶
func (ThinkingEndFrame) FrameType() AssistantMessageFrameType
func (ThinkingEndFrame) MarshalJSON ¶
func (frame ThinkingEndFrame) MarshalJSON() ([]byte, error)
type ThinkingLevel ¶
type ThinkingLevel string
const ( ThinkingOff ThinkingLevel = "off" ThinkingNone ThinkingLevel = ThinkingOff // backward-compatible alias ThinkingMinimal ThinkingLevel = "minimal" // lightest reasoning: mirrors upstream "minimal" ThinkingLow ThinkingLevel = "low" ThinkingMedium ThinkingLevel = "medium" ThinkingHigh ThinkingLevel = "high" // ThinkingXHigh is supported only by models that explicitly declare // MaxThinking = ThinkingXHigh in their Capabilities. // Mirrors upstream THINKING_LEVELS_WITH_XHIGH (agent-session.ts:232). ThinkingXHigh ThinkingLevel = "xhigh" // ThinkingMax is supported only by models that explicitly map "max" in // their thinkingLevelMap (e.g. Claude Opus 4.6 adaptive thinking). Like // xhigh it clamps to "high" for budget-based and non-supporting providers. // Mirrors upstream ThinkingLevel "max" (ai/types.ts:79). ThinkingMax ThinkingLevel = "max" )
func ClampThinkingLevel ¶
func ClampThinkingLevel(m *Model, level ThinkingLevel) ThinkingLevel
ClampThinkingLevel clamps level to the nearest supported thinking level. Mirrors upstream models.ts:clampThinkingLevel.
func GetSupportedThinkingLevels ¶
func GetSupportedThinkingLevels(m *Model) []ThinkingLevel
GetSupportedThinkingLevels returns the model's supported thinking levels. Catalog models use empty MaxThinking for non-reasoning models.
type ThinkingLevelMap ¶
type ThinkingLevelMap = map[ModelThinkingLevel]*string
type ThinkingStartEvent ¶
type ThinkingStartEvent struct {
ContentIndex int `json:"contentIndex"`
Partial *AssistantMessage `json:"partial"`
}
func (ThinkingStartEvent) EventType ¶
func (ThinkingStartEvent) EventType() AssistantEventType
func (ThinkingStartEvent) MarshalJSON ¶
func (event ThinkingStartEvent) MarshalJSON() ([]byte, error)
type ThinkingStartFrame ¶
type ThinkingStartFrame struct {
ContentIndex int `json:"contentIndex"`
Content ThinkingContent `json:"content"`
}
func (ThinkingStartFrame) FrameType ¶
func (ThinkingStartFrame) FrameType() AssistantMessageFrameType
func (ThinkingStartFrame) MarshalJSON ¶
func (frame ThinkingStartFrame) MarshalJSON() ([]byte, error)
type TokenFailure ¶
type ToolCall ¶
type ToolCall struct {
ID string `json:"id"`
Name string `json:"name"`
Arguments JsonObject `json:"arguments"`
ThoughtSignature string `json:"thoughtSignature,omitempty"`
Namespace string `json:"namespace,omitempty"`
}
ToolCall is a tool invocation block in an assistant message.
func (ToolCall) MarshalJSON ¶
type ToolCallCheckpointFrame ¶
type ToolCallCheckpointFrame struct {
ContentIndex int `json:"contentIndex"`
JSON string `json:"json"`
}
func (ToolCallCheckpointFrame) FrameType ¶
func (ToolCallCheckpointFrame) FrameType() AssistantMessageFrameType
func (ToolCallCheckpointFrame) MarshalJSON ¶
func (frame ToolCallCheckpointFrame) MarshalJSON() ([]byte, error)
type ToolCallDeltaEvent ¶
type ToolCallDeltaEvent struct {
ContentIndex int `json:"contentIndex"`
Delta string `json:"delta"`
Partial *AssistantMessage `json:"partial"`
}
func (ToolCallDeltaEvent) EventType ¶
func (ToolCallDeltaEvent) EventType() AssistantEventType
func (ToolCallDeltaEvent) MarshalJSON ¶
func (event ToolCallDeltaEvent) MarshalJSON() ([]byte, error)
type ToolCallDeltaFrame ¶
type ToolCallDeltaFrame struct {
ContentIndex int `json:"contentIndex"`
Delta string `json:"delta"`
}
func (ToolCallDeltaFrame) FrameType ¶
func (ToolCallDeltaFrame) FrameType() AssistantMessageFrameType
func (ToolCallDeltaFrame) MarshalJSON ¶
func (frame ToolCallDeltaFrame) MarshalJSON() ([]byte, error)
type ToolCallEndEvent ¶
type ToolCallEndEvent struct {
ContentIndex int `json:"contentIndex"`
ToolCall ToolCall `json:"toolCall"`
Partial *AssistantMessage `json:"partial"`
}
func (ToolCallEndEvent) EventType ¶
func (ToolCallEndEvent) EventType() AssistantEventType
func (ToolCallEndEvent) MarshalJSON ¶
func (event ToolCallEndEvent) MarshalJSON() ([]byte, error)
type ToolCallEndFrame ¶
type ToolCallEndFrame struct {
ContentIndex int `json:"contentIndex"`
ID string `json:"id"`
Name string `json:"name"`
Arguments JsonObject `json:"arguments"`
ThoughtSignature string `json:"thoughtSignature,omitempty"`
Namespace string `json:"namespace,omitempty"`
}
func (ToolCallEndFrame) FrameType ¶
func (ToolCallEndFrame) FrameType() AssistantMessageFrameType
func (ToolCallEndFrame) MarshalJSON ¶
func (frame ToolCallEndFrame) MarshalJSON() ([]byte, error)
type ToolCallStartEvent ¶
type ToolCallStartEvent struct {
ContentIndex int `json:"contentIndex"`
Partial *AssistantMessage `json:"partial"`
}
func (ToolCallStartEvent) EventType ¶
func (ToolCallStartEvent) EventType() AssistantEventType
func (ToolCallStartEvent) MarshalJSON ¶
func (event ToolCallStartEvent) MarshalJSON() ([]byte, error)
type ToolCallStartFrame ¶
type ToolCallStartFrame struct {
ContentIndex int `json:"contentIndex"`
ToolCall ToolCall `json:"toolCall"`
}
func (ToolCallStartFrame) FrameType ¶
func (ToolCallStartFrame) FrameType() AssistantMessageFrameType
func (ToolCallStartFrame) MarshalJSON ¶
func (frame ToolCallStartFrame) MarshalJSON() ([]byte, error)
type ToolReference ¶
type ToolReference struct {
Name string `json:"name"`
}
ToolReference names a tool removed from the transcript's active tool set.
type ToolResultMessage ¶
type ToolResultMessage struct {
ToolCallID string `json:"toolCallId"`
ToolName string `json:"toolName"`
Content []ToolResultMessageContent `json:"content"`
Details any `json:"details,omitempty"`
Usage *Usage `json:"usage,omitempty"`
IsError bool `json:"isError"`
Timestamp int64 `json:"timestamp"`
}
ToolResultMessage carries one tool execution result.
func (ToolResultMessage) MarshalJSON ¶
func (message ToolResultMessage) MarshalJSON() ([]byte, error)
type ToolResultMessageContent ¶
type ToolResultMessageContent interface {
ContentBlock
// contains filtered or unexported methods
}
ToolResultMessageContent is valid inside a tool-result message.
type ToolSchema ¶
type ToolSchema struct {
Name string `json:"name"`
Description string `json:"description"`
Parameters map[string]any `json:"parameters"` // JSON Schema object
PromptGuidelines []string `json:"promptGuidelines,omitempty"` // Guidelines injected into system prompt
// ConstrainedSampling is the optional provider-side constrained sampling
// request for this tool (nil = unset, equivalent to upstream's false).
// Mirrors upstream Tool.constrainedSampling (types.ts).
ConstrainedSampling *ConstrainedSamplingConfig `json:"constrainedSampling,omitempty"`
}
ToolSchema describes an LLM-callable tool in JSON Schema format.
func GetCurrentTools ¶
func GetCurrentTools(messages []Message) []ToolSchema
func GetDeclaredTools ¶
func GetDeclaredTools(messages []Message) []ToolSchema
func ToToolDeclaration ¶
func ToToolDeclaration(tool ToolSchema) ToolSchema
type ToolStateChanges ¶
type ToolStateChanges struct {
ToolsAdded []ToolSchema
ToolsRemoved []ToolReference
}
func GetToolStateChanges ¶
func GetToolStateChanges(previous, current []ToolSchema) ToolStateChanges
type TranscriptContext ¶
type TranscriptContext struct {
// contains filtered or unexported fields
}
TranscriptContext is the normalized provider-facing request. Only NormalizeContext and replay helpers construct one.
func CollapseSystemMessages ¶
func CollapseSystemMessages(context TranscriptContext) TranscriptContext
func NormalizeContext ¶
func NormalizeContext(context Context) TranscriptContext
NormalizeContext folds shorthand prompt and tools into a leading system message.
func ResolveTranscript ¶
func ResolveTranscript(context TranscriptContext, supportsMidConversationSystemMessages bool) TranscriptContext
func (TranscriptContext) Messages ¶
func (context TranscriptContext) Messages() []Message
Messages returns a deep copy of the normalized transcript.
type TranscriptTools ¶
type TranscriptTools struct {
RequestTools []ToolSchema
AnchorsAdditions bool
}
func ResolveTranscriptTools ¶
func ResolveTranscriptTools(messages []Message, supportsToolAdditions bool) TranscriptTools
type Usage ¶
type Usage struct {
Input int `json:"input"`
Output int `json:"output"`
CacheRead int `json:"cacheRead"`
CacheWrite int `json:"cacheWrite"`
CacheWrite1h *int `json:"cacheWrite1h,omitempty"`
Reasoning *int `json:"reasoning,omitempty"`
TotalTokens int `json:"totalTokens"`
Cost UsageCost `json:"cost"`
}
Usage reports token usage from the provider.
func (Usage) MarshalJSON ¶
MarshalJSON emits the upstream Usage wire shape.
func (*Usage) UnmarshalJSON ¶
UnmarshalJSON decodes the upstream Usage wire shape.
type UsageCost ¶
type UsageCost struct {
Input float64 `json:"input"`
Output float64 `json:"output"`
CacheRead float64 `json:"cacheRead"`
CacheWrite float64 `json:"cacheWrite"`
Total float64 `json:"total"`
}
UsageCost is the provider-reported cost breakdown carried by upstream Usage.
func CalculateCost ¶
CalculateCost fills usage.Cost from the model's prices and returns it. Mirrors upstream models.ts:calculateCost.
type UserContent ¶
type UserContent interface {
// contains filtered or unexported methods
}
UserContent is the closed content union for user messages.
type UserContentBlock ¶
type UserContentBlock interface {
ContentBlock
// contains filtered or unexported methods
}
UserContentBlock is valid inside a user message.
type UserContentBlocks ¶
type UserContentBlocks []UserContentBlock
UserContentBlocks carries text and image user content.
type UserMessage ¶
type UserMessage struct {
Content UserContent `json:"content"`
Timestamp int64 `json:"timestamp"`
}
UserMessage is one user turn.
func (UserMessage) MarshalJSON ¶
func (message UserMessage) MarshalJSON() ([]byte, error)
Source Files
¶
- anthropic.go
- anthropic_client.go
- api_key_providers.go
- assistant_message_frame.go
- assistant_message_frame_json.go
- assistant_retry.go
- auth.go
- auth_env_keys.go
- auth_lock_unix.go
- auth_providers.go
- auth_resolve.go
- auth_revision_unix.go
- auth_store.go
- azure_openai_responses.go
- bedrock.go
- cloudflare.go
- constrained_sampling.go
- content_block.go
- doc.go
- estimate.go
- event_stream.go
- events.go
- faux.go
- githubcopilot.go
- google.go
- google_vertex.go
- http_transport.go
- image_models_generated.go
- images.go
- images_registry.go
- json_repair.go
- messages.go
- mistral.go
- model_utils.go
- models_generated.go
- models_store.go
- oauth_anthropic.go
- oauth_device_code.go
- oauth_kimi.go
- oauth_meta.go
- oauth_openai_codex.go
- oauth_openrouter.go
- oauth_page.go
- oauth_radius.go
- oauth_registry.go
- oauth_types.go
- oauth_xai.go
- openai.go
- openai_cache_control.go
- openai_codex_frames.go
- openai_codex_responses.go
- openai_codex_websocket.go
- openai_compat_upstream.go
- openai_prompt_cache.go
- openai_responses.go
- openrouter_images.go
- overflow.go
- pi_messages.go
- pi_messages_events.go
- pkce.go
- provider_env.go
- provider_headers.go
- provider_retry.go
- radius.go
- radius_config.go
- register_builtins.go
- registry.go
- runtime_credentials.go
- session_resources.go
- simple_options.go
- sse.go
- stream_builder.go
- streaming_json.go
- test_faux.go
- transcript.go
- transport_error.go
- types.go
- usage_json.go
- user_agent.go
- user_agent_unix.go
- zstd_raw.go