Documentation
¶
Overview ¶
Package chat is go-tool-base's thin adapter over the standalone multi-provider chat client gitlab.com/phpboyscout/go/chat. It maps GTB's Props/Viper config into the module's typed Settings (see config_adapter.go), owns the GTB config key schema (see constants.go), and blank-imports every provider module (see providers.go). The declarations below re-export the module's public API so the existing GTB call sites keep referencing chat.Config, chat.New, etc. from this package unchanged.
Index ¶
- Constants
- Variables
- func GenerateSchema[T any]() any
- type ChatClient
- func NewFromProps(ctx context.Context, p *props.Props, cfg Config) (ChatClient, error)
- func NewWithFallback(ctx context.Context, p *props.Props, cfg Config, opts ...FallbackOption) (ChatClient, error)
- func NewWithFallbackFromProps(ctx context.Context, p *props.Props, cfg Config, opts ...FallbackOption) (ChatClient, error)
- type Config
- type ConversationStore
- type CredentialConfig
- type FailoverDecision
- type FailoverPolicy
- type FallbackConfig
- type FallbackOption
- type FileStoreOption
- type HTTPStatusExtractor
- type KeychainLookup
- type Media
- type PersistentChatClient
- type Provider
- type ProviderFactory
- type ResolvedMedia
- type RuntimeConfig
- type Settings
- type Snapshot
- type SnapshotSummary
- type StreamCallback
- type StreamEvent
- type StreamEventType
- type StreamToolCall
- type StreamingChatClient
- type Tool
- type ToolCall
- type ToolResult
- type Usage
- type UsageTracker
Constants ¶
const ( ConfigKeyOpenAIKey = configRootOpenAI + ".key" ConfigKeyOpenAIEnv = configRootOpenAI + ".env" ConfigKeyOpenAIKeychain = configRootOpenAI + ".keychain" EnvOpenAIKey = "OPENAI_API_KEY" ConfigKeyClaudeKey = configRootClaude + ".key" ConfigKeyClaudeEnv = configRootClaude + ".env" ConfigKeyClaudeKeychain = configRootClaude + ".keychain" EnvClaudeKey = "ANTHROPIC_API_KEY" ConfigKeyGeminiKey = configRootGemini + ".key" ConfigKeyGeminiEnv = configRootGemini + ".env" ConfigKeyGeminiKeychain = configRootGemini + ".keychain" EnvGeminiKey = "GEMINI_API_KEY" )
Per-provider credential config keys.
- ConfigKey<Provider>Key — full config path for the literal API key.
- ConfigKey<Provider>Env — full config path for an env-var reference (the value stored is the NAME of an env var holding the secret).
- ConfigKey<Provider>Keychain — full config path for an OS-keychain reference.
- Env<Provider>Key — well-known unprefixed environment variable used as the ecosystem fallback when no config is present.
const ( ProviderOpenAI = gochat.ProviderOpenAI ProviderOpenAICompatible = gochat.ProviderOpenAICompatible ProviderClaude = gochat.ProviderClaude ProviderClaudeLocal = gochat.ProviderClaudeLocal ProviderGemini = gochat.ProviderGemini EventTextDelta = gochat.EventTextDelta EventToolCallStart = gochat.EventToolCallStart EventToolCallEnd = gochat.EventToolCallEnd EventComplete = gochat.EventComplete EventError = gochat.EventError FailoverNext = gochat.FailoverNext FailoverFatal = gochat.FailoverFatal DefaultModelClaude = gochat.DefaultModelClaude DefaultModelOpenAI = gochat.DefaultModelOpenAI DefaultModelGemini = gochat.DefaultModelGemini DefaultMaxSteps = gochat.DefaultMaxSteps DefaultMaxTokensClaude = gochat.DefaultMaxTokensClaude DefaultMaxTokensOpenAI = gochat.DefaultMaxTokensOpenAI DefaultMaxTokensGemini = gochat.DefaultMaxTokensGemini DefaultChatRequestTimeout = gochat.DefaultChatRequestTimeout MaxBaseURLLength = gochat.MaxBaseURLLength )
Re-exported constants (provider names, streaming events, defaults).
const ConfigKeyAIFallbackEnabled = "ai.fallback.enabled"
ConfigKeyAIFallbackEnabled toggles cross-provider failover.
const ConfigKeyAIFallbackProviders = "ai.fallback.providers"
ConfigKeyAIFallbackProviders is the ordered list of provider names to fail over across; index 0 is the primary.
const ConfigKeyAIProvider = "ai.provider"
ConfigKeyAIProvider is the config key for the AI provider.
const ConfigKeyAIRequestTimeout = "ai.request_timeout"
ConfigKeyAIRequestTimeout is the config key for the per-request AI timeout (a duration like "8m"). Overrides DefaultChatRequestTimeout.
const EnvAIProvider = "AI_PROVIDER"
EnvAIProvider is the environment variable for overriding the AI provider.
Variables ¶
var ( ErrInvalidBaseURL = gochat.ErrInvalidBaseURL ErrInvalidSnapshotID = gochat.ErrInvalidSnapshotID ErrMediaRejected = gochat.ErrMediaRejected ErrMediaUnsupported = gochat.ErrMediaUnsupported DefaultFailoverPolicy = gochat.DefaultFailoverPolicy )
Re-exported sentinels and the default failover policy.
var ( New = gochat.New NewSnapshot = gochat.NewSnapshot NewFileStore = gochat.NewFileStore WithEncryption = gochat.WithEncryption WithLogger = gochat.WithLogger GenerateEncryptionKey = gochat.GenerateEncryptionKey ValidateBaseURL = gochat.ValidateBaseURL ValidateSnapshotID = gochat.ValidateSnapshotID ValidateMediaSet = gochat.ValidateMediaSet NewFallback = gochat.NewFallback NewFallbackFromSettings = gochat.NewFallbackFromSettings NewFallbackFromConfigs = gochat.NewFallbackFromConfigs NewWithFallbackSettings = gochat.NewWithFallbackSettings WithFallbackLogger = gochat.WithFallbackLogger WithFailoverPolicy = gochat.WithFailoverPolicy WithOnFailover = gochat.WithOnFailover WithStrictToolContext = gochat.WithStrictToolContext RegisterProvider = gochat.RegisterProvider RegisterStatusExtractor = gochat.RegisterStatusExtractor ResolveAPIKey = gochat.ResolveAPIKey ChatHTTPClient = gochat.ChatHTTPClient DispatchToolExecution = gochat.DispatchToolExecution ExecuteTool = gochat.ExecuteTool ExecuteToolsParallel = gochat.ExecuteToolsParallel NewUsage = gochat.NewUsage )
Re-exported constructors and helpers (function values forwarding to the module).
Functions ¶
func GenerateSchema ¶
GenerateSchema forwards to the module's generic schema generator (a generic function cannot be re-exported as a value, so it is wrapped).
Types ¶
type ChatClient ¶
type ChatClient = gochat.ChatClient
ChatClient is the multi-provider chat client interface.
func NewFromProps ¶ added in v0.30.0
NewFromProps adapts GTB props into typed chat settings, then constructs a provider client with the reusable package constructor.
func NewWithFallback ¶ added in v0.22.0
func NewWithFallback(ctx context.Context, p *props.Props, cfg Config, opts ...FallbackOption) (ChatClient, error)
NewWithFallback adapts GTB props and framework config before constructing a chat client with optional provider failover.
func NewWithFallbackFromProps ¶ added in v0.30.0
func NewWithFallbackFromProps(ctx context.Context, p *props.Props, cfg Config, opts ...FallbackOption) (ChatClient, error)
NewWithFallbackFromProps adapts GTB props into package-owned chat settings, then constructs either a single provider client or a fallback composite.
type ConversationStore ¶
type ConversationStore = gochat.ConversationStore
ConversationStore persists conversation snapshots.
type CredentialConfig ¶ added in v0.30.0
type CredentialConfig = gochat.CredentialConfig
CredentialConfig is the package-owned provider credential shape.
type FailoverDecision ¶ added in v0.22.0
type FailoverDecision = gochat.FailoverDecision
FailoverDecision is the outcome of classifying a provider error.
type FailoverPolicy ¶ added in v0.22.0
type FailoverPolicy = gochat.FailoverPolicy
FailoverPolicy classifies a provider error for failover.
type FallbackConfig ¶ added in v0.30.0
type FallbackConfig = gochat.FallbackConfig
FallbackConfig is the package-owned shape for ai.fallback.*.
type FallbackOption ¶ added in v0.22.0
type FallbackOption = gochat.FallbackOption
FallbackOption configures a fallback composite.
type FileStoreOption ¶
type FileStoreOption = gochat.FileStoreOption
FileStoreOption configures a FileStore.
type HTTPStatusExtractor ¶ added in v0.31.1
type HTTPStatusExtractor = gochat.HTTPStatusExtractor
HTTPStatusExtractor pulls an HTTP status from a provider error.
type KeychainLookup ¶ added in v0.31.1
type KeychainLookup = gochat.KeychainLookup
KeychainLookup resolves a keychain reference to a secret.
type PersistentChatClient ¶
type PersistentChatClient = gochat.PersistentChatClient
PersistentChatClient is the optional Save/Restore interface.
type ProviderFactory ¶
type ProviderFactory = gochat.ProviderFactory
ProviderFactory constructs a ChatClient for a provider.
type ResolvedMedia ¶ added in v0.31.1
type ResolvedMedia = gochat.ResolvedMedia
ResolvedMedia is an attachment that passed the safety filter.
type RuntimeConfig ¶ added in v0.30.0
type RuntimeConfig = gochat.RuntimeConfig
RuntimeConfig is the package-owned shape for the ai.* config section.
type SnapshotSummary ¶
type SnapshotSummary = gochat.SnapshotSummary
SnapshotSummary is the metadata for a stored snapshot.
type StreamCallback ¶
type StreamCallback = gochat.StreamCallback
StreamCallback receives streaming events.
type StreamEventType ¶
type StreamEventType = gochat.StreamEventType
StreamEventType enumerates streaming event kinds.
type StreamToolCall ¶
type StreamToolCall = gochat.StreamToolCall
StreamToolCall describes a tool call surfaced during streaming.
type StreamingChatClient ¶
type StreamingChatClient = gochat.StreamingChatClient
StreamingChatClient is the optional streaming interface.
type UsageTracker ¶ added in v0.31.1
type UsageTracker = gochat.UsageTracker
UsageTracker accumulates per-round-trip usage (embed to satisfy Usage()).