Skip to content

Commit 80a9a52

Browse files
committed
refactor(config): centralize provider configuration management
This change refactors provider configuration handling by introducing new SettingsManager methods for accessing active provider settings, API keys, base URLs, and models. The SuperAgent class now uses these centralized methods instead of directly accessing settings, ensuring consistent provider ID normalization and improved maintainability of configuration logic.
1 parent 5e58584 commit 80a9a52

3 files changed

Lines changed: 33 additions & 33 deletions

File tree

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
## [0.0.70](https://github.com/involvex/super-agent-cli/compare/v0.0.69...v0.0.70) (2026-01-30)
2+
3+
### Features
4+
5+
- **settings:** add zai models, update default to glm-4 ([231f2a2](https://github.com/involvex/super-agent-cli/commit/231f2a261c57ad253f9d1269ed94d6ab1310ca01))
6+
7+
## [0.0.69](https://github.com/involvex/super-agent-cli/compare/v0.0.68...v0.0.69) (2026-01-30)
8+
19
## [0.0.68](https://github.com/involvex/super-agent-cli/compare/v0.0.67...v0.0.68) (2026-01-30)
210

311
### Features

src/agent/super-agent.ts

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -68,38 +68,29 @@ export class SuperAgent extends EventEmitter {
6868
) {
6969
super();
7070
const manager = getSettingsManager();
71-
const settings = manager.loadUserSettings();
72-
const activeProviderId = (settings.active_provider || "grok").toLowerCase();
73-
74-
const providerConfig = settings.providers[activeProviderId];
75-
// Fallback if config is missing (shouldn't happen with defaults, but safety check)
76-
const providerType = providerConfig?.provider || activeProviderId;
7771

7872
// Resolve effective configuration
7973
// Command line args (constructor params) override settings
80-
const effectiveApiKey = apiKey || providerConfig?.api_key || "";
81-
// Ensure baseURL is undefined if empty string to let SDKs use defaults
82-
let effectiveBaseURL =
83-
baseURL ||
84-
(providerConfig?.base_url ? providerConfig.base_url : undefined);
74+
const activeConfig = manager.getActiveProviderConfig();
75+
const activeProviderId = activeConfig?.id || "grok";
76+
const providerType = activeConfig?.provider || activeProviderId;
77+
78+
const effectiveApiKey = apiKey || manager.getApiKey() || "";
79+
let effectiveBaseURL = baseURL || manager.getBaseURL();
80+
const effectiveModel = model || manager.getCurrentModel();
8581

8682
// Cloudflare Workers AI specific handling
8783
if (
88-
providerConfig?.provider === "workers-ai" &&
84+
providerType === "workers-ai" &&
8985
effectiveBaseURL?.includes("{ACCOUNT_ID}")
9086
) {
91-
if (providerConfig.account_id) {
87+
if (activeConfig?.account_id) {
9288
effectiveBaseURL = effectiveBaseURL.replace(
9389
"{ACCOUNT_ID}",
94-
providerConfig.account_id,
90+
activeConfig.account_id,
9591
);
9692
}
9793
}
98-
const effectiveModel =
99-
model ||
100-
providerConfig?.model ||
101-
providerConfig?.default_model ||
102-
"grok-code-fast-1";
10394

10495
this.maxToolRounds = maxToolRounds || 400;
10596

@@ -231,26 +222,24 @@ Current working directory: ${process.cwd()}`,
231222
*/
232223
public setProvider(providerId: string): void {
233224
const manager = getSettingsManager();
234-
const settings = manager.loadUserSettings();
235225

236-
// Normalize provider ID
226+
// Normalize provider ID and update active provider in settings
237227
const activeProviderId = (providerId || "grok").toLowerCase();
238228

229+
// Load config for this specific provider ID
230+
const settings = manager.loadUserSettings();
239231
const providerConfig = settings.providers[activeProviderId];
240-
if (!providerConfig) {
241-
throw new Error(`Provider '${activeProviderId}' not configured.`);
242-
}
232+
const providerType = providerConfig?.provider || activeProviderId;
243233

244-
const providerType = providerConfig.provider || activeProviderId;
245-
const effectiveApiKey = providerConfig.api_key || "";
246-
let effectiveBaseURL = providerConfig.base_url || undefined;
234+
const effectiveApiKey = providerConfig?.api_key || "";
235+
let effectiveBaseURL = providerConfig?.base_url || undefined;
247236

248237
// Cloudflare Workers AI specific handling
249238
if (
250-
providerConfig.provider === "workers-ai" &&
239+
providerType === "workers-ai" &&
251240
effectiveBaseURL?.includes("{ACCOUNT_ID}")
252241
) {
253-
if (providerConfig.account_id) {
242+
if (providerConfig?.account_id) {
254243
effectiveBaseURL = effectiveBaseURL.replace(
255244
"{ACCOUNT_ID}",
256245
providerConfig.account_id,
@@ -259,8 +248,8 @@ Current working directory: ${process.cwd()}`,
259248
}
260249

261250
const effectiveModel =
262-
providerConfig.model ||
263-
providerConfig.default_model ||
251+
providerConfig?.model ||
252+
providerConfig?.default_model ||
264253
"grok-code-fast-1";
265254

266255
// Re-instantiate appropriate provider

src/utils/settings-manager.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,9 @@ export class SettingsManager {
312312
value: UserSettings[K],
313313
): void {
314314
const settings = { [key]: value } as Partial<UserSettings>;
315+
if (key === "active_provider" && typeof value === "string") {
316+
settings.active_provider = value.toLowerCase();
317+
}
315318
this.saveUserSettings(settings);
316319
}
317320

@@ -372,7 +375,7 @@ export class SettingsManager {
372375

373376
public getActiveProviderConfig(): ProviderConfig | undefined {
374377
const settings = this.getEffectiveSettings();
375-
const active = settings.active_provider;
378+
const active = (settings.active_provider || "grok").toLowerCase();
376379
return settings.providers?.[active];
377380
}
378381

@@ -383,7 +386,7 @@ export class SettingsManager {
383386

384387
public setCurrentModel(model: string): void {
385388
const settings = this.loadUserSettings();
386-
const active = settings.active_provider;
389+
const active = (settings.active_provider || "grok").toLowerCase();
387390
if (settings.providers && settings.providers[active]) {
388391
settings.providers[active].model = model;
389392
this.saveUserSettings(settings);

0 commit comments

Comments
 (0)