@@ -2,10 +2,7 @@ import { DEFAULT_MODEL, DEFAULT_PROVIDER } from "../agents/defaults.js";
22import { resolveVisibleModelCatalog } from "../agents/model-catalog-visibility.js" ;
33import { loadModelCatalog } from "../agents/model-catalog.js" ;
44import type { ModelCatalogEntry } from "../agents/model-catalog.js" ;
5- import {
6- isModelPickerVisibleModelRef ,
7- isModelPickerVisibleProvider ,
8- } from "../agents/model-picker-visibility.js" ;
5+ import { createModelPickerVisibleProviderPredicate } from "../agents/model-picker-visibility.js" ;
96import { createProviderAuthChecker } from "../agents/model-provider-auth.js" ;
107import { formatLiteralProviderPrefixedModelRef } from "../agents/model-ref-shared.js" ;
118import {
@@ -244,13 +241,14 @@ async function addModelSelectOption(params: {
244241 aliasIndex : ReturnType < typeof buildModelAliasIndex > ;
245242 hasAuth : ( provider : string ) => Promise < boolean > ;
246243 literalPrefixProviders : Set < string > ;
244+ isVisibleProvider : ( provider : string ) => boolean ;
247245} ) {
248246 const normalizedRef = normalizeModelRef ( params . entry . provider , params . entry . id ) ;
249247 const key = modelKey ( normalizedRef . provider , normalizedRef . model ) ;
250248 if (
251249 params . seen . has ( key ) ||
252250 HIDDEN_ROUTER_MODELS . has ( key ) ||
253- ! isModelPickerVisibleProvider ( normalizedRef . provider )
251+ ! params . isVisibleProvider ( normalizedRef . provider )
254252 ) {
255253 return ;
256254 }
@@ -304,6 +302,7 @@ async function addModelKeySelectOption(params: {
304302 aliasIndex : ReturnType < typeof buildModelAliasIndex > ;
305303 hasAuth : ( provider : string ) => Promise < boolean > ;
306304 literalPrefixProviders ?: Set < string > ;
305+ isVisibleProvider : ( provider : string ) => boolean ;
307306 fallbackHint : string ;
308307} ) {
309308 const entry = splitModelKey ( params . key ) ;
@@ -318,6 +317,7 @@ async function addModelKeySelectOption(params: {
318317 aliasIndex : params . aliasIndex ,
319318 hasAuth : params . hasAuth ,
320319 literalPrefixProviders : params . literalPrefixProviders ?? EMPTY_LITERAL_PREFIX_PROVIDERS ,
320+ isVisibleProvider : params . isVisibleProvider ,
321321 } ) ;
322322 if ( params . seen . size > before ) {
323323 const option = params . options . at ( - 1 ) ;
@@ -415,8 +415,9 @@ async function maybeFilterModelsByProvider(params: {
415415 cfg : OpenClawConfig ;
416416 workspaceDir ?: string ;
417417 env ?: NodeJS . ProcessEnv ;
418+ isVisibleProvider : ( provider : string ) => boolean ;
418419} ) : Promise < typeof params . models > {
419- let next = params . models . filter ( ( entry ) => isModelPickerVisibleProvider ( entry . provider ) ) ;
420+ let next = params . models . filter ( ( entry ) => params . isVisibleProvider ( entry . provider ) ) ;
420421 const providerIds = sortUniqueStrings ( next . map ( ( entry ) => entry . provider ) ) ;
421422 const hasPreferredProvider = ! ! params . preferredProvider ;
422423 const shouldPromptProvider =
@@ -738,13 +739,19 @@ export async function promptDefaultModel(
738739 } ) ;
739740 }
740741
742+ const isVisibleProvider = createModelPickerVisibleProviderPredicate ( {
743+ config : cfg ,
744+ env : params . env ,
745+ includeSetupRegistry : true ,
746+ } ) ;
741747 const filteredModels = await maybeFilterModelsByProvider ( {
742748 models,
743749 preferredProvider,
744750 prompter : params . prompter ,
745751 cfg,
746752 workspaceDir : params . workspaceDir ,
747753 env : params . env ,
754+ isVisibleProvider,
748755 } ) ;
749756 if ( filteredModels . length === 0 ) {
750757 return promptManualModel ( {
@@ -807,6 +814,7 @@ export async function promptDefaultModel(
807814 aliasIndex,
808815 hasAuth,
809816 literalPrefixProviders,
817+ isVisibleProvider,
810818 } ) ;
811819 }
812820 if ( configuredKey && ! seen . has ( configuredKey ) ) {
@@ -947,6 +955,11 @@ export async function promptModelAllowlist(params: {
947955 } )
948956 : [ ] ;
949957 if ( scopedFastKeys . length > 0 ) {
958+ const isVisibleProvider = createModelPickerVisibleProviderPredicate ( {
959+ config : cfg ,
960+ env : params . env ,
961+ includeSetupRegistry : true ,
962+ } ) ;
950963 const scopeKeys = allowedKeys . length > 0 ? allowedKeys : scopedFastKeys ;
951964 const scopeKeySet = new Set ( scopeKeys ) ;
952965 const initialKeys = normalizeModelKeys ( initialSeeds . filter ( ( key ) => scopeKeySet . has ( key ) ) ) ;
@@ -964,6 +977,7 @@ export async function promptModelAllowlist(params: {
964977 seen,
965978 aliasIndex,
966979 hasAuth,
980+ isVisibleProvider,
967981 fallbackHint :
968982 allowedKeys . length > 0 ? t ( "wizard.model.allowed" ) : t ( "wizard.model.configured" ) ,
969983 } ) ;
@@ -1037,14 +1051,23 @@ export async function promptModelAllowlist(params: {
10371051 workspaceDir : params . workspaceDir ,
10381052 env : params . env ,
10391053 } ) ;
1054+ const isVisibleProvider = createModelPickerVisibleProviderPredicate ( {
1055+ config : cfg ,
1056+ env : params . env ,
1057+ includeSetupRegistry : true ,
1058+ } ) ;
1059+ const isVisibleModelRef = ( ref : string ) : boolean => {
1060+ const separatorIndex = ref . indexOf ( "/" ) ;
1061+ return separatorIndex <= 0 || isVisibleProvider ( ref . slice ( 0 , separatorIndex ) ) ;
1062+ } ;
10401063
10411064 const options : WizardSelectOption [ ] = [ ] ;
10421065 const seen = new Set < string > ( ) ;
10431066 const allowedCatalog = (
10441067 allowedKeySet
10451068 ? catalog . filter ( ( entry ) => allowedKeySet . has ( modelKey ( entry . provider , entry . id ) ) )
10461069 : catalog
1047- ) . filter ( ( entry ) => isModelPickerVisibleProvider ( entry . provider ) ) ;
1070+ ) . filter ( ( entry ) => isVisibleProvider ( entry . provider ) ) ;
10481071 const filteredCatalog =
10491072 preferredProvider && allowedCatalog . some ( ( entry ) => matchesPreferredProvider ?.( entry . provider ) )
10501073 ? allowedCatalog . filter ( ( entry ) => matchesPreferredProvider ?.( entry . provider ) )
@@ -1067,7 +1090,7 @@ export async function promptModelAllowlist(params: {
10671090 : initialSeeds ;
10681091 const initialKeys = allowedKeySet
10691092 ? initialSeeds . filter ( ( key ) => allowedKeySet . has ( key ) )
1070- : selectableInitialSeeds . filter ( isModelPickerVisibleModelRef ) ;
1093+ : selectableInitialSeeds . filter ( isVisibleModelRef ) ;
10711094
10721095 for ( const entry of filteredCatalog ) {
10731096 await addModelSelectOption ( {
@@ -1077,11 +1100,12 @@ export async function promptModelAllowlist(params: {
10771100 aliasIndex,
10781101 hasAuth,
10791102 literalPrefixProviders,
1103+ isVisibleProvider,
10801104 } ) ;
10811105 }
10821106
10831107 const supplementalKeys = ( allowedKeySet ? allowedKeys : selectableInitialSeeds ) . filter (
1084- isModelPickerVisibleModelRef ,
1108+ isVisibleModelRef ,
10851109 ) ;
10861110 for ( const key of supplementalKeys ) {
10871111 if ( seen . has ( key ) ) {
@@ -1266,9 +1290,17 @@ export function applyModelFallbacksFromSelection(
12661290 scopeKeySet && ! includesResolvedPrimary
12671291 ? rawSelectedFallbacks . filter ( ( key ) => existingFallbackSet . has ( key ) )
12681292 : rawSelectedFallbacks ;
1293+ const isVisibleProvider = createModelPickerVisibleProviderPredicate ( {
1294+ config : cfg ,
1295+ includeSetupRegistry : true ,
1296+ } ) ;
1297+ const isVisibleModelRef = ( ref : string ) : boolean => {
1298+ const separatorIndex = ref . indexOf ( "/" ) ;
1299+ return separatorIndex <= 0 || isVisibleProvider ( ref . slice ( 0 , separatorIndex ) ) ;
1300+ } ;
12691301 const preserveExistingFallback = scopeKeySet
12701302 ? ( fallback : string ) => ! scopeKeySet . has ( fallback )
1271- : ( fallback : string ) => ! isModelPickerVisibleModelRef ( fallback ) ;
1303+ : ( fallback : string ) => ! isVisibleModelRef ( fallback ) ;
12721304 const fallbacks = mergeFallbackSelection ( {
12731305 existingFallbacks,
12741306 selectedFallbacks,
0 commit comments