Documentation
¶
Overview ¶
Package provider integrates model providers and normalizes their request flows.
Index ¶
- Constants
- Variables
- func BuildOpenAIOAuthAuthorizeURL(redirectURI, state, codeChallenge, originator string) (string, error)
- func BuiltinPromptFS() embed.FS
- func CanonicalProviderID(providerID string) string
- func ComposeInstructions(baseInstructions, providerID, modelID string) string
- func DefaultAnthropicBaseURL() string
- func DefaultGoogleBaseURL() string
- func DefaultOpenAIBaseURL() string
- func DefaultOpenAIOAuthBaseURL() string
- func EffectiveMaxOutputTokens(req Request) int
- func EffectiveReasoningVariantForTurn(model ModelRef, allowedTools []string, requested string) string
- func EffectiveThinkingEnabledForTurn(model ModelRef, allowedTools []string, requested bool) bool
- func EstimateInputTokens(input Input) int
- func EstimateRequestTokens(req Request) int
- func EstimateTextTokens(text string) int
- func IsInputLimitExceeded(err error) bool
- func JoinPromptSections(parts ...string) string
- func LooksLikeAuthProviderResponse(statusCode int, message string) bool
- func NormalizeOpenAIBaseURL(baseURL string) string
- func NormalizeReasoningVariant(value string) (string, bool)
- func OpenAIOAuthCodeChallenge(codeVerifier string) string
- func PromptText(req Request) string
- func ReasoningVariantNames() []string
- func RegisterProviderAlias(providerID, canonical string)
- func RequiresOpenAIReasoningContentReplay(req Request) bool
- func SuggestedMaxOutputTokens(ref ModelRef) int
- func SupportedReasoningVariantsForTurn(model ModelRef, allowedTools []string) []string
- func SupportsCustomTools(model ModelRef) bool
- func SupportsReasoningVariants(model ModelRef) bool
- func SupportsReasoningVariantsForTurn(model ModelRef, allowedTools []string) bool
- func SupportsThinkingOutputForTurn(model ModelRef, allowedTools []string) bool
- func SupportsThinkingOutputFromCatalog(model ModelRef, reasoning bool) bool
- func SystemPrompt(providerID, modelID string) string
- func ThinkingOutputSupportForTurn(model ModelRef, allowedTools []string) (bool, bool)
- func ValidateOpenAIPromptCacheRetention(value string) error
- type AnthropicClient
- type AnthropicConfig
- type AnthropicThinkingBlock
- type Attachment
- type AuthEntry
- type AuthStore
- type AuthType
- type CatalogModel
- type Client
- type ConversationToolCallIDAliases
- type Embedder
- type EmbeddingRequest
- type Event
- type EventKind
- type FinishReason
- type GitHubCopilotConfig
- type GitHubCopilotDeviceCode
- type GitHubCopilotModel
- type GitHubCopilotOAuthConfig
- type GoogleClient
- type GoogleConfig
- type Input
- type InputKind
- type LocalModelCatalogProvider
- type ModelCapacity
- type ModelCatalog
- func (c *ModelCatalog) EnsureFresh(ctx context.Context) error
- func (c *ModelCatalog) Init(ctx context.Context)
- func (c *ModelCatalog) ModelsForProvider(providerID string) []CatalogModel
- func (c *ModelCatalog) ProviderName(providerID string) string
- func (c *ModelCatalog) Refresh(ctx context.Context) error
- type ModelCatalogConfig
- type ModelRef
- type ModelRoute
- type OpenAIBackend
- type OpenAIClient
- type OpenAICompatibleClient
- type OpenAICompatibleConfig
- type OpenAICompatibleEmbeddingConfig
- type OpenAIConfig
- type OpenAIEmbedder
- type OpenAIEmbeddingConfig
- type OpenAIOAuthCodeExchangeRequest
- type OpenAIOAuthConfig
- type PromptCacheSupport
- type ProviderError
- type RawSSEFrame
- type RawSSEObserver
- type RemoteModelCatalogProvider
- type RemoteModelCatalogProviderKind
- type Request
- type RequestTokenBreakdown
- type RequestTrace
- type RetryHint
- type RouteAttempt
- type RouteError
- type RouteTrace
- type RoutedClient
- type RoutedEmbedder
- type SliceStream
- type Stream
- type SystemPromptResolution
- type TokenCountSource
- type Tool
- type ToolInputFormat
- type ToolKind
- type UsageReport
Constants ¶
const ( OpenAIPromptCacheRetentionInMemory = "in_memory" OpenAIPromptCacheRetention24h = "24h" )
const ( AnthropicThinkingBlockTypeThinking = "thinking" AnthropicThinkingBlockTypeRedactedThinking = "redacted_thinking" )
const ( ReasoningVariantMinimal = "minimal" ReasoningVariantNone = "none" ReasoningVariantLow = "low" ReasoningVariantMedium = "medium" ReasoningVariantHigh = "high" ReasoningVariantXHigh = "xhigh" ReasoningVariantMax = "max" )
Variables ¶
var ( ErrEmbeddingModelRequired = errors.New("embedding model is required") ErrEmbeddingInputsRequired = errors.New("embedding inputs are required") ErrEmbeddingProviderNotConfigured = errors.New("embedding provider is not configured") ErrEmbeddingVectorCountMismatch = errors.New("embedding vector count mismatch") ErrEmbeddingVectorDimensionsMismatch = errors.New("embedding vector dimensions mismatch") )
var ( ErrGitHubCopilotOAuthStoreRequired = errors.New("github copilot oauth store is required") ErrGitHubCopilotOAuthCredentialsRequired = errors.New("github copilot oauth access or refresh token is required") ErrGitHubCopilotNotAvailable = errors.New("github copilot is not available for this GitHub account") )
var ( ErrModelProviderIDRequired = errors.New("model provider_id is required") ErrModelIDRequired = errors.New("model model_id is required") ErrModelRefFormat = errors.New("model ref must be in provider/model format") )
var ( ErrOpenAIAuthRequired = errors.New("openai api key or oauth auth is required") ErrOpenAIOAuthStoreRequired = errors.New("openai oauth store is required") ErrOpenAIOAuthCredentialsRequired = errors.New("openai oauth access or refresh token is required") )
var ( ErrOpenAICompatibleAPIKeyRequired = errors.New("openai compatible api key is required") ErrOpenAICompatibleBaseURLRequired = errors.New("openai compatible base_url is required") ErrGitHubCopilotTokenRequired = errors.New("github copilot token is required") )
var ( ErrProviderRouteIDRequired = errors.New("provider route id is required") ErrProviderRouteClientNeeded = errors.New("provider route client is required") ErrProviderNotConfigured = errors.New("provider not configured") )
var ErrAnthropicAPIKeyRequired = errors.New("anthropic api key is required")
var ErrAnthropicMaxTokensExceeded = errors.New("anthropic response stopped at max_tokens")
var ErrAnthropicPauseTurnUnsupported = errors.New("anthropic pause_turn is not supported by this runtime")
var ErrGoogleAPIKeyRequired = errors.New("google api key is required")
var ErrOpenAIPromptCacheRetentionInvalid = errors.New("openai prompt_cache_retention must be empty, in_memory, or 24h")
var ErrProviderInputLimitExceeded = errors.New("provider input limit exceeded")
Functions ¶
func BuiltinPromptFS ¶
func CanonicalProviderID ¶
func ComposeInstructions ¶
func DefaultAnthropicBaseURL ¶
func DefaultAnthropicBaseURL() string
func DefaultGoogleBaseURL ¶
func DefaultGoogleBaseURL() string
func DefaultOpenAIBaseURL ¶
func DefaultOpenAIBaseURL() string
func DefaultOpenAIOAuthBaseURL ¶
func DefaultOpenAIOAuthBaseURL() string
func EstimateInputTokens ¶
EstimateInputTokens returns a rough token estimate for a provider input.
func EstimateRequestTokens ¶
EstimateRequestTokens returns a rough token estimate for a provider request, including instructions, tool schemas, and turn inputs. This mirrors the fallback budgeting model used in koda when accurate provider-side token counting is unavailable.
func EstimateTextTokens ¶
EstimateTextTokens returns a rough token estimate for UTF-8 text. It treats ASCII text at roughly 4 chars/token and non-ASCII runes at roughly 1 token each to avoid undercounting mixed or multibyte content too aggressively.
func IsInputLimitExceeded ¶
func JoinPromptSections ¶
JoinPromptSections renders the provider-facing prompt text from stable and dynamic prompt sections. When split sections are present, they are the canonical prompt authority.
func NormalizeOpenAIBaseURL ¶
func PromptText ¶
PromptText returns the canonical prompt text for a request. Split prompt sections win when present so every provider sees the same effective prompt.
func ReasoningVariantNames ¶
func ReasoningVariantNames() []string
func RegisterProviderAlias ¶
func RegisterProviderAlias(providerID, canonical string)
Experiemental Delete before Release RegisterProviderAlias lets local experimental providers declare that they should inherit the canonical behavior of a shipped provider family.
func SuggestedMaxOutputTokens ¶
SuggestedMaxOutputTokens returns a provider/model-family limit when the runtime does not have fresher catalog metadata for the selected model.
func SupportsCustomTools ¶
func SystemPrompt ¶
SystemPrompt returns a provider/model-specific prompt supplement.
Resolution order:
- Per-model: ~/.config/kodacode/prompts/{providerID}/{modelID}.md|.txt
- Per-provider: ~/.config/kodacode/prompts/{providerID}.md|.txt
- Canonical override: ~/.config/kodacode/prompts/openai.md, deepseek.md, etc.
- Built-in embedded prompt
Types ¶
type AnthropicClient ¶
type AnthropicClient struct {
// contains filtered or unexported fields
}
func NewAnthropicClient ¶
func NewAnthropicClient(config AnthropicConfig) (*AnthropicClient, error)
func (*AnthropicClient) CountTokens ¶
func (c *AnthropicClient) CountTokens(ctx context.Context, req Request) (int, TokenCountSource, error)
type AnthropicConfig ¶
type AnthropicThinkingBlock ¶
func (*AnthropicThinkingBlock) Validate ¶
func (b *AnthropicThinkingBlock) Validate() error
type Attachment ¶
func (Attachment) Validate ¶
func (a Attachment) Validate() error
type AuthEntry ¶
type AuthEntry struct {
Type AuthType
Access string
Refresh string
Expires int64
Project string
AccountID string
ClientVersion string
}
func ExchangeOpenAIOAuthCode ¶
type AuthStore ¶
type AuthStore struct {
// contains filtered or unexported fields
}
func NewAuthStore ¶
func NewAuthStore() *AuthStore
func NewAuthStoreAt ¶
type CatalogModel ¶
type CatalogModel struct {
ID string
Name string
Family string
ContextSize int
MaxInputTokens int
MaxOutputTokens int
Reasoning bool
ReasoningKnown bool
SupportedReasoningVariants []string
SupportsThinkingOutput bool
ToolCalls bool
ToolCallsKnown bool
Vision bool
VisionKnown bool
CostInput float64
CostInputKnown bool
CostOutput float64
CostOutputKnown bool
CostCacheRead float64
CostCacheReadKnown bool
CostCacheWrite float64
CostCacheWriteKnown bool
InputModalities []string
OutputModalities []string
SupportedEndpoints []string
}
func NormalizeCatalogModelCapabilities ¶
func NormalizeCatalogModelCapabilities(providerID string, model CatalogModel) CatalogModel
func (CatalogModel) Capacity ¶
func (m CatalogModel) Capacity() ModelCapacity
type Client ¶
func NewPromptingClient ¶
type ConversationToolCallIDAliases ¶
type ConversationToolCallIDAliases struct {
// contains filtered or unexported fields
}
ConversationToolCallIDAliases resolves between runtime tool call ids and the provider-safe request-local aliases used in an outbound conversation.
func BuildConversationToolCallIDAliases ¶
func BuildConversationToolCallIDAliases(req Request) ConversationToolCallIDAliases
BuildConversationToolCallIDAliases returns the request-local alias mapping that normalizeConversationToolCallIDs applies to tool call/result inputs.
func (ConversationToolCallIDAliases) OriginalToProvider ¶
func (a ConversationToolCallIDAliases) OriginalToProvider(original string) (string, bool)
func (ConversationToolCallIDAliases) ProviderToOriginal ¶
func (a ConversationToolCallIDAliases) ProviderToOriginal(providerID string) (string, bool)
type Embedder ¶
type Embedder interface {
Embed(context.Context, EmbeddingRequest) ([][]float32, error)
}
type EmbeddingRequest ¶
func (EmbeddingRequest) Validate ¶
func (r EmbeddingRequest) Validate() error
type Event ¶
type EventKind ¶
type EventKind string
const ( EventKindAssistantDelta EventKind = "assistant_delta" EventKindReasoningDelta EventKind = "reasoning_delta" EventKindAnthropicThinkingCommitted EventKind = "anthropic_thinking_committed" EventKindOpenAIReasoningCommitted EventKind = "openai_reasoning_committed" EventKindToolCallDelta EventKind = "tool_call_delta" EventKindToolCallDone EventKind = "tool_call_done" )
type FinishReason ¶
type FinishReason string
const ( FinishReasonStop FinishReason = "stop" FinishReasonToolCalls FinishReason = "tool_calls" FinishReasonLength FinishReason = "length" FinishReasonContentFilter FinishReason = "content_filter" FinishReasonError FinishReason = "error" FinishReasonUnknown FinishReason = "unknown" )
func NormalizeFinishReason ¶
func NormalizeFinishReason(reason FinishReason) FinishReason
func StreamFinishReason ¶
func StreamFinishReason(stream Stream) FinishReason
type GitHubCopilotConfig ¶
type GitHubCopilotConfig struct {
Token string
BaseURL string
OAuth *GitHubCopilotOAuthConfig
HTTPClient *http.Client
}
type GitHubCopilotDeviceCode ¶
type GitHubCopilotDeviceCode struct {
DeviceCode string
UserCode string
VerificationURL string
ExpiresIn int
Interval int
}
type GitHubCopilotModel ¶
type GitHubCopilotModel struct {
ID string
Name string
Family string
ModelPickerEnabled bool
SupportedEndpoints []string
ContextSize int
MaxInputTokens int
MaxOutputTokens int
ToolCalls bool
Vision bool
Reasoning bool
}
func FetchGitHubCopilotModels ¶
func FetchGitHubCopilotModels(ctx context.Context, config GitHubCopilotConfig) ([]GitHubCopilotModel, error)
type GoogleClient ¶
type GoogleClient struct {
// contains filtered or unexported fields
}
func NewGoogleClient ¶
func NewGoogleClient(ctx context.Context, config GoogleConfig) (*GoogleClient, error)
func (*GoogleClient) CountTokens ¶
func (c *GoogleClient) CountTokens(ctx context.Context, req Request) (int, TokenCountSource, error)
type GoogleConfig ¶
type Input ¶
type Input struct {
Kind InputKind
Content string
Attachments []Attachment
AnthropicThinking *AnthropicThinkingBlock
GoogleThoughtSignature []byte
OpenAIReasoningContent string
OpenAIReasoningItem json.RawMessage
CallID string
ToolName string
ToolKind ToolKind
Arguments string
Output string
Error string
RetryOfCallID string
ReusedFromCallID string
ReusedFromSessionID string
ReusedFromTurnID string
}
type InputKind ¶
type InputKind string
const ( InputKindUserMessage InputKind = "user_message" InputKindAssistantMessage InputKind = "assistant_message" InputKindAnthropicThinking InputKind = "anthropic_thinking" InputKindOpenAIReasoning InputKind = "openai_reasoning" InputKindToolCall InputKind = "tool_call" InputKindToolResult InputKind = "tool_result" )
type ModelCapacity ¶
func NormalizeModelCapacity ¶
func NormalizeModelCapacity(windowTokens, inputTokens, outputTokens int) ModelCapacity
func (ModelCapacity) HasDistinctWindow ¶
func (c ModelCapacity) HasDistinctWindow() bool
type ModelCatalog ¶
type ModelCatalog struct {
// contains filtered or unexported fields
}
func NewModelCatalog ¶
func NewModelCatalog(config ModelCatalogConfig) *ModelCatalog
func (*ModelCatalog) EnsureFresh ¶
func (c *ModelCatalog) EnsureFresh(ctx context.Context) error
func (*ModelCatalog) Init ¶
func (c *ModelCatalog) Init(ctx context.Context)
func (*ModelCatalog) ModelsForProvider ¶
func (c *ModelCatalog) ModelsForProvider(providerID string) []CatalogModel
func (*ModelCatalog) ProviderName ¶
func (c *ModelCatalog) ProviderName(providerID string) string
type ModelCatalogConfig ¶
type ModelCatalogConfig struct {
CacheFile string
ExpiryDays int
OpenAIOAuth bool
OpenAIAPIKey bool
RemoteProviders []RemoteModelCatalogProvider
LocalProviders []LocalModelCatalogProvider
ReportError func(message string, err error)
}
type ModelRef ¶
func ParseModelRef ¶
type ModelRoute ¶
type ModelRoute struct {
Primary ModelRef
}
func (ModelRoute) Candidates ¶
func (r ModelRoute) Candidates() []ModelRef
func (ModelRoute) Validate ¶
func (r ModelRoute) Validate() error
type OpenAIBackend ¶
type OpenAIBackend string
const ( OpenAIBackendPlatformAPI OpenAIBackend = "platform_api" OpenAIBackendChatGPTCodex OpenAIBackend = "chatgpt_codex" )
type OpenAIClient ¶
type OpenAIClient struct {
// contains filtered or unexported fields
}
func NewOpenAIClient ¶
func NewOpenAIClient(config OpenAIConfig) (*OpenAIClient, error)
func (*OpenAIClient) CountTokens ¶
func (c *OpenAIClient) CountTokens(ctx context.Context, req Request) (int, TokenCountSource, error)
type OpenAICompatibleClient ¶
type OpenAICompatibleClient struct {
// contains filtered or unexported fields
}
func NewGitHubCopilotClient ¶
func NewGitHubCopilotClient(config GitHubCopilotConfig) (*OpenAICompatibleClient, error)
func NewOpenAICompatibleClient ¶
func NewOpenAICompatibleClient(config OpenAICompatibleConfig) (*OpenAICompatibleClient, error)
func (*OpenAICompatibleClient) CountTokens ¶
func (c *OpenAICompatibleClient) CountTokens(ctx context.Context, req Request) (int, TokenCountSource, error)
type OpenAICompatibleConfig ¶
type OpenAIConfig ¶
type OpenAIConfig struct {
APIKey string
OAuth *OpenAIOAuthConfig
Backend OpenAIBackend
BaseURL string
PromptCacheRetention string
ResponsesStore bool
EncryptedReasoningReplay bool
HTTPClient *http.Client
}
type OpenAIEmbedder ¶
type OpenAIEmbedder struct {
// contains filtered or unexported fields
}
func NewOpenAICompatibleEmbedder ¶
func NewOpenAICompatibleEmbedder(config OpenAICompatibleEmbeddingConfig) (*OpenAIEmbedder, error)
func NewOpenAIEmbedder ¶
func NewOpenAIEmbedder(config OpenAIEmbeddingConfig) (*OpenAIEmbedder, error)
func (*OpenAIEmbedder) Embed ¶
func (e *OpenAIEmbedder) Embed(ctx context.Context, req EmbeddingRequest) ([][]float32, error)
type OpenAIEmbeddingConfig ¶
type OpenAIEmbeddingConfig struct {
APIKey string
OAuth *OpenAIOAuthConfig
BaseURL string
HTTPClient *http.Client
}
type OpenAIOAuthConfig ¶
type PromptCacheSupport ¶
type PromptCacheSupport struct {
ProviderID string
RequestHintsSupported bool
CacheReadReportingSupported bool
CacheWriteReportingSupported bool
UnsupportedReason string
}
func PromptCacheSupportForModel ¶
func PromptCacheSupportForModel(ref ModelRef) PromptCacheSupport
type ProviderError ¶
type ProviderError struct {
Message string
StatusCode int
Retryable bool
RetryAfter time.Duration
Cause error
AuthDebug *providerAuthDebugState
}
func (*ProviderError) Error ¶
func (e *ProviderError) Error() string
func (*ProviderError) Unwrap ¶
func (e *ProviderError) Unwrap() error
type RawSSEObserver ¶
type RawSSEObserver func(RawSSEFrame)
type RemoteModelCatalogProvider ¶
type RemoteModelCatalogProvider struct {
ID string
Name string
Kind RemoteModelCatalogProviderKind
BaseURL string
APIKey string
OAuth *OpenAIOAuthConfig
GitHubCopilotOAuth *GitHubCopilotOAuthConfig
HTTPClient *http.Client
}
type RemoteModelCatalogProviderKind ¶
type RemoteModelCatalogProviderKind string
const ( RemoteModelCatalogProviderOpenAI RemoteModelCatalogProviderKind = "openai" RemoteModelCatalogProviderAnthropic RemoteModelCatalogProviderKind = "anthropic" RemoteModelCatalogProviderGoogle RemoteModelCatalogProviderKind = "google" RemoteModelCatalogProviderOpenAICompatible RemoteModelCatalogProviderKind = "openai_compatible" RemoteModelCatalogProviderGitHubCopilot RemoteModelCatalogProviderKind = "github_copilot" RemoteModelCatalogProviderModelsDev RemoteModelCatalogProviderKind = "models_dev" )
type Request ¶
type Request struct {
SessionID string
TurnID string
AgentID string
Model ModelRef
MaxOutputTokens int
// PromptCacheRetention is currently honored by OpenAI requests. Empty uses
// the provider default.
PromptCacheRetention string
OpenAIResponsesStore bool
OpenAIEncryptedReasoningReplay bool
ThinkingSupported bool
ThinkingEnabled bool
ThinkingMode string
Instructions string
CacheablePrefix string
DynamicSuffix string
Inputs []Input
Tools []Tool
RawSSEObserver RawSSEObserver
}
func NormalizePromptRequest ¶
NormalizePromptRequest rewrites request prompt fields into their canonical form so Instructions always matches the effective provider prompt text.
func PreparePromptRequest ¶
PreparePromptRequest normalizes the request and applies any provider/model- specific prompt supplement so callers can reason about the same provider- facing prompt shape used during execution.
type RequestTokenBreakdown ¶
type RequestTokenBreakdown struct {
PromptTokens int
ConversationTokens int
ToolNameTokens int
ToolDescriptionTokens int
ToolSchemaTokens int
ToolCount int
TotalTokens int
}
func EstimateRequestTokenBreakdown ¶
func EstimateRequestTokenBreakdown(req Request) RequestTokenBreakdown
EstimateRequestTokenBreakdown returns the same rough token estimate used for budgeting, but split into prompt, conversation, and tool-surface components.
func (RequestTokenBreakdown) ToolSurfaceTokens ¶
func (b RequestTokenBreakdown) ToolSurfaceTokens() int
type RequestTrace ¶
func StreamRequestTrace ¶
func StreamRequestTrace(stream Stream) (RequestTrace, bool)
type RetryHint ¶
func RetryHintForError ¶
type RouteAttempt ¶
type RouteError ¶
type RouteError struct {
// contains filtered or unexported fields
}
func (*RouteError) Error ¶
func (e *RouteError) Error() string
func (*RouteError) RouteTrace ¶
func (e *RouteError) RouteTrace() RouteTrace
func (*RouteError) Unwrap ¶
func (e *RouteError) Unwrap() []error
type RouteTrace ¶
type RouteTrace struct {
RequestedModel ModelRef
Attempts []RouteAttempt
}
func ErrorRouteTrace ¶
func ErrorRouteTrace(err error) (RouteTrace, bool)
func StreamRouteTrace ¶
func StreamRouteTrace(stream Stream) (RouteTrace, bool)
func (RouteTrace) SelectedModel ¶
func (t RouteTrace) SelectedModel() (ModelRef, bool)
type RoutedClient ¶
type RoutedClient struct {
// contains filtered or unexported fields
}
func NewRoutedClient ¶
func NewRoutedClient(clients map[string]Client) (*RoutedClient, error)
func (*RoutedClient) CountTokens ¶
func (c *RoutedClient) CountTokens(ctx context.Context, req Request) (int, TokenCountSource, error)
func (*RoutedClient) SetRouteObserver ¶
func (c *RoutedClient) SetRouteObserver(observer func(RouteAttempt))
type RoutedEmbedder ¶
type RoutedEmbedder struct {
// contains filtered or unexported fields
}
func NewRoutedEmbedder ¶
func NewRoutedEmbedder(embedders map[string]Embedder) *RoutedEmbedder
func (*RoutedEmbedder) Embed ¶
func (r *RoutedEmbedder) Embed(ctx context.Context, req EmbeddingRequest) ([][]float32, error)
type SliceStream ¶
type SliceStream struct {
// contains filtered or unexported fields
}
func NewSliceStream ¶
func NewSliceStream(events []Event) *SliceStream
func NewSliceStreamWithFinishReason ¶
func NewSliceStreamWithFinishReason(events []Event, reason FinishReason) *SliceStream
func (*SliceStream) Close ¶
func (s *SliceStream) Close() error
func (*SliceStream) FinishReason ¶
func (s *SliceStream) FinishReason() FinishReason
func (*SliceStream) Recv ¶
func (s *SliceStream) Recv() (Event, error)
type SystemPromptResolution ¶
type SystemPromptResolution struct {
Content string
CanonicalName string
SourcePath string
UserOverride bool
}
func ResolveSystemPrompt ¶
func ResolveSystemPrompt(providerID, modelID string) SystemPromptResolution
type TokenCountSource ¶
type TokenCountSource string
const ( TokenCountSourceEstimated TokenCountSource = "estimated" TokenCountSourceExact TokenCountSource = "exact" )
func CountRequestTokens ¶
type Tool ¶
type Tool struct {
Name string
Description string
Kind ToolKind
InputSchema string
InputFormat *ToolInputFormat
ParallelSafe bool `json:"-"`
}
func (Tool) KindOrDefault ¶
type ToolInputFormat ¶
type UsageReport ¶
type UsageReport struct {
RequestID string
Model string
InputTokens int
CacheReadInputTokens int
CacheWriteInputTokens int
OutputTokens int
ReasoningTokens int
TotalTokens int
}
func StreamUsageReport ¶
func StreamUsageReport(stream Stream) (UsageReport, bool)
Source Files
¶
- anthropic_client.go
- anthropic_stream.go
- attachments.go
- auth_debug.go
- auth_store.go
- copilot_models.go
- custom_tools.go
- doc.go
- embedder.go
- error.go
- github_copilot_compat.go
- github_copilot_oauth.go
- google_client.go
- google_stream.go
- model.go
- model_capacity.go
- model_catalog.go
- model_catalog_adapters.go
- model_catalog_cache.go
- model_catalog_helpers.go
- model_catalog_local.go
- model_catalog_openai.go
- model_catalog_refresh.go
- model_catalog_remote.go
- model_output_limits.go
- native_conversation.go
- openai_auth.go
- openai_authorized_http.go
- openai_base_url.go
- openai_chat_completions.go
- openai_chat_stream.go
- openai_client.go
- openai_compatible_client.go
- openai_embedder.go
- openai_input_tokens.go
- openai_oauth.go
- openai_oauth_browser.go
- openai_prompt_cache.go
- openai_reasoning.go
- openai_stream.go
- prompt.go
- prompt_cache_support.go
- prompting_client.go
- prompts_embed.go
- provider.go
- provider_alias.go
- reasoning_support.go
- reasoning_variant.go
- reasoning_variant_error.go
- request_prompt.go
- request_sanitize.go
- request_tokens.go
- request_tool_ids.go
- request_trace.go
- router.go
- think_tag_router.go
- tool_result_serialization.go
- tool_schema_normalize.go