



















@@ -0,0 +1,96 @@
1+import type { OpenClawConfig } from "../../config/types.openclaw.js";
2+import type { NormalizedModelCatalogRow } from "../../model-catalog/index.js";
3+4+export type ModelListSourcePlanKind =
5+| "registry"
6+| "manifest"
7+| "provider-index"
8+| "provider-runtime-static"
9+| "provider-runtime-scoped";
10+11+export type ModelListSourcePlan = {
12+kind: ModelListSourcePlanKind;
13+manifestCatalogRows: readonly NormalizedModelCatalogRow[];
14+providerIndexCatalogRows: readonly NormalizedModelCatalogRow[];
15+requiresInitialRegistry: boolean;
16+skipRuntimeModelSuppression: boolean;
17+fallbackToRegistryWhenEmpty: boolean;
18+};
19+20+function createSourcePlan(params: {
21+kind: ModelListSourcePlanKind;
22+manifestCatalogRows?: readonly NormalizedModelCatalogRow[];
23+providerIndexCatalogRows?: readonly NormalizedModelCatalogRow[];
24+requiresInitialRegistry?: boolean;
25+skipRuntimeModelSuppression?: boolean;
26+fallbackToRegistryWhenEmpty?: boolean;
27+}): ModelListSourcePlan {
28+return {
29+kind: params.kind,
30+manifestCatalogRows: params.manifestCatalogRows ?? [],
31+providerIndexCatalogRows: params.providerIndexCatalogRows ?? [],
32+requiresInitialRegistry: params.requiresInitialRegistry ?? false,
33+skipRuntimeModelSuppression: params.skipRuntimeModelSuppression ?? false,
34+fallbackToRegistryWhenEmpty: params.fallbackToRegistryWhenEmpty ?? false,
35+};
36+}
37+38+export function createRegistryModelListSourcePlan(): ModelListSourcePlan {
39+return createSourcePlan({
40+kind: "registry",
41+requiresInitialRegistry: true,
42+});
43+}
44+45+export async function planAllModelListSources(params: {
46+all?: boolean;
47+providerFilter?: string;
48+cfg: OpenClawConfig;
49+}): Promise<ModelListSourcePlan> {
50+if (!params.all || !params.providerFilter) {
51+return createRegistryModelListSourcePlan();
52+}
53+54+const { loadStaticManifestCatalogRowsForList } = await import("./list.manifest-catalog.js");
55+const manifestCatalogRows = loadStaticManifestCatalogRowsForList({
56+cfg: params.cfg,
57+providerFilter: params.providerFilter,
58+});
59+if (manifestCatalogRows.length > 0) {
60+return createSourcePlan({
61+kind: "manifest",
62+ manifestCatalogRows,
63+skipRuntimeModelSuppression: true,
64+});
65+}
66+67+const { loadProviderIndexCatalogRowsForList } = await import("./list.provider-index-catalog.js");
68+const providerIndexCatalogRows = loadProviderIndexCatalogRowsForList({
69+cfg: params.cfg,
70+providerFilter: params.providerFilter,
71+});
72+if (providerIndexCatalogRows.length > 0) {
73+return createSourcePlan({
74+kind: "provider-index",
75+ providerIndexCatalogRows,
76+skipRuntimeModelSuppression: true,
77+});
78+}
79+80+const { hasProviderStaticCatalogForFilter } = await import("./list.provider-catalog.js");
81+const hasProviderStaticCatalog = await hasProviderStaticCatalogForFilter({
82+cfg: params.cfg,
83+providerFilter: params.providerFilter,
84+});
85+if (hasProviderStaticCatalog) {
86+return createSourcePlan({
87+kind: "provider-runtime-static",
88+skipRuntimeModelSuppression: true,
89+fallbackToRegistryWhenEmpty: true,
90+});
91+}
92+93+return createSourcePlan({
94+kind: "provider-runtime-scoped",
95+});
96+}
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。