@@ -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
0 commit comments