@@ -71,18 +71,20 @@ function resolveModelCatalogBrowseTimeoutMs(value: number | undefined): number {
7171 ) ;
7272}
7373
74- async function loadCatalogForBrowse < T > ( params : {
74+ /** Loads an explicit logical/physical catalog snapshot for route-aware browse surfaces. */
75+ export async function loadPreparedModelCatalogSnapshotForBrowse ( params : {
7576 cfg : OpenClawConfig ;
7677 agentId ?: string ;
7778 view ?: ModelCatalogBrowseView ;
79+ /** Never starts provider discovery; a completed generation cache may still be reused. */
7880 preparedOnly ?: boolean ;
81+ /** Replaces the completed generation cache when discovery is otherwise required. */
7982 refresh ?: boolean ;
80- loadCatalog : ( params : { readOnly : boolean ; refresh ?: boolean } ) => Promise < T > ;
81- empty : T ;
83+ loadCatalog : ( params : { readOnly : boolean ; refresh ?: boolean } ) => Promise < ModelCatalogSnapshot > ;
8284 timeoutFullDiscovery ?: boolean ;
8385 timeoutMs ?: number ;
8486 onTimeout ?: ( timeoutMs : number ) => void ;
85- } ) : Promise < T > {
87+ } ) : Promise < ModelCatalogSnapshot > {
8688 const view = params . view ?? "default" ;
8789 const requiresFullDiscovery =
8890 params . preparedOnly !== true &&
@@ -98,19 +100,16 @@ async function loadCatalogForBrowse<T>(params: {
98100 ( params . refresh !== true &&
99101 requiresFullDiscovery &&
100102 ( view === "default" || view === "provider-config" ) ) ;
103+ const catalogPromise = params . loadCatalog ( {
104+ readOnly : ! requiresFullDiscovery ,
105+ ...( requiresFullDiscovery && params . refresh ? { refresh : true } : { } ) ,
106+ } ) ;
101107 if ( ( requiresFullDiscovery || params . refresh === true ) && ! shouldTimeoutFullDiscovery ) {
102- return await params . loadCatalog ( {
103- readOnly : ! requiresFullDiscovery ,
104- ...( requiresFullDiscovery && params . refresh ? { refresh : true } : { } ) ,
105- } ) ;
108+ return await catalogPromise ;
106109 }
107110
108111 let timeout : NodeJS . Timeout | undefined ;
109112 const timeoutMs = resolveModelCatalogBrowseTimeoutMs ( params . timeoutMs ) ;
110- const catalogPromise = params . loadCatalog ( {
111- readOnly : ! requiresFullDiscovery ,
112- ...( requiresFullDiscovery && params . refresh ? { refresh : true } : { } ) ,
113- } ) ;
114113 const catalogResult = catalogPromise . then ( ( value ) => ( { kind : "catalog" as const , value } ) ) ;
115114 const timeoutPromise = new Promise < { kind : "timeout" } > ( ( resolve ) => {
116115 timeout = globalThis . setTimeout ( ( ) => resolve ( { kind : "timeout" } ) , timeoutMs ) ;
@@ -123,7 +122,7 @@ async function loadCatalogForBrowse<T>(params: {
123122 // The browse path may return partial/empty results; keep late catalog failures off stderr.
124123 catalogPromise . catch ( ( ) => undefined ) ;
125124 params . onTimeout ?.( timeoutMs ) ;
126- return params . empty ;
125+ return { entries : [ ] , routeVariants : [ ] } ;
127126 }
128127 return result . value ;
129128 } finally {
@@ -132,20 +131,3 @@ async function loadCatalogForBrowse<T>(params: {
132131 }
133132 }
134133}
135-
136- /** Loads an explicit logical/physical catalog snapshot for route-aware browse surfaces. */
137- export function loadPreparedModelCatalogSnapshotForBrowse ( params : {
138- cfg : OpenClawConfig ;
139- agentId ?: string ;
140- view ?: ModelCatalogBrowseView ;
141- /** Never starts provider discovery; a completed generation cache may still be reused. */
142- preparedOnly ?: boolean ;
143- /** Replaces the completed generation cache when discovery is otherwise required. */
144- refresh ?: boolean ;
145- loadCatalog : ( params : { readOnly : boolean ; refresh ?: boolean } ) => Promise < ModelCatalogSnapshot > ;
146- timeoutFullDiscovery ?: boolean ;
147- timeoutMs ?: number ;
148- onTimeout ?: ( timeoutMs : number ) => void ;
149- } ) : Promise < ModelCatalogSnapshot > {
150- return loadCatalogForBrowse ( { ...params , empty : { entries : [ ] , routeVariants : [ ] } } ) ;
151- }
0 commit comments