




















@@ -5,20 +5,52 @@ import type { RuntimeEnv } from "../../runtime.js";
55import { normalizeLowercaseStringOrEmpty } from "../../shared/string-coerce.js";
66import { resolveConfiguredEntries } from "./list.configured.js";
77import { formatErrorWithStack } from "./list.errors.js";
8-import { hasProviderStaticCatalogForFilter } from "./list.provider-catalog.js";
9-import { loadConfiguredListModelRegistry, loadListModelRegistry } from "./list.registry-load.js";
10-import {
11-appendAllModelRowSources,
12-appendConfiguredModelRowSources,
13-modelRowSourcesRequireRegistry,
14-} from "./list.row-sources.js";
158import { printModelTable } from "./list.table.js";
169import type { ModelRow } from "./list.types.js";
1710import { loadModelsConfigWithSource } from "./load-config.js";
1811import { DEFAULT_PROVIDER, ensureFlagCompatibility } from "./shared.js";
19122013const DISPLAY_MODEL_PARSE_OPTIONS = { allowPluginNormalization: false } as const;
211415+type RegistryLoadModule = typeof import("./list.registry-load.js");
16+type RowSourcesModule = typeof import("./list.row-sources.js");
17+type ProviderCatalogModule = typeof import("./list.provider-catalog.js");
18+19+let registryLoadModulePromise: Promise<RegistryLoadModule> | undefined;
20+let rowSourcesModulePromise: Promise<RowSourcesModule> | undefined;
21+let providerCatalogModulePromise: Promise<ProviderCatalogModule> | undefined;
22+23+function loadRegistryLoadModule(): Promise<RegistryLoadModule> {
24+registryLoadModulePromise ??= import("./list.registry-load.js");
25+return registryLoadModulePromise;
26+}
27+28+function loadRowSourcesModule(): Promise<RowSourcesModule> {
29+rowSourcesModulePromise ??= import("./list.row-sources.js");
30+return rowSourcesModulePromise;
31+}
32+33+function loadProviderCatalogModule(): Promise<ProviderCatalogModule> {
34+providerCatalogModulePromise ??= import("./list.provider-catalog.js");
35+return providerCatalogModulePromise;
36+}
37+38+function modelRowSourcesRequireRegistry(params: {
39+all?: boolean;
40+providerFilter?: string;
41+useManifestCatalogFastPath: boolean;
42+useProviderCatalogFastPath: boolean;
43+useProviderIndexCatalogFastPath: boolean;
44+}): boolean {
45+if (!params.all) {
46+return false;
47+}
48+if (params.providerFilter) {
49+return false;
50+}
51+return true;
52+}
53+2254export async function modelsListCommand(
2355opts: {
2456all?: boolean;
@@ -48,12 +80,16 @@ export async function modelsListCommand(
4880if (providerFilter === null) {
4981return;
5082}
51-const { ensureAuthProfileStore, resolveOpenClawAgentDir } = await import("./list.runtime.js");
83+const [{ loadAuthProfileStoreWithoutExternalProfiles }, { resolveOpenClawAgentDir }] =
84+await Promise.all([
85+import("../../agents/auth-profiles/store.js"),
86+import("../../agents/agent-paths.js"),
87+]);
5288const { resolvedConfig: cfg } = await loadModelsConfigWithSource({
5389commandName: "models list",
5490 runtime,
5591});
56-const authStore = ensureAuthProfileStore();
92+const authStore = loadAuthProfileStoreWithoutExternalProfiles();
5793const agentDir = resolveOpenClawAgentDir();
58945995let modelRegistry: ModelRegistry | undefined;
@@ -69,16 +105,24 @@ export async function modelsListCommand(
69105manifestCatalogRows = loadStaticManifestCatalogRowsForList({ cfg, providerFilter });
70106}
71107const useManifestCatalogFastPath = manifestCatalogRows.length > 0;
72-const useProviderCatalogFastPath =
73-!useManifestCatalogFastPath && opts.all && providerFilter
74- ? await hasProviderStaticCatalogForFilter({ cfg, providerFilter })
75- : false;
76-if (!useManifestCatalogFastPath && !useProviderCatalogFastPath && opts.all && providerFilter) {
108+if (!useManifestCatalogFastPath && opts.all && providerFilter) {
77109const { loadProviderIndexCatalogRowsForList } =
78110await import("./list.provider-index-catalog.js");
79111providerIndexCatalogRows = loadProviderIndexCatalogRowsForList({ cfg, providerFilter });
80112}
81113const useProviderIndexCatalogFastPath = providerIndexCatalogRows.length > 0;
114+const useProviderCatalogFastPath = await (async () => {
115+if (
116+useManifestCatalogFastPath ||
117+useProviderIndexCatalogFastPath ||
118+!opts.all ||
119+!providerFilter
120+) {
121+return false;
122+}
123+const { hasProviderStaticCatalogForFilter } = await loadProviderCatalogModule();
124+return hasProviderStaticCatalogForFilter({ cfg, providerFilter });
125+})();
82126const shouldLoadRegistry = modelRowSourcesRequireRegistry({
83127all: opts.all,
84128 providerFilter,
@@ -87,6 +131,7 @@ export async function modelsListCommand(
87131 useProviderIndexCatalogFastPath,
88132});
89133const loadRegistryState = async () => {
134+const { loadListModelRegistry } = await loadRegistryLoadModule();
90135const loaded = await loadListModelRegistry(cfg, { providerFilter });
91136modelRegistry = loaded.registry;
92137discoveredKeys = loaded.discoveredKeys;
@@ -96,7 +141,8 @@ export async function modelsListCommand(
96141try {
97142if (shouldLoadRegistry) {
98143await loadRegistryState();
99-} else if (!opts.all) {
144+} else if (!opts.all && opts.local) {
145+const { loadConfiguredListModelRegistry } = await loadRegistryLoadModule();
100146const loaded = loadConfiguredListModelRegistry(cfg, entries, { providerFilter });
101147modelRegistry = loaded.registry;
102148discoveredKeys = loaded.discoveredKeys;
@@ -123,6 +169,7 @@ export async function modelsListCommand(
123169const rows: ModelRow[] = [];
124170125171if (opts.all) {
172+const { appendAllModelRowSources } = await loadRowSourcesModule();
126173let rowContext = buildRowContext(
127174useManifestCatalogFastPath || useProviderCatalogFastPath || useProviderIndexCatalogFastPath,
128175);
@@ -158,17 +205,12 @@ export async function modelsListCommand(
158205});
159206}
160207} else {
161-const registry = modelRegistry;
162-if (!registry) {
163-runtime.error("Model registry unavailable.");
164-process.exitCode = 1;
165-return;
166-}
167-appendConfiguredModelRowSources({
208+const { appendConfiguredModelRowSources } = await loadRowSourcesModule();
209+await appendConfiguredModelRowSources({
168210 rows,
169211 entries,
170-modelRegistry: registry,
171-context: buildRowContext(false),
212+ modelRegistry,
213+context: buildRowContext(!modelRegistry),
172214});
173215}
174216此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。