Help us shape the future of Go! Take the 2026 Go Developer Survey

ai

package
v0.19.12 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: MIT Imports: 25 Imported by: 0

Documentation

Overview

Package ai provides pi's provider-neutral message and streaming contracts.

Index

Constants

View Source
const (
	ImagesAPIOpenRouter      ImagesAPI        = "openrouter-images"
	ImagesProviderOpenRouter ImagesProviderID = "openrouter"

	ImagesStopReasonStop    ImagesStopReason = "stop"
	ImagesStopReasonError   ImagesStopReason = "error"
	ImagesStopReasonAborted ImagesStopReason = "aborted"
)
View Source
const DefaultMaxAgentRetryDelayMS int64 = 60_000

Variables

View Source
var ErrStreamIncomplete = errors.New("ai: stream ended without a terminal event")

Functions

func CalculateCost

func CalculateCost(model *Model, usage *Usage)

CalculateCost fills usage.Cost from the model's rates, applying tiered pricing above each tier's input-token threshold and Anthropic's 2x base input rate for 1h cache writes.

func CleanupSessionResources

func CleanupSessionResources(sessionID ...string) error

CleanupSessionResources runs registered provider cleanups in registration order. Omitting sessionID releases resources for every session.

func CloneJSONValue added in v0.19.1

func CloneJSONValue(value any) any

CloneJSONValue deep-copies a JSON-shaped value: objects, arrays and raw JSON are copied, immutable scalars shared, and other Go values copied by reflection.

func ContentText

func ContentText(content any, separators ...string) string

ContentText extracts text blocks and joins them with a newline by default.

func CurrentSystemPrompt added in v0.7.0

func CurrentSystemPrompt(messages MessageList) string

func HasToolRedefinitions added in v0.7.0

func HasToolRedefinitions(messages MessageList) bool

func IsContextOverflow

func IsContextOverflow(message *AssistantMessage, contextWindow float64) bool

IsContextOverflow recognizes upstream's explicit and silent overflow forms.

func IsRetryableAssistantError

func IsRetryableAssistantError(message *AssistantMessage) bool

IsRetryableAssistantError reports whether a failed assistant message is a transient provider or transport error.

func Marshal

func Marshal(value any) ([]byte, error)

Marshal encodes the ai wire format with JSON.stringify-compatible string escaping. Internal protocol and persistence surfaces must use this instead of encoding/json's HTML-safe default.

func MarshalAssistantMessageEvent

func MarshalAssistantMessageEvent(event AssistantMessageEvent) ([]byte, error)

func MarshalMessage

func MarshalMessage(message Message) ([]byte, error)

func MarshalToolCallArguments

func MarshalToolCallArguments(content *ToolCall) ([]byte, error)

MarshalToolCallArguments preserves the provider's decoded JSON shape and object member order while the public argument map remains convenient for ordinary object-shaped tool calls.

func NormalizeJSONStringifyJSON

func NormalizeJSONStringifyJSON(data []byte) ([]byte, error)

NormalizeJSONStringifyJSON parses JSON with JavaScript Number semantics and re-emits the same value using JSON.stringify's ordering and scalar spelling.

func RegisterSessionResourceCleanup

func RegisterSessionResourceCleanup(cleanup SessionResourceCleanup) func()

RegisterSessionResourceCleanup installs a provider cleanup and returns an idempotent function that unregisters it.

func RetryDelayMS added in v0.7.0

func RetryDelayMS(policy RetryPolicy, attempt int) int64

func SetAssistantMessageErrorBeforeResponseID

func SetAssistantMessageErrorBeforeResponseID(message *AssistantMessage, enabled bool)

SetAssistantMessageErrorBeforeResponseID preserves the order produced when a streaming backend appends errorMessage before responseId to an existing message.

func SetAssistantMessageErrorBeforeTimestamp

func SetAssistantMessageErrorBeforeTimestamp(message *AssistantMessage, enabled bool)

SetAssistantMessageErrorBeforeTimestamp preserves the member order of upstream message constructors that insert errorMessage before timestamp.

func SetAssistantMessageProviderThinkingLevelBeforeUsage added in v0.6.0

func SetAssistantMessageProviderThinkingLevelBeforeUsage(message *AssistantMessage, before bool)

SetAssistantMessageProviderThinkingLevelBeforeUsage preserves constructor field order for managed Anthropic responses.

func SetAssistantMessageRawStopBeforeDiagnostics added in v0.6.0

func SetAssistantMessageRawStopBeforeDiagnostics(message *AssistantMessage, before bool)

SetAssistantMessageRawStopBeforeDiagnostics preserves diagnostics appended after stream termination.

func SetToolCallArgumentsJSON

func SetToolCallArgumentsJSON(content *ToolCall, data []byte) error

SetToolCallArgumentsJSON records a complete provider-emitted argument value so a later replay preserves JSON.stringify's original shape and member order. ToolCall.Arguments remains an object-oriented Go convenience; malformed provider values are retained in the wire representation and exposed through ToolCallArgumentsValue.

func SetToolCallPartialJSON added in v0.9.0

func SetToolCallPartialJSON(content *ToolCall, partial string) error

SetToolCallPartialJSON parses a streamed argument prefix, retaining the same ordered wire representation as SetToolCallArgumentsJSON without normalizing twice.

func SetUsageOptionalsBeforeTotals

func SetUsageOptionalsBeforeTotals(usage *Usage)

SetUsageOptionalsBeforeTotals preserves the order of upstream usage objects built by compaction aggregation.

func SystemMessageText added in v0.7.0

func SystemMessageText(message *SystemMessage) string

func ToolCallArgumentsValue

func ToolCallArgumentsValue(content *ToolCall) any

ToolCallArgumentsValue returns the provider-emitted JSON value. Valid tool calls return the public argument map; malformed non-object values remain observable so schema validation and transforms see the same runtime value as upstream.

func ToolDeclarationsEqual added in v0.16.0

func ToolDeclarationsEqual(left, right Tool) bool

ToolDeclarationsEqual reports whether two tools declare the same name, description, parameters and constrained sampling.

func ToolStateChanges added in v0.7.0

func ToolStateChanges(previous, current []Tool) (added []Tool, removed []ToolReference)

func TotalCost

func TotalCost(cost Cost) float64

TotalCost sums the individually rounded rate components. The explicit conversions are contraction barriers: Go may fuse a multiply and an add across statements (spec: Floating-point operators) unless a conversion rounds first, and on arm64 it does. That made an unfused -race build match upstream while the shipped CGO_ENABLED=0 binary wrote totals one ULP off and persisted them. JavaScript never fuses, so every site whose total reaches the wire sums here.

func UUIDv7

func UUIDv7() (string, error)

UUIDv7 returns a monotonic UUIDv7.

func WithTranscriptContext added in v0.7.0

func WithTranscriptContext(ctx context.Context, transcript TranscriptContext) context.Context

Types

type API

type API string
const (
	APIUnknown              API = ""
	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"
	APIBedrockConverse      API = "bedrock-converse-stream"
	APIGoogleGenerativeAI   API = "google-generative-ai"
	APIGoogleVertex         API = "google-vertex"
	APIPiMessages           API = "pi-messages"
)

type AnthropicAllowedFallbackModel added in v0.6.0

type AnthropicAllowedFallbackModel struct {
	Provider ProviderID `json:"provider"`
	Model    string     `json:"model"`
	Cost     ModelCost  `json:"cost"`
}

type AnthropicMessagesCompat

type AnthropicMessagesCompat struct {
	SupportsEagerToolInputStreaming *bool                            `json:"supportsEagerToolInputStreaming,omitempty"`
	SupportsLongCacheRetention      *bool                            `json:"supportsLongCacheRetention,omitempty"`
	SendSessionAffinityHeaders      *bool                            `json:"sendSessionAffinityHeaders,omitempty"`
	SupportsCacheControlOnTools     *bool                            `json:"supportsCacheControlOnTools,omitempty"`
	SupportsTemperature             *bool                            `json:"supportsTemperature,omitempty"`
	AllowEmptySignature             *bool                            `json:"allowEmptySignature,omitempty"`
	SupportsStrictTools             *bool                            `json:"supportsStrictTools,omitempty"`
	SupportsMidConvoEffort          *bool                            `json:"supportsMidConvoEffort,omitempty"`
	SupportsMidConvoSystemMessages  *bool                            `json:"supportsMidConvoSystemMessages,omitempty"`
	SupportsMidConvoToolChanges     *bool                            `json:"supportsMidConvoToolChanges,omitempty"`
	ForceAdaptiveThinking           *bool                            `json:"forceAdaptiveThinking,omitempty"`
	SessionAffinityFormat           *SessionAffinityFormat           `json:"sessionAffinityFormat,omitempty"`
	AllowedFallbackModels           *[]AnthropicAllowedFallbackModel `json:"allowedFallbackModels,omitempty"`
	SupportsToolReferences          *bool                            `json:"supportsToolReferences,omitempty"`
}

type AssistantCall

type AssistantCall func() (*AssistantMessage, error)

AssistantCall produces one terminal assistant message. Returned errors are terminal because upstream retries message-level provider failures, not rejected calls.

type AssistantContent

type AssistantContent []AssistantContentBlock

func (AssistantContent) MarshalJSON

func (blocks AssistantContent) MarshalJSON() ([]byte, error)

func (*AssistantContent) UnmarshalJSON

func (blocks *AssistantContent) UnmarshalJSON(data []byte) error

type AssistantContentBlock

type AssistantContentBlock interface {
	// contains filtered or unexported methods
}

type AssistantImages

type AssistantImages struct {
	API          ImagesAPI        `json:"api"`
	Provider     ImagesProviderID `json:"provider"`
	Model        string           `json:"model"`
	Output       ImagesContent    `json:"output"`
	ResponseID   *string          `json:"responseId,omitempty"`
	Usage        *Usage           `json:"usage,omitempty"`
	StopReason   ImagesStopReason `json:"stopReason"`
	ErrorMessage *string          `json:"errorMessage,omitempty"`
	Timestamp    int64            `json:"timestamp"`
}

type AssistantMessage

type AssistantMessage struct {
	ProviderThinkingLevel *string                       `json:"providerThinkingLevel,omitempty"`
	Content               AssistantContent              `json:"content"`
	API                   API                           `json:"api"`
	Provider              ProviderID                    `json:"provider"`
	Model                 string                        `json:"model"`
	Usage                 Usage                         `json:"usage"`
	StopReason            StopReason                    `json:"stopReason"`
	Timestamp             int64                         `json:"timestamp"`
	ResponseID            *string                       `json:"responseId,omitempty"`
	ResponseModel         *string                       `json:"responseModel,omitempty"`
	Diagnostics           *[]AssistantMessageDiagnostic `json:"diagnostics,omitempty"`
	ErrorMessage          *string                       `json:"errorMessage,omitempty"`
	RawStopReason         *string                       `json:"rawStopReason,omitempty"`
	// EndTurn records the provider's indication that the model explicitly ended
	// its turn. Preserved for debugging; it does not affect agent control flow.
	EndTurn *bool `json:"endTurn,omitempty"`
	// ThinkingLevel records the level the agent loop requested for this
	// response, whichever stream function answered it.
	ThinkingLevel *ModelThinkingLevel `json:"thinkingLevel,omitempty"`
	// contains filtered or unexported fields
}

func RetryAssistantCall

func RetryAssistantCall(
	ctx context.Context,
	produce AssistantCall,
	policy *RetryPolicy,
	callbacks *RetryCallbacks,
) (*AssistantMessage, error)

RetryAssistantCall runs produce once and retries transient assistant errors according to policy. Cancellation during backoff is returned as a shallow copy of the last response with an aborted stop reason and no error message.

func (AssistantMessage) MarshalJSON

func (message AssistantMessage) MarshalJSON() ([]byte, error)

func (*AssistantMessage) UnmarshalJSON

func (message *AssistantMessage) UnmarshalJSON(data []byte) error

type AssistantMessageDiagnostic

type AssistantMessageDiagnostic struct {
	Type      string               `json:"type"`
	Timestamp int64                `json:"timestamp"`
	Error     *DiagnosticErrorInfo `json:"error,omitempty"`
	Details   json.RawMessage      `json:"details,omitempty"`
}

func (AssistantMessageDiagnostic) MarshalJSON

func (diagnostic AssistantMessageDiagnostic) MarshalJSON() ([]byte, error)

func (*AssistantMessageDiagnostic) UnmarshalJSON

func (diagnostic *AssistantMessageDiagnostic) UnmarshalJSON(data []byte) error

type AssistantMessageEvent

type AssistantMessageEvent interface {
	// contains filtered or unexported methods
}

func UnmarshalAssistantMessageEvent

func UnmarshalAssistantMessageEvent(data []byte) (AssistantMessageEvent, error)

type AssistantMessageEventStream

type AssistantMessageEventStream = iter.Seq2[AssistantMessageEvent, error]

type BedrockCompat

type BedrockCompat struct {
	SupportsStrictMode *bool `json:"supportsStrictMode,omitempty"`
}

type CacheControlFormat

type CacheControlFormat string
const CacheControlAnthropic CacheControlFormat = "anthropic"

type CacheRetention

type CacheRetention string
const (
	CacheRetentionNone  CacheRetention = "none"
	CacheRetentionShort CacheRetention = "short"
	CacheRetentionLong  CacheRetention = "long"
)

type ConstrainedSamplingConfig

type ConstrainedSamplingConfig struct {
	Type     ConstrainedSamplingType   `json:"type"`
	Strict   ConstrainedSamplingStrict `json:"strict,omitempty"`
	Variants *GrammarVariants          `json:"variants,omitempty"`
}

type ConstrainedSamplingStrict

type ConstrainedSamplingStrict string
const (
	ConstrainedSamplingPrefer  ConstrainedSamplingStrict = "prefer"
	ConstrainedSamplingRequire ConstrainedSamplingStrict = "require"
)

type ConstrainedSamplingType

type ConstrainedSamplingType string
const (
	ConstrainedSamplingJSONSchema ConstrainedSamplingType = "json_schema"
	ConstrainedSamplingGrammar    ConstrainedSamplingType = "grammar"
)

type Context

type Context struct {
	SystemPrompt *string     `json:"systemPrompt,omitempty"`
	Messages     MessageList `json:"messages"`
	Tools        *[]Tool     `json:"tools,omitempty"`
}

type Cost

type Cost struct {
	Input      float64 `json:"input"`
	Output     float64 `json:"output"`
	CacheRead  float64 `json:"cacheRead"`
	CacheWrite float64 `json:"cacheWrite"`
	Total      float64 `json:"total"`
}

type DeferredToolsMode

type DeferredToolsMode string
const DeferredToolsKimi DeferredToolsMode = "kimi"

type DiagnosticErrorInfo

type DiagnosticErrorInfo struct {
	Name    *string         `json:"name,omitempty"`
	Message string          `json:"message"`
	Stack   *string         `json:"stack,omitempty"`
	Code    json.RawMessage `json:"code,omitempty"`
}

func (DiagnosticErrorInfo) MarshalJSON

func (info DiagnosticErrorInfo) MarshalJSON() ([]byte, error)

func (*DiagnosticErrorInfo) UnmarshalJSON

func (info *DiagnosticErrorInfo) UnmarshalJSON(data []byte) error

type DoneEvent

type DoneEvent struct {
	Reason  StopReason        `json:"reason"`
	Message *AssistantMessage `json:"message"`
}

func (DoneEvent) MarshalJSON

func (event DoneEvent) MarshalJSON() ([]byte, error)

type ErrorEvent

type ErrorEvent struct {
	Reason StopReason        `json:"reason"`
	Error  *AssistantMessage `json:"error"`
}

func (ErrorEvent) MarshalJSON

func (event ErrorEvent) MarshalJSON() ([]byte, error)

type GrammarVariants

type GrammarVariants struct {
	OpenAILark  *string `json:"openai_lark,omitempty"`
	OpenAIRegex *string `json:"openai_regex,omitempty"`
}

type HeadersHook

type HeadersHook func(ctx context.Context, headers ProviderHeaders, model *Model) (ProviderHeaders, error)

type ImageContent

type ImageContent struct {
	Data     string `json:"data"`
	MimeType string `json:"mimeType"`
}

func (ImageContent) MarshalJSON

func (content ImageContent) MarshalJSON() ([]byte, error)

func (*ImageContent) UnmarshalJSON

func (content *ImageContent) UnmarshalJSON(data []byte) error

type ImagesAPI

type ImagesAPI string

type ImagesContent

type ImagesContent []ImagesContentBlock

func (ImagesContent) MarshalJSON

func (blocks ImagesContent) MarshalJSON() ([]byte, error)

func (*ImagesContent) UnmarshalJSON

func (blocks *ImagesContent) UnmarshalJSON(data []byte) error

type ImagesContentBlock

type ImagesContentBlock interface {
	// contains filtered or unexported methods
}

type ImagesModel

type ImagesModel struct {
	ID               string                          `json:"id"`
	Name             string                          `json:"name"`
	API              ImagesAPI                       `json:"api"`
	Provider         ImagesProviderID                `json:"provider"`
	BaseURL          string                          `json:"baseUrl"`
	ThinkingLevelMap *map[ModelThinkingLevel]*string `json:"thinkingLevelMap,omitempty"`
	Input            InputModalities                 `json:"input"`
	Output           InputModalities                 `json:"output"`
	Cost             ModelCost                       `json:"cost"`
	Headers          *map[string]string              `json:"headers,omitempty"`
}

type ImagesProviderID

type ImagesProviderID string

type ImagesStopReason

type ImagesStopReason string

type InputModalities

type InputModalities []InputModality

func (InputModalities) MarshalJSON

func (modalities InputModalities) MarshalJSON() ([]byte, error)

type InputModality

type InputModality string
const (
	InputText  InputModality = "text"
	InputImage InputModality = "image"
)

type JSONSchema

type JSONSchema = jsonschema.Schema

JSONSchema is a raw JSON Schema value. It preserves its input bytes when marshaled so extension and MCP schemas can cross the provider boundary without a Go-side rewrite.

func JSONSchemaFrom

func JSONSchemaFrom[T any]() (JSONSchema, error)

JSONSchemaFrom derives an inline JSON Schema from T.

type MaxTokensField

type MaxTokensField string
const (
	MaxTokensFieldCompletion MaxTokensField = "max_completion_tokens"
	MaxTokensFieldLegacy     MaxTokensField = "max_tokens"
)

type Message

type Message interface {
	// contains filtered or unexported methods
}

func UnmarshalMessage

func UnmarshalMessage(data []byte) (Message, error)

type MessageList

type MessageList []Message

func WithoutInitialSystemMessage added in v0.7.0

func WithoutInitialSystemMessage(messages MessageList) MessageList

func (MessageList) MarshalJSON

func (messages MessageList) MarshalJSON() ([]byte, error)

func (*MessageList) UnmarshalJSON

func (messages *MessageList) UnmarshalJSON(data []byte) error

type MistralConversationsCompat added in v0.7.0

type MistralConversationsCompat struct {
	SupportsMidConvoSystemMessages *bool `json:"supportsMidConvoSystemMessages,omitempty"`
}

type Model

type Model struct {
	ID               string                          `json:"id"`
	Name             string                          `json:"name"`
	API              API                             `json:"api"`
	Provider         ProviderID                      `json:"provider"`
	BaseURL          string                          `json:"baseUrl"`
	Reasoning        bool                            `json:"reasoning"`
	ThinkingLevelMap *map[ModelThinkingLevel]*string `json:"thinkingLevelMap,omitempty"`
	Input            InputModalities                 `json:"input"`
	InputLimits      *ModelInputLimits               `json:"inputLimits,omitempty"`
	Cost             ModelCost                       `json:"cost"`
	PromptCache      *ModelPromptCache               `json:"promptCache,omitempty"`
	ContextWindow    float64                         `json:"contextWindow"`
	MaxTokens        float64                         `json:"maxTokens"`
	// SamplingParams are default request-body parameters for OpenAI-compatible
	// APIs; per-request StreamOptions.SamplingParams override them per key.
	SamplingParams map[string]any     `json:"samplingParams,omitempty"`
	Headers        *map[string]string `json:"headers,omitempty"`
	Compat         json.RawMessage    `json:"compat,omitempty"`
	// Type is the catalog operation; chat models may omit it.
	Type string `json:"type,omitempty"`
}

func (*Model) Clone added in v0.19.1

func (model *Model) Clone() *Model

Clone returns a copy of model that shares no mutable input, cost-tier, thinking-level, header or compat storage with it; nil stays nil.

type ModelCost

type ModelCost struct {
	ModelCostRates
	Tiers *[]ModelCostTier `json:"tiers,omitempty"`
}

type ModelCostRates

type ModelCostRates struct {
	Input      float64 `json:"input"`
	Output     float64 `json:"output"`
	CacheRead  float64 `json:"cacheRead"`
	CacheWrite float64 `json:"cacheWrite"`
}

type ModelCostTier

type ModelCostTier struct {
	InputTokensAbove float64 `json:"inputTokensAbove"`
	ModelCostRates
}

type ModelImageInputLimits added in v0.14.0

type ModelImageInputLimits struct {
	// Resize is applied before a new image enters conversation history.
	Resize        *ModelImageResizeOptions `json:"resize,omitempty"`
	MaxPerMessage *float64                 `json:"maxPerMessage,omitempty"`
	MaxPerRequest *float64                 `json:"maxPerRequest,omitempty"`
}

type ModelImageResizeOptions added in v0.14.0

type ModelImageResizeOptions struct {
	MaxWidth  *float64 `json:"maxWidth,omitempty"`
	MaxHeight *float64 `json:"maxHeight,omitempty"`
	// MaxBytes bounds the base64-encoded payload.
	MaxBytes    *float64 `json:"maxBytes,omitempty"`
	JPEGQuality *float64 `json:"jpegQuality,omitempty"`
}

type ModelInputLimits added in v0.14.0

type ModelInputLimits struct {
	// MaxRequestBytes is the maximum serialized provider request size.
	MaxRequestBytes *float64               `json:"maxRequestBytes,omitempty"`
	Images          *ModelImageInputLimits `json:"images,omitempty"`
}

ModelInputLimits are a model's provider input limits and cache-safe preprocessing metadata.

type ModelPromptCache added in v0.7.0

type ModelPromptCache struct {
	Short *float64 `json:"short,omitempty"`
	Long  *float64 `json:"long,omitempty"`
}

type ModelThinkingLevel

type ModelThinkingLevel string
const (
	ModelThinkingOff     ModelThinkingLevel = "off"
	ModelThinkingMinimal ModelThinkingLevel = "minimal"
	ModelThinkingLow     ModelThinkingLevel = "low"
	ModelThinkingMedium  ModelThinkingLevel = "medium"
	ModelThinkingHigh    ModelThinkingLevel = "high"
	ModelThinkingXHigh   ModelThinkingLevel = "xhigh"
	ModelThinkingMax     ModelThinkingLevel = "max"
)

func ClampThinkingLevel

func ClampThinkingLevel(model *Model, requested ModelThinkingLevel) ModelThinkingLevel

ClampThinkingLevel returns the requested level when supported, otherwise the nearest supported level upward first, then downward.

func SupportedThinkingLevels

func SupportedThinkingLevels(model *Model) []ModelThinkingLevel

SupportedThinkingLevels lists the model's usable thinking levels: a mapped null removes a level, and xhigh/max require an explicit mapping. A nil model reports every level (Go seam tolerance).

type NestedToolCallRecord added in v0.14.0

type NestedToolCallRecord struct {
	ID   string `json:"id"`
	Name string `json:"name"`
	// Arguments is omitted over the size limits; ArgumentsBytes then gives their size.
	Arguments      json.RawMessage `json:"arguments,omitempty"`
	ArgumentsBytes int             `json:"argumentsBytes,omitempty"`
	// Status is "ok", "error", or "unfinished" (still running when the caller finished).
	Status     string `json:"status"`
	DurationMS *int64 `json:"durationMs,omitempty"`
	Error      string `json:"error,omitempty"`
}

type NestedToolCalls added in v0.14.0

type NestedToolCalls struct {
	Calls []NestedToolCallRecord `json:"calls"`
	// Complete is false when calls were dropped, arguments omitted, or calls
	// had not finished.
	Complete bool `json:"complete"`
}

NestedToolCalls are the tool calls a tool made while it ran.

type OpenAICompletionsCompat

type OpenAICompletionsCompat struct {
	SupportsStore                               *bool                     `json:"supportsStore,omitempty"`
	SupportsDeveloperRole                       *bool                     `json:"supportsDeveloperRole,omitempty"`
	SupportsReasoningEffort                     *bool                     `json:"supportsReasoningEffort,omitempty"`
	SupportsUsageInStreaming                    *bool                     `json:"supportsUsageInStreaming,omitempty"`
	SupportsFinishReason                        *bool                     `json:"supportsFinishReason,omitempty"`
	MaxTokensField                              *MaxTokensField           `json:"maxTokensField,omitempty"`
	RequiresToolResultName                      *bool                     `json:"requiresToolResultName,omitempty"`
	RequiresAssistantAfterToolResult            *bool                     `json:"requiresAssistantAfterToolResult,omitempty"`
	RequiresThinkingAsText                      *bool                     `json:"requiresThinkingAsText,omitempty"`
	RequiresReasoningContentOnAssistantMessages *bool                     `json:"requiresReasoningContentOnAssistantMessages,omitempty"`
	ThinkingFormat                              *ThinkingFormat           `json:"thinkingFormat,omitempty"`
	ChatTemplateKwargs                          *map[string]any           `json:"chatTemplateKwargs,omitempty"`
	ChatTemplateArgs                            *map[string]any           `json:"chatTemplateArgs,omitempty"`
	OpenRouterRouting                           *OpenRouterRouting        `json:"openRouterRouting,omitempty"`
	VercelGatewayRouting                        *VercelGatewayRouting     `json:"vercelGatewayRouting,omitempty"`
	ZAIToolStream                               *bool                     `json:"zaiToolStream,omitempty"`
	ThinkingTokenBudgetField                    *ThinkingTokenBudgetField `json:"thinkingTokenBudgetField,omitempty"`
	SupportsThinkingTokenBudget                 *bool                     `json:"supportsThinkingTokenBudget,omitempty"`
	SupportsOpenAIGrammarTools                  *bool                     `json:"supportsOpenAIGrammarTools,omitempty"`
	SupportsMidConvoSystemMessages              *bool                     `json:"supportsMidConvoSystemMessages,omitempty"`
	SupportsMidConvoToolAdditions               *bool                     `json:"supportsMidConvoToolAdditions,omitempty"`
	SupportsStrictMode                          *bool                     `json:"supportsStrictMode,omitempty"`
	CacheControlFormat                          *CacheControlFormat       `json:"cacheControlFormat,omitempty"`
	SendSessionAffinityHeaders                  *bool                     `json:"sendSessionAffinityHeaders,omitempty"`
	DeferredToolsMode                           *DeferredToolsMode        `json:"deferredToolsMode,omitempty"`
	SessionAffinityFormat                       *SessionAffinityFormat    `json:"sessionAffinityFormat,omitempty"`
	SupportsLongCacheRetention                  *bool                     `json:"supportsLongCacheRetention,omitempty"`
	VLLMPriority                                *float64                  `json:"vllmPriority,omitempty"`
}

type OpenAIResponsesCompat

type OpenAIResponsesCompat struct {
	SupportsDeveloperRole           *bool                  `json:"supportsDeveloperRole,omitempty"`
	SupportsMidConvoSystemMessages  *bool                  `json:"supportsMidConvoSystemMessages,omitempty"`
	SessionAffinityFormat           *SessionAffinityFormat `json:"sessionAffinityFormat,omitempty"`
	SupportsLongCacheRetention      *bool                  `json:"supportsLongCacheRetention,omitempty"`
	SupportsStrictMode              *bool                  `json:"supportsStrictMode,omitempty"`
	SupportsOpenAIGrammarTools      *bool                  `json:"supportsOpenAIGrammarTools,omitempty"`
	SupportsAdditionalTools         *bool                  `json:"supportsAdditionalTools,omitempty"`
	SupportsToolSearch              *bool                  `json:"supportsToolSearch,omitempty"`
	SupportsExplicitPromptCacheMode *bool                  `json:"supportsExplicitPromptCacheMode,omitempty"`
	SupportsMaxOutputTokens         *bool                  `json:"supportsMaxOutputTokens,omitempty"`
}

type OpenRouterRouting

type OpenRouterRouting struct {
	AllowFallbacks         *bool           `json:"allow_fallbacks,omitempty"`
	RequireParameters      *bool           `json:"require_parameters,omitempty"`
	DataCollection         *string         `json:"data_collection,omitempty"`
	ZDR                    *bool           `json:"zdr,omitempty"`
	EnforceDistillableText *bool           `json:"enforce_distillable_text,omitempty"`
	Order                  *[]string       `json:"order,omitempty"`
	Only                   *[]string       `json:"only,omitempty"`
	Ignore                 *[]string       `json:"ignore,omitempty"`
	Quantizations          *[]string       `json:"quantizations,omitempty"`
	Sort                   json.RawMessage `json:"sort,omitempty"`
	MaxPrice               json.RawMessage `json:"max_price,omitempty"`
	PreferredMinThroughput json.RawMessage `json:"preferred_min_throughput,omitempty"`
	PreferredMaxLatency    json.RawMessage `json:"preferred_max_latency,omitempty"`
	// contains filtered or unexported fields
}

OpenRouterRouting is passed through to the provider verbatim. Upstream never re-types the compat object, so decoded values carry the raw JSON to preserve unknown keys and member order on the wire; the typed fields only serve Go-side construction.

func (OpenRouterRouting) MarshalJSON

func (routing OpenRouterRouting) MarshalJSON() ([]byte, error)

func (*OpenRouterRouting) UnmarshalJSON

func (routing *OpenRouterRouting) UnmarshalJSON(data []byte) error

type PayloadHook

type PayloadHook func(ctx context.Context, payload any, model *Model) (replacement any, replace bool, err error)

type ProviderEnv

type ProviderEnv map[string]string

type ProviderHeaders

type ProviderHeaders map[string]*string

type ProviderID

type ProviderID string

type ProviderResponse

type ProviderResponse struct {
	Status  int               `json:"status"`
	Headers map[string]string `json:"headers"`
}

type ProviderStreamEventHook added in v0.14.0

type ProviderStreamEventHook func(ctx context.Context, data json.RawMessage, model *Model)

ProviderStreamEventHook receives each parsed provider stream event, as JSON, before normalization. It is awaited in stream order and must not mutate data.

type RawAssistantMessageEvent

type RawAssistantMessageEvent struct {
	Raw     json.RawMessage
	Partial *AssistantMessage
}

RawAssistantMessageEvent retains a future event shape emitted by a provider while attaching the partial assistant message expected by stream consumers.

func (RawAssistantMessageEvent) MarshalJSON

func (event RawAssistantMessageEvent) MarshalJSON() ([]byte, error)

type Request

type Request struct {
	Model   *Model
	Context Context
	Options *StreamOptions
}

type ResponseHook

type ResponseHook func(ctx context.Context, response ProviderResponse, model *Model) error

type RetryCallbacks

type RetryCallbacks struct {
	OnRetryScheduled    func(attempt, maxAttempts int, delayMS int64, errorMessage string) error
	OnRetryAttemptStart func() error
	OnRetryFinished     func(success bool, attempt int, finalError *string) error
}

RetryCallbacks reports the lifecycle of retries after the initial call. Callback errors stop the retry operation, matching rejected async callbacks upstream.

type RetryPolicy

type RetryPolicy struct {
	Enabled         bool   `json:"enabled"`
	MaxRetries      int    `json:"maxRetries"`
	BaseDelayMS     int64  `json:"baseDelayMs"`
	MaxAgentDelayMS *int64 `json:"maxAgentDelayMs,omitempty"`
}

RetryPolicy applies bounded exponential backoff to assistant-producing calls. MaxRetries counts retries after the initial call.

type SessionAffinityFormat

type SessionAffinityFormat string
const (
	SessionAffinityOpenAI          SessionAffinityFormat = "openai"
	SessionAffinityOpenAINoSession SessionAffinityFormat = "openai-nosession"
	SessionAffinityOpenRouter      SessionAffinityFormat = "openrouter"
)

type SessionResourceCleanup

type SessionResourceCleanup func(sessionID string) error

SessionResourceCleanup releases provider resources associated with one session. An empty session ID means release every cached session resource.

type SimpleStreamOptions

type SimpleStreamOptions struct {
	StreamOptions
	Reasoning       *ThinkingLevel   `json:"reasoning,omitempty"`
	ThinkingBudgets *ThinkingBudgets `json:"thinkingBudgets,omitempty"`
	ToolChoice      ToolChoice       `json:"toolChoice,omitempty"`
}

type StartEvent

type StartEvent struct {
	Partial *AssistantMessage `json:"partial"`
}

func (StartEvent) MarshalJSON

func (event StartEvent) MarshalJSON() ([]byte, error)

type StopReason

type StopReason string
const (
	StopReasonPending StopReason = "pending"
	StopReasonStop    StopReason = "stop"
	StopReasonLength  StopReason = "length"
	StopReasonToolUse StopReason = "toolUse"
	StopReasonError   StopReason = "error"
	StopReasonAborted StopReason = "aborted"
)

type StreamFn

type StreamFn func(ctx context.Context, request Request) (AssistantMessageEventStream, error)

type StreamOptions

type StreamOptions struct {
	Temperature               *float64                `json:"temperature,omitempty"`
	MaxTokens                 *float64                `json:"maxTokens,omitempty"`
	APIKey                    *string                 `json:"apiKey,omitempty"`
	HTTPClient                *http.Client            `json:"-"`
	Transport                 *Transport              `json:"transport,omitempty"`
	CacheRetention            *CacheRetention         `json:"cacheRetention,omitempty"`
	SessionID                 *string                 `json:"sessionId,omitempty"`
	OnPayload                 PayloadHook             `json:"-"`
	TransformHeaders          HeadersHook             `json:"-"`
	OnResponse                ResponseHook            `json:"-"`
	OnProviderStreamEvent     ProviderStreamEventHook `json:"-"`
	Headers                   ProviderHeaders         `json:"headers,omitempty"`
	TimeoutMS                 *int64                  `json:"timeoutMs,omitempty"`
	WebSocketConnectTimeoutMS *int64                  `json:"websocketConnectTimeoutMs,omitempty"`
	MaxRetries                *int                    `json:"maxRetries,omitempty"`
	MaxRetryDelayMS           *int64                  `json:"maxRetryDelayMs,omitempty"`
	Metadata                  map[string]any          `json:"metadata,omitempty"`
	Env                       ProviderEnv             `json:"env,omitempty"`
	// SamplingParams are merged into OpenAI-compatible request bodies after the
	// named fields, over Model.SamplingParams per key; other APIs ignore them.
	SamplingParams map[string]any `json:"samplingParams,omitempty"`
}

type SystemMessage added in v0.7.0

type SystemMessage struct {
	Content      any                  `json:"content"`
	Sections     SystemPromptSections `json:"sections,omitempty"`
	ToolsAdded   []Tool               `json:"toolsAdded,omitempty"`
	ToolsRemoved []ToolReference      `json:"toolsRemoved,omitempty"`
	Timestamp    int64                `json:"timestamp"`
	// contains filtered or unexported fields
}

SystemMessage records prompt and tool state in the transcript. Content is either a string or a slice of text blocks, matching pi's public wire shape.

func CloneSystemMessage added in v0.16.0

func CloneSystemMessage(message *SystemMessage) (*SystemMessage, bool)

CloneSystemMessage returns what decoding message's JSON would, without the encoding, for a message with text content and valid UTF-8 strings; ok is false for any other.

func CreateInitialSystemMessage added in v0.7.0

func CreateInitialSystemMessage(systemPrompt *string, tools *[]Tool) *SystemMessage

func CurrentSystemMessage added in v0.7.0

func CurrentSystemMessage(messages MessageList) *SystemMessage

func InitialSystemMessage added in v0.7.0

func InitialSystemMessage(messages MessageList) *SystemMessage

func NewToolStateSystemMessage added in v0.7.0

func NewToolStateSystemMessage(timestamp int64, added []Tool, removed []ToolReference) *SystemMessage

NewToolStateSystemMessage creates the loop-generated wire shape where the timestamp precedes tool deltas, matching upstream object spread order.

func WithToolStateChanges added in v0.7.0

func WithToolStateChanges(message *SystemMessage, added []Tool, removed []ToolReference) *SystemMessage

func (SystemMessage) MarshalJSON added in v0.7.0

func (message SystemMessage) MarshalJSON() ([]byte, error)

func (*SystemMessage) UnmarshalJSON added in v0.7.0

func (message *SystemMessage) UnmarshalJSON(data []byte) error

type SystemPromptSection added in v0.7.0

type SystemPromptSection struct {
	Name string
	Text *string
}

SystemPromptSection is one insertion-ordered system prompt section. A nil Text removes a previously declared section.

type SystemPromptSections added in v0.7.0

type SystemPromptSections []SystemPromptSection

SystemPromptSections preserves JavaScript object insertion order on the wire.

func (SystemPromptSections) MarshalJSON added in v0.7.0

func (sections SystemPromptSections) MarshalJSON() ([]byte, error)

func (*SystemPromptSections) UnmarshalJSON added in v0.7.0

func (sections *SystemPromptSections) UnmarshalJSON(data []byte) error

type TextContent

type TextContent struct {
	Text          string  `json:"text"`
	TextSignature *string `json:"textSignature,omitempty"`
	// Index exists only while Anthropic content blocks are streaming and is cleared at block end.
	Index *int `json:"index,omitempty"`
}

func (TextContent) MarshalJSON

func (content TextContent) MarshalJSON() ([]byte, error)

func (*TextContent) UnmarshalJSON

func (content *TextContent) UnmarshalJSON(data []byte) error

type TextDeltaEvent

type TextDeltaEvent struct {
	ContentIndex int               `json:"contentIndex"`
	Delta        string            `json:"delta"`
	Partial      *AssistantMessage `json:"partial"`
}

func (TextDeltaEvent) MarshalJSON

func (event TextDeltaEvent) MarshalJSON() ([]byte, error)

type TextEndEvent

type TextEndEvent struct {
	ContentIndex     int               `json:"contentIndex"`
	Content          string            `json:"content"`
	ContentSignature *string           `json:"contentSignature,omitempty"`
	Partial          *AssistantMessage `json:"partial"`
}

func (TextEndEvent) MarshalJSON

func (event TextEndEvent) MarshalJSON() ([]byte, error)

type TextSignatureV1

type TextSignatureV1 struct {
	Version int    `json:"v"`
	ID      string `json:"id"`
	Phase   string `json:"phase,omitempty"`
}

type TextStartEvent

type TextStartEvent struct {
	ContentIndex int               `json:"contentIndex"`
	Partial      *AssistantMessage `json:"partial"`
}

func (TextStartEvent) MarshalJSON

func (event TextStartEvent) MarshalJSON() ([]byte, error)

type ThinkingBudgets

type ThinkingBudgets struct {
	Minimal *int `json:"minimal,omitempty"`
	Low     *int `json:"low,omitempty"`
	Medium  *int `json:"medium,omitempty"`
	High    *int `json:"high,omitempty"`
}

type ThinkingContent

type ThinkingContent struct {
	RedactedChunks    []json.RawMessage `json:"redactedChunks,omitempty"`
	Thinking          string            `json:"thinking"`
	ThinkingSignature *string           `json:"thinkingSignature,omitempty"`
	Redacted          *bool             `json:"redacted,omitempty"`
	// Index exists only while Anthropic content blocks are streaming and is cleared at block end.
	Index *int `json:"index,omitempty"`
}

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) MarshalJSON

func (event ThinkingDeltaEvent) MarshalJSON() ([]byte, error)

type ThinkingEndEvent

type ThinkingEndEvent struct {
	ContentIndex     int               `json:"contentIndex"`
	Content          string            `json:"content"`
	ContentSignature *string           `json:"contentSignature,omitempty"`
	Redacted         *bool             `json:"redacted,omitempty"`
	Partial          *AssistantMessage `json:"partial"`
}

func (ThinkingEndEvent) MarshalJSON

func (event ThinkingEndEvent) MarshalJSON() ([]byte, error)

type ThinkingFormat

type ThinkingFormat string
const (
	ThinkingFormatOpenAI           ThinkingFormat = "openai"
	ThinkingFormatOpenRouter       ThinkingFormat = "openrouter"
	ThinkingFormatDeepSeek         ThinkingFormat = "deepseek"
	ThinkingFormatTogether         ThinkingFormat = "together"
	ThinkingFormatBaseten          ThinkingFormat = "baseten"
	ThinkingFormatZAI              ThinkingFormat = "zai"
	ThinkingFormatQwen             ThinkingFormat = "qwen"
	ThinkingFormatChatTemplate     ThinkingFormat = "chat-template"
	ThinkingFormatQwenChatTemplate ThinkingFormat = "qwen-chat-template"
	ThinkingFormatString           ThinkingFormat = "string-thinking"
	ThinkingFormatAntLing          ThinkingFormat = "ant-ling"
)

type ThinkingLevel

type ThinkingLevel string
const (
	ThinkingMinimal ThinkingLevel = "minimal"
	ThinkingLow     ThinkingLevel = "low"
	ThinkingMedium  ThinkingLevel = "medium"
	ThinkingHigh    ThinkingLevel = "high"
	ThinkingXHigh   ThinkingLevel = "xhigh"
	ThinkingMax     ThinkingLevel = "max"
)

type ThinkingStartEvent

type ThinkingStartEvent struct {
	ContentIndex int               `json:"contentIndex"`
	Partial      *AssistantMessage `json:"partial"`
}

func (ThinkingStartEvent) MarshalJSON

func (event ThinkingStartEvent) MarshalJSON() ([]byte, error)

type ThinkingTokenBudgetField added in v0.6.0

type ThinkingTokenBudgetField string

type Tool

type Tool struct {
	Name                string                     `json:"name"`
	Label               string                     `json:"label,omitempty"`
	Description         string                     `json:"description"`
	Parameters          JSONSchema                 `json:"parameters"`
	ConstrainedSampling *ConstrainedSamplingConfig `json:"constrainedSampling,omitempty"`
}

func CurrentTools added in v0.7.0

func CurrentTools(messages MessageList) []Tool

func DeclaredTools added in v0.7.0

func DeclaredTools(messages MessageList) []Tool

type ToolCall

type ToolCall struct {
	ID               string         `json:"id"`
	Name             string         `json:"name"`
	Arguments        map[string]any `json:"arguments"`
	ThoughtSignature *string        `json:"thoughtSignature,omitempty"`
	// Namespace is the OpenAI Responses namespace for calls to dynamically
	// loaded or namespaced tools.
	Namespace *string `json:"namespace,omitempty"`
	// ArgumentsError says why the finished call's arguments text is no JSON object, with the text: the call
	// then fails validation and the model sees what it sent. A pi gateway or JavaScript provider sends it too.
	ArgumentsError string `json:"argumentsError,omitempty"`

	// Provider adapters clear streaming scratch fields before a terminal message is persisted.
	PartialJSON *string `json:"partialJson,omitempty"`
	PartialArgs *string `json:"partialArgs,omitempty"`
	StreamIndex *int    `json:"streamIndex,omitempty"`
	// Index exists only while Anthropic content blocks are streaming and is cleared at block end.
	Index *int `json:"index,omitempty"`
	// contains filtered or unexported fields
}

func (ToolCall) MarshalJSON

func (content ToolCall) MarshalJSON() ([]byte, error)

func (*ToolCall) UnmarshalJSON

func (content *ToolCall) UnmarshalJSON(data []byte) error

type ToolCallDeltaEvent

type ToolCallDeltaEvent struct {
	ContentIndex int               `json:"contentIndex"`
	Delta        string            `json:"delta"`
	Partial      *AssistantMessage `json:"partial"`
}

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) MarshalJSON

func (event ToolCallEndEvent) MarshalJSON() ([]byte, error)

type ToolCallStartEvent

type ToolCallStartEvent struct {
	ContentIndex int               `json:"contentIndex"`
	ID           string            `json:"id,omitempty"`
	ToolName     string            `json:"toolName,omitempty"`
	Partial      *AssistantMessage `json:"partial"`
}

func (ToolCallStartEvent) MarshalJSON

func (event ToolCallStartEvent) MarshalJSON() ([]byte, error)

type ToolChoice

type ToolChoice string
const (
	ToolChoiceAuto     ToolChoice = "auto"
	ToolChoiceNone     ToolChoice = "none"
	ToolChoiceRequired ToolChoice = "required"
)

type ToolReference added in v0.7.0

type ToolReference struct {
	Name string `json:"name"`
}

type ToolResultContent

type ToolResultContent []ToolResultContentBlock

func (ToolResultContent) MarshalJSON

func (blocks ToolResultContent) MarshalJSON() ([]byte, error)

func (*ToolResultContent) UnmarshalJSON

func (blocks *ToolResultContent) UnmarshalJSON(data []byte) error

type ToolResultContentBlock

type ToolResultContentBlock interface {
	// contains filtered or unexported methods
}

type ToolResultMessage

type ToolResultMessage struct {
	ToolCallID     string            `json:"toolCallId"`
	ToolName       string            `json:"toolName"`
	Content        ToolResultContent `json:"content"`
	Details        json.RawMessage   `json:"details,omitempty"`
	Usage          *Usage            `json:"usage,omitempty"`
	AddedToolNames *[]string         `json:"addedToolNames,omitempty"`
	IsError        bool              `json:"isError"`
	Timestamp      int64             `json:"timestamp"`
	// NestedCalls records the calls the tool made through ctx.ExecuteTool.
	NestedCalls *NestedToolCalls `json:"nestedCalls,omitempty"`
}

func (ToolResultMessage) MarshalJSON

func (message ToolResultMessage) MarshalJSON() ([]byte, error)

func (*ToolResultMessage) UnmarshalJSON

func (message *ToolResultMessage) UnmarshalJSON(data []byte) error

type TranscriptContext added in v0.7.0

type TranscriptContext struct {
	Messages MessageList `json:"messages"`
}

TranscriptContext is the normalized provider request context. Context is retained as the public compatibility input; NormalizeContext folds its legacy prompt and tool fields into the transcript.

func CollapseSystemMessages added in v0.7.0

func CollapseSystemMessages(context TranscriptContext) TranscriptContext

func NormalizeContext added in v0.7.0

func NormalizeContext(context Context) TranscriptContext

func TranscriptContextFrom added in v0.7.0

func TranscriptContextFrom(ctx context.Context) (TranscriptContext, bool)

type TranscriptTools added in v0.7.0

type TranscriptTools struct {
	RequestTools []Tool
	// FoldedSystemMessages is how many leading system messages RequestTools holds; later ones declare
	// their additions in place. A removal or redeclaration cannot be declared in place, so the list is the
	// tool state after the last one, and the cached prefix breaks once per removal instead of at every later
	// addition (pi 1.4.0).
	FoldedSystemMessages int
}

func ResolveTranscriptTools added in v0.7.0

func ResolveTranscriptTools(messages MessageList, supportsToolAdditions bool) TranscriptTools

type Transport

type Transport string
const (
	TransportSSE             Transport = "sse"
	TransportWebSocket       Transport = "websocket"
	TransportWebSocketCached Transport = "websocket-cached"
	TransportAuto            Transport = "auto"
)

type UnknownContentBlock

type UnknownContentBlock struct {
	Raw json.RawMessage
}

UnknownContentBlock retains a future upstream content shape while this port has not learned its concrete Go type yet.

func (UnknownContentBlock) MarshalJSON

func (content UnknownContentBlock) MarshalJSON() ([]byte, error)

type Usage

type Usage struct {
	Input        int64  `json:"input"`
	Output       int64  `json:"output"`
	CacheRead    int64  `json:"cacheRead"`
	CacheWrite   int64  `json:"cacheWrite"`
	Reasoning    *int64 `json:"reasoning,omitempty"`
	TotalTokens  int64  `json:"totalTokens"`
	Cost         Cost   `json:"cost"`
	CacheWrite1h *int64 `json:"cacheWrite1h,omitempty"`
	// contains filtered or unexported fields
}

func (*Usage) Clone added in v0.19.1

func (usage *Usage) Clone() *Usage

Clone returns a deep copy of usage; nil stays nil.

func (Usage) MarshalJSON

func (usage Usage) MarshalJSON() ([]byte, error)

func (*Usage) UnmarshalJSON

func (usage *Usage) UnmarshalJSON(data []byte) error

type UserContent

type UserContent struct {
	Text   *string
	Blocks UserContentBlocks
}

func NewUserContent

func NewUserContent(blocks ...UserContentBlock) UserContent

func NewUserText

func NewUserText(text string) UserContent

func (UserContent) MarshalJSON

func (content UserContent) MarshalJSON() ([]byte, error)

func (*UserContent) UnmarshalJSON

func (content *UserContent) UnmarshalJSON(data []byte) error

type UserContentBlock

type UserContentBlock interface {
	// contains filtered or unexported methods
}

type UserContentBlocks

type UserContentBlocks []UserContentBlock

func (UserContentBlocks) MarshalJSON

func (blocks UserContentBlocks) MarshalJSON() ([]byte, error)

func (*UserContentBlocks) UnmarshalJSON

func (blocks *UserContentBlocks) UnmarshalJSON(data []byte) error

type UserMessage

type UserMessage struct {
	Content   UserContent `json:"content"`
	Timestamp int64       `json:"timestamp"`
}

func (UserMessage) MarshalJSON

func (message UserMessage) MarshalJSON() ([]byte, error)

type VercelGatewayRouting

type VercelGatewayRouting struct {
	Only  *[]string `json:"only,omitempty"`
	Order *[]string `json:"order,omitempty"`
}

Directories

Path Synopsis
api
all
Package all is the default provider registry: the CLI and SDK sessions that pass no stream function dispatch through it.
Package all is the default provider registry: the CLI and SDK sessions that pass no stream function dispatch through it.
bedrock
Package bedrock is Orb's Bedrock ConverseStream transport: the request, signed with SigV4 or a bearer token, goes over net/http, and the response is read from the AWS event stream framing.
Package bedrock is Orb's Bedrock ConverseStream transport: the request, signed with SigV4 or a bearer token, goes over net/http, and the response is read from the AWS event stream framing.
accounts
Package accounts adds named credentials without changing the provider-keyed compatibility store.
Package accounts adds named credentials without changing the provider-keyed compatibility store.
Package models contains the generated model catalog and its persisted refresh overlay.
Package models contains the generated model catalog and its persisted refresh overlay.
cmd/genmodels command
internal/cataloggen
Package cataloggen normalizes the models.dev api.json shape into pi models.
Package cataloggen normalizes the models.dev api.json shape into pi models.
faux
Package faux provides a scripted, in-memory provider for agent and provider tests.
Package faux provides a scripted, in-memory provider for agent and provider tests.

Jump to

Keyboard shortcuts

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