1- import { normalizeProviderId } from "@openclaw/model-catalog-core/provider-id" ;
21/**
32 * Merges generated model-provider config with explicit user config and
43 * preserved secret fields. Setup and doctor flows use this boundary to update
54 * model catalogs without discarding existing credentials.
65 */
76import { normalizeOptionalString } from "@openclaw/normalization-core/string-coerce" ;
87import { isNonSecretApiKeyMarker } from "./model-auth-markers.js" ;
8+ import { normalizeProviderMapKeys } from "./models-config.providers.keys.js" ;
99import type { ProviderConfig } from "./models-config.providers.secrets.js" ;
1010
1111/** Existing provider config shape that may carry persisted secret/base URL fields. */
@@ -147,19 +147,8 @@ export function mergeProviders(params: {
147147 implicit ?: Record < string , ProviderConfig > | null ;
148148 explicit ?: Record < string , ProviderConfig > | null ;
149149} ) : Record < string , ProviderConfig > {
150- const out : Record < string , ProviderConfig > = { } ;
151- for ( const [ key , implicit ] of Object . entries ( params . implicit ?? { } ) ) {
152- const providerKey = normalizeProviderId ( key ) ;
153- if ( ! providerKey ) {
154- continue ;
155- }
156- out [ providerKey ] = implicit ;
157- }
158- for ( const [ key , explicit ] of Object . entries ( params . explicit ?? { } ) ) {
159- const providerKey = normalizeProviderId ( key ) ;
160- if ( ! providerKey ) {
161- continue ;
162- }
150+ const out = normalizeProviderMapKeys ( params . implicit ) ;
151+ for ( const [ providerKey , explicit ] of Object . entries ( normalizeProviderMapKeys ( params . explicit ) ) ) {
163152 const implicit = out [ providerKey ] ;
164153 out [ providerKey ] = implicit ? mergeProviderModels ( implicit , explicit ) : explicit ;
165154 }
@@ -242,14 +231,8 @@ export function mergeWithExistingProviderSecrets(params: {
242231 secretRefManagedProviders : ReadonlySet < string > ;
243232} ) : Record < string , ProviderConfig > {
244233 const { nextProviders, existingProviders, secretRefManagedProviders } = params ;
245- const normalizedExistingProviders : Record < string , ExistingProviderConfig > = { } ;
246- for ( const [ key , entry ] of Object . entries ( existingProviders ) ) {
247- const providerKey = normalizeProviderId ( key ) ;
248- if ( ! providerKey ) {
249- continue ;
250- }
251- normalizedExistingProviders [ providerKey ] = entry ;
252- }
234+ const normalizedExistingProviders = normalizeProviderMapKeys ( existingProviders ) ;
235+ const normalizedNextProviders = normalizeProviderMapKeys ( nextProviders ) ;
253236
254237 const mergedProviders : Record < string , ProviderConfig > = { } ;
255238 for ( const [ key , entry ] of Object . entries ( normalizedExistingProviders ) ) {
@@ -258,7 +241,7 @@ export function mergeWithExistingProviderSecrets(params: {
258241 }
259242 mergedProviders [ key ] = entry ;
260243 }
261- for ( const [ key , newEntry ] of Object . entries ( nextProviders ) ) {
244+ for ( const [ key , newEntry ] of Object . entries ( normalizedNextProviders ) ) {
262245 const existing = normalizedExistingProviders [ key ] ;
263246 if ( ! existing ) {
264247 mergedProviders [ key ] = newEntry ;
0 commit comments