Documentation
¶
Overview ¶
Package pigo exposes the core pi.ai-style library surface for Go.
The package is intentionally a small core library, not a full agent framework. It focuses on model metadata, provider and API routing, streaming assistant events, message transformation for replay across providers, and minimal tool argument validation.
Core concepts:
- Model describes a concrete model plus provider-specific compatibility metadata and capabilities.
- Provider and API registries route Stream and Complete calls without a hard-coded provider switch.
- Context carries the system prompt, message history, and tools.
- Message and ContentBlock capture the normalized conversation format used across providers.
- AssistantMessageEventStream exposes incremental streaming events and a final AssistantMessage result.
Basic usage:
model := pigo.GetModel("kimi-coding", "kimi-k2-thinking")
if model == nil {
panic("missing model")
}
result := pigo.CompleteSimple(*model, pigo.Context{
SystemPrompt: "You are a precise coding assistant.",
Messages: []pigo.Message{
pigo.UserMessage{Content: "Summarize this repository."},
},
}, pigo.SimpleStreamOptions{
APIKey: "kimi-api-key",
})
_ = result
StreamSimple provides the same execution path with incremental events when a caller needs text deltas, tool-call lifecycle events, or explicit stop/error handling.
Index ¶
- Constants
- Variables
- func CleanupSessionResources(sessionID string) error
- func DeclarationsEqual(left, right Tool) bool
- func FindEnvKeys(provider Provider) []string
- func GetCurrentSystemPrompt(messages []Message) string
- func GetEnvAPIKey(provider Provider) string
- func GetOverflowPatterns() []*regexp.Regexp
- func GetSystemMessageText(message SystemMessage) string
- func IsContextOverflow(message AssistantMessage, contextWindow int) bool
- func ModelsAreEqual(a, b *Model) bool
- func NewProviderHTTPClient(base *http.Client, policy ProviderHTTPPolicy) *http.Client
- func NormalizeOpenAIResponsesToolCallID(id string, targetModel Model, source AssistantMessage) string
- func NormalizeSimpleToolCallID(id string) string
- func RegisterAPIModule(module APIModule)
- func RegisterAPIModuleForSource(sourceID string, module APIModule)
- func RegisterAPIModuleWithValidationForSource(sourceID string, module APIModule, validation APIOptionValidation)
- func RegisterKiroBufferedModule(sourceID string, config KiroBufferedConfig) error
- func RegisterKiroBufferedModuleWithOptions(sourceID string, config KiroBufferedConfig, options ...KiroBufferedOption) error
- func RegisterKiroIncrementalModule(sourceID string, config KiroIncrementalConfig, options KiroIncrementalOptions) error
- func RegisterKiroIncrementalModuleWithAuthoredToolHistory(sourceID string, config KiroIncrementalConfig, options KiroIncrementalOptions) error
- func RegisterKiroLiveTextModule(sourceID string, config KiroLiveTextConfig) error
- func RegisterKiroLiveTextModuleWithOptions(sourceID string, config KiroLiveTextConfig, options KiroLiveTextOptions) error
- func RegisterKiroSessionBufferedModule(sourceID string, config KiroBufferedConfig, affinity KiroSessionAffinity) error
- func RegisterLazyAPIModule(api API, factory APIModuleFactory)
- func RegisterLazyAPIModuleForSource(sourceID string, api API, factory APIModuleFactory)
- func RegisterLazyProviderModule(provider Provider, factory ProviderModuleFactory)
- func RegisterProviderModule(module ProviderModule)
- func RegisterSessionResourceCleanup(cleanup SessionResourceCleanup) func()
- func RegisterSessionResourceCleanupOptional(cleanup SessionResourceCleanupOptional) func()
- func RenderSystemMessageUpdate(message SystemMessage) string
- func RequiresOAuth(provider Provider) bool
- func ResolveAPIKey(provider Provider, auth map[Provider]AuthConfig) string
- func ResolveAuthorization(provider Provider, auth map[Provider]AuthConfig, httpClient *http.Client, ...) (string, error)
- func ResolveCommandCodeAPIKey(auth map[Provider]AuthConfig) string
- func SerializeContext(context Context) ([]byte, error)
- func ShortHash(value string) string
- func SupportsHostedTool(model Model, toolType HostedToolType) bool
- func SupportsMax(model Model) bool
- func SupportsQuotaQuery(provider Provider) bool
- func SupportsXHigh(model Model) bool
- func UnregisterAPIModules(sourceID string)
- func ValidateResponseFormat(model Model, format *ResponseFormat) error
- func ValidateToolArguments(tool Tool, toolCall ToolCall) (map[string]any, error)
- func ValidateToolCall(tools []Tool, toolCall ToolCall) (map[string]any, error)
- type API
- type APIModule
- type APIModuleFactory
- type APIOptionValidation
- type APISimpleStreamFunc
- type APIStreamFunc
- type AnthropicMessagesCompat
- type AnthropicMessagesProviderOptions
- type AssistantMessage
- type AssistantMessageDiagnostic
- type AssistantMessageEvent
- type AssistantMessageEventStream
- type AssistantMessageEventType
- type AuthConfig
- type AuthType
- type CacheRetention
- type CapabilitySupport
- type CommandCodeCompat
- type CommandCodeModelsResult
- type CommandCodeModelsSource
- type CommonProviderOptions
- type ContentBlock
- type Context
- type DeepSeekProviderOptions
- type DiagnosticErrorInfo
- type GoogleProviderOptions
- type GoogleThinkingConfig
- type HTTPDelivery
- type HTTPObservation
- type HTTPStreamClient
- type HandoffCredentials
- type HandoffOAuthCredentials
- type HandoffProviderAuth
- type HostedTool
- type HostedToolCapabilities
- type HostedToolExecution
- type HostedToolType
- type ImageContent
- type InputType
- type KimiCodingProviderOptions
- type KiroBufferedConfig
- type KiroBufferedOption
- type KiroCatalogFetchConfig
- type KiroCatalogIDKind
- type KiroCredentialKind
- type KiroCredentialScope
- type KiroDesktopRefreshConfig
- type KiroDesktopRefreshError
- type KiroDesktopRefreshResult
- func (r KiroDesktopRefreshResult) Credential() KiroScopedCredential
- func (r KiroDesktopRefreshResult) ExpiresAt() time.Time
- func (KiroDesktopRefreshResult) GoString() string
- func (r KiroDesktopRefreshResult) RefreshAfter() time.Time
- func (r KiroDesktopRefreshResult) RefreshToken() string
- func (r KiroDesktopRefreshResult) RetainedRefreshToken() bool
- func (KiroDesktopRefreshResult) String() string
- type KiroIDCRefreshConfig
- type KiroIDCRefreshError
- type KiroIDCRefreshOption
- type KiroIDCRefreshResult
- func (r KiroIDCRefreshResult) Credential() KiroScopedCredential
- func (r KiroIDCRefreshResult) ExpiresAt() time.Time
- func (KiroIDCRefreshResult) GoString() string
- func (r KiroIDCRefreshResult) RefreshAfter() time.Time
- func (r KiroIDCRefreshResult) RefreshToken() string
- func (r KiroIDCRefreshResult) RetainedRefreshToken() bool
- func (KiroIDCRefreshResult) String() string
- type KiroIncrementalConfig
- type KiroIncrementalOptions
- type KiroLiveTextConfig
- type KiroLiveTextOptions
- type KiroModelCatalog
- func (KiroModelCatalog) GoString() string
- func (c *KiroModelCatalog) Models(scope KiroCredentialScope, now time.Time, maxAge time.Duration) ([]KiroModelObservation, error)
- func (c *KiroModelCatalog) Select(scope KiroCredentialScope, kind KiroCatalogIDKind, id string, now time.Time, ...) (KiroModelObservation, error)
- func (KiroModelCatalog) String() string
- type KiroModelObservation
- func (m KiroModelObservation) Alias() string
- func (m KiroModelObservation) DisplayName() string
- func (KiroModelObservation) GoString() string
- func (m KiroModelObservation) MaxInputTokens() (int64, bool)
- func (m KiroModelObservation) MaxOutputTokens() (int64, bool)
- func (m KiroModelObservation) RawMetadata() json.RawMessage
- func (m KiroModelObservation) RequestFieldsSchema() json.RawMessage
- func (m KiroModelObservation) ServiceID() string
- func (KiroModelObservation) String() string
- type KiroRequestIDs
- type KiroScopedCredential
- type KiroSessionAffinity
- type LoggingObserver
- func (o *LoggingObserver) OnRequestComplete(ctx context.Context, model Model, result AssistantMessage, ...)
- func (o *LoggingObserver) OnRequestError(ctx context.Context, model Model, err error, duration time.Duration)
- func (o *LoggingObserver) OnRequestStart(ctx context.Context, model Model, _ any) context.Context
- func (o *LoggingObserver) OnStreamEvent(_ context.Context, _ Model, _ AssistantMessageEvent)
- func (o *LoggingObserver) OnStreamFinish(ctx context.Context, model Model, _ AssistantMessage, eventCount int, ...)
- type Message
- type MessageTransformer
- type MistralProviderOptions
- type Model
- type ModelCapabilities
- type ModelCapabilitySnapshot
- type ModelCostTier
- type ModelThinkingLevel
- type OAuthCredentials
- type Observer
- type OpenAICodexProviderOptions
- type OpenAICompletionsCompat
- type OpenAICompletionsProviderOptions
- type OpenAIResponsesCompat
- type OpenAIResponsesProviderOptions
- type OpenRouterRouting
- type Option
- type Provider
- type ProviderAuth
- type ProviderAuthResolveFunc
- type ProviderCapabilities
- type ProviderCapabilitySnapshot
- type ProviderCompat
- type ProviderFailure
- type ProviderHTTPPolicy
- type ProviderModule
- type ProviderModuleFactory
- type ProviderOptionsBuildFunc
- type ProviderOptionsNormalizeFunc
- type ProviderResponse
- type ProviderStreamOptionsdeprecated
- type QuotaBalance
- type QuotaIssue
- type QuotaQuerier
- type QuotaQueryError
- type QuotaQueryOptions
- type QuotaResult
- type QuotaSubscription
- type QuotaWindow
- type Registry
- type RequestObserver
- type ResponseFormat
- type ResponseFormatCapabilities
- type ResponseFormatType
- type SamplingParams
- type SamplingParamsByThinkingLevel
- type SessionResourceCleanup
- type SessionResourceCleanupOptional
- type SimpleStreamOptionsdeprecated
- type StopReason
- type StreamObserver
- type StreamOptions
- type SystemMessage
- type TextContent
- type TextSignatureV1
- type ThinkingBudgets
- type ThinkingContent
- type ThinkingLevel
- type ThinkingLevelMap
- type Tool
- type ToolArgumentsValidator
- type ToolArgumentsValidatorFunc
- type ToolCall
- type ToolConstrainedSampling
- type ToolReference
- type ToolResultMessage
- type ToolSamplingDecision
- type ToolStateChanges
- type TranscriptContext
- type Transport
- type Usage
- type UsageCost
- type UserMessage
- type VercelGatewayRouting
Constants ¶
const ( ProviderFailureUpstream = "upstream_error" ProviderFailureStream = "stream_interrupted" ProviderFailureParse = "response_parse_error" ProviderFailureSDK = "sdk_error" )
const ( HTTPDeliveryUnknown HTTPDelivery = "unknown" HTTPDeliveryNotSent HTTPDelivery = "not_sent" HTTPDeliveryResponseReceived HTTPDelivery = "response_received" DefaultMaxProviderErrorBytes int64 = 64 << 10 )
const ( KiroCatalogAlias = kiroCatalogAlias KiroCatalogServiceID = kiroCatalogServiceID )
const ( KiroCredentialBearer = kiroCredentialBearer KiroCredentialAPIKey = kiroCredentialAPIKey KiroCredentialExternalIDP = kiroCredentialExternalIDP )
const ( StopReasonStop StopReason = "stop" StopReasonLength StopReason = "length" StopReasonToolUse StopReason = "toolUse" StopReasonError StopReason = "error" StopReasonAborted StopReason = "aborted" InputText InputType = "text" InputImage InputType = "image" CacheRetentionNone CacheRetention = "none" CacheRetentionShort CacheRetention = "short" CacheRetentionLong CacheRetention = "long" ThinkingLevelMinimal ThinkingLevel = "minimal" ThinkingLevelLow ThinkingLevel = "low" ThinkingLevelMedium ThinkingLevel = "medium" ThinkingLevelHigh ThinkingLevel = "high" ThinkingLevelXHigh ThinkingLevel = "xhigh" ThinkingLevelMax ThinkingLevel = "max" ModelThinkingLevelOff ModelThinkingLevel = "off" ModelThinkingLevelMinimal ModelThinkingLevel = "minimal" ModelThinkingLevelLow ModelThinkingLevel = "low" ModelThinkingLevelMedium ModelThinkingLevel = "medium" ModelThinkingLevelHigh ModelThinkingLevel = "high" ModelThinkingLevelXHigh ModelThinkingLevel = "xhigh" ModelThinkingLevelMax ModelThinkingLevel = "max" TransportSSE Transport = "sse" TransportWebSocket Transport = "websocket" TransportWebSocketCached Transport = "websocket-cached" TransportAuto Transport = "auto" HostedToolTypeWebSearch HostedToolType = "web_search" HostedToolTypeFetch HostedToolType = "fetch" HostedToolTypeCodeRunner HostedToolType = "code_runner" HostedToolTypeExcel HostedToolType = "excel" )
const (
MaxCustomToolInputBytes = 1 << 20
)
Native input is bounded independently of SSE frame and pending-event limits. Codemode applies its own smaller source limit after this transport boundary.
const MaxToolGrammarBytes = 64 << 10
const Version = "0.19.0"
Version is the current package version.
Variables ¶
var ( ErrQuotaUnsupported = errors.New("provider does not support quota queries") ErrQuotaCredentials = errors.New("missing credentials for quota query") )
var ( ErrResponseFormatInvalid = errors.New("invalid response format") ErrResponseFormatUnsupported = errors.New("response format is not supported by provider") )
var ErrProviderErrorBodyTooLarge = errors.New("provider error body exceeds limit")
var ErrSSEEventTooLarge = errors.New("provider SSE event exceeds limit")
var ErrStreamBufferExceeded = errors.New("stream event buffer limit exceeded")
ErrStreamBufferExceeded means event delivery could not preserve lifecycle events within the stream's pending-buffer budget. Result retains provider evidence but reports StopReasonError rather than successful partial delivery.
Functions ¶
func CleanupSessionResources ¶
func DeclarationsEqual ¶
func FindEnvKeys ¶
func GetCurrentSystemPrompt ¶
func GetEnvAPIKey ¶
func GetOverflowPatterns ¶
GetOverflowPatterns returns a copy of the overflow detection patterns for testing and debugging purposes.
func GetSystemMessageText ¶
func GetSystemMessageText(message SystemMessage) string
func IsContextOverflow ¶
func IsContextOverflow(message AssistantMessage, contextWindow int) bool
IsContextOverflow recognizes explicit provider errors or usage evidence of context overflow. A zero contextWindow disables usage-based heuristics. This only classifies the response; the host decides whether to compact or retry.
func ModelsAreEqual ¶
func NewProviderHTTPClient ¶
func NewProviderHTTPClient(base *http.Client, policy ProviderHTTPPolicy) *http.Client
NewProviderHTTPClient preserves a supplied client's transport, redirects, timeout and cookie jar; failures through that client remain unknown. A nil base uses a shared private standard transport with environment proxies and HTTP/2, independent of http.DefaultClient and http.DefaultTransport. Supply an explicit client to preserve customizations to those globals. It bounds error bodies before any SDK consumes them and reports transport evidence.
func NormalizeOpenAIResponsesToolCallID ¶
func NormalizeOpenAIResponsesToolCallID(id string, targetModel Model, source AssistantMessage) string
func RegisterAPIModule ¶
func RegisterAPIModule(module APIModule)
func RegisterAPIModuleWithValidationForSource ¶ added in v0.18.0
func RegisterAPIModuleWithValidationForSource(sourceID string, module APIModule, validation APIOptionValidation)
RegisterAPIModuleWithValidationForSource atomically registers a module and its option contract. Legacy registration remains unchanged; no API is enabled by merely constructing validation. In-flight snapshots survive unregistration.
func RegisterKiroBufferedModule ¶ added in v0.18.0
func RegisterKiroBufferedModule(sourceID string, config KiroBufferedConfig) error
RegisterKiroBufferedModule explicitly registers only an API module, not a model catalog or provider identity. The caller owns sourceID and unregisters using UnregisterAPIModules. Duplicate APIs panic like existing registration methods. Registration validates/copies config and never invokes callbacks. Requests return buffered lifecycle events only after complete response validation; this is NOT realtime streaming. This API does not establish service-use permission.
func RegisterKiroBufferedModuleWithOptions ¶ added in v0.18.0
func RegisterKiroBufferedModuleWithOptions(sourceID string, config KiroBufferedConfig, options ...KiroBufferedOption) error
RegisterKiroBufferedModuleWithOptions leaves original registration APIs and public config layouts unchanged. At most one of each controlled option is accepted; zero/duplicate options reject before registration/callbacks. With no options this has the same strict behavior as RegisterKiroBufferedModule.
func RegisterKiroIncrementalModule ¶ added in v0.18.0
func RegisterKiroIncrementalModule(sourceID string, config KiroIncrementalConfig, options KiroIncrementalOptions) error
RegisterKiroIncrementalModule installs only an explicitly selected API module. Text previews are provisional; tool lifecycle events require completed response validation. Execution still needs final success and Agent permission/schema/ context checks. No network default, login, model catalog or retry is installed. Use Stream/StreamSimple guards, not raw GetAPIModule callbacks. Trusted sources, executor and body operations must cooperate with context. Previews cannot be recalled after a late failure. sourceID owns UnregisterAPIModules cleanup.
func RegisterKiroIncrementalModuleWithAuthoredToolHistory ¶ added in v0.18.0
func RegisterKiroIncrementalModuleWithAuthoredToolHistory(sourceID string, config KiroIncrementalConfig, options KiroIncrementalOptions) error
RegisterKiroIncrementalModuleWithAuthoredToolHistory is an explicit alternative that re-encodes current argument objects as authored history, not original wire. It adds no persistence, tool execution authority, network default or retry. All other incremental delivery/permission/late-error boundaries are unchanged.
func RegisterKiroLiveTextModule ¶ added in v0.18.0
func RegisterKiroLiveTextModule(sourceID string, config KiroLiveTextConfig) error
RegisterKiroLiveTextModule opts into actual incremental text delivery. A late failure invalidates completion even if previews were already observed. Tools and unsupported host options fail closed; there is no buffered fallback or retry. This installs only an API module, not a model/provider or login flow. Use Stream/StreamSimple, not raw GetAPIModule callbacks, to retain host guards. sourceID owns UnregisterAPIModules cleanup; duplicate API registration panics.
func RegisterKiroLiveTextModuleWithOptions ¶ added in v0.18.0
func RegisterKiroLiveTextModuleWithOptions(sourceID string, config KiroLiveTextConfig, options KiroLiveTextOptions) error
RegisterKiroLiveTextModuleWithOptions preserves the strict original entry point. Options select behavior before any request; they never retry a partial stream.
func RegisterKiroSessionBufferedModule ¶ added in v0.18.0
func RegisterKiroSessionBufferedModule(sourceID string, config KiroBufferedConfig, affinity KiroSessionAffinity) error
RegisterKiroSessionBufferedModule explicitly enables nonempty host SessionID. Conversation IDs bind tenant/routing/profile/region/session using HMAC-SHA256; no session map, randomness, logging or implicit conversation reset. RequestIDs must supply invocation identity and either an empty or exactly matching conversation ID; conflicts fail before credentials/HTTP. Default registration still rejects SessionID. Scope/tenant labels are assertions, not verified IAM.
func RegisterLazyAPIModule ¶
func RegisterLazyAPIModule(api API, factory APIModuleFactory)
func RegisterLazyAPIModuleForSource ¶
func RegisterLazyAPIModuleForSource(sourceID string, api API, factory APIModuleFactory)
func RegisterLazyProviderModule ¶
func RegisterLazyProviderModule(provider Provider, factory ProviderModuleFactory)
func RegisterProviderModule ¶
func RegisterProviderModule(module ProviderModule)
func RegisterSessionResourceCleanup ¶
func RegisterSessionResourceCleanup(cleanup SessionResourceCleanup) func()
func RegisterSessionResourceCleanupOptional ¶
func RegisterSessionResourceCleanupOptional(cleanup SessionResourceCleanupOptional) func()
RegisterSessionResourceCleanupOptional registers a cleanup that does not require a sessionID. It wraps the cleanup so it can be stored alongside session-aware cleanups.
func RenderSystemMessageUpdate ¶
func RenderSystemMessageUpdate(message SystemMessage) string
func RequiresOAuth ¶
func ResolveAPIKey ¶
func ResolveAPIKey(provider Provider, auth map[Provider]AuthConfig) string
func ResolveAuthorization ¶
func ResolveCommandCodeAPIKey ¶
func ResolveCommandCodeAPIKey(auth map[Provider]AuthConfig) string
ResolveCommandCodeAPIKey follows pi-commandcode-provider v0.6.4's credential lookup after considering caller-supplied runtime auth. Explicit stream API keys are handled before this function by the transport.
func SerializeContext ¶
func SupportsHostedTool ¶
func SupportsHostedTool(model Model, toolType HostedToolType) bool
func SupportsMax ¶
func SupportsQuotaQuery ¶
SupportsQuotaQuery checks the provider registration without making a request.
func SupportsXHigh ¶
func UnregisterAPIModules ¶
func UnregisterAPIModules(sourceID string)
func ValidateResponseFormat ¶
func ValidateResponseFormat(model Model, format *ResponseFormat) error
func ValidateToolArguments ¶
Types ¶
type APIModule ¶
type APIModule struct {
API API
Stream APIStreamFunc
StreamSimple APISimpleStreamFunc
Capabilities ModelCapabilities
}
func GetAPIModule ¶
type APIModuleFactory ¶
type APIModuleFactory func() APIModule
type APIOptionValidation ¶ added in v0.18.0
type APIOptionValidation struct {
ValidateOptions func(Model, ProviderStreamOptions) error
ValidateSimpleOptions func(Model, SimpleStreamOptions) error
}
APIOptionValidation supplies optional pure/read-only preflight callbacks. Errors produce a fixed redacted failure. Validation is not execution permission.
type APISimpleStreamFunc ¶
type APISimpleStreamFunc func(Model, Context, SimpleStreamOptions) *AssistantMessageEventStream
type APIStreamFunc ¶
type APIStreamFunc func(Model, Context, ProviderStreamOptions) *AssistantMessageEventStream
type AnthropicMessagesCompat ¶
type AnthropicMessagesProviderOptions ¶
type AnthropicMessagesProviderOptions struct {
StreamOptions
}
type AssistantMessage ¶
type AssistantMessage struct {
Content []ContentBlock
HostedToolExecutions []HostedToolExecution
API API
Provider Provider
Model string
ResponseModel string
ResponseID string
ThinkingLevel ModelThinkingLevel
Usage Usage
UsageReported bool
StopReason StopReason
ErrorMessage string
Diagnostics []AssistantMessageDiagnostic
Timestamp time.Time
}
func Complete ¶
func Complete(model Model, ctx Context, options ProviderStreamOptions) AssistantMessage
func CompleteSimple ¶
func CompleteSimple(model Model, ctx Context, options SimpleStreamOptions) AssistantMessage
type AssistantMessageEvent ¶
type AssistantMessageEvent struct {
Type AssistantMessageEventType
ContentIndex int
Delta string
Content string
ToolCall ToolCall
Partial AssistantMessage
Reason StopReason
Message AssistantMessage
Error AssistantMessage
DroppedEvents int
}
type AssistantMessageEventStream ¶
type AssistantMessageEventStream struct {
// contains filtered or unexported fields
}
func Stream ¶
func Stream(model Model, ctx Context, options ProviderStreamOptions) *AssistantMessageEventStream
func StreamSimple ¶
func StreamSimple(model Model, ctx Context, options SimpleStreamOptions) *AssistantMessageEventStream
func (*AssistantMessageEventStream) Close ¶
func (s *AssistantMessageEventStream) Close()
Close cancels the owned provider request, discards unread events and waits for the event dispatcher to exit. It is safe to call concurrently and repeatedly. It does not fabricate a provider result or wait for provider/observer callbacks; Result still waits for the provider's final message and preserves its evidence.
func (*AssistantMessageEventStream) Events ¶
func (s *AssistantMessageEventStream) Events() <-chan AssistantMessageEvent
Events exposes the event channel. Consumers that stop early must Close the stream or cancel the RequestContext supplied to Stream/StreamSimple.
func (*AssistantMessageEventStream) Result ¶
func (s *AssistantMessageEventStream) Result() AssistantMessage
Result does not consume events. Events remain readable afterwards unless the stream was closed or its caller context was cancelled.
type AssistantMessageEventType ¶
type AssistantMessageEventType string
const ( AssistantMessageEventStart AssistantMessageEventType = "start" AssistantMessageEventTextStart AssistantMessageEventType = "text_start" AssistantMessageEventTextDelta AssistantMessageEventType = "text_delta" AssistantMessageEventTextEnd AssistantMessageEventType = "text_end" AssistantMessageEventThinkingStart AssistantMessageEventType = "thinking_start" AssistantMessageEventThinkingDelta AssistantMessageEventType = "thinking_delta" AssistantMessageEventThinkingEnd AssistantMessageEventType = "thinking_end" AssistantMessageEventToolCallStart AssistantMessageEventType = "toolcall_start" AssistantMessageEventToolCallDelta AssistantMessageEventType = "toolcall_delta" AssistantMessageEventToolCallEnd AssistantMessageEventType = "toolcall_end" AssistantMessageEventDone AssistantMessageEventType = "done" AssistantMessageEventError AssistantMessageEventType = "error" )
type AuthConfig ¶
type AuthConfig struct {
Type AuthType
APIKey string
OAuth *OAuthCredentials
// OnOAuthCredentialsRefreshed is called synchronously after OAuth
// credentials are refreshed. The callback owns any persistence. The
// refreshed credentials are passed by value, and the library does not
// mutate OAuth or the caller's auth map. Concurrent authorization calls
// may invoke the callback concurrently, so external storage must provide
// its own synchronization.
OnOAuthCredentialsRefreshed func(provider Provider, credentials OAuthCredentials)
}
type CacheRetention ¶
type CacheRetention string
type CapabilitySupport ¶
type CapabilitySupport string
CapabilitySupport describes whether pi-go can faithfully accept and dispatch a capability for a registered provider/model pair. A fixed, silently ignored, or otherwise non-configurable request parameter is unsupported. Unknown must be treated as unsupported by fail-closed consumers. These statuses describe the local adapter contract, not live upstream availability or authorization.
const ( CapabilityUnknown CapabilitySupport = "unknown" CapabilityUnsupported CapabilitySupport = "unsupported" CapabilitySupported CapabilitySupport = "supported" )
type CommandCodeCompat ¶
type CommandCodeCompat struct {
API API
}
CommandCodeCompat selects the public wire protocol advertised by model discovery. An empty API uses the provider's legacy name-based selection.
type CommandCodeModelsResult ¶
type CommandCodeModelsResult struct {
Models []Model
Source CommandCodeModelsSource
Warning string
}
CommandCodeModelsResult reports the catalog selected by the v0.4.3-compatible live/cache fallback. Warning is informational when Models remains usable.
func LoadCommandCodeModels ¶
func LoadCommandCodeModels(ctx context.Context, client *http.Client) CommandCodeModelsResult
LoadCommandCodeModels loads a live catalog and updates its cache. If live discovery fails, it uses the last valid v1 cache. A first offline load with no valid cache returns an empty catalog and a warning instead of failing.
func RefreshCommandCodeModelsWithResult ¶
func RefreshCommandCodeModelsWithResult(ctx context.Context, client *http.Client) (CommandCodeModelsResult, error)
RefreshCommandCodeModelsWithResult applies the v0.4.3-compatible live/cache result to the provider registry and preserves non-fatal warning details.
type CommandCodeModelsSource ¶
type CommandCodeModelsSource string
CommandCodeModelsSource identifies where the current catalog came from.
const ( CommandCodeModelsSourceLive CommandCodeModelsSource = "live" CommandCodeModelsSourceCache CommandCodeModelsSource = "cache" CommandCodeModelsSourceEmpty CommandCodeModelsSource = "empty" )
type CommonProviderOptions ¶
type CommonProviderOptions struct {
APIKey string
Auth map[Provider]AuthConfig
HTTPClient *http.Client
Headers map[string]string
MaxTokens int
Temperature *float64
Transport Transport
CacheRetention CacheRetention
SessionID string
OnPayload func(payload any, model Model) any
OnResponse func(response ProviderResponse, model Model)
OnProviderStreamEvent func(data json.RawMessage, model Model) error
ServiceTier string
TimeoutMs int
MaxRetries int
MaxRetryDelay int
Metadata map[string]any
RequestContext context.Context
PreviousResponseID string
Truncation string
Observer Observer
ResponseFormat *ResponseFormat
}
type ContentBlock ¶
type ContentBlock interface {
// contains filtered or unexported methods
}
type Context ¶
type Context struct {
SystemPrompt string
Messages []Message
Tools []Tool
HostedTools []HostedTool
}
func DeserializeContext ¶
func (Context) MarshalJSON ¶
func (*Context) UnmarshalJSON ¶
type DeepSeekProviderOptions ¶
type DeepSeekProviderOptions struct {
StreamOptions
}
type DiagnosticErrorInfo ¶
type GoogleProviderOptions ¶
type GoogleProviderOptions struct {
StreamOptions
ToolChoice string
Thinking *GoogleThinkingConfig
}
GoogleProviderOptions captures provider-specific options for the Google Generative AI (Gemini) provider.
type GoogleThinkingConfig ¶
type GoogleThinkingConfig struct {
Enabled bool
BudgetTokens int // -1 for dynamic, 0 to disable
Level string
}
GoogleThinkingConfig controls Gemini reasoning/thinking behavior.
type HTTPDelivery ¶
type HTTPDelivery string
HTTPDelivery describes transport evidence, not whether a model executed or billed. Unknown is intentional: a generic RoundTripper cannot prove non-delivery. Only the private standard transport used by a nil base client can prove not_sent.
type HTTPObservation ¶
type HTTPObservation struct {
Delivery HTTPDelivery
StatusCode int
ErrorType string
ErrorCode string
ErrorBodyTruncated bool
Err error
}
HTTPObservation describes one RoundTrip, not an entire redirect or retry sequence. Error identifiers are bounded. Err preserves the original error chain and must not be logged as trusted metadata. Redirect observations are delivered when their body finishes or is closed. A successful response is observed at headers and, if its body later fails to read, once more with the original read error. Observations are not attempt counts. Observe may run concurrently when the client is shared. A callback must be concurrency-safe.
type HTTPStreamClient ¶
type HTTPStreamClient struct {
HTTPClient *http.Client
MaxRetries int
BaseRetryDelay time.Duration
MaxRetryDelay time.Duration
}
HTTPStreamClient sends SSE-based POST requests with shared retry behavior.
type HandoffCredentials ¶
type HandoffCredentials struct {
Version int `json:"version"`
Providers map[Provider]HandoffProviderAuth `json:"providers"`
}
func HandoffCredentialsFromAuth ¶
func HandoffCredentialsFromAuth(auth map[Provider]AuthConfig) HandoffCredentials
func (HandoffCredentials) ToAuthConfigMap ¶
func (credentials HandoffCredentials) ToAuthConfigMap() map[Provider]AuthConfig
type HandoffOAuthCredentials ¶
type HandoffProviderAuth ¶
type HandoffProviderAuth struct {
Type AuthType `json:"type"`
APIKey string `json:"apiKey,omitempty"`
OAuth *HandoffOAuthCredentials `json:"oauth,omitempty"`
}
type HostedTool ¶
type HostedTool struct {
Type HostedToolType
Name string
}
type HostedToolCapabilities ¶
func (HostedToolCapabilities) Supports ¶
func (c HostedToolCapabilities) Supports(toolType HostedToolType) bool
type HostedToolExecution ¶
type HostedToolType ¶
type HostedToolType string
type ImageContent ¶
type KimiCodingProviderOptions ¶
type KimiCodingProviderOptions struct {
AnthropicMessagesProviderOptions
}
type KiroBufferedConfig ¶ added in v0.18.0
type KiroBufferedConfig struct {
API API
Provider Provider
Region, ProfileARN, Origin, UserAgent string
SystemPromptPolicy string
Schemas map[string]json.RawMessage
RequestIDs func(context.Context) (KiroRequestIDs, error)
Credentials func(context.Context, KiroCredentialScope) (KiroScopedCredential, error)
RoundTrip func(*http.Request) (*http.Response, error)
}
KiroBufferedConfig opts into a community-protocol, completed-response adapter. Callbacks are trusted, concurrency-safe and context-cooperative. No default network client, login, credentials, endpoint override, retry or tool execution. SystemPromptPolicy accepts "reject" (also the empty default) or the explicit semantic downgrade "prepend_first_user". Origin and UserAgent have no default.
type KiroBufferedOption ¶ added in v0.18.0
type KiroBufferedOption struct {
// contains filtered or unexported fields
}
KiroBufferedOption is a controlled opt-in, not an arbitrary callback. Its zero value is invalid. Secret-bearing affinity options redact fmt and JSON fields.
func WithKiroAutoHTTP ¶ added in v0.18.0
func WithKiroAutoHTTP() KiroBufferedOption
WithKiroAutoHTTP opts the Auto selector into the sole implemented injected HTTP path. It adds no WebSocket attempt, retry/fallback or default network client. Explicit WebSocket remains rejected. Delivery is buffered.
func WithKiroCallerAuthoredToolHistory ¶ added in v0.18.0
func WithKiroCallerAuthoredToolHistory() KiroBufferedOption
WithKiroCallerAuthoredToolHistory explicitly sends current argument objects as authored history, including precise restored values. It does not claim original provider wire provenance or populate RawArguments. Conflicting supplied raw evidence still rejects. Tool permission checks remain separate.
func WithKiroSessionAffinity ¶ added in v0.18.0
func WithKiroSessionAffinity(affinity KiroSessionAffinity) KiroBufferedOption
WithKiroSessionAffinity snapshots caller-owned key material at option creation. Registration validates and copies it again. No key generation or persistence.
func (KiroBufferedOption) GoString ¶ added in v0.18.0
func (KiroBufferedOption) GoString() string
func (KiroBufferedOption) String ¶ added in v0.18.0
func (KiroBufferedOption) String() string
type KiroCatalogFetchConfig ¶ added in v0.18.0
type KiroCatalogFetchConfig struct {
Scope KiroCredentialScope
Origin, UserAgent string
MaxBytes, MaxModels int
Clock func(context.Context) (time.Time, error)
Credentials func(context.Context, KiroCredentialScope) (KiroScopedCredential, error)
RoundTrip func(*http.Request) (*http.Response, error)
}
KiroCatalogFetchConfig explicitly injects every network/auth/clock boundary. Use keyed literals. No zero-value network/default scope/limits/clock exists. Callbacks must cooperate with context; RoundTrip must not retry or redirect. This is an explicit operation, never invoked by provider registration.
func (KiroCatalogFetchConfig) GoString ¶ added in v0.18.0
func (KiroCatalogFetchConfig) GoString() string
func (KiroCatalogFetchConfig) String ¶ added in v0.18.0
func (KiroCatalogFetchConfig) String() string
type KiroCatalogIDKind ¶ added in v0.18.0
type KiroCatalogIDKind = kiroCatalogIDKind
KiroCatalogIDKind requires the caller to distinguish alias from service ID.
type KiroCredentialKind ¶ added in v0.18.0
type KiroCredentialKind = kiroCredentialKind
KiroCredentialKind selects an explicit supported authentication header form.
type KiroCredentialScope ¶ added in v0.18.0
type KiroCredentialScope = kiroCredentialScope
KiroCredentialScope is asserted by the caller, not verified account ownership.
type KiroDesktopRefreshConfig ¶ added in v0.18.0
type KiroDesktopRefreshConfig struct {
Scope KiroCredentialScope
UserAgent string
RefreshToken string `json:"-"`
MaxRequestBytes, MaxResponseBytes int
MaxLifetime, RefreshSkew time.Duration
Clock func(context.Context) (time.Time, error)
RoundTrip func(*http.Request) (*http.Response, error)
}
KiroDesktopRefreshConfig requires caller-owned inputs and an explicit executor. Use keyed literals. Clock runs before dispatch and after successful Close; no default network, desktop/CLI login, source update, store or retry is installed. The community-observed endpoint is not an official third-party API guarantee.
func (KiroDesktopRefreshConfig) GoString ¶ added in v0.18.0
func (KiroDesktopRefreshConfig) GoString() string
func (KiroDesktopRefreshConfig) String ¶ added in v0.18.0
func (KiroDesktopRefreshConfig) String() string
type KiroDesktopRefreshError ¶ added in v0.18.0
type KiroDesktopRefreshError struct {
// contains filtered or unexported fields
}
KiroDesktopRefreshError carries no raw cause or secret. ExecutorInvoked reports control handoff only; true may hide server-side rotation and is not retry-safe.
func (*KiroDesktopRefreshError) Error ¶ added in v0.18.0
func (*KiroDesktopRefreshError) Error() string
func (*KiroDesktopRefreshError) ExecutorInvoked ¶ added in v0.18.0
func (e *KiroDesktopRefreshError) ExecutorInvoked() bool
type KiroDesktopRefreshResult ¶ added in v0.18.0
type KiroDesktopRefreshResult struct {
// contains filtered or unexported fields
}
KiroDesktopRefreshResult is an opaque in-memory observation, not stored account access. Explicit getters disclose copies of secret values; do not log them. Scope is asserted; a matching returned profile does not prove ownership.
func RefreshKiroDesktop ¶ added in v0.18.0
func RefreshKiroDesktop(ctx context.Context, config KiroDesktopRefreshConfig) (*KiroDesktopRefreshResult, error)
RefreshKiroDesktop makes at most one explicit executor invocation. Returned profileArn must match the asserted profile; true omission of refreshToken may retain the request token only after all success checks. Null/empty/error never fall back. Caller owns serialization of credential generations and must not redirect/retry/log inside the executor. Read/Close/clock cancellation is cooperative; plaintext buffers are not securely zeroized. No persistence.
func (KiroDesktopRefreshResult) Credential ¶ added in v0.18.0
func (r KiroDesktopRefreshResult) Credential() KiroScopedCredential
func (KiroDesktopRefreshResult) ExpiresAt ¶ added in v0.18.0
func (r KiroDesktopRefreshResult) ExpiresAt() time.Time
func (KiroDesktopRefreshResult) GoString ¶ added in v0.18.0
func (KiroDesktopRefreshResult) GoString() string
func (KiroDesktopRefreshResult) RefreshAfter ¶ added in v0.18.0
func (r KiroDesktopRefreshResult) RefreshAfter() time.Time
func (KiroDesktopRefreshResult) RefreshToken ¶ added in v0.18.0
func (r KiroDesktopRefreshResult) RefreshToken() string
func (KiroDesktopRefreshResult) RetainedRefreshToken ¶ added in v0.18.0
func (r KiroDesktopRefreshResult) RetainedRefreshToken() bool
RetainedRefreshToken is provenance, not a continuing-validity guarantee.
func (KiroDesktopRefreshResult) String ¶ added in v0.18.0
func (KiroDesktopRefreshResult) String() string
type KiroIDCRefreshConfig ¶ added in v0.18.0
type KiroIDCRefreshConfig struct {
Scope KiroCredentialScope
UserAgent string
ClientID string `json:"-"`
ClientSecret string `json:"-"`
RefreshToken string `json:"-"`
MaxRequestBytes, MaxResponseBytes int
MaxLifetime, RefreshSkew time.Duration
Clock func(context.Context) (time.Time, error)
RoundTrip func(*http.Request) (*http.Response, error)
}
KiroIDCRefreshConfig is explicitly caller-owned; use keyed literals. No zero- value client, scope, clock, credential, budget, retry or persistence exists. The executor MUST NOT retry, redirect or log secrets and must honor context. Clock is called before dispatch and after successful Close (up to twice); expiry is anchored conservatively before dispatch, never extended by Close. Client credentials must already be authorized; this does not register/login.
func (KiroIDCRefreshConfig) GoString ¶ added in v0.18.0
func (KiroIDCRefreshConfig) GoString() string
func (KiroIDCRefreshConfig) String ¶ added in v0.18.0
func (KiroIDCRefreshConfig) String() string
type KiroIDCRefreshError ¶ added in v0.18.0
type KiroIDCRefreshError struct {
// contains filtered or unexported fields
}
KiroIDCRefreshError exposes only whether this helper invoked the executor. True is NOT proof bytes were sent, nor that they were not: the server may have rotated tokens even if the response/read/Close/parser subsequently failed. Never treat this flag as automatic retry permission. No raw cause is retained.
func (*KiroIDCRefreshError) Error ¶ added in v0.18.0
func (*KiroIDCRefreshError) Error() string
func (*KiroIDCRefreshError) ExecutorInvoked ¶ added in v0.18.0
func (e *KiroIDCRefreshError) ExecutorInvoked() bool
type KiroIDCRefreshOption ¶ added in v0.18.0
type KiroIDCRefreshOption struct {
// contains filtered or unexported fields
}
KiroIDCRefreshOption is a controlled policy, not an arbitrary callback. Its zero value is invalid. Existing config layout and strict entry are unchanged.
func WithKiroIDCRetainMissingRefreshToken ¶ added in v0.18.0
func WithKiroIDCRetainMissingRefreshToken() KiroIDCRefreshOption
WithKiroIDCRetainMissingRefreshToken permits retaining only the exact request token when a fully validated successful response OMITS refreshToken. It never handles null/empty values, failures or unknown rotation outcomes as retention.
type KiroIDCRefreshResult ¶ added in v0.18.0
type KiroIDCRefreshResult struct {
// contains filtered or unexported fields
}
KiroIDCRefreshResult holds an immutable in-memory observation, not persisted credentials or authenticated account ownership. JSON/fmt do not expose secrets. Explicit getters return secrets by value: callers must not log or persist them accidentally. This package neither updates nor caches a credential source.
func RefreshKiroIDC ¶ added in v0.18.0
func RefreshKiroIDC(ctx context.Context, config KiroIDCRefreshConfig) (*KiroIDCRefreshResult, error)
RefreshKiroIDC performs one explicitly injected attempt; no default network or implicit retry exists. Its response is released only after full HTTP/Close and strict parsing checks. A failure after executor invocation has an indeterminate server-side rotation outcome. Required returned rotation is a conservative subset: an otherwise valid response omitting refreshToken is rejected. Scope and clock are caller assertions. Real service compatibility is not guaranteed.
func RefreshKiroIDCWithOptions ¶ added in v0.18.0
func RefreshKiroIDCWithOptions(ctx context.Context, config KiroIDCRefreshConfig, options ...KiroIDCRefreshOption) (*KiroIDCRefreshResult, error)
RefreshKiroIDCWithOptions leaves no-option behavior strict. At most one valid option is accepted before any clock/executor callback. Caller must serialize refreshes per credential generation; there is no source lock/store or retry.
func (KiroIDCRefreshResult) Credential ¶ added in v0.18.0
func (r KiroIDCRefreshResult) Credential() KiroScopedCredential
func (KiroIDCRefreshResult) ExpiresAt ¶ added in v0.18.0
func (r KiroIDCRefreshResult) ExpiresAt() time.Time
func (KiroIDCRefreshResult) GoString ¶ added in v0.18.0
func (KiroIDCRefreshResult) GoString() string
func (KiroIDCRefreshResult) RefreshAfter ¶ added in v0.18.0
func (r KiroIDCRefreshResult) RefreshAfter() time.Time
func (KiroIDCRefreshResult) RefreshToken ¶ added in v0.18.0
func (r KiroIDCRefreshResult) RefreshToken() string
func (KiroIDCRefreshResult) RetainedRefreshToken ¶ added in v0.18.0
func (r KiroIDCRefreshResult) RetainedRefreshToken() bool
RetainedRefreshToken reports successful omission-policy retention, not proof the old token remains valid. An explicit returned token, even identical, is false.
func (KiroIDCRefreshResult) String ¶ added in v0.18.0
func (KiroIDCRefreshResult) String() string
type KiroIncrementalConfig ¶ added in v0.18.0
type KiroIncrementalConfig KiroBufferedConfig
KiroIncrementalConfig has the explicit request/auth/schema fields of KiroBufferedConfig but selects live text and completed-only tool events. It is a distinct type: buffered callers never change behavior implicitly. Schemas are an exact raw catalog, not permission to execute declared tools.
type KiroIncrementalOptions ¶ added in v0.18.0
type KiroIncrementalOptions KiroLiveTextOptions
KiroIncrementalOptions opts Auto into injected HTTP and/or explicit scoped sessions. Zero options reject Auto and nonempty SessionID. Keys are copied.
type KiroLiveTextConfig ¶ added in v0.18.0
type KiroLiveTextConfig struct {
API API
Provider Provider
Region, ProfileARN, Origin, UserAgent string
SystemPromptPolicy string
RequestIDs func(context.Context) (KiroRequestIDs, error)
Credentials func(context.Context, KiroCredentialScope) (KiroScopedCredential, error)
RoundTrip func(*http.Request) (*http.Response, error)
}
KiroLiveTextConfig explicitly selects provisional live text, not buffered delivery. It intentionally has no tool catalog, session or Auto option. Trusted callbacks must cooperate with context. No default network client is installed. SystemPromptPolicy has the same explicit downgrade semantics as buffered mode.
type KiroLiveTextOptions ¶ added in v0.18.0
type KiroLiveTextOptions struct {
AutoHTTP bool
SessionAffinity *KiroSessionAffinity
}
KiroLiveTextOptions explicitly selects HTTP for Auto and/or session affinity. Nil affinity keeps SessionID rejected. No fallback, retry or default client. Affinity key material is validated and copied during registration.
type KiroModelCatalog ¶ added in v0.18.0
type KiroModelCatalog struct {
// contains filtered or unexported fields
}
KiroModelCatalog is an immutable caller-scoped observation, NOT entitlement, a Model registry, cache or serializable persisted catalog. Its zero value fails selection. Models/Select return detached observations; no public mutable fields.
func FetchKiroModelCatalog ¶ added in v0.18.0
func FetchKiroModelCatalog(ctx context.Context, config KiroCatalogFetchConfig) (*KiroModelCatalog, error)
FetchKiroModelCatalog calls only the explicit credentials/executor/clock once each where reached. It returns no observation until status/JSON/length/EOF/Close validate. It neither installs models/providers nor discovers profiles, chooses a default model, reads tokens, logs data, retries or grants service permission.
func (KiroModelCatalog) GoString ¶ added in v0.18.0
func (KiroModelCatalog) GoString() string
func (*KiroModelCatalog) Models ¶ added in v0.18.0
func (c *KiroModelCatalog) Models(scope KiroCredentialScope, now time.Time, maxAge time.Duration) ([]KiroModelObservation, error)
Models requires matching asserted scope and an explicit freshness policy. At maxAge the observation is stale. No capability/price/default inference.
func (*KiroModelCatalog) Select ¶ added in v0.18.0
func (c *KiroModelCatalog) Select(scope KiroCredentialScope, kind KiroCatalogIDKind, id string, now time.Time, maxAge time.Duration) (KiroModelObservation, error)
Select uses an explicit ID namespace; overlapping alias/service strings must never be guessed. The returned ServiceID is exact request-time evidence, not a runnable host Model. Scope/time are assertions, not authenticated provenance.
func (KiroModelCatalog) String ¶ added in v0.18.0
func (KiroModelCatalog) String() string
type KiroModelObservation ¶ added in v0.18.0
type KiroModelObservation struct {
// contains filtered or unexported fields
}
KiroModelObservation has immutable private state. Unknown limits remain absent. Raw getters explicitly expose detached potentially sensitive metadata: do not indiscriminately log or interpret schemas as capabilities/account authorization.
func (KiroModelObservation) Alias ¶ added in v0.18.0
func (m KiroModelObservation) Alias() string
func (KiroModelObservation) DisplayName ¶ added in v0.18.0
func (m KiroModelObservation) DisplayName() string
func (KiroModelObservation) GoString ¶ added in v0.18.0
func (KiroModelObservation) GoString() string
func (KiroModelObservation) MaxInputTokens ¶ added in v0.18.0
func (m KiroModelObservation) MaxInputTokens() (int64, bool)
func (KiroModelObservation) MaxOutputTokens ¶ added in v0.18.0
func (m KiroModelObservation) MaxOutputTokens() (int64, bool)
func (KiroModelObservation) RawMetadata ¶ added in v0.18.0
func (m KiroModelObservation) RawMetadata() json.RawMessage
func (KiroModelObservation) RequestFieldsSchema ¶ added in v0.18.0
func (m KiroModelObservation) RequestFieldsSchema() json.RawMessage
func (KiroModelObservation) ServiceID ¶ added in v0.18.0
func (m KiroModelObservation) ServiceID() string
func (KiroModelObservation) String ¶ added in v0.18.0
func (KiroModelObservation) String() string
type KiroRequestIDs ¶ added in v0.18.0
type KiroRequestIDs struct{ ConversationID, InvocationID string }
KiroRequestIDs are supplied per attempt. The caller owns conversation affinity and invocation uniqueness; this package neither generates nor persists IDs.
type KiroScopedCredential ¶ added in v0.18.0
type KiroScopedCredential = kiroScopedCredential
KiroScopedCredential contains a secret. Its JSON/String forms redact Token, but the executor receives secret headers and must never log them.
type KiroSessionAffinity ¶ added in v0.18.0
KiroSessionAffinity is explicit caller-owned tenant/session isolation material. Key must contain 32..64 bytes of caller-managed secret entropy. It is copied at registration, not generated or persisted by this package. Key rotation changes all derived conversations. No memory zeroization guarantee is made.
func (KiroSessionAffinity) GoString ¶ added in v0.18.0
func (KiroSessionAffinity) GoString() string
func (KiroSessionAffinity) String ¶ added in v0.18.0
func (KiroSessionAffinity) String() string
type LoggingObserver ¶
type LoggingObserver struct {
// contains filtered or unexported fields
}
func NewLoggingObserver ¶
func NewLoggingObserver(logger *slog.Logger, level slog.Level) *LoggingObserver
func (*LoggingObserver) OnRequestComplete ¶
func (o *LoggingObserver) OnRequestComplete(ctx context.Context, model Model, result AssistantMessage, duration time.Duration)
func (*LoggingObserver) OnRequestError ¶
func (*LoggingObserver) OnRequestStart ¶
func (*LoggingObserver) OnStreamEvent ¶
func (o *LoggingObserver) OnStreamEvent(_ context.Context, _ Model, _ AssistantMessageEvent)
func (*LoggingObserver) OnStreamFinish ¶
func (o *LoggingObserver) OnStreamFinish(ctx context.Context, model Model, _ AssistantMessage, eventCount int, droppedCount int, duration time.Duration)
type Message ¶
type Message interface {
// contains filtered or unexported methods
}
func TransformMessages ¶
type MessageTransformer ¶
type MistralProviderOptions ¶
type MistralProviderOptions struct {
StreamOptions
ToolChoice string
PromptMode string
ReasoningEffort string
}
MistralProviderOptions captures provider-specific options for the Mistral API.
type Model ¶
type Model struct {
ID string
Name string
API API
Provider Provider
BaseURL string
Reasoning bool
ThinkingLevelMap ThinkingLevelMap
SamplingParams SamplingParams
SamplingParamsByThinkingLevel SamplingParamsByThinkingLevel
Capabilities ModelCapabilities
Input []InputType
HostedTools HostedToolCapabilities
Cost UsageCost
CostTiers []ModelCostTier
ContextWindow int
MaxTokens int
Headers map[string]string
Compat ProviderCompat
}
func FetchCommandCodeModels ¶
FetchCommandCodeModels reads the current Provider API catalog without mutating the provider registry. COMMANDCODE_MODELS_URL and COMMANDCODE_API_BASE match pi-commandcode-provider's endpoint overrides.
func RefreshCommandCodeModels ¶
RefreshCommandCodeModels replaces the registered Command Code catalog. It accepts a valid cached catalog as a successful refresh and keeps the legacy error return for a first offline load with no usable catalog.
type ModelCapabilities ¶
type ModelCapabilities struct {
Streaming CapabilitySupport `json:"streaming"`
Tools CapabilitySupport `json:"tools"`
// Native custom input and Lark/regex grammars are model-only facts. API and
// provider defaults never grant these capabilities to an entire catalog.
CustomTools CapabilitySupport `json:"custom_tools"`
GrammarTools CapabilitySupport `json:"grammar_tools"`
// ToolAdditions permits position-anchored function declarations on Responses.
// Like custom tools, it is granted only by exact registered model facts.
ToolAdditions CapabilitySupport `json:"tool_additions"`
StrictTools CapabilitySupport `json:"strict_tools"`
ToolChoice CapabilitySupport `json:"tool_choice"`
Reasoning CapabilitySupport `json:"reasoning"`
ReasoningLevels CapabilitySupport `json:"reasoning_levels"`
SupportedReasoningLevels []ModelThinkingLevel `json:"supported_reasoning_levels,omitempty"`
DefaultReasoningLevel ModelThinkingLevel `json:"default_reasoning_level,omitempty"`
Temperature CapabilitySupport `json:"temperature"`
TemperatureReasoningLevels []ModelThinkingLevel `json:"temperature_reasoning_levels,omitempty"`
TopP CapabilitySupport `json:"top_p"`
TopPReasoningLevels []ModelThinkingLevel `json:"top_p_reasoning_levels,omitempty"`
ParallelToolCalls CapabilitySupport `json:"parallel_tool_calls"`
}
ModelCapabilities contains model-contract facts. On APIModule, ProviderModule.ModelCapabilities, and Model.Capabilities, empty fields mean unspecified and later registry layers may refine them. Lookup snapshots normalize every status to unknown, unsupported, or supported. For a reasoning model, sampling support is only actionable at the listed reasoning levels; a supported sampling field without such a list normalizes to unknown.
type ModelCapabilitySnapshot ¶
type ModelCapabilitySnapshot struct {
Provider Provider `json:"provider"`
ModelID string `json:"model_id"`
WireAPI API `json:"wire_api"`
BaseURL string `json:"base_url"`
Input []InputType `json:"input,omitempty"`
ContextWindow int `json:"context_window,omitempty"`
MaxOutputTokens int `json:"max_output_tokens,omitempty"`
Capabilities ModelCapabilities `json:"capabilities"`
ResponseFormats ResponseFormatCapabilities `json:"response_formats"`
HostedTools []HostedToolType `json:"hosted_tools,omitempty"`
}
ModelCapabilitySnapshot is an immutable-by-convention copy of the current registry facts for one provider/model pair.
func LookupModelCapabilities ¶
func LookupModelCapabilities(provider Provider, modelID string) (ModelCapabilitySnapshot, bool)
LookupModelCapabilities returns the current capability facts for an exact registered provider/model pair. It returns false for an unknown provider or model; callers must not fall back to model-name inference.
type ModelCostTier ¶
type ModelThinkingLevel ¶
type ModelThinkingLevel string
func ClampThinkingLevel ¶
func ClampThinkingLevel(model Model, level ModelThinkingLevel) ModelThinkingLevel
func GetSupportedThinkingLevels ¶
func GetSupportedThinkingLevels(model Model) []ModelThinkingLevel
type OAuthCredentials ¶
type Observer ¶
type Observer interface {
RequestObserver
StreamObserver
}
type OpenAICodexProviderOptions ¶
type OpenAICodexProviderOptions struct {
StreamOptions
}
type OpenAICompletionsCompat ¶
type OpenAICompletionsCompat struct {
SupportsMidConvoSystemMessages *bool
SupportsStore *bool
SupportsDeveloperRole *bool
SupportsReasoningEffort *bool
SupportsUsageInStreaming *bool
MaxTokensField string
RequiresToolResultName *bool
RequiresAssistantAfterToolResult *bool
RequiresThinkingAsText *bool
RequiresReasoningContentOnAssistantMessages *bool
ThinkingFormat string
OpenRouterRouting *OpenRouterRouting
VercelGatewayRouting *VercelGatewayRouting
ZaiToolStream *bool
SupportsStrictMode *bool
CacheControlFormat string
SendSessionAffinityHeaders *bool
SupportsLongCacheRetention *bool
}
type OpenAICompletionsProviderOptions ¶
type OpenAICompletionsProviderOptions struct {
StreamOptions
}
type OpenAIResponsesCompat ¶
type OpenAIResponsesProviderOptions ¶
type OpenAIResponsesProviderOptions struct {
StreamOptions
}
type OpenRouterRouting ¶
type Option ¶
type Option func(*StreamOptions)
Option mutates StreamOptions when constructing new option sets.
func WithMaxTokens ¶
WithMaxTokens sets the shared max token limit on StreamOptions.
func WithParallelToolCalls ¶
WithParallelToolCalls controls whether providers may issue tool calls in parallel.
func WithResponseFormat ¶
func WithResponseFormat(format ResponseFormat) Option
WithResponseFormat requests provider-neutral structured text output.
func WithTemperature ¶
WithTemperature sets the shared temperature field on StreamOptions.
func WithToolChoice ¶
WithToolChoice sets the provider-specific tool choice field on StreamOptions.
type ProviderAuth ¶
type ProviderAuth struct {
RequiresOAuth bool
EnvAPIKeyName string
EnvAPIKeyNames []string
ResolveAuthorization ProviderAuthResolveFunc
}
type ProviderAuthResolveFunc ¶
type ProviderCapabilities ¶
type ProviderCapabilities struct {
SupportsStreaming bool
SupportsJSONOutput bool
SupportsJSONSchema bool
SupportsSession bool
SupportsPromptCacheKey bool
SupportsPromptCacheControl bool
SupportsReasoningSummary bool
SupportsTextVerbosity bool
SupportsThinkingBudget bool
SupportsToolChoice bool
HostedTools HostedToolCapabilities
}
func GetProviderCapabilities ¶
func GetProviderCapabilities(provider Provider) ProviderCapabilities
type ProviderCapabilitySnapshot ¶
type ProviderCapabilitySnapshot struct {
Provider Provider `json:"provider"`
Models []ModelCapabilitySnapshot `json:"models"`
}
ProviderCapabilitySnapshot is a deterministic, point-in-time copy of one provider module's registered model capabilities.
func SnapshotProviderModelCapabilities ¶
func SnapshotProviderModelCapabilities(provider Provider) (ProviderCapabilitySnapshot, bool)
SnapshotProviderModelCapabilities returns a sorted point-in-time snapshot of a registered provider. Replacing a dynamic catalog never mutates a previously returned snapshot.
type ProviderCompat ¶
type ProviderCompat interface {
// contains filtered or unexported methods
}
ProviderCompat describes provider-specific model compatibility metadata.
type ProviderFailure ¶
type ProviderFailure struct {
Kind string
Reason string
Message string
// Code and Type retain decoded OpenAI Responses error fields when present.
// Empty values also cover other protocols and older stored diagnostics.
Code string
Type string
}
ProviderFailure is diagnostic evidence, never permission to retry. Message is untrusted provider/SDK text. Code and Type are also untrusted provider values, not retry authorization. These fields can contain private data; do not expose them in a public API or an unrestricted log.
func ProviderFailureOf ¶
func ProviderFailureOf(message AssistantMessage) (ProviderFailure, bool)
ProviderFailureOf returns the final classified failure without interpreting error text. The existing message diagnostics survive cloning and JSON storage.
type ProviderHTTPPolicy ¶
type ProviderHTTPPolicy struct {
// Non-positive limits use DefaultMaxProviderErrorBytes.
MaxErrorBodyBytes int64
Observe func(HTTPObservation)
}
type ProviderModule ¶
type ProviderModule struct {
Provider Provider
Models map[string]Model
Auth ProviderAuth
Quota QuotaQuerier
Capabilities ProviderCapabilities
ModelCapabilities ModelCapabilities
BuildOptions ProviderOptionsBuildFunc
NormalizeOptions ProviderOptionsNormalizeFunc
}
type ProviderModuleFactory ¶
type ProviderModuleFactory func() ProviderModule
type ProviderOptionsBuildFunc ¶
type ProviderOptionsBuildFunc func(Model, SimpleStreamOptions) ProviderStreamOptions
type ProviderOptionsNormalizeFunc ¶
type ProviderOptionsNormalizeFunc func(Model, ProviderStreamOptions) ProviderStreamOptions
type ProviderResponse ¶
type ProviderStreamOptions
deprecated
type ProviderStreamOptions struct {
APIKey string
Auth map[Provider]AuthConfig
HTTPClient *http.Client
Headers map[string]string
MaxTokens int
Temperature *float64
TopP *float64
SamplingParams SamplingParams
ParallelToolCalls *bool
Transport Transport
CacheRetention CacheRetention
SessionID string
OnPayload func(payload any, model Model) any
OnResponse func(response ProviderResponse, model Model)
OnProviderStreamEvent func(data json.RawMessage, model Model) error
ServiceTier string
TimeoutMs int
MaxRetries int
MaxRetryDelay int
Metadata map[string]any
RequestContext context.Context
Reasoning ThinkingLevel
ReasoningSummary string
TextVerbosity string
ThinkingBudgetTokens int
ThinkingBudgets ThinkingBudgets
ToolChoice string
PreviousResponseID string
Truncation string
Observer Observer
ResponseFormat *ResponseFormat
}
Deprecated: use StreamOptions with StreamOptions.providerStreamOptions instead.
func BuildProviderStreamOptions ¶
func BuildProviderStreamOptions(model Model, options SimpleStreamOptions) ProviderStreamOptions
func NormalizeProviderStreamOptions ¶
func NormalizeProviderStreamOptions(model Model, options ProviderStreamOptions) ProviderStreamOptions
type QuotaBalance ¶
type QuotaBalance struct {
ID string `json:"id"`
Unit string `json:"unit"`
Total *float64 `json:"total,omitempty"`
Used *float64 `json:"used,omitempty"`
Remaining *float64 `json:"remaining,omitempty"`
}
QuotaBalance describes one credit pool. Unit is provider-defined, such as USD or tokens; amounts in different units must not be combined.
type QuotaIssue ¶
type QuotaIssue struct {
Section string `json:"section"`
Message string `json:"message"`
HTTPStatus int `json:"httpStatus,omitempty"`
}
QuotaIssue identifies an unavailable section of an otherwise usable snapshot. Messages must not contain credentials, response bodies, or account identities.
type QuotaQuerier ¶
type QuotaQuerier interface {
QueryQuota(context.Context, QuotaQueryOptions) (QuotaResult, error)
}
QuotaQuerier is an optional account capability on ProviderModule. It must be safe for concurrent calls and must not invoke a model or mutate account state. Implementations return unavailable sections explicitly, never as zero usage.
type QuotaQueryError ¶
QuotaQueryError preserves status and cancellation without exposing raw upstream responses. Authentication failures and invalid required responses are fatal.
func (*QuotaQueryError) Error ¶
func (e *QuotaQueryError) Error() string
func (*QuotaQueryError) Unwrap ¶
func (e *QuotaQueryError) Unwrap() error
type QuotaQueryOptions ¶
type QuotaQueryOptions struct {
APIKey string
Auth map[Provider]AuthConfig
BaseURL string
HTTPClient *http.Client
}
QuotaQueryOptions is account-scoped, independent of model generation options. APIKey overrides Auth. Providers may use their normal local credential lookup when neither is supplied. BaseURL is an explicit, trusted account API override.
type QuotaResult ¶
type QuotaResult struct {
Provider Provider `json:"provider"`
QueriedAt time.Time `json:"queriedAt"`
Balances []QuotaBalance `json:"balances"`
Windows []QuotaWindow `json:"windows"`
Subscription *QuotaSubscription `json:"subscription,omitempty"`
}
QuotaResult is a live snapshot. Balances and window headroom are independent constraints and must not be added together. A nil amount or timestamp means unknown; a non-nil zero amount means a known normalized zero.
func QueryQuota ¶
func QueryQuota(ctx context.Context, provider Provider, options QuotaQueryOptions) (QuotaResult, error)
QueryQuota dispatches through the provider's optional account query interface. It does not refresh models, retry, cache, or make model-generation requests. Callers can set a deadline; otherwise the complete query is bounded to 15s.
type QuotaSubscription ¶
type QuotaWindow ¶
type QuotaWindow struct {
// BalanceIDs identifies the pools affected by this window. Nil means the
// provider did not report a pool scope; it does not mean all balances.
BalanceIDs []string `json:"balanceIds,omitempty"`
ID string `json:"id"`
Unit string `json:"unit"`
Limit *float64 `json:"limit,omitempty"`
Used *float64 `json:"used,omitempty"`
Remaining *float64 `json:"remaining,omitempty"`
ResetsAt *time.Time `json:"resetsAt,omitempty"`
}
QuotaWindow describes a rate or spending window, not an additional balance.
type Registry ¶
type Registry[K comparable, V any] struct { // contains filtered or unexported fields }
Registry stores static values or lazy factories behind a concurrency-safe key lookup.
func NewRegistry ¶
func NewRegistry[K comparable, V any]() *Registry[K, V]
NewRegistry creates an empty concurrency-safe registry.
func (*Registry[K, V]) Delete ¶
func (r *Registry[K, V]) Delete(key K)
Delete removes a key without resolving any lazy entry.
func (*Registry[K, V]) Keys ¶
func (r *Registry[K, V]) Keys() []K
Keys lists the currently registered keys without forcing lazy factories to resolve.
func (*Registry[K, V]) Register ¶
func (r *Registry[K, V]) Register(key K, value *V, factory func() V)
Register adds a static value or lazy factory for a key.
func (*Registry[K, V]) Replace ¶
Replace swaps an existing entry for a resolved value without exposing a partially updated value to concurrent readers. It returns false when the key is not registered.
func (*Registry[K, V]) Resolve ¶
func (r *Registry[K, V]) Resolve(key K) *V
Resolve returns a cached value for a key, materializing its lazy factory at most once.
func (*Registry[K, V]) SetResolveHook ¶
func (r *Registry[K, V]) SetResolveHook(hook func(K))
SetResolveHook installs a callback invoked when a lazy entry resolves.
type RequestObserver ¶
type ResponseFormat ¶
type ResponseFormat struct {
Type ResponseFormatType
Name string
JSONSchema json.RawMessage
Strict bool
}
ResponseFormat expresses provider-neutral structured text output. JSONSchema is required for json_schema and omitted for json_object.
type ResponseFormatCapabilities ¶
type ResponseFormatCapabilities struct {
JSONObject CapabilitySupport `json:"json_object"`
JSONSchema CapabilitySupport `json:"json_schema"`
}
ResponseFormatCapabilities describes the structured-output formats accepted by pi-go's public ResponseFormat contract for a concrete model.
type ResponseFormatType ¶
type ResponseFormatType string
const ( ResponseFormatJSON ResponseFormatType = "json_object" ResponseFormatJSONSchema ResponseFormatType = "json_schema" )
type SamplingParams ¶
SamplingParams contains JSON sampling fields for OpenAI Completions and Responses. These fields override the named request fields, including zero values. Protocol controls (model, reasoning, tools, stream, etc.) are not sampling fields and are rejected; use the corresponding request options instead.
type SamplingParamsByThinkingLevel ¶
type SamplingParamsByThinkingLevel map[ModelThinkingLevel]SamplingParams
SamplingParamsByThinkingLevel selects overrides by the effective pi thinking level, before that level is translated to a provider's wire value.
type SessionResourceCleanup ¶
type SessionResourceCleanup func(sessionID string)
type SessionResourceCleanupOptional ¶
type SessionResourceCleanupOptional func()
SessionResourceCleanupOptional is the variant that allows omitting sessionID. Use this when registering cleanups that do not need a session identifier.
type SimpleStreamOptions
deprecated
type SimpleStreamOptions struct {
APIKey string
Auth map[Provider]AuthConfig
HTTPClient *http.Client
Headers map[string]string
MaxTokens int
Temperature *float64
TopP *float64
SamplingParams SamplingParams
ParallelToolCalls *bool
Transport Transport
CacheRetention CacheRetention
SessionID string
OnPayload func(payload any, model Model) any
OnResponse func(response ProviderResponse, model Model)
OnProviderStreamEvent func(data json.RawMessage, model Model) error
ServiceTier string
TimeoutMs int
MaxRetries int
MaxRetryDelay int
Metadata map[string]any
RequestContext context.Context
Reasoning ThinkingLevel
ThinkingBudgets ThinkingBudgets
PreviousResponseID string
Truncation string
Observer Observer
ResponseFormat *ResponseFormat
}
Deprecated: use StreamOptions with streamOptionsFromSimple or NewStreamOptions instead.
type StopReason ¶
type StopReason string
type StreamObserver ¶
type StreamOptions ¶
type StreamOptions struct {
// Common remains as a legacy compatibility snapshot. Flat fields are the
// authoritative state and Common is rebuilt from them at conversion boundaries.
Common CommonProviderOptions
// Legacy flat common fields remain the direct access path for callers.
APIKey string
Auth map[Provider]AuthConfig
HTTPClient *http.Client
Headers map[string]string
MaxTokens int
Temperature *float64
TopP *float64
SamplingParams SamplingParams
ParallelToolCalls *bool
Transport Transport
CacheRetention CacheRetention
SessionID string
OnPayload func(payload any, model Model) any
OnResponse func(response ProviderResponse, model Model)
// OnProviderStreamEvent observes valid provider JSON events before normalization.
// The data is an isolated copy; returning an error stops the request without retry.
OnProviderStreamEvent func(data json.RawMessage, model Model) error
ServiceTier string
TimeoutMs int
MaxRetries int
MaxRetryDelay int
Metadata map[string]any
RequestContext context.Context
Reasoning ThinkingLevel
ReasoningSummary string
TextVerbosity string
ThinkingBudgetTokens int
ToolChoice string
PreviousResponseID string
Truncation string
ThinkingBudgets ThinkingBudgets
Observer Observer
ResponseFormat *ResponseFormat
}
func NewStreamOptions ¶
func NewStreamOptions(options ...Option) StreamOptions
NewStreamOptions builds StreamOptions from functional options.
type SystemMessage ¶
type SystemMessage struct {
Content string
Sections map[string]*string
ToolsAdded []Tool
ToolsRemoved []ToolReference
Timestamp time.Time
}
SystemMessage records instruction and tool state changes at their position in a transcript. Later content appends instructions; a nil section removes it. Section names are rendered in sorted order to keep Go map iteration stable.
func CreateInitialSystemMessage ¶
func CreateInitialSystemMessage(systemPrompt string, tools []Tool) *SystemMessage
func GetCurrentSystemMessage ¶
func GetCurrentSystemMessage(messages []Message) *SystemMessage
func GetInitialSystemMessage ¶
func GetInitialSystemMessage(messages []Message) *SystemMessage
type TextContent ¶
type TextSignatureV1 ¶
type ThinkingBudgets ¶
ThinkingBudgets overrides individual reasoning budgets. Zero-valued fields leave the provider's default budget unchanged.
func (ThinkingBudgets) ForLevel ¶
func (b ThinkingBudgets) ForLevel(level ThinkingLevel) int
func (ThinkingBudgets) IsEmpty ¶
func (b ThinkingBudgets) IsEmpty() bool
type ThinkingContent ¶
type ThinkingLevel ¶
type ThinkingLevel string
type ThinkingLevelMap ¶
type ThinkingLevelMap map[ModelThinkingLevel]string
type Tool ¶
type Tool struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
Parameters any `json:"parameters,omitempty"`
OutputSchema any `json:"outputSchema,omitempty"`
Validator ToolArgumentsValidator `json:"-"`
ConstrainedSampling *ToolConstrainedSampling `json:"constrainedSampling,omitempty"`
}
func GetCurrentTools ¶
GetCurrentTools replays removal before addition. Updating an existing name preserves its position; removing and adding it later appends it to the end.
func ToToolDeclaration ¶
type ToolArgumentsValidator ¶
type ToolCall ¶
type ToolCall struct {
ID string
Name string
// Namespace is provider replay metadata, not a local tool routing key.
Namespace string
Arguments map[string]any
// RawArguments is the original JSON object text when the provider exposes
// it. It is available on completed calls from Responses, OpenAI chat
// completions, DeepSeek chat, Anthropic Messages and Command Code. Unlike Arguments, it
// preserves exact number literals and duplicate keys. It is ephemeral
// provider evidence and is not part of serialized conversation history.
RawArguments string `json:"-"`
ThoughtSignature string
}
type ToolConstrainedSampling ¶
type ToolConstrainedSampling struct {
Type string `json:"type"`
Mode string `json:"mode,omitempty"`
Syntax string `json:"syntax,omitempty"`
Definition string `json:"definition,omitempty"`
}
ToolConstrainedSampling opts a single-string object tool into a native custom input. Type is "text" or "grammar"; grammar requires Syntax ("lark" or "regex") and Definition. Mode is "prefer" (the default) or "require". Prefer selects an ordinary function before dispatch when native support is unknown/unsupported. Require fails before authorization or network activity. This is a sampling constraint, not a replacement for argument validation.
func (*ToolConstrainedSampling) Clone ¶
func (sampling *ToolConstrainedSampling) Clone() *ToolConstrainedSampling
Clone returns an independent declaration, including for a nil receiver.
type ToolReference ¶
type ToolReference struct {
Name string `json:"name"`
}
type ToolResultMessage ¶
type ToolSamplingDecision ¶
ToolSamplingDecision makes the pre-request fallback observable to hosts. Representation is "function" or "custom". InputProperty is set for custom.
func ResolveToolSampling ¶
func ResolveToolSampling(model Model, tool Tool) (ToolSamplingDecision, error)
ResolveToolSampling uses only registered facts for the exact provider/model and wire API. Per-request Model.Capabilities cannot grant native support. The parameter schema must have exactly one property, a required string.
type ToolStateChanges ¶
type ToolStateChanges struct {
ToolsAdded []Tool
ToolsRemoved []ToolReference
}
func GetToolStateChanges ¶
func GetToolStateChanges(previous, current []Tool) ToolStateChanges
type TranscriptContext ¶
type TranscriptContext struct {
Messages []Message
HostedTools []HostedTool
}
TranscriptContext carries the prompt and tool declarations in system messages. Context remains the public authoring form accepted by Stream and StreamSimple.
func CollapseSystemMessages ¶
func CollapseSystemMessages(ctx TranscriptContext) TranscriptContext
func NormalizeContext ¶
func NormalizeContext(ctx Context) TranscriptContext
func ResolveTranscript ¶
func ResolveTranscript(ctx TranscriptContext, supportsMidConvoSystemMessages bool) TranscriptContext
func (TranscriptContext) MarshalJSON ¶
func (ctx TranscriptContext) MarshalJSON() ([]byte, error)
func (*TranscriptContext) UnmarshalJSON ¶
func (ctx *TranscriptContext) UnmarshalJSON(data []byte) error
type UsageCost ¶
type UsageCost struct {
Input float64
Output float64
CacheRead float64
CacheWrite float64
Total float64
}
func CalculateCost ¶
type UserMessage ¶
type VercelGatewayRouting ¶
Source Files
¶
- api_registry.go
- auth.go
- auth_env.go
- capabilities.go
- clone.go
- complete.go
- context_json.go
- diagnostics.go
- doc.go
- handoff_credentials.go
- hash.go
- http_stream_client.go
- json_parse.go
- models.go
- observer.go
- observer_logging.go
- overflow.go
- provider_anthropic_messages.go
- provider_anthropic_protocol.go
- provider_commandcode.go
- provider_commandcode_auth.go
- provider_commandcode_catalog.go
- provider_commandcode_discovery.go
- provider_commandcode_images.go
- provider_commandcode_messages.go
- provider_commandcode_models.go
- provider_commandcode_quota.go
- provider_commandcode_transport.go
- provider_common.go
- provider_deepseek_chat.go
- provider_deepseek_options.go
- provider_failure.go
- provider_google.go
- provider_google_options.go
- provider_http.go
- provider_http_body.go
- provider_http_redirect.go
- provider_kimi.go
- provider_kimi_options.go
- provider_kiro_authored_arguments.go
- provider_kiro_catalog_attempt.go
- provider_kiro_catalog_public.go
- provider_kiro_catalog_request.go
- provider_kiro_client_headers.go
- provider_kiro_completion.go
- provider_kiro_context_diagnostics.go
- provider_kiro_context_usage.go
- provider_kiro_credential_source.go
- provider_kiro_desktop_refresh_attempt.go
- provider_kiro_desktop_refresh_public.go
- provider_kiro_desktop_refresh_request.go
- provider_kiro_envelope.go
- provider_kiro_eventstream.go
- provider_kiro_explicit_auth.go
- provider_kiro_history_groups.go
- provider_kiro_host_context.go
- provider_kiro_host_options.go
- provider_kiro_http_request.go
- provider_kiro_idc_refresh_attempt.go
- provider_kiro_idc_refresh_public.go
- provider_kiro_idc_refresh_request.go
- provider_kiro_incremental_events.go
- provider_kiro_incremental_registration.go
- provider_kiro_incremental_tools.go
- provider_kiro_injected_attempt.go
- provider_kiro_injected_tool_stream.go
- provider_kiro_json.go
- provider_kiro_live_mixed_stream.go
- provider_kiro_live_registration.go
- provider_kiro_live_text_stream.go
- provider_kiro_metadata.go
- provider_kiro_model_catalog.go
- provider_kiro_offline_response.go
- provider_kiro_refresh_response.go
- provider_kiro_registration.go
- provider_kiro_registration_options.go
- provider_kiro_request_auth.go
- provider_kiro_request_envelope.go
- provider_kiro_retry_after.go
- provider_kiro_retry_policy.go
- provider_kiro_scoped_catalog.go
- provider_kiro_session_affinity.go
- provider_kiro_system_policy.go
- provider_kiro_text_events.go
- provider_kiro_text_message.go
- provider_kiro_text_projection.go
- provider_kiro_text_stream.go
- provider_kiro_tool_assembly.go
- provider_kiro_tool_events.go
- provider_kiro_tool_evidence.go
- provider_kiro_tool_message.go
- provider_kiro_tool_projection.go
- provider_kiro_tool_stream.go
- provider_mistral.go
- provider_mistral_options.go
- provider_openai_codex.go
- provider_openai_codex_auth.go
- provider_openai_codex_options.go
- provider_openai_codex_transport.go
- provider_openai_codex_user_agent.go
- provider_openai_codex_user_agent_unix.go
- provider_openai_completions.go
- provider_openai_completions_options.go
- provider_openai_responses.go
- provider_openai_responses_custom.go
- provider_openai_responses_options.go
- provider_openai_responses_sampling.go
- provider_openai_responses_shared.go
- provider_openai_responses_tools.go
- provider_opencode_go.go
- provider_options_common.go
- provider_registry.go
- provider_registry_builtin.go
- provider_stream_event.go
- provider_tokenharbor.go
- quota.go
- registry_generic.go
- request_context.go
- response_format.go
- sampling_params.go
- session_resources.go
- simple_options.go
- sse.go
- stream.go
- stream_buffer.go
- stream_lifecycle.go
- tool_sampling.go
- toolcall_ids.go
- transcript.go
- transform_messages.go
- types_compat.go
- types_content.go
- types_core.go
- types_event.go
- types_message.go
- types_model.go
- types_system.go
- types_tool.go
- validation.go
- version.go