Documentation
¶
Index ¶
- Constants
- func AgentsSupportsProvider(provider string) bool
- func AnthropicThinkingDisplayFromChat(value *string) *fantasyanthropic.ThinkingDisplay
- func BetaHeadersFromCallConfig(providerName string, config *codersdk.ChatModelCallConfig) map[string]string
- func CoderHeaders(chat database.Chat) map[string]string
- func GoogleThinkingLevelFromChat(value *string) *fantasygoogle.ThinkingLevel
- func InlineImageCapBytes(provider string) (int, bool)
- func IsValidReasoningEffort(value string) bool
- func NormalizeProvider(provider string) string
- func ProviderAllowsAmbientCredentials(provider string) bool
- func ProviderDisplayName(provider string) string
- func ProviderOptionsForCall(model Model, config codersdk.ChatModelCallConfig, requestedEffort *string) fantasy.ProviderOptions
- func PruneDisabledProviderKeys(keys *ProviderAPIKeys, enabledProviders map[string]struct{})
- func ReasoningEffortLessOrEqual(a, b string) bool
- func ResolveModelWithProviderHint(modelName, providerHint string) (provider string, model string, err error)
- func ResolveReasoningEffort(requested *string, config *codersdk.ChatModelReasoningEffortConfig) *string
- func SelectableReasoningEfforts(config *codersdk.ChatModelReasoningEffortConfig) []string
- func ToolResultMediaOmission(transportProvider, configuredProvider, mediaType string, size int) (string, bool)
- func UnsupportedProviders(configured []ConfiguredProvider) []codersdk.ChatUnsupportedProvider
- func UserAgent() string
- type ConfiguredProvider
- type Model
- func (m Model) AcceptsFilePartMediaType(mediaType string) bool
- func (m Model) LanguageModel() fantasy.LanguageModel
- func (m Model) ModelID() string
- func (m Model) Provider() string
- func (m Model) Transport() chatopenai.Transport
- func (m Model) Valid() bool
- func (m Model) WithLanguageModel(lm fantasy.LanguageModel) Model
- type ProviderAPIKeys
- type ProviderAvailability
- type UserProviderKey
Constants ¶
const ( // HeaderCoderOwnerID identifies the Coder user who owns the chat. HeaderCoderOwnerID = "X-Coder-Owner-Id" // HeaderCoderChatID identifies the top-level (parent) chat. // For root chats this is the chat's own ID; for subchats it // is the parent chat's ID. HeaderCoderChatID = "X-Coder-Chat-Id" // HeaderCoderSubchatID identifies the current subchat. Only // present when the request originates from a child chat. HeaderCoderSubchatID = "X-Coder-Subchat-Id" // HeaderCoderWorkspaceID identifies the workspace associated // with the chat, if any. HeaderCoderWorkspaceID = "X-Coder-Workspace-Id" )
Header constants sent on upstream LLM API requests so that intermediaries (e.g. aibridged) can correlate traffic back to Coder entities.
const AnthropicBetaContext1M = "context-1m-2025-08-07"
AnthropicBetaContext1M is the beta token for Anthropic's 1M context window.
const HeaderAnthropicBeta = "Anthropic-Beta"
HeaderAnthropicBeta names Anthropic's beta feature header.
Variables ¶
This section is empty.
Functions ¶
func AgentsSupportsProvider ¶ added in v2.35.0
AgentsSupportsProvider reports whether the Agents harness can use the provider type.
func AnthropicThinkingDisplayFromChat ¶ added in v2.35.0
func AnthropicThinkingDisplayFromChat(value *string) *fantasyanthropic.ThinkingDisplay
AnthropicThinkingDisplayFromChat normalizes chat-config thinking display values for Anthropic and returns the canonical provider display value.
func BetaHeadersFromCallConfig ¶ added in v2.36.0
func BetaHeadersFromCallConfig(providerName string, config *codersdk.ChatModelCallConfig) map[string]string
BetaHeadersFromCallConfig returns beta feature headers for Anthropic and Bedrock calls.
func CoderHeaders ¶
CoderHeaders builds the set of Coder identity headers to attach to outgoing LLM API requests for the given chat.
func GoogleThinkingLevelFromChat ¶ added in v2.37.0
func GoogleThinkingLevelFromChat(value *string) *fantasygoogle.ThinkingLevel
GoogleThinkingLevelFromChat normalizes chat-config thinking level values for Google and returns the canonical provider level value.
func InlineImageCapBytes ¶ added in v2.34.0
InlineImageCapBytes returns the per-image byte cap for inline image parts, or (0, false) when no documented cap applies. Bedrock shares Anthropic's cap because fantasy's bedrock provider wraps the anthropic client.
func IsValidReasoningEffort ¶ added in v2.36.0
func NormalizeProvider ¶
NormalizeProvider canonicalizes a provider name.
func ProviderAllowsAmbientCredentials ¶ added in v2.33.0
ProviderAllowsAmbientCredentials reports whether a direct client for the provider type can use ambient credentials from the Coder server instead of an explicit API key. Individual provider configs can also support ambient credentials through ConfiguredProvider.SupportsAmbientCredentials.
func ProviderDisplayName ¶
ProviderDisplayName returns a default display name for a provider.
func ProviderOptionsForCall ¶ added in v2.37.0
func ProviderOptionsForCall( model Model, config codersdk.ChatModelCallConfig, requestedEffort *string, ) fantasy.ProviderOptions
ProviderOptionsForCall builds the provider options for one inference call. Config conversion and reasoning effort both create OpenAI option structs, so owning them together is what keeps their type aligned with the model's transport. requestedEffort is the caller's per-turn choice, which the config's bounds clamp.
func PruneDisabledProviderKeys ¶
func PruneDisabledProviderKeys(keys *ProviderAPIKeys, enabledProviders map[string]struct{})
PruneDisabledProviderKeys removes entries from keys that do not belong to an enabled provider. It clears ByProvider, BaseURLByProvider, and RegionByProvider entries for disabled providers and zeroes the legacy OpenAI and Anthropic fields when those providers are not enabled.
func ReasoningEffortLessOrEqual ¶ added in v2.36.0
ReasoningEffortLessOrEqual reports whether a is lower than or equal to b on the global effort scale. Unknown values return false.
func ResolveReasoningEffort ¶ added in v2.36.0
func ResolveReasoningEffort( requested *string, config *codersdk.ChatModelReasoningEffortConfig, ) *string
ResolveReasoningEffort computes the effective reasoning effort for a generation. The requested per-turn value wins over the config's default, and the result is clamped to the config's max on the global scale. Returns nil when the model config has no reasoning effort configured, no usable value remains, or the max is unknown.
func SelectableReasoningEfforts ¶ added in v2.36.0
func SelectableReasoningEfforts( config *codersdk.ChatModelReasoningEffortConfig, ) []string
func ToolResultMediaOmission ¶
func ToolResultMediaOmission(transportProvider, configuredProvider, mediaType string, size int) (string, bool)
ToolResultMediaOmission reports media unsupported by the transport or upstream provider. configuredProvider supplies vendor limits hidden by a shared OpenAI-compatible transport.
func UnsupportedProviders ¶ added in v2.35.0
func UnsupportedProviders(configured []ConfiguredProvider) []codersdk.ChatUnsupportedProvider
UnsupportedProviders returns the configured providers the Agents harness cannot use, deduplicated by provider type.
func UserAgent ¶
func UserAgent() string
UserAgent returns the User-Agent string sent on all outgoing LLM API requests made by Coder's built-in chat (chatd). The format mirrors conventions used by other coding agents so that LLM providers can identify traffic originating from Coder.
Example: coder-agents/v2.21.0 (linux/amd64)
Types ¶
type ConfiguredProvider ¶
type ConfiguredProvider struct {
ProviderID uuid.UUID
Provider string
APIKey string
BaseURL string
Region string
CentralAPIKeyEnabled bool
AllowUserAPIKey bool
AllowCentralAPIKeyFallback bool
// SupportsAmbientCredentials reports that the provider configuration supports
// ambient credentials. It does not verify that credentials are available.
SupportsAmbientCredentials bool
}
ConfiguredProvider is an enabled provider loaded from database config.
type Model ¶ added in v2.37.0
type Model struct {
// contains filtered or unexported fields
}
Model pairs a language model client with the facts resolved when it was built. Its fields are unexported and nothing sets transport except NewModel, which derives it from the client, so no caller can choose a transport that disagrees with the client it wraps.
func ModelFromConfig ¶
func ModelFromConfig( providerHint string, modelName string, providerKeys ProviderAPIKeys, userAgent string, extraHeaders map[string]string, httpClient *http.Client, callConfig *codersdk.ChatModelCallConfig, ) (Model, error)
ModelFromConfig resolves a provider/model pair and constructs a fantasy language model client using the provided provider credentials. The userAgent is sent as the User-Agent header on every outgoing LLM API request. extraHeaders, when non-nil, are sent as additional HTTP headers on every request. httpClient, when non-nil, is used for all provider HTTP requests. callConfig carries the model's client-scoped OpenAI settings applied here: the transport override and reasoning mode.
func NewModel ¶ added in v2.37.0
func NewModel(lm fantasy.LanguageModel, openAIConfig *codersdk.ChatModelOpenAIConfig) Model
NewModel pairs an already-built client with the transport resolved from that client's own identity. Callers must pass the config the client was built with, the one degree of freedom Model cannot police. ModelFromConfig is the only production caller.
func (Model) AcceptsFilePartMediaType ¶ added in v2.37.0
AcceptsFilePartMediaType reports whether m's provider accepts mediaType as a file content part rather than silently dropping it. Callers replace rejected parts with text, so a false negative costs fidelity while a false positive loses the attachment entirely. Unknown providers therefore return false.
func (Model) LanguageModel ¶ added in v2.37.0
func (m Model) LanguageModel() fantasy.LanguageModel
func (Model) Transport ¶ added in v2.37.0
func (m Model) Transport() chatopenai.Transport
func (Model) Valid ¶ added in v2.37.0
Valid reports whether m wraps a client rather than being the zero value.
func (Model) WithLanguageModel ¶ added in v2.37.0
func (m Model) WithLanguageModel(lm fantasy.LanguageModel) Model
WithLanguageModel replaces the wrapped client and keeps the resolved transport, because decorators such as debug recording do not change what the client speaks. It panics on an invalid receiver or a replacement that reports a different identity, because both would pair the kept transport with a client it was not resolved from.
type ProviderAPIKeys ¶
type ProviderAPIKeys struct {
OpenAI string
Anthropic string
ByProvider map[string]string
BaseURLByProvider map[string]string
RegionByProvider map[string]string
}
ProviderAPIKeys contains API keys for provider calls.
func ResolveUserProviderKeys ¶
func ResolveUserProviderKeys( fallback ProviderAPIKeys, providers []ConfiguredProvider, userKeys []UserProviderKey, ) (ProviderAPIKeys, map[string]ProviderAvailability)
ResolveUserProviderKeys computes effective API keys and per-provider availability for a given user. It considers the provider's credential policy flags alongside central (DB/deployment) keys and the user's personal keys.
func (ProviderAPIKeys) APIKey ¶
func (k ProviderAPIKeys) APIKey(provider string) string
APIKey returns the effective API key for a provider.
func (ProviderAPIKeys) BaseURL ¶
func (k ProviderAPIKeys) BaseURL(provider string) string
BaseURL returns the configured base URL for a provider.
func (ProviderAPIKeys) Empty ¶ added in v2.34.0
func (k ProviderAPIKeys) Empty() bool
Empty reports whether no provider keys or base URL overrides are set.
func (ProviderAPIKeys) HasProvider ¶ added in v2.33.0
func (k ProviderAPIKeys) HasProvider(provider string) bool
HasProvider reports whether a provider has an explicit resolved entry in the provider key map, even when the resolved key is empty.
func (ProviderAPIKeys) Region ¶ added in v2.35.0
func (k ProviderAPIKeys) Region(provider string) string
Region returns the configured region for a provider.
type ProviderAvailability ¶
type ProviderAvailability struct {
Available bool
}
ProviderAvailability describes whether a provider has a usable API key and, if not, why.
type UserProviderKey ¶
UserProviderKey is a user-supplied API key for a specific provider.