on main help sign in
fix: tweak the logic in config to ensure that env vs file configurations merge properly (#115)
e14de7aAiden Cline
internal/config/config.go+13−9
@@ -129,7 +129,6 @@ func Load(workingDir string, debug bool) (*Config, error) {
129
129
130 configureViper()
130 configureViper()
131 setDefaults(debug)
131 setDefaults(debug)
132− setProviderDefaults()
133
132
134 // Read global config
133 // Read global config
135 if err := readConfig(viper.ReadInConfig()); err != nil {
134 if err := readConfig(viper.ReadInConfig()); err != nil {
@@ -139,6 +138,8 @@ func Load(workingDir string, debug bool) (*Config, error) {
139 // Load and merge local config
138 // Load and merge local config
140 mergeLocalConfig(workingDir)
139 mergeLocalConfig(workingDir)
141
140
141+ setProviderDefaults()
142+
142 // Apply configuration to the struct
143 // Apply configuration to the struct
143 if err := viper.Unmarshal(cfg); err != nil {
144 if err := viper.Unmarshal(cfg); err != nil {
144 return cfg, fmt.Errorf("failed to unmarshal config: %w", err)
145 return cfg, fmt.Errorf("failed to unmarshal config: %w", err)
@@ -222,7 +223,8 @@ func setDefaults(debug bool) {
222 }
223 }
223}
224}
224
225
225−// setProviderDefaults configures LLM provider defaults based on environment variables.
226+// setProviderDefaults configures LLM provider defaults based on provider provided by
227+// environment variables and configuration file.
226func setProviderDefaults() {
228func setProviderDefaults() {
227 // Set all API keys we can find in the environment
229 // Set all API keys we can find in the environment
228 if apiKey := os.Getenv("ANTHROPIC_API_KEY"); apiKey != "" {
230 if apiKey := os.Getenv("ANTHROPIC_API_KEY"); apiKey != "" {
@@ -246,9 +248,12 @@ func setProviderDefaults() {
246 // 2. OpenAI
248 // 2. OpenAI
247 // 3. Google Gemini
249 // 3. Google Gemini
248 // 4. Groq
250 // 4. Groq
251+ // 5. OpenRouter
249− // 5. AWS Bedrock
252+ // 6. AWS Bedrock
253+ // 7. Azure
254+
250 // Anthropic configuration
255 // Anthropic configuration
251− if apiKey := os.Getenv("ANTHROPIC_API_KEY"); apiKey != "" {
256+ if viper.Get("providers.anthropic.apiKey") != "" {
252 viper.SetDefault("agents.coder.model", models.Claude37Sonnet)
257 viper.SetDefault("agents.coder.model", models.Claude37Sonnet)
253 viper.SetDefault("agents.task.model", models.Claude37Sonnet)
258 viper.SetDefault("agents.task.model", models.Claude37Sonnet)
254 viper.SetDefault("agents.title.model", models.Claude37Sonnet)
259 viper.SetDefault("agents.title.model", models.Claude37Sonnet)
@@ -256,7 +261,7 @@ func setProviderDefaults() {
256 }
261 }
257
262
258 // OpenAI configuration
263 // OpenAI configuration
259− if apiKey := os.Getenv("OPENAI_API_KEY"); apiKey != "" {
264+ if viper.Get("providers.openai.apiKey") != "" {
260 viper.SetDefault("agents.coder.model", models.GPT41)
265 viper.SetDefault("agents.coder.model", models.GPT41)
261 viper.SetDefault("agents.task.model", models.GPT41Mini)
266 viper.SetDefault("agents.task.model", models.GPT41Mini)
262 viper.SetDefault("agents.title.model", models.GPT41Mini)
267 viper.SetDefault("agents.title.model", models.GPT41Mini)
@@ -264,7 +269,7 @@ func setProviderDefaults() {
264 }
269 }
265
270
266 // Google Gemini configuration
271 // Google Gemini configuration
267− if apiKey := os.Getenv("GEMINI_API_KEY"); apiKey != "" {
272+ if viper.Get("providers.google.gemini.apiKey") != "" {
268 viper.SetDefault("agents.coder.model", models.Gemini25)
273 viper.SetDefault("agents.coder.model", models.Gemini25)
269 viper.SetDefault("agents.task.model", models.Gemini25Flash)
274 viper.SetDefault("agents.task.model", models.Gemini25Flash)
270 viper.SetDefault("agents.title.model", models.Gemini25Flash)
275 viper.SetDefault("agents.title.model", models.Gemini25Flash)
@@ -272,7 +277,7 @@ func setProviderDefaults() {
272 }
277 }
273
278
274 // Groq configuration
279 // Groq configuration
275− if apiKey := os.Getenv("GROQ_API_KEY"); apiKey != "" {
280+ if viper.Get("providers.groq.apiKey") != "" {
276 viper.SetDefault("agents.coder.model", models.QWENQwq)
281 viper.SetDefault("agents.coder.model", models.QWENQwq)
277 viper.SetDefault("agents.task.model", models.QWENQwq)
282 viper.SetDefault("agents.task.model", models.QWENQwq)
278 viper.SetDefault("agents.title.model", models.QWENQwq)
283 viper.SetDefault("agents.title.model", models.QWENQwq)
@@ -280,8 +285,7 @@ func setProviderDefaults() {
280 }
285 }
281
286
282 // OpenRouter configuration
287 // OpenRouter configuration
283− if apiKey := os.Getenv("OPENROUTER_API_KEY"); apiKey != "" {
284− viper.SetDefault("providers.openrouter.apiKey", apiKey)
288+ if viper.Get("providers.openrouter.apiKey") != "" {
285 viper.SetDefault("agents.coder.model", models.OpenRouterClaude37Sonnet)
289 viper.SetDefault("agents.coder.model", models.OpenRouterClaude37Sonnet)
286 viper.SetDefault("agents.task.model", models.OpenRouterClaude37Sonnet)
290 viper.SetDefault("agents.task.model", models.OpenRouterClaude37Sonnet)
287 viper.SetDefault("agents.title.model", models.OpenRouterClaude35Haiku)
291 viper.SetDefault("agents.title.model", models.OpenRouterClaude35Haiku)
internal/llm/models/models.go+7−5
@@ -35,11 +35,13 @@ const (
35
35
36// Providers in order of popularity
36// Providers in order of popularity
37var ProviderPopularity = map[ModelProvider]int{
37var ProviderPopularity = map[ModelProvider]int{
38− ProviderAnthropic: 1,
38+ ProviderAnthropic: 1,
39− ProviderOpenAI: 2,
39+ ProviderOpenAI: 2,
40− ProviderGemini: 3,
40+ ProviderGemini: 3,
41− ProviderGROQ: 4,
41+ ProviderGROQ: 4,
42+ ProviderOpenRouter: 5,
42− ProviderBedrock: 5,
43+ ProviderBedrock: 6,
44+ ProviderAzure: 7,
43}
45}
44
46
45var SupportedModels = map[ModelID]Model{
47var SupportedModels = map[ModelID]Model{