Documentation
¶
Overview ¶
Package setup provides an interactive first-time setup wizard for AINative Code.
The setup wizard guides new users through the initial configuration process, including:
- LLM provider selection (Anthropic, OpenAI, Google Gemini, Ollama)
- API key input and validation
- Model selection with recommendations
- Optional AINative platform integration
- Extended thinking configuration
- Color scheme and UI preferences
The wizard creates a configuration file at ~/.ainative-code.yaml and an initialization marker at ~/.ainative-code-initialized to track first-time setup.
Interactive Mode ¶
By default, the wizard runs in interactive mode with a rich TUI powered by Bubble Tea. Users can navigate through steps using arrow keys and make selections interactively:
wizard := setup.NewWizard(ctx, setup.WizardConfig{
InteractiveMode: true,
SkipValidation: false,
})
result, err := wizard.Run()
Non-Interactive Mode ¶
For CI/CD environments or automated setups, the wizard supports non-interactive mode using environment variables:
export AINATIVE_PROVIDER=anthropic export AINATIVE_ANTHROPIC_API_KEY=sk-ant-... export AINATIVE_ANTHROPIC_MODEL=claude-3-5-sonnet-20241022 ainative-code setup --non-interactive
Validation ¶
The wizard validates API keys and credentials by default:
- Anthropic: Tests API key format and authentication
- OpenAI: Validates key format and tests API access
- Google: Checks API key validity
- Ollama: Verifies server connectivity and model availability
Validation can be skipped for faster setup:
ainative-code setup --skip-validation
First-Run Detection ¶
The wizard automatically detects first-time runs by checking for the initialization marker file. Users can force re-run setup:
ainative-code setup --force
Configuration Structure ¶
The generated configuration includes:
- App metadata (name, version, environment)
- LLM provider settings with defaults
- Platform authentication (optional)
- Performance tuning (cache, concurrency)
- Logging configuration
- Security settings
Provider-Specific Configuration ¶
Anthropic (Claude):
- API key validation (must start with "sk-ant-")
- Model selection (Sonnet 3.5, Opus 3, etc.)
- Extended thinking mode
- Prompt caching preferences
OpenAI (GPT):
- API key validation (must start with "sk-")
- Model selection (GPT-4 Turbo, GPT-4, GPT-3.5)
- Organization ID (optional)
Google (Gemini):
- API key validation
- Model selection (Gemini Pro, Gemini Pro Vision)
- Project ID and location (optional)
Ollama (Local):
- Server URL (default: http://localhost:11434)
- Model name (must be pre-downloaded)
- Connection validation
Error Handling ¶
The wizard handles errors gracefully:
- Invalid API keys: Clear error messages with help links
- Network failures: Distinguishes from validation failures
- User cancellation: Clean exit without partial state
- File system errors: Directory creation and permissions
Testing ¶
The package includes comprehensive tests for:
- Configuration building for all providers
- API key validation
- File operations (writing config, creating markers)
- First-run detection
- Non-interactive mode
- Error cases
Example usage in tests:
wizard := setup.NewWizard(ctx, setup.WizardConfig{
InteractiveMode: false,
SkipValidation: true,
})
wizard.SetSelections(map[string]interface{}{
"provider": "anthropic",
"anthropic_api_key": "sk-ant-test",
})
result, err := wizard.Run()
Index ¶
- func CheckFirstRun() bool
- func SanitizeAPIKey(apiKey string) string
- type PromptModel
- type Step
- type SummaryModel
- type Validator
- func (v *Validator) ValidateAINativeKey(ctx context.Context, apiKey string) error
- func (v *Validator) ValidateAll(ctx context.Context, selections map[string]interface{}) error
- func (v *Validator) ValidateAnthropicKey(ctx context.Context, apiKey string) error
- func (v *Validator) ValidateGoogleKey(ctx context.Context, apiKey string) error
- func (v *Validator) ValidateOllamaConnection(ctx context.Context, baseURL string) error
- func (v *Validator) ValidateOllamaModel(ctx context.Context, baseURL, modelName string) error
- func (v *Validator) ValidateOpenAIKey(ctx context.Context, apiKey string) error
- func (v *Validator) ValidateProviderConfig(ctx context.Context, provider string, selections map[string]interface{}) error
- type Wizard
- type WizardConfig
- type WizardResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckFirstRun ¶
func CheckFirstRun() bool
CheckFirstRun checks if this is a first run and whether setup is needed
func SanitizeAPIKey ¶
SanitizeAPIKey sanitizes an API key for display
Types ¶
type PromptModel ¶
type PromptModel struct {
Selections map[string]interface{}
// contains filtered or unexported fields
}
PromptModel represents the state of the interactive prompts
type Step ¶
type Step int
Step represents each step in the wizard
const ( StepProvider Step = iota StepAnthropicAPIKey StepAnthropicModel StepExtendedThinking StepOpenAIAPIKey StepOpenAIModel StepGoogleAPIKey StepGoogleModel StepOllamaURL StepOllamaModel StepMetaLlamaAPIKey StepMetaLlamaModel StepAINativeLogin StepAINativeAPIKey StepColorScheme StepPromptCaching StepComplete )
type SummaryModel ¶
type SummaryModel struct {
Config interface{}
Selections map[string]interface{}
Confirmed bool
// contains filtered or unexported fields
}
SummaryModel displays the configuration summary
func NewSummaryModel ¶
func NewSummaryModel(cfg interface{}, selections map[string]interface{}) SummaryModel
NewSummaryModel creates a new summary model
type Validator ¶
type Validator struct {
// contains filtered or unexported fields
}
Validator handles validation of API keys and connections
func (*Validator) ValidateAINativeKey ¶
ValidateAINativeKey validates an AINative platform API key
func (*Validator) ValidateAll ¶
ValidateAll performs comprehensive validation of all user inputs
func (*Validator) ValidateAnthropicKey ¶
ValidateAnthropicKey validates an Anthropic API key
func (*Validator) ValidateGoogleKey ¶
ValidateGoogleKey validates a Google API key
func (*Validator) ValidateOllamaConnection ¶
ValidateOllamaConnection validates connection to an Ollama server
func (*Validator) ValidateOllamaModel ¶
ValidateOllamaModel validates that a model exists in Ollama
func (*Validator) ValidateOpenAIKey ¶
ValidateOpenAIKey validates an OpenAI API key
type Wizard ¶
type Wizard struct {
// contains filtered or unexported fields
}
Wizard orchestrates the first-time setup process
func NewWizard ¶
func NewWizard(ctx context.Context, cfg WizardConfig) *Wizard
NewWizard creates a new setup wizard instance
func (*Wizard) Run ¶
func (w *Wizard) Run() (*WizardResult, error)
Run executes the setup wizard flow
func (*Wizard) SetSelections ¶
SetSelections manually sets user selections (for non-interactive mode)
type WizardConfig ¶
WizardConfig holds configuration for the setup wizard