Documentation
¶
Overview ¶
Package chat is go-tool-base's framework-integration layer over the standalone multi-provider chat client gitlab.com/phpboyscout/go/chat.
It maps GTB's Props configuration into the module's typed Settings (see config_adapter.go via SettingsFromProps, NewFromProps and NewWithFallbackFromProps) and owns the GTB config-key schema (see constants.go). It registers no provider: the binary that ships one blank-imports its module (see ProviderModule). The adapter names go/chat types (chat.Config, chat.New, …) directly; they are no longer re-exported from this package.
Code that wants the pure chat client API without the GTB config container imports gitlab.com/phpboyscout/go/chat directly.
Index ¶
- Constants
- Variables
- func IsLocalCLI(provider gochat.Provider) bool
- func LinkedProviders(set features.Set) (linked, unregistered []gochat.Provider)
- func LinkedProvidersIn(set features.Set, registered []gochat.Provider) (linked, unregistered []gochat.Provider)
- func NeedsCredential(provider gochat.Provider) bool
- func NeedsToolServer(provider gochat.Provider) bool
- func NewFromProps(ctx context.Context, p *props.Props, cfg gochat.Config) (gochat.ChatClient, error)
- func NewWithFallback(ctx context.Context, p *props.Props, cfg gochat.Config, ...) (gochat.ChatClient, error)
- func NewWithFallbackFromProps(ctx context.Context, p *props.Props, cfg gochat.Config, ...) (gochat.ChatClient, error)
- func ProviderKeyOptional(provider gochat.Provider) bool
- func ProviderKeyResolves(ctx context.Context, cfg credentialposture.Reader, provider gochat.Provider) (bool, error)
- func ProviderModule(provider gochat.Provider) (string, bool)
- func SettingsFromProps(p *props.Props, cfg gochat.Config) (gochat.Settings, error)
- type CredentialKeys
- type ProviderDisplay
- type ProviderModuleEntry
Constants ¶
const ( // ConfigKeyAIBaseURL overrides the API endpoint; required by // openai-compatible and azure-openai. ConfigKeyAIBaseURL = "ai.base_url" // ConfigKeyAIAPIVersion is the dated API version azure-openai requires. ConfigKeyAIAPIVersion = "ai.api_version" // ConfigKeyAIProject is the cloud project gemini-vertex addresses. ConfigKeyAIProject = "ai.project" // ConfigKeyAILocation is the region gemini-vertex and bedrock address. ConfigKeyAILocation = "ai.location" )
The addressing keys a few providers need. They apply to ai.provider only; a fallback member resolves its own endpoint (spec 0196 D6).
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" ConfigKeyAzureKey = configRootAzure + ".key" ConfigKeyAzureEnv = configRootAzure + ".env" ConfigKeyAzureKeychain = configRootAzure + ".keychain" EnvAzureKey = "AZURE_OPENAI_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 ConfigKeyAIClaudeLocal = "ai.claude.local"
ConfigKeyAIClaudeLocal is the legacy switch that routes generation through the local claude CLI.
const ConfigKeyAIFallback = "ai.fallback"
ConfigKeyAIFallback is the config section holding the fallback-provider chain.
const ConfigKeyAIModel = "ai.model"
ConfigKeyAIModel is the config key for the default model name.
const ConfigKeyAIProvider = configSectionAI + ".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.
const ToolServerModule = "gitlab.com/phpboyscout/go/chat-mcptools"
ToolServerModule is the module whose blank import serves a local-CLI provider its tools over MCP. Without it claude-local and codex-local refuse any tool (chat-anthropic and chat-openai v0.17.0).
Variables ¶
var ErrProviderUnset = errors.NewSentinel("gtb.chat.provider_unset", "no AI provider is configured")
ErrProviderUnset is a chat client asked for with no provider anywhere: not the caller's Config, not ai.provider, not AI_PROVIDER. The framework names no vendor as its default (spec 0196 D5); a tool's author does, through its embedded defaults, and an end user does through init ai.
Functions ¶
func IsLocalCLI ¶ added in v0.42.0
IsLocalCLI reports whether a provider drives a locally installed CLI, which authenticates on its own and so carries no credential in GTB's config.
func LinkedProviders ¶ added in v0.43.0
LinkedProviders is what this binary says it links, in the order the author chose: the chat providers declared as link features (a generated tool declares one per provider in cmd/<name>/chat.go, #81), or, for a tool that declared none, every provider the linked modules register. The two differ when a module carries more providers than the author selected; doctor and the init wizard speak about the author's choice.
Declared is the set's answer, Unregistered the declared providers whose module is not in the binary: a build mistake, never a configuration one.
func LinkedProvidersIn ¶ added in v0.43.0
func LinkedProvidersIn(set features.Set, registered []gochat.Provider) (linked, unregistered []gochat.Provider)
LinkedProvidersIn is LinkedProviders over an explicit registry listing, so a test states what is registered rather than registering it.
func NeedsCredential ¶ added in v0.43.0
NeedsCredential reports whether GTB holds a credential for the provider: a local CLI authenticates on its own, bedrock through the AWS chain and gemini-vertex through application default credentials, so none of them has a credential root in GTB's config.
func NeedsToolServer ¶ added in v0.46.0
NeedsToolServer reports whether a binary linking the provider needs ToolServerModule for the provider to accept tools.
func NewFromProps ¶ added in v0.30.0
func NewFromProps(ctx context.Context, p *props.Props, cfg gochat.Config) (gochat.ChatClient, error)
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 gochat.Config, opts ...gochat.FallbackOption) (gochat.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 gochat.Config, opts ...gochat.FallbackOption) (gochat.ChatClient, error)
NewWithFallbackFromProps adapts GTB props into package-owned chat settings, then constructs either a single provider client or a fallback composite.
The chain itself is the module's: NewWithFallbackSettings keeps the primary's model and addressing and lets every other member self-resolve, and the credential resolver below is how each member finds GTB's credential for it. GTB used to derive the per-member configs itself with a denylist that cleared the primary's model and would have carried addressing fields to every member (spec 0196 D6).
func ProviderKeyOptional ¶ added in v0.49.0
ProviderKeyOptional reports whether provider runs without a key: openai-compatible sends none, for a host that needs no authentication.
func ProviderKeyResolves ¶ added in v0.49.0
func ProviderKeyResolves(ctx context.Context, cfg credentialposture.Reader, provider gochat.Provider) (bool, error)
ProviderKeyResolves reports whether provider's key resolves through the walk chat.New reads, so doctor can say what the client will find. A provider GTB holds no key for reports true, and a configured rung that cannot be read is the error.
func ProviderModule ¶ added in v0.41.0
ProviderModule returns the module path whose blank import registers the provider, and reports whether the provider is one this adapter knows.
Types ¶
type CredentialKeys ¶ added in v0.43.0
type CredentialKeys struct {
Root, Env, Keychain, Literal, FallbackEnv string
}
CredentialKeys is where GTB keeps a provider's credential: the config root and the three storage-mode keys under it, plus the well-known environment variable the resolver falls back to.
func CredentialKeysFor ¶ added in v0.43.0
func CredentialKeysFor(provider gochat.Provider) (CredentialKeys, bool)
CredentialKeysFor derives a provider's credential keys from its root, and reports false for a provider that carries no GTB credential. Every list of these keys (init ai, config migrate, the posture descriptors) reads this one derivation.
func ProviderCredentialKeys ¶ added in v0.43.0
func ProviderCredentialKeys() []CredentialKeys
ProviderCredentialKeys is every credential GTB keeps for a chat provider, one per config root in the order the wizard offers them. The migration and the project-trust list read it rather than naming the roots again.
type ProviderDisplay ¶ added in v0.43.0
type ProviderDisplay struct {
ID gochat.Provider
Label string
// Gloss says what the provider is and what it needs, in a few words.
Gloss string
}
ProviderDisplay is how a provider is shown to a person: init ai's select, the generator's wizard and the --provider help all read this one table.
func DisplayFor ¶ added in v0.43.0
func DisplayFor(provider gochat.Provider) (ProviderDisplay, bool)
DisplayFor returns a provider's display, and whether the provider is known.
func ProviderDisplays ¶ added in v0.43.0
func ProviderDisplays() []ProviderDisplay
ProviderDisplays returns every known provider's display, in module-table order.
type ProviderModuleEntry ¶ added in v0.41.0
ProviderModuleEntry pairs a chat provider with the module whose blank import registers it.
func ProviderModules ¶ added in v0.41.0
func ProviderModules() []ProviderModuleEntry
ProviderModules returns every provider this adapter knows with its module, in a stable order.