# Configure Command

The Contaigents CLI now includes a `configure` command that provides an easy, interactive way to set up LLM providers and configure default settings.

## Usage

```bash
contaigents configure
```

## Features

### 1. Interactive Provider Setup
- Lists all available LLM providers
- Guides you through configuration for each provider
- Supports both numeric selection and provider names
- Shows available models and default values

### 2. Environment Variable Support
- API keys can be stored as environment variable references
- Use `env:VARIABLE_NAME` format to reference environment variables
- Automatically resolves environment variables when loading configuration
- Warns when referenced environment variables are missing

### 3. Default Provider Management
- Option to set any configured provider as the default
- Global configuration stored in `.config/global_config.json`
- Default provider is used by chat command and other CLI features

## Supported Providers

- **OpenAI** - GPT models (gpt-4o, gpt-4, gpt-3.5-turbo, etc.)
- **Anthropic** - Claude models (claude-3-opus, claude-3-sonnet, claude-3-haiku)
- **Google** - Gemini models (gemini-2.0-flash, gemini-1.5-pro, etc.)
- **DeepSeek** - DeepSeek models (deepseek-chat, deepseek-coder)
- **HuggingFace** - Various open-source models
- **Ollama** - Local models via Ollama
- **OllamaApi** - Ollama API integration
- **Replicate** - Cloud-hosted models
- **OpenRouter** - Multi-provider API access

## Example Configuration Session

```bash
$ contaigents configure

🔧 Contaigents LLM Configuration Setup

📋 Available LLM Providers:
  1. OpenAI
  2. Anthropic
  3. Google
  4. DeepSeek
  5. HuggingFace
  6. Ollama
  7. OllamaApi
  8. Replicate
  9. OpenRouter

Select a provider (enter number or name): 1

✅ Selected provider: OpenAI

🔑 Configuring OpenAI:

📝 apiKey:
   Enter apiKey (or "env:VARIABLE_NAME" to use environment variable): env:OPENAI_API_KEY

📝 model:
   Available options:
     1. gpt-4o (default)
     2. gpt-4
     3. gpt-3.5-turbo
     4. gpt-4-turbo-preview
     5. gpt-4-0125-preview
     6. gpt-4-1106-preview
     7. gpt-3.5-turbo-0125
   Default: gpt-4o
   Enter model [gpt-4o]: 

✅ OpenAI configuration saved!

🎯 Set this as the default provider? (y/N): y
✅ OpenAI set as default provider!

📊 Configuration Summary:
   Provider: OpenAI
   apiKey: env:OPENAI_API_KEY
   model: gpt-4o
   Default Provider: OpenAI

🎉 Configuration completed successfully!
💡 You can now use this provider with the chat command or other CLI features.
```

## Environment Variable Configuration

### Setting API Keys via Environment Variables

Instead of storing API keys directly in configuration files, you can reference environment variables:

1. **During configuration**, enter `env:VARIABLE_NAME` when prompted for API key
2. **Set the environment variable** in your shell or `.env` file:
   ```bash
   export OPENAI_API_KEY="your-actual-api-key"
   export ANTHROPIC_API_KEY="your-anthropic-key"
   export GOOGLE_API_KEY="your-google-key"
   ```

### Supported Environment Variable Patterns

- `env:OPENAI_API_KEY` → resolves to `process.env.OPENAI_API_KEY`
- `env:ANTHROPIC_API_KEY` → resolves to `process.env.ANTHROPIC_API_KEY`
- `env:CUSTOM_KEY_NAME` → resolves to `process.env.CUSTOM_KEY_NAME`

### Benefits

- **Security**: API keys are not stored in configuration files
- **Flexibility**: Different environments can use different keys
- **Portability**: Configuration works across different machines
- **CI/CD Friendly**: Easy to use in automated environments

## Configuration Files

### Provider Configurations
Individual provider configurations are stored in:
```
.config/llm_config/
├── openai.json
├── anthropic.json
├── google.json
└── ...
```

### Global Configuration
Default provider and global settings are stored in:
```
.config/global_config.json
```

Example global config:
```json
{
  "defaultProvider": "OpenAI"
}
```

## Integration with Other Commands

Once configured, providers can be used with:

- **Chat Command**: `contaigents chat` (uses default provider)
- **Chat with Specific Provider**: `contaigents chat --provider anthropic`
- **Audio Generation**: `contaigents audio --provider google`

## Troubleshooting

### Environment Variable Not Found
If you see warnings like:
```
⚠️ Environment variable OPENAI_API_KEY not found for OpenAI.apiKey
```

Make sure to:
1. Set the environment variable: `export OPENAI_API_KEY="your-key"`
2. Restart your terminal or reload your shell configuration
3. Verify the variable is set: `echo $OPENAI_API_KEY`

### Provider Not Configured
If you get errors about unconfigured providers:
1. Run `contaigents configure` to set up the provider
2. Make sure all required fields are filled
3. Verify environment variables are properly set

### Reconfiguring a Provider
To reconfigure an existing provider:
1. Run `contaigents configure` again
2. Select the same provider
3. Enter new configuration values
4. The old configuration will be overwritten
