


























@@ -81,15 +81,17 @@ function instantiatePiModelRegistry(
8181export async function loadModelCatalog(params?: {
8282config?: OpenClawConfig;
8383useCache?: boolean;
84+readOnly?: boolean;
8485}): Promise<ModelCatalogEntry[]> {
85-if (params?.useCache === false) {
86+const readOnly = params?.readOnly === true;
87+if (!readOnly && params?.useCache === false) {
8688modelCatalogPromise = null;
8789}
88-if (modelCatalogPromise) {
90+if (!readOnly && modelCatalogPromise) {
8991return modelCatalogPromise;
9092}
919392-modelCatalogPromise = (async () => {
94+const loadCatalog = async () => {
9395const models: ModelCatalogEntry[] = [];
9496const timingEnabled = shouldLogModelCatalogTiming();
9597const startMs = timingEnabled ? Date.now() : 0;
@@ -110,8 +112,10 @@ export async function loadModelCatalog(params?: {
110112});
111113try {
112114const 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?: {
121125const agentDir = resolveOpenClawAgentDir();
122126const { shouldSuppressBuiltInModel } = await loadModelSuppression();
123127logStage("catalog-deps-ready");
124-const authStorage = piSdk.discoverAuthStorage(agentDir);
128+const authStorage = piSdk.discoverAuthStorage(
129+agentDir,
130+readOnly ? { readOnly: true } : undefined,
131+);
125132logStage("auth-storage-ready");
126133const registry = instantiatePiModelRegistry(
127134piSdk,
@@ -182,7 +189,9 @@ export async function loadModelCatalog(params?: {
182189183190if (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}
187196188197const sorted = sortModels(models);
@@ -194,14 +203,21 @@ export async function loadModelCatalog(params?: {
194203log.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+}
198209if (models.length > 0) {
199210return sortModels(models);
200211}
201212return [];
202213}
203-})();
214+};
215+216+if (readOnly) {
217+return loadCatalog();
218+}
204219220+modelCatalogPromise = loadCatalog();
205221return modelCatalogPromise;
206222}
207223此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。