Help us shape the future of Go! Take the 2026 Go Developer Survey

ai

package
v0.49.0 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: MIT Imports: 18 Imported by: 0

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

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

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

func NewCmdInitAI(p *props.Props) *cobra.Command

NewCmdInitAI creates the `init ai` subcommand.

func RunAIInit

func RunAIInit(ctx context.Context, p *props.Props, dir string) error

RunAIInit executes the AI configuration form and writes the results to the config file, which is seeded from the merged init template when absent.

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

func (a *AIInitialiser) Configure(ctx context.Context, p *props.Props, cfg setup.Editor) error

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.

Jump to

Keyboard shortcuts

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