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.
Ports packages/ai/src/utils/validation.ts.
Index ¶
- Constants
- Variables
- func APIKeyProviderName(id string) string
- func AbortReason(ctx context.Context) error
- func AdjustMaxTokensForThinking(baseMaxTokens *int, modelMaxTokens int, reasoningLevel string, ...) (maxTokens, thinkingBudget int)
- func AppendAssistantMessageDiagnostic(message *AssistantMessage, diagnostic AssistantMessageDiagnostic)
- func ApplyHTTPProxySettings(httpProxy string) error
- func ApplyOmittedReasoning(model *Model, options *StreamOptions)
- func AssertChatModel(model AnyModel) error
- func AssertClassifierInputSupported(model *ClassifierModel, request ClassifierContext) error
- func AssertClassifierModel(model AnyModel) error
- func AssertImageModel(model AnyModel) error
- func BuildCopilotDynamicHeaders(messages []Message, hasImages bool) map[string]string
- func CalculateContextTokens(usage Usage) int
- func CatalogModelJSON(model AnyModel) (data json.RawMessage, ok bool, err error)
- func CatalogRecordOf(model *Model) string
- func CheckSchemaValue(schema map[string]any, value json.RawMessage) (path, message string, ok bool, err error)
- func ClampMaxTokensToContext(model *Model, context TranscriptContext, maxTokens int) int
- func ClampOpenAIPromptCacheKey(key string) string
- func ClampThinkingBudgetToAnswerRoom(thinkingBudget, ceiling int) int
- func CleanupSessionResources(sessionID string) error
- func CloseOpenAICodexWebSocketSessions(sessionID ...string)
- func CodexAccountID(accessToken string) string
- func CompareThinkingLevels(a, b ModelThinkingLevel) int
- func ConfigureHTTPDispatcher(timeoutMs int) error
- func ConfigureProviderRetry(maxRetries, maxRetryDelayMs int) error
- func ConfiguredHTTPIdleTimeoutMs() int
- func ConfiguredProviderRetry() (maxRetries, maxRetryDelayMs int)
- func ContentText[...](content T, separator ...string) string
- func CredentialStoreProviderEnv(ctx context.Context, store CredentialStore, providerID string) (map[string]string, error)
- func DateParse(s string) float64
- func DateParseHeader(s string) float64
- func DateParseIn(s string, local *time.Location) float64
- func DeclarationsEqual(left, right ToolSchema) bool
- func EncodeModelsCatalog(models []AnyModel) ([]json.RawMessage, error)
- func EncodeStoredModel(model AnyModel) (json.RawMessage, error)
- func ErrorKeyBeforeTimestamp(data []byte) bool
- func EstimateMessageTokens(message Message) int
- func EstimateTextAndImageContentTokens(content UserContent) int
- func EstimateTextTokens(text string) int
- func ExtensionModelRecord(definition json.RawMessage, api API, providerID, baseURL string) string
- func FindEnvKeys(provider string, env map[string]string) []string
- func FormatProviderError(norm NormalizedProviderError, prefix ...string) string
- func FormatThrownValue(value any) string
- func GetBuiltinModelDataGeneratedAt() *float64
- func GetCurrentSystemPrompt[M RoleMessage](messages TranscriptMessages[M]) string
- func GetEnvAPIKey(provider string, env map[string]string) string
- func GetOverflowPatterns() []*regexp.Regexp
- func GetSystemMessageText(message SystemMessage) string
- func HasApi(model AnyModel, api API) bool
- func HasCopilotVisionInput(messages []Message) bool
- func HasNonAdditiveToolChanges[M RoleMessage](messages TranscriptMessages[M]) bool
- func HasToolRedefinitions[M RoleMessage](messages TranscriptMessages[M]) booldeprecated
- func InferCopilotInitiator(msgs []Message) string
- func IsContextOverflow(message AssistantMessage, contextWindow int) bool
- func IsModelType(model AnyModel, modelType ModelType) bool
- func IsOAuthSubscriptionProvider(providerID string) bool
- func IsRecord(value json.RawMessage) 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 LlamaCppLabelProbabilities(logprobs []float64, temperature float64) []float64
- func LlamaCppPeakConfidence(probabilities []float64) float64
- func LlamaCppServerRoot(baseURL string) string
- func MakeStrictJSONSchema(parameters map[string]any, ...) (map[string]any, error)
- func MarshalJSONInSourceOrder(value any, source []byte) ([]byte, error)
- func ModelsAreEqual(a, b AnyModel) bool
- func NormalizeRadiusGatewayURL(value string) string
- func OAuthErrorHTML(message, details string) string
- func OAuthRefreshTimeout(ctx context.Context) (timeout time.Duration, ok bool)
- func OAuthSuccessHTML(message string) string
- func OfferedModels[T AnyModel](models []T) []T
- func OperationSignal(signal context.Context) context.Context
- func ParseJSONWithRepair[T any](data string) (T, error)
- func PiUserAgent() string
- func PollOAuthDeviceCodeFlow[T any](ctx context.Context, opts DeviceCodePollOptions[T]) (T, error)
- func PostClassifierRequest(ctx context.Context, label, target string, model ClassifierModel, payload any, ...) (json.RawMessage, error)
- func ProviderBaseURL(providerID string) string
- func ProviderDisplayName(providerID string) string
- func ProviderHeader(value string) *string
- func ProviderMaxRetries(ctx context.Context) int
- func ProviderStripped(providerID string) bool
- func ProvidersRunOnCaller(ctx context.Context) bool
- func RaceWithAbortSignal[T any](signal context.Context, operation func() (T, error)) (T, error)
- func RegisterAPIProvider(provider APIProvider, sourceID ...string)
- func RegisterBuiltInAPIProviders()
- func RegisterBuiltInImagesAPIProviders()
- func RegisterImagesAPIProvider(provider ImagesAPIProvider, sourceID ...string)
- func RegisterOAuthProvider(id string, provider OAuthProviderInterface)
- func RegisterSessionResourceCleanup(cleanup SessionResourceCleanup) func()
- func ReleaseRequestCaches()
- func RenderSystemMessageUpdate(message SystemMessage) string
- func RequiredNumber(label string, value json.RawMessage, field string) (float64, error)
- func ResetAPIProviders()
- func ResetOAuthProviders()
- func ResetOpenAICodexWebSocketDebugStats(sessionID ...string)
- func ResolveAzureBaseURL(modelBaseURL string, options AzureEndpointOptions) (string, error)
- func ResolveAzureDeploymentName(modelID string, options AzureEndpointOptions) string
- func ResolveCopilotEnvFallback(auth *AuthStorage, envToken string) (bearer, baseURL string, err error)
- func ResolveHTTPProxyURLForTarget(target string, env ProviderEnv) (*url.URL, 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 RetainThoughtSignature(existing, incoming string) string
- func RetryDelayMs(policy RetryPolicy, attempt int) int
- func RetryGoogleRequest[T any](ctx context.Context, request func() (T, error), options ...StreamOptions) (T, error)
- func RetryProviderRequest[T any](ctx context.Context, request func() (T, error), options ProviderRetryOptions) (T, error)
- func RunStreamContinuation(ctx context.Context, body func(*StreamObservation) error) error
- func SafeJsonStringify(value any) string
- func ShortHash(s string) string
- func Sleep(ctx context.Context, ms float64) error
- func StringEnum(values []string, options *StringEnumOptions) map[string]any
- func StrippedModelError(providerID, modelID string) error
- func ThinkingBudgetForLevel(reasoningLevel string, custom *ThinkingBudgets) int
- func TruncateErrorText(text string, maxChars int) string
- func UUIDv7(timestampMs *int64) (string, error)
- func UnregisterAPIProviders(sourceID string)
- func UnregisterOAuthProvider(id string)
- func UsesGoogleThinkingLevel(model *Model) bool
- func ValidateToolArguments(tool ToolSchema, call ToolCall) (map[string]any, error)
- func ValidateToolArgumentsJSON(toolName string, schema, args json.RawMessage) (json.RawMessage, error)
- func ValidateToolArgumentsSchema(toolName string, schema map[string]any, args json.RawMessage) (json.RawMessage, error)
- func ValidateToolCall(tools []ToolSchema, call ToolCall) (map[string]any, error)
- func WithFileReadSnapshot(ctx context.Context) context.Context
- func WithFileReadSnapshotOnCaller(ctx context.Context) context.Context
- func WithOAuthRefreshTimeout(ctx context.Context, timeout time.Duration) context.Context
- func WithProviderMaxRetries(ctx context.Context, maxRetries int) context.Context
- func WithProviderRequestRetry(ctx context.Context, maxRetries int, maxRetryDelayMs *int) context.Context
- func WithStreamContinuations(ctx context.Context) context.Context
- type AIBinding
- type API
- type APIKeyAuth
- type APIKeyAuthInput
- type APIKeyProviderInfo
- type APIProvider
- type APIStreamFunction
- type APIStreamSimpleFunction
- type AnthropicAllowedFallbackModel
- type AnthropicClient
- type AnthropicConfig
- type AnthropicCreateParams
- type AnthropicEffort
- 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 (a AnthropicOAuthProvider) LoginContext(ctx context.Context, callbacks OAuthLoginCallbacks) (OAuthCredentials, error)
- func (AnthropicOAuthProvider) LoginMethodPrompt() OAuthSelectPrompt
- 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 AnthropicRequestOptions
- type AnthropicThinkingDisplay
- type AnyModel
- func AnyModels[T AnyModel](models []T) []AnyModel
- func DecodeModelsCatalog(models []AnyModel, providerID string) ([]AnyModel, error)
- func DecodeStoredModel(data []byte) (model AnyModel, known bool, err error)
- func DecodeStoredModels(records []json.RawMessage) ([]AnyModel, error)
- func GetAllBuiltinModels(provider string) []AnyModel
- func PersonalizeOpenRouterCatalog(catalog []AnyModel, refresh RefreshModelsContext) ([]AnyModel, error)
- type ArgumentMember
- type AssistantContentBlock
- type AssistantContentProjection
- type AssistantEventType
- type AssistantImages
- func GenerateImages(ctx context.Context, model ImageModel, imagesCtx ImagesContext, ...) (AssistantImages, error)
- func GenerateImagesOpenRouter(ctx context.Context, model ImageModel, imagesCtx ImagesContext, ...) AssistantImages
- func ImageErrorResult(model *ImageModel, err error, aborted bool) AssistantImages
- type AssistantMessage
- func Complete(ctx context.Context, model *Model, request Context, options ...StreamOptions) (*AssistantMessage, error)
- func CompleteSimple(ctx context.Context, model *Model, request Context, options ...StreamOptions) (*AssistantMessage, error)
- func FauxAssistantMessage(content FauxAssistantContent, options FauxAssistantMessageOptions) AssistantMessage
- func RetryAssistantCall(ctx context.Context, produce func() (AssistantMessage, error), ...) (AssistantMessage, error)
- func (message AssistantMessage) MarshalJSON() ([]byte, error)
- func (AssistantMessage) MessageRole() string
- func (message *AssistantMessage) Observe() *AssistantMessage
- func (message *AssistantMessage) ObserveProjection(content []AssistantContentProjection) (blocks []AssistantContentProjection, stopReason StopReason, ...)
- func (message *AssistantMessage) ObserveToolCallIdentity(index int) (id, name string, toolCall, indexValid bool)
- func (message *AssistantMessage) ObserveUsage() Usage
- func (message *AssistantMessage) Publication() (cell uintptr, seq uint64)
- func (message *AssistantMessage) ShallowCopy() *AssistantMessage
- func (message *AssistantMessage) UnmarshalJSON(data []byte) error
- type AssistantMessageDiagnostic
- type AssistantMessageEvent
- type AssistantMessageEventStream
- func APIModuleStream(ctx context.Context, model *Model, ...) (*AssistantMessageEventStream, error)
- func LazyStream(ctx context.Context, model *Model, ...) *AssistantMessageEventStream
- func LazyStreamSync(ctx context.Context, model *Model, ...) *AssistantMessageEventStream
- func NewAssistantMessageEventStream() *AssistantMessageEventStream
- func Stream(ctx context.Context, model *Model, request Context, options ...StreamOptions) (*AssistantMessageEventStream, error)
- func StreamAnthropic(ctx context.Context, model *Model, transcript TranscriptContext, ...) (*AssistantMessageEventStream, error)
- func StreamAzureOpenAIResponses(ctx context.Context, model *Model, transcript TranscriptContext, ...) (*AssistantMessageEventStream, error)
- func StreamGoogle(ctx context.Context, model *Model, transcript TranscriptContext, ...) (*AssistantMessageEventStream, error)
- func StreamGoogleVertex(ctx context.Context, model *Model, transcript TranscriptContext, ...) (*AssistantMessageEventStream, error)
- func StreamMistral(ctx context.Context, model *Model, transcript TranscriptContext, ...) (*AssistantMessageEventStream, error)
- func StreamOpenAICodexResponses(ctx context.Context, model *Model, transcript TranscriptContext, ...) (*AssistantMessageEventStream, error)
- func StreamOpenAICompletions(ctx context.Context, model *Model, transcript TranscriptContext, ...) (*AssistantMessageEventStream, error)
- func StreamOpenAIResponses(ctx context.Context, model *Model, transcript TranscriptContext, ...) (*AssistantMessageEventStream, error)
- func StreamSimple(ctx context.Context, model *Model, transcript TranscriptContext, ...) (*AssistantMessageEventStream, error)
- func StreamSimpleAnthropic(ctx context.Context, model *Model, transcript TranscriptContext, ...) (*AssistantMessageEventStream, error)
- func StreamSimpleAzureOpenAIResponses(ctx context.Context, model *Model, transcript TranscriptContext, ...) (*AssistantMessageEventStream, error)
- func StreamSimpleContext(ctx context.Context, model *Model, request Context, options ...StreamOptions) (*AssistantMessageEventStream, error)
- func StreamSimpleGoogle(ctx context.Context, model *Model, transcript TranscriptContext, ...) (*AssistantMessageEventStream, error)
- func StreamSimpleGoogleVertex(ctx context.Context, model *Model, transcript TranscriptContext, ...) (*AssistantMessageEventStream, error)
- func StreamSimpleMistral(ctx context.Context, model *Model, transcript TranscriptContext, ...) (*AssistantMessageEventStream, error)
- func StreamSimpleOpenAICodexResponses(ctx context.Context, model *Model, transcript TranscriptContext, ...) (*AssistantMessageEventStream, error)
- func StreamSimpleOpenAICompletions(ctx context.Context, model *Model, transcript TranscriptContext, ...) (*AssistantMessageEventStream, error)
- func StreamSimpleOpenAIResponses(ctx context.Context, model *Model, transcript TranscriptContext, ...) (*AssistantMessageEventStream, error)
- func (s *AssistantMessageEventStream) End(result ...*AssistantMessage)
- func (s *AssistantMessageEventStream) Events(ctx context.Context) iter.Seq[AssistantMessageEvent]
- func (stream *AssistantMessageEventStream) ForwardStream(ctx context.Context, source *AssistantMessageEventStream) error
- func (stream *AssistantMessageEventStream) ObservationContext(ctx context.Context) context.Context
- func (stream *AssistantMessageEventStream) ObserveEvents(ctx context.Context) iter.Seq2[*StreamObservation, AssistantMessageEvent]
- func (stream *AssistantMessageEventStream) ObservePublishedEvents(ctx context.Context) iter.Seq2[*StreamObservation, AssistantMessageEvent]
- func (s *AssistantMessageEventStream) Push(event AssistantMessageEvent) error
- func (s *AssistantMessageEventStream) Result() *AssistantMessage
- func (s *AssistantMessageEventStream) ResultContext(ctx context.Context) (*AssistantMessage, error)
- type AuthCheck
- type AuthContext
- type AuthDeviceCodeEvent
- type AuthEvent
- type AuthInfoEvent
- type AuthInfoLink
- type AuthInteraction
- type AuthManualCodePrompt
- type AuthOperationOptions
- type AuthProgressEvent
- type AuthPrompt
- type AuthResolutionOverrides
- type AuthResult
- type AuthSecretPrompt
- type AuthSelectOption
- type AuthSelectPrompt
- type AuthSource
- type AuthStatus
- type AuthStorage
- func (a *AuthStorage) Delete(ctx context.Context, 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 AuthTextPrompt
- type AuthType
- type AuthURLEvent
- type AzureConfig
- type AzureEndpointOptions
- type AzureOpenAIResponsesConfig
- type BedrockProvider
- type BedrockThinkingDisplay
- type BlockDeltas
- func (deltas *BlockDeltas) AppendArguments(contentIndex int, current, delta string) string
- func (deltas *BlockDeltas) AppendContent(contentIndex int, current, delta string) string
- func (deltas *BlockDeltas) Release(contentIndex int)
- func (deltas *BlockDeltas) SetStreamingArguments(call *ToolCall, contentIndex int, text string)
- type BuiltinImageProvider
- type CacheRetention
- type ChatModelCatalog
- func AmazonBedrockModels() ChatModelCatalog
- func AntLingModels() ChatModelCatalog
- func AnthropicModels() ChatModelCatalog
- func AzureModels() ChatModelCatalog
- func BasetenModels() ChatModelCatalog
- func CerebrasModels() ChatModelCatalog
- func CloudflareAIGatewayModels() ChatModelCatalog
- func CloudflareWorkersAIModels() ChatModelCatalog
- func DeepSeekModels() ChatModelCatalog
- func FireworksModels() ChatModelCatalog
- func GitHubCopilotModels() ChatModelCatalog
- func GoogleModels() ChatModelCatalog
- func GoogleVertexModels() ChatModelCatalog
- func GroqModels() ChatModelCatalog
- func HuggingFaceModels() ChatModelCatalog
- func KimiCodingModels() ChatModelCatalog
- func MetaModels() ChatModelCatalog
- func MiniMaxCNModels() ChatModelCatalog
- func MiniMaxModels() ChatModelCatalog
- func MistralModels() ChatModelCatalog
- func MoonshotAICNModels() ChatModelCatalog
- func MoonshotAIModels() ChatModelCatalog
- func NVIDIAModels() ChatModelCatalog
- func OpenAICodexModels() ChatModelCatalog
- func OpenAIModels() ChatModelCatalog
- func OpenCodeGoModels() ChatModelCatalog
- func OpenCodeModels() ChatModelCatalog
- func OpenRouterModels() ChatModelCatalog
- func QwenTokenPlanCNModels() ChatModelCatalog
- func QwenTokenPlanIndividualModels() ChatModelCatalog
- func QwenTokenPlanModels() ChatModelCatalog
- func RadiusModels() ChatModelCatalog
- func TogetherModels() ChatModelCatalog
- func TypesafeModels() ChatModelCatalog
- func VercelAIGatewayModels() ChatModelCatalog
- func XAIModels() ChatModelCatalog
- func XiaomiModels() ChatModelCatalog
- func XiaomiTokenPlanAMSModels() ChatModelCatalog
- func XiaomiTokenPlanCNModels() ChatModelCatalog
- func XiaomiTokenPlanSGPModels() ChatModelCatalog
- func ZAICodingCNModels() ChatModelCatalog
- func ZAIModels() ChatModelCatalog
- type ChatTemplateKwargValue
- type ClassifierAPI
- type ClassifierAnswer
- type ClassifierAnswerEntry
- type ClassifierAnswers
- type ClassifierBoolAnswer
- type ClassifierBoolCriteria
- type ClassifierBoolQuestion
- type ClassifierChoiceAnswer
- type ClassifierChoiceCriterion
- type ClassifierChoiceQuestion
- type ClassifierContext
- type ClassifierFunction
- type ClassifierHTTPError
- type ClassifierModel
- type ClassifierModelCatalog
- func AmazonBedrockClassifierModels() ClassifierModelCatalog
- func AntLingClassifierModels() ClassifierModelCatalog
- func AnthropicClassifierModels() ClassifierModelCatalog
- func AzureClassifierModels() ClassifierModelCatalog
- func BasetenClassifierModels() ClassifierModelCatalog
- func CerebrasClassifierModels() ClassifierModelCatalog
- func CloudflareAIGatewayClassifierModels() ClassifierModelCatalog
- func CloudflareWorkersAIClassifierModels() ClassifierModelCatalog
- func DeepSeekClassifierModels() ClassifierModelCatalog
- func FireworksClassifierModels() ClassifierModelCatalog
- func GitHubCopilotClassifierModels() ClassifierModelCatalog
- func GoogleClassifierModels() ClassifierModelCatalog
- func GoogleVertexClassifierModels() ClassifierModelCatalog
- func GroqClassifierModels() ClassifierModelCatalog
- func HuggingFaceClassifierModels() ClassifierModelCatalog
- func KimiCodingClassifierModels() ClassifierModelCatalog
- func MetaClassifierModels() ClassifierModelCatalog
- func MiniMaxCNClassifierModels() ClassifierModelCatalog
- func MiniMaxClassifierModels() ClassifierModelCatalog
- func MistralClassifierModels() ClassifierModelCatalog
- func MoonshotAICNClassifierModels() ClassifierModelCatalog
- func MoonshotAIClassifierModels() ClassifierModelCatalog
- func NVIDIAClassifierModels() ClassifierModelCatalog
- func OpenAIClassifierModels() ClassifierModelCatalog
- func OpenAICodexClassifierModels() ClassifierModelCatalog
- func OpenCodeClassifierModels() ClassifierModelCatalog
- func OpenCodeGoClassifierModels() ClassifierModelCatalog
- func OpenRouterClassifierModels() ClassifierModelCatalog
- func QwenTokenPlanCNClassifierModels() ClassifierModelCatalog
- func QwenTokenPlanClassifierModels() ClassifierModelCatalog
- func QwenTokenPlanIndividualClassifierModels() ClassifierModelCatalog
- func RadiusClassifierModels() ClassifierModelCatalog
- func TogetherClassifierModels() ClassifierModelCatalog
- func TypesafeClassifierModels() ClassifierModelCatalog
- func VercelAIGatewayClassifierModels() ClassifierModelCatalog
- func XAIClassifierModels() ClassifierModelCatalog
- func XiaomiClassifierModels() ClassifierModelCatalog
- func XiaomiTokenPlanAMSClassifierModels() ClassifierModelCatalog
- func XiaomiTokenPlanCNClassifierModels() ClassifierModelCatalog
- func XiaomiTokenPlanSGPClassifierModels() ClassifierModelCatalog
- func ZAIClassifierModels() ClassifierModelCatalog
- func ZAICodingCNClassifierModels() ClassifierModelCatalog
- type ClassifierOptions
- type ClassifierProbability
- type ClassifierQuestion
- type ClassifierQuestionEntry
- type ClassifierQuestions
- type ClassifierResult
- func ClassifierErrorResult(model *ClassifierModel, err error, aborted bool) ClassifierResult
- func ClassifyCloudflareWorkersAISystemOne(ctx context.Context, model ClassifierModel, request ClassifierContext, ...) ClassifierResult
- func ClassifyLlamaCpp(ctx context.Context, model ClassifierModel, request ClassifierContext, ...) ClassifierResult
- func ClassifyOpenAIDecisions(ctx context.Context, model ClassifierModel, request ClassifierContext, ...) ClassifierResult
- func ClassifySystemOne(ctx context.Context, transport SystemOneTransport, model ClassifierModel, ...) ClassifierResult
- func ClassifyTypesafeSystemOne(ctx context.Context, model ClassifierModel, request ClassifierContext, ...) ClassifierResult
- type ClassifierScoreAnswer
- type ClassifierScoreQuestion
- type ClassifierStopReason
- 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 CombinedAbortSignal
- type ConstrainedSamplingConfig
- type ConstrainedSamplingStrict
- type ConstrainedSamplingType
- type ContentBlock
- type ContentBlocks
- type Context
- type ContextTokensSource
- type ContextUsageEstimate
- type ConvertCompletionsMessagesOptions
- type ConvertResponsesMessagesOptions
- type ConvertResponsesToolsOptions
- type CopilotLoginCallbacks
- type CopilotProviderConfig
- type CostTier
- type CreateModelsOptions
- type CreateProviderOptions
- type Credential
- func (c *Credential) ClearExpires()
- func (c Credential) ExpiresMillis() float64
- func (c Credential) HasExpires() bool
- func (c Credential) MarshalJSON() ([]byte, error)
- func (c Credential) OAuthCredentials() OAuthCredentials
- func (c *Credential) SetExpiresMillis(value float64)
- func (c *Credential) UnmarshalJSON(data []byte) error
- type CredentialInfo
- type CredentialStore
- type CredentialType
- type DeferredCancelOptions
- type DeferredFetchOptions
- type DeferredHandle
- type DeferredOption
- type DeviceCodePollOptions
- type DeviceCodePollResult
- type DeviceCodePollStatus
- type DiagnosticCoder
- type DiagnosticErrorInfo
- type DoneEvent
- type ErrorEvent
- type EventStream
- type FauxAssistantContent
- type FauxAssistantMessageOptions
- type FauxConfig
- type FauxContentBlock
- type FauxContentBlockType
- type FauxContentBlocks
- type FauxContentString
- type FauxCore
- type FauxDeferredConfig
- type FauxModelDefinition
- type FauxProviderHandle
- func (p *FauxProviderHandle) API() API
- func (p *FauxProviderHandle) AppendResponses(responses []FauxResponseStep)
- func (p *FauxProviderHandle) CallCount() int
- func (p *FauxProviderHandle) CancelledDeferred() []DeferredHandle
- func (p *FauxProviderHandle) Close() error
- func (p *FauxProviderHandle) DeferredFetchCount() int
- func (p *FauxProviderHandle) GetModel(id ...string) *Model
- func (p *FauxProviderHandle) ID() string
- func (p *FauxProviderHandle) Models() []*Model
- func (p *FauxProviderHandle) PendingResponseCount() int
- func (p *FauxProviderHandle) Provider() *ModelsProvider
- func (p *FauxProviderHandle) SetResponses(responses []FauxResponseStep)
- func (p *FauxProviderHandle) State() *FauxProviderState
- func (p *FauxProviderHandle) Stream(ctx context.Context, request TranscriptContext, options StreamOptions) (*AssistantMessageEventStream, error)
- func (p *FauxProviderHandle) Unregister()
- type FauxProviderRegistration
- type FauxProviderState
- type FauxResponse
- type FauxResponseFactory
- type FauxResponseStep
- type FauxTokenSize
- type FauxToolCallOptions
- type FetchFunction
- 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 GeminiContent
- type GeneratedModel
- type GoogleConfig
- type GoogleSdkThinkingLevel
- type GoogleThinkingLevel
- type GoogleThinkingOptions
- type GoogleVertexConfig
- type GrammarFormat
- type GrammarVariants
- type ImageAPI
- type ImageContent
- type ImageModel
- type ImageModelCatalog
- func AmazonBedrockImageModels() ImageModelCatalog
- func AntLingImageModels() ImageModelCatalog
- func AnthropicImageModels() ImageModelCatalog
- func AzureImageModels() ImageModelCatalog
- func BasetenImageModels() ImageModelCatalog
- func CerebrasImageModels() ImageModelCatalog
- func CloudflareAIGatewayImageModels() ImageModelCatalog
- func CloudflareWorkersAIImageModels() ImageModelCatalog
- func DeepSeekImageModels() ImageModelCatalog
- func FireworksImageModels() ImageModelCatalog
- func GitHubCopilotImageModels() ImageModelCatalog
- func GoogleImageModels() ImageModelCatalog
- func GoogleVertexImageModels() ImageModelCatalog
- func GroqImageModels() ImageModelCatalog
- func HuggingFaceImageModels() ImageModelCatalog
- func KimiCodingImageModels() ImageModelCatalog
- func MetaImageModels() ImageModelCatalog
- func MiniMaxCNImageModels() ImageModelCatalog
- func MiniMaxImageModels() ImageModelCatalog
- func MistralImageModels() ImageModelCatalog
- func MoonshotAICNImageModels() ImageModelCatalog
- func MoonshotAIImageModels() ImageModelCatalog
- func NVIDIAImageModels() ImageModelCatalog
- func OpenAICodexImageModels() ImageModelCatalog
- func OpenAIImageModels() ImageModelCatalog
- func OpenCodeGoImageModels() ImageModelCatalog
- func OpenCodeImageModels() ImageModelCatalog
- func OpenRouterImageModels() ImageModelCatalog
- func QwenTokenPlanCNImageModels() ImageModelCatalog
- func QwenTokenPlanImageModels() ImageModelCatalog
- func QwenTokenPlanIndividualImageModels() ImageModelCatalog
- func RadiusImageModels() ImageModelCatalog
- func TogetherImageModels() ImageModelCatalog
- func TypesafeImageModels() ImageModelCatalog
- func VercelAIGatewayImageModels() ImageModelCatalog
- func XAIImageModels() ImageModelCatalog
- func XiaomiImageModels() ImageModelCatalog
- func XiaomiTokenPlanAMSImageModels() ImageModelCatalog
- func XiaomiTokenPlanCNImageModels() ImageModelCatalog
- func XiaomiTokenPlanSGPImageModels() ImageModelCatalog
- func ZAICodingCNImageModels() ImageModelCatalog
- func ZAIImageModels() ImageModelCatalog
- type ImagesAPIProvider
- type ImagesContext
- type ImagesFunction
- type ImagesInputContent
- type ImagesOptions
- type ImagesOutputContent
- type ImagesStopReason
- type InMemoryAuthStorage
- func (s *InMemoryAuthStorage) Delete(ctx context.Context, providerID string) error
- func (s *InMemoryAuthStorage) List(ctx context.Context) ([]CredentialInfo, error)
- func (s *InMemoryAuthStorage) Modify(ctx context.Context, providerID string, ...) (*Credential, error)
- func (s *InMemoryAuthStorage) Read(ctx context.Context, providerID string) (*Credential, error)
- type InMemoryCredentialStore
- func (s *InMemoryCredentialStore) Delete(ctx context.Context, providerID string) error
- func (s *InMemoryCredentialStore) List(ctx context.Context) ([]CredentialInfo, error)
- func (s *InMemoryCredentialStore) Modify(ctx context.Context, providerID string, ...) (*Credential, error)
- func (s *InMemoryCredentialStore) Read(ctx context.Context, providerID string) (*Credential, error)
- type InMemoryModelsStore
- func (s *InMemoryModelsStore) Delete(ctx context.Context, providerID string) error
- func (s *InMemoryModelsStore) DeleteWith(ctx context.Context, providerID string, options ModelsStoreOperationOptions) error
- func (s *InMemoryModelsStore) Read(ctx context.Context, providerID string) (*ModelsStoreEntry, error)
- func (s *InMemoryModelsStore) ReadWith(ctx context.Context, providerID string, options ModelsStoreOperationOptions) (*ModelsStoreEntry, error)
- func (s *InMemoryModelsStore) Write(ctx context.Context, providerID string, entry ModelsStoreEntry) error
- func (s *InMemoryModelsStore) WriteWith(ctx context.Context, providerID string, entry ModelsStoreEntry, ...) error
- type JsonObject
- type JsonValue
- type KnownProvider
- type LazyAPICapabilities
- type LazyOAuthInput
- type LlamaCppLabeledQuestion
- type LoginOptions
- type Message
- type MistralConfig
- type Model
- func GetBuiltinModel(provider, modelID string) *Model
- func GetBuiltinModels(provider string) []*Model
- func GetRadiusModels(providerID string, credential *Credential) []*Model
- func GetRadiusModelsFromConfig(providerID string, config RadiusGatewayConfig) []*Model
- func ResolveCloudflareModel(model *Model, env ProviderEnv) *Model
- type ModelAuth
- type ModelCapabilities
- type ModelCatalogProvider
- type ModelCompat
- type ModelCost
- type ModelImageInputLimits
- type ModelImageResizeOptions
- type ModelInputLimits
- type ModelInputModality
- type ModelPromptCache
- type ModelThinkingLevel
- type ModelType
- type Models
- func (m *Models) CancelDeferred(ctx context.Context, model *Model, handle DeferredHandle, ...) error
- func (m *Models) CheckAuth(ctx context.Context, providerID string) (*AuthCheck, error)
- func (m *Models) CheckAuthWith(ctx context.Context, providerID string, options AuthOperationOptions) (*AuthCheck, error)
- func (m *Models) Classify(ctx context.Context, model *ClassifierModel, request ClassifierContext, ...) ClassifierResult
- func (m *Models) ClearProviders()
- func (m *Models) Close()
- func (m *Models) Complete(ctx context.Context, model *Model, request Context, options ...StreamOptions) *AssistantMessage
- func (m *Models) CompleteSimple(ctx context.Context, model *Model, request Context, options ...StreamOptions) *AssistantMessage
- func (m *Models) DeleteProvider(id string)
- func (m *Models) FetchDeferred(ctx context.Context, model *Model, handle DeferredHandle, ...) *AssistantMessage
- func (m *Models) GenerateImages(ctx context.Context, model *ImageModel, request ImagesContext, ...) AssistantImages
- func (m *Models) GetAllAvailable(ctx context.Context, providerID ...string) ([]AnyModel, error)
- func (m *Models) GetAllAvailableWith(ctx context.Context, providerID string, options AuthOperationOptions) ([]AnyModel, error)
- func (m *Models) GetAllModels(provider ...string) []AnyModel
- func (m *Models) GetAuth(ctx context.Context, providerID string, overrides ...AuthResolutionOverrides) (*AuthResult, error)
- func (m *Models) GetAvailable(ctx context.Context, providerID ...string) ([]*Model, error)
- func (m *Models) GetAvailableOfType(ctx context.Context, modelType ModelType, providerID ...string) ([]AnyModel, error)
- func (m *Models) GetAvailableOfTypeWith(ctx context.Context, modelType ModelType, providerID string, ...) ([]AnyModel, error)
- func (m *Models) GetAvailableWith(ctx context.Context, providerID string, options AuthOperationOptions) ([]*Model, error)
- func (m *Models) GetModel(provider, id string) *Model
- func (m *Models) GetModelAuth(ctx context.Context, anyModel AnyModel, overrides ...AuthResolutionOverrides) (*AuthResult, error)
- func (m *Models) GetModelOfType(modelType ModelType, provider, id string) AnyModel
- func (m *Models) GetModels(provider ...string) []*Model
- func (m *Models) GetModelsOfType(modelType ModelType, provider ...string) []AnyModel
- func (m *Models) GetProvider(id string) *ModelsProvider
- func (m *Models) GetProviders() []*ModelsProvider
- func (m *Models) Login(ctx context.Context, providerID string, authType AuthType, ...) (Credential, error)
- func (m *Models) LoginProvider(ctx context.Context, provider *ModelsProvider, authType AuthType, ...) (Credential, error)
- func (m *Models) Logout(ctx context.Context, providerID string) error
- func (m *Models) LogoutWith(ctx context.Context, providerID string, options AuthOperationOptions) error
- func (m *Models) Refresh(ctx context.Context, options ...ModelsRefreshOptions) ModelsRefreshResult
- func (m *Models) SetProvider(provider *ModelsProvider)
- func (m *Models) Stream(ctx context.Context, model *Model, request Context, options ...StreamOptions) *AssistantMessageEventStream
- func (m *Models) StreamDeferred(ctx context.Context, model *Model, handle DeferredHandle, ...) *AssistantMessageEventStream
- func (m *Models) StreamSimple(ctx context.Context, model *Model, request Context, options ...StreamOptions) *AssistantMessageEventStream
- type ModelsClassifierOptions
- type ModelsError
- type ModelsErrorCode
- type ModelsImagesOptions
- type ModelsProvider
- func AmazonBedrockProvider() *ModelsProvider
- func AntLingProvider() *ModelsProvider
- func AnthropicProvider() *ModelsProvider
- func AzureProvider() *ModelsProvider
- func BasetenProvider() *ModelsProvider
- func BuiltinProvider() *ModelsProvider
- func BuiltinProviders() []*ModelsProvider
- func CerebrasProvider() *ModelsProvider
- func CloudflareAIGatewayProvider() *ModelsProvider
- func CloudflareWorkersAIProvider() *ModelsProvider
- func CreateProvider(input CreateProviderOptions) *ModelsProvider
- func DeepseekProvider() *ModelsProvider
- func FireworksProvider() *ModelsProvider
- func GithubCopilotProvider() *ModelsProvider
- func GoogleProvider() *ModelsProvider
- func GoogleVertexProvider() *ModelsProvider
- func GroqProvider() *ModelsProvider
- func HuggingFaceProvider() *ModelsProvider
- func KimiCodingProvider() *ModelsProvider
- func MetaProvider() *ModelsProvider
- func MinimaxCnProvider() *ModelsProvider
- func MinimaxProvider() *ModelsProvider
- func MistralProvider() *ModelsProvider
- func MoonshotaiCnProvider() *ModelsProvider
- func MoonshotaiProvider() *ModelsProvider
- func NewRadiusProvider(radiusOptions ...RadiusProviderOptions) *ModelsProvider
- func NvidiaProvider() *ModelsProvider
- func OpenAIProvider() *ModelsProvider
- func OpenCodeGoProvider() *ModelsProvider
- func OpenaiCodexProvider() *ModelsProvider
- func OpenaiProvider() *ModelsProvider
- func OpencodeProvider() *ModelsProvider
- func OpenrouterProvider() *ModelsProvider
- func QwenTokenPlanCnProvider() *ModelsProvider
- func QwenTokenPlanIndividualProvider() *ModelsProvider
- func QwenTokenPlanProvider() *ModelsProvider
- func TogetherProvider() *ModelsProvider
- func TypesafeProvider() *ModelsProvider
- func VercelAIGatewayProvider() *ModelsProvider
- func XaiProvider() *ModelsProvider
- func XiaomiProvider() *ModelsProvider
- func XiaomiTokenPlanAmsProvider() *ModelsProvider
- func XiaomiTokenPlanCnProvider() *ModelsProvider
- func XiaomiTokenPlanSgpProvider() *ModelsProvider
- func ZaiCodingCnProvider() *ModelsProvider
- func ZaiProvider() *ModelsProvider
- type ModelsPublication
- type ModelsRefreshOptions
- type ModelsRefreshResult
- type ModelsStore
- type ModelsStoreEntry
- type ModelsStoreOperationOptions
- type ModelsStreamFunction
- type MutableModels
- type NestedToolCallRecord
- type NestedToolCallStatus
- type NestedToolCalls
- type NodeFetch
- type NormalizedProviderError
- type OAuthAuth
- type OAuthAuthInfo
- type OAuthCallbackOrManualInput
- type OAuthCallbackServer
- type OAuthCallbackServerOptions
- 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 LoginAnthropicCopyCode(ctx context.Context, callbacks OAuthLoginCallbacks) (OAuthCredentials, error)
- func LoginOpenAIChatGPT(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)
- func RefreshOpenAIChatGPTToken(ctx context.Context, credentials OAuthCredentials) (OAuthCredentials, error)
- func (c *OAuthCredentials) ClearExpires()
- func (c OAuthCredentials) ExpiresMillis() float64
- func (c OAuthCredentials) HasExpires() bool
- func (c OAuthCredentials) MarshalJSON() ([]byte, error)
- func (c *OAuthCredentials) SetExpiresMillis(value float64)
- func (c *OAuthCredentials) UnmarshalJSON(data []byte) error
- type OAuthDeviceCodeInfo
- type OAuthLoginCallbacks
- type OAuthPrompt
- type OAuthProviderInterface
- type OAuthSelectOption
- type OAuthSelectPrompt
- type OAuthSubscriptionProvider
- type OpenAIChatGPTOAuthProvider
- func (OpenAIChatGPTOAuthProvider) GetAPIKey(c OAuthCredentials) string
- func (OpenAIChatGPTOAuthProvider) ID() string
- func (OpenAIChatGPTOAuthProvider) IsSubscription() bool
- func (p OpenAIChatGPTOAuthProvider) Login(callbacks OAuthLoginCallbacks) (OAuthCredentials, error)
- func (OpenAIChatGPTOAuthProvider) LoginContext(ctx context.Context, callbacks OAuthLoginCallbacks) (OAuthCredentials, error)
- func (OpenAIChatGPTOAuthProvider) Name() string
- func (p OpenAIChatGPTOAuthProvider) RefreshToken(creds OAuthCredentials) (OAuthCredentials, error)
- func (OpenAIChatGPTOAuthProvider) RefreshTokenContext(ctx context.Context, creds OAuthCredentials) (OAuthCredentials, error)
- func (OpenAIChatGPTOAuthProvider) UsesCallbackServer() bool
- type OpenAIChatMessage
- type OpenAICodexResponsesConfig
- type OpenAICodexWebSocketDebugStats
- type OpenAICompat
- type OpenAIConfig
- type OpenAIResponsesCompat
- type OpenAIResponsesConfig
- type OpenAIResponsesStreamOptions
- type OpenRouterModel
- 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 OpenRouterPricing
- type OpenRouterPricingOverride
- type OpenRouterRate
- type OpenRouterRouting
- type OpenRouterTopProvider
- type OrderedSections
- type PKCE
- type PiMessagesConfig
- type PiMessagesEvent
- type PiMessagesEventType
- type PiMessagesResponseError
- type PiMessagesRewriteImpact
- type PromptSection
- type Provider
- func NewAnthropicProvider(cfg AnthropicConfig) Provider
- func NewAzureOpenAIResponsesProvider(cfg AzureOpenAIResponsesConfig) Provider
- func NewBedrockAPIProvider(model Model) (Provider, error)
- func NewCopilotProvider(cfg CopilotProviderConfig) (Provider, error)
- func NewGoogleProvider(cfg GoogleConfig) Provider
- func NewGoogleVertexAPIProvider(cfg GoogleVertexConfig) (Provider, error)
- func NewGoogleVertexProvider(cfg GoogleVertexConfig) Provider
- func NewMistralAPIProvider(cfg MistralConfig) (Provider, error)
- 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
- func WrapBuiltinProvider(providerID string, provider Provider) Provider
- type ProviderAPIMap
- type ProviderAPIs
- type ProviderAuth
- type ProviderClassifier
- type ProviderClassifierMap
- type ProviderEnv
- type ProviderFactory
- type ProviderHeaders
- type ProviderID
- type ProviderImageAPIMap
- type ProviderImages
- type ProviderImagesOptions
- type ProviderMetadata
- type ProviderRequestError
- type ProviderResponse
- type ProviderRetryOptions
- type ProviderStreams
- func AnthropicMessagesAPI() *ProviderStreams
- func AzureOpenAIResponsesAPI() *ProviderStreams
- func BedrockConverseStreamAPI() *ProviderStreams
- func CloudflareStreams(streams *ProviderStreams) *ProviderStreams
- func GoogleGenerativeAIAPI() *ProviderStreams
- func GoogleVertexAPI() *ProviderStreams
- func LazyAPI(load func(context.Context) (*ProviderStreams, error), ...) *ProviderStreams
- func MistralConversationsAPI() *ProviderStreams
- func OpenAICodexResponsesAPI() *ProviderStreams
- func OpenAICompletionsAPI() *ProviderStreams
- func OpenAIResponsesAPI() *ProviderStreams
- func PiMessagesAPI() *ProviderStreams
- func WithOpenCodeSessionHeader(streams *ProviderStreams) *ProviderStreams
- type RadiusGatewayConfig
- type RadiusGatewayModel
- 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) Auth() ProviderAuth
- func (p *RadiusProvider) FindModel(id string) (*Model, bool)
- func (p *RadiusProvider) Gateway() string
- func (p *RadiusProvider) GetModels() []*Model
- 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) Delete(context.Context, string) error
- 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 RegisterFauxProviderOptions
- type ResolvedGoogleThinkingLevel
- type ResponsesInputItem
- type ResponsesStrictDefault
- type ResponsesTool
- type ResponsesToolFormat
- type RetryCallbacks
- type RetryPolicy
- type RoleMessage
- 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 SamplingParams
- type SamplingParamsByThinkingLevel
- type SessionAffinityFormat
- type SessionResourceCleanup
- type ShallowCapture
- type SplitErrorToolResult
- type StartEvent
- type StopReason
- type StreamContinuation
- type StreamFunction
- type StreamObservation
- func (observation *StreamObservation) Await(wait func() error) error
- func (observation *StreamObservation) AwaitContinuation(continuation *StreamContinuation, wait func() error) error
- func (observation *StreamObservation) AwaitExternal(wait func() error) error
- func (observation *StreamObservation) AwaitTick(wait func() error) error
- func (observation *StreamObservation) Context(ctx context.Context) context.Context
- func (observation *StreamObservation) Owner() StreamOwner
- func (observation *StreamObservation) PrepareContinuation() *StreamContinuation
- func (observation *StreamObservation) Yield()
- type StreamOptions
- type StreamOwner
- type StringEnumOptions
- type SystemContent
- type SystemMessage
- type SystemOneTransport
- type SystemOneWireQuestions
- type SystemOneWireRequest
- type SystemText
- type SystemTextBlocks
- type TestFauxProvider
- type TextContent
- type TextDeltaEvent
- type TextEndEvent
- type TextSignatureV1
- type TextStartEvent
- type ThinkingBudgetLevels
- type ThinkingBudgets
- type ThinkingContent
- type ThinkingDeltaEvent
- type ThinkingEndEvent
- type ThinkingLevel
- type ThinkingLevelMap
- type ThinkingStartEvent
- type ThinkingTokenBudgetField
- type TokenFailure
- type ToolCall
- func (content ToolCall) AppendStringify(dst []byte) ([]byte, error)
- func (content ToolCall) ArgumentMembers() ([]ArgumentMember, error)
- func (content ToolCall) ArgumentsJSON() ([]byte, error)
- func (content *ToolCall) CopyArgumentsFrom(other ToolCall)
- func (content *ToolCall) DefaultFalsyArguments()
- func (content *ToolCall) DeletePartialJson()
- func (content ToolCall) MarshalJSON() ([]byte, error)
- func (content *ToolCall) SetArgumentsJSON(raw []byte) error
- func (content *ToolCall) SetFinalArguments(input string)
- func (content *ToolCall) SetPartialJson(text string)
- func (content *ToolCall) SetStreamingArguments(input string)
- func (content *ToolCall) UnmarshalJSON(data []byte) error
- type ToolCallDeltaEvent
- type ToolCallEndEvent
- type ToolCallStartEvent
- type ToolChoice
- type ToolReference
- type ToolResultMessage
- type ToolResultMessageContent
- type ToolSchema
- type ToolStateChanges
- type TranscriptContext
- type TranscriptMessages
- type TranscriptTools
- type Transport
- type UnsupportedStrictSchemaKeywordCheck
- type Usage
- type UsageCost
- type UserContent
- type UserContentBlock
- type UserContentBlocks
- type UserMessage
- type UserText
- type ValidationMemo
- type VercelGatewayRouting
Constants ¶
const ( AnthropicAuthTokenEnv = "ANTHROPIC_AUTH_TOKEN" AnthropicOAuthTokenEnv = "ANTHROPIC_OAUTH_TOKEN" AnthropicAPIKeyEnv = "ANTHROPIC_API_KEY" AnthropicFederationRuleIDEnv = "ANTHROPIC_FEDERATION_RULE_ID" AnthropicOrganizationIDEnv = "ANTHROPIC_ORGANIZATION_ID" AnthropicServiceAccountIDEnv = "ANTHROPIC_SERVICE_ACCOUNT_ID" AnthropicIdentityTokenFileEnv = "ANTHROPIC_IDENTITY_TOKEN_FILE" AnthropicWorkspaceIDEnv = "ANTHROPIC_WORKSPACE_ID" )
Anthropic credential variables. Mirrors upstream ANTHROPIC_AUTH_TOKEN_ENV, ANTHROPIC_OAUTH_TOKEN_ENV, ANTHROPIC_API_KEY_ENV and the workload identity federation variables of packages/ai/src/env-api-keys.ts.
const ( CloudflareWorkersAIBaseURL = "https://api.cloudflare.com/client/v4/accounts/{CLOUDFLARE_ACCOUNT_ID}/ai/v1" // CloudflareWorkersAIRESTBaseURL is the Workers AI REST endpoint root; model runs are posted to `run` (api/cloudflare.ts:5-7). CloudflareWorkersAIRESTBaseURL = "https://api.cloudflare.com/client/v4/accounts/{CLOUDFLARE_ACCOUNT_ID}/ai" 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 ( // AnthropicBrowserLoginMethod and AnthropicCopyCodeLoginMethod are the login method IDs Anthropic login offers. AnthropicBrowserLoginMethod = "browser" AnthropicCopyCodeLoginMethod = "copy_code" )
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 (test/parity/testdata/test-faux-provider.ts), so both sides report the same context window and output budget.
const AnthropicFederationAuthSource = "workload identity federation"
AnthropicFederationAuthSource is the source the anthropic auth resolver reports when workload identity federation is the only credential. upstream: packages/ai/src/providers/anthropic.ts:68
const AnthropicOAuthDisplayName = "Anthropic (Claude Pro/Max)"
AnthropicOAuthDisplayName is the OAuth method label upstream renders for Claude Pro/Max subscription login.
const CloudflareGatewayBindingAuthSentinel = "cloudflare-gateway-binding"
CloudflareGatewayBindingAuthSentinel is the placeholder value of an auth header on a binding-routed request. API implementations require an API key or a recognized auth header before dispatch; binding calls are pre-authenticated, so a request sends `cf-aig-authorization: Bearer <sentinel>` to satisfy the check, with nil `Authorization` and `x-api-key` headers so no SDK placeholder reaches the gateway (CLOUDFLARE_GATEWAY_BINDING_AUTH_SENTINEL).
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 MaxProviderErrorBodyChars = 4000
const MinAnswerTokens = 1024
MinAnswerTokens is the number of tokens always left for the answer when a thinking budget shares the response ceiling. Mirrors upstream MIN_ANSWER_TOKENS (simple-options.ts:68).
const (
// OpenAIChatGPTOAuthName is the OAuth method name of the openai provider.
OpenAIChatGPTOAuthName = "OpenAI (ChatGPT subscription)"
)
const OpenAICodexOAuthDisplayName = "OpenAI (ChatGPT Plus/Pro)"
OpenAICodexOAuthDisplayName is the OAuth method label upstream renders for ChatGPT Plus/Pro Codex subscription login.
const ProviderImagesOpenRouter = "openrouter"
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.
const UnsupportedProxyProtocolMessage = "Unsupported proxy protocol. SOCKS and PAC proxy URLs are not supported; use an HTTP or HTTPS proxy URL."
Variables ¶
var GeneratedClassifierModels = []ClassifierModel{ {ID: "@cf/cloudflare/clef", Name: "Clef", API: ClassifierAPI("cloudflare-workers-ai-system-one"), Provider: "cloudflare-workers-ai", BaseURL: "https://api.cloudflare.com/client/v4/accounts/{CLOUDFLARE_ACCOUNT_ID}/ai", Input: []string{"text"}, Cost: ModelCost{Input: 0.24, Output: 0, CacheRead: 0, CacheWrite: 0}, ContextWindow: 65536}, {ID: "@cf/cloudflare/clef-flash", Name: "Clef Flash", API: ClassifierAPI("cloudflare-workers-ai-system-one"), Provider: "cloudflare-workers-ai", BaseURL: "https://api.cloudflare.com/client/v4/accounts/{CLOUDFLARE_ACCOUNT_ID}/ai", Input: []string{"text"}, Cost: ModelCost{Input: 0.09, Output: 0, CacheRead: 0, CacheWrite: 0}, ContextWindow: 65536}, {ID: "typesafe/jev", Name: "Jev", API: ClassifierAPI("cloudflare-workers-ai-system-one"), Provider: "cloudflare-workers-ai", BaseURL: "https://api.cloudflare.com/client/v4/accounts/{CLOUDFLARE_ACCOUNT_ID}/ai", Input: []string{"text"}, Cost: ModelCost{Input: 0, Output: 0, CacheRead: 0, CacheWrite: 0}, ContextWindow: 32000}, {ID: "gpt-6-luna", Name: "GPT-6 Luna", API: ClassifierAPI("openai-decisions"), Provider: "openai", BaseURL: "https://api.openai.com/v1", Input: []string{"text", "image"}, Cost: ModelCost{Input: 0.1, Output: 0, CacheRead: 0, CacheWrite: 0, Tiers: []CostTier{{InputTokensAbove: 272000, InputCostPer1M: 0.2, OutputCostPer1M: 0, CacheReadCostPer1M: 0, CacheWriteCostPer1M: 0}}}, ContextWindow: 922000}, {ID: "jev-1.13", Name: "Jev 1.13", API: ClassifierAPI("typesafe-system-one"), Provider: "opencode", BaseURL: "https://opencode.ai/inference/v1", Input: []string{"text"}, Cost: ModelCost{Input: 0.042, Output: 0, CacheRead: 0, CacheWrite: 0}, ContextWindow: 32000}, {ID: "jev-1.13-free", Name: "Jev 1.13 Free", API: ClassifierAPI("typesafe-system-one"), Provider: "opencode", BaseURL: "https://opencode.ai/inference/v1", Input: []string{"text"}, Cost: ModelCost{Input: 0, Output: 0, CacheRead: 0, CacheWrite: 0}, ContextWindow: 32000}, {ID: "~perplexity/pplx-decider-flash-latest", Name: "Perplexity: Decider Flash Latest", API: ClassifierAPI("typesafe-system-one"), Provider: "openrouter", BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, Cost: ModelCost{Input: 0.01, Output: 0, CacheRead: 0, CacheWrite: 0}, ContextWindow: 262144}, {ID: "~perplexity/pplx-decider-latest", Name: "Perplexity: Decider Latest", API: ClassifierAPI("typesafe-system-one"), Provider: "openrouter", BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, Cost: ModelCost{Input: 0.02, Output: 0, CacheRead: 0, CacheWrite: 0}, ContextWindow: 262144}, {ID: "~typesafe/jev-latest", Name: "TypeSafe: Jev Latest", API: ClassifierAPI("typesafe-system-one"), Provider: "openrouter", BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, Cost: ModelCost{Input: 0.042, Output: 0, CacheRead: 0, CacheWrite: 0}, ContextWindow: 262144}, {ID: "cloudflare/clef", Name: "Cloudflare: Clef", API: ClassifierAPI("typesafe-system-one"), Provider: "openrouter", BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, Cost: ModelCost{Input: 0.042, Output: 0, CacheRead: 0, CacheWrite: 0}, ContextWindow: 16384}, {ID: "cloudflare/clef-flash", Name: "Cloudflare: Clef Flash", API: ClassifierAPI("typesafe-system-one"), Provider: "openrouter", BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, Cost: ModelCost{Input: 0.038, Output: 0, CacheRead: 0, CacheWrite: 0}, ContextWindow: 24576}, {ID: "cloudflare/clef-omni", Name: "Cloudflare: Clef Omni", API: ClassifierAPI("typesafe-system-one"), Provider: "openrouter", BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, Cost: ModelCost{Input: 0.15, Output: 0, CacheRead: 0, CacheWrite: 0}, ContextWindow: 65536}, {ID: "inception/mercury-decide", Name: "Inception: Mercury Decide", API: ClassifierAPI("typesafe-system-one"), Provider: "openrouter", BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, Cost: ModelCost{Input: 0.02, Output: 0, CacheRead: 0, CacheWrite: 0}, ContextWindow: 65536}, {ID: "inception/mercury-decide:free", Name: "Inception: Mercury Decide (free)", API: ClassifierAPI("typesafe-system-one"), Provider: "openrouter", BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, Cost: ModelCost{Input: 0, Output: 0, CacheRead: 0, CacheWrite: 0}, ContextWindow: 65536}, {ID: "jaredpalmer/kev-4b", Name: "Jared Palmer: Kev 4B", API: ClassifierAPI("typesafe-system-one"), Provider: "openrouter", BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text"}, Cost: ModelCost{Input: 0.042, Output: 0, CacheRead: 0, CacheWrite: 0}, ContextWindow: 8192}, {ID: "liquid/d1", Name: "LiquidAI: d1", API: ClassifierAPI("typesafe-system-one"), Provider: "openrouter", BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, Cost: ModelCost{Input: 0.02, Output: 0, CacheRead: 0.02, CacheWrite: 0}, ContextWindow: 65536}, {ID: "liquid/d1-ultra", Name: "LiquidAI: d1-ultra", API: ClassifierAPI("typesafe-system-one"), Provider: "openrouter", BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, Cost: ModelCost{Input: 0.042, Output: 0, CacheRead: 0.042, CacheWrite: 0}, ContextWindow: 32768}, {ID: "microsoft/microsoft-decision-1", Name: "Microsoft: Microsoft-Decision-1", API: ClassifierAPI("typesafe-system-one"), Provider: "openrouter", BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text"}, Cost: ModelCost{Input: 0.042, Output: 0, CacheRead: 0, CacheWrite: 0}, ContextWindow: 32768}, {ID: "nace-ai/drex-v1.5", Name: "Nace.AI: Drex v1.5", API: ClassifierAPI("typesafe-system-one"), Provider: "openrouter", BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text"}, Cost: ModelCost{Input: 0.04, Output: 0, CacheRead: 0, CacheWrite: 0}, ContextWindow: 131072}, {ID: "nace-ai/drex-v2.0", Name: "Nace.AI: Drex v2.0", API: ClassifierAPI("typesafe-system-one"), Provider: "openrouter", BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text"}, Cost: ModelCost{Input: 0.06, Output: 0, CacheRead: 0, CacheWrite: 0}, ContextWindow: 131072}, {ID: "openai/gpt-6-luna-decisions", Name: "OpenAI: GPT-6 Luna Decisions", API: ClassifierAPI("typesafe-system-one"), Provider: "openrouter", BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, Cost: ModelCost{Input: 0.1, Output: 0, CacheRead: 0, CacheWrite: 0}, ContextWindow: 1050000}, {ID: "perplexity/pplx-decider-flash-v1.2", Name: "Perplexity: Decider Flash V1.2", API: ClassifierAPI("typesafe-system-one"), Provider: "openrouter", BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, Cost: ModelCost{Input: 0.01, Output: 0, CacheRead: 0, CacheWrite: 0}, ContextWindow: 262144}, {ID: "perplexity/pplx-decider-v1.2", Name: "Perplexity: Decider V1.2", API: ClassifierAPI("typesafe-system-one"), Provider: "openrouter", BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, Cost: ModelCost{Input: 0.02, Output: 0, CacheRead: 0, CacheWrite: 0}, ContextWindow: 262144}, {ID: "respan/span-01", Name: "Respan: Span-01", API: ClassifierAPI("typesafe-system-one"), Provider: "openrouter", BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text"}, Cost: ModelCost{Input: 0.02, Output: 0, CacheRead: 0, CacheWrite: 0}, ContextWindow: 4096}, {ID: "respan/span-01-lite", Name: "Respan: Span-01 Lite", API: ClassifierAPI("typesafe-system-one"), Provider: "openrouter", BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text"}, Cost: ModelCost{Input: 0, Output: 0, CacheRead: 0, CacheWrite: 0}, ContextWindow: 4096}, {ID: "respan/span-01-lite:free", Name: "Respan: Span-01 Lite (free)", API: ClassifierAPI("typesafe-system-one"), Provider: "openrouter", BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text"}, Cost: ModelCost{Input: 0, Output: 0, CacheRead: 0, CacheWrite: 0}, ContextWindow: 4096}, {ID: "respan/span-02", Name: "Respan: Span-02", API: ClassifierAPI("typesafe-system-one"), Provider: "openrouter", BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, Cost: ModelCost{Input: 0.01, Output: 0, CacheRead: 0, CacheWrite: 0}, ContextWindow: 131072}, {ID: "scaledown/classify-1", Name: "ScaleDown: Classify-1", API: ClassifierAPI("typesafe-system-one"), Provider: "openrouter", BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, Cost: ModelCost{Input: 0.04, Output: 0, CacheRead: 0, CacheWrite: 0}, ContextWindow: 1000000}, {ID: "togethercomputer/tev1-4b-experimental", Name: "Together: Tev1 4B Experimental", API: ClassifierAPI("typesafe-system-one"), Provider: "openrouter", BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text"}, Cost: ModelCost{Input: 0.042, Output: 0, CacheRead: 0, CacheWrite: 0}, ContextWindow: 32768}, {ID: "typesafe/jev-1.13", Name: "TypeSafe: Jev 1.13", API: ClassifierAPI("typesafe-system-one"), Provider: "openrouter", BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, Cost: ModelCost{Input: 0.042, Output: 0, CacheRead: 0, CacheWrite: 0}, ContextWindow: 262144}, {ID: "typesafe/jev-1.14", Name: "TypeSafe: Jev 1.14", API: ClassifierAPI("typesafe-system-one"), Provider: "openrouter", BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, Cost: ModelCost{Input: 0.042, Output: 0, CacheRead: 0, CacheWrite: 0}, ContextWindow: 262144}, {ID: "upstage/solar-decide", Name: "Upstage: Solar Decide", API: ClassifierAPI("typesafe-system-one"), Provider: "openrouter", BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text"}, Cost: ModelCost{Input: 0.05, Output: 0, CacheRead: 0.05, CacheWrite: 0}, ContextWindow: 524288}, {ID: "upstage/solar-decide-flash", Name: "Upstage: Solar Decide Flash", API: ClassifierAPI("typesafe-system-one"), Provider: "openrouter", BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text"}, Cost: ModelCost{Input: 0.05, Output: 0, CacheRead: 0.05, CacheWrite: 0}, ContextWindow: 524288}, {ID: "jev-latest", Name: "Jev", API: ClassifierAPI("typesafe-system-one"), Provider: "typesafe", BaseURL: "https://api.typesafe.ai/v1/", Input: []string{"text"}, Cost: ModelCost{Input: 0, Output: 0, CacheRead: 0, CacheWrite: 0}, ContextWindow: 64000}, {ID: "convaiinnovations/laya", Name: "Laya", API: ClassifierAPI("typesafe-system-one"), Provider: "vercel-ai-gateway", BaseURL: "https://ai-gateway.vercel.sh/typesafe/v1", Input: []string{"text"}, Cost: ModelCost{Input: 0, Output: 0, CacheRead: 0, CacheWrite: 0}, ContextWindow: 8192}, {ID: "convaiinnovations/laya-free", Name: "Laya (Free)", API: ClassifierAPI("typesafe-system-one"), Provider: "vercel-ai-gateway", BaseURL: "https://ai-gateway.vercel.sh/typesafe/v1", Input: []string{"text"}, Cost: ModelCost{Input: 0, Output: 0, CacheRead: 0, CacheWrite: 0}, ContextWindow: 8192}, {ID: "liquid/d1", Name: "Liquid d1", API: ClassifierAPI("typesafe-system-one"), Provider: "vercel-ai-gateway", BaseURL: "https://ai-gateway.vercel.sh/typesafe/v1", Input: []string{"text"}, Cost: ModelCost{Input: 0.02, Output: 0, CacheRead: 0, CacheWrite: 0}, ContextWindow: 65536}, {ID: "liquid/d1-ultra", Name: "Liquid d1 Ultra", API: ClassifierAPI("typesafe-system-one"), Provider: "vercel-ai-gateway", BaseURL: "https://ai-gateway.vercel.sh/typesafe/v1", Input: []string{"text"}, Cost: ModelCost{Input: 0.042, Output: 0, CacheRead: 0, CacheWrite: 0}, ContextWindow: 32768}, {ID: "microsoft/microsoft-decision-1", Name: "Decision-1", API: ClassifierAPI("typesafe-system-one"), Provider: "vercel-ai-gateway", BaseURL: "https://ai-gateway.vercel.sh/typesafe/v1", Input: []string{"text"}, Cost: ModelCost{Input: 0.042, Output: 0, CacheRead: 0, CacheWrite: 0}, ContextWindow: 32768}, {ID: "openai/gpt-6-luna-decisions", Name: "GPT-6 Luna Decisions", API: ClassifierAPI("typesafe-system-one"), Provider: "vercel-ai-gateway", BaseURL: "https://ai-gateway.vercel.sh/typesafe/v1", Input: []string{"text"}, Cost: ModelCost{Input: 0.1, Output: 0, CacheRead: 0, CacheWrite: 0}, ContextWindow: 1050000}, {ID: "perplexity/pplx-decider-flash-v1.2", Name: "Decider Flash V1.2 4B", API: ClassifierAPI("typesafe-system-one"), Provider: "vercel-ai-gateway", BaseURL: "https://ai-gateway.vercel.sh/typesafe/v1", Input: []string{"text"}, Cost: ModelCost{Input: 0.01, Output: 0, CacheRead: 0, CacheWrite: 0}, ContextWindow: 262144}, {ID: "perplexity/pplx-decider-v1.2", Name: "Decider V1.2 27B", API: ClassifierAPI("typesafe-system-one"), Provider: "vercel-ai-gateway", BaseURL: "https://ai-gateway.vercel.sh/typesafe/v1", Input: []string{"text"}, Cost: ModelCost{Input: 0.02, Output: 0, CacheRead: 0, CacheWrite: 0}, ContextWindow: 262144}, {ID: "scaledown/scaledown-classify-1", Name: "Classify-1", API: ClassifierAPI("typesafe-system-one"), Provider: "vercel-ai-gateway", BaseURL: "https://ai-gateway.vercel.sh/typesafe/v1", Input: []string{"text"}, Cost: ModelCost{Input: 0.05, Output: 0, CacheRead: 0, CacheWrite: 0}, ContextWindow: 4096}, {ID: "typesafe-ai/jev", Name: "Jev", API: ClassifierAPI("typesafe-system-one"), Provider: "vercel-ai-gateway", BaseURL: "https://ai-gateway.vercel.sh/typesafe/v1", Input: []string{"text"}, Cost: ModelCost{Input: 0.042, Output: 0, CacheRead: 0, CacheWrite: 0}, ContextWindow: 32000}, {ID: "typesafe-ai/jev-1.13.0", Name: "Jev 1.13.0", API: ClassifierAPI("typesafe-system-one"), Provider: "vercel-ai-gateway", BaseURL: "https://ai-gateway.vercel.sh/typesafe/v1", Input: []string{"text"}, Cost: ModelCost{Input: 0.042, Output: 0, CacheRead: 0, CacheWrite: 0}, ContextWindow: 32000}, {ID: "typesafe-ai/jev-1.14.0", Name: "Jev 1.14.0", API: ClassifierAPI("typesafe-system-one"), Provider: "vercel-ai-gateway", BaseURL: "https://ai-gateway.vercel.sh/typesafe/v1", Input: []string{"text"}, Cost: ModelCost{Input: 0.042, Output: 0, CacheRead: 0, CacheWrite: 0}, ContextWindow: 32000}, }
GeneratedClassifierModels is the static classifier model catalog (46 entries).
var GeneratedImageModels = []ImageModel{ {ID: "black-forest-labs/flux-3-image", Name: "Black Forest Labs: FLUX 3 Image", API: ImageAPI("openrouter-images"), Provider: "openrouter", BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, InputLimits: &ModelInputLimits{Images: &ModelImageInputLimits{Resize: &ModelImageResizeOptions{MaxWidth: 2000, MaxHeight: 2000, MaxBytes: 4718592, JPEGQuality: 80}}}, Output: []string{"image"}, Cost: ModelCost{Input: 0, Output: 0, CacheRead: 0, CacheWrite: 0}}, {ID: "black-forest-labs/flux-3-image-klein", Name: "Black Forest Labs: FLUX 3 Image Klein", API: ImageAPI("openrouter-images"), Provider: "openrouter", BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, InputLimits: &ModelInputLimits{Images: &ModelImageInputLimits{Resize: &ModelImageResizeOptions{MaxWidth: 2000, MaxHeight: 2000, MaxBytes: 4718592, JPEGQuality: 80}}}, Output: []string{"image"}, Cost: ModelCost{Input: 0, Output: 0, CacheRead: 0, CacheWrite: 0}}, {ID: "black-forest-labs/flux.2-flex", Name: "Black Forest Labs: FLUX.2 Flex", API: ImageAPI("openrouter-images"), Provider: "openrouter", BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, InputLimits: &ModelInputLimits{Images: &ModelImageInputLimits{Resize: &ModelImageResizeOptions{MaxWidth: 2000, MaxHeight: 2000, MaxBytes: 4718592, JPEGQuality: 80}}}, Output: []string{"image"}, Cost: ModelCost{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: ImageAPI("openrouter-images"), Provider: "openrouter", BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, InputLimits: &ModelInputLimits{Images: &ModelImageInputLimits{Resize: &ModelImageResizeOptions{MaxWidth: 2000, MaxHeight: 2000, MaxBytes: 4718592, JPEGQuality: 80}}}, Output: []string{"image"}, Cost: ModelCost{Input: 0, Output: 0, CacheRead: 0, CacheWrite: 0}}, {ID: "black-forest-labs/flux.2-max", Name: "Black Forest Labs: FLUX.2 Max", API: ImageAPI("openrouter-images"), Provider: "openrouter", BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, InputLimits: &ModelInputLimits{Images: &ModelImageInputLimits{Resize: &ModelImageResizeOptions{MaxWidth: 2000, MaxHeight: 2000, MaxBytes: 4718592, JPEGQuality: 80}}}, Output: []string{"image"}, Cost: ModelCost{Input: 0, Output: 0, CacheRead: 0, CacheWrite: 0}}, {ID: "black-forest-labs/flux.2-pro", Name: "Black Forest Labs: FLUX.2 Pro", API: ImageAPI("openrouter-images"), Provider: "openrouter", BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, InputLimits: &ModelInputLimits{Images: &ModelImageInputLimits{Resize: &ModelImageResizeOptions{MaxWidth: 2000, MaxHeight: 2000, MaxBytes: 4718592, JPEGQuality: 80}}}, Output: []string{"image"}, Cost: ModelCost{Input: 0, Output: 0, CacheRead: 0, CacheWrite: 0}}, {ID: "bytedance-seed/seedream-4.5", Name: "ByteDance Seed: Seedream 4.5", API: ImageAPI("openrouter-images"), Provider: "openrouter", BaseURL: "https://openrouter.ai/api/v1", Input: []string{"image", "text"}, InputLimits: &ModelInputLimits{Images: &ModelImageInputLimits{Resize: &ModelImageResizeOptions{MaxWidth: 2000, MaxHeight: 2000, MaxBytes: 4718592, JPEGQuality: 80}}}, Output: []string{"image"}, Cost: ModelCost{Input: 0, Output: 0, CacheRead: 0, CacheWrite: 0}}, {ID: "bytedance-seed/seedream-5-0-flash", Name: "ByteDance Seed: Seedream 5.0 Flash", API: ImageAPI("openrouter-images"), Provider: "openrouter", BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, InputLimits: &ModelInputLimits{Images: &ModelImageInputLimits{Resize: &ModelImageResizeOptions{MaxWidth: 2000, MaxHeight: 2000, MaxBytes: 4718592, JPEGQuality: 80}}}, Output: []string{"image"}, Cost: ModelCost{Input: 0, Output: 0, CacheRead: 0, CacheWrite: 0}}, {ID: "bytedance-seed/seedream-5-0-lite", Name: "ByteDance Seed: Seedream 5.0 Lite", API: ImageAPI("openrouter-images"), Provider: "openrouter", BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, InputLimits: &ModelInputLimits{Images: &ModelImageInputLimits{Resize: &ModelImageResizeOptions{MaxWidth: 2000, MaxHeight: 2000, MaxBytes: 4718592, JPEGQuality: 80}}}, Output: []string{"image"}, Cost: ModelCost{Input: 0, Output: 0, CacheRead: 0, CacheWrite: 0}}, {ID: "bytedance-seed/seedream-5-0-pro", Name: "ByteDance Seed: Seedream 5.0 Pro", API: ImageAPI("openrouter-images"), Provider: "openrouter", BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, InputLimits: &ModelInputLimits{Images: &ModelImageInputLimits{Resize: &ModelImageResizeOptions{MaxWidth: 2000, MaxHeight: 2000, MaxBytes: 4718592, JPEGQuality: 80}}}, Output: []string{"image"}, Cost: ModelCost{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: ImageAPI("openrouter-images"), Provider: "openrouter", BaseURL: "https://openrouter.ai/api/v1", Input: []string{"image", "text"}, InputLimits: &ModelInputLimits{Images: &ModelImageInputLimits{Resize: &ModelImageResizeOptions{MaxWidth: 2000, MaxHeight: 2000, MaxBytes: 4718592, JPEGQuality: 80}}}, Output: []string{"image", "text"}, Cost: ModelCost{Input: 0.3, Output: 2.5, CacheRead: 0.03, CacheWrite: 0.083333}}, {ID: "google/gemini-3-pro-image", Name: "Google: Nano Banana Pro (Gemini 3 Pro Image)", API: ImageAPI("openrouter-images"), Provider: "openrouter", BaseURL: "https://openrouter.ai/api/v1", Input: []string{"image", "text"}, InputLimits: &ModelInputLimits{Images: &ModelImageInputLimits{Resize: &ModelImageResizeOptions{MaxWidth: 2000, MaxHeight: 2000, MaxBytes: 4718592, JPEGQuality: 80}}}, Output: []string{"image", "text"}, Cost: ModelCost{Input: 2, Output: 12, CacheRead: 0.2, CacheWrite: 0.375}}, {ID: "google/gemini-3-pro-image-preview", Name: "Google: Nano Banana Pro (Gemini 3 Pro Image Preview)", API: ImageAPI("openrouter-images"), Provider: "openrouter", BaseURL: "https://openrouter.ai/api/v1", Input: []string{"image", "text"}, InputLimits: &ModelInputLimits{Images: &ModelImageInputLimits{Resize: &ModelImageResizeOptions{MaxWidth: 2000, MaxHeight: 2000, MaxBytes: 4718592, JPEGQuality: 80}}}, Output: []string{"image", "text"}, Cost: ModelCost{Input: 2, Output: 12, CacheRead: 0.2, CacheWrite: 0.375}}, {ID: "google/gemini-3.1-flash-image", Name: "Google: Nano Banana 2 (Gemini 3.1 Flash Image)", API: ImageAPI("openrouter-images"), Provider: "openrouter", BaseURL: "https://openrouter.ai/api/v1", Input: []string{"image", "text"}, InputLimits: &ModelInputLimits{Images: &ModelImageInputLimits{Resize: &ModelImageResizeOptions{MaxWidth: 2000, MaxHeight: 2000, MaxBytes: 4718592, JPEGQuality: 80}}}, Output: []string{"image", "text"}, Cost: ModelCost{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: ImageAPI("openrouter-images"), Provider: "openrouter", BaseURL: "https://openrouter.ai/api/v1", Input: []string{"image", "text"}, InputLimits: &ModelInputLimits{Images: &ModelImageInputLimits{Resize: &ModelImageResizeOptions{MaxWidth: 2000, MaxHeight: 2000, MaxBytes: 4718592, JPEGQuality: 80}}}, Output: []string{"image", "text"}, Cost: ModelCost{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: ImageAPI("openrouter-images"), Provider: "openrouter", BaseURL: "https://openrouter.ai/api/v1", Input: []string{"image", "text"}, InputLimits: &ModelInputLimits{Images: &ModelImageInputLimits{Resize: &ModelImageResizeOptions{MaxWidth: 2000, MaxHeight: 2000, MaxBytes: 4718592, JPEGQuality: 80}}}, Output: []string{"image", "text"}, Cost: ModelCost{Input: 0.25, Output: 1.5, CacheRead: 0, CacheWrite: 0}}, {ID: "google/gemini-nano-banana-2.1", Name: "Google: Nano Banana 2.1", API: ImageAPI("openrouter-images"), Provider: "openrouter", BaseURL: "https://openrouter.ai/api/v1", Input: []string{"image", "text"}, InputLimits: &ModelInputLimits{Images: &ModelImageInputLimits{Resize: &ModelImageResizeOptions{MaxWidth: 2000, MaxHeight: 2000, MaxBytes: 4718592, JPEGQuality: 80}}}, Output: []string{"image", "text"}, Cost: ModelCost{Input: 1.5, Output: 7.5, CacheRead: 0, CacheWrite: 0}}, {ID: "krea/k3-edit", Name: "Krea: K3 Edit", API: ImageAPI("openrouter-images"), Provider: "openrouter", BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, InputLimits: &ModelInputLimits{Images: &ModelImageInputLimits{Resize: &ModelImageResizeOptions{MaxWidth: 2000, MaxHeight: 2000, MaxBytes: 4718592, JPEGQuality: 80}}}, Output: []string{"image"}, Cost: ModelCost{Input: 0, Output: 0, CacheRead: 0, CacheWrite: 0}}, {ID: "krea/krea-2-large", Name: "Krea: Krea 2 Large", API: ImageAPI("openrouter-images"), Provider: "openrouter", BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, InputLimits: &ModelInputLimits{Images: &ModelImageInputLimits{Resize: &ModelImageResizeOptions{MaxWidth: 2000, MaxHeight: 2000, MaxBytes: 4718592, JPEGQuality: 80}}}, Output: []string{"image"}, Cost: ModelCost{Input: 0, Output: 0, CacheRead: 0, CacheWrite: 0}}, {ID: "krea/krea-2-medium", Name: "Krea: Krea 2 Medium", API: ImageAPI("openrouter-images"), Provider: "openrouter", BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, InputLimits: &ModelInputLimits{Images: &ModelImageInputLimits{Resize: &ModelImageResizeOptions{MaxWidth: 2000, MaxHeight: 2000, MaxBytes: 4718592, JPEGQuality: 80}}}, Output: []string{"image"}, Cost: ModelCost{Input: 0, Output: 0, CacheRead: 0, CacheWrite: 0}}, {ID: "krea/krea-2-medium-turbo", Name: "Krea: Krea 2 Medium Turbo", API: ImageAPI("openrouter-images"), Provider: "openrouter", BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, InputLimits: &ModelInputLimits{Images: &ModelImageInputLimits{Resize: &ModelImageResizeOptions{MaxWidth: 2000, MaxHeight: 2000, MaxBytes: 4718592, JPEGQuality: 80}}}, Output: []string{"image"}, Cost: ModelCost{Input: 0, Output: 0, CacheRead: 0, CacheWrite: 0}}, {ID: "meta/muse-image", Name: "Meta: Muse Image", API: ImageAPI("openrouter-images"), Provider: "openrouter", BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, InputLimits: &ModelInputLimits{Images: &ModelImageInputLimits{Resize: &ModelImageResizeOptions{MaxWidth: 2000, MaxHeight: 2000, MaxBytes: 4718592, JPEGQuality: 80}}}, Output: []string{"image"}, Cost: ModelCost{Input: 0, Output: 0, CacheRead: 0, CacheWrite: 0}}, {ID: "microsoft/mai-image-2.5", Name: "Microsoft AI: MAI-Image-2.5", API: ImageAPI("openrouter-images"), Provider: "openrouter", BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, InputLimits: &ModelInputLimits{Images: &ModelImageInputLimits{Resize: &ModelImageResizeOptions{MaxWidth: 2000, MaxHeight: 2000, MaxBytes: 4718592, JPEGQuality: 80}}}, Output: []string{"image"}, Cost: ModelCost{Input: 5, Output: 0, CacheRead: 0, CacheWrite: 0}}, {ID: "microsoft/mai-image-2.5-pro", Name: "Microsoft AI: MAI-Image-2.5 Pro", API: ImageAPI("openrouter-images"), Provider: "openrouter", BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, InputLimits: &ModelInputLimits{Images: &ModelImageInputLimits{Resize: &ModelImageResizeOptions{MaxWidth: 2000, MaxHeight: 2000, MaxBytes: 4718592, JPEGQuality: 80}}}, Output: []string{"image"}, Cost: ModelCost{Input: 5, Output: 0, CacheRead: 0, CacheWrite: 0}}, {ID: "microsoft/mai-image-2.6", Name: "Microsoft AI: MAI-Image-2.6", API: ImageAPI("openrouter-images"), Provider: "openrouter", BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, InputLimits: &ModelInputLimits{Images: &ModelImageInputLimits{Resize: &ModelImageResizeOptions{MaxWidth: 2000, MaxHeight: 2000, MaxBytes: 4718592, JPEGQuality: 80}}}, Output: []string{"image"}, Cost: ModelCost{Input: 5, Output: 0, CacheRead: 0, CacheWrite: 0}}, {ID: "microsoft/mai-image-2.6-flash", Name: "Microsoft AI: MAI-Image-2.6 Flash", API: ImageAPI("openrouter-images"), Provider: "openrouter", BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, InputLimits: &ModelInputLimits{Images: &ModelImageInputLimits{Resize: &ModelImageResizeOptions{MaxWidth: 2000, MaxHeight: 2000, MaxBytes: 4718592, JPEGQuality: 80}}}, Output: []string{"image"}, Cost: ModelCost{Input: 1.75, Output: 0, CacheRead: 0, CacheWrite: 0}}, {ID: "openai/gpt-5-image", Name: "OpenAI: GPT-5 Image", API: ImageAPI("openrouter-images"), Provider: "openrouter", BaseURL: "https://openrouter.ai/api/v1", Input: []string{"image", "text"}, InputLimits: &ModelInputLimits{Images: &ModelImageInputLimits{Resize: &ModelImageResizeOptions{MaxWidth: 2000, MaxHeight: 2000, MaxBytes: 4718592, JPEGQuality: 80}}}, Output: []string{"image", "text"}, Cost: ModelCost{Input: 10, Output: 10, CacheRead: 1.25, CacheWrite: 0}}, {ID: "openai/gpt-5-image-mini", Name: "OpenAI: GPT-5 Image Mini", API: ImageAPI("openrouter-images"), Provider: "openrouter", BaseURL: "https://openrouter.ai/api/v1", Input: []string{"image", "text"}, InputLimits: &ModelInputLimits{Images: &ModelImageInputLimits{Resize: &ModelImageResizeOptions{MaxWidth: 2000, MaxHeight: 2000, MaxBytes: 4718592, JPEGQuality: 80}}}, Output: []string{"image", "text"}, Cost: ModelCost{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: ImageAPI("openrouter-images"), Provider: "openrouter", BaseURL: "https://openrouter.ai/api/v1", Input: []string{"image", "text"}, InputLimits: &ModelInputLimits{Images: &ModelImageInputLimits{Resize: &ModelImageResizeOptions{MaxWidth: 2000, MaxHeight: 2000, MaxBytes: 4718592, JPEGQuality: 80}}}, Output: []string{"image", "text"}, Cost: ModelCost{Input: 8, Output: 15, CacheRead: 2, CacheWrite: 0}}, {ID: "openai/gpt-image-1", Name: "OpenAI: GPT Image 1", API: ImageAPI("openrouter-images"), Provider: "openrouter", BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, InputLimits: &ModelInputLimits{Images: &ModelImageInputLimits{Resize: &ModelImageResizeOptions{MaxWidth: 2000, MaxHeight: 2000, MaxBytes: 4718592, JPEGQuality: 80}}}, Output: []string{"image"}, Cost: ModelCost{Input: 10, Output: 10, CacheRead: 1.25, CacheWrite: 0}}, {ID: "openai/gpt-image-1-mini", Name: "OpenAI: GPT Image 1 Mini", API: ImageAPI("openrouter-images"), Provider: "openrouter", BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, InputLimits: &ModelInputLimits{Images: &ModelImageInputLimits{Resize: &ModelImageResizeOptions{MaxWidth: 2000, MaxHeight: 2000, MaxBytes: 4718592, JPEGQuality: 80}}}, Output: []string{"image"}, Cost: ModelCost{Input: 2.5, Output: 2.5, CacheRead: 0.25, CacheWrite: 0}}, {ID: "openai/gpt-image-2", Name: "OpenAI: GPT Image 2", API: ImageAPI("openrouter-images"), Provider: "openrouter", BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, InputLimits: &ModelInputLimits{Images: &ModelImageInputLimits{Resize: &ModelImageResizeOptions{MaxWidth: 2000, MaxHeight: 2000, MaxBytes: 4718592, JPEGQuality: 80}}}, Output: []string{"image"}, Cost: ModelCost{Input: 8, Output: 8, CacheRead: 2, CacheWrite: 0}}, {ID: "openai/gpt-image-2.5-flare", Name: "OpenAI: GPT Image 2.5 Flare", API: ImageAPI("openrouter-images"), Provider: "openrouter", BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, InputLimits: &ModelInputLimits{Images: &ModelImageInputLimits{Resize: &ModelImageResizeOptions{MaxWidth: 2000, MaxHeight: 2000, MaxBytes: 4718592, JPEGQuality: 80}}}, Output: []string{"image"}, Cost: ModelCost{Input: 8, Output: 8, CacheRead: 2, CacheWrite: 0}}, {ID: "openai/gpt-image-2.5-sunburst", Name: "OpenAI: GPT Image 2.5 Sunburst", API: ImageAPI("openrouter-images"), Provider: "openrouter", BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, InputLimits: &ModelInputLimits{Images: &ModelImageInputLimits{Resize: &ModelImageResizeOptions{MaxWidth: 2000, MaxHeight: 2000, MaxBytes: 4718592, JPEGQuality: 80}}}, Output: []string{"image"}, Cost: ModelCost{Input: 8, Output: 8, CacheRead: 2, CacheWrite: 0}}, {ID: "openrouter/auto", Name: "Auto Router", API: ImageAPI("openrouter-images"), Provider: "openrouter", BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, InputLimits: &ModelInputLimits{Images: &ModelImageInputLimits{Resize: &ModelImageResizeOptions{MaxWidth: 2000, MaxHeight: 2000, MaxBytes: 4718592, JPEGQuality: 80}}}, Output: []string{"text", "image"}, Cost: ModelCost{Input: 0, Output: 0, CacheRead: 0, CacheWrite: 0}}, {ID: "openrouter/auto-beta", Name: "Auto Router (Beta)", API: ImageAPI("openrouter-images"), Provider: "openrouter", BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, InputLimits: &ModelInputLimits{Images: &ModelImageInputLimits{Resize: &ModelImageResizeOptions{MaxWidth: 2000, MaxHeight: 2000, MaxBytes: 4718592, JPEGQuality: 80}}}, Output: []string{"text", "image"}, Cost: ModelCost{Input: 0, Output: 0, CacheRead: 0, CacheWrite: 0}}, {ID: "qwen/qwen-image-2.1-pro", Name: "Qwen: Qwen Image 2.1 Pro", API: ImageAPI("openrouter-images"), Provider: "openrouter", BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, InputLimits: &ModelInputLimits{Images: &ModelImageInputLimits{Resize: &ModelImageResizeOptions{MaxWidth: 2000, MaxHeight: 2000, MaxBytes: 4718592, JPEGQuality: 80}}}, Output: []string{"image"}, Cost: ModelCost{Input: 0, Output: 0, CacheRead: 0, CacheWrite: 0}}, {ID: "qwen/qwen-image-2.1-turbo", Name: "Qwen: Qwen Image 2.1 Turbo", API: ImageAPI("openrouter-images"), Provider: "openrouter", BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, InputLimits: &ModelInputLimits{Images: &ModelImageInputLimits{Resize: &ModelImageResizeOptions{MaxWidth: 2000, MaxHeight: 2000, MaxBytes: 4718592, JPEGQuality: 80}}}, Output: []string{"image"}, Cost: ModelCost{Input: 0, Output: 0, CacheRead: 0, CacheWrite: 0}}, {ID: "qwen/qwen-image-3", Name: "Qwen: Qwen Image 3", API: ImageAPI("openrouter-images"), Provider: "openrouter", BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, InputLimits: &ModelInputLimits{Images: &ModelImageInputLimits{Resize: &ModelImageResizeOptions{MaxWidth: 2000, MaxHeight: 2000, MaxBytes: 4718592, JPEGQuality: 80}}}, Output: []string{"image"}, Cost: ModelCost{Input: 0, Output: 0, CacheRead: 0, CacheWrite: 0}}, {ID: "qwen/qwen-image-3-pro", Name: "Qwen: Qwen Image 3 Pro", API: ImageAPI("openrouter-images"), Provider: "openrouter", BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, InputLimits: &ModelInputLimits{Images: &ModelImageInputLimits{Resize: &ModelImageResizeOptions{MaxWidth: 2000, MaxHeight: 2000, MaxBytes: 4718592, JPEGQuality: 80}}}, Output: []string{"image"}, Cost: ModelCost{Input: 0, Output: 0, CacheRead: 0, CacheWrite: 0}}, {ID: "recraft/recraft-v3", Name: "Recraft: Recraft V3", API: ImageAPI("openrouter-images"), Provider: "openrouter", BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, InputLimits: &ModelInputLimits{Images: &ModelImageInputLimits{Resize: &ModelImageResizeOptions{MaxWidth: 2000, MaxHeight: 2000, MaxBytes: 4718592, JPEGQuality: 80}}}, Output: []string{"image"}, Cost: ModelCost{Input: 0, Output: 0, CacheRead: 0, CacheWrite: 0}}, {ID: "recraft/recraft-v4", Name: "Recraft: Recraft V4", API: ImageAPI("openrouter-images"), Provider: "openrouter", BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, InputLimits: &ModelInputLimits{Images: &ModelImageInputLimits{Resize: &ModelImageResizeOptions{MaxWidth: 2000, MaxHeight: 2000, MaxBytes: 4718592, JPEGQuality: 80}}}, Output: []string{"image"}, Cost: ModelCost{Input: 0, Output: 0, CacheRead: 0, CacheWrite: 0}}, {ID: "recraft/recraft-v4-pro", Name: "Recraft: Recraft V4 Pro", API: ImageAPI("openrouter-images"), Provider: "openrouter", BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, InputLimits: &ModelInputLimits{Images: &ModelImageInputLimits{Resize: &ModelImageResizeOptions{MaxWidth: 2000, MaxHeight: 2000, MaxBytes: 4718592, JPEGQuality: 80}}}, Output: []string{"image"}, Cost: ModelCost{Input: 0, Output: 0, CacheRead: 0, CacheWrite: 0}}, {ID: "recraft/recraft-v4-pro-vector", Name: "Recraft: Recraft V4 Pro Vector", API: ImageAPI("openrouter-images"), Provider: "openrouter", BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, InputLimits: &ModelInputLimits{Images: &ModelImageInputLimits{Resize: &ModelImageResizeOptions{MaxWidth: 2000, MaxHeight: 2000, MaxBytes: 4718592, JPEGQuality: 80}}}, Output: []string{"image"}, Cost: ModelCost{Input: 0, Output: 0, CacheRead: 0, CacheWrite: 0}}, {ID: "recraft/recraft-v4-styles", Name: "Recraft: Recraft V4 Styles", API: ImageAPI("openrouter-images"), Provider: "openrouter", BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, InputLimits: &ModelInputLimits{Images: &ModelImageInputLimits{Resize: &ModelImageResizeOptions{MaxWidth: 2000, MaxHeight: 2000, MaxBytes: 4718592, JPEGQuality: 80}}}, Output: []string{"image"}, Cost: ModelCost{Input: 0, Output: 0, CacheRead: 0, CacheWrite: 0}}, {ID: "recraft/recraft-v4-styles-pro", Name: "Recraft: Recraft V4 Styles Pro", API: ImageAPI("openrouter-images"), Provider: "openrouter", BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, InputLimits: &ModelInputLimits{Images: &ModelImageInputLimits{Resize: &ModelImageResizeOptions{MaxWidth: 2000, MaxHeight: 2000, MaxBytes: 4718592, JPEGQuality: 80}}}, Output: []string{"image"}, Cost: ModelCost{Input: 0, Output: 0, CacheRead: 0, CacheWrite: 0}}, {ID: "recraft/recraft-v4-styles-pro-vector", Name: "Recraft: Recraft V4 Styles Pro Vector", API: ImageAPI("openrouter-images"), Provider: "openrouter", BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, InputLimits: &ModelInputLimits{Images: &ModelImageInputLimits{Resize: &ModelImageResizeOptions{MaxWidth: 2000, MaxHeight: 2000, MaxBytes: 4718592, JPEGQuality: 80}}}, Output: []string{"image"}, Cost: ModelCost{Input: 0, Output: 0, CacheRead: 0, CacheWrite: 0}}, {ID: "recraft/recraft-v4-styles-vector", Name: "Recraft: Recraft V4 Styles Vector", API: ImageAPI("openrouter-images"), Provider: "openrouter", BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, InputLimits: &ModelInputLimits{Images: &ModelImageInputLimits{Resize: &ModelImageResizeOptions{MaxWidth: 2000, MaxHeight: 2000, MaxBytes: 4718592, JPEGQuality: 80}}}, Output: []string{"image"}, Cost: ModelCost{Input: 0, Output: 0, CacheRead: 0, CacheWrite: 0}}, {ID: "recraft/recraft-v4-vector", Name: "Recraft: Recraft V4 Vector", API: ImageAPI("openrouter-images"), Provider: "openrouter", BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, InputLimits: &ModelInputLimits{Images: &ModelImageInputLimits{Resize: &ModelImageResizeOptions{MaxWidth: 2000, MaxHeight: 2000, MaxBytes: 4718592, JPEGQuality: 80}}}, Output: []string{"image"}, Cost: ModelCost{Input: 0, Output: 0, CacheRead: 0, CacheWrite: 0}}, {ID: "recraft/recraft-v4.1", Name: "Recraft: Recraft V4.1", API: ImageAPI("openrouter-images"), Provider: "openrouter", BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, InputLimits: &ModelInputLimits{Images: &ModelImageInputLimits{Resize: &ModelImageResizeOptions{MaxWidth: 2000, MaxHeight: 2000, MaxBytes: 4718592, JPEGQuality: 80}}}, Output: []string{"image"}, Cost: ModelCost{Input: 0, Output: 0, CacheRead: 0, CacheWrite: 0}}, {ID: "recraft/recraft-v4.1-flash", Name: "Recraft: Recraft V4.1 Flash", API: ImageAPI("openrouter-images"), Provider: "openrouter", BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text"}, Output: []string{"image"}, Cost: ModelCost{Input: 0, Output: 0, CacheRead: 0, CacheWrite: 0}}, {ID: "recraft/recraft-v4.1-pro", Name: "Recraft: Recraft V4.1 Pro", API: ImageAPI("openrouter-images"), Provider: "openrouter", BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, InputLimits: &ModelInputLimits{Images: &ModelImageInputLimits{Resize: &ModelImageResizeOptions{MaxWidth: 2000, MaxHeight: 2000, MaxBytes: 4718592, JPEGQuality: 80}}}, Output: []string{"image"}, Cost: ModelCost{Input: 0, Output: 0, CacheRead: 0, CacheWrite: 0}}, {ID: "recraft/recraft-v4.1-pro-vector", Name: "Recraft: Recraft V4.1 Pro Vector", API: ImageAPI("openrouter-images"), Provider: "openrouter", BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, InputLimits: &ModelInputLimits{Images: &ModelImageInputLimits{Resize: &ModelImageResizeOptions{MaxWidth: 2000, MaxHeight: 2000, MaxBytes: 4718592, JPEGQuality: 80}}}, Output: []string{"image"}, Cost: ModelCost{Input: 0, Output: 0, CacheRead: 0, CacheWrite: 0}}, {ID: "recraft/recraft-v4.1-utility", Name: "Recraft: Recraft V4.1 Utility", API: ImageAPI("openrouter-images"), Provider: "openrouter", BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, InputLimits: &ModelInputLimits{Images: &ModelImageInputLimits{Resize: &ModelImageResizeOptions{MaxWidth: 2000, MaxHeight: 2000, MaxBytes: 4718592, JPEGQuality: 80}}}, Output: []string{"image"}, Cost: ModelCost{Input: 0, Output: 0, CacheRead: 0, CacheWrite: 0}}, {ID: "recraft/recraft-v4.1-utility-pro", Name: "Recraft: Recraft V4.1 Utility Pro", API: ImageAPI("openrouter-images"), Provider: "openrouter", BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, InputLimits: &ModelInputLimits{Images: &ModelImageInputLimits{Resize: &ModelImageResizeOptions{MaxWidth: 2000, MaxHeight: 2000, MaxBytes: 4718592, JPEGQuality: 80}}}, Output: []string{"image"}, Cost: ModelCost{Input: 0, Output: 0, CacheRead: 0, CacheWrite: 0}}, {ID: "recraft/recraft-v4.1-vector", Name: "Recraft: Recraft V4.1 Vector", API: ImageAPI("openrouter-images"), Provider: "openrouter", BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, InputLimits: &ModelInputLimits{Images: &ModelImageInputLimits{Resize: &ModelImageResizeOptions{MaxWidth: 2000, MaxHeight: 2000, MaxBytes: 4718592, JPEGQuality: 80}}}, Output: []string{"image"}, Cost: ModelCost{Input: 0, Output: 0, CacheRead: 0, CacheWrite: 0}}, {ID: "sourceful/riverflow-v2-fast", Name: "Sourceful: Riverflow V2 Fast", API: ImageAPI("openrouter-images"), Provider: "openrouter", BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, InputLimits: &ModelInputLimits{Images: &ModelImageInputLimits{Resize: &ModelImageResizeOptions{MaxWidth: 2000, MaxHeight: 2000, MaxBytes: 4718592, JPEGQuality: 80}}}, Output: []string{"image"}, Cost: ModelCost{Input: 0, Output: 0, CacheRead: 0, CacheWrite: 0}}, {ID: "sourceful/riverflow-v2-pro", Name: "Sourceful: Riverflow V2 Pro", API: ImageAPI("openrouter-images"), Provider: "openrouter", BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, InputLimits: &ModelInputLimits{Images: &ModelImageInputLimits{Resize: &ModelImageResizeOptions{MaxWidth: 2000, MaxHeight: 2000, MaxBytes: 4718592, JPEGQuality: 80}}}, Output: []string{"image"}, Cost: ModelCost{Input: 0, Output: 0, CacheRead: 0, CacheWrite: 0}}, {ID: "sourceful/riverflow-v2.5-fast", Name: "Sourceful: Riverflow V2.5 Fast", API: ImageAPI("openrouter-images"), Provider: "openrouter", BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, InputLimits: &ModelInputLimits{Images: &ModelImageInputLimits{Resize: &ModelImageResizeOptions{MaxWidth: 2000, MaxHeight: 2000, MaxBytes: 4718592, JPEGQuality: 80}}}, Output: []string{"image"}, Cost: ModelCost{Input: 0, Output: 0, CacheRead: 0, CacheWrite: 0}}, {ID: "sourceful/riverflow-v2.5-pro", Name: "Sourceful: Riverflow V2.5 Pro", API: ImageAPI("openrouter-images"), Provider: "openrouter", BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, InputLimits: &ModelInputLimits{Images: &ModelImageInputLimits{Resize: &ModelImageResizeOptions{MaxWidth: 2000, MaxHeight: 2000, MaxBytes: 4718592, JPEGQuality: 80}}}, Output: []string{"image"}, Cost: ModelCost{Input: 0, Output: 0, CacheRead: 0, CacheWrite: 0}}, {ID: "tencent/hy-image-v3.5-preview", Name: "Tencent: Hy Image 3.5 Preview", API: ImageAPI("openrouter-images"), Provider: "openrouter", BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, InputLimits: &ModelInputLimits{Images: &ModelImageInputLimits{Resize: &ModelImageResizeOptions{MaxWidth: 2000, MaxHeight: 2000, MaxBytes: 4718592, JPEGQuality: 80}}}, Output: []string{"image"}, Cost: ModelCost{Input: 0, Output: 0, CacheRead: 0, CacheWrite: 0}}, {ID: "x-ai/grok-imagine-image-2.0", Name: "xAI: Grok Imagine Image 2.0", API: ImageAPI("openrouter-images"), Provider: "openrouter", BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, InputLimits: &ModelInputLimits{Images: &ModelImageInputLimits{Resize: &ModelImageResizeOptions{MaxWidth: 2000, MaxHeight: 2000, MaxBytes: 4718592, JPEGQuality: 80}}}, Output: []string{"image"}, Cost: ModelCost{Input: 0, Output: 0, CacheRead: 0, CacheWrite: 0}}, {ID: "x-ai/grok-imagine-image-quality", Name: "SpaceXAI: Grok Imagine Image Quality", API: ImageAPI("openrouter-images"), Provider: "openrouter", BaseURL: "https://openrouter.ai/api/v1", Input: []string{"text", "image"}, InputLimits: &ModelInputLimits{Images: &ModelImageInputLimits{Resize: &ModelImageResizeOptions{MaxWidth: 2000, MaxHeight: 2000, MaxBytes: 4718592, JPEGQuality: 80}}}, Output: []string{"image"}, Cost: ModelCost{Input: 0, Output: 0, CacheRead: 0, CacheWrite: 0}}, }
GeneratedImageModels is the static image model catalog (63 entries).
var GeneratedModelDataGeneratedAt = new(float64(1792361307278))
GeneratedModelDataGeneratedAt is the generation time shared by every built-in provider catalog, in Unix milliseconds (providers/all.ts getBuiltinModelDataGeneratedAt); nil when the data manifest carries no valid time.
var GeneratedModels = []GeneratedModel{}/* 1618 elements not displayed */
GeneratedModels is the static catalog (1618 entries).
var GeneratedProviders = []string{
"amazon-bedrock",
"ant-ling",
"anthropic",
"azure",
"baseten",
"cerebras",
"cloudflare-ai-gateway",
"cloudflare-workers-ai",
"deepseek",
"fireworks",
"github-copilot",
"google",
"google-vertex",
"groq",
"huggingface",
"kimi-coding",
"meta",
"minimax",
"minimax-cn",
"mistral",
"moonshotai",
"moonshotai-cn",
"nvidia",
"openai",
"openai-codex",
"opencode",
"opencode-go",
"openrouter",
"qwen-token-plan",
"qwen-token-plan-cn",
"qwen-token-plan-individual",
"radius",
"together",
"typesafe",
"vercel-ai-gateway",
"xai",
"xiaomi",
"xiaomi-token-plan-ams",
"xiaomi-token-plan-cn",
"xiaomi-token-plan-sgp",
"zai",
"zai-coding-cn",
}
GeneratedProviders lists the catalog barrel's providers in barrel order (providers/all.ts getBuiltinProviders).
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 "" when the provider has no built-in API-key auth method.
func AbortReason ¶
AbortReason is signal.reason for a cancelled ctx: the error an aborted operation rejects with, as signal.throwIfAborted() and raceWithAbortSignal do. A plain cancellation is Node's DOMException AbortError, "This operation was aborted", wrapping context.Canceled; a cancellation cause keeps its own error. It is nil while ctx is live.
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 AppendAssistantMessageDiagnostic ¶
func AppendAssistantMessageDiagnostic(message *AssistantMessage, diagnostic AssistantMessageDiagnostic)
AppendAssistantMessageDiagnostic replaces the message's diagnostics with a new slice that ends with diagnostic, so a slice shared with another message is never written through (utils/diagnostics.ts appendAssistantMessageDiagnostic).
func ApplyHTTPProxySettings ¶
ApplyHTTPProxySettings sets absent HTTP_PROXY and HTTPS_PROXY variables. An explicitly empty environment value remains authoritative.
func ApplyOmittedReasoning ¶
func ApplyOmittedReasoning(model *Model, options *StreamOptions)
ApplyOmittedReasoning sets the native thinking options a simple stream sends when `reasoning` is omitted: Anthropic disables thinking and Google and Vertex send `thinking: { enabled: false }` unless the caller supplied native thinking.
func AssertChatModel ¶
AssertChatModel rejects a model whose type is not chat (model-operations.ts assertChatModel).
func AssertClassifierInputSupported ¶
func AssertClassifierInputSupported(model *ClassifierModel, request ClassifierContext) error
AssertClassifierInputSupported rejects classifier images for a model whose catalog entry does not accept image input (model-operations.ts assertClassifierInputSupported).
func AssertClassifierModel ¶
AssertClassifierModel rejects a model whose type is not classifier (model-operations.ts assertClassifierModel).
func AssertImageModel ¶
AssertImageModel rejects a model whose type is not image (model-operations.ts assertImageModel).
func BuildCopilotDynamicHeaders ¶
BuildCopilotDynamicHeaders returns the per-request Copilot headers. Ports github-copilot-headers.ts buildCopilotDynamicHeaders.
func CalculateContextTokens ¶
CalculateContextTokens returns the context size a usage block reports: the provider total, else the sum of its components.
func CatalogModelJSON ¶
func CatalogModelJSON(model AnyModel) (data json.RawMessage, ok bool, err error)
CatalogModelJSON is the JSON object of a model that came from a catalog record, the built-in catalog or a models store, as Pi serializes that model object: the record's members in the record's order, with the record's own bytes for every member the model still holds at its catalog value. ok is false for a model without a record.
func CatalogRecordOf ¶
CatalogRecordOf is the catalog record model was made from, its built-in catalog entry or the models store record it was decoded from, as a JSON object in the record's member order, or "" for a model of neither. A model built from it again (GeneratedModel.Record) encodes with CatalogModelJSON in that order.
func CheckSchemaValue ¶
func CheckSchemaValue(schema map[string]any, value json.RawMessage) (path, message string, ok bool, err error)
CheckSchemaValue checks value, a JSON text, against the JSON schema as TypeBox's validator does, with no conversion and no coercion. A value that matches returns ok. Otherwise it returns the instance path of the first error, dotted with the leading slash removed and "root" for the whole value, and its message.
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 ClampThinkingBudgetToAnswerRoom ¶
ClampThinkingBudgetToAnswerRoom caps a thinking budget so at least MinAnswerTokens remain under a shared response ceiling. Mirrors upstream clampThinkingBudgetToAnswerRoom (simple-options.ts:88).
func CleanupSessionResources ¶
CleanupSessionResources calls every registered cleanup hook with the session id, in registration order, and keeps going when one panics (a JavaScript throw). It returns nil when every hook returned, and otherwise an error whose message is "Failed to cleanup session resources" and that wraps each hook's failure (session-resources.ts cleanupSessionResources throws an AggregateError). An empty session id is `undefined`.
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 is Pi's getAccountId (openai-codex.ts:310): the chatgpt_account_id claim of the access token, "" when the token lacks the JWT shape or the claim. Pi's decodeJwt reads the payload with atob and JSON.parse, so the claim is read as Latin-1 characters of the decoded bytes.
func CompareThinkingLevels ¶
func CompareThinkingLevels(a, b ModelThinkingLevel) 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 ContentText ¶
func ContentText[T string | UserText | SystemText | []AssistantContentBlock | []ToolResultMessageContent | UserContentBlocks | SystemTextBlocks | ContentBlocks](content T, separator ...string) string
ContentText extracts text blocks in order and joins them with a newline, or the supplied separator. String content passes through unchanged.
func CredentialStoreProviderEnv ¶
func CredentialStoreProviderEnv(ctx context.Context, store CredentialStore, providerID string) (map[string]string, error)
CredentialStoreProviderEnv returns the provider-scoped environment overrides of providerID's API-key credential in store, or nil. It mirrors AuthStorage.GetProviderEnv over any CredentialStore.
func DateParse ¶
DateParse is JavaScript's Date.parse of a JavaScript string: milliseconds since the epoch, or NaN when V8 does not recognise the string. A string that names no zone is local time. The Go string is UTF-8, so U+00A0 and U+FEFF are single white space code units as in V8.
func DateParseHeader ¶
DateParseHeader is Date.parse of an HTTP header value, which Node holds as a ByteString: each byte is one code unit.
func DateParseIn ¶
DateParseIn is DateParse with the zone V8 applies to a string that names none: the zone of a caller that does not use the process's local one.
func DeclarationsEqual ¶
func DeclarationsEqual(left, right ToolSchema) bool
DeclarationsEqual reports whether two tools marshal to the same declaration, prompt guidelines aside. Plain trees are compared in place; anything else is marshaled, as before.
func EncodeModelsCatalog ¶
func EncodeModelsCatalog(models []AnyModel) ([]json.RawMessage, error)
EncodeModelsCatalog writes models as their persisted JSON records, the Pi model shapes a provider object receives and returns.
func EncodeStoredModel ¶
func EncodeStoredModel(model AnyModel) (json.RawMessage, error)
EncodeStoredModel is the persisted catalog record of a model; a model that was decoded from a record re-encodes with its unknown fields and field order.
func ErrorKeyBeforeTimestamp ¶
ErrorKeyBeforeTimestamp reports whether the top-level "errorMessage" member of an assistant message object precedes its "timestamp" member: JavaScript keeps the order a message was built in, and a stored message decodes to the order it holds.
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 EstimateTextAndImageContentTokens ¶
func EstimateTextAndImageContentTokens(content UserContent) int
EstimateTextAndImageContentTokens estimates string or block content at 3.5 characters per token, counting each image as 4800 characters (estimate.ts estimateTextAndImageContentTokens).
func EstimateTextTokens ¶
EstimateTextTokens estimates text at 3.5 characters per token.
func ExtensionModelRecord ¶
func ExtensionModelRecord(definition json.RawMessage, api API, providerID, baseURL string) string
ExtensionModelRecord is the catalog record of the chat model an extension registers from definition, a model definition as the extension wrote it: Pi's `{ ...definition, api, provider, baseUrl, headers: undefined }` (provider-composer.ts extensionModelFromDefinition). The definition's members keep the extension's order; api, provider and baseUrl take their place when the definition has them and follow in that order when it does not; headers is undefined, so it is no member of the object. A model built from the record (GeneratedModel.Record) encodes with CatalogModelJSON as Pi serializes it. A definition that is not a JSON object has no record ("").
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 FormatProviderError ¶
func FormatProviderError(norm NormalizedProviderError, prefix ...string) string
FormatProviderError adds body/status only when they are not already carried by the message. Omit prefix to return the unprefixed provider error.
func FormatThrownValue ¶
FormatThrownValue renders a thrown value as text: an error reports its message, or its name when the message is empty, a string is itself, and anything else is formatted like String(value). A nil value is `undefined` (utils/diagnostics.ts formatThrownValue).
func GetBuiltinModelDataGeneratedAt ¶
func GetBuiltinModelDataGeneratedAt() *float64
GetBuiltinModelDataGeneratedAt returns the generation time shared by every built-in provider catalog, in Unix milliseconds, or nil when the data manifest records no valid time. Mirrors upstream providers/all.ts:getBuiltinModelDataGeneratedAt.
func GetCurrentSystemPrompt ¶
func GetCurrentSystemPrompt[M RoleMessage](messages TranscriptMessages[M]) string
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 GetSystemMessageText ¶
func GetSystemMessageText(message SystemMessage) string
GetSystemMessageText renders a system message as its content followed by its non-removed sections (upstream getSystemMessageText).
func HasApi ¶
HasApi reports whether model is a chat model on api. Non-chat models never match, even on an equal api string.
func HasCopilotVisionInput ¶
HasCopilotVisionInput reports whether any message carries image content, including images returned by tools (e.g. the read tool reading a PNG). Triggers the Copilot-Vision-Request header. Ports github-copilot-headers.ts hasCopilotVisionInput, which checks both user messages and tool-result messages for image blocks.
func HasNonAdditiveToolChanges ¶
func HasNonAdditiveToolChanges[M RoleMessage](messages TranscriptMessages[M]) bool
func HasToolRedefinitions
deprecated
func HasToolRedefinitions[M RoleMessage](messages TranscriptMessages[M]) bool
HasToolRedefinitions reports whether a tool name was declared twice with different definitions. A transport that can only reference previously declared tools by name cannot replay such a history.
Deprecated: No built-in transport needs this anymore: Anthropic expresses redefinitions with inline tool_definition blocks. Pi keeps it for API compatibility.
func InferCopilotInitiator ¶
InferCopilotInitiator returns "agent" if the most recent message is from the assistant or a tool result, "user" otherwise. Ports packages/ai/src/api/github-copilot-headers.ts inferCopilotInitiator.
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 IsModelType ¶
IsModelType reports whether model has the given type, including chat models without an explicit Type.
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 IsRecord ¶
func IsRecord(value json.RawMessage) bool
IsRecord reports whether value is a JSON object, like classifier-shared.ts isRecord (a non-null, non-array object).
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). It counts the text JSON.stringify writes: no HTML escaping, negative zero as 0, line separators literally.
func ListProviders ¶
func ListProviders() []string
ListProviders returns the provider ids of the generated catalog barrel in barrel order. Mirrors upstream providers/all.ts:getBuiltinProviders (Object.keys(MODELS)) and compat.ts:getProviders; a provider with only image or classifier models is included.
func ListRuntimeProviders ¶
func ListRuntimeProviders() []string
ListRuntimeProviders returns providers with an implemented runtime API.
func LlamaCppLabelProbabilities ¶
LlamaCppLabelProbabilities is the softmax over label log-probabilities after dividing them by temperature.
func LlamaCppPeakConfidence ¶
LlamaCppPeakConfidence is TypeSafe's documented choice confidence, (n * peak - 1) / (n - 1), clamped to [0, 1].
func LlamaCppServerRoot ¶
LlamaCppServerRoot is the server root: llama.cpp models use the OpenAI-compatible /v1 URL as their base URL.
func MakeStrictJSONSchema ¶
func MakeStrictJSONSchema(parameters map[string]any, isUnsupportedKeyword UnsupportedStrictSchemaKeywordCheck) (map[string]any, error)
MakeStrictJSONSchema converts a tool schema to the strict subset accepted by provider constrained sampling without mutating the authored schema. A nil isUnsupportedKeyword rejects no keyword. A Go map has no key order, so objects take their keys in sorted order here; a ToolSchema keeps its authored order through resolveJSONSchemaStrictSampling.
func MarshalJSONInSourceOrder ¶
MarshalJSONInSourceOrder encodes value with the object member order of the JSON text source. Members source does not have follow in sorted order. A source that is not JSON gives sorted order.
func ModelsAreEqual ¶
ModelsAreEqual compares model IDs and declared provider IDs independently of backend construction. Native models without provider metadata use their backend's provider ID. Mirrors upstream models.ts:modelsAreEqual.
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 OAuthRefreshTimeout ¶
OAuthRefreshTimeout returns the timeout that alone bounds the refresh signal, or ok false when the refresh signal is a caller's cancellation.
func OAuthSuccessHTML ¶
OAuthSuccessHTML returns the HTML page shown on successful OAuth callback.
func OfferedModels ¶
func OfferedModels[T AnyModel](models []T) []T
OfferedModels returns models without the chat models of a stripped API. The generated catalog listing (ListModels) and every Models collection read pass their models through it, so a stripped API's models are offered nowhere: not by --list-models, /model, the --models scope, startup's default model, RPC or the extension model registry. An exact catalog lookup (LookupModel, LookupModelExact) still finds such a model, so that using one reports the strip. pig additive (D92): Stock PiG strips no API and returns models unchanged.
func OperationSignal ¶
OperationSignal normalizes an optional public signal without imposing a deadline: a nil signal becomes a context that is never cancelled.
upstream: packages/ai/src/utils/abort.ts:operationSignal
func ParseJSONWithRepair ¶
ParseJSONWithRepair parses json into T and, when strict parsing fails, parses the repairJSON rewrite instead. It returns the strict error when the repair changes nothing (upstream utils/json-parse.ts parseJsonWithRepair).
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. Times are floating-point milliseconds as in upstream, so a NaN or infinite interval or expiry behaves as it does there. Mirrors upstream pollOAuthDeviceCodeFlow.
func PostClassifierRequest ¶
func PostClassifierRequest(ctx context.Context, label, target string, model ClassifierModel, payload any, options ClassifierOptions, noRetryStatuses []int) (json.RawMessage, error)
PostClassifierRequest posts one JSON classifier request with bearer auth, the OnPayload and OnResponse hooks, a fresh timeout per attempt, and provider retries. It returns the response body, which is valid JSON; failures are errors. noRetryStatuses lists HTTP statuses that fail at once although they are normally retried.
func ProviderBaseURL ¶
ProviderBaseURL returns the upstream provider.baseUrl of a built-in provider, or "" when the provider declares none.
func ProviderDisplayName ¶
ProviderDisplayName returns the upstream provider.name for a built-in provider, or providerID when the provider is not in the catalog.
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 ProviderStripped ¶
ProviderStripped reports whether every generated catalog model of providerID is on a stripped API, so the provider offers no model and is no login provider. A provider without catalog models is never stripped. Matching ignores case. pig additive (D92): Stock PiG strips no API, so this is always false there.
func ProvidersRunOnCaller ¶
ProvidersRunOnCaller reports whether ctx belongs to an operation that carries a file-read snapshot over this package's own stores (WithFileReadSnapshotOnCaller), and so runs no extension code and reads no caller-supplied store.
func RaceWithAbortSignal ¶
RaceWithAbortSignal runs operation and stops waiting for it when signal is cancelled. The operation is never interrupted: it runs to completion on its own goroutine and its result is dropped, so an abandoned operation is observed through settlement as in the upstream promise race. The cancellation cause is returned when the signal wins, including a signal that is already cancelled when the race starts; otherwise the operation's value and error are returned. A nil signal waits for the operation alone.
upstream: packages/ai/src/utils/abort.ts:raceWithAbortSignal
func RegisterAPIProvider ¶
func RegisterAPIProvider(provider APIProvider, sourceID ...string)
RegisterAPIProvider registers an API implementation under an optional source id, replacing any earlier one for the same API (compat.ts registerApiProvider). The registry holds a wrapped copy whose streams reject a model of another API. The built-in implementations register first, as compat.ts registers them when it loads, so an override replaces the built-in.
func RegisterBuiltInAPIProviders ¶
func RegisterBuiltInAPIProviders()
RegisterBuiltInAPIProviders registers the built-in API implementations without replacing an entry that is already registered, so an override registered earlier survives (compat.ts registerBuiltInApiProviders). The registry runs it once at first use, as compat.ts runs it on import.
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, sourceID ...string)
RegisterImagesAPIProvider registers or replaces an image API provider. The optional sourceID names the registering source and is stored on the entry (registerImagesApiProvider(provider, sourceId?)); Pi keeps it without reading it.
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 ReleaseRequestCaches ¶
func ReleaseRequestCaches()
ReleaseRequestCaches forgets every encoding the request caches hold: large strings and finalized messages. The next request encodes what it sends again, as it would have the first time; a build that runs meanwhile finds nothing to splice and encodes its values itself, so its body is the same. pig additive (D112): an interactive session that went idle calls it from its idle collection (D172), so the encodings of the conversation it sent do not stay live while it waits.
func RenderSystemMessageUpdate ¶
func RenderSystemMessageUpdate(message SystemMessage) string
RenderSystemMessageUpdate joins instruction blocks with newlines and frames section changes using literal names.
func RequiredNumber ¶
func ResetAPIProviders ¶
func ResetAPIProviders()
ResetAPIProviders clears the registry and registers the built-in implementations again (compat.ts resetApiProviders).
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 ResolveAzureBaseURL ¶
func ResolveAzureBaseURL(modelBaseURL string, options AzureEndpointOptions) (string, error)
ResolveAzureBaseURL resolves the endpoint from the explicit option, AZURE_OPENAI_BASE_URL, the resource name, then the model's base URL, and normalizes it.
func ResolveAzureDeploymentName ¶
func ResolveAzureDeploymentName(modelID string, options AzureEndpointOptions) string
ResolveAzureDeploymentName returns the request model's deployment name: the explicit option, else the AZURE_OPENAI_DEPLOYMENT_NAME_MAP entry for the model, else the model ID. The map is parsed as upstream parseDeploymentNameMap does: each entry is trimmed with String.prototype.trim and split with split("=", 2), which drops the text after a second "="; a later entry for the same model replaces an earlier one; and a model mapped to an empty name falls back to the model ID.
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 ResolveHTTPProxyURLForTarget ¶
func ResolveHTTPProxyURLForTarget(target string, env ProviderEnv) (*url.URL, error)
ResolveHTTPProxyURLForTarget resolves scoped/process proxy aliases and NO_PROXY exclusions. It rejects non-HTTP proxy protocols before a request is sent.
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 RetainThoughtSignature ¶
RetainThoughtSignature keeps the signature already on a streamed block unless the incoming part carries a non-empty one. Ports packages/ai/src/api/google-shared.ts retainThoughtSignature: it never moves signatures across parts, it only prevents an overwrite with an empty value within one block.
func RetryDelayMs ¶
func RetryDelayMs(policy RetryPolicy, attempt int) int
RetryDelayMs returns the capped exponential delay for a 1-based attempt from the policy base delay and agent cap (only BaseDelayMs and MaxAgentDelayMs are read). Overflowing products saturate at Number.MAX_SAFE_INTEGER before the cap.
func RetryGoogleRequest ¶
func RetryGoogleRequest[T any](ctx context.Context, request func() (T, error), options ...StreamOptions) (T, error)
RetryGoogleRequest is google-shared.ts retryGoogleRequest: retryProviderRequest for the Google SDK, whose ApiError has a status but no headers. A status-only error is given `headers: undefined`, so it is retried by status, and the caller still receives the error it threw. Retries and the delay cap come from the stream options; the context is their AbortSignal.
func RetryProviderRequest ¶
func RetryProviderRequest[T any](ctx context.Context, request func() (T, error), options ProviderRetryOptions) (T, error)
RetryProviderRequest ports provider-retry.ts retryProviderRequest: the request runs again after a retryable ProviderRequestError, the backoff sleep is interruptible by ctx, and a provider-requested delay above MaxRetryDelayMs fails at once. A failure that is not a ProviderRequestError, or whose status is in NoRetryStatuses, is returned as is.
func RunStreamContinuation ¶
func RunStreamContinuation(ctx context.Context, body func(*StreamObservation) error) error
RunStreamContinuation owns a caller's synchronous stream-creation prefix through iteration. The context must carry the shared reaction queue from WithStreamContinuations. The callback uses observation.Context(ctx) for its iterator and Yield when awaiting an already-returned stream.
func SafeJsonStringify ¶
SafeJsonStringify formats JSON-compatible values without HTML escaping and falls back to their Go string representation when encoding fails.
func ShortHash ¶
ShortHash ports upstream packages/ai/src/utils/hash.ts shortHash: a 32-bit non-cryptographic hash rendered as two base36 numbers. Iterating UTF-16 code units with uint32 arithmetic (matching JS Math.imul low-32-bit wrap and `>>>`) keeps the output byte-identical to upstream for the tool-call ids it hashes.
func Sleep ¶
Sleep waits ms milliseconds as Node's setTimeout would, or until ctx is cancelled. A context that is already cancelled fails at once, even for a zero delay, and a cancellation during the wait stops the timer. Both return the cancellation cause, as the upstream promise rejects with signal.reason.
upstream: packages/ai/src/utils/sleep.ts:1
func StringEnum ¶
func StringEnum(values []string, options *StringEnumOptions) map[string]any
StringEnum creates a string enum JSON schema compatible with Google's API and other providers that do not support anyOf/const patterns: {"type":"string","enum":values} plus the description and default when they are non-empty (typebox-helpers.ts:14-24).
func StrippedModelError ¶
StrippedModelError reports the strip that keeps a catalog model from being offered: the stripped API of providerID's catalog model modelID or, when that catalog lacks modelID, the stripped API of a provider whose catalog models are all on stripped APIs. An empty providerID matches modelID under every provider. Matching ignores case, as model resolution does. It returns nil when no strip explains the model's absence. pig additive (D92): Stock PiG strips no API, so this is always nil there.
func ThinkingBudgetForLevel ¶
func ThinkingBudgetForLevel(reasoningLevel string, custom *ThinkingBudgets) int
ThinkingBudgetForLevel is the token budget for a reasoning level: a configured budget replaces the default, whatever its value, and xhigh and max use the high budget. A level without a budget (for example "off") yields zero. Mirrors upstream thinkingBudgetForLevel (api/simple-options.ts:81).
func TruncateErrorText ¶
TruncateErrorText caps error text in UTF-16 units and reports the number of omitted units.
func UUIDv7 ¶
UUIDv7 returns a time-ordered UUIDv7. A nil timestamp uses the wall clock and never moves backwards; a supplied timestamp is preserved exactly for follower ids. A process-wide 41-bit sequence seeded from randomness keeps ids unique and ordered within one millisecond.
func UnregisterAPIProviders ¶
func UnregisterAPIProviders(sourceID string)
UnregisterAPIProviders removes every implementation registered under a source id (compat.ts unregisterApiProviders).
func UnregisterOAuthProvider ¶
func UnregisterOAuthProvider(id string)
UnregisterOAuthProvider removes a custom OAuth provider. Mirrors upstream unregisterOAuthProvider (oauth/index.ts:74).
func UsesGoogleThinkingLevel ¶
UsesGoogleThinkingLevel reports whether the model takes Gemini's discrete thinkingLevel control instead of the token-based thinkingBudget control. The levels a model supports come from its thinking-level map; this only selects the Google wire format. Mirrors upstream usesGoogleThinkingLevel (google-shared.ts), which lowercases the id before every comparison.
func ValidateToolArguments ¶
func ValidateToolArguments(tool ToolSchema, call ToolCall) (map[string]any, error)
ValidateToolArguments clones, prepares optional nulls, coerces and validates the call's arguments without changing the provider call. The arguments are read in the call's member order, as Pi's are, so the received arguments of a validation error list them in that order. The schema is read in its authored member order (ParametersJSON), as Pi validates tool.parameters itself (validation.ts:317-341), so its errors follow that order.
func ValidateToolArgumentsJSON ¶
func ValidateToolArgumentsJSON(toolName string, schema, args json.RawMessage) (json.RawMessage, error)
ValidateToolArgumentsJSON validates arguments against a JSON schema and returns the validated arguments with the member order of args, which is what an agent passes to hooks and execution. An empty schema accepts any object.
func ValidateToolArgumentsSchema ¶
func ValidateToolArgumentsSchema(toolName string, schema map[string]any, args json.RawMessage) (json.RawMessage, error)
ValidateToolArgumentsSchema is ValidateToolArgumentsJSON for a schema held as a map; a nil schema accepts any object.
func ValidateToolCall ¶
func ValidateToolCall(tools []ToolSchema, call ToolCall) (map[string]any, error)
ValidateToolCall finds the tool the call names and validates the call's arguments against its schema. It returns an error when no tool has the name or validation fails.
func WithFileReadSnapshot ¶
WithFileReadSnapshot starts one model operation's file-read snapshot: its auth.json and models-store.json reads stat once while no write replaces what they read. Only an operation that runs no extension code between its reads may carry one.
func WithFileReadSnapshotOnCaller ¶
WithFileReadSnapshotOnCaller is WithFileReadSnapshot for an operation whose credential and models stores are this package's own (the file and in-memory ones): an offline one does no I/O but reads of their one view, so its providers may run one after another on the caller (ProvidersRunOnCaller). A caller-supplied store reads with the caller's code, which can wait on anything; Pi races each provider's refresh and check with the caller's signal (models.ts:586,605,684), so an operation over one keeps a goroutine per provider and settles when the caller cancels while its reads finish on their own.
func WithOAuthRefreshTimeout ¶
WithOAuthRefreshTimeout marks the context of a provider refresh whose signal Pi builds as AbortSignal.timeout(timeout): the caller's cancellation does not reach it (auth/resolve.ts:refreshStoredOAuthCredential). A provider that hands its callback a signal, such as an extension bridge, reads the timeout with OAuthRefreshTimeout.
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 AIBinding ¶
type AIBinding struct {
Fetch FetchFunction
}
AIBinding is the Workers AI binding (`env.AI`). Fetch is the binding's `fetch()` passthrough; it is optional because the published binding type does not declare it, so CreateAIBindingFetch checks it. Upstream's `aiGatewayLogId` member only pins the TypeScript type to the AI binding and has no behaviour, so Go does not carry it.
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.
func StrippableAPIs ¶
func StrippableAPIs() []API
StrippableAPIs lists the APIs a Piglet can strip (strip.apis). A Piglet Binary compiles each one's implementation out with the build tag pig_strip_<api> (see internal/pigstrip.Tag), and a Piglet that Stock PiG runs disables it at runtime. A stripped API's models are not offered (OfferedModels), and building a provider for one of them fails. pig additive (D92): Stock PiG strips no API.
type APIKeyAuth ¶
type APIKeyAuth struct {
Name string
// Login performs provider-owned setup. Nil denotes ambient-only authentication.
Login func(context.Context, AuthInteraction) (Credential, error)
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.
func (*APIKeyAuth) AuthMethodName ¶
func (a *APIKeyAuth) AuthMethodName() string
AuthMethodName is the method's display name, which the provider selector searches (oauth-selector.ts:136 `provider.method?.name`).
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).
func APIKeyProviders ¶
func APIKeyProviders() []APIKeyProviderInfo
APIKeyProviders returns the built-in providers that expose an API-key auth method, sorted by provider.name.
Mirrors upstream interactive-mode.ts:getLoginProviderOptions filtered by auth.apiKey: upstream iterates ModelRuntime.getProviders() (the whole catalog) rather than a hand-maintained subset, so a provider such as opencode-go appears in /login → "Sign in with an API key". Deriving the list here keeps a newly added upstream provider from being silently omitted. pig additive (D92): a provider whose catalog models are all on stripped APIs (ProviderStripped) is left out.
type APIProvider ¶
type APIProvider struct {
API API
Stream StreamFunction
StreamSimple StreamFunction
}
APIProvider is one API implementation in the global API registry (compat.ts ApiProvider).
func GetAPIProvider ¶
func GetAPIProvider(api API) *APIProvider
GetAPIProvider returns the registered implementation of an API, or nil (compat.ts getApiProvider).
func GetAPIProviders ¶
func GetAPIProviders() []*APIProvider
GetAPIProviders lists the registered implementations in registration order (compat.ts getApiProviders).
type APIStreamFunction ¶
type APIStreamFunction = ModelsStreamFunction
APIStreamFunction is a registered API's stream (compat.ts ApiStreamFunction).
type APIStreamSimpleFunction ¶
type APIStreamSimpleFunction = ModelsStreamFunction
APIStreamSimpleFunction is a registered API's simple stream (compat.ts ApiStreamSimpleFunction).
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 AnthropicClient ¶
type AnthropicClient interface {
// CreateMessage sends the streaming Messages request and returns its raw response. ctx carries the request's abort. The provider reads the streamed events from the response body and handles a non-success status itself. A retryable failure that implements ProviderRequestError is retried within StreamOptions.MaxRetries, as retryProviderRequest does for Pi's client.
CreateMessage(ctx context.Context, params AnthropicCreateParams, options AnthropicRequestOptions) (*http.Response, error)
}
AnthropicClient is the part of an Anthropic SDK client that the Anthropic Messages provider uses: Pi's `client.beta.messages.create(params, requestOptions).asResponse()` (anthropic-messages.ts:650). Inject one through StreamOptions.AnthropicClient to send the request through an alternative client that shares the Messages API, such as Anthropic on Vertex.
upstream: packages/ai/src/api/anthropic-messages.ts:286-290 (AnthropicOptions.client), 607-609
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
// ModelMetadata retains the caller-selected model's capabilities and API metadata instead of resolving an ID through the catalog.
ModelMetadata *Model
// 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 AnthropicCreateParams ¶
type AnthropicCreateParams struct {
// Body is the JSON request body. The betas list is not in it.
Body []byte
// Betas is the comma-joined anthropic-beta header value the SDK derives from params.betas; nil sends no header.
Betas *string
// UserProfileID and WorkspaceID are the anthropic-user-profile-id and anthropic-workspace-id header values the SDK derives from params.user_profile_id
// and params.workspace_id (beta/messages/messages.js:24-58); nil sends no header.
UserProfileID, WorkspaceID *string
}
AnthropicCreateParams are the Messages request an injected AnthropicClient sends: the params after the payload hook, with streaming enforced.
type AnthropicEffort ¶
type AnthropicEffort string
AnthropicEffort is the Anthropic output_config effort level (anthropic-messages.ts:186).
const ( AnthropicEffortLow AnthropicEffort = "low" AnthropicEffortMedium AnthropicEffort = "medium" AnthropicEffortHigh AnthropicEffort = "high" AnthropicEffortXHigh AnthropicEffort = "xhigh" AnthropicEffortMax AnthropicEffort = "max" )
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 (a AnthropicOAuthProvider) LoginContext(ctx context.Context, callbacks OAuthLoginCallbacks) (OAuthCredentials, error)
LoginContext asks for the browser or copy code login method, then runs it. Without a select callback it runs browser login, the default. Ports anthropicOAuth.login (.upstream/v1.0.0/packages/ai/src/auth/oauth/anthropic.ts:273).
func (AnthropicOAuthProvider) LoginMethodPrompt ¶
func (AnthropicOAuthProvider) LoginMethodPrompt() OAuthSelectPrompt
LoginMethodPrompt is the login method selection Anthropic login asks first.
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 AnthropicRequestOptions ¶
type AnthropicRequestOptions struct {
// TimeoutMs is StreamOptions.TimeoutMs; nil sets none.
TimeoutMs *int
}
AnthropicRequestOptions are the SDK request options of the call (anthropic-messages.ts:644-648; its `signal` is CreateMessage's ctx and its `maxRetries: 0` is the provider's own retry).
type AnthropicThinkingDisplay ¶
type AnthropicThinkingDisplay string
AnthropicThinkingDisplay selects whether thinking blocks carry summarized text or an empty field (anthropic-messages.ts:188).
const ( AnthropicThinkingDisplaySummarized AnthropicThinkingDisplay = "summarized" AnthropicThinkingDisplayOmitted AnthropicThinkingDisplay = "omitted" )
type AnyModel ¶
type AnyModel interface {
ModelType() ModelType
ModelID() string
ProviderID() string
// CostRates returns the model's per-million-token prices (types.ts BaseModel.cost). A nil model has no price.
CostRates() ModelCost
// contains filtered or unexported methods
}
AnyModel is the closed union of everything a provider can list: *Model (chat), *ImageModel and *ClassifierModel.
func DecodeModelsCatalog ¶
DecodeModelsCatalog keeps the stored models of providerID. Records of types this version does not know never reach it: ModelsStoreEntry decoding sets them aside.
func DecodeStoredModel ¶
DecodeStoredModel restores one persisted catalog record as a typed model that keeps the fields it has no member for. known is false, with a nil model, for a model type this version does not know.
func DecodeStoredModels ¶
func DecodeStoredModels(records []json.RawMessage) ([]AnyModel, error)
DecodeStoredModels restores persisted catalog records in order; records of a model type this version does not know are dropped.
func GetAllBuiltinModels ¶
GetAllBuiltinModels lists the built-in chat, image and classifier models of one provider.
func PersonalizeOpenRouterCatalog ¶
func PersonalizeOpenRouterCatalog(catalog []AnyModel, refresh RefreshModelsContext) ([]AnyModel, error)
PersonalizeOpenRouterCatalog restricts an OpenRouter catalog to the chat models the key may use, with the key's limits and prices from `GET /models/user`. Image and classifier models are returned unchanged. A missing limit keeps the catalog value. The request uses the provider's configured base URL (refresh.BaseURL), so regional endpoints such as `https://us.openrouter.ai/api/v1` apply their region's filtering. When the endpoint rejects the key (401/403) or does not exist (404), for example with a proxy configured in models.json, the catalog is returned unchanged.
type ArgumentMember ¶
ArgumentMember is one member of a tool call's arguments: its key and the text JSON.stringify gives its value.
type AssistantContentBlock ¶
type AssistantContentBlock interface {
ContentBlock
// contains filtered or unexported methods
}
AssistantContentBlock is valid inside an assistant message.
type AssistantContentProjection ¶
type AssistantContentProjection struct {
Kind string
Text string
Thinking string
ToolCallID string
ToolCallName string
Arguments JsonObject
}
AssistantContentProjection is what a renderer reads of one content block. Kind is the block's type ("text", "thinking" or "toolCall"); Text, Thinking, ToolCallID, ToolCallName and Arguments are set for the kind that holds them. The values are the observed state's own, not copies: a live view's published state never changes, and a plain message's are its own fields. Arguments must not be modified.
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 ImageAPI
Provider string
Model string
Output []ImagesOutputContent
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 ImageModel, 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 ImageModel, imagesCtx ImagesContext, options ProviderImagesOptions) AssistantImages
GenerateImagesOpenRouter implements upstream api/openrouter-images.ts generateImages.
func ImageErrorResult ¶
func ImageErrorResult(model *ImageModel, err error, aborted bool) AssistantImages
ImageErrorResult reports a failed image request as an error or aborted result instead of an error (model-operations.ts imageErrorResult).
func (AssistantImages) MarshalJSON ¶
func (r AssistantImages) MarshalJSON() ([]byte, error)
MarshalJSON writes the result with its output blocks.
func (*AssistantImages) UnmarshalJSON ¶
func (r *AssistantImages) UnmarshalJSON(data []byte) error
UnmarshalJSON reads a result.
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"`
RawStopReason string `json:"rawStopReason,omitempty"`
EndTurn *bool `json:"endTurn,omitempty"`
Timestamp int64 `json:"timestamp"`
// ErrorMessage follows the timestamp: a provider's catch block sets it on the output it built with its timestamp. A message
// built with the error first (ErrorBeforeTimestamp) encodes it before the timestamp.
ErrorMessage string `json:"errorMessage,omitempty"`
// ErrorBeforeTimestamp records that the message was built with errorMessage before timestamp, as faux.ts builds its
// messages (fauxAssistantMessage and createErrorMessage spread errorMessage, then timestamp), and as a stored record
// that lists the keys in that order decodes. JavaScript keeps the order its source wrote, so the order is part of the
// message; both encoders write it.
ErrorBeforeTimestamp bool `json:"-"`
// DurationMs is the milliseconds from the start of the request to the final message, measured with a monotonic clock by the AssistantMessageEventStream. Nil for legacy messages and for deferred results fetched later.
// upstream: ai/src/types.ts:582 AssistantMessage.durationMs
DurationMs *int64 `json:"durationMs,omitempty"`
// ModelThinkingLevel is the thinking level the agent loop requested for this response. Absent outside the agent loop and for legacy responses. Mirrors upstream AssistantMessage.thinkingLevel (packages/ai/src/types.ts:557).
ThinkingLevel ModelThinkingLevel `json:"thinkingLevel,omitempty"`
// contains filtered or unexported fields
}
AssistantMessage is a complete or partial model response. A stream event delivers a partial whose exported fields equal the stream state at delivery; they do not change behind readers. Observe and RefreshEvent read the current state of a partial retained past its delivery.
func Complete ¶
func Complete(ctx context.Context, model *Model, request Context, options ...StreamOptions) (*AssistantMessage, error)
Complete is Stream followed by its final message (compat.ts complete).
func CompleteSimple ¶
func CompleteSimple(ctx context.Context, model *Model, request Context, options ...StreamOptions) (*AssistantMessage, error)
CompleteSimple is the simple-options form of Complete (compat.ts completeSimple).
func FauxAssistantMessage ¶
func FauxAssistantMessage(content FauxAssistantContent, options FauxAssistantMessageOptions) AssistantMessage
FauxAssistantMessage is faux.ts fauxAssistantMessage: a scripted response with the given content blocks, a "stop" stop reason unless options say otherwise, and the creation time as its timestamp unless options supply one.
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) MessageRole ¶
func (AssistantMessage) MessageRole() string
MessageRole is the role property of a message.
func (*AssistantMessage) Observe ¶
func (message *AssistantMessage) Observe() *AssistantMessage
Observe returns independently owned message data at the current publication. Full views advance all fields; shallow views retain copied scalars and the nested objects present at their copy boundary. An ordinary message is deep-copied; native JSON scalar values and nil containers retain their representation. Nil stays nil.
func (*AssistantMessage) ObserveProjection ¶
func (message *AssistantMessage) ObserveProjection(content []AssistantContentProjection) (blocks []AssistantContentProjection, stopReason StopReason, errorMessage string)
ObserveProjection is Observe for a reader of block kinds, texts, thinking, tool calls, stop reason and error message: it appends one projection per content block to content, returns that slice with the stop reason and error message of the same publication, and copies nothing else. Full and shallow views read their current publication as Observe does. Returning the blocks as their own result keeps a caller's buffer on its stack when the caller stores the stop reason or error message.
func (*AssistantMessage) ObserveToolCallIdentity ¶
func (message *AssistantMessage) ObserveToolCallIdentity(index int) (id, name string, toolCall, indexValid bool)
ObserveToolCallIdentity reads only the selected block's kind, ID and name. indexValid distinguishes an absent index from a present non-tool block. Full and shallow views use their retained content reference.
func (*AssistantMessage) ObserveUsage ¶
func (message *AssistantMessage) ObserveUsage() Usage
ObserveUsage returns an owned copy of the current referenced usage without traversing message content, arguments, diagnostics or deferred data.
func (*AssistantMessage) Publication ¶
func (message *AssistantMessage) Publication() (cell uintptr, seq uint64)
Publication identifies the state message observes: the producer cell its live view reads and the number of publications the cell has made. While a message's cell and seq are unchanged, every observation of that message returns the same state (a shallow view adds its own top-level fields, which only its holder assigns), so a reader may reuse what it derived from an earlier one. A message that is not a live view returns (0, 0); its fields are the caller's to track.
func (*AssistantMessage) ShallowCopy ¶
func (message *AssistantMessage) ShallowCopy() *AssistantMessage
ShallowCopy copies top-level fields. For a live view it retains synchronized nested references, as the Agent's object spread does in packages/agent/src/agent-loop.ts:416-438. For ordinary data it shares the existing nested values. Nil stays nil.
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"`
// contains filtered or unexported fields
}
AssistantMessageDiagnostic is a provider/runtime diagnostic attached to an assistant message when a recoverable failure or transport fallback occurs.
func CreateAssistantMessageDiagnostic ¶
func CreateAssistantMessageDiagnostic(diagnosticType string, thrown any, details JsonObject) AssistantMessageDiagnostic
CreateAssistantMessageDiagnostic builds a timestamped diagnostic for a thrown value (utils/diagnostics.ts createAssistantMessageDiagnostic).
func (AssistantMessageDiagnostic) MarshalJSON ¶
func (diagnostic AssistantMessageDiagnostic) MarshalJSON() ([]byte, error)
MarshalJSON writes the diagnostic as Pi's JSON.stringify does: details, when present even if empty, keep the member order they were built or read in.
func (*AssistantMessageDiagnostic) UnmarshalJSON ¶
func (diagnostic *AssistantMessageDiagnostic) UnmarshalJSON(data []byte) error
UnmarshalJSON reads a diagnostic and keeps the member order of its details, so a diagnostic loaded from a session is written back as Pi writes the parsed object.
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.
func RefreshEvent ¶
func RefreshEvent(event AssistantMessageEvent) AssistantMessageEvent
RefreshEvent returns the event with its partial's exported fields set to the stream state at this call. A host dispatcher calls it when it delivers a retained event to a listener after an awaited step, so the listener's direct field reads match what a JavaScript listener sees at that tick. Events without a partial are returned unchanged.
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 APIModuleStream ¶
func APIModuleStream(ctx context.Context, model *Model, stream func(context.Context) (*AssistantMessageEventStream, error)) (*AssistantMessageEventStream, error)
APIModuleStream calls an API module's Go stream. Pi's API modules catch their own failures inside the stream they return (for example google-generative-ai.ts:288-298, azure-openai-responses.ts:115-125), so a Go provider's Stream error ends that stream instead: the module's message, timestamp from the call before errorMessage, with the abort-aware stop reason (`options?.signal?.aborted ? "aborted" : "error"`). A lazySetupError stays a returned error for lazyStream's setup.
func LazyStream ¶
func LazyStream(ctx context.Context, model *Model, setup func(context.Context) (*AssistantMessageEventStream, error)) *AssistantMessageEventStream
LazyStream returns before setup runs. Setup starts in the first promise reaction after the call, as the continuation of an async function whose first statement awaits; use LazyStreamSync when Pi's setup has no await before its provider call. The producer owns cancellation and its final event/result; forwarding never replaces an established terminal value with an iterator cancellation.
func LazyStreamSync ¶
func LazyStreamSync(ctx context.Context, model *Model, setup func(context.Context) (*AssistantMessageEventStream, error)) *AssistantMessageEventStream
LazyStreamSync is LazyStream for a setup that never awaits before it returns its stream. Like an async function without an await, setup runs to completion in the caller's synchronous prefix, before LazyStreamSync returns, and only the forwarding reaction is queued (packages/ai/src/api/lazy.ts:48-50). A caller that already owns the shared continuation queue runs setup inline; any other caller first acquires the queue.
func NewAssistantMessageEventStream ¶
func NewAssistantMessageEventStream() *AssistantMessageEventStream
NewAssistantMessageEventStream creates an open stream.
func Stream ¶
func Stream(ctx context.Context, model *Model, request Context, options ...StreamOptions) (*AssistantMessageEventStream, error)
Stream sends a request through the global API registry, filling the API key from the environment (compat.ts stream). A model whose API has no registered implementation is an error.
func StreamAnthropic ¶
func StreamAnthropic(ctx context.Context, model *Model, transcript TranscriptContext, options StreamOptions) (*AssistantMessageEventStream, error)
StreamAnthropic is the anthropic-messages stream (legacy-api-aliases.ts streamAnthropic).
func StreamAzureOpenAIResponses ¶
func StreamAzureOpenAIResponses(ctx context.Context, model *Model, transcript TranscriptContext, options StreamOptions) (*AssistantMessageEventStream, error)
StreamAzureOpenAIResponses is the azure-openai-responses stream (legacy-api-aliases.ts streamAzureOpenAIResponses).
func StreamGoogle ¶
func StreamGoogle(ctx context.Context, model *Model, transcript TranscriptContext, options StreamOptions) (*AssistantMessageEventStream, error)
StreamGoogle is the google-generative-ai stream (legacy-api-aliases.ts streamGoogle).
func StreamGoogleVertex ¶
func StreamGoogleVertex(ctx context.Context, model *Model, transcript TranscriptContext, options StreamOptions) (*AssistantMessageEventStream, error)
StreamGoogleVertex is the google-vertex stream (legacy-api-aliases.ts streamGoogleVertex).
func StreamMistral ¶
func StreamMistral(ctx context.Context, model *Model, transcript TranscriptContext, options StreamOptions) (*AssistantMessageEventStream, error)
StreamMistral is the mistral-conversations stream (legacy-api-aliases.ts streamMistral).
func StreamOpenAICodexResponses ¶
func StreamOpenAICodexResponses(ctx context.Context, model *Model, transcript TranscriptContext, options StreamOptions) (*AssistantMessageEventStream, error)
StreamOpenAICodexResponses is the openai-codex-responses stream (legacy-api-aliases.ts streamOpenAICodexResponses).
func StreamOpenAICompletions ¶
func StreamOpenAICompletions(ctx context.Context, model *Model, transcript TranscriptContext, options StreamOptions) (*AssistantMessageEventStream, error)
StreamOpenAICompletions is the openai-completions stream (legacy-api-aliases.ts streamOpenAICompletions).
func StreamOpenAIResponses ¶
func StreamOpenAIResponses(ctx context.Context, model *Model, transcript TranscriptContext, options StreamOptions) (*AssistantMessageEventStream, error)
StreamOpenAIResponses is the openai-responses stream (legacy-api-aliases.ts streamOpenAIResponses).
func StreamSimple ¶
func StreamSimple(ctx context.Context, model *Model, transcript TranscriptContext, options StreamOptions) (*AssistantMessageEventStream, error)
StreamSimple invokes a direct API implementation with model metadata and simple options. Omitted Anthropic reasoning explicitly disables thinking where the selected model permits it. Bedrock leaves authentication to the AWS credential chain or an optional bearer token, and Google Vertex to Application Default Credentials or an express-mode key. Other APIs reject missing request authentication before an event stream exists.
func StreamSimpleAnthropic ¶
func StreamSimpleAnthropic(ctx context.Context, model *Model, transcript TranscriptContext, options StreamOptions) (*AssistantMessageEventStream, error)
StreamSimpleAnthropic is the anthropic-messages simple stream (legacy-api-aliases.ts streamSimpleAnthropic).
func StreamSimpleAzureOpenAIResponses ¶
func StreamSimpleAzureOpenAIResponses(ctx context.Context, model *Model, transcript TranscriptContext, options StreamOptions) (*AssistantMessageEventStream, error)
StreamSimpleAzureOpenAIResponses is the azure-openai-responses simple stream (legacy-api-aliases.ts streamSimpleAzureOpenAIResponses).
func StreamSimpleContext ¶
func StreamSimpleContext(ctx context.Context, model *Model, request Context, options ...StreamOptions) (*AssistantMessageEventStream, error)
StreamSimpleContext is compat.ts streamSimple: Stream through the registered simple stream function of the model's API. It takes a Context as Pi's does; StreamSimple is the direct API implementation, which takes the normalized transcript.
func StreamSimpleGoogle ¶
func StreamSimpleGoogle(ctx context.Context, model *Model, transcript TranscriptContext, options StreamOptions) (*AssistantMessageEventStream, error)
StreamSimpleGoogle is the google-generative-ai simple stream (legacy-api-aliases.ts streamSimpleGoogle).
func StreamSimpleGoogleVertex ¶
func StreamSimpleGoogleVertex(ctx context.Context, model *Model, transcript TranscriptContext, options StreamOptions) (*AssistantMessageEventStream, error)
StreamSimpleGoogleVertex is the google-vertex simple stream (legacy-api-aliases.ts streamSimpleGoogleVertex).
func StreamSimpleMistral ¶
func StreamSimpleMistral(ctx context.Context, model *Model, transcript TranscriptContext, options StreamOptions) (*AssistantMessageEventStream, error)
StreamSimpleMistral is the mistral-conversations simple stream (legacy-api-aliases.ts streamSimpleMistral).
func StreamSimpleOpenAICodexResponses ¶
func StreamSimpleOpenAICodexResponses(ctx context.Context, model *Model, transcript TranscriptContext, options StreamOptions) (*AssistantMessageEventStream, error)
StreamSimpleOpenAICodexResponses is the openai-codex-responses simple stream (legacy-api-aliases.ts streamSimpleOpenAICodexResponses).
func StreamSimpleOpenAICompletions ¶
func StreamSimpleOpenAICompletions(ctx context.Context, model *Model, transcript TranscriptContext, options StreamOptions) (*AssistantMessageEventStream, error)
StreamSimpleOpenAICompletions is the openai-completions simple stream (legacy-api-aliases.ts streamSimpleOpenAICompletions).
func StreamSimpleOpenAIResponses ¶
func StreamSimpleOpenAIResponses(ctx context.Context, model *Model, transcript TranscriptContext, options StreamOptions) (*AssistantMessageEventStream, error)
StreamSimpleOpenAIResponses is the openai-responses simple stream (legacy-api-aliases.ts streamSimpleOpenAIResponses).
func (*AssistantMessageEventStream) End ¶
func (s *AssistantMessageEventStream) End(result ...*AssistantMessage)
End closes iteration without synthesizing an event. An optional result resolves Result once; ending without a result leaves it pending, as Pi's EventStream.end does.
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) ForwardStream ¶
func (stream *AssistantMessageEventStream) ForwardStream(ctx context.Context, source *AssistantMessageEventStream) error
ForwardStream awaits and forwards one source iterator without observing or cloning its partial references. Its caller owns setup, cancellation, errors and draining. A caller that owns the running turn forwards in it, so the source it just created cannot advance before the first await; any other caller acquires the queue, and a source it created earlier may already have run ahead.
func (*AssistantMessageEventStream) ObservationContext ¶
func (stream *AssistantMessageEventStream) ObservationContext(ctx context.Context) context.Context
ObservationContext attaches this stream's continuation executor to owned setup and forwarding work.
func (*AssistantMessageEventStream) ObserveEvents ¶
func (stream *AssistantMessageEventStream) ObserveEvents(ctx context.Context) iter.Seq2[*StreamObservation, AssistantMessageEvent]
ObserveEvents yields the same FIFO as Events and exposes the continuation scope for callers that await asynchronous event handling.
func (*AssistantMessageEventStream) ObservePublishedEvents ¶
func (stream *AssistantMessageEventStream) ObservePublishedEvents(ctx context.Context) iter.Seq2[*StreamObservation, AssistantMessageEvent]
ObservePublishedEvents is ObserveEvents without refreshing each event's partial at delivery. A caller hands an event to a reader only through RefreshEvent, called at the tick the event arrives, before anything awaits; a caller that reads nothing of an event skips the copy.
func (*AssistantMessageEventStream) Push ¶
func (s *AssistantMessageEventStream) Push(event AssistantMessageEvent) error
Push appends an event. Pushes after termination are ignored, matching Pi's EventStream. Done and error may terminate without a start event. Missing data and invalid closed-union values return a payload error.
func (*AssistantMessageEventStream) Result ¶
func (s *AssistantMessageEventStream) Result() *AssistantMessage
Result waits for a terminal event or End result and returns the first resolved message pointer.
func (*AssistantMessageEventStream) ResultContext ¶
func (s *AssistantMessageEventStream) ResultContext(ctx context.Context) (*AssistantMessage, error)
ResultContext waits for the final result or the caller's cancellation without changing stream ownership. The goroutine that runs a consumer callback awaits the result as Pi's `await stream.result()` inside that callback does: it releases the callback's turn and resumes in FIFO order. Any other goroutine only waits, so it never yields a callback that is running.
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.
func (*AuthCheck) AuthCheckSource ¶
AuthCheckSource is where the configured auth comes from, as the provider selector prints it.
func (*AuthCheck) AuthCheckType ¶
AuthCheckType is the credential type the check found, "oauth" or "api_key" (the provider selector compares it with the option's auth type).
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. It treats ECMAScript-trimmed empty values as absent without trimming nonblank values. Mirrors upstream defaultProviderAuthContext.
type AuthDeviceCodeEvent ¶
type AuthDeviceCodeEvent struct {
UserCode string `json:"userCode"`
VerificationURI string `json:"verificationUri"`
IntervalSeconds *float64 `json:"intervalSeconds,omitempty"`
ExpiresInSeconds *float64 `json:"expiresInSeconds,omitempty"`
}
func (AuthDeviceCodeEvent) MarshalJSON ¶
func (value AuthDeviceCodeEvent) MarshalJSON() ([]byte, error)
func (AuthDeviceCodeEvent) Type ¶
func (AuthDeviceCodeEvent) Type() string
type AuthEvent ¶
type AuthEvent interface {
Type() string
// contains filtered or unexported methods
}
type AuthInfoEvent ¶
type AuthInfoEvent struct {
Message string `json:"message"`
Links []AuthInfoLink `json:"links,omitempty"`
}
func (AuthInfoEvent) MarshalJSON ¶
func (value AuthInfoEvent) MarshalJSON() ([]byte, error)
func (AuthInfoEvent) Type ¶
func (AuthInfoEvent) Type() string
type AuthInfoLink ¶
type AuthInteraction ¶
type AuthInteraction struct {
Prompt func(context.Context, AuthPrompt) (string, error)
Notify func(AuthEvent)
}
AuthInteraction supplies awaited prompts and synchronous notifications. Login receives its owning context separately.
type AuthManualCodePrompt ¶
type AuthManualCodePrompt struct {
Message string `json:"message"`
Placeholder string `json:"placeholder,omitempty"`
}
func (AuthManualCodePrompt) MarshalJSON ¶
func (value AuthManualCodePrompt) MarshalJSON() ([]byte, error)
func (AuthManualCodePrompt) Type ¶
func (AuthManualCodePrompt) Type() string
type AuthOperationOptions ¶
AuthOperationOptions is Pi's AuthOperationOptions: optional cancellation of a public auth or credential operation. A nil Signal is an operation that only its own context cancels; a cancelled Signal cancels the operation with the Signal's cancellation cause (Pi rejects with `signal.reason`).
upstream: packages/ai/src/auth/types.ts:AuthOperationOptions
type AuthProgressEvent ¶
type AuthProgressEvent struct {
Message string `json:"message"`
}
func (AuthProgressEvent) MarshalJSON ¶
func (value AuthProgressEvent) MarshalJSON() ([]byte, error)
func (AuthProgressEvent) Type ¶
func (AuthProgressEvent) Type() string
type AuthPrompt ¶
type AuthPrompt interface {
Type() string
// contains filtered or unexported methods
}
AuthPrompt is a closed login-prompt union. The callback context carries the per-prompt signal.
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
// SourcePresent preserves an explicitly empty source received over JSON.
SourcePresent bool `json:"-"`
}
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.
func (*AuthResult) UnmarshalJSON ¶
func (r *AuthResult) UnmarshalJSON(data []byte) error
type AuthSecretPrompt ¶
type AuthSecretPrompt struct {
Message string `json:"message"`
Placeholder string `json:"placeholder,omitempty"`
}
func (AuthSecretPrompt) MarshalJSON ¶
func (value AuthSecretPrompt) MarshalJSON() ([]byte, error)
func (AuthSecretPrompt) Type ¶
func (AuthSecretPrompt) Type() string
type AuthSelectOption ¶
type AuthSelectPrompt ¶
type AuthSelectPrompt struct {
Message string `json:"message"`
Options []AuthSelectOption `json:"options"`
}
func (AuthSelectPrompt) MarshalJSON ¶
func (value AuthSelectPrompt) MarshalJSON() ([]byte, error)
func (AuthSelectPrompt) Type ¶
func (AuthSelectPrompt) Type() string
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.
func CredentialStoreAuthStatus ¶
func CredentialStoreAuthStatus(ctx context.Context, store CredentialStore, providerID string) AuthStatus
CredentialStoreAuthStatus reports whether auth is configured for providerID in store without refreshing OAuth tokens. It mirrors AuthStorage.GetAuthStatus over any CredentialStore.
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 the credential store and materializes a missing auth.json as {} with mode 0600. The parent directory uses mode 0700. Existing bytes and permissions remain unchanged; a failed initial load preserves the last valid snapshot. Instances of the first auth path share that snapshot.
func (*AuthStorage) Delete ¶
func (a *AuthStorage) Delete(ctx context.Context, provider string) error
Delete removes the credential for a provider (no-op if absent). Cancellation aborts process-local or file-lock acquisition and prevents a pending write without releasing another operation's ownership.
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 in ECMAScript object-key order without resolving configured key values. It shares Read's reload, cancellation, and unsignalled fallback behavior.
func (*AuthStorage) Load ¶
func (a *AuthStorage) Load() (map[string]Credential, error)
Load reads all credentials, creating an empty file if it no longer exists.
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. A caller waiting for process-local ownership can cancel without waiting for the active callback.
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. Concurrent readers share a reload; canceling one reader leaves the others running. A read without a cancellable context falls back to the last valid snapshot on reload failure.
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 AuthTextPrompt ¶
type AuthTextPrompt struct {
Message string `json:"message"`
Placeholder string `json:"placeholder,omitempty"`
}
func (AuthTextPrompt) MarshalJSON ¶
func (value AuthTextPrompt) MarshalJSON() ([]byte, error)
func (AuthTextPrompt) Type ¶
func (AuthTextPrompt) Type() string
type AuthType ¶
type AuthType = CredentialType
type AuthURLEvent ¶
type AuthURLEvent struct {
URL string `json:"url"`
Instructions string `json:"instructions,omitempty"`
}
func (AuthURLEvent) MarshalJSON ¶
func (value AuthURLEvent) MarshalJSON() ([]byte, error)
func (AuthURLEvent) Type ¶
func (AuthURLEvent) Type() string
type AzureConfig ¶
AzureConfig is the resolved Azure endpoint.
func ResolveAzureConfig ¶
func ResolveAzureConfig(modelBaseURL string, options AzureEndpointOptions) (AzureConfig, error)
ResolveAzureConfig resolves the endpoint and API version.
type AzureEndpointOptions ¶
type AzureEndpointOptions = StreamOptions
AzureEndpointOptions are the per-request Azure endpoint options: the Azure fields of StreamOptions plus its Env. Azure models ship without a base URL: each user has their own resource, resolved per request.
Ports AzureEndpointOptions (packages/ai/src/api/azure-openai-config.ts:7), which extends StreamOptions.
type AzureOpenAIResponsesConfig ¶
type AzureOpenAIResponsesConfig struct {
ModelMetadata *Model
APIKey string
Model string
ProviderID string
BaseURL string
ExtraHeaders map[string]string
SamplingParams map[string]any
// SamplingParamsByThinkingLevel overrides SamplingParams for the effective thinking level.
SamplingParamsByThinkingLevel SamplingParamsByThinkingLevel
// ThinkingLevelMap overrides catalog effort values when non-nil.
ThinkingLevelMap ThinkingLevelMap
// Env is the provider's environment; request env entries outrank it. The Azure endpoint options (azureBaseUrl, azureResourceName, azureApiVersion, azureDeploymentName) are per-request StreamOptions fields.
Env ProviderEnv
Compat *OpenAIResponsesCompat
// IsReasoning indicates the model supports extended reasoning (model.reasoning).
IsReasoning bool
}
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 NewBedrockProviderWithModel ¶
func NewBedrockProviderWithModel(model Model) *BedrockProvider
NewBedrockProviderWithModel retains the selected model's limits and compatibility metadata for requests and callbacks. Ports packages/ai/src/api/bedrock-converse-stream.ts (stream receives the caller's model, including overrides).
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 selected model's provider identity, or the canonical Bedrock identity for constructors without model metadata.
func (*BedrockProvider) Stream ¶
func (p *BedrockProvider) Stream(ctx context.Context, transcript TranscriptContext, opts StreamOptions) (*AssistantMessageEventStream, error)
Stream runs ConverseStream and translates its events into one terminal assistant result. Request failures preserve available HTTP status, AWS error code, and request identity as diagnostics. An explicit CacheRetention overrides the legacy environment preference. Nil contexts are rejected before stream construction.
type BedrockThinkingDisplay ¶
type BedrockThinkingDisplay = AnthropicThinkingDisplay
BedrockThinkingDisplay is how Bedrock Claude returns thinking content; it has the values of AnthropicThinkingDisplay. Mirrors upstream BedrockThinkingDisplay (api/bedrock-converse-stream.ts:77).
type BlockDeltas ¶
type BlockDeltas struct {
// contains filtered or unexported fields
}
BlockDeltas is the state a consumer of a streamed message keeps for its open blocks so that a delta costs the delta and not the block: the bytes of earlier deltas stay in one growing buffer, and the argument text of a tool call is parsed from where the previous delta ended. It is the machinery the provider stream builders use, for a consumer outside this package that applies `text += delta` and `parseStreamingJson(partialJson)` per event (packages/agent/src/proxy.ts processProxyEvent). The zero value is ready to use. A block ends with Release.
func (*BlockDeltas) AppendArguments ¶
func (deltas *BlockDeltas) AppendArguments(contentIndex int, current, delta string) string
AppendArguments is current+delta for the argument text of the tool call at contentIndex.
func (*BlockDeltas) AppendContent ¶
func (deltas *BlockDeltas) AppendContent(contentIndex int, current, delta string) string
AppendContent is current+delta for the text or thinking of the block at contentIndex.
func (*BlockDeltas) Release ¶
func (deltas *BlockDeltas) Release(contentIndex int)
Release drops the buffers and parser of the block at contentIndex.
func (*BlockDeltas) SetStreamingArguments ¶
func (deltas *BlockDeltas) SetStreamingArguments(call *ToolCall, contentIndex int, text string)
SetStreamingArguments is call.SetStreamingArguments(text) for the tool call at contentIndex, whose text is the previous call's text with the delta of AppendArguments added.
type BuiltinImageProvider ¶
type BuiltinImageProvider string
BuiltinImageProvider is a built-in provider with at least one image model in the generated catalog. upstream: image-models.ts:13 BuiltinImageProvider
func GetImageProviders ¶
func GetImageProviders() []BuiltinImageProvider
GetImageProviders returns the generated image providers in stable order.
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 ChatModelCatalog ¶
type ChatModelCatalog struct {
// contains filtered or unexported fields
}
ChatModelCatalog holds the chat models of one provider by model id.
func AmazonBedrockModels ¶
func AmazonBedrockModels() ChatModelCatalog
AmazonBedrockModels is AMAZON_BEDROCK_MODELS.
func CloudflareAIGatewayModels ¶
func CloudflareAIGatewayModels() ChatModelCatalog
CloudflareAIGatewayModels is CLOUDFLARE_AI_GATEWAY_MODELS.
func CloudflareWorkersAIModels ¶
func CloudflareWorkersAIModels() ChatModelCatalog
CloudflareWorkersAIModels is CLOUDFLARE_WORKERS_AI_MODELS.
func GitHubCopilotModels ¶
func GitHubCopilotModels() ChatModelCatalog
GitHubCopilotModels is GITHUB_COPILOT_MODELS.
func GoogleVertexModels ¶
func GoogleVertexModels() ChatModelCatalog
GoogleVertexModels is GOOGLE_VERTEX_MODELS.
func HuggingFaceModels ¶
func HuggingFaceModels() ChatModelCatalog
HuggingFaceModels is HUGGINGFACE_MODELS.
func KimiCodingModels ¶
func KimiCodingModels() ChatModelCatalog
KimiCodingModels is KIMI_CODING_MODELS.
func MiniMaxCNModels ¶
func MiniMaxCNModels() ChatModelCatalog
MiniMaxCNModels is MINIMAX_CN_MODELS.
func MoonshotAICNModels ¶
func MoonshotAICNModels() ChatModelCatalog
MoonshotAICNModels is MOONSHOTAI_CN_MODELS.
func MoonshotAIModels ¶
func MoonshotAIModels() ChatModelCatalog
MoonshotAIModels is MOONSHOTAI_MODELS.
func OpenAICodexModels ¶
func OpenAICodexModels() ChatModelCatalog
OpenAICodexModels is OPENAI_CODEX_MODELS.
func OpenCodeGoModels ¶
func OpenCodeGoModels() ChatModelCatalog
OpenCodeGoModels is OPENCODE_GO_MODELS.
func OpenRouterModels ¶
func OpenRouterModels() ChatModelCatalog
OpenRouterModels is OPENROUTER_MODELS.
func QwenTokenPlanCNModels ¶
func QwenTokenPlanCNModels() ChatModelCatalog
QwenTokenPlanCNModels is QWEN_TOKEN_PLAN_CN_MODELS.
func QwenTokenPlanIndividualModels ¶
func QwenTokenPlanIndividualModels() ChatModelCatalog
QwenTokenPlanIndividualModels is QWEN_TOKEN_PLAN_INDIVIDUAL_MODELS.
func QwenTokenPlanModels ¶
func QwenTokenPlanModels() ChatModelCatalog
QwenTokenPlanModels is QWEN_TOKEN_PLAN_MODELS.
func VercelAIGatewayModels ¶
func VercelAIGatewayModels() ChatModelCatalog
VercelAIGatewayModels is VERCEL_AI_GATEWAY_MODELS.
func XiaomiTokenPlanAMSModels ¶
func XiaomiTokenPlanAMSModels() ChatModelCatalog
XiaomiTokenPlanAMSModels is XIAOMI_TOKEN_PLAN_AMS_MODELS.
func XiaomiTokenPlanCNModels ¶
func XiaomiTokenPlanCNModels() ChatModelCatalog
XiaomiTokenPlanCNModels is XIAOMI_TOKEN_PLAN_CN_MODELS.
func XiaomiTokenPlanSGPModels ¶
func XiaomiTokenPlanSGPModels() ChatModelCatalog
XiaomiTokenPlanSGPModels is XIAOMI_TOKEN_PLAN_SGP_MODELS.
func ZAICodingCNModels ¶
func ZAICodingCNModels() ChatModelCatalog
ZAICodingCNModels is ZAI_CODING_CN_MODELS.
type ChatTemplateKwargValue ¶
type ChatTemplateKwargValue = any
ChatTemplateKwargValue is one chat-template keyword value: a string, number, boolean or null, or a `{ "$var": ... }` placeholder resolved per request (types.ts:90).
type ClassifierAPI ¶
type ClassifierAPI string
ClassifierAPI identifies a classifier provider API.
const ( ClassifierAPITypesafeSystemOne ClassifierAPI = "typesafe-system-one" ClassifierAPICloudflareWorkersAISystemOne ClassifierAPI = "cloudflare-workers-ai-system-one" ClassifierAPILlamaCppClassify ClassifierAPI = "llama-cpp-classify" ClassifierAPIOpenAIDecisions ClassifierAPI = "openai-decisions" )
type ClassifierAnswer ¶
type ClassifierAnswer interface {
// AnswerType is the wire `type` of the answer: "choice", "score" or "bool".
AnswerType() string
// contains filtered or unexported methods
}
ClassifierAnswer is the closed union of classifier answers: ClassifierChoiceAnswer, ClassifierScoreAnswer and ClassifierBoolAnswer.
func LlamaCppAnswerFromProbabilities ¶
func LlamaCppAnswerFromProbabilities(question ClassifierQuestion, keys []string, probabilities []float64) ClassifierAnswer
LlamaCppAnswerFromProbabilities turns label probabilities, in the order of keys, into the public answer shape.
type ClassifierAnswerEntry ¶
type ClassifierAnswerEntry struct {
ID string
Answer ClassifierAnswer
}
ClassifierAnswerEntry is the answer to one named question.
type ClassifierAnswers ¶
type ClassifierAnswers []ClassifierAnswerEntry
ClassifierAnswers keeps the answers of a result in the order the service returned them.
func (ClassifierAnswers) MarshalJSON ¶
func (a ClassifierAnswers) MarshalJSON() ([]byte, error)
MarshalJSON writes the answers as an object keyed by question ID, in order.
func (*ClassifierAnswers) UnmarshalJSON ¶
func (a *ClassifierAnswers) UnmarshalJSON(data []byte) error
UnmarshalJSON reads an object keyed by question ID, keeping the order of the keys.
type ClassifierBoolAnswer ¶
type ClassifierBoolAnswer struct {
Probability float64
}
ClassifierBoolAnswer is the answer to a bool question.
func (ClassifierBoolAnswer) AnswerType ¶
func (ClassifierBoolAnswer) AnswerType() string
func (ClassifierBoolAnswer) MarshalJSON ¶
func (a ClassifierBoolAnswer) MarshalJSON() ([]byte, error)
type ClassifierBoolCriteria ¶
ClassifierBoolCriteria describes the two outcomes of a bool question.
type ClassifierBoolQuestion ¶
type ClassifierBoolQuestion struct {
Instructions string
Criteria ClassifierBoolCriteria
}
ClassifierBoolQuestion asks a yes/no question.
func (ClassifierBoolQuestion) MarshalJSON ¶
func (q ClassifierBoolQuestion) MarshalJSON() ([]byte, error)
func (ClassifierBoolQuestion) QuestionType ¶
func (ClassifierBoolQuestion) QuestionType() string
type ClassifierChoiceAnswer ¶
type ClassifierChoiceAnswer struct {
Choice string
Probabilities []ClassifierProbability
Confidence float64
}
ClassifierChoiceAnswer is the answer to a choice question.
func (ClassifierChoiceAnswer) AnswerType ¶
func (ClassifierChoiceAnswer) AnswerType() string
func (ClassifierChoiceAnswer) MarshalJSON ¶
func (a ClassifierChoiceAnswer) MarshalJSON() ([]byte, error)
type ClassifierChoiceCriterion ¶
ClassifierChoiceCriterion is one option of a choice question.
type ClassifierChoiceQuestion ¶
type ClassifierChoiceQuestion struct {
Instructions string
Criteria []ClassifierChoiceCriterion
}
ClassifierChoiceQuestion asks for one of several named options. Criteria keep their declaration order.
func (ClassifierChoiceQuestion) MarshalJSON ¶
func (q ClassifierChoiceQuestion) MarshalJSON() ([]byte, error)
func (ClassifierChoiceQuestion) QuestionType ¶
func (ClassifierChoiceQuestion) QuestionType() string
type ClassifierContext ¶
type ClassifierContext struct {
State JsonObject
// Images are judged together with State. Only models whose Input includes "image" accept them; other models return an error result (types.ts:669-677).
Images []ImageContent
Questions ClassifierQuestions
}
ClassifierContext is the input to a classification: the state to judge and the questions to answer about it.
func (ClassifierContext) MarshalJSON ¶
func (c ClassifierContext) MarshalJSON() ([]byte, error)
MarshalJSON writes the context as {state, images?, questions} (types.ts:669-677 declaration order); images is omitted when absent.
func (*ClassifierContext) UnmarshalJSON ¶
func (c *ClassifierContext) UnmarshalJSON(data []byte) error
UnmarshalJSON reads {state, images?, questions}, keeping the order of the questions.
type ClassifierFunction ¶
type ClassifierFunction func(context.Context, ClassifierModel, ClassifierContext, ClassifierOptions) ClassifierResult
ClassifierFunction classifies with one classifier API. It reports failures in the result.
type ClassifierHTTPError ¶
type ClassifierHTTPError struct {
// Status is the HTTP status; nil for a timeout.
Status *int
// Headers are the response headers; nil for a timeout.
Headers http.Header
// Body is the response body text.
Body string
Message string
}
ClassifierHTTPError is a failed HTTP attempt: a non-2xx response, or a timeout (no status, no headers). Only these errors are retried; a transport failure is not.
Ports packages/ai/src/api/classifier-shared.ts (ClassifierHttpError: status, headers and body beside the message).
func (*ClassifierHTTPError) Error ¶
func (e *ClassifierHTTPError) Error() string
func (*ClassifierHTTPError) Name ¶
func (e *ClassifierHTTPError) Name() string
Name is the `name` property (classifier-shared.ts:8-27): a timeout, which has no status or headers, is "TimeoutError" (timeoutError sets it), and an HTTP failure keeps Error's default name, "Error" (httpError sets none).
func (*ClassifierHTTPError) ProviderHeaders ¶
func (e *ClassifierHTTPError) ProviderHeaders() http.Header
func (*ClassifierHTTPError) ProviderStatus ¶
func (e *ClassifierHTTPError) ProviderStatus() *int
ProviderStatus and ProviderHeaders make a failed classifier attempt a ProviderRequestError: a timeout has neither.
type ClassifierModel ¶
type ClassifierModel struct {
ID string
Name string
API ClassifierAPI
Provider string
BaseURL string
Headers map[string]string
Input []string
InputLimits *ModelInputLimits
Cost ModelCost
ContextWindow int
// contains filtered or unexported fields
}
ClassifierModel is a structured classifier model. It is usable with Models.Classify only.
func GetBuiltinClassifierModel ¶
func GetBuiltinClassifierModel(provider, id string) *ClassifierModel
GetBuiltinClassifierModel reads one built-in classifier model, or nil.
func GetBuiltinClassifierModels ¶
func GetBuiltinClassifierModels(provider string) []*ClassifierModel
GetBuiltinClassifierModels lists the built-in classifier models of one provider, in catalog order. The models are copies: changing one does not change the catalog.
func (*ClassifierModel) CostRates ¶
func (m *ClassifierModel) CostRates() ModelCost
CostRates returns the classifier model's per-million-token prices. A nil model has no price.
func (*ClassifierModel) ModelID ¶
func (m *ClassifierModel) ModelID() string
func (*ClassifierModel) ModelType ¶
func (*ClassifierModel) ModelType() ModelType
func (*ClassifierModel) ProviderID ¶
func (m *ClassifierModel) ProviderID() string
type ClassifierModelCatalog ¶
type ClassifierModelCatalog struct {
// contains filtered or unexported fields
}
ClassifierModelCatalog holds the classifier models of one provider by model id.
func AmazonBedrockClassifierModels ¶
func AmazonBedrockClassifierModels() ClassifierModelCatalog
AmazonBedrockClassifierModels is AMAZON_BEDROCK_CLASSIFIER_MODELS.
func AntLingClassifierModels ¶
func AntLingClassifierModels() ClassifierModelCatalog
AntLingClassifierModels is ANT_LING_CLASSIFIER_MODELS.
func AnthropicClassifierModels ¶
func AnthropicClassifierModels() ClassifierModelCatalog
AnthropicClassifierModels is ANTHROPIC_CLASSIFIER_MODELS.
func AzureClassifierModels ¶
func AzureClassifierModels() ClassifierModelCatalog
AzureClassifierModels is AZURE_CLASSIFIER_MODELS.
func BasetenClassifierModels ¶
func BasetenClassifierModels() ClassifierModelCatalog
BasetenClassifierModels is BASETEN_CLASSIFIER_MODELS.
func CerebrasClassifierModels ¶
func CerebrasClassifierModels() ClassifierModelCatalog
CerebrasClassifierModels is CEREBRAS_CLASSIFIER_MODELS.
func CloudflareAIGatewayClassifierModels ¶
func CloudflareAIGatewayClassifierModels() ClassifierModelCatalog
CloudflareAIGatewayClassifierModels is CLOUDFLARE_AI_GATEWAY_CLASSIFIER_MODELS.
func CloudflareWorkersAIClassifierModels ¶
func CloudflareWorkersAIClassifierModels() ClassifierModelCatalog
CloudflareWorkersAIClassifierModels is CLOUDFLARE_WORKERS_AI_CLASSIFIER_MODELS.
func DeepSeekClassifierModels ¶
func DeepSeekClassifierModels() ClassifierModelCatalog
DeepSeekClassifierModels is DEEPSEEK_CLASSIFIER_MODELS.
func FireworksClassifierModels ¶
func FireworksClassifierModels() ClassifierModelCatalog
FireworksClassifierModels is FIREWORKS_CLASSIFIER_MODELS.
func GitHubCopilotClassifierModels ¶
func GitHubCopilotClassifierModels() ClassifierModelCatalog
GitHubCopilotClassifierModels is GITHUB_COPILOT_CLASSIFIER_MODELS.
func GoogleClassifierModels ¶
func GoogleClassifierModels() ClassifierModelCatalog
GoogleClassifierModels is GOOGLE_CLASSIFIER_MODELS.
func GoogleVertexClassifierModels ¶
func GoogleVertexClassifierModels() ClassifierModelCatalog
GoogleVertexClassifierModels is GOOGLE_VERTEX_CLASSIFIER_MODELS.
func GroqClassifierModels ¶
func GroqClassifierModels() ClassifierModelCatalog
GroqClassifierModels is GROQ_CLASSIFIER_MODELS.
func HuggingFaceClassifierModels ¶
func HuggingFaceClassifierModels() ClassifierModelCatalog
HuggingFaceClassifierModels is HUGGINGFACE_CLASSIFIER_MODELS.
func KimiCodingClassifierModels ¶
func KimiCodingClassifierModels() ClassifierModelCatalog
KimiCodingClassifierModels is KIMI_CODING_CLASSIFIER_MODELS.
func MetaClassifierModels ¶
func MetaClassifierModels() ClassifierModelCatalog
MetaClassifierModels is META_CLASSIFIER_MODELS.
func MiniMaxCNClassifierModels ¶
func MiniMaxCNClassifierModels() ClassifierModelCatalog
MiniMaxCNClassifierModels is MINIMAX_CN_CLASSIFIER_MODELS.
func MiniMaxClassifierModels ¶
func MiniMaxClassifierModels() ClassifierModelCatalog
MiniMaxClassifierModels is MINIMAX_CLASSIFIER_MODELS.
func MistralClassifierModels ¶
func MistralClassifierModels() ClassifierModelCatalog
MistralClassifierModels is MISTRAL_CLASSIFIER_MODELS.
func MoonshotAICNClassifierModels ¶
func MoonshotAICNClassifierModels() ClassifierModelCatalog
MoonshotAICNClassifierModels is MOONSHOTAI_CN_CLASSIFIER_MODELS.
func MoonshotAIClassifierModels ¶
func MoonshotAIClassifierModels() ClassifierModelCatalog
MoonshotAIClassifierModels is MOONSHOTAI_CLASSIFIER_MODELS.
func NVIDIAClassifierModels ¶
func NVIDIAClassifierModels() ClassifierModelCatalog
NVIDIAClassifierModels is NVIDIA_CLASSIFIER_MODELS.
func OpenAIClassifierModels ¶
func OpenAIClassifierModels() ClassifierModelCatalog
OpenAIClassifierModels is OPENAI_CLASSIFIER_MODELS.
func OpenAICodexClassifierModels ¶
func OpenAICodexClassifierModels() ClassifierModelCatalog
OpenAICodexClassifierModels is OPENAI_CODEX_CLASSIFIER_MODELS.
func OpenCodeClassifierModels ¶
func OpenCodeClassifierModels() ClassifierModelCatalog
OpenCodeClassifierModels is OPENCODE_CLASSIFIER_MODELS.
func OpenCodeGoClassifierModels ¶
func OpenCodeGoClassifierModels() ClassifierModelCatalog
OpenCodeGoClassifierModels is OPENCODE_GO_CLASSIFIER_MODELS.
func OpenRouterClassifierModels ¶
func OpenRouterClassifierModels() ClassifierModelCatalog
OpenRouterClassifierModels is OPENROUTER_CLASSIFIER_MODELS.
func QwenTokenPlanCNClassifierModels ¶
func QwenTokenPlanCNClassifierModels() ClassifierModelCatalog
QwenTokenPlanCNClassifierModels is QWEN_TOKEN_PLAN_CN_CLASSIFIER_MODELS.
func QwenTokenPlanClassifierModels ¶
func QwenTokenPlanClassifierModels() ClassifierModelCatalog
QwenTokenPlanClassifierModels is QWEN_TOKEN_PLAN_CLASSIFIER_MODELS.
func QwenTokenPlanIndividualClassifierModels ¶
func QwenTokenPlanIndividualClassifierModels() ClassifierModelCatalog
QwenTokenPlanIndividualClassifierModels is QWEN_TOKEN_PLAN_INDIVIDUAL_CLASSIFIER_MODELS.
func RadiusClassifierModels ¶
func RadiusClassifierModels() ClassifierModelCatalog
RadiusClassifierModels is RADIUS_CLASSIFIER_MODELS.
func TogetherClassifierModels ¶
func TogetherClassifierModels() ClassifierModelCatalog
TogetherClassifierModels is TOGETHER_CLASSIFIER_MODELS.
func TypesafeClassifierModels ¶
func TypesafeClassifierModels() ClassifierModelCatalog
TypesafeClassifierModels is TYPESAFE_CLASSIFIER_MODELS.
func VercelAIGatewayClassifierModels ¶
func VercelAIGatewayClassifierModels() ClassifierModelCatalog
VercelAIGatewayClassifierModels is VERCEL_AI_GATEWAY_CLASSIFIER_MODELS.
func XAIClassifierModels ¶
func XAIClassifierModels() ClassifierModelCatalog
XAIClassifierModels is XAI_CLASSIFIER_MODELS.
func XiaomiClassifierModels ¶
func XiaomiClassifierModels() ClassifierModelCatalog
XiaomiClassifierModels is XIAOMI_CLASSIFIER_MODELS.
func XiaomiTokenPlanAMSClassifierModels ¶
func XiaomiTokenPlanAMSClassifierModels() ClassifierModelCatalog
XiaomiTokenPlanAMSClassifierModels is XIAOMI_TOKEN_PLAN_AMS_CLASSIFIER_MODELS.
func XiaomiTokenPlanCNClassifierModels ¶
func XiaomiTokenPlanCNClassifierModels() ClassifierModelCatalog
XiaomiTokenPlanCNClassifierModels is XIAOMI_TOKEN_PLAN_CN_CLASSIFIER_MODELS.
func XiaomiTokenPlanSGPClassifierModels ¶
func XiaomiTokenPlanSGPClassifierModels() ClassifierModelCatalog
XiaomiTokenPlanSGPClassifierModels is XIAOMI_TOKEN_PLAN_SGP_CLASSIFIER_MODELS.
func ZAIClassifierModels ¶
func ZAIClassifierModels() ClassifierModelCatalog
ZAIClassifierModels is ZAI_CLASSIFIER_MODELS.
func ZAICodingCNClassifierModels ¶
func ZAICodingCNClassifierModels() ClassifierModelCatalog
ZAICodingCNClassifierModels is ZAI_CODING_CN_CLASSIFIER_MODELS.
func (ClassifierModelCatalog) IDs ¶
func (c ClassifierModelCatalog) IDs() []string
IDs returns the model ids in catalog order (Object.keys).
type ClassifierOptions ¶
type ClassifierOptions struct {
// TelemetryContext parents provider request spans; nil means no recording backend.
TelemetryContext telemetry.TelemetryContext
// Fetch replaces HTTP execution without changing the caller's request context or redirect policy.
Fetch *http.Client
APIKey string
// APIKeySet distinguishes an explicit empty key from an omitted override.
APIKeySet bool
Headers ProviderHeaders
Env ProviderEnv
// TimeoutMs bounds each HTTP attempt. Nil means no timeout.
TimeoutMs *int
// MaxRetries is the retry budget after a retryable failure. Nil means 2.
MaxRetries *int
// MaxRetryDelayMs caps a server-requested retry delay. Nil means 60000; 0 disables the cap.
MaxRetryDelayMs *int
// OnPayload inspects or replaces the request payload before it is sent. Returning false keeps the payload.
OnPayload func(payload any, model ClassifierModel) (any, bool, error)
OnResponse func(response ProviderResponse, model ClassifierModel) error
// Temperature divides the answer logits before they are normalized into probabilities. It must be positive; APIs
// that cannot apply it ignore it.
Temperature *float64
}
ClassifierOptions configures classifier provider requests. Cancellation comes from the request context.
type ClassifierProbability ¶
ClassifierProbability is the probability of one option of a choice answer.
type ClassifierQuestion ¶
type ClassifierQuestion interface {
// QuestionType is the wire `type` of the question: "choice", "score" or "bool".
QuestionType() string
// contains filtered or unexported methods
}
ClassifierQuestion is the closed union of classifier questions: ClassifierChoiceQuestion, ClassifierScoreQuestion and ClassifierBoolQuestion.
type ClassifierQuestionEntry ¶
type ClassifierQuestionEntry struct {
ID string
Question ClassifierQuestion
}
ClassifierQuestionEntry is one named question.
type ClassifierQuestions ¶
type ClassifierQuestions []ClassifierQuestionEntry
ClassifierQuestions keeps the questions of a request in insertion order.
func (ClassifierQuestions) MarshalJSON ¶
func (q ClassifierQuestions) MarshalJSON() ([]byte, error)
MarshalJSON writes the questions as an object keyed by question ID, in order.
func (*ClassifierQuestions) UnmarshalJSON ¶
func (q *ClassifierQuestions) UnmarshalJSON(data []byte) error
UnmarshalJSON reads an object keyed by question ID, keeping the order of the keys.
type ClassifierResult ¶
type ClassifierResult struct {
API ClassifierAPI
Provider string
Model string
Answers ClassifierAnswers
// Usage is the token usage priced at the model's catalog price, when the service reports token counts.
Usage *Usage
StopReason ClassifierStopReason
ErrorMessage string
Timestamp int64
}
ClassifierResult is the final result of a classification. Failures are results with StopReason error or aborted.
func ClassifierErrorResult ¶
func ClassifierErrorResult(model *ClassifierModel, err error, aborted bool) ClassifierResult
ClassifierErrorResult reports a failed classification as an error or aborted result instead of an error (model-operations.ts classifierErrorResult).
func ClassifyCloudflareWorkersAISystemOne ¶
func ClassifyCloudflareWorkersAISystemOne(ctx context.Context, model ClassifierModel, request ClassifierContext, options ClassifierOptions) ClassifierResult
ClassifyCloudflareWorkersAISystemOne runs System One models on the Workers AI REST endpoint, with public bool values mapped to wire-level noul.
func ClassifyLlamaCpp ¶
func ClassifyLlamaCpp(ctx context.Context, model ClassifierModel, request ClassifierContext, options ClassifierOptions) ClassifierResult
ClassifyLlamaCpp classifies with a chat model on llama-server by reading next-token probabilities of answer labels.
func ClassifyOpenAIDecisions ¶
func ClassifyOpenAIDecisions(ctx context.Context, model ClassifierModel, request ClassifierContext, options ClassifierOptions) ClassifierResult
ClassifyOpenAIDecisions classifies through OpenAI's Decisions API.
func ClassifySystemOne ¶
func ClassifySystemOne(ctx context.Context, transport SystemOneTransport, model ClassifierModel, request ClassifierContext, options ClassifierOptions) ClassifierResult
ClassifySystemOne runs one System One classification over the given transport.
func ClassifyTypesafeSystemOne ¶
func ClassifyTypesafeSystemOne(ctx context.Context, model ClassifierModel, request ClassifierContext, options ClassifierOptions) ClassifierResult
ClassifyTypesafeSystemOne runs TypeSafe's native System One protocol with public bool values mapped to wire-level noul. OpenRouter, OpenCode Zen and Vercel AI Gateway serve the same protocol at other base URLs.
func (ClassifierResult) MarshalJSON ¶
func (r ClassifierResult) MarshalJSON() ([]byte, error)
MarshalJSON writes the result with its answers in order.
func (*ClassifierResult) UnmarshalJSON ¶
func (r *ClassifierResult) UnmarshalJSON(data []byte) error
UnmarshalJSON reads a result, keeping the order of its answers.
type ClassifierScoreAnswer ¶
ClassifierScoreAnswer is the answer to a score question.
func (ClassifierScoreAnswer) AnswerType ¶
func (ClassifierScoreAnswer) AnswerType() string
func (ClassifierScoreAnswer) MarshalJSON ¶
func (a ClassifierScoreAnswer) MarshalJSON() ([]byte, error)
type ClassifierScoreQuestion ¶
ClassifierScoreQuestion asks for a level; Criteria describe the levels from lowest to highest.
func (ClassifierScoreQuestion) MarshalJSON ¶
func (q ClassifierScoreQuestion) MarshalJSON() ([]byte, error)
func (ClassifierScoreQuestion) QuestionType ¶
func (ClassifierScoreQuestion) QuestionType() string
type ClassifierStopReason ¶
type ClassifierStopReason string
ClassifierStopReason is why a classification ended.
const ( ClassifierStopReasonStop ClassifierStopReason = "stop" ClassifierStopReasonError ClassifierStopReason = "error" ClassifierStopReasonAborted ClassifierStopReason = "aborted" )
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 CombinedAbortSignal ¶
type CombinedAbortSignal struct {
Signal context.Context
Cleanup func()
// contains filtered or unexported fields
}
CombinedAbortSignal is the result of CombineAbortSignals. Signal is nil when no signal was supplied. Cleanup releases the listeners the combination installed.
upstream: packages/ai/src/utils/abort-signals.ts:1
func CombineAbortSignals ¶
func CombineAbortSignals(signals ...context.Context) CombinedAbortSignal
CombineAbortSignals returns one signal that aborts when any supplied signal aborts, with that signal's cause. Nil signals are ignored, no signal gives a nil Signal, and a single signal is returned as it is. A signal that is already cancelled cancels the combination before it is returned, and the signals after it are not observed. Cleanup stops observing the supplied signals. A Go context has no synchronous abort listener, so the combination follows a supplied signal one goroutine hop after that signal is cancelled; wait on Signal.Done rather than reading Err straight after the cancel.
upstream: packages/ai/src/utils/abort-signals.ts:6
type ConstrainedSamplingConfig ¶
type ConstrainedSamplingConfig struct {
Type ConstrainedSamplingType `json:"type"`
Strict ConstrainedSamplingStrict `json:"strict,omitempty"` // json_schema only
Variants GrammarVariants `json:"variants,omitempty"` // grammar only: 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 ConstrainedSamplingStrict ¶
type ConstrainedSamplingStrict string
ConstrainedSamplingStrict is how strictly a json_schema tool must be sampled: `"prefer" | "require"`. upstream: packages/ai/src/types.ts:709-711
const ( ConstrainedSamplingStrictPrefer ConstrainedSamplingStrict = "prefer" ConstrainedSamplingStrictRequire ConstrainedSamplingStrict = "require" )
type ConstrainedSamplingType ¶
type ConstrainedSamplingType string
ConstrainedSamplingType is the discriminator of ConstrainedSamplingConfig: `"json_schema" | "grammar"`. upstream: packages/ai/src/types.ts:707-715
const ( ConstrainedSamplingJSONSchema ConstrainedSamplingType = "json_schema" ConstrainedSamplingGrammar ConstrainedSamplingType = "grammar" )
type ContentBlock ¶
type ContentBlock interface {
// contains filtered or unexported methods
}
ContentBlock is the closed union of provider-facing content types.
func DecodedFormBlock ¶
func DecodedFormBlock(block ContentBlock) (ContentBlock, bool)
DecodedFormBlock is the block decoding the JSON encoding of block yields, when that can be proven without encoding or decoding: a text, thinking, image or tool call block that holds no streaming scratch, only valid UTF-8 text and, for a tool call, arguments that are an object of plain JSON values (nil, bool, finite float64 other than negative zero, string, []any, map[string]any). It reports false for anything else, and the caller decodes the record.
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
// Frozen declares that nothing modifies Messages, or anything they reference, while a request or stream made
// from this context is live. Normalization then shares the messages instead of deep-copying them, as pi-ai's
// normalizeContext does. TranscriptContext.Messages still returns copies.
// pig additive (D104): pi-ai copies nothing; PiG copies unless the caller declares the messages immutable.
Frozen bool
// Validated lets a Frozen context skip validating a value an earlier request of the same transcript already
// validated: it answers by the value's identity, so the caller promises that no value the memo has seen changes
// while the memo is in use. It is ignored unless Frozen is set.
// pig additive (D104): pi-ai validates nothing; PiG checks every tool result's details and call arguments for JSON, and a transcript that grows by one message per turn would otherwise check them all again every turn.
Validated *ValidationMemo
// contains filtered or unexported fields
}
Context is the public request shape accepted before provider normalization.
type ContextTokensSource ¶
type ContextTokensSource interface {
[]Message | TranscriptContext
}
ContextTokensSource is the input of EstimateContextTokens: a transcript or its messages (estimate.ts `TranscriptContext | readonly Message[]`).
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[T ContextTokensSource](context T) 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 ConvertCompletionsMessagesOptions ¶
type ConvertCompletionsMessagesOptions struct {
// GrammarToolInputProperties maps a grammar tool's name to its constrained input property. Nil derives it from the transcript.
GrammarToolInputProperties map[string]string
}
ConvertCompletionsMessagesOptions are the options of ConvertCompletionsMessages.
Ports packages/ai/src/api/openai-completions.ts (ConvertCompletionsMessagesOptions).
type ConvertResponsesMessagesOptions ¶
type ConvertResponsesMessagesOptions struct {
// IncludeSystemPrompt nil is true: the transcript's leading system message becomes the first input item.
IncludeSystemPrompt *bool
// GrammarToolInputProperties maps a grammar tool's name to the argument property its custom input carries.
GrammarToolInputProperties map[string]string
// SupportsMidConvoSystemMessages sends later system messages in place; otherwise they fold into the leading prompt.
SupportsMidConvoSystemMessages bool
SupportsAdditionalTools bool
SupportsToolSearch bool
ToolOptions ConvertResponsesToolsOptions
// ConfigurationUpdateEffort is the effort of the reply being generated. When set, the thinking level goes in
// configuration_update items instead of a changing reasoning.effort: one before every earlier reply of this model
// with its recorded level (ProviderThinkingLevel), and one with this effort at the end, so earlier input never
// changes (openai-responses-shared.ts convertResponsesMessages configurationUpdateEffort).
ConfigurationUpdateEffort string
}
ConvertResponsesMessagesOptions mirrors upstream ConvertResponsesMessagesOptions (openai-responses-shared.ts:124).
type ConvertResponsesToolsOptions ¶
type ConvertResponsesToolsOptions struct {
// Strict is the strict field of a function tool that no constrained-sampling request decides.
Strict ResponsesStrictDefault
// SupportsStrictMode nil is true, as `options?.supportsStrictMode ?? true`.
SupportsStrictMode *bool
// SupportsOpenAIGrammarTools nil is false.
SupportsOpenAIGrammarTools bool
// ToolSearchResult marks every tool as loaded by a tool_search_output (defer_loading).
ToolSearchResult bool
}
ConvertResponsesToolsOptions mirrors upstream ConvertResponsesToolsOptions (openai-responses-shared.ts:132).
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)
// OnDeviceCode receives the complete device notification and takes precedence over OnAuth.
OnDeviceCode func(OAuthDeviceCodeInfo)
// 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). 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)
// BaseURL is the request model's base URL. It applies when a resolved key
// (RuntimeToken) owns the request: upstream ModelRuntime sends the model
// with resolution.auth.baseUrl when the credential's toAuth derives one
// (an OAuth token's proxy-ep endpoint), and otherwise the catalog or
// models.json baseUrl. Empty falls back to the individual endpoint.
BaseURL string
// ModelMetadata is the selected model (catalog, refreshed catalog or
// models.json), carrying its compat and thinking metadata. Every API leaf
// reads model.compat as upstream anthropic-messages, openai-completions and
// openai-responses do. Nil resolves the generated github-copilot catalog
// entry by id.
ModelMetadata *Model
}
CopilotProviderConfig configures a github-copilot provider.
type CostTier ¶
type CostTier struct {
InputTokensAbove float64 `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 CreateModelsOptions ¶
type CreateModelsOptions struct {
Credentials CredentialStore
ModelsStore ModelsStore
AuthContext *AuthContext
}
CreateModelsOptions supplies application-owned stores and auth context to model collections.
type CreateProviderOptions ¶
type CreateProviderOptions struct {
ID string
Name *string
BaseURL string
Headers ProviderHeaders
Auth ProviderAuth
// Models are the static baseline models of every type. Models without a type are chat models.
Models []AnyModel
// FetchModels returns a dynamic overlay of every type.
FetchModels func(RefreshModelsContext) ([]AnyModel, error)
FilterModels func([]*Model, *Credential) []*Model
FilterAllModels func([]AnyModel, *Credential) []AnyModel
// API is the chat implementation. It is optional when Images or Classifiers is given.
API ProviderAPIs
Images ProviderImageAPIMap
Classifiers ProviderClassifierMap
}
type Credential ¶
type Credential struct {
Extra map[string]json.RawMessage `json:"-"`
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 is the truncated integer projection of expires in milliseconds since the epoch. ExpiresMillis returns Pi's exact value, including a fraction or an absent property.
// Expiry decisions must use ExpiresMillis. SetExpiresMillis stores a fraction; assigning Expires replaces any retained exact value.
Expires int64 `json:"expires,omitempty"`
ProjectID string `json:"projectId,omitempty"`
AccountID string `json:"accountId,omitempty"`
EnterpriseDomain string `json:"enterpriseUrl,omitempty"`
// Scope is the granted OAuth scope some flows (Radius) return and persist.
Scope string `json:"scope,omitempty"`
// AvailableModelIDs retains the account's optional picker filter, including an explicit empty list or malformed external value.
AvailableModelIDs json.RawMessage `json:"availableModelIds,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"`
// contains filtered or unexported fields
}
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 CredentialFromOAuth ¶
func CredentialFromOAuth(value OAuthCredentials) (Credential, error)
CredentialFromOAuth returns the stored OAuth credential for a token object, as Pi's `{ ...credential, type: "oauth" }` does. It fails only when retained metadata is not valid 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).
func ReadRawCredential ¶
func ReadRawCredential(ctx context.Context, store CredentialStore, providerID string) (Credential, bool, error)
ReadRawCredential uses GetRaw when the store exposes it. Otherwise it calls Read, which may resolve configuration values according to the supplied store's contract.
func (*Credential) ClearExpires ¶
func (c *Credential) ClearExpires()
ClearExpires removes the expires property.
func (Credential) ExpiresMillis ¶
func (c Credential) ExpiresMillis() float64
ExpiresMillis returns ToNumber of an OAuth credential's expires value. An absent value is NaN, so both orderings compare false.
func (Credential) HasExpires ¶
func (c Credential) HasExpires() bool
HasExpires reports whether the credential carries an expires property.
func (Credential) MarshalJSON ¶
func (c Credential) MarshalJSON() ([]byte, error)
func (Credential) OAuthCredentials ¶
func (c Credential) OAuthCredentials() OAuthCredentials
OAuthCredentials returns the OAuth token object stored in c, including provider-owned metadata and the exact expires value.
func (*Credential) SetExpiresMillis ¶
func (c *Credential) SetExpiresMillis(value float64)
SetExpiresMillis stores a JavaScript number, including a fraction. Expires receives its truncated projection.
func (*Credential) UnmarshalJSON ¶
func (c *Credential) UnmarshalJSON(data []byte) error
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 in ECMAScript object-key order 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)
// Delete removes the stored credential, doing nothing if it is absent.
Delete(ctx context.Context, providerID string) error
}
CredentialStore is app-owned credential storage keyed by provider id. Modify serializes OAuth refreshes as read-modify-write operations; Delete removes a provider's credential for logout. Both honor the operation context.
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 DeferredCancelOptions ¶
type DeferredCancelOptions = StreamOptions
type DeferredFetchOptions ¶
type DeferredFetchOptions struct {
StreamOptions
Wait *float64
}
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 JsonValue `json:"data,omitempty"`
}
DeferredHandle identifies a provider-side deferred response and the data required to retrieve it later.
type DeferredOption ¶
DeferredOption is a deferred-generation boolean or an object with an optional window.
func (DeferredOption) MarshalJSON ¶
func (option DeferredOption) MarshalJSON() ([]byte, error)
MarshalJSON emits the upstream boolean or object form.
func (*DeferredOption) UnmarshalJSON ¶
func (option *DeferredOption) UnmarshalJSON(data []byte) error
UnmarshalJSON decodes either deferred-generation option form.
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 DiagnosticCoder ¶
type DiagnosticCoder interface {
DiagnosticCode() any
}
DiagnosticCoder is implemented by an error that carries a JavaScript-style `error.code`: a string or a number.
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.
func ExtractDiagnosticError ¶
func ExtractDiagnosticError(value any) DiagnosticErrorInfo
ExtractDiagnosticError summarizes a thrown value for a diagnostic. A value that is not an error is reported as a `ThrownValue`. An error reports its name (an empty name is omitted, like upstream's `error.name || undefined`), its message (its name when the message is empty), and a string or numeric code from DiagnosticCoder. Go errors carry no stack, so Stack stays empty (utils/diagnostics.ts extractDiagnosticError). pig divergence (D103): JS Error.stack is not modelled; a Go stack would persist build-machine paths.
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 EventStream ¶
type EventStream[T, R any] struct { // contains filtered or unexported fields }
EventStream delivers pushed events in order to its consumers and resolves one result. An event for which isComplete is true ends the stream and supplies the result through extractResult. Events pushed after the stream ended are dropped. Events are buffered without bound until read. Waiting consumers receive events in the order they began waiting.
func NewEventStream ¶
func NewEventStream[T, R any](isComplete func(T) bool, extractResult func(T) R) *EventStream[T, R]
NewEventStream creates a stream that ends when isComplete reports an event and then resolves with extractResult of that event.
func (*EventStream[T, R]) End ¶
func (s *EventStream[T, R]) End(result ...R)
End ends the stream and releases every waiting consumer; buffered events remain readable. With a result it resolves Result unless Result is already resolved; without one Result stays unresolved, as upstream end() without an argument leaves it. Only the first result counts.
func (*EventStream[T, R]) Events ¶
func (s *EventStream[T, R]) Events() iter.Seq[T]
Events yields buffered and future events in order and returns once the stream ended and its buffer is empty.
func (*EventStream[T, R]) Push ¶
func (s *EventStream[T, R]) Push(event T)
Push delivers an event to the longest-waiting consumer, or buffers it. It ignores events after the stream ended.
func (*EventStream[T, R]) Result ¶
func (s *EventStream[T, R]) Result() R
Result blocks until the stream resolves its result.
func (*EventStream[T, R]) ResultContext ¶
func (s *EventStream[T, R]) ResultContext(ctx context.Context) (R, error)
ResultContext is Result that gives up when ctx ends.
type FauxAssistantContent ¶
type FauxAssistantContent interface {
// contains filtered or unexported methods
}
FauxAssistantContent is the `string | FauxContentBlock | FauxContentBlock[]` content of faux.ts fauxAssistantMessage: a FauxContentString becomes one text block, a FauxContentBlock one block and FauxContentBlocks the blocks as given. A nil content is no blocks.
type FauxAssistantMessageOptions ¶
type FauxAssistantMessageOptions struct {
StopReason string
Deferred *DeferredHandle
ErrorMessage string
ResponseID string
Timestamp *int64
}
FauxAssistantMessageOptions are the options of faux.ts fauxAssistantMessage.
type FauxConfig ¶
type FauxConfig struct {
Deferred *FauxDeferredConfig
API API
ProviderID string
Model string
Models []FauxModelDefinition
TokensPerSecond int
// TokenSize is faux.ts RegisterFauxProviderOptions.tokenSize: the streamed chunk size range in tokens. A nil bound takes the default (3, 5).
TokenSize *FauxTokenSize
}
type FauxContentBlock ¶
type FauxContentBlock struct {
Type FauxContentBlockType `json:"type"`
Text string `json:"text,omitempty"`
// TextSignature is the optional TextContent member of a text block (types.ts TextContent.textSignature). Like the optional ToolCall members, only the final message keeps it.
TextSignature string `json:"textSignature,omitempty"`
Thinking string `json:"thinking,omitempty"`
// ThinkingSignature and Redacted are the optional ThinkingContent members of a thinking block (types.ts ThinkingContent). Only the final message keeps them.
ThinkingSignature string `json:"thinkingSignature,omitempty"`
Redacted bool `json:"redacted,omitempty"`
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Arguments map[string]any `json:"arguments,omitempty"`
// ThoughtSignature and Namespace are the optional ToolCall members of a toolCall block (types.ts ToolCall). The stream carries them on the toolcall_end event and the final message, as faux.ts does; the partial message of the events keeps only id, name and arguments.
ThoughtSignature string `json:"thoughtSignature,omitempty"`
Namespace string `json:"namespace,omitempty"`
// ArgumentsError is the optional ToolCall member Pi 87f9a364 adds: why the final arguments text did not parse.
ArgumentsError string `json:"argumentsError,omitempty"`
}
func FauxText ¶
func FauxText(text string) FauxContentBlock
func FauxThinking ¶
func FauxThinking(thinking string) FauxContentBlock
func FauxToolCall ¶
func FauxToolCall(name string, args map[string]any, options *FauxToolCallOptions) FauxContentBlock
FauxToolCall is faux.ts fauxToolCall(name, arguments, options = {}).
type FauxContentBlockType ¶
type FauxContentBlockType string
FauxContentBlockType is the "type" of a FauxContentBlock: the closed union of TextContent | ThinkingContent | ToolCall types (faux.ts FauxContentBlock).
const ( FauxContentText FauxContentBlockType = "text" FauxContentThinking FauxContentBlockType = "thinking" FauxContentToolCall FauxContentBlockType = "toolCall" )
The FauxContentBlock types.
type FauxContentBlocks ¶
type FauxContentBlocks []FauxContentBlock
FauxContentBlocks is the array form of fauxAssistantMessage's content.
type FauxContentString ¶
type FauxContentString string
FauxContentString is the string form of fauxAssistantMessage's content: one text block.
type FauxCore ¶
type FauxCore struct {
// API is `api` (faux.ts:455): the requested API name, else "faux:<time>:<random>".
API string
// Provider is `provider` (faux.ts:456): the provider id, "faux" unless one was requested.
Provider string
// Models is `models` (faux.ts:477-492): the faux models, in definition order, with the core's api and provider.
Models []*Model
// Stream is `stream` (faux.ts:508-571): it shifts the next queued response and streams it for the model, or ends the stream with an error message when none is queued.
Stream ModelsStreamFunction
// StreamSimple is `streamSimple` (faux.ts:573-574): stream, which takes the same options.
StreamSimple ModelsStreamFunction
// FetchDeferred is `fetchDeferred` (faux.ts:576-638): it answers a fetch of a deferred submission, the original handle while fetches remain pending, then the scripted response.
FetchDeferred func(ctx context.Context, model *Model, handle DeferredHandle, options DeferredFetchOptions) (*AssistantMessageEventStream, error)
// CancelDeferred is `cancelDeferred` (faux.ts:640-650): it records the handle as cancelled, so a later fetch of it fails.
CancelDeferred func(ctx context.Context, model *Model, handle DeferredHandle, options DeferredCancelOptions) error
// GetModel is `getModel` (faux.ts:652-659): the first model, or the model with the id, nil for an unknown id.
GetModel func(id ...string) *Model
// State is `state` (faux.ts:665): the call, deferred fetch and cancelled deferred counters.
State *FauxProviderState
// SetResponses is `setResponses` (faux.ts:667-669): the queue becomes a copy of responses.
SetResponses func(responses []FauxResponseStep)
// AppendResponses is `appendResponses` (faux.ts:670-672): responses join the end of the queue.
AppendResponses func(responses []FauxResponseStep)
// GetPendingResponseCount is `getPendingResponseCount` (faux.ts:673-675): the number of queued responses.
GetPendingResponseCount func() int
// contains filtered or unexported fields
}
FauxCore is the object faux.ts createFauxCore returns (faux.ts:454-702): the faux provider's api and provider names, its models, the functions that serve them (stream, streamSimple, fetchDeferred, cancelDeferred, getModel), the call counters, and the response queue. fauxProvider and registerFauxProvider are built on it; here they are NewFauxProvider and RegisterFauxProvider, whose handle shares this core's queue and state. Like upstream's object, every function is a field a caller keeps and calls on its own.
func CreateFauxCore ¶
func CreateFauxCore(options RegisterFauxProviderOptions) *FauxCore
CreateFauxCore is faux.ts createFauxCore(options): it builds the faux provider's core. A nil option field takes upstream's default.
type FauxDeferredConfig ¶
type FauxModelDefinition ¶
type FauxModelDefinition struct {
ID string
Name string
Reasoning bool
Input []string
// InputLimits mirrors upstream FauxModelDefinition.inputLimits.
InputLimits *ModelInputLimits
// Cost is the per-million-token price; nil is a free model. Its Tiers are ignored (upstream's cost has none).
Cost *ModelCost
ContextWindow int
MaxTokens int
}
type FauxProviderHandle ¶
type FauxProviderHandle struct {
// contains filtered or unexported fields
}
FauxProviderHandle is faux.ts FauxProviderHandle: the registered faux provider with its models and shared response queue.
func NewFauxProvider ¶
func NewFauxProvider(cfg FauxConfig) *FauxProviderHandle
NewFauxProvider creates a deterministic response source with a shared queue and per-session cache simulation.
func (*FauxProviderHandle) API ¶
func (p *FauxProviderHandle) API() API
API is the API name every model of the handle carries (faux.ts FauxProviderHandle.api): the requested one, else "faux:<time>:<random>".
func (*FauxProviderHandle) AppendResponses ¶
func (p *FauxProviderHandle) AppendResponses(responses []FauxResponseStep)
func (*FauxProviderHandle) CallCount ¶
func (p *FauxProviderHandle) CallCount() int
func (*FauxProviderHandle) CancelledDeferred ¶
func (p *FauxProviderHandle) CancelledDeferred() []DeferredHandle
func (*FauxProviderHandle) Close ¶
func (p *FauxProviderHandle) Close() error
func (*FauxProviderHandle) DeferredFetchCount ¶
func (p *FauxProviderHandle) DeferredFetchCount() int
func (*FauxProviderHandle) GetModel ¶
func (p *FauxProviderHandle) GetModel(id ...string) *Model
GetModel returns a canonical model with its provider identity, or nil for an unknown ID.
func (*FauxProviderHandle) ID ¶
func (p *FauxProviderHandle) ID() string
func (*FauxProviderHandle) Models ¶
func (p *FauxProviderHandle) Models() []*Model
func (*FauxProviderHandle) PendingResponseCount ¶
func (p *FauxProviderHandle) PendingResponseCount() int
func (*FauxProviderHandle) Provider ¶
func (p *FauxProviderHandle) Provider() *ModelsProvider
Provider exposes the model-aware provider definition for an explicit Models collection.
func (*FauxProviderHandle) SetResponses ¶
func (p *FauxProviderHandle) SetResponses(responses []FauxResponseStep)
func (*FauxProviderHandle) State ¶
func (p *FauxProviderHandle) State() *FauxProviderState
State is the live call counters of the provider (faux.ts FauxProviderHandle.state).
func (*FauxProviderHandle) Stream ¶
func (p *FauxProviderHandle) Stream(ctx context.Context, request TranscriptContext, options StreamOptions) (*AssistantMessageEventStream, error)
func (*FauxProviderHandle) Unregister ¶
func (p *FauxProviderHandle) Unregister()
type FauxProviderRegistration ¶
type FauxProviderRegistration = FauxProviderHandle
FauxProviderRegistration is faux.ts FauxProviderRegistration: the handle plus unregister, which FauxProviderHandle.Unregister is.
func RegisterFauxProvider ¶
func RegisterFauxProvider(options ...RegisterFauxProviderOptions) *FauxProviderRegistration
RegisterFauxProvider is compat.ts registerFauxProvider: it creates the faux provider (createFauxCore) and registers its API in the global API registry under a generated `faux-provider-<id>` source id, so Stream and StreamSimple reach it for a model of its API. Unregister removes the registry entry.
type FauxProviderState ¶
type FauxProviderState struct {
// contains filtered or unexported fields
}
FauxProviderState is the live state of a faux provider (faux.ts FauxProviderState). A factory receives it while other streams run, so every member is read through a method that is safe across concurrent factories.
func (*FauxProviderState) CallCount ¶
func (s *FauxProviderState) CallCount() int
CallCount is the number of streams started on the provider (faux.ts FauxProviderState.callCount).
func (*FauxProviderState) CancelledDeferred ¶
func (s *FauxProviderState) CancelledDeferred() []DeferredHandle
CancelledDeferred returns copies of the handles passed to the provider's cancelDeferred, in call order (faux.ts FauxProviderState.cancelledDeferred).
func (*FauxProviderState) DeferredFetchCount ¶
func (s *FauxProviderState) DeferredFetchCount() int
DeferredFetchCount is the number of deferred fetches started on the provider (faux.ts FauxProviderState.deferredFetchCount).
type FauxResponse ¶
type FauxResponse struct {
API API
Provider string
Model string
Usage Usage
Deferred *DeferredHandle
// Timestamp supplies the response's Unix-millisecond timestamp; nil keeps the provider clock.
Timestamp *int64
Content []FauxContentBlock
StopReason string
ErrorMessage string
ResponseID string
// The scripted message keeps these members on every partial and on the final message (faux.ts:282-291 overwrites only api, provider, model, timestamp and usage).
ResponseModel string
ProviderThinkingLevel string
ThinkingLevel ModelThinkingLevel
Diagnostics []AssistantMessageDiagnostic
RawStopReason string
EndTurn *bool
// DurationMs is the scripted message's durationMs; the event stream measures it only when the message has none (event-stream.ts:127).
DurationMs *int64
// contains filtered or unexported fields
}
FauxResponse is the scripted AssistantMessage of faux.ts: a FauxResponseStep that carries one response. API, Provider, Model and Usage are the message's own members; the provider replaces them on every message it streams (faux.ts cloneMessage and withUsageEstimate), so a scripted value never reaches a caller.
func (FauxResponse) AssistantMessage ¶
func (r FauxResponse) AssistantMessage() AssistantMessage
AssistantMessage is the AssistantMessage a scripted FauxResponse stands for, the value faux.ts factories and fauxAssistantMessage return. A response without a timestamp takes the creation time, as fauxAssistantMessage does.
type FauxResponseFactory ¶
type FauxResponseFactory func(TranscriptContext, StreamOptions, *FauxProviderState, *Model) (AssistantMessage, error)
FauxResponseFactory is awaited by its stream; a returned error terminates that stream before generation.
type FauxResponseStep ¶
type FauxResponseStep interface {
// contains filtered or unexported methods
}
FauxResponseStep is faux.ts FauxResponseStep, `AssistantMessage | FauxResponseFactory`: a scripted AssistantMessage (an ai.AssistantMessage or the FauxResponse that fauxAssistantMessage builds) or a FauxResponseFactory.
func FauxFactoryStep ¶
func FauxFactoryStep(factory FauxResponseFactory) FauxResponseStep
FauxFactoryStep is the step for a function literal, which has no FauxResponseFactory methods until it is converted.
func FauxStaticStep ¶
func FauxStaticStep(response FauxResponse) FauxResponseStep
FauxStaticStep is the step for a scripted response.
type FauxTokenSize ¶
FauxTokenSize is the faux.ts tokenSize option {min?, max?}. A nil Min or Max is absent (the TypeScript `??` default), so a set 0 is not the default.
type FauxToolCallOptions ¶
type FauxToolCallOptions struct {
// ID names the tool call; empty draws a random "tool:..." id.
ID string
}
FauxToolCallOptions are the options of faux.ts fauxToolCall.
type FetchFunction ¶
FetchFunction is a per-request HTTP transport. The request context owns cancellation; the caller owns and closes the returned streaming response body. Ports packages/ai/src/types.ts (ProviderRequestOptions.fetch).
func CreateAIBindingFetch ¶
func CreateAIBindingFetch(binding AIBinding) (FetchFunction, error)
CreateAIBindingFetch returns a fetch backed by the AI binding, for models whose base URL names a route the binding serves, including the gateway's provider passthrough `https://workers-binding.ai/ai-gateway/gateways/{gateway}/{provider}/...`. Requests pass through untouched. A binding without Fetch is rejected here, not on the first request. Set the result as `StreamOptions.Fetch` with `&http.Client{Transport: fetch}`.
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 a fresh copy of the provider's stored catalog. Concurrent readers share reloads and cancel their waits independently; unchanged files use the cached revision.
func (*FileModelsStore) Write ¶
func (s *FileModelsStore) Write(ctx context.Context, providerID string, entry ModelsStoreEntry) error
Write replaces the provider's stored catalog.
type GeminiContent ¶
type GeminiContent = geminiContent
GeminiContent is one Google `Content` of a generateContent request.
func ConvertGoogleMessages ¶
func ConvertGoogleMessages(model *Model, transcript TranscriptContext) []GeminiContent
ConvertGoogleMessages converts a transcript to the Google `Content[]` of model's request: system messages are collapsed, the leading one is dropped (it is sent as systemInstruction) and the rest is converted for the model's provider, id and image support. Ports google-shared.ts convertMessages(model, context).
type GeneratedModel ¶
type GeneratedModel struct {
ID string
Provider string
DisplayName string
API API
BaseURL string
Headers map[string]string
Compat *ModelCompat
ThinkingLevelMap map[ModelThinkingLevel]*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
// Record is the entry's JSON as Pi's catalog data spells it: the model object Pi serializes, member order included.
Record string
}
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. It omits the models of a stripped API (OfferedModels); LookupModel and LookupModelExact still find them.
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 OfferedGeneratedModels ¶
func OfferedGeneratedModels(models []GeneratedModel) []*GeneratedModel
OfferedGeneratedModels returns pointers to the entries of models whose built models OfferedModels keeps, in catalog order.
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 preserves catalog prices, limits, modalities, capabilities and provider metadata for runtime requests.
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
// ThinkingLevelMap carries the selected model's logical-to-provider thinking mapping. Nil uses the catalog mapping.
ThinkingLevelMap ThinkingLevelMap
// ModelMetadata is the selected model, which an OnProviderStreamEvent observer receives. Nil hands the observer the configured identity only.
ModelMetadata *Model
// contains filtered or unexported fields
}
GoogleConfig configures the Google Gemini provider.
type GoogleSdkThinkingLevel ¶
type GoogleSdkThinkingLevel string
GoogleSdkThinkingLevel is the @google/genai ThinkingLevel enum a thinkingConfig carries (google-shared.ts GoogleSdkThinkingLevel).
func ToGoogleSdkThinkingLevel ¶
func ToGoogleSdkThinkingLevel(level GoogleThinkingLevel) GoogleSdkThinkingLevel
ToGoogleSdkThinkingLevel selects the SDK enum value for a Google API level (google-shared.ts:98 toGoogleSdkThinkingLevel).
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" )
func ToGoogleThinkingLevel ¶
func ToGoogleThinkingLevel(level ResolvedGoogleThinkingLevel) GoogleThinkingLevel
ToGoogleThinkingLevel maps a resolved level to Google's enum value (google-shared.ts:85 toGoogleThinkingLevel).
type GoogleThinkingOptions ¶
type GoogleThinkingOptions struct {
Enabled bool `json:"enabled"`
BudgetTokens *int `json:"budgetTokens,omitempty"`
Level GoogleThinkingLevel `json:"level,omitempty"`
}
GoogleThinkingOptions is the raw Google API thinking object. A level takes precedence over a budget; a non-nil zero budget remains explicit.
type GoogleVertexConfig ¶
type GoogleVertexConfig struct {
APIKey string
Model string
ProviderID string
BaseURL string
Project string
Location string
Headers map[string]string
ThinkingLevelMap ThinkingLevelMap
// ModelMetadata is the selected model, which an OnProviderStreamEvent observer receives. Nil hands the observer the configured identity only.
ModelMetadata *Model
}
GoogleVertexConfig configures Vertex API-key or Application Default Credentials requests.
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 GrammarVariants ¶
type GrammarVariants = map[GrammarFormat]string
GrammarVariants maps a grammar format to its definition.
upstream: packages/ai/src/types.ts:698
type ImageAPI ¶
type ImageAPI string
ImageAPI identifies an image-generation provider API.
const APIImagesOpenRouter ImageAPI = "openrouter-images"
type ImageContent ¶
ImageContent is a base64-encoded image in a message.
func (ImageContent) AppendStringify ¶
func (content ImageContent) AppendStringify(dst []byte) ([]byte, error)
AppendStringify appends the JSON.stringify text of MarshalJSON's output to dst (sdkjson.StringifyAppender).
func (ImageContent) MarshalJSON ¶
func (content ImageContent) MarshalJSON() ([]byte, error)
type ImageModel ¶
type ImageModel struct {
ID string
Name string
API ImageAPI
Provider string
BaseURL string
Headers map[string]string
Input []string
// InputLimits carries provider input limits and cache-safe preprocessing metadata.
InputLimits *ModelInputLimits
// Output always includes "image"; "text" means the model can also return text blocks.
Output []string
Cost ModelCost
// contains filtered or unexported fields
}
ImageModel is an image-generation model. It is usable with Models.GenerateImages only.
func GetImageModel ¶
func GetImageModel(provider BuiltinImageProvider, modelID string) (ImageModel, bool)
GetImageModel returns a generated image model by provider and id.
func GetImageModels ¶
func GetImageModels(provider BuiltinImageProvider) []ImageModel
GetImageModels returns generated image models for provider in stable ID order.
func (*ImageModel) CostRates ¶
func (m *ImageModel) CostRates() ModelCost
CostRates returns the image model's per-million-token prices. A nil model has no price.
func (*ImageModel) ModelID ¶
func (m *ImageModel) ModelID() string
func (*ImageModel) ModelType ¶
func (*ImageModel) ModelType() ModelType
func (*ImageModel) ProviderID ¶
func (m *ImageModel) ProviderID() string
type ImageModelCatalog ¶
type ImageModelCatalog struct {
// contains filtered or unexported fields
}
ImageModelCatalog holds the image models of one provider by model id.
func AmazonBedrockImageModels ¶
func AmazonBedrockImageModels() ImageModelCatalog
AmazonBedrockImageModels is AMAZON_BEDROCK_IMAGE_MODELS.
func AntLingImageModels ¶
func AntLingImageModels() ImageModelCatalog
AntLingImageModels is ANT_LING_IMAGE_MODELS.
func AnthropicImageModels ¶
func AnthropicImageModels() ImageModelCatalog
AnthropicImageModels is ANTHROPIC_IMAGE_MODELS.
func AzureImageModels ¶
func AzureImageModels() ImageModelCatalog
AzureImageModels is AZURE_IMAGE_MODELS.
func BasetenImageModels ¶
func BasetenImageModels() ImageModelCatalog
BasetenImageModels is BASETEN_IMAGE_MODELS.
func CerebrasImageModels ¶
func CerebrasImageModels() ImageModelCatalog
CerebrasImageModels is CEREBRAS_IMAGE_MODELS.
func CloudflareAIGatewayImageModels ¶
func CloudflareAIGatewayImageModels() ImageModelCatalog
CloudflareAIGatewayImageModels is CLOUDFLARE_AI_GATEWAY_IMAGE_MODELS.
func CloudflareWorkersAIImageModels ¶
func CloudflareWorkersAIImageModels() ImageModelCatalog
CloudflareWorkersAIImageModels is CLOUDFLARE_WORKERS_AI_IMAGE_MODELS.
func DeepSeekImageModels ¶
func DeepSeekImageModels() ImageModelCatalog
DeepSeekImageModels is DEEPSEEK_IMAGE_MODELS.
func FireworksImageModels ¶
func FireworksImageModels() ImageModelCatalog
FireworksImageModels is FIREWORKS_IMAGE_MODELS.
func GitHubCopilotImageModels ¶
func GitHubCopilotImageModels() ImageModelCatalog
GitHubCopilotImageModels is GITHUB_COPILOT_IMAGE_MODELS.
func GoogleImageModels ¶
func GoogleImageModels() ImageModelCatalog
GoogleImageModels is GOOGLE_IMAGE_MODELS.
func GoogleVertexImageModels ¶
func GoogleVertexImageModels() ImageModelCatalog
GoogleVertexImageModels is GOOGLE_VERTEX_IMAGE_MODELS.
func GroqImageModels ¶
func GroqImageModels() ImageModelCatalog
GroqImageModels is GROQ_IMAGE_MODELS.
func HuggingFaceImageModels ¶
func HuggingFaceImageModels() ImageModelCatalog
HuggingFaceImageModels is HUGGINGFACE_IMAGE_MODELS.
func KimiCodingImageModels ¶
func KimiCodingImageModels() ImageModelCatalog
KimiCodingImageModels is KIMI_CODING_IMAGE_MODELS.
func MetaImageModels ¶
func MetaImageModels() ImageModelCatalog
MetaImageModels is META_IMAGE_MODELS.
func MiniMaxCNImageModels ¶
func MiniMaxCNImageModels() ImageModelCatalog
MiniMaxCNImageModels is MINIMAX_CN_IMAGE_MODELS.
func MiniMaxImageModels ¶
func MiniMaxImageModels() ImageModelCatalog
MiniMaxImageModels is MINIMAX_IMAGE_MODELS.
func MistralImageModels ¶
func MistralImageModels() ImageModelCatalog
MistralImageModels is MISTRAL_IMAGE_MODELS.
func MoonshotAICNImageModels ¶
func MoonshotAICNImageModels() ImageModelCatalog
MoonshotAICNImageModels is MOONSHOTAI_CN_IMAGE_MODELS.
func MoonshotAIImageModels ¶
func MoonshotAIImageModels() ImageModelCatalog
MoonshotAIImageModels is MOONSHOTAI_IMAGE_MODELS.
func NVIDIAImageModels ¶
func NVIDIAImageModels() ImageModelCatalog
NVIDIAImageModels is NVIDIA_IMAGE_MODELS.
func OpenAICodexImageModels ¶
func OpenAICodexImageModels() ImageModelCatalog
OpenAICodexImageModels is OPENAI_CODEX_IMAGE_MODELS.
func OpenAIImageModels ¶
func OpenAIImageModels() ImageModelCatalog
OpenAIImageModels is OPENAI_IMAGE_MODELS.
func OpenCodeGoImageModels ¶
func OpenCodeGoImageModels() ImageModelCatalog
OpenCodeGoImageModels is OPENCODE_GO_IMAGE_MODELS.
func OpenCodeImageModels ¶
func OpenCodeImageModels() ImageModelCatalog
OpenCodeImageModels is OPENCODE_IMAGE_MODELS.
func OpenRouterImageModels ¶
func OpenRouterImageModels() ImageModelCatalog
OpenRouterImageModels is OPENROUTER_IMAGE_MODELS.
func QwenTokenPlanCNImageModels ¶
func QwenTokenPlanCNImageModels() ImageModelCatalog
QwenTokenPlanCNImageModels is QWEN_TOKEN_PLAN_CN_IMAGE_MODELS.
func QwenTokenPlanImageModels ¶
func QwenTokenPlanImageModels() ImageModelCatalog
QwenTokenPlanImageModels is QWEN_TOKEN_PLAN_IMAGE_MODELS.
func QwenTokenPlanIndividualImageModels ¶
func QwenTokenPlanIndividualImageModels() ImageModelCatalog
QwenTokenPlanIndividualImageModels is QWEN_TOKEN_PLAN_INDIVIDUAL_IMAGE_MODELS.
func RadiusImageModels ¶
func RadiusImageModels() ImageModelCatalog
RadiusImageModels is RADIUS_IMAGE_MODELS.
func TogetherImageModels ¶
func TogetherImageModels() ImageModelCatalog
TogetherImageModels is TOGETHER_IMAGE_MODELS.
func TypesafeImageModels ¶
func TypesafeImageModels() ImageModelCatalog
TypesafeImageModels is TYPESAFE_IMAGE_MODELS.
func VercelAIGatewayImageModels ¶
func VercelAIGatewayImageModels() ImageModelCatalog
VercelAIGatewayImageModels is VERCEL_AI_GATEWAY_IMAGE_MODELS.
func XiaomiImageModels ¶
func XiaomiImageModels() ImageModelCatalog
XiaomiImageModels is XIAOMI_IMAGE_MODELS.
func XiaomiTokenPlanAMSImageModels ¶
func XiaomiTokenPlanAMSImageModels() ImageModelCatalog
XiaomiTokenPlanAMSImageModels is XIAOMI_TOKEN_PLAN_AMS_IMAGE_MODELS.
func XiaomiTokenPlanCNImageModels ¶
func XiaomiTokenPlanCNImageModels() ImageModelCatalog
XiaomiTokenPlanCNImageModels is XIAOMI_TOKEN_PLAN_CN_IMAGE_MODELS.
func XiaomiTokenPlanSGPImageModels ¶
func XiaomiTokenPlanSGPImageModels() ImageModelCatalog
XiaomiTokenPlanSGPImageModels is XIAOMI_TOKEN_PLAN_SGP_IMAGE_MODELS.
func ZAICodingCNImageModels ¶
func ZAICodingCNImageModels() ImageModelCatalog
ZAICodingCNImageModels is ZAI_CODING_CN_IMAGE_MODELS.
func (ImageModelCatalog) IDs ¶
func (c ImageModelCatalog) IDs() []string
IDs returns the model ids in catalog order (Object.keys).
type ImagesAPIProvider ¶
type ImagesAPIProvider struct {
API ImageAPI
GenerateImages ImagesFunction
}
ImagesAPIProvider registers a provider implementation for an ImageAPI.
func GetImagesAPIProvider ¶
func GetImagesAPIProvider(api ImageAPI) (ImagesAPIProvider, bool)
GetImagesAPIProvider returns the registered provider for api.
type ImagesContext ¶
type ImagesContext struct {
Input []ImagesInputContent
}
ImagesContext is the input to an image-generation request.
func (ImagesContext) MarshalJSON ¶
func (c ImagesContext) MarshalJSON() ([]byte, error)
MarshalJSON writes the context as {input}.
func (*ImagesContext) UnmarshalJSON ¶
func (c *ImagesContext) UnmarshalJSON(data []byte) error
UnmarshalJSON reads {input}.
type ImagesFunction ¶
type ImagesFunction func(context.Context, ImageModel, ImagesContext, ProviderImagesOptions) AssistantImages
ImagesFunction is an image-generation provider function.
type ImagesInputContent ¶
type ImagesInputContent = ContentBlock
ImagesInputContent is one block of an image-generation request: text or an image (types.ts:614).
type ImagesOptions ¶
type ImagesOptions struct {
// TelemetryContext parents provider request spans; nil means no recording backend.
TelemetryContext telemetry.TelemetryContext
// Fetch replaces HTTP execution without changing the caller's request context or redirect policy.
Fetch *http.Client
APIKey string
// APIKeySet distinguishes an explicit empty key from an omitted override.
APIKeySet bool
Headers ProviderHeaders
Env map[string]string
Metadata map[string]any
TimeoutMs int
// MaxRetries is the retry budget after a retryable failure. Nil uses retry.provider.maxRetries; an explicit zero disables retries.
MaxRetries *int
// MaxRetryDelayMs caps a server-requested retry delay. Nil means 60000; 0 disables the cap.
MaxRetryDelayMs *int
OnPayload func(payload any, model ImageModel) (any, bool, error)
OnResponse func(response ProviderResponse, model ImageModel) error
}
ImagesOptions configures image-generation provider requests.
type ImagesOutputContent ¶
type ImagesOutputContent = ContentBlock
ImagesOutputContent is one block of an image-generation result: text or an image (types.ts:615).
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. Seed keys use lexical order because Go maps have no insertion order; later writes retain their insertion order.
func (*InMemoryAuthStorage) Delete ¶
func (s *InMemoryAuthStorage) Delete(ctx context.Context, providerID string) error
Delete removes a credential in the same cancellable queue as Modify.
func (*InMemoryAuthStorage) List ¶
func (s *InMemoryAuthStorage) List(ctx context.Context) ([]CredentialInfo, error)
List implements CredentialStore after preceding store operations settle.
func (*InMemoryAuthStorage) Modify ¶
func (s *InMemoryAuthStorage) Modify(ctx context.Context, providerID string, fn func(current *Credential) (*Credential, error)) (*Credential, error)
Modify serializes callbacks across providers with isolated input and result snapshots. Cancellation releases the caller immediately, but an active callback keeps its queue position until settlement and cannot commit a canceled write.
func (*InMemoryAuthStorage) Read ¶
func (s *InMemoryAuthStorage) Read(ctx context.Context, providerID string) (*Credential, error)
Read returns an isolated credential snapshot after preceding store operations settle. Cancellation releases the caller without bypassing an active mutation.
type InMemoryCredentialStore ¶
type InMemoryCredentialStore struct {
// contains filtered or unexported fields
}
InMemoryCredentialStore stores literal credentials and serializes mutations per provider. Unlike app AuthStorage, it does not evaluate configuration expressions.
func NewInMemoryCredentialStore ¶
func NewInMemoryCredentialStore() *InMemoryCredentialStore
func (*InMemoryCredentialStore) Delete ¶
func (s *InMemoryCredentialStore) Delete(ctx context.Context, providerID string) error
func (*InMemoryCredentialStore) List ¶
func (s *InMemoryCredentialStore) List(ctx context.Context) ([]CredentialInfo, error)
func (*InMemoryCredentialStore) Modify ¶
func (s *InMemoryCredentialStore) Modify(ctx context.Context, providerID string, fn func(*Credential) (*Credential, error)) (*Credential, error)
func (*InMemoryCredentialStore) Read ¶
func (s *InMemoryCredentialStore) Read(ctx context.Context, providerID string) (*Credential, error)
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) DeleteWith ¶
func (s *InMemoryModelsStore) DeleteWith(ctx context.Context, providerID string, options ModelsStoreOperationOptions) error
DeleteWith is InMemoryModelsStore.delete(providerId, options).
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) ReadWith ¶
func (s *InMemoryModelsStore) ReadWith(ctx context.Context, providerID string, options ModelsStoreOperationOptions) (*ModelsStoreEntry, error)
ReadWith is InMemoryModelsStore.read(providerId, options).
func (*InMemoryModelsStore) Write ¶
func (s *InMemoryModelsStore) Write(ctx context.Context, providerID string, entry ModelsStoreEntry) error
Write stores a copy of the provider's catalog.
func (*InMemoryModelsStore) WriteWith ¶
func (s *InMemoryModelsStore) WriteWith(ctx context.Context, providerID string, entry ModelsStoreEntry, options ModelsStoreOperationOptions) error
WriteWith is InMemoryModelsStore.write(providerId, entry, options).
type JsonObject ¶
JsonObject is a provider-facing JSON object (types.ts:459).
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 JsonValue ¶
type JsonValue = any
JsonValue is any JSON value: null, a boolean, a number, a string, an array or a JsonObject (types.ts:458).
type KnownProvider ¶
type KnownProvider string
KnownProvider is a built-in provider id. Ports packages/ai/src/types.ts (KnownProvider).
const ( KnownProviderAmazonBedrock KnownProvider = "amazon-bedrock" KnownProviderAntLing KnownProvider = "ant-ling" KnownProviderAnthropic KnownProvider = "anthropic" KnownProviderGoogle KnownProvider = "google" KnownProviderGoogleVertex KnownProvider = "google-vertex" KnownProviderOpenai KnownProvider = "openai" KnownProviderAzure KnownProvider = "azure" KnownProviderOpenaiCodex KnownProvider = "openai-codex" KnownProviderRadius KnownProvider = "radius" KnownProviderTypesafe KnownProvider = "typesafe" KnownProviderNvidia KnownProvider = "nvidia" KnownProviderDeepseek KnownProvider = "deepseek" KnownProviderGithubCopilot KnownProvider = "github-copilot" KnownProviderXai KnownProvider = "xai" KnownProviderGroq KnownProvider = "groq" KnownProviderCerebras KnownProvider = "cerebras" KnownProviderOpenrouter KnownProvider = "openrouter" KnownProviderVercelAiGateway KnownProvider = "vercel-ai-gateway" KnownProviderZai KnownProvider = "zai" KnownProviderZaiCodingCn KnownProvider = "zai-coding-cn" KnownProviderMistral KnownProvider = "mistral" KnownProviderMinimax KnownProvider = "minimax" KnownProviderMinimaxCn KnownProvider = "minimax-cn" KnownProviderMoonshotai KnownProvider = "moonshotai" KnownProviderMoonshotaiCn KnownProvider = "moonshotai-cn" KnownProviderHuggingface KnownProvider = "huggingface" KnownProviderFireworks KnownProvider = "fireworks" KnownProviderTogether KnownProvider = "together" KnownProviderBaseten KnownProvider = "baseten" KnownProviderOpencode KnownProvider = "opencode" KnownProviderOpencodeGo KnownProvider = "opencode-go" KnownProviderKimiCoding KnownProvider = "kimi-coding" KnownProviderMeta KnownProvider = "meta" KnownProviderCloudflareWorkersAi KnownProvider = "cloudflare-workers-ai" KnownProviderCloudflareAiGateway KnownProvider = "cloudflare-ai-gateway" KnownProviderQwenTokenPlan KnownProvider = "qwen-token-plan" KnownProviderQwenTokenPlanCn KnownProvider = "qwen-token-plan-cn" KnownProviderQwenTokenPlanIndividual KnownProvider = "qwen-token-plan-individual" KnownProviderXiaomi KnownProvider = "xiaomi" KnownProviderXiaomiTokenPlanCn KnownProvider = "xiaomi-token-plan-cn" KnownProviderXiaomiTokenPlanAms KnownProvider = "xiaomi-token-plan-ams" KnownProviderXiaomiTokenPlanSgp KnownProvider = "xiaomi-token-plan-sgp" )
type LazyAPICapabilities ¶
LazyAPICapabilities declares optional methods without loading the implementation.
type LazyOAuthInput ¶
type LazyOAuthInput struct {
Name string
IsSubscription bool
LoginLabel string
// Load returns the flow. It runs at most once, at the first Login, Refresh or ToAuth; its error is returned by every one of those calls, as a rejected promise stays rejected.
Load func() (*OAuthAuth, error)
}
LazyOAuthInput describes an OAuth method whose flow is loaded on first use.
upstream: packages/ai/src/auth/helpers.ts:40 (lazyOAuth input)
type LlamaCppLabeledQuestion ¶
type LlamaCppLabeledQuestion struct {
// Content is the user message: the state, the questions and this question's answer labels.
Content string
// Labels are the answer labels the model can emit, in the order of Keys.
Labels []string
// Keys are the answer keys each label stands for: choice keys, level indices, or "true" and "false".
Keys []string
}
LlamaCppLabeledQuestion is one question rendered for the model.
func LlamaCppRenderQuestion ¶
func LlamaCppRenderQuestion(request ClassifierContext, id string) (LlamaCppLabeledQuestion, error)
LlamaCppRenderQuestion writes one question of the request as a user message and picks its labels. It fails for unsupported option counts.
The message is the state, every question of the request with its options, the state again, and then this question with labeled options. A causal model reads the first copy of the state before it knows what is asked; the second copy is read with the questions in view (prompt repetition). Everything before the final question is the same for all questions of a request, so the server's prompt cache evaluates it once.
type LoginOptions ¶
type LoginOptions struct {
// GetDeviceID returns the stable ID of this app installation, for example sent to OpenAI as its agent host ID.
// Login flows call it only when they need it, so apps can create the ID on first use; it must return the same ID on
// every later call. Nil means the app supplies none.
GetDeviceID func() string
// AgentName is the name this app introduces itself with during login, for example OpenAI's agent name hint and the Codex originator. Nil means the flow's own default; an empty name is kept as given (auth/types.ts:206-213).
AgentName *string
}
LoginOptions is app-supplied context for Models.Login.
type Message ¶
type Message interface {
MessageRole() string
// contains filtered or unexported methods
}
Message is the closed provider-facing transcript union.
func RepairToolFlow ¶
RepairToolFlow makes every tool result answer an open tool call, before transformMessages accounts for the calls.
pig divergence (D48): upstream transformMessages sends a result whose calling turn was dropped, a repeated result, and a result that arrives after its flow closed (while it also adds a "No result provided" placeholder for the call), and the provider rejects the request. Here an out-of-order result moves into the slot of its call, and an orphan or repeat is dropped. A result is matched in order against open calls rather than by id alone, because a provider may number its calls per response and reuse an id every turn. A call of an errored or aborted turn is not open: transformMessages omits that turn. A result is not moved back past a turn that opens a call with its id again: it answers that turn, as in Pi's request, so a request Pi sends with an intact tool flow reaches the provider unchanged.
func TransformMessages ¶
func TransformMessages(messages []Message, model *Model, normalizeToolCallId func(string, *Model, AssistantMessage) string) []Message
TransformMessages prepares history for a target provider without changing retained messages. It preserves valid same-model signatures, drops another model's thinking, normalizes foreign content and paired IDs, drops incomplete assistant turns, and closes unanswered tool calls before the next turn while holding intervening system updates.
type MistralConfig ¶
type MistralConfig struct {
// ModelMetadata retains the selected model's input capabilities, identity and thinking map.
ModelMetadata *Model
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 {
// Type is optional: chat is the default model type, so models without it are chat models.
Type ModelType
ID string
DisplayName string
Provider Provider
Capabilities ModelCapabilities
ProviderMeta ProviderMetadata
Input []ModelInputModality
ThinkingLevelMap ThinkingLevelMap
SamplingParams map[string]any
// SamplingParamsByThinkingLevel overrides SamplingParams for the effective thinking level on OpenAI-compatible APIs.
SamplingParamsByThinkingLevel SamplingParamsByThinkingLevel
PromptCache ModelPromptCache
// InputLimits mirrors upstream Model.inputLimits.
InputLimits *ModelInputLimits
// contains filtered or unexported fields
}
Model pairs an identifier with a provider and capabilities.
func GetBuiltinModel ¶
GetBuiltinModel reads one built-in chat model, or nil (providers/all.ts getBuiltinModel; compat.ts getModel).
func GetBuiltinModels ¶
GetBuiltinModels lists the built-in chat models of one provider.
func GetRadiusModels ¶
func GetRadiusModels(providerID string, credential *Credential) []*Model
GetRadiusModels returns the legacy credential catalog bound to providerID (radius-config.ts:70).
func GetRadiusModelsFromConfig ¶
func GetRadiusModelsFromConfig(providerID string, config RadiusGatewayConfig) []*Model
GetRadiusModelsFromConfig binds a gateway catalog to providerID: Model<"pi-messages">[] (radius-config.ts:61).
func ResolveCloudflareModel ¶
func ResolveCloudflareModel(model *Model, env ProviderEnv) *Model
ResolveCloudflareModel materializes the Cloudflare account and gateway placeholders of model's base URL from env (cloudflare-stream.ts:6-17). A missing value keeps its placeholder and an empty one replaces it with the empty string. A nil env or an endpoint without placeholders returns model itself; otherwise the result is a copy and model is untouched.
func (*Model) CostRates ¶
CostRates returns the model's per-million-token prices in upstream Model.cost shape. A nil model has no price.
func (*Model) ProviderID ¶
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, presence included: nil is no tiers member, empty is tiers: [] (see ModelCost).
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,omitzero"`
}
ModelCost is the provider price per million tokens for one model. Tiers is optional (types.ts ModelCost.tiers): a nil Tiers is an absent member and an empty one an authored [], which JSON keeps apart, so copies of a cost keep a nil Tiers nil and an empty one empty (slices.Clone, not append to nil).
func OpenRouterCost ¶
func OpenRouterCost(pricing *OpenRouterPricing) ModelCost
OpenRouterCost converts OpenRouter's $/token prices to $/1M tokens. A missing, invalid or negative base price is 0. Prompt-length overrides become request-wide tiers; a rate a tier does not list keeps the base price. Time-of-day overrides are skipped because a ModelCost cannot express them.
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 ModelInputModality ¶
type ModelInputModality = string
ModelInputModality is an input a model accepts (model-schema.ts ModelInputModality): "text" or "image". It is an alias of string, so the lists of catalog and models.json inputs stay []string.
const ( ModelInputText ModelInputModality = "text" ModelInputImage ModelInputModality = "image" )
The modalities of ModelInputModality.
type ModelPromptCache ¶
ModelPromptCache gives the best-effort prompt-cache lifetime in seconds for each retention tier. Pi's ModelPromptCacheSchema types a lifetime as Type.Number({ exclusiveMinimum: 0 }), so it need not be whole.
type ModelThinkingLevel ¶
type ModelThinkingLevel string
ModelThinkingLevel is "off" or a ThinkingLevel (types.ts ModelThinkingLevel); it is the level a model supports, maps and clamps to.
const ( ThinkingOff ModelThinkingLevel = "off" ThinkingMinimal ModelThinkingLevel = "minimal" ThinkingLow ModelThinkingLevel = "low" ThinkingMedium ModelThinkingLevel = "medium" ThinkingHigh ModelThinkingLevel = "high" ThinkingXHigh ModelThinkingLevel = "xhigh" ThinkingMax ModelThinkingLevel = "max" )
The levels of ModelThinkingLevel: "off" and the request levels.
func ClampReasoning ¶
func ClampReasoning(effort ModelThinkingLevel) ModelThinkingLevel
ClampReasoning maps the levels above high, xhigh and max, to high and returns every other level, including the empty "undefined" level, unchanged. Mirrors upstream clampReasoning (simple-options.ts:77).
func ClampThinkingLevel ¶
func ClampThinkingLevel(m *Model, level ModelThinkingLevel) ModelThinkingLevel
ClampThinkingLevel clamps level to the nearest supported thinking level. Mirrors upstream models.ts:clampThinkingLevel.
func GetSupportedThinkingLevels ¶
func GetSupportedThinkingLevels(m *Model) []ModelThinkingLevel
GetSupportedThinkingLevels returns the model's supported thinking levels. Selected model reasoning metadata or a native MaxThinking capability enables reasoning.
func (ModelThinkingLevel) ReasoningOption ¶
func (level ModelThinkingLevel) ReasoningOption() ThinkingLevel
ReasoningOption is the request option for a model level: "off" is no request (the `reasoning` option omitted), every other level is itself.
type ModelType ¶
type ModelType string
ModelType names what a catalog entry is for. It decides which Models operation accepts the entry.
func GetModelType ¶
GetModelType returns the type of a model. Chat models without an explicit Type are chat models.
type Models ¶
type Models struct {
// contains filtered or unexported fields
}
Models owns provider selection, request auth and refresh publication. Callers own operation contexts; callbacks must settle before their owners are discarded.
func BuiltinModels ¶
func BuiltinModels(options ...CreateModelsOptions) *Models
BuiltinModels returns a Models collection with every built-in provider registered.
func CreateModels ¶
func CreateModels(options ...CreateModelsOptions) *Models
func CreateModelsWithModelAuth ¶
func CreateModelsWithModelAuth(modelAuth func(ctx context.Context, model *Model, overrides AuthResolutionOverrides) (*AuthResult, error), options ...CreateModelsOptions) *Models
CreateModelsWithModelAuth supplies model-level authentication for GetModelAuth and every request. The callback must resolve provider auth with GetAuth, not GetModelAuth, to avoid recursion.
func (*Models) CancelDeferred ¶
func (m *Models) CancelDeferred(ctx context.Context, model *Model, handle DeferredHandle, options ...DeferredCancelOptions) error
func (*Models) CheckAuthWith ¶
func (m *Models) CheckAuthWith(ctx context.Context, providerID string, options AuthOperationOptions) (*AuthCheck, error)
CheckAuthWith is Models.checkAuth(providerId, options): CheckAuth cancelled also by options.Signal.
func (*Models) Classify ¶
func (m *Models) Classify(ctx context.Context, model *ClassifierModel, request ClassifierContext, options ...ModelsClassifierOptions) ClassifierResult
Classify classifies structured state through the owning provider with auth resolved like Stream. It never returns an error: failures and cancellation are error or aborted results. Ports Models.classify (.upstream/v0.99.1/packages/ai/src/models.ts:966).
func (*Models) ClearProviders ¶
func (m *Models) ClearProviders()
func (*Models) Close ¶
func (m *Models) Close()
Close cancels active refreshes and joins collection-owned operations. Completed refresh signals keep their existing lifetime semantics.
func (*Models) Complete ¶
func (m *Models) Complete(ctx context.Context, model *Model, request Context, options ...StreamOptions) *AssistantMessage
func (*Models) CompleteSimple ¶
func (m *Models) CompleteSimple(ctx context.Context, model *Model, request Context, options ...StreamOptions) *AssistantMessage
func (*Models) DeleteProvider ¶
func (*Models) FetchDeferred ¶
func (m *Models) FetchDeferred(ctx context.Context, model *Model, handle DeferredHandle, options ...DeferredFetchOptions) *AssistantMessage
func (*Models) GenerateImages ¶
func (m *Models) GenerateImages(ctx context.Context, model *ImageModel, request ImagesContext, options ...ModelsImagesOptions) AssistantImages
GenerateImages generates images through the owning provider with auth resolved like Stream. It never returns an error: unknown providers, unconfigured auth, cancellation and providers without image generation become an error or aborted AssistantImages.
func (*Models) GetAllAvailable ¶
GetAllAvailable returns models of every type whose providers have complete auth configuration. Without FilterAllModels, FilterModels applies to chat models and every other model is kept.
func (*Models) GetAllAvailableWith ¶
func (m *Models) GetAllAvailableWith(ctx context.Context, providerID string, options AuthOperationOptions) ([]AnyModel, error)
GetAllAvailableWith is Models.getAllAvailable(providerId, options).
func (*Models) GetAllModels ¶
GetAllModels reads the last-known models of every type from one provider or all providers. A provider whose listing fails contributes no models.
func (*Models) GetAuth ¶
func (m *Models) GetAuth(ctx context.Context, providerID string, overrides ...AuthResolutionOverrides) (*AuthResult, error)
func (*Models) GetAvailable ¶
func (*Models) GetAvailableOfType ¶
func (m *Models) GetAvailableOfType(ctx context.Context, modelType ModelType, providerID ...string) ([]AnyModel, error)
GetAvailableOfType returns models of one type whose providers have complete auth configuration.
func (*Models) GetAvailableOfTypeWith ¶
func (m *Models) GetAvailableOfTypeWith(ctx context.Context, modelType ModelType, providerID string, options AuthOperationOptions) ([]AnyModel, error)
GetAvailableOfTypeWith is Models.getAvailableOfType(type, providerId, options).
func (*Models) GetAvailableWith ¶
func (m *Models) GetAvailableWith(ctx context.Context, providerID string, options AuthOperationOptions) ([]*Model, error)
GetAvailableWith is Models.getAvailable(providerId, options). An empty providerID is every provider, as Pi's omitted one (GetAvailable already reads an empty id so).
func (*Models) GetModelAuth ¶
func (m *Models) GetModelAuth(ctx context.Context, anyModel AnyModel, overrides ...AuthResolutionOverrides) (*AuthResult, error)
func (*Models) GetModelOfType ¶
GetModelOfType looks up one model of the given type in the last-known lists, or returns nil.
func (*Models) GetModelsOfType ¶
GetModelsOfType reads the last-known models of one type from one provider or all providers.
func (*Models) GetProvider ¶
func (m *Models) GetProvider(id string) *ModelsProvider
func (*Models) GetProviders ¶
func (m *Models) GetProviders() []*ModelsProvider
func (*Models) Login ¶
func (m *Models) Login(ctx context.Context, providerID string, authType AuthType, interaction AuthInteraction, options ...LoginOptions) (Credential, error)
Login runs a provider-owned login flow of a provider registered with this collection and persists its returned credential.
func (*Models) LoginProvider ¶
func (m *Models) LoginProvider(ctx context.Context, provider *ModelsProvider, authType AuthType, interaction AuthInteraction, options ...LoginOptions) (Credential, error)
LoginProvider runs the provider's own login flow and persists the returned credential in this collection's credential store under the provider's ID. The provider need not be registered here, so a caller can log in a provider it composed itself.
func (*Models) LogoutWith ¶
func (m *Models) LogoutWith(ctx context.Context, providerID string, options AuthOperationOptions) error
LogoutWith is Models.logout(providerId, options).
func (*Models) Refresh ¶
func (m *Models) Refresh(ctx context.Context, options ...ModelsRefreshOptions) ModelsRefreshResult
func (*Models) SetProvider ¶
func (m *Models) SetProvider(provider *ModelsProvider)
func (*Models) Stream ¶
func (m *Models) Stream(ctx context.Context, model *Model, request Context, options ...StreamOptions) *AssistantMessageEventStream
func (*Models) StreamDeferred ¶
func (m *Models) StreamDeferred(ctx context.Context, model *Model, handle DeferredHandle, options ...DeferredFetchOptions) *AssistantMessageEventStream
func (*Models) StreamSimple ¶
func (m *Models) StreamSimple(ctx context.Context, model *Model, request Context, options ...StreamOptions) *AssistantMessageEventStream
type ModelsClassifierOptions ¶
type ModelsClassifierOptions struct {
ClassifierOptions
// TransformHeaders runs once after configured, auth, and request headers are merged.
TransformHeaders func(context.Context, ProviderHeaders) (ProviderHeaders, error)
}
ModelsClassifierOptions is ClassifierOptions plus the per-request header transform Models applies.
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, including ECMAScript trimming of the cause detail.
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 ModelsImagesOptions ¶
type ModelsImagesOptions struct {
ImagesOptions
// TransformHeaders runs once after configured, auth, and request headers are merged.
TransformHeaders func(context.Context, ProviderHeaders) (ProviderHeaders, error)
}
ModelsImagesOptions is ImagesOptions plus the per-request header transform Models applies.
type ModelsProvider ¶
type ModelsProvider struct {
ID string
Name string
BaseURL string
Headers ProviderHeaders
Auth ProviderAuth
GetModels func() ([]*Model, error)
RefreshModels func(RefreshModelsContext) error
FilterModels func([]*Model, *Credential) []*Model
// GetAllModels lists models of every type. Providers with only chat models may leave it nil.
GetAllModels func() ([]AnyModel, error)
// FilterAllModels is the credential-specific availability policy across every model type.
FilterAllModels func([]AnyModel, *Credential) []AnyModel
// GenerateImages is present when the provider supports image models.
GenerateImages func(context.Context, *ImageModel, ImagesContext, ImagesOptions) (AssistantImages, error)
// Classify is present when the provider supports classifier models.
Classify func(context.Context, *ClassifierModel, ClassifierContext, ClassifierOptions) (ClassifierResult, error)
Stream ModelsStreamFunction
StreamSimple ModelsStreamFunction
FetchDeferred func(context.Context, *Model, DeferredHandle, DeferredFetchOptions) (*AssistantMessageEventStream, error)
CancelDeferred func(context.Context, *Model, DeferredHandle, DeferredCancelOptions) error
}
ModelsProvider is the provider-owned runtime unit from models.ts; Provider remains the existing bound-backend streaming contract.
func AmazonBedrockProvider ¶
func AmazonBedrockProvider() *ModelsProvider
AmazonBedrockProvider is the built-in "amazon-bedrock" provider.
func AntLingProvider ¶
func AntLingProvider() *ModelsProvider
AntLingProvider is the built-in "ant-ling" provider.
func AnthropicProvider ¶
func AnthropicProvider() *ModelsProvider
AnthropicProvider is the built-in "anthropic" provider.
func AzureProvider ¶
func AzureProvider() *ModelsProvider
AzureProvider is the built-in "azure" provider.
func BasetenProvider ¶
func BasetenProvider() *ModelsProvider
BasetenProvider is the built-in "baseten" provider.
func BuiltinProvider ¶
func BuiltinProvider() *ModelsProvider
BuiltinProvider is the built-in "all" provider.
func BuiltinProviders ¶
func BuiltinProviders() []*ModelsProvider
BuiltinProviders returns every built-in provider, freshly constructed.
func CerebrasProvider ¶
func CerebrasProvider() *ModelsProvider
CerebrasProvider is the built-in "cerebras" provider.
func CloudflareAIGatewayProvider ¶
func CloudflareAIGatewayProvider() *ModelsProvider
CloudflareAIGatewayProvider is the built-in "cloudflare-ai-gateway" provider.
func CloudflareWorkersAIProvider ¶
func CloudflareWorkersAIProvider() *ModelsProvider
CloudflareWorkersAIProvider is the Cloudflare Workers AI provider.
func CreateProvider ¶
func CreateProvider(input CreateProviderOptions) *ModelsProvider
CreateProvider merges a dynamic overlay over its baseline and routes each request through the model's API implementation. It panics when no chat, image or classifier implementation is given.
func DeepseekProvider ¶
func DeepseekProvider() *ModelsProvider
DeepseekProvider is the built-in "deepseek" provider.
func FireworksProvider ¶
func FireworksProvider() *ModelsProvider
FireworksProvider is the built-in "fireworks" provider.
func GithubCopilotProvider ¶
func GithubCopilotProvider() *ModelsProvider
GithubCopilotProvider is the built-in "github-copilot" provider.
func GoogleProvider ¶
func GoogleProvider() *ModelsProvider
GoogleProvider is the Google provider (providers/google.ts googleProvider).
func GoogleVertexProvider ¶
func GoogleVertexProvider() *ModelsProvider
GoogleVertexProvider is the built-in "google-vertex" provider.
func GroqProvider ¶
func GroqProvider() *ModelsProvider
GroqProvider is the built-in "groq" provider.
func HuggingFaceProvider ¶
func HuggingFaceProvider() *ModelsProvider
HuggingFaceProvider is the Hugging Face provider (providers/huggingface.ts huggingfaceProvider).
func KimiCodingProvider ¶
func KimiCodingProvider() *ModelsProvider
KimiCodingProvider is the built-in "kimi-coding" provider.
func MetaProvider ¶
func MetaProvider() *ModelsProvider
MetaProvider is the built-in "meta" provider.
func MinimaxCnProvider ¶
func MinimaxCnProvider() *ModelsProvider
MinimaxCnProvider is the built-in "minimax-cn" provider.
func MinimaxProvider ¶
func MinimaxProvider() *ModelsProvider
MinimaxProvider is the built-in "minimax" provider.
func MistralProvider ¶
func MistralProvider() *ModelsProvider
MistralProvider is the built-in "mistral" provider.
func MoonshotaiCnProvider ¶
func MoonshotaiCnProvider() *ModelsProvider
MoonshotaiCnProvider is the built-in "moonshotai-cn" provider.
func MoonshotaiProvider ¶
func MoonshotaiProvider() *ModelsProvider
MoonshotaiProvider is the built-in "moonshotai" provider.
func NewRadiusProvider ¶
func NewRadiusProvider(radiusOptions ...RadiusProviderOptions) *ModelsProvider
NewRadiusProvider ports radius.ts radiusProvider(options = {}) (radius.ts:22): the Radius gateway Provider<"pi-messages"> with a persisted, dynamically refreshed catalog. options is optional, and no argument is the empty options. It serves the published static catalog for the default gateway until the account's gateway catalog is known, which then replaces it (organization owners can disable models, so the shipped baseline only covers the time before any catalog exists).
func NvidiaProvider ¶
func NvidiaProvider() *ModelsProvider
NvidiaProvider is the built-in "nvidia" provider.
func OpenAIProvider ¶
func OpenAIProvider() *ModelsProvider
OpenAIProvider is the OpenAI provider (providers/openai.ts openaiProvider).
func OpenCodeGoProvider ¶
func OpenCodeGoProvider() *ModelsProvider
OpenCodeGoProvider is the OpenCode Go provider (providers/opencode-go.ts opencodeGoProvider).
func OpenaiCodexProvider ¶
func OpenaiCodexProvider() *ModelsProvider
OpenaiCodexProvider is the built-in "openai-codex" provider.
func OpenaiProvider ¶
func OpenaiProvider() *ModelsProvider
OpenaiProvider is the built-in "openai" provider.
func OpencodeProvider ¶
func OpencodeProvider() *ModelsProvider
OpencodeProvider is the built-in "opencode" provider; its API streams add the OpenCode session header (providers/opencode.ts).
func OpenrouterProvider ¶
func OpenrouterProvider() *ModelsProvider
OpenrouterProvider is the built-in "openrouter" provider.
func QwenTokenPlanCnProvider ¶
func QwenTokenPlanCnProvider() *ModelsProvider
QwenTokenPlanCnProvider is the built-in "qwen-token-plan-cn" provider.
func QwenTokenPlanIndividualProvider ¶
func QwenTokenPlanIndividualProvider() *ModelsProvider
QwenTokenPlanIndividualProvider is the built-in "qwen-token-plan-individual" provider.
func QwenTokenPlanProvider ¶
func QwenTokenPlanProvider() *ModelsProvider
QwenTokenPlanProvider is the built-in "qwen-token-plan" provider.
func TogetherProvider ¶
func TogetherProvider() *ModelsProvider
TogetherProvider is the Together provider (providers/together.ts togetherProvider).
func TypesafeProvider ¶
func TypesafeProvider() *ModelsProvider
TypesafeProvider is the TypeSafe provider: classifier models only.
func VercelAIGatewayProvider ¶
func VercelAIGatewayProvider() *ModelsProvider
VercelAIGatewayProvider is the built-in "vercel-ai-gateway" provider.
func XiaomiProvider ¶
func XiaomiProvider() *ModelsProvider
XiaomiProvider is the Xiaomi provider (providers/xiaomi.ts xiaomiProvider).
func XiaomiTokenPlanAmsProvider ¶
func XiaomiTokenPlanAmsProvider() *ModelsProvider
XiaomiTokenPlanAmsProvider is the built-in "xiaomi-token-plan-ams" provider.
func XiaomiTokenPlanCnProvider ¶
func XiaomiTokenPlanCnProvider() *ModelsProvider
XiaomiTokenPlanCnProvider is the built-in "xiaomi-token-plan-cn" provider.
func XiaomiTokenPlanSgpProvider ¶
func XiaomiTokenPlanSgpProvider() *ModelsProvider
XiaomiTokenPlanSgpProvider is the built-in "xiaomi-token-plan-sgp" provider.
func ZaiCodingCnProvider ¶
func ZaiCodingCnProvider() *ModelsProvider
ZaiCodingCnProvider is the built-in "zai-coding-cn" provider.
type ModelsPublication ¶
type ModelsPublication struct {
Persist *ModelsStoreEntry
// PersistSet with a nil Persist is an explicit null publication, which deletes storage.
PersistSet bool
Update func()
}
type ModelsRefreshOptions ¶
type ModelsRefreshResult ¶
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 []AnyModel
// LastModified is the Unix timestamp from the remote catalog's
// Last-Modified header.
LastModified *float64
// CheckedAt is the Unix timestamp of the last completed remote check.
CheckedAt *float64
// ETag is the remote catalog's opaque validator, stored verbatim.
ETag string
// contains filtered or unexported fields
}
ModelsStoreEntry mirrors pi-ai ModelsStoreEntry (models-store.ts:3-15). Models are typed and lossless: a model decoded from a catalog keeps the fields it has no member for and re-encodes them in their original order. A record of a model type this version does not know is kept aside and written back at its position, so reading and rewriting a catalog never drops it; it is not part of Models.
func (ModelsStoreEntry) Clone ¶
func (entry ModelsStoreEntry) Clone() ModelsStoreEntry
Clone returns a deep copy, mirroring upstream's structuredClone at the store boundary.
func (ModelsStoreEntry) MarshalJSON ¶
func (entry ModelsStoreEntry) MarshalJSON() ([]byte, error)
MarshalJSON writes the entry as the persisted object: every model through its catalog record, unknown-type records at their positions.
func (*ModelsStoreEntry) UnmarshalJSON ¶
func (entry *ModelsStoreEntry) UnmarshalJSON(data []byte) error
UnmarshalJSON reads the persisted object; each model keeps its unknown fields, and records of unknown model types are set aside.
type ModelsStoreOperationOptions ¶
ModelsStoreOperationOptions is Pi's ModelsStoreOperationOptions: optional cancellation of a models-store operation, with the same meaning as AuthOperationOptions.Signal.
upstream: packages/ai/src/models-store.ts:ModelsStoreOperationOptions
type ModelsStreamFunction ¶
type ModelsStreamFunction func(context.Context, *Model, TranscriptContext, StreamOptions) (*AssistantMessageEventStream, error)
type MutableModels ¶
type MutableModels = Models
type NestedToolCallRecord ¶
type NestedToolCallRecord struct {
ID string `json:"id"`
Name string `json:"name"`
Status NestedToolCallStatus `json:"status"`
// Arguments is omitted when over the size limits.
Arguments JsonObject `json:"arguments,omitempty"`
// ArgumentsBytes is the UTF-8 size of the arguments as JSON, set when Arguments is omitted.
ArgumentsBytes *int `json:"argumentsBytes,omitempty"`
DurationMs *int64 `json:"durationMs,omitempty"`
// Error is the error text, truncated.
Error string `json:"error,omitempty"`
// contains filtered or unexported fields
}
NestedToolCallRecord is a tool call that another tool made while it ran, for example from a codemode script. Arguments is nil when it was over the size limits; ArgumentsBytes then gives their size.
upstream: .upstream/v0.99.1/packages/ai/src/types.ts:573-586 (NestedToolCallRecord)
func (NestedToolCallRecord) MarshalJSON ¶
func (record NestedToolCallRecord) MarshalJSON() ([]byte, error)
MarshalJSON keeps an empty `arguments` object, which differs from omitted arguments (over the size limits): only a nil Arguments is left out.
func (*NestedToolCallRecord) SetArgumentsJSON ¶
func (record *NestedToolCallRecord) SetArgumentsJSON(raw []byte) error
SetArgumentsJSON decodes a complete JSON object into Arguments and keeps its member order.
func (*NestedToolCallRecord) UnmarshalJSON ¶
func (record *NestedToolCallRecord) UnmarshalJSON(data []byte) error
UnmarshalJSON decodes the record and keeps the member order of its arguments.
type NestedToolCallStatus ¶
type NestedToolCallStatus string
NestedToolCallStatus is the state of a NestedToolCallRecord. `unfinished` means the call was still running when the calling tool finished.
upstream: .upstream/v0.99.1/packages/ai/src/types.ts:573-586 (NestedToolCallRecord.status)
const ( NestedToolCallOK NestedToolCallStatus = "ok" NestedToolCallError NestedToolCallStatus = "error" NestedToolCallUnfinished NestedToolCallStatus = "unfinished" )
The statuses of upstream's NestedToolCallRecord.status union.
type NestedToolCalls ¶
type NestedToolCalls struct {
Calls []NestedToolCallRecord `json:"calls"`
Complete bool `json:"complete"`
}
NestedToolCalls is the bounded record of the nested calls a tool made. Results are not recorded. Complete is false when calls were dropped, arguments omitted, or calls had not finished.
upstream: .upstream/v0.99.1/packages/ai/src/types.ts:588-592 (NestedToolCalls)
type NodeFetch ¶
type NodeFetch struct{}
NodeFetch is Node's global fetch under the configured dispatcher, for code that calls fetch directly (the MCP transports and OAuth requests): a failure before the response headers rejects with TypeError("fetch failed"), an aborted request with "This operation was aborted", a body that drops with "terminated", and the idle timeouts of ConfigureHTTPDispatcher apply. It follows the environment proxy rules of the provider clients.
func NewNodeFetch ¶
func NewNodeFetch() *NodeFetch
NewNodeFetch returns a fetch that sends each request through the dispatcher configured at that time, sharing its connection pool with the provider clients.
func (*NodeFetch) Do ¶
Do sends the request. A rejection is the fetch error itself: http.Client's "Post <url>:" decoration around it is not part of what fetch rejects with. The client is resolved per request because fetch uses the global dispatcher current at the call: ConfigureHTTPDispatcher after NewNodeFetch applies, as Pi's configureHttpDispatcher reinstalling the dispatcher (interactive-mode.ts applyRuntimeSettings) does.
type NormalizedProviderError ¶
type NormalizedProviderError struct {
Status *int `json:"status,omitempty"`
Body *string `json:"body,omitempty"`
Message string `json:"message"`
MessageCarriesBody bool `json:"messageCarriesBody"`
}
NormalizedProviderError separates a provider's HTTP status and body from its error message.
func NormalizeProviderError ¶
func NormalizeProviderError(value any) NormalizedProviderError
NormalizeProviderError extracts supported error metadata without serializing unread response streams or SDK wrapper objects.
type OAuthAuth ¶
type OAuthAuth struct {
Name string
IsSubscription bool
LoginLabel string
Login func(context.Context, AuthInteraction, LoginOptions) (Credential, error)
Refresh func(ctx context.Context, credential Credential) (Credential, error)
ToAuth func(credential Credential) (ModelAuth, error)
// contains filtered or unexported fields
}
OAuthAuth refreshes stored OAuth credentials and derives request auth from them.
func LazyOAuth ¶
func LazyOAuth(input LazyOAuthInput) *OAuthAuth
LazyOAuth wraps an OAuth flow so a provider definition can advertise OAuth without loading the implementation.
upstream: packages/ai/src/auth/helpers.ts:40 (lazyOAuth)
func OAuthProviderAuth ¶
OAuthProviderAuth returns the OAuth auth method for a provider registered in the OAuth provider registry.
func (*OAuthAuth) AuthMethodName ¶
AuthMethodName is the method's display name, which the provider selector searches (oauth-selector.ts:136 `provider.method?.name`).
type OAuthAuthInfo ¶
OAuthAuthInfo is the URL + instructions presented to the user.
type OAuthCallbackOrManualInput ¶
type OAuthCallbackOrManualInput[T any] struct { // Callback is true when the browser callback completed the sign-in. Callback bool Value T Input string }
OAuthCallbackOrManualInput is the outcome of WaitForCallbackOrManualInput: the callback result or the pasted input.
func WaitForCallbackOrManualInput ¶
func WaitForCallbackOrManualInput[T any](ctx context.Context, interaction AuthInteraction, callback *OAuthCallbackServer[T], prompt AuthManualCodePrompt) (OAuthCallbackOrManualInput[T], error)
WaitForCallbackOrManualInput waits for the browser callback, or for the user to paste the code or redirect URL when the browser cannot reach the loopback server (for example over SSH). Without a callback server only the manual prompt is used. The manual prompt's context ends, and the prompt is joined, before it returns.
type OAuthCallbackServer ¶
type OAuthCallbackServer[T any] struct { // RedirectURI is the URI the provider redirects the browser to. RedirectURI string // contains filtered or unexported fields }
OAuthCallbackServer waits for one browser redirect.
func StartOAuthCallbackServer ¶
func StartOAuthCallbackServer[T any](ctx context.Context, options OAuthCallbackServerOptions[T]) (*OAuthCallbackServer[T], error)
StartOAuthCallbackServer listens for the provider's redirect. Cancelling ctx ends the wait with "Login cancelled".
func (*OAuthCallbackServer[T]) Cancel ¶
func (s *OAuthCallbackServer[T]) Cancel()
Cancel stops waiting for the browser unless a callback is already being completed.
func (*OAuthCallbackServer[T]) Close ¶
func (s *OAuthCallbackServer[T]) Close()
Close fails a pending wait, stops the listener and drops every connection (callback-server.ts:145-148). Node's server.close() also closes idle connections, so a browser's spare connection cannot keep the server alive past its login; http.Server.Close additionally ends a connection whose Complete is still running.
func (*OAuthCallbackServer[T]) Wait ¶
func (s *OAuthCallbackServer[T]) Wait() (value T, ok bool, err error)
Wait returns the result of Complete, or ok=false after Cancel. It fails when the provider redirects with an error, Complete fails, the context ends or the timeout elapses.
type OAuthCallbackServerOptions ¶
type OAuthCallbackServerOptions[T any] struct { // ProviderName is used on the browser page, for example "OpenAI". ProviderName string // Host is the address to listen on. Host string // Port is the port to listen on; 0 picks a free port. Port int Path string // RedirectHost is the host in the redirect URI when it differs from Host, for example "localhost". RedirectHost string // State is the expected state parameter. Nil skips the check for providers that send none. State *string // Complete finishes the sign-in with the received code before the browser page is sent, so the page can show // exchange failures. Its context is the one passed to StartOAuthCallbackServer. Complete func(ctx context.Context, code string) (T, error) // Timeout ends the wait with an error. Zero means no timeout. Timeout time.Duration }
OAuthCallbackServerOptions configures the loopback redirect handler shared by the browser sign-in flows.
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 {
Extra map[string]json.RawMessage `json:"-"`
Refresh string `json:"refresh"`
Access string `json:"access"`
// Expires is the truncated integer projection of expires in Unix milliseconds. ExpiresMillis returns Pi's exact JavaScript number, including a fraction or an absent property.
// Expiry decisions must use ExpiresMillis. SetExpiresMillis stores a fraction; assigning Expires replaces any retained exact value.
Expires int64 `json:"expires"`
// ProjectID is used by Google Cloud Code Assist / Antigravity OAuth.
// Other provider-owned fields are retained in Extra.
ProjectID string `json:"projectId,omitempty"`
// AccountID is the provider account associated with the access token.
AccountID string `json:"accountId,omitempty"`
// Scope is the granted scope returned by flows that report one (Radius).
Scope string `json:"scope,omitempty"`
// contains filtered or unexported fields
}
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. The browser callback and the manual prompt race; the callback server closes, and the manual prompt is joined, before the token exchange result returns. Ports loginAnthropic (.upstream/v1.0.0/packages/ai/src/auth/oauth/anthropic.ts:138).
func LoginAnthropicCopyCode ¶
func LoginAnthropicCopyCode(ctx context.Context, callbacks OAuthLoginCallbacks) (OAuthCredentials, error)
LoginAnthropicCopyCode runs the Anthropic authorization code + PKCE flow without a callback server: Anthropic's page shows the code, which the user pastes. It works when the browser runs on another machine. Ports loginAnthropicCopyCode (.upstream/v1.0.0/packages/ai/src/auth/oauth/anthropic.ts:191).
func LoginOpenAIChatGPT ¶
func LoginOpenAIChatGPT(ctx context.Context, callbacks OAuthLoginCallbacks) (OAuthCredentials, error)
LoginOpenAIChatGPT runs the Sign in with ChatGPT flow: the browser callback and the pasted redirect URL race, then the authorization code is exchanged for tokens. callbacks.GetDeviceID supplies the installation's device ID.
func LoginOpenAICodex ¶
func LoginOpenAICodex(ctx context.Context, callbacks OAuthLoginCallbacks) (OAuthCredentials, error)
LoginOpenAICodex runs the OpenAI Codex (ChatGPT) OAuth flow. Port 1455 is shared with the Codex CLI; when it is taken, the pasted redirect URL completes the login. Ports loginOpenAICodex (.upstream/v0.99.1/packages/ai/src/auth/oauth/openai-codex.ts:359).
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. OpenRouter sends no state; the random path keeps stray requests from completing the sign-in. A claimed browser callback always wins over a racing paste. Ports loginOpenRouter (.upstream/v0.99.1/packages/ai/src/auth/oauth/openrouter.ts:113).
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.
func RefreshOpenAIChatGPTToken ¶
func RefreshOpenAIChatGPTToken(ctx context.Context, credentials OAuthCredentials) (OAuthCredentials, error)
RefreshOpenAIChatGPTToken refreshes a Sign in with ChatGPT credential with the client ID OpenAI issued at login.
func (*OAuthCredentials) ClearExpires ¶
func (c *OAuthCredentials) ClearExpires()
ClearExpires removes the expires property, as a provider result without one does in Pi.
func (OAuthCredentials) ExpiresMillis ¶
func (c OAuthCredentials) ExpiresMillis() float64
ExpiresMillis returns ToNumber of the credential's expires value, the operand Pi compares with Date.now(). An absent value is NaN, so both orderings compare false.
func (OAuthCredentials) HasExpires ¶
func (c OAuthCredentials) HasExpires() bool
HasExpires reports whether the credential carries an expires property.
func (OAuthCredentials) MarshalJSON ¶
func (c OAuthCredentials) MarshalJSON() ([]byte, error)
func (*OAuthCredentials) SetExpiresMillis ¶
func (c *OAuthCredentials) SetExpiresMillis(value float64)
SetExpiresMillis stores a JavaScript number, including a fraction. Expires receives its truncated projection.
func (*OAuthCredentials) UnmarshalJSON ¶
func (c *OAuthCredentials) UnmarshalJSON(data []byte) error
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)
// OnManualCodePromptContext asks for a pasted code with the flow's own manual_code message and placeholder. Nil falls back to OnManualCodeInputContext, then OnManualCodeInput.
OnManualCodePromptContext func(context.Context, AuthManualCodePrompt) (string, error)
OnSelect func(prompt OAuthSelectPrompt) (string, error)
OnSelectContext func(context.Context, OAuthSelectPrompt) (string, error)
// GetDeviceID returns the stable ID of this app installation. It comes from LoginOptions.GetDeviceID; nil means the
// app supplies none.
GetDeviceID func() string
// AgentName comes from LoginOptions.AgentName; nil means the flow's own default name.
AgentName *string
}
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 OpenAIChatGPTOAuthProvider ¶
type OpenAIChatGPTOAuthProvider struct{}
OpenAIChatGPTOAuthProvider implements OAuthProviderInterface for Sign in with ChatGPT on the openai provider.
func (OpenAIChatGPTOAuthProvider) GetAPIKey ¶
func (OpenAIChatGPTOAuthProvider) GetAPIKey(c OAuthCredentials) string
func (OpenAIChatGPTOAuthProvider) ID ¶
func (OpenAIChatGPTOAuthProvider) ID() string
func (OpenAIChatGPTOAuthProvider) IsSubscription ¶
func (OpenAIChatGPTOAuthProvider) IsSubscription() bool
func (OpenAIChatGPTOAuthProvider) Login ¶
func (p OpenAIChatGPTOAuthProvider) Login(callbacks OAuthLoginCallbacks) (OAuthCredentials, error)
func (OpenAIChatGPTOAuthProvider) LoginContext ¶
func (OpenAIChatGPTOAuthProvider) LoginContext(ctx context.Context, callbacks OAuthLoginCallbacks) (OAuthCredentials, error)
func (OpenAIChatGPTOAuthProvider) Name ¶
func (OpenAIChatGPTOAuthProvider) Name() string
func (OpenAIChatGPTOAuthProvider) RefreshToken ¶
func (p OpenAIChatGPTOAuthProvider) RefreshToken(creds OAuthCredentials) (OAuthCredentials, error)
func (OpenAIChatGPTOAuthProvider) RefreshTokenContext ¶
func (OpenAIChatGPTOAuthProvider) RefreshTokenContext(ctx context.Context, creds OAuthCredentials) (OAuthCredentials, error)
func (OpenAIChatGPTOAuthProvider) UsesCallbackServer ¶
func (OpenAIChatGPTOAuthProvider) UsesCallbackServer() bool
type OpenAIChatMessage ¶
type OpenAIChatMessage = oaiMessage
OpenAIChatMessage is one message of a chat-completions request.
func ConvertCompletionsMessages ¶
func ConvertCompletionsMessages(model *Model, transcript TranscriptContext, compat *OpenAICompat, options ConvertCompletionsMessagesOptions) ([]OpenAIChatMessage, error)
ConvertCompletionsMessages converts a transcript to the messages of an openai-completions request for model and compat: the transcript is resolved and transformed for the model, and the instruction message leads. A nil compat resolves every flag to its default.
Ports packages/ai/src/api/openai-completions.ts (convertMessages).
type OpenAICodexResponsesConfig ¶
type OpenAICodexResponsesConfig struct {
APIKey string
Model string
ModelMetadata *Model
// ThinkingLevelMap supplies an explicit map when selected ModelMetadata is absent.
ThinkingLevelMap ThinkingLevelMap
ProviderID string
BaseURL string
Compat *OpenAIResponsesCompat
// ExtraHeaders are the model's headers (models.json). They override the default originator and User-Agent; Authorization,
// chatgpt-account-id and the transport headers stay the provider's.
ExtraHeaders map[string]string
}
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 OpenRouterRouting `json:"openRouterRouting,omitempty"`
ChatTemplateKwargs map[string]ChatTemplateKwargValue `json:"chatTemplateKwargs,omitempty"`
VLLMPriority *float64 `json:"vllmPriority,omitempty"`
// VercelGatewayRouting contains Vercel AI Gateway routing preferences.
VercelGatewayRouting *VercelGatewayRouting `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"`
// ThinkingTokenBudgetField selects the budget wire field and takes precedence over SupportsThinkingTokenBudget.
ThinkingTokenBudgetField ThinkingTokenBudgetField `json:"thinkingTokenBudgetField,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"`
// Extra holds the members PiG does not model, as written. Pi's compat schemas allow additional properties and a compat object keeps
// them (model-config.ts getProvider, provider-composer.ts mergeCompat), so a custom API can read its own compat settings.
Extra map[string]json.RawMessage `json:"-"`
}
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 the compat flags a provider name and base URL imply (openai-completions.ts detectCompat for a model without an id).
func (OpenAICompat) MarshalJSON ¶
func (compat OpenAICompat) MarshalJSON() ([]byte, error)
MarshalJSON preserves an explicit empty fallback list, which disables server-side fallback rather than inheriting catalog defaults, and writes the unmodeled members (Extra) after the modeled ones.
func (*OpenAICompat) UnmarshalJSON ¶
func (compat *OpenAICompat) UnmarshalJSON(data []byte) error
UnmarshalJSON decodes the modeled members and keeps every other member of the object in Extra, as Pi's compat object keeps an additional property.
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
// ModelMetadata supplies the selected model's capabilities and thinking map without falling back to a same-named catalog entry.
ModelMetadata *Model
// ThinkingLevelMap supplies an explicit map when selected ModelMetadata is absent.
ThinkingLevelMap ThinkingLevelMap
// 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
// SamplingParamsByThinkingLevel overrides SamplingParams for the effective thinking level.
SamplingParamsByThinkingLevel SamplingParamsByThinkingLevel
// 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
// contains filtered or unexported fields
}
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 logical model identity used for response metadata and replay capabilities.
Model string
// ModelMetadata supplies the selected model's thinking map and input capabilities.
ModelMetadata *Model
// 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
// SamplingParamsByThinkingLevel overrides SamplingParams for the effective thinking level.
SamplingParamsByThinkingLevel SamplingParamsByThinkingLevel
// ThinkingLevelMap supplies an explicit map when selected ModelMetadata is absent.
ThinkingLevelMap ThinkingLevelMap
// 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 OpenAIResponsesStreamOptions ¶
type OpenAIResponsesStreamOptions struct {
// OnProviderStreamEvent observes each wire event before it is mapped, with the model processResponsesStream was given; its error ends
// the stream. Nil observes nothing. It is StreamOptions.OnProviderStreamEvent (openai-responses-shared.ts:111).
OnProviderStreamEvent func(ctx context.Context, data any, model *Model) error
// ServiceTier is the request's service tier, which prices a response that reports none.
ServiceTier string
// GrammarToolInputProperties names the input property of each grammar tool by tool name.
GrammarToolInputProperties map[string]string
// ResolveServiceTier picks the tier that prices a response from the response's tier and the request's; nil picks the response's
// tier, then the request's.
ResolveServiceTier func(responseServiceTier, requestServiceTier string) string
// ApplyServiceTierPricing scales the response's priced usage by its tier; nil leaves the usage at the default rate.
ApplyServiceTierPricing func(usage *Usage, serviceTier string)
// contains filtered or unexported fields
}
OpenAIResponsesStreamOptions is openai-responses-shared.ts OpenAIResponsesStreamOptions: what a Responses adapter injects into processResponsesStream.
type OpenRouterModel ¶
type OpenRouterModel struct {
ID string `json:"id"`
ContextLength *float64 `json:"context_length"`
TopProvider *OpenRouterTopProvider `json:"top_provider"`
Pricing *OpenRouterPricing `json:"pricing"`
}
OpenRouterModel is the fields pi reads from a model in OpenRouter's `GET /models` and `GET /models/user`.
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 OpenRouterPricing ¶
type OpenRouterPricing struct {
Prompt OpenRouterRate `json:"prompt"`
Completion OpenRouterRate `json:"completion"`
InputCacheRead OpenRouterRate `json:"input_cache_read"`
InputCacheWrite OpenRouterRate `json:"input_cache_write"`
Overrides []OpenRouterPricingOverride `json:"overrides"`
}
OpenRouterPricing is OpenRouter's per-token prices.
type OpenRouterPricingOverride ¶
type OpenRouterPricingOverride struct {
MinPromptTokens *float64 `json:"min_prompt_tokens"`
UTCStart json.RawMessage `json:"utc_start"`
UTCEnd json.RawMessage `json:"utc_end"`
UTCDays json.RawMessage `json:"utc_days"`
Prompt OpenRouterRate `json:"prompt"`
Completion OpenRouterRate `json:"completion"`
InputCacheRead OpenRouterRate `json:"input_cache_read"`
InputCacheWrite OpenRouterRate `json:"input_cache_write"`
}
OpenRouterPricingOverride is a conditional price. MinPromptTokens selects prompt-length pricing; the utc_* members select time-of-day or weekday pricing and keep their raw JSON because only their presence matters. Missing rates keep the base price.
type OpenRouterRate ¶
type OpenRouterRate string
OpenRouterRate is one of OpenRouter's per-token prices, a decimal string. A JSON number reads as its text, as String(value) does for Number.parseFloat; any other JSON value reads as the empty string, which parseFloat turns into NaN.
func (*OpenRouterRate) UnmarshalJSON ¶
func (r *OpenRouterRate) UnmarshalJSON(data []byte) error
type OpenRouterRouting ¶
OpenRouterRouting is OpenRouter's provider-routing preferences, sent verbatim as the request's `provider` field (types.ts:977).
type OpenRouterTopProvider ¶
type OpenRouterTopProvider struct {
ContextLength *float64 `json:"context_length"`
MaxCompletionTokens *float64 `json:"max_completion_tokens"`
}
OpenRouterTopProvider is the limits OpenRouter reports for the provider that serves a model. A limit that is absent, null or 0 is not reported.
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
// ModelMetadata is the selected model, which an OnProviderStreamEvent observer receives. Nil hands the observer the configured identity only.
ModelMetadata *Model
}
PiMessagesConfig configures a pi-messages provider. The per-request options (debug, toolChoice, onResponse) are StreamOptions fields.
type PiMessagesEvent ¶
type PiMessagesEvent struct {
Type PiMessagesEventType `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"`
// contains filtered or unexported fields
}
PiMessagesEvent is one serialized assistant-message event sent by a pi-messages backend. Type selects which fields apply.
type PiMessagesEventType ¶
type PiMessagesEventType string
PiMessagesEventType is the discriminator of the PiMessagesEvent union.
const ( PiMessagesEventStart PiMessagesEventType = "start" PiMessagesEventTextStart PiMessagesEventType = "text_start" PiMessagesEventTextDelta PiMessagesEventType = "text_delta" PiMessagesEventTextEnd PiMessagesEventType = "text_end" PiMessagesEventThinkingStart PiMessagesEventType = "thinking_start" PiMessagesEventThinkingDelta PiMessagesEventType = "thinking_delta" PiMessagesEventThinkingEnd PiMessagesEventType = "thinking_end" PiMessagesEventToolcallStart PiMessagesEventType = "toolcall_start" PiMessagesEventToolcallDelta PiMessagesEventType = "toolcall_delta" PiMessagesEventToolcallEnd PiMessagesEventType = "toolcall_end" PiMessagesEventDone PiMessagesEventType = "done" PiMessagesEventError PiMessagesEventType = "error" )
The event types a pi-messages backend sends (pi-messages.ts PiMessagesEvent).
type PiMessagesResponseError ¶
type PiMessagesResponseError struct {
Message string
Code string
DiagnosticDetails map[string]any
// contains filtered or unexported fields
}
PiMessagesResponseError is a non-2xx backend response with diagnostic details.
func NewPiMessagesResponseError ¶
func NewPiMessagesResponseError(message, code string, diagnosticDetails map[string]any) *PiMessagesResponseError
NewPiMessagesResponseError ports pi-messages.ts PiMessagesResponseError constructor(message, code, diagnosticDetails); an empty code is upstream's undefined.
func (*PiMessagesResponseError) DiagnosticCode ¶
func (e *PiMessagesResponseError) DiagnosticCode() any
DiagnosticCode is the upstream `code` property; it is absent when the backend sent none.
func (*PiMessagesResponseError) Error ¶
func (e *PiMessagesResponseError) Error() string
func (*PiMessagesResponseError) Name ¶
func (*PiMessagesResponseError) Name() string
Name is the upstream `name` property.
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 NewBedrockAPIProvider ¶
NewBedrockAPIProvider builds the bedrock-converse-stream provider for model, the provider every model-to-provider factory uses.
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 NewGoogleVertexAPIProvider ¶
func NewGoogleVertexAPIProvider(cfg GoogleVertexConfig) (Provider, error)
NewGoogleVertexAPIProvider builds the google-vertex provider for cfg, the provider every model-to-provider factory uses.
func NewGoogleVertexProvider ¶
func NewGoogleVertexProvider(cfg GoogleVertexConfig) Provider
NewGoogleVertexProvider creates a Vertex provider. Placeholder keys select ADC; real keys select Vertex express mode without project or location.
func NewMistralAPIProvider ¶
func NewMistralAPIProvider(cfg MistralConfig) (Provider, error)
NewMistralAPIProvider builds the mistral-conversations provider for cfg, the provider every model-to-provider factory uses.
func NewMistralProvider ¶
func NewMistralProvider(cfg MistralConfig) Provider
NewMistralProvider creates a Provider backed by the Mistral API. BaseURL defaults to https://api.mistral.ai; requests resolve v1/chat/completions beneath its normalized base pathname, preserving any existing v1 segment.
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.
func WrapBuiltinProvider ¶
WrapBuiltinProvider applies to a per-model provider the wrapper that the built-in provider's upstream constructor puts on its API streams (providers/cloudflare-workers-ai.ts:20, providers/cloudflare-ai-gateway.ts:22-24: cloudflareStreams), the same table that registers the built-in providers uses. A provider without a wrapper, or whose API is not one of the HTTP providers that carry an endpoint, is returned as it is.
type ProviderAPIMap ¶
type ProviderAPIMap map[API]*ProviderStreams
type ProviderAPIs ¶
type ProviderAPIs interface {
// contains filtered or unexported methods
}
ProviderAPIs is the closed single-module or API-keyed implementation union.
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.
type ProviderClassifier ¶
type ProviderClassifier struct {
Classify func(context.Context, *ClassifierModel, ClassifierContext, ClassifierOptions) (ClassifierResult, error)
}
ProviderClassifier is a classifier API module.
func CloudflareClassifier ¶
func CloudflareClassifier(classifier *ProviderClassifier) *ProviderClassifier
CloudflareClassifier wraps a classifier module so Cloudflare account and gateway endpoint placeholders materialize from the resolved provider env before dispatch (cloudflare-stream.ts:31-36). The classifier receives model itself when nothing changes.
func CloudflareWorkersAISystemOneAPI ¶
func CloudflareWorkersAISystemOneAPI() *ProviderClassifier
CloudflareWorkersAISystemOneAPI is the cloudflare-workers-ai-system-one classifier module.
func LlamaCppClassifyAPI ¶
func LlamaCppClassifyAPI() *ProviderClassifier
LlamaCppClassifyAPI is the llama-cpp-classify classifier module.
func OpenAIDecisionsAPI ¶
func OpenAIDecisionsAPI() *ProviderClassifier
OpenAIDecisionsAPI is the openai-decisions classifier module.
func TypesafeSystemOneAPI ¶
func TypesafeSystemOneAPI() *ProviderClassifier
TypesafeSystemOneAPI is the typesafe-system-one classifier module.
type ProviderClassifierMap ¶
type ProviderClassifierMap map[ClassifierAPI]*ProviderClassifier
ProviderClassifierMap keys classifier implementations by ClassifierModel.API.
func BuiltinClassifiers ¶
func BuiltinClassifiers(provider string) ProviderClassifierMap
BuiltinClassifiers returns the classifier implementations of one built-in provider by classifier API (all.ts provider assembly).
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>).
func AnthropicFederationEnv ¶
func AnthropicFederationEnv(env ProviderEnv) ProviderEnv
AnthropicFederationEnv returns the workload identity federation variables set in env or the process env, or nil unless the rule, organization and identity token file are all set. The service account and workspace travel when set. The anthropic auth resolver, the federation client and the coding registry's availability checks share it, so they agree on when federation is configured. upstream: packages/ai/src/providers/anthropic.ts:47-69, packages/ai/src/api/anthropic-messages.ts:343-372
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 ProviderID ¶
type ProviderID = string
ProviderID is a provider id: a KnownProvider or any other string (types.ts ProviderId = KnownProvider | string).
type ProviderImageAPIMap ¶
type ProviderImageAPIMap map[ImageAPI]*ProviderImages
ProviderImageAPIMap keys image implementations by ImageModel.API.
type ProviderImages ¶
type ProviderImages struct {
GenerateImages func(context.Context, *ImageModel, ImagesContext, ImagesOptions) (AssistantImages, error)
}
ProviderImages is an image API module. Rejections are returned as errors.
func OpenRouterImagesAPI ¶
func OpenRouterImagesAPI() *ProviderImages
OpenRouterImagesAPI is the OpenRouter image implementation a provider lists under APIImagesOpenRouter (api/openrouter-images.lazy.ts openrouterImagesApi).
type ProviderImagesOptions ¶
type ProviderImagesOptions = ImagesOptions
ProviderImagesOptions is the image API options shape.
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 ProviderRequestError ¶
ProviderRequestError is the failure shape retryProviderRequest classifies (provider-retry.ts ProviderError): an optional HTTP status and the response headers. A nil status is a failure with no response, which is retried.
type ProviderResponse ¶
type ProviderResponse struct {
Status int `json:"status"`
Headers map[string]string `json:"headers"`
}
ProviderResponse is the status and headers observed before consuming a provider response.
type ProviderRetryOptions ¶
type ProviderRetryOptions struct {
// MaxRetries is the retry budget after a retryable failure. Nil means 0.
MaxRetries *int
// MaxRetryDelayMs caps a server-requested retry delay. Nil means 60000; 0 disables the cap.
MaxRetryDelayMs *int
// NoRetryStatuses are HTTP statuses that fail at once although the default policy would retry them.
NoRetryStatuses []int
}
ProviderRetryOptions is provider-retry.ts ProviderRetryOptions; the signal is RetryProviderRequest's context.
type ProviderStreams ¶
type ProviderStreams struct {
Stream ModelsStreamFunction
StreamSimple ModelsStreamFunction
FetchDeferred func(context.Context, *Model, DeferredHandle, DeferredFetchOptions) (*AssistantMessageEventStream, error)
CancelDeferred func(context.Context, *Model, DeferredHandle, DeferredCancelOptions) error
}
func AnthropicMessagesAPI ¶
func AnthropicMessagesAPI() *ProviderStreams
AnthropicMessagesAPI is the anthropic-messages API (api/anthropic-messages.lazy.ts anthropicMessagesApi).
func AzureOpenAIResponsesAPI ¶
func AzureOpenAIResponsesAPI() *ProviderStreams
AzureOpenAIResponsesAPI is the azure-openai-responses API (azureOpenAIResponsesApi).
func BedrockConverseStreamAPI ¶
func BedrockConverseStreamAPI() *ProviderStreams
BedrockConverseStreamAPI is the bedrock-converse-stream API (bedrockConverseStreamApi).
func CloudflareStreams ¶
func CloudflareStreams(streams *ProviderStreams) *ProviderStreams
CloudflareStreams wraps an API implementation so Cloudflare account and gateway endpoint placeholders materialize from the resolved provider env before dispatch (cloudflare-stream.ts:19-29). As Pi's wrapper returns an object with only stream and streamSimple, the result has no deferred operations, so a Cloudflare-wrapped API does not support deferred responses (models.ts:925-927).
func GoogleGenerativeAIAPI ¶
func GoogleGenerativeAIAPI() *ProviderStreams
GoogleGenerativeAIAPI is the google-generative-ai API (googleGenerativeAIApi).
func GoogleVertexAPI ¶
func GoogleVertexAPI() *ProviderStreams
GoogleVertexAPI is the google-vertex API (googleVertexApi).
func LazyAPI ¶
func LazyAPI(load func(context.Context) (*ProviderStreams, error), capabilities LazyAPICapabilities) *ProviderStreams
LazyAPI invokes the loader per operation, as Pi does. Module caching belongs to the loader; unsupported deferred callbacks stay nil.
func MistralConversationsAPI ¶
func MistralConversationsAPI() *ProviderStreams
MistralConversationsAPI is the mistral-conversations API (mistralConversationsApi).
func OpenAICodexResponsesAPI ¶
func OpenAICodexResponsesAPI() *ProviderStreams
OpenAICodexResponsesAPI is the openai-codex-responses API (openAICodexResponsesApi).
func OpenAICompletionsAPI ¶
func OpenAICompletionsAPI() *ProviderStreams
OpenAICompletionsAPI is the openai-completions API (openAICompletionsApi).
func OpenAIResponsesAPI ¶
func OpenAIResponsesAPI() *ProviderStreams
OpenAIResponsesAPI is the openai-responses API (openAIResponsesApi).
func PiMessagesAPI ¶
func PiMessagesAPI() *ProviderStreams
PiMessagesAPI is the pi-messages API (piMessagesApi).
func WithOpenCodeSessionHeader ¶
func WithOpenCodeSessionHeader(streams *ProviderStreams) *ProviderStreams
WithOpenCodeSessionHeader adds OpenCode's required per-conversation routing header before API dispatch.
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 {
// Type is Model.type, the optional "chat" a gateway may advertise (types.ts:1119); it travels through the spread of getRadiusModelsFromConfig.
Type ModelType `json:"type,omitempty"`
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 ModelCost `json:"cost"`
PromptCache ModelPromptCache `json:"promptCache,omitempty"`
ContextWindow int `json:"contextWindow"`
MaxTokens int `json:"maxTokens"`
SamplingParams map[string]any `json:"samplingParams,omitempty"`
// SamplingParamsByThinkingLevel is Model.samplingParamsByThinkingLevel: radius-config.ts sanitizeRadiusGatewayConfig and
// getRadiusModelsFromConfig spread each gateway model, so the field a gateway advertises reaches the Model<"pi-messages">.
//portlint:allow emptydrop a level missing from the map selects no sampling params, so an explicit empty map and an absent one resolve alike
SamplingParamsByThinkingLevel SamplingParamsByThinkingLevel `json:"samplingParamsByThinkingLevel,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 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 Go handle of a Radius provider: the Pi provider object radiusProvider returns, with the gateway and the OAuth flow the object's auth was built from.
func NewRadiusGatewayProvider ¶
func NewRadiusGatewayProvider(options RadiusProviderOptions) *RadiusProvider
NewRadiusGatewayProvider is NewRadiusProvider with the gateway and OAuth flow its auth was built from, for callers that configure Radius gateways from models.json.
func (*RadiusProvider) Auth ¶
func (p *RadiusProvider) Auth() ProviderAuth
Auth is the provider's `auth` property (radius.ts:33-40, models.ts Provider.auth): 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.
func (*RadiusProvider) FindModel ¶
func (p *RadiusProvider) FindModel(id string) (*Model, bool)
FindModel returns the effective model with id.
func (*RadiusProvider) Gateway ¶
func (p *RadiusProvider) Gateway() string
func (*RadiusProvider) GetModels ¶
func (p *RadiusProvider) GetModels() []*Model
GetModels returns the account's catalog once it is known and the static baseline before (radius.ts getModels: dynamicModels ?? baselineModels). Each call returns new copies that the caller owns.
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. ctx is the refresh's abort signal.
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) Delete ¶
func (s *ReadOnlyAuthStorage) Delete(context.Context, string) error
Delete always fails: the store is read-only.
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
Publish func(ModelsPublication) (bool, error)
AllowNetwork bool
Force *bool
Signal context.Context
// BaseURL is the base URL of the registered provider, including configuration overrides that wrappers apply outside the provider receiving this context (models.ts RefreshModelsContext.baseUrl).
BaseURL string
}
type RegisterFauxProviderOptions ¶
type RegisterFauxProviderOptions = FauxConfig
RegisterFauxProviderOptions is faux.ts RegisterFauxProviderOptions: the options NewFauxProvider takes.
type ResolvedGoogleThinkingLevel ¶
type ResolvedGoogleThinkingLevel string
ResolvedGoogleThinkingLevel is a ThinkingLevel without "xhigh" and "max" (google-shared.ts ResolvedGoogleThinkingLevel).
const ( ResolvedGoogleThinkingLevelMinimal ResolvedGoogleThinkingLevel = "minimal" ResolvedGoogleThinkingLevelLow ResolvedGoogleThinkingLevel = "low" ResolvedGoogleThinkingLevelMedium ResolvedGoogleThinkingLevel = "medium" ResolvedGoogleThinkingLevelHigh ResolvedGoogleThinkingLevel = "high" )
type ResponsesInputItem ¶
type ResponsesInputItem struct {
// Common
Type string `json:"type,omitempty"`
Role string `json:"role,omitempty"`
// For type=message (user/assistant/system/developer)
Content json.RawMessage `json:"content,omitempty"`
Status string `json:"status,omitempty"`
ID string `json:"id,omitempty"`
Phase string `json:"phase,omitempty"`
// For type=function_call (a JSON string) and type=tool_search_call (an object)
CallID string `json:"call_id,omitempty"`
Namespace string `json:"namespace,omitempty"`
Name string `json:"name,omitempty"`
Arguments json.RawMessage `json:"arguments,omitempty"`
// For type=tool_search_call / tool_search_output: "client"
Execution string `json:"execution,omitempty"`
// For type=additional_tools / tool_search_output
Tools []ResponsesTool `json:"tools,omitempty"`
// For type=custom_tool_call (grammar tools): the raw string input.
Input string `json:"input,omitempty"`
// For type=function_call_output
Output json.RawMessage `json:"output,omitempty"`
// For type=reasoning (opaque replay)
Summary json.RawMessage `json:"summary,omitempty"`
EncryptedContent json.RawMessage `json:"encrypted_content,omitempty"`
// For type=configuration_update
Reasoning *respReasoningEffort `json:"reasoning,omitempty"`
}
ResponsesInputItem is one element of the Responses API "input" array. Upstream: ResponseInput (union of message | function_call | function_call_output | reasoning).
func ConvertResponsesMessages ¶
func ConvertResponsesMessages(model *Model, transcript TranscriptContext, allowedToolCallProviders map[string]bool, options ConvertResponsesMessagesOptions) ([]ResponsesInputItem, error)
ConvertResponsesMessages converts a transcript to the Responses API "input" array for model: the leading system message (unless options.IncludeSystemPrompt is false), user, assistant and tool-result messages, with tool-call ids normalized for the providers in allowedToolCallProviders. Ports packages/ai/src/api/openai-responses-shared.ts convertResponsesMessages.
type ResponsesStrictDefault ¶
type ResponsesStrictDefault int
ResponsesStrictDefault is the strict field of a function tool that no constrained-sampling request decides: absent from the options or false emits false, true emits true and null emits null (convertResponsesTools options.strict: boolean | null).
const ( ResponsesStrictFalse ResponsesStrictDefault = iota ResponsesStrictTrue ResponsesStrictNull )
type ResponsesTool ¶
type ResponsesTool struct {
Type string `json:"type"` // "function" | "custom"
Name string `json:"name"`
Description string `json:"description"`
Parameters map[string]any `json:"parameters,omitempty"`
// Strict is a tri-state: absent (nil), null, true, or false. The default
// varies by provider (generic omits it; codex sends null; strict-mode models
// send false), so it is a raw JSON token rather than *bool.
Strict json.RawMessage `json:"strict,omitempty"`
Format *ResponsesToolFormat `json:"format,omitempty"`
// DeferLoading marks a tool loaded by a synthetic tool_search_output.
DeferLoading bool `json:"defer_loading,omitempty"`
// contains filtered or unexported fields
}
ResponsesTool is one entry of the Responses API "tools" array. A function tool carries parameters (+ strict when the model supports strict mode); a grammar (custom) tool carries a format block instead. Mirrors upstream OpenAITool.
func ConvertResponsesTools ¶
func ConvertResponsesTools(tools []ToolSchema, options ConvertResponsesToolsOptions) ([]ResponsesTool, error)
ConvertResponsesTools maps tools to the Responses API "tools" array. A grammar constrained-sampling tool becomes a custom tool with a format block; a json_schema constrained tool requests strict mode when supported; any other function tool takes the default strict value and emits it only when the model supports strict mode. Ports packages/ai/src/api/openai-responses-shared.ts convertResponsesTools.
func (ResponsesTool) MarshalJSON ¶
func (t ResponsesTool) MarshalJSON() ([]byte, error)
MarshalJSON writes a tool's members in the order convertResponsesTools creates them: strict is assigned after the literal that holds defer_loading (openai-responses-shared.ts:386-393), and the parameters keep the tool schema's own member order.
func (ResponsesTool) MarshalJSONTo ¶
func (t ResponsesTool) MarshalJSONTo(encoder *jsontext.Encoder) error
MarshalJSONTo is MarshalJSON written straight into the request encoder (respRequest.MarshalJSONTo).
type ResponsesToolFormat ¶
type ResponsesToolFormat struct {
Type string `json:"type"` // "grammar"
Syntax string `json:"syntax"` // "lark" | "regex"
Definition string `json:"definition"`
}
ResponsesToolFormat is a grammar (custom) tool's constrained-sampling format. Mirrors upstream OpenAITool custom.format.
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 RoleMessage ¶
type RoleMessage interface{ MessageRole() string }
RoleMessage is upstream's `{ role: string }`: anything with a role, including an agent message type the transcript helpers do not know.
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. Failed or cancelled deletion leaves the runtime key intact and preserves the cancellation cause.
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. It checks cancellation after the base list completes and preserves the caller's cause.
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. Cancellation returns the caller's cause.
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 SamplingParams ¶
SamplingParams holds free-form request body sampling keys such as temperature, top_p, top_k, min_p or repetition_penalty.
func ResolveSamplingParams ¶
func ResolveSamplingParams(model *Model, thinkingLevel ModelThinkingLevel, requestParams SamplingParams) SamplingParams
ResolveSamplingParams merges the model's sampling defaults, the overrides for the effective thinking level, and the request's sampling keys, later keys winning. The level is first clamped to one the model supports. It returns nil when none of the three is set. Mirrors upstream resolveSamplingParams (simple-options.ts:24-34).
type SamplingParamsByThinkingLevel ¶
type SamplingParamsByThinkingLevel = map[ModelThinkingLevel]SamplingParams
SamplingParamsByThinkingLevel holds sampling overrides keyed by Pi thinking level, not by provider effort value.
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 ShallowCapture ¶
type ShallowCapture struct {
// contains filtered or unexported fields
}
ShallowCapture is ShallowCopy taken now and copied later. Capture records what ShallowCopy would copy, without copying message data or parsing deferred tool arguments: a live view's published state is immutable once published and its nested-object references keep their identity, so the copy ShallowCopy builds from the capture at any later time equals the copy ShallowCopy would have built at the capture. A consumer that may never read the copy pays only for the capture.
func (*ShallowCapture) Capture ¶
func (capture *ShallowCapture) Capture(message *AssistantMessage)
Capture records message as it is now. Nil captures nil.
func (*ShallowCapture) Observe ¶
func (capture *ShallowCapture) Observe() *AssistantMessage
Observe returns what message.ShallowCopy().Observe() returned at the capture: owned message data at that publication.
func (*ShallowCapture) Publication ¶
func (capture *ShallowCapture) Publication() (cell uintptr, seq uint64)
Publication is the captured message's Publication at the capture: the producer cell and its publication count for a live view, (0, 0) otherwise. The copies the capture returns hold the state of that publication.
func (*ShallowCapture) ShallowCopy ¶
func (capture *ShallowCapture) ShallowCopy() *AssistantMessage
ShallowCopy returns what message.ShallowCopy returned at the capture.
type SplitErrorToolResult ¶
type SplitErrorToolResult struct {
// Content is the result content with each run of images replaced by a note.
Content []TextContent
// Caption is the text naming the tool call, to send before Images.
Caption string
Images []ImageContent
}
SplitErrorToolResult is an error tool result split into a text-only result and the images to send after the tool results (transform-messages.ts SplitErrorToolResult).
func SplitErrorToolResultImages ¶
func SplitErrorToolResultImages(message ToolResultMessage) *SplitErrorToolResult
SplitErrorToolResultImages splits the images out of an error tool result, for APIs that reject images in error results (Anthropic, and Claude on Bedrock). Send Content as the tool result and the caption and images after all tool results of the turn, in the same user message. It returns nil for a result that needs no split (Pi #10794, transform-messages.ts splitErrorToolResultImages).
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 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 StreamContinuation ¶
type StreamContinuation struct {
// contains filtered or unexported fields
}
StreamContinuation reserves a FIFO continuation before its owner transfers work to another goroutine. Its owner must Run it once or Cancel it before abandoning queued work.
func (*StreamContinuation) Cancel ¶
func (continuation *StreamContinuation) Cancel() bool
Cancel releases an unclaimed reservation without waiting for its queue position. It returns false once Run owns the callback; that running callback must be canceled and joined by its caller.
func (*StreamContinuation) Run ¶
func (continuation *StreamContinuation) Run(body func(*StreamObservation) error) error
Run waits for the reserved continuation, runs its synchronous callback with an observation scope, and releases ownership on return. A canceled reservation returns context.Canceled without invoking the callback. The callback runs as a coroutine turn, so a long-lived callback that awaits many times hands execution to other turns without goroutine wakes; it identifies its goroutine once.
func (*StreamContinuation) RunOwned ¶
func (continuation *StreamContinuation) RunOwned(owner StreamOwner, body func(*StreamObservation) error) error
RunOwned is Run for a caller that already holds its own StreamOwner: owner must be CurrentStreamOwner() of the goroutine that calls RunOwned, which is the goroutine the callback runs on. The callback runs directly on that goroutine, for a caller that runs one short callback after another.
type StreamFunction ¶
type StreamFunction = ModelsStreamFunction
StreamFunction is a provider stream for one request (types.ts StreamFunction). Its options are the one StreamOptions.
type StreamObservation ¶
type StreamObservation struct {
// contains filtered or unexported fields
}
StreamObservation owns the synchronous part of a stream-consumer continuation. Await releases execution while an upstream asynchronous operation waits, then resumes through the same reaction queue. Its awaits are called by the callback it scopes, on the callback's goroutine.
func StreamObservationFromContext ¶
func StreamObservationFromContext(ctx context.Context) *StreamObservation
StreamObservationFromContext returns the host observation, if this callback belongs to a scoped stream continuation. A callback that runs while a provider response turn holds execution belongs to that turn, even when its context was derived from a consumer that is parked in an await: an awaiting host callback must release the turn that is running.
func (*StreamObservation) Await ¶
func (observation *StreamObservation) Await(wait func() error) error
Await runs a blocking wait outside the synchronous observation and resumes in FIFO continuation order. Prepare any values that upstream reads before its await before calling Await.
func (*StreamObservation) AwaitContinuation ¶
func (observation *StreamObservation) AwaitContinuation(continuation *StreamContinuation, wait func() error) error
AwaitContinuation is Await for a wait that ends when continuation's callback returns. The resume reaction is queued when the callback returns, before its turn releases execution, so the awaiting goroutine keeps its place ahead of any I/O completion that became ready while the callback ran, however late that goroutine is scheduled. An unclaimed or canceled continuation resumes when wait returns, as in Await.
wait must return once the callback has returned: the returning callback also tells the executor that this goroutine is about to serve it, so a turn granted in between waits for this goroutine instead of waking another.
func (*StreamObservation) AwaitExternal ¶
func (observation *StreamObservation) AwaitExternal(wait func() error) error
AwaitExternal is Await for a wait that Pi settles from an I/O completion or timer callback instead of a promise reaction. The continuation runs after every ready reaction, and every reaction those queue, has run, so a wait that ends while the provider's reactions are still running resumes deterministically at their end. An extension handler that awaits its process is such a wait. wait runs outside the observation, as in Await.
func (*StreamObservation) AwaitTick ¶
func (observation *StreamObservation) AwaitTick(wait func() error) error
AwaitTick is Await for a wait that Pi settles from a process.nextTick callback: the continuation runs after every ready reaction and before any I/O completion, including completions queued earlier. A synchronous pipe or file write's callback is such a wait (output-guard.ts:writeRawStdoutChunk). Node queues the callback while the caller still runs, so wait runs first, on the caller's goroutine and still holding the observation; it must not depend on the executor.
func (*StreamObservation) Context ¶
func (observation *StreamObservation) Context(ctx context.Context) context.Context
Context carries the active observation through host callbacks without adding a wire field. A nil observation preserves the caller's context identity.
func (*StreamObservation) Owner ¶
func (observation *StreamObservation) Owner() StreamOwner
Owner is the goroutine that runs the callback this observation scopes.
func (*StreamObservation) PrepareContinuation ¶
func (observation *StreamObservation) PrepareContinuation() *StreamContinuation
PrepareContinuation reserves the next callback's place while the current observation still owns its synchronous prefix.
func (*StreamObservation) Yield ¶
func (observation *StreamObservation) Yield()
Yield awaits an already resolved operation. It reserves the resume reaction before releasing execution, so synchronous completion never depends on goroutine admission.
type StreamOptions ¶
type StreamOptions struct {
// TelemetryContext parents provider request spans; nil means no recording backend.
TelemetryContext telemetry.TelemetryContext
// Deferred preserves the deferred-generation boolean or window object.
Deferred *DeferredOption
// Fetch replaces HTTP execution with a caller-owned client, preserving its redirect policy and request context.
Fetch *http.Client `json:"-"`
// AnthropicClient replaces the Anthropic Messages provider's client construction entirely: the provider sends its request through it and skips federation, OAuth and API-key header assembly, as Pi's `AnthropicOptions.client` does (anthropic-messages.ts:286-290, 607-609). Other providers ignore it.
AnthropicClient AnthropicClient `json:"-"`
MaxTokens int
// Region selects the Bedrock request region. An inference-profile ARN's embedded region takes precedence.
Region string `json:"region,omitempty"`
// Profile selects the AWS shared credentials profile for a Bedrock request.
Profile string `json:"profile,omitempty"`
// Project is the Google Cloud project of a Vertex AI request; it takes precedence over the provider configuration and GOOGLE_CLOUD_PROJECT/GCLOUD_PROJECT (GoogleVertexOptions.project).
Project string `json:"project,omitempty"`
// Location is the Google Cloud location of a Vertex AI request; it takes precedence over the provider configuration and GOOGLE_CLOUD_LOCATION (GoogleVertexOptions.location).
Location string `json:"location,omitempty"`
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 `json:"reasoning,omitempty"`
// GoogleThinking carries Google's raw thinking object; Thinking is the provider-neutral reasoning option.
GoogleThinking *GoogleThinkingOptions `json:"thinking,omitempty"`
ThinkingEnabled *bool `json:"thinkingEnabled,omitempty"`
ThinkingBudgetTokens *int `json:"thinkingBudgetTokens,omitempty"`
Effort AnthropicEffort `json:"effort,omitempty"`
// ThinkingDisplay controls how Anthropic returns thinking content. Empty means "summarized" when thinking is enabled (anthropic-messages.ts:271, :1238, :1246).
ThinkingDisplay AnthropicThinkingDisplay `json:"thinkingDisplay,omitempty"`
InterleavedThinking *bool `json:"interleavedThinking,omitempty"`
RequestMetadata map[string]string `json:"requestMetadata,omitempty"`
// RequestMetadataOrder is the insertion order of RequestMetadata's keys, which Bedrock's requestMetadata object keeps on the wire.
// Keys missing from it follow in sorted order. Callers that decode the metadata from JSON fill it.
RequestMetadataOrder []string `json:"-"`
// BearerToken is the Bedrock bearer token; it takes precedence over APIKey and AWS_BEARER_TOKEN_BEDROCK (BedrockOptions.bearerToken).
BearerToken string `json:"bearerToken,omitempty"`
// ServiceTier is the OpenAI Responses and Codex service_tier request value (OpenAIResponsesOptions.serviceTier).
ServiceTier string `json:"serviceTier,omitempty"`
// TextVerbosity is the Codex text verbosity ("low", "medium" or "high"); empty is "low" (OpenAICodexResponsesOptions.textVerbosity).
TextVerbosity string `json:"textVerbosity,omitempty"`
// ReasoningEffort is the raw OpenAI-compatible or Mistral API effort. Unlike the provider-neutral Thinking level, it is mapped but not clamped so the provider can reject unsupported values.
ReasoningEffort string
// ReasoningSummary is the raw OpenAI Responses reasoning summary mode ("auto", "detailed" or "concise"). Without an effort it requests medium effort.
ReasoningSummary string `json:"reasoningSummary,omitempty"`
// PromptMode is the raw Mistral prompt mode, independent of provider-neutral Thinking.
PromptMode string `json:"promptMode,omitempty"`
// 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
// RepairToolFlow makes a real provider repair the tool results of its request before transformMessages: an out-of-order result moves to its call and an orphaned or repeated result is dropped. The agent loop sets it for a model request; a direct provider call keeps Pi's request.
// pig divergence (D48): upstream sends such results and the provider rejects the request.
RepairToolFlow bool `json:"-"`
// 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
// Signal carries the request lifetime to extension-owned provider callbacks. Native Provider.Stream implementations receive the same lifetime as their context argument.
Signal context.Context `json:"-"`
// APIKey is the request credential; ModelRuntime and direct StreamSimple construct the selected API provider with it. Bedrock also accepts it directly as a bearer token.
APIKey string
// 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 (a ToolChoice or its string) or a
// provider-specific choice object. Anthropic and Bedrock also accept "any" and
// {"type":"tool","name":...}.
ToolChoice any
// Debug asks a pi-messages backend for debug metadata such as routing response headers (pi-messages.ts PiMessagesOptions.debug).
Debug bool `json:"debug,omitempty"`
// Metadata contains optional provider request metadata. Providers extract
// recognized fields and ignore the rest.
Metadata map[string]any
// AzureAPIVersion, AzureResourceName, AzureBaseURL and AzureDeploymentName are the per-request Azure endpoint options (AzureEndpointOptions, api/azure-openai-config.ts:7). Each outranks the matching AZURE_OPENAI_* variable.
AzureAPIVersion string `json:"azureApiVersion,omitempty"`
AzureResourceName string `json:"azureResourceName,omitempty"`
AzureBaseURL string `json:"azureBaseUrl,omitempty"`
AzureDeploymentName string `json:"azureDeploymentName,omitempty"`
// Transport requests a provider-specific streaming transport.
// Empty lets the provider choose its default.
Transport Transport
// TimeoutMs bounds the full Mistral request through SSE consumption, and response headers or stream idleness for other supported providers. Nil selects the provider default; zero remains explicit and follows the selected provider's timeout semantics.
TimeoutMs *int `json:"timeoutMs,omitempty"`
// WebSocketConnectTimeoutMs bounds only the opening handshake. Nil selects the provider default; zero explicitly disables it.
WebSocketConnectTimeoutMs *int `json:"websocketConnectTimeoutMs,omitempty"`
MaxRetries *int `json:"maxRetries,omitempty"`
MaxRetryDelayMs *int `json:"maxRetryDelayMs,omitempty"`
// OnPayload is an optional payload-inspection hook invoked after the provider builds its native payload and before it serializes and 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)
// OnResponse is awaited before response consumption. The request context owns cancellation.
OnResponse func(context.Context, ProviderResponse, *Model) error
// OnProviderStreamEvent observes each parsed provider stream event before normalization. Event data is adapter-owned and read-only; an adapter without explicit support never calls it. Mirrors upstream StreamOptions.onProviderStreamEvent (packages/ai/src/types.ts:198).
OnProviderStreamEvent func(ctx context.Context, data any, model *Model) error
// ProviderStreamEventWanted reports, before an adapter parses a wire event for OnProviderStreamEvent, whether the observer would act on it now. When it reports false, the adapter skips parsing and calling OnProviderStreamEvent for that event; the caller promises that such a call would have returned nil and had no other effect. A wire event that would fail to parse is still parsed, so its error ends the request as before. Nil means the observer always acts.
ProviderStreamEventWanted func() bool
// contains filtered or unexported fields
}
StreamOptions are the options for a streaming LLM call.
func BuildBaseOptions ¶
func BuildBaseOptions(model *Model, context TranscriptContext, options StreamOptions, apiKey string) StreamOptions
BuildBaseOptions returns the request options every simple stream sends: the output budget is the requested one, or the model's maximum when none was requested, clamped to the context window; the sampling parameters are resolved for the simple reasoning level, "off" when it is unset; and apiKey, when not empty, replaces options.APIKey. Go has one StreamOptions type for the simple and the provider-specific options, so every other field passes through unchanged.
upstream: packages/ai/src/api/simple-options.ts:buildBaseOptions
type StreamOwner ¶
type StreamOwner struct {
// contains filtered or unexported fields
}
StreamOwner identifies the goroutine that runs stream callbacks, so a goroutine that runs one callback after another identifies itself once instead of at each callback.
func CurrentStreamOwner ¶
func CurrentStreamOwner() StreamOwner
CurrentStreamOwner is the owner of the calling goroutine.
type StringEnumOptions ¶
StringEnumOptions are the optional description and default of StringEnum.
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"`
Timestamp int64 `json:"timestamp"`
ToolsAdded []ToolSchema `json:"toolsAdded,omitempty"`
ToolsRemoved []ToolReference `json:"toolsRemoved,omitempty"`
}
SystemMessage changes instructions and tool state at one transcript position.
func CreateInitialSystemMessage ¶
func CreateInitialSystemMessage(systemPrompt string, tools []ToolSchema) *SystemMessage
func GetCurrentSystemMessage ¶
func GetCurrentSystemMessage[M RoleMessage](messages TranscriptMessages[M]) *SystemMessage
func GetInitialSystemMessage ¶
func GetInitialSystemMessage[M RoleMessage](messages TranscriptMessages[M]) *SystemMessage
func (SystemMessage) MarshalJSON ¶
func (message SystemMessage) MarshalJSON() ([]byte, error)
MarshalJSON writes an empty but present sections object as {}, which Pi's durable store writes after a reset: an absent member and an empty object are different records.
func (SystemMessage) MessageRole ¶
func (SystemMessage) MessageRole() string
MessageRole is the role property of a message.
type SystemOneTransport ¶
type SystemOneTransport struct {
// API is the classifier API this transport implements.
API ClassifierAPI
// Label names the service in error messages.
Label string
URL func(model ClassifierModel) string
// Payload wraps the System One request in the service's request envelope.
Payload func(model ClassifierModel, request SystemOneWireRequest) map[string]any
// Output extracts the System One output ({ answers, usage }) from the service's response envelope.
Output func(body json.RawMessage) (map[string]json.RawMessage, error)
}
SystemOneTransport holds the differences between services that serve System One models.
type SystemOneWireQuestions ¶
type SystemOneWireQuestions ClassifierQuestions
SystemOneWireQuestions are the questions as System One names them: a public bool question is a wire-level noul.
func (SystemOneWireQuestions) MarshalJSON ¶
func (q SystemOneWireQuestions) MarshalJSON() ([]byte, error)
type SystemOneWireRequest ¶
type SystemOneWireRequest struct {
State JsonObject
Questions SystemOneWireQuestions
}
SystemOneWireRequest is the System One request body without the transport-specific envelope.
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"`
// contains filtered or unexported fields
}
TextContent is a text fragment in a message.
func (TextContent) AppendStringify ¶
func (content TextContent) AppendStringify(dst []byte) ([]byte, error)
AppendStringify appends the JSON.stringify text of MarshalJSON's output to dst (sdkjson.StringifyAppender).
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 TextEndEvent ¶
type TextEndEvent struct {
ContentIndex int `json:"contentIndex"`
Content string `json:"content"`
Partial *AssistantMessage `json:"partial"`
// contains filtered or unexported fields
}
func (TextEndEvent) EventType ¶
func (TextEndEvent) EventType() AssistantEventType
func (TextEndEvent) MarshalJSON ¶
func (event TextEndEvent) MarshalJSON() ([]byte, error)
type TextSignatureV1 ¶
type TextSignatureV1 struct {
V int `json:"v"`
ID string `json:"id"`
Phase string `json:"phase,omitempty"`
}
TextSignatureV1 is the JSON payload an OpenAI Responses text block keeps in TextContent.TextSignature (types.ts TextSignatureV1). V is always 1; Phase is "commentary" or "final_answer" when set.
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 ThinkingBudgetLevels ¶
type ThinkingBudgetLevels uint8
ThinkingBudgetLevels is a set of thinking levels that have a configured budget.
const ( ThinkingBudgetMinimalSet ThinkingBudgetLevels = 1 << iota ThinkingBudgetLowSet ThinkingBudgetMediumSet ThinkingBudgetHighSet )
The levels of ThinkingBudgets that can carry a configured budget.
type ThinkingBudgets ¶
type ThinkingBudgets struct {
Minimal int
Low int
Medium int
High int
// Set flags the levels whose budget was configured, including zero and negative budgets.
Set ThinkingBudgetLevels
}
ThinkingBudgets maps thinking level names to token budgets. Upstream's ThinkingBudgets has an optional number per level, and a configured budget wins over the default whatever its value (simple-options.ts:82 spreads it over the defaults; google-generative-ai.ts:436 tests !== undefined), so a budget of zero or below is a real setting. A Go int cannot tell "0" from "unset", so Set records the levels configured explicitly; a level also counts as configured when its field is non-zero, which keeps a literal with only the level fields working. Use NewThinkingBudgets to build the value from optional settings.
func DefaultThinkingBudgets ¶
func DefaultThinkingBudgets() ThinkingBudgets
DefaultThinkingBudgets returns the default budget map. Mirrors upstream defaultBudgets (simple-options.ts:32-37).
func NewThinkingBudgets ¶
func NewThinkingBudgets(minimal, low, medium, high *int) *ThinkingBudgets
NewThinkingBudgets builds the custom budgets from optional per-level settings: a nil level is unset, any other value (zero and negative included) is configured. It returns nil when no level is set.
func (ThinkingBudgets) MarshalJSON ¶
func (b ThinkingBudgets) MarshalJSON() ([]byte, error)
MarshalJSON writes the configured levels as upstream's ThinkingBudgets object ({"minimal":n,...}) in the declaration order minimal, low, medium, high; a configured zero is written, an unset level is omitted.
func (*ThinkingBudgets) UnmarshalJSON ¶
func (b *ThinkingBudgets) UnmarshalJSON(data []byte) error
UnmarshalJSON reads upstream's ThinkingBudgets object: a present number is a configured level, whatever its value; an absent or null level is unset.
type ThinkingContent ¶
type ThinkingContent struct {
Thinking string `json:"thinking"`
ThinkingSignature string `json:"thinkingSignature,omitempty"`
Redacted bool `json:"redacted,omitempty"`
// contains filtered or unexported fields
}
ThinkingContent is a thinking/reasoning block. JSON decoding and provider streams preserve the distinction between omitted and explicitly empty signatures.
func (ThinkingContent) AppendStringify ¶
func (content ThinkingContent) AppendStringify(dst []byte) ([]byte, error)
AppendStringify appends the JSON.stringify text of MarshalJSON's output to dst (sdkjson.StringifyAppender).
func (ThinkingContent) MarshalJSON ¶
func (content ThinkingContent) MarshalJSON() ([]byte, error)
func (*ThinkingContent) UnmarshalJSON ¶
func (content *ThinkingContent) UnmarshalJSON(data []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 ThinkingEndEvent ¶
type ThinkingEndEvent struct {
ContentIndex int `json:"contentIndex"`
Content string `json:"content"`
Partial *AssistantMessage `json:"partial"`
// contains filtered or unexported fields
}
func (ThinkingEndEvent) EventType ¶
func (ThinkingEndEvent) EventType() AssistantEventType
func (ThinkingEndEvent) MarshalJSON ¶
func (event ThinkingEndEvent) MarshalJSON() ([]byte, error)
type ThinkingLevel ¶
type ThinkingLevel string
ThinkingLevel is the reasoning effort a request can ask for (types.ts ThinkingLevel). It has no "off": an omitted level means no reasoning request.
const ( ThinkingLevelMinimal ThinkingLevel = "minimal" ThinkingLevelLow ThinkingLevel = "low" ThinkingLevelMedium ThinkingLevel = "medium" ThinkingLevelHigh ThinkingLevel = "high" // ThinkingLevelXHigh is supported only by models whose thinkingLevelMap maps "xhigh". ThinkingLevelXHigh ThinkingLevel = "xhigh" // ThinkingLevelMax is supported only by models whose thinkingLevelMap maps "max" (for example Claude Opus 4.6 adaptive thinking). Like xhigh it clamps down for models that do not map it. ThinkingLevelMax ThinkingLevel = "max" )
The request levels of ThinkingLevel.
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 ThinkingTokenBudgetField ¶
type ThinkingTokenBudgetField string
ThinkingTokenBudgetField is the top-level request field that caps reasoning tokens on OpenAI-compatible servers.
upstream: packages/ai/src/types.ts:101
const ( ThinkingTokenBudgetFieldThinkingTokenBudget ThinkingTokenBudgetField = "thinking_token_budget" ThinkingTokenBudgetFieldThinkingBudget ThinkingTokenBudgetField = "thinking_budget" ThinkingTokenBudgetFieldThinkingBudgetTokens ThinkingTokenBudgetField = "thinking_budget_tokens" )
The request fields an OpenAI-compatible server reads a reasoning-token cap from.
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"`
// ArgumentsError is set when the model's complete arguments text was not a valid JSON object. Arguments is then empty; the text describes the problem and includes what the model sent, and tool argument validation fails with it (Pi 87f9a364).
ArgumentsError string `json:"argumentsError,omitempty"`
// contains filtered or unexported fields
}
ToolCall is a tool invocation block in an assistant message. Streaming OpenAI calls also serialize provider scratch fields until finalization or failure. Arguments is read and edited as a Go map; the member order the model sent is kept beside it and is written by ArgumentsJSON and MarshalJSON.
func NewDecodedToolCall ¶
func NewDecodedToolCall(id, name, thoughtSignature, namespace string, arguments JsonObject, rawArguments []byte) (ToolCall, error)
NewDecodedToolCall returns the tool call that decoding {"id":...,"name":...,"arguments":rawArguments,...} yields: the arguments object and the member order of its objects, which rawArguments, the JSON text of the arguments value, fixes. A caller that has already parsed the object uses it to skip the general decode. pig additive (D104): builds a decoded tool call for the single-pass entry decoder.
func ParseToolCallArguments ¶
ParseToolCallArguments is json-parse.ts parseToolCallArguments: the complete arguments text of a finished tool call becomes Pick<ToolCall, "arguments" | "argumentsError">, returned as a ToolCall holding only those two members. Text that is not a JSON object leaves Arguments empty and ArgumentsError describing the problem, never the parsed prefix.
func (ToolCall) AppendStringify ¶
AppendStringify appends the JSON.stringify text of MarshalJSON's output to dst (sdkjson.StringifyAppender): arguments in their recorded member order are appended in place rather than encoded apart.
func (ToolCall) ArgumentMembers ¶
func (content ToolCall) ArgumentMembers() ([]ArgumentMember, error)
ArgumentMembers lists the members of Arguments as `Object.entries(arguments).map(([key, value]) => [key, JSON.stringify(value)])` does: integer-like keys ascending first, then the others in the order the model sent them, each value written as JSON.stringify writes it (no HTML escaping, negative zero as 0, finite numbers in JavaScript form, lone surrogates kept).
func (ToolCall) ArgumentsJSON ¶
ArgumentsJSON encodes Arguments in the member order the model sent them. A nil Arguments is the empty object, as Pi's arguments are always an object. The bytes may be shared with other calls of ArgumentsJSON: the caller must not modify them.
func (*ToolCall) CopyArgumentsFrom ¶
CopyArgumentsFrom gives content other's arguments, a non-object value included.
func (*ToolCall) DefaultFalsyArguments ¶
func (content *ToolCall) DefaultFalsyArguments()
DefaultFalsyArguments is `arguments || {}`: a non-object value JavaScript treats as false (null, 0, false, "") becomes the empty object; [] and any other value stay.
func (*ToolCall) DeletePartialJson ¶
func (content *ToolCall) DeletePartialJson()
DeletePartialJson removes the `partialJson` member, as `delete toolCall.partialJson` does when the call ends.
func (ToolCall) MarshalJSON ¶
func (*ToolCall) SetArgumentsJSON ¶
SetArgumentsJSON decodes a complete JSON object into Arguments and keeps its member order. A text that is not a JSON object is an error and leaves the call unchanged.
func (*ToolCall) SetFinalArguments ¶
SetFinalArguments stores the complete arguments text of a finished tool call as Pi's parseToolCallArguments does: text that is not a valid JSON object leaves Arguments empty and ArgumentsError describing the problem, never the parsed prefix.
func (*ToolCall) SetPartialJson ¶
SetPartialJson records text as the call's `partialJson` member, the argument text an unfinished streamed call has received so far; JSON shows it until DeletePartialJson. Pi keeps the member on the block it streams into, so a message delivered before the call ends carries it.
func (*ToolCall) SetStreamingArguments ¶
SetStreamingArguments parses a streamed tool-argument text as ParseStreamingJson does and keeps its member order.
func (*ToolCall) UnmarshalJSON ¶
UnmarshalJSON decodes the call and keeps the member order of its arguments.
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 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 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 ToolChoice ¶
type ToolChoice string
ToolChoice is the provider-neutral tool choice: let the model decide, or call no tool. Mirrors upstream ToolChoice (types.ts:84).
const ( ToolChoiceAuto ToolChoice = "auto" ToolChoiceNone ToolChoice = "none" )
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 is the tool's details value. Nil is no details unless DetailsNull is set.
Details any `json:"details,omitempty"`
// DetailsNull marks a nil Details as an explicit JSON null, which JSON writes as `"details":null`; without it a nil
// Details is absent and JSON omits the key, as JSON.stringify omits undefined. It has no effect when Details is set.
DetailsNull bool `json:"-"`
Usage *Usage `json:"usage,omitempty"`
// NestedCalls are the calls this tool made to other tools. Kept for the session record; not sent to the model.
// upstream: .upstream/v0.99.1/packages/ai/src/types.ts:604
NestedCalls *NestedToolCalls `json:"nestedCalls,omitempty"`
IsError bool `json:"isError"`
// DurationMs is the milliseconds execute() took, measured with a monotonic clock. Nil when the tool did not run, and for results stored before it was recorded.
// upstream: ai/src/types.ts ToolResultMessage.durationMs
DurationMs *int64 `json:"durationMs,omitempty"`
Timestamp int64 `json:"timestamp"`
}
ToolResultMessage carries one tool execution result.
func (ToolResultMessage) MarshalJSON ¶
func (message ToolResultMessage) MarshalJSON() ([]byte, error)
func (ToolResultMessage) MessageRole ¶
func (ToolResultMessage) MessageRole() string
MessageRole is the role property of a message.
func (*ToolResultMessage) UnmarshalJSON ¶
func (message *ToolResultMessage) UnmarshalJSON(data []byte) error
UnmarshalJSON decodes a toolResult message. A details member that is JSON null sets DetailsNull; a missing one leaves Details nil and DetailsNull unset.
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"`
// ConstrainedSamplingDisabled records upstream's explicit `constrainedSampling: false`. It behaves like an
// unset request for providers, but transcript tool declarations keep it (transcript.ts:123-129).
ConstrainedSamplingDisabled bool `json:"-"`
// contains filtered or unexported fields
}
ToolSchema describes an LLM-callable tool in JSON Schema format. JSON decoding and encoding retain schema declaration order for provider strict-schema derivation; directly authored Go maps use deterministic key order.
func GetCurrentTools ¶
func GetCurrentTools[M RoleMessage](messages TranscriptMessages[M]) []ToolSchema
func GetDeclaredTools ¶
func GetDeclaredTools[M RoleMessage](messages TranscriptMessages[M]) []ToolSchema
func ToToolDeclaration ¶
func ToToolDeclaration(tool ToolSchema) ToolSchema
func (ToolSchema) MarshalJSON ¶
func (tool ToolSchema) MarshalJSON() ([]byte, error)
MarshalJSON preserves imported parameter ordering when tool definitions cross a session or SDK boundary.
func (ToolSchema) ParametersJSON ¶
func (tool ToolSchema) ParametersJSON() ([]byte, error)
ParametersJSON encodes Parameters as JSON.stringify writes the schema: a decoded schema keeps its authored member order, and an object the order does not record (a Go-authored map) has sorted members.
func (*ToolSchema) UnmarshalJSON ¶
func (tool *ToolSchema) UnmarshalJSON(data []byte) error
UnmarshalJSON keeps schema key order as well as its validated data values.
type ToolStateChanges ¶
type ToolStateChanges struct {
ToolsAdded []ToolSchema
ToolsRemoved []ToolReference
}
func GetToolStateChanges ¶
func GetToolStateChanges(previous, current []ToolSchema) ToolStateChanges
func GetToolStateChangesFrom ¶
func GetToolStateChangesFrom[M RoleMessage](messages TranscriptMessages[M], current []ToolSchema) ToolStateChanges
GetToolStateChangesFrom is GetToolStateChanges(GetCurrentTools(messages), current) without the copy of every replayed tool: the replayed declarations are only compared, never returned.
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
CollapseSystemMessages and ResolveTranscript share the messages of the transcript they are given: nothing modifies a transcript's messages (Messages hands out copies, At's callers and borrowers must not modify), and every one of them is already normalized and validated, so only the collapsed system message is new. Providers borrow the result (collapsedMessages, resolvedMessages), so a request build copies no message it does not change. pi-ai shares the same way: resolveTranscript returns the context itself and collapseSystemMessages filters it. upstream: packages/ai/src/utils/transcript.ts:collapseSystemMessages
func NormalizeContext ¶
func NormalizeContext(context Context) TranscriptContext
NormalizeContext folds shorthand prompt/tools into a leading system message and normalizes missing content to empty block arrays.
func ResolveTranscript ¶
func ResolveTranscript(context TranscriptContext, supportsMidConversationSystemMessages bool) TranscriptContext
func (TranscriptContext) At ¶
func (context TranscriptContext) At(i int) Message
At returns the transcript's i-th message without copying it, as reading pi-ai's transcript.messages[i] does. The message shares its content with the transcript: modifying anything it references corrupts the transcript. Use Messages for a copy. It panics when i is out of range.
func (TranscriptContext) FrozenContext ¶
func (context TranscriptContext) FrozenContext() Context
FrozenContext is a Context for a stream made from this transcript: its messages are shared, not copied, and normalizing it does not validate them again. The caller must not modify Messages or anything a message references. pig additive (D104): pi-ai's normalizeContext neither copies nor revalidates a transcript's messages.
func (TranscriptContext) Len ¶
func (context TranscriptContext) Len() int
Len is the number of messages in the normalized transcript. pig additive (D104): reads transcript.messages without the copy Messages makes.
func (TranscriptContext) Messages ¶
func (context TranscriptContext) Messages() []Message
Messages returns a deep copy of the normalized transcript.
type TranscriptMessages ¶
type TranscriptMessages[M RoleMessage] = []M
TranscriptMessages is any message list: `readonly { role: string }[]` (utils/transcript.ts:40). The replay helpers read only the entries whose role is "system".
type TranscriptTools ¶
type TranscriptTools struct {
RequestTools []ToolSchema
AnchorsAdditions bool
}
func ResolveTranscriptTools ¶
func ResolveTranscriptTools[M RoleMessage](messages TranscriptMessages[M], supportsToolAdditions bool) TranscriptTools
type UnsupportedStrictSchemaKeywordCheck ¶
UnsupportedStrictSchemaKeywordCheck reports whether a provider's strict mode rejects a schema keyword with this value. Mirrors upstream UnsupportedStrictSchemaKeywordCheck.
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"`
// contains filtered or unexported fields
}
Usage reports token usage from the provider.
func DecodedFormUsage ¶
DecodedFormUsage is the usage decoding the JSON encoding of usage yields, and false when a cost is not a finite number other than negative zero.
func ParseClassifierUsage ¶
func ParseClassifierUsage(raw json.RawMessage, model ClassifierModel) *Usage
ParseClassifierUsage reads a { input_tokens, output_tokens } object and prices it from the model catalog like chat usage. A missing or malformed usage object leaves the result without usage instead of failing it.
func (Usage) AppendStringify ¶
AppendStringify appends the JSON.stringify text of MarshalJSON's output to dst (sdkjson.StringifyAppender). A non-finite cost is the error MarshalJSON reports.
func (Usage) MarshalJSON ¶
MarshalJSON emits the upstream Usage wire shape. A provider creates cacheWrite1h and reasoning on a usage object that already holds totalTokens and cost (anthropic-messages.ts:684, :846-851, bedrock-converse-stream.ts:715), so JSON.stringify writes them last; usage built as one literal (usage-totals.ts combineUsage) holds them before totalTokens.
func (*Usage) UnmarshalJSON ¶
UnmarshalJSON decodes the upstream Usage wire shape and keeps where the source wrote cacheWrite1h and reasoning.
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 prices of a chat, image or classifier model and returns it. A nil model has no price. Mirrors upstream models.ts:calculateCost(model: AnyModel, usage).
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)
func (UserMessage) MessageRole ¶
func (UserMessage) MessageRole() string
MessageRole is the role property of a message.
type ValidationMemo ¶
type ValidationMemo struct {
// contains filtered or unexported fields
}
ValidationMemo remembers which JSON-valued references (a tool result's details, a tool call's arguments) a Frozen transcript already validated, so a transcript that grows by one message per turn validates each value once instead of once per turn. A value is known by its identity: a pointer, a map, or the first element and length of a slice. A Frozen context promises that nothing modifies a value it references, and a caller that reuses a memo extends that promise to every request the memo serves. The memo holds each value it has seen, so an identity never names two values.
Each normalization keeps the entries its transcript still references and drops the rest, so the memo holds the live transcript's values and no replaced history. The zero value is an empty memo; a nil *ValidationMemo validates every value. pig additive (D104): pi-ai validates nothing.
func NewValidationMemo ¶
func NewValidationMemo() *ValidationMemo
NewValidationMemo returns an empty memo.
type VercelGatewayRouting ¶
type VercelGatewayRouting struct {
// Only lists provider slugs to exclusively use for a request, for example ["bedrock", "anthropic"]. An empty list is set.
Only []string `json:"only,omitzero"`
// Order lists provider slugs to try in order, for example ["anthropic", "openai"]. An empty list is set.
Order []string `json:"order,omitzero"`
}
VercelGatewayRouting is the Vercel AI Gateway routing preference: which upstream providers the gateway may use and in which order (types.ts VercelGatewayRouting).
Source Files
¶
- abort_race.go
- abort_utils.go
- accumulated_string.go
- anthropic.go
- anthropic_client.go
- anthropic_delta_fast.go
- anthropic_event_jsread.go
- anthropic_federation.go
- anthropic_message_key.go
- anthropic_request_jsonv2.go
- anthropic_stream.go
- api_key_providers.go
- api_streams.go
- api_strip.go
- assistant_message_json.go
- assistant_observation.go
- assistant_observation_settle.go
- assistant_publication.go
- assistant_retry.go
- assistant_snapshot.go
- auth.go
- auth_env_keys.go
- auth_interaction.go
- auth_lazy.go
- auth_login.go
- auth_mutex.go
- auth_native_login.go
- auth_providers.go
- auth_reload.go
- auth_reload_snapshot.go
- auth_resolve.go
- auth_revision_unix.go
- auth_store.go
- azure.go
- azure_config.go
- azure_openai_responses.go
- bedrock.go
- bedrock_body_tap.go
- bedrock_error_response.go
- bedrock_eventstream.go
- bedrock_request_validity.go
- bedrock_retry_backoff.go
- bedrock_stream_pipeline.go
- bedrock_stream_state.go
- bedrock_wire.go
- block_deltas.go
- body_readiness.go
- builtin_providers.go
- builtin_providers_google_openai_together.go
- classifier.go
- classifier_http.go
- classifier_join.go
- classifier_models_generated.go
- classifier_wire.go
- cloudflare.go
- cloudflare_ai_binding.go
- cloudflare_streams.go
- compat.go
- constrained_sampling.go
- content_block.go
- continuation.go
- continuation_ticks.go
- copilot_verification_uri.go
- credential_expiry.go
- credential_json.go
- decoded_form.go
- deferred_option.go
- diagnostics.go
- direct_simple.go
- doc.go
- errors.go
- estimate.go
- event_stream.go
- event_stream_continuation.go
- event_stream_generic.go
- event_stream_partial.go
- events.go
- faux.go
- faux_core.go
- faux_deferred.go
- form_fields.go
- gemini_chunk_jsread.go
- github_copilot_filter.go
- githubcopilot.go
- google.go
- google_sdk_pipeline.go
- google_vertex.go
- google_vertex_config.go
- google_wire.go
- goroutine_id.go
- http_body_observation.go
- http_proxy.go
- http_transport.go
- image_models_generated.go
- images.go
- images_registry.go
- in_memory_credential_store.go
- js_async_generator.go
- js_date_parse.go
- js_promise.go
- json_plain.go
- json_repair.go
- known_provider.go
- llama_cpp_classify.go
- messages.go
- mistral.go
- mistral_chunk_jsread.go
- mistral_config.go
- mistral_reader.go
- mistral_response_body.go
- model_catalog.go
- model_compat_clone.go
- model_compat_json.go
- model_operations_export.go
- model_types.go
- model_utils.go
- models_catalog_codec.go
- models_generated.go
- models_options.go
- models_provider.go
- models_runtime.go
- models_runtime_auth.go
- models_runtime_close.go
- models_runtime_refresh.go
- models_runtime_signal.go
- models_runtime_stream.go
- models_runtime_typed.go
- models_store.go
- models_store_read.go
- native_body_iterator.go
- node_http_proxy.go
- node_readable.go
- node_readable_iterator.go
- node_web_stream.go
- oauth_anthropic.go
- oauth_authorization_input.go
- oauth_callback_server.go
- oauth_device_code.go
- oauth_kimi.go
- oauth_meta.go
- oauth_openai_chatgpt.go
- oauth_openai_codex.go
- oauth_openrouter.go
- oauth_page.go
- oauth_radius.go
- oauth_registry.go
- oauth_response_json.go
- oauth_trusted_url.go
- oauth_types.go
- oauth_xai.go
- openai.go
- openai_cache_control.go
- openai_chunk_fast.go
- openai_chunk_jsread.go
- openai_codex_frames.go
- openai_codex_http.go
- openai_codex_responses.go
- openai_codex_sse_stream.go
- openai_codex_websocket.go
- openai_completions_compat.go
- openai_decisions.go
- openai_error.go
- openai_message_jsonv2.go
- openai_message_key.go
- openai_prompt_cache.go
- openai_responses.go
- openai_responses_delta_fast.go
- openai_responses_jsread.go
- openai_responses_request_jsonv2.go
- openai_stream_decoder.go
- opencode_headers.go
- openrouter_api.go
- openrouter_cost.go
- openrouter_images.go
- openrouter_images_api.go
- openrouter_images_chat.go
- openrouter_user_models.go
- operation_options.go
- ordered_json.go
- ordered_json_object.go
- overflow.go
- pi_messages.go
- pi_messages_events.go
- pi_messages_reader.go
- pkce.go
- provider_catalogs.go
- provider_constructors.go
- provider_env.go
- provider_headers.go
- provider_login.go
- provider_names.go
- provider_request_options.go
- provider_response.go
- provider_retry.go
- provider_stream_event.go
- provider_streams.go
- provider_strip.go
- provider_tool_scratch.go
- provider_wrap.go
- providers_generated.go
- radius.go
- radius_config.go
- register_builtins.go
- registry.go
- request_body_jsonv2.go
- request_body_raw.go
- request_body_splice.go
- request_body_stringify.go
- request_message_cache.go
- request_message_splice_jsonv2.go
- request_string_splice.go
- request_validity.go
- runtime_credentials.go
- sampling_params_assign.go
- sanitize_unicode.go
- schema_object_order.go
- sdk_request_url.go
- session_resources.go
- simple_options.go
- socket_read_linux.go
- socket_read_raw_linux.go
- sse.go
- sse_event_idle.go
- stream_builder.go
- stream_continuation.go
- stream_forward.go
- stream_observation.go
- stream_observation_capture.go
- stream_response.go
- streamed_blocks.go
- streaming_json.go
- streaming_json_resume.go
- system_one.go
- test_faux.go
- text.go
- tool_call_arguments.go
- tool_flow.go
- tool_flow_repair.go
- transcript.go
- transform_messages.go
- transport_diagnostic.go
- transport_error.go
- tslib_async.go
- tslib_promise.go
- typebox_helpers.go
- types.go
- types_unions.go
- usage_json.go
- user_agent.go
- user_agent_unix.go
- uuid.go
- validate.go
- validate_arguments.go
- validate_convert.go
- validate_errors.go
- validate_json.go
- validate_value.go
- validate_wrapped_order.go
- validation_memo.go
- zstd_codex.go