chatprovider

package
v2.37.5 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: AGPL-3.0 Imports: 28 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
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.

View Source
const AnthropicBetaContext1M = "context-1m-2025-08-07"

AnthropicBetaContext1M is the beta token for Anthropic's 1M context window.

View Source
const HeaderAnthropicBeta = "Anthropic-Beta"

HeaderAnthropicBeta names Anthropic's beta feature header.

Variables

This section is empty.

Functions

func AgentsSupportsProvider added in v2.35.0

func AgentsSupportsProvider(provider string) bool

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

func CoderHeaders(chat database.Chat) map[string]string

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

func InlineImageCapBytes(provider string) (int, bool)

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 IsValidReasoningEffort(value string) bool

func NormalizeProvider

func NormalizeProvider(provider string) string

NormalizeProvider canonicalizes a provider name.

func ProviderAllowsAmbientCredentials added in v2.33.0

func ProviderAllowsAmbientCredentials(provider string) bool

ProviderAllowsAmbientCredentials reports whether provider can use ambient credentials from the Coder server instead of an explicit API key.

func ProviderDisplayName

func ProviderDisplayName(provider string) string

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

func ReasoningEffortLessOrEqual(a, b string) bool

ReasoningEffortLessOrEqual reports whether a is lower than or equal to b on the global effort scale. Unknown values return false.

func ResolveModelWithProviderHint

func ResolveModelWithProviderHint(modelName, providerHint string) (provider string, model string, err error)

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 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
}

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,
	openAIConfig *codersdk.ChatModelOpenAIConfig,
) (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. openAIConfig carries the model's OpenAI client settings, including the transport override applied here.

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

func (m Model) AcceptsFilePartMediaType(mediaType string) bool

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) ModelID added in v2.37.0

func (m Model) ModelID() string

func (Model) Provider added in v2.37.0

func (m Model) Provider() string

func (Model) Transport added in v2.37.0

func (m Model) Transport() chatopenai.Transport

func (Model) Valid added in v2.37.0

func (m Model) Valid() bool

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 MergeProviderAPIKeys

func MergeProviderAPIKeys(fallback ProviderAPIKeys, providers []ConfiguredProvider) ProviderAPIKeys

MergeProviderAPIKeys overlays configured provider keys over fallback keys.

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
	UnavailableReason codersdk.ChatModelProviderUnavailableReason
}

ProviderAvailability describes whether a provider has a usable API key and, if not, why.

type UserProviderKey

type UserProviderKey struct {
	ChatProviderID uuid.UUID
	APIKey         string
}

UserProviderKey is a user-supplied API key for a specific provider.

Jump to

Keyboard shortcuts

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