Documentation
¶
Overview ¶
Package ai provides the interactive AI-provider setup initialiser.
It registers a setup [Initialiser] (and the `init ai` command via NewCmdInitAI) that walks the user through choosing an AI provider (Claude, OpenAI, Gemini) and recording its credentials — via an env-var reference, the OS keychain, or a literal in config — using the shared credential storage modes. It configures the provider for later use; it does not construct chat clients (see pkg/chat).
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNoKeyEntered = errors.NewSentinel("gtb.setup.ai.no_key_entered", "no API key was entered")
ErrNoKeyEntered is returned when the key prompt closes without a key in a mode that stores one and there is no existing key to keep. The password prompt needs a terminal, so over a pipe it reads nothing; reporting success then would store nothing and say otherwise.
var ErrProviderNotLinked = errors.NewSentinel("gtb.setup.ai.provider_not_linked", "this tool does not link the chosen chat provider")
ErrProviderNotLinked is a provider chosen for init ai that this binary does not register: writing it to config would only fail at first use.
Functions ¶
func IsAIConfigured ¶
func IsAIConfigured(p props.ConfigProvider) bool
IsAIConfigured checks if the AI provider and its corresponding key are configured.
func NewCmdInitAI ¶
NewCmdInitAI creates the `init ai` subcommand.
Types ¶
type AIConfig ¶
type AIConfig struct {
Provider string
APIKey string
ExistingKey string // populated from disk config; used to show masked hint in the form
// StorageMode selects how the API key is persisted. Defaults to
// [credentials.ModeEnvVar] when the wizard presents the choice.
// [credentials.ModeLiteral] is refused when the process runs
// under CI (CI=true); the only accepted CI credential path is a
// platform-injected environment variable referenced via env-var
// mode.
StorageMode credentials.Mode
// EnvVarName is the environment variable name recorded in
// {provider}.api.env when [StorageMode] is [credentials.ModeEnvVar].
// Ignored in literal mode.
EnvVarName string
}
AIConfig holds the AI provider configuration captured from the form.
type AIInitialiser ¶
type AIInitialiser struct{}
AIInitialiser implements setup.Initialiser for AI provider configuration.
func NewAIInitialiser ¶
func NewAIInitialiser(_ *props.Props) *AIInitialiser
NewAIInitialiser creates a new AIInitialiser. Its asset bundle is registered from init() via setup.RegisterAssets, applied for enabled features at root construction.
func (*AIInitialiser) Configure ¶
Configure runs the interactive AI configuration forms and writes the results through the editor.
func (*AIInitialiser) IsConfigured ¶
func (a *AIInitialiser) IsConfigured(cfg config.Reader) bool
IsConfigured checks if a valid AI provider is set and its corresponding API key is present.
func (*AIInitialiser) Name ¶
func (a *AIInitialiser) Name() string
Name returns the human-readable name for this initialiser.