@@ -81,15 +81,17 @@ function instantiatePiModelRegistry(
8181export async function loadModelCatalog ( params ?: {
8282 config ?: OpenClawConfig ;
8383 useCache ?: boolean ;
84+ readOnly ?: boolean ;
8485} ) : Promise < ModelCatalogEntry [ ] > {
85- if ( params ?. useCache === false ) {
86+ const readOnly = params ?. readOnly === true ;
87+ if ( ! readOnly && params ?. useCache === false ) {
8688 modelCatalogPromise = null ;
8789 }
88- if ( modelCatalogPromise ) {
90+ if ( ! readOnly && modelCatalogPromise ) {
8991 return modelCatalogPromise ;
9092 }
9193
92- modelCatalogPromise = ( async ( ) => {
94+ const loadCatalog = async ( ) => {
9395 const models : ModelCatalogEntry [ ] = [ ] ;
9496 const timingEnabled = shouldLogModelCatalogTiming ( ) ;
9597 const startMs = timingEnabled ? Date . now ( ) : 0 ;
@@ -110,8 +112,10 @@ export async function loadModelCatalog(params?: {
110112 } ) ;
111113 try {
112114 const cfg = params ?. config ?? loadConfig ( ) ;
113- await ensureOpenClawModelsJson ( cfg ) ;
114- logStage ( "models-json-ready" ) ;
115+ if ( ! readOnly ) {
116+ await ensureOpenClawModelsJson ( cfg ) ;
117+ logStage ( "models-json-ready" ) ;
118+ }
115119 // IMPORTANT: keep the dynamic import *inside* the try/catch.
116120 // If this fails once (e.g. during a pnpm install that temporarily swaps node_modules),
117121 // we must not poison the cache with a rejected promise (otherwise all channel handlers
@@ -121,7 +125,10 @@ export async function loadModelCatalog(params?: {
121125 const agentDir = resolveOpenClawAgentDir ( ) ;
122126 const { shouldSuppressBuiltInModel } = await loadModelSuppression ( ) ;
123127 logStage ( "catalog-deps-ready" ) ;
124- const authStorage = piSdk . discoverAuthStorage ( agentDir ) ;
128+ const authStorage = piSdk . discoverAuthStorage (
129+ agentDir ,
130+ readOnly ? { readOnly : true } : undefined ,
131+ ) ;
125132 logStage ( "auth-storage-ready" ) ;
126133 const registry = instantiatePiModelRegistry (
127134 piSdk ,
@@ -182,7 +189,9 @@ export async function loadModelCatalog(params?: {
182189
183190 if ( models . length === 0 ) {
184191 // If we found nothing, don't cache this result so we can try again.
185- modelCatalogPromise = null ;
192+ if ( ! readOnly ) {
193+ modelCatalogPromise = null ;
194+ }
186195 }
187196
188197 const sorted = sortModels ( models ) ;
@@ -194,14 +203,21 @@ export async function loadModelCatalog(params?: {
194203 log . warn ( `Failed to load model catalog: ${ String ( error ) } ` ) ;
195204 }
196205 // Don't poison the cache on transient dependency/filesystem issues.
197- modelCatalogPromise = null ;
206+ if ( ! readOnly ) {
207+ modelCatalogPromise = null ;
208+ }
198209 if ( models . length > 0 ) {
199210 return sortModels ( models ) ;
200211 }
201212 return [ ] ;
202213 }
203- } ) ( ) ;
214+ } ;
215+
216+ if ( readOnly ) {
217+ return loadCatalog ( ) ;
218+ }
204219
220+ modelCatalogPromise = loadCatalog ( ) ;
205221 return modelCatalogPromise ;
206222}
207223
0 commit comments