@@ -424,13 +424,21 @@ function findConfiguredProviderModel(params: {
424424 } ) ;
425425}
426426
427- function toFallbackConfiguredListModel ( entry : ConfiguredEntry , cfg : OpenClawConfig ) : ListRowModel {
427+ function toFallbackConfiguredListModel (
428+ entry : ConfiguredEntry ,
429+ cfg : OpenClawConfig ,
430+ catalogEntry ?: ModelCatalogEntry ,
431+ ) : ListRowModel {
432+ // Explicit models.providers definitions stay authoritative; the prepared
433+ // catalog fills plugin-owned refs so this view matches `--all`, and the
434+ // placeholder is a last resort for refs nothing knows.
428435 return (
429436 findConfiguredProviderModel ( {
430437 cfg,
431438 provider : entry . ref . provider ,
432439 modelId : entry . ref . model ,
433- } ) ?? {
440+ } ) ??
441+ ( catalogEntry ? toPreparedCatalogListModel ( catalogEntry ) : undefined ) ?? {
434442 provider : entry . ref . provider ,
435443 id : entry . ref . model ,
436444 name : entry . ref . model ,
@@ -440,6 +448,35 @@ function toFallbackConfiguredListModel(entry: ConfiguredEntry, cfg: OpenClawConf
440448 ) ;
441449}
442450
451+ /** Loads the committed catalog generation shared by every model-list row source. */
452+ export async function loadListModelCatalogSnapshot (
453+ context : RowBuilderContext ,
454+ ) : Promise < ModelCatalogSnapshot > {
455+ const { loadPreparedModelCatalogSnapshot } = await loadPreparedModelCatalogModule ( ) ;
456+ const workspaceDir = context . workspaceDir ?? context . metadataSnapshot ?. workspaceDir ;
457+ return loadPreparedModelCatalogSnapshot ( {
458+ config : context . cfg ,
459+ ...( context . agentId ? { agentId : context . agentId } : { } ) ,
460+ agentDir : context . agentDir ,
461+ ...( workspaceDir ? { workspaceDir } : { } ) ,
462+ readOnly : true ,
463+ } ) ;
464+ }
465+
466+ /** Indexes a catalog generation by model key so configured refs can reuse its metadata. */
467+ function indexModelCatalogEntriesByKey (
468+ snapshot : ModelCatalogSnapshot ,
469+ ) : ReadonlyMap < string , ModelCatalogEntry > {
470+ const byKey = new Map < string , ModelCatalogEntry > ( ) ;
471+ for ( const entry of [ ...snapshot . entries , ...( snapshot . staticEntries ?? [ ] ) ] ) {
472+ const key = modelKey ( entry . provider , entry . id ) ;
473+ if ( ! byKey . has ( key ) ) {
474+ byKey . set ( key , entry ) ;
475+ }
476+ }
477+ return byKey ;
478+ }
479+
443480/** Appends rows discovered from the loaded model registry. */
444481export async function appendDiscoveredRows ( params : {
445482 rows : ModelRow [ ] ;
@@ -538,20 +575,10 @@ export async function appendAuthenticatedCatalogRows(params: {
538575 rows : ModelRow [ ] ;
539576 context : RowBuilderContext ;
540577 seenKeys : Set < string > ;
578+ catalogSnapshot ?: ModelCatalogSnapshot ;
541579} ) : Promise < void > {
542- const { loadPreparedModelCatalogSnapshot } = await loadPreparedModelCatalogModule ( ) ;
543- const { entries : catalog , routeVariants } = await loadPreparedModelCatalogSnapshot ( {
544- config : params . context . cfg ,
545- ...( params . context . agentId ? { agentId : params . context . agentId } : { } ) ,
546- agentDir : params . context . agentDir ,
547- ...( ( params . context . workspaceDir ?? params . context . metadataSnapshot ?. workspaceDir )
548- ? {
549- workspaceDir :
550- params . context . workspaceDir ?? params . context . metadataSnapshot ?. workspaceDir ,
551- }
552- : { } ) ,
553- readOnly : true ,
554- } ) ;
580+ const { entries : catalog , routeVariants } =
581+ params . catalogSnapshot ?? ( await loadListModelCatalogSnapshot ( params . context ) ) ;
555582 const routeIndex = createModelCatalogLogicalRouteIndex ( routeVariants ) ;
556583 for ( const entry of catalog ) {
557584 const model = toPreparedCatalogListModel ( entry ) ;
@@ -587,21 +614,7 @@ export async function appendPreparedModelCatalogRows(params: {
587614 catalogSnapshot ?: ModelCatalogSnapshot ;
588615} ) : Promise < void > {
589616 const catalogSnapshot =
590- params . catalogSnapshot ??
591- ( await (
592- await loadPreparedModelCatalogModule ( )
593- ) . loadPreparedModelCatalogSnapshot ( {
594- config : params . context . cfg ,
595- ...( params . context . agentId ? { agentId : params . context . agentId } : { } ) ,
596- agentDir : params . context . agentDir ,
597- ...( ( params . context . workspaceDir ?? params . context . metadataSnapshot ?. workspaceDir )
598- ? {
599- workspaceDir :
600- params . context . workspaceDir ?? params . context . metadataSnapshot ?. workspaceDir ,
601- }
602- : { } ) ,
603- readOnly : true ,
604- } ) ) ;
617+ params . catalogSnapshot ?? ( await loadListModelCatalogSnapshot ( params . context ) ) ;
605618 const staticEntries = catalogSnapshot . staticEntries ?? [ ] ;
606619 const routeVariants = [ ...catalogSnapshot . routeVariants ] ;
607620 const seenRouteVariants = new Set (
@@ -640,10 +653,14 @@ export async function appendConfiguredRows(params: {
640653 entries : ConfiguredEntry [ ] ;
641654 modelRegistry ?: ModelRegistry ;
642655 context : RowBuilderContext ;
656+ catalogSnapshot ?: ModelCatalogSnapshot ;
643657} ) : Promise < void > {
644658 const resolveModelWithRegistry = params . modelRegistry
645659 ? ( await loadModelResolverModule ( ) ) . resolveModelWithRegistry
646660 : undefined ;
661+ const catalogByKey = params . catalogSnapshot
662+ ? indexModelCatalogEntriesByKey ( params . catalogSnapshot )
663+ : undefined ;
647664 for ( const entry of params . entries ) {
648665 if ( ! matchesProviderFilter ( params . context , entry . ref . provider ) ) {
649666 continue ;
@@ -656,7 +673,7 @@ export async function appendConfiguredRows(params: {
656673 modelRegistry : params . modelRegistry ,
657674 cfg : params . context . cfg ,
658675 } )
659- : toFallbackConfiguredListModel ( entry , params . context . cfg ) ;
676+ : toFallbackConfiguredListModel ( entry , params . context . cfg , catalogByKey ?. get ( entry . key ) ) ;
660677 const model = resolvedModel
661678 ? normalizeListRowWithProviderPlugin ( { model : resolvedModel , context : params . context } )
662679 : resolvedModel ;
0 commit comments