11import type { UnifiedModelCatalogEntry } from "@openclaw/model-catalog-core/model-catalog-types" ;
2+ import {
3+ normalizeStringEntries ,
4+ uniqueStrings ,
5+ } from "../../packages/normalization-core/src/string-normalization.js" ;
26import { createProviderApiKeyAuthMethod } from "../plugins/provider-api-key-auth.js" ;
37import { projectProviderCatalogResultToUnifiedTextRows } from "../plugins/provider-catalog-unified-text.js" ;
48import type {
@@ -10,7 +14,7 @@ import type {
1014 UnifiedModelCatalogProviderContext ,
1115 ProviderPluginWizardSetup ,
1216} from "../plugins/types.js" ;
13- import { normalizeStringEntries , uniqueStrings } from "../../packages/normalization-core/src/string-normalization .js" ;
17+ import { copyArrayEntries , isRecord , readRecordValue } from "../shared/safe-record .js" ;
1418import { definePluginEntry } from "./plugin-entry.js" ;
1519import type {
1620 OpenClawPluginApi ,
@@ -99,13 +103,21 @@ function resolveWizardSetup(params: {
99103 } ;
100104}
101105
106+ function copyProviderAuthOptions ( value : unknown ) : SingleProviderPluginApiKeyAuthOptions [ ] {
107+ return copyArrayEntries ( value ) . filter ( isRecord ) as SingleProviderPluginApiKeyAuthOptions [ ] ;
108+ }
109+
110+ function copyProviderAuthMethods ( value : unknown ) : ProviderAuthMethod [ ] {
111+ return copyArrayEntries ( value ) . filter ( isRecord ) as ProviderAuthMethod [ ] ;
112+ }
113+
102114function resolveEnvVars ( params : {
103- envVars ?: string [ ] ;
115+ envVars ?: unknown ;
104116 auth ?: SingleProviderPluginApiKeyAuthOptions [ ] ;
105117} ) : string [ ] | undefined {
106118 const combined = normalizeStringEntries ( [
107- ...( params . envVars ?? [ ] ) ,
108- ...( params . auth ?? [ ] ) . map ( ( entry ) => entry . envVar ) . filter ( Boolean ) ,
119+ ...copyArrayEntries ( params . envVars ) ,
120+ ...( params . auth ?? [ ] ) . map ( ( entry ) => readRecordValue ( entry , " envVar" ) ) . filter ( Boolean ) ,
109121 ] ) ;
110122 return combined . length > 0 ? uniqueStrings ( combined ) : undefined ;
111123}
@@ -135,25 +147,33 @@ export function defineSingleProviderPluginEntry(options: SingleProviderPluginOpt
135147 const provider = options . provider ;
136148 if ( provider ) {
137149 const providerId = provider . id ?? options . id ;
150+ const providerAuth = copyProviderAuthOptions ( provider . auth ) ;
151+ const acceptedProviderAuth : SingleProviderPluginApiKeyAuthOptions [ ] = [ ] ;
152+ const auth = providerAuth . flatMap ( ( entry ) => {
153+ try {
154+ const { wizard : _wizard , ...authParams } = entry ;
155+ const wizard = resolveWizardSetup ( {
156+ providerId,
157+ providerLabel : provider . label ,
158+ auth : entry ,
159+ } ) ;
160+ const method = createProviderApiKeyAuthMethod ( {
161+ ...authParams ,
162+ providerId,
163+ expectedProviders : entry . expectedProviders ?? [ providerId ] ,
164+ ...( wizard ? { wizard } : { } ) ,
165+ } ) ;
166+ acceptedProviderAuth . push ( entry ) ;
167+ return [ method ] ;
168+ } catch {
169+ return [ ] ;
170+ }
171+ } ) ;
138172 const envVars = resolveEnvVars ( {
139173 envVars : provider . envVars ,
140- auth : provider . auth ,
141- } ) ;
142- const auth = ( provider . auth ?? [ ] ) . map ( ( entry ) => {
143- const { wizard : _wizard , ...authParams } = entry ;
144- const wizard = resolveWizardSetup ( {
145- providerId,
146- providerLabel : provider . label ,
147- auth : entry ,
148- } ) ;
149- return createProviderApiKeyAuthMethod ( {
150- ...authParams ,
151- providerId,
152- expectedProviders : entry . expectedProviders ?? [ providerId ] ,
153- ...( wizard ? { wizard } : { } ) ,
154- } ) ;
174+ auth : acceptedProviderAuth ,
155175 } ) ;
156- auth . push ( ...( provider . extraAuth ?? [ ] ) ) ;
176+ auth . push ( ...copyProviderAuthMethods ( provider . extraAuth ) ) ;
157177 let catalog : ProviderPluginCatalog ;
158178 if ( "run" in provider . catalog ) {
159179 const catalogRun = provider . catalog . run ;
0 commit comments