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 ¶
This section is empty.
Functions ¶
func IsAIConfigured ¶
func IsAIConfigured(p props.ConfigProvider) bool
IsAIConfigured checks if the AI provider and its corresponding key are configured.
func NewCmdInitAI ¶
func NewCmdInitAI(p *props.Props, opts ...FormOption) *cobra.Command
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 {
// contains filtered or unexported fields
}
AIInitialiser implements setup.Initialiser for AI provider configuration.
func NewAIInitialiser ¶
func NewAIInitialiser(_ *props.Props, opts ...FormOption) *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.
type FormOption ¶
type FormOption func(*formConfig)
FormOption configures the AI init form for testability.
func WithAIForm ¶
func WithAIForm(creator func(*AIConfig) []*huh.Form) FormOption
WithAIForm allows injecting custom form creators for testing. The creator returns forms in order: [0] provider, [1] storage mode, [2] env-var name (or key input), [3] key input fallback.
Returning fewer forms is allowed — the runner skips stages whose slot is nil or absent.