Skip to content

Commit 3303217

Browse files
committed
refactor(models): remove obsolete prepared catalog paths
1 parent 83b40f3 commit 3303217

13 files changed

Lines changed: 44 additions & 218 deletions

‎src/agents/models-config.skips-writing-models-json-no-env-token.test.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,15 @@ import {
1616
import type { ProviderConfig as ModelsProviderConfig } from "./models-config.providers.secrets.js";
1717
import {
1818
encodePluginModelCatalogRelativePath,
19-
listPersistedPluginModelCatalogs,
19+
loadPersistedPluginModelCatalogs,
2020
PLUGIN_MODEL_CATALOG_GENERATED_BY,
2121
replacePersistedPluginModelCatalogs,
2222
} from "./plugin-model-catalog.js";
2323

24+
function listPersistedPluginModelCatalogs(agentDir: string) {
25+
return loadPersistedPluginModelCatalogs(agentDir).catalogs;
26+
}
27+
2428
vi.mock("./auth-profiles/external-cli-sync.js", () => ({
2529
resolveExternalCliAuthProfiles: () => [],
2630
syncExternalCliCredentials: () => false,

‎src/agents/models-config.write-serialization.test.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,15 @@ import {
1313
import { readGeneratedModelsJson } from "./models-config.test-utils.js";
1414
import {
1515
encodePluginModelCatalogRelativePath,
16-
listPersistedPluginModelCatalogs,
16+
loadPersistedPluginModelCatalogs,
1717
PLUGIN_MODEL_CATALOG_GENERATED_BY,
1818
replacePersistedPluginModelCatalogs,
1919
} from "./plugin-model-catalog.js";
2020

21+
function listPersistedPluginModelCatalogs(agentDir: string) {
22+
return loadPersistedPluginModelCatalogs(agentDir).catalogs;
23+
}
24+
2125
const planOpenClawModelsJsonMock = vi.fn();
2226
const writePrivateStoreTextWriteMock = vi.fn();
2327
let actualPrivateFileStore:

‎src/agents/plugin-model-catalog.test.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,16 @@ import { closeOpenClawAgentDatabasesForTest } from "../state/openclaw-agent-db.j
1818
import {
1919
decodePluginModelCatalogRelativePathPluginId,
2020
encodePluginModelCatalogRelativePath,
21-
listPersistedPluginModelCatalogs,
2221
loadPersistedPluginModelCatalogs,
2322
migrateLegacyPluginModelCatalogs,
2423
PLUGIN_MODEL_CATALOG_GENERATED_BY,
2524
replacePersistedPluginModelCatalogs,
2625
} from "./plugin-model-catalog.js";
2726

27+
function listPersistedPluginModelCatalogs(agentDir: string) {
28+
return loadPersistedPluginModelCatalogs(agentDir).catalogs;
29+
}
30+
2831
const tempDirs: string[] = [];
2932

3033
function createAgentDir(): string {

‎src/agents/plugin-model-catalog.ts‎

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ export function isPluginModelCatalogMigrationFile(filename: string): boolean {
3535

3636
type PluginModelCatalogDatabase = Pick<OpenClawAgentKyselyDatabase, "cache_entries">;
3737

38-
export type PersistedPluginModelCatalog = {
38+
type PersistedPluginModelCatalog = {
3939
pluginId: string;
4040
contents: string;
4141
};
4242

43-
export type PersistedPluginModelCatalogLoadResult = {
43+
type PersistedPluginModelCatalogLoadResult = {
4444
catalogs: PersistedPluginModelCatalog[];
4545
warnings: string[];
4646
};
@@ -187,7 +187,7 @@ function replacePersistedPluginModelCatalogEntries(params: {
187187
);
188188
}
189189

190-
export type PluginModelCatalogMigrationResult = {
190+
type PluginModelCatalogMigrationResult = {
191191
detected: number;
192192
migrated: number;
193193
warnings: string[];
@@ -552,11 +552,6 @@ export function loadPersistedPluginModelCatalogs(
552552
};
553553
}
554554

555-
/** Reads plugin-owned catalogs after any credential-preserving upgrade migration. */
556-
export function listPersistedPluginModelCatalogs(agentDir: string): PersistedPluginModelCatalog[] {
557-
return loadPersistedPluginModelCatalogs(agentDir).catalogs;
558-
}
559-
560555
/** Replaces rebuildable provider catalogs in the existing per-agent SQLite cache. */
561556
export function replacePersistedPluginModelCatalogs(params: {
562557
agentDir: string;
@@ -589,7 +584,7 @@ export function encodePluginModelCatalogRelativePath(pluginId: string): string {
589584
}
590585

591586
/** Returns true only for canonical profile-relative generated catalog paths. */
592-
export function isPluginModelCatalogRelativePath(relativePath: string): boolean {
587+
function isPluginModelCatalogRelativePath(relativePath: string): boolean {
593588
const parts = relativePath.split(/[\\/]/);
594589
return (
595590
!path.isAbsolute(relativePath) &&

‎src/agents/sessions/model-registry.test.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,18 @@ import { dirname, join } from "node:path";
55
import { getApiProvider } from "@openclaw/ai/internal/runtime";
66
import { afterEach, describe, expect, it, vi } from "vitest";
77
import {
8-
listPersistedPluginModelCatalogs,
8+
loadPersistedPluginModelCatalogs,
99
PLUGIN_MODEL_CATALOG_GENERATED_BY,
1010
replacePersistedPluginModelCatalogs,
1111
} from "../plugin-model-catalog.js";
1212
import { AuthStorage } from "./auth-storage.js";
1313
import { getModelRegistryRuntime } from "./model-registry-runtime.js";
1414
import { ModelRegistry, type ProviderConfigInput } from "./model-registry.js";
1515

16+
function listPersistedPluginModelCatalogs(agentDir: string) {
17+
return loadPersistedPluginModelCatalogs(agentDir).catalogs;
18+
}
19+
1620
const PLUGIN_MODEL_CATALOG_FILE = "catalog.json";
1721

1822
const tempDirs: string[] = [];

‎src/commands/doctor-plugin-model-catalog.test.ts‎

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,21 @@ import path from "node:path";
55
import { afterEach, describe, expect, it, vi } from "vitest";
66
import {
77
encodePluginModelCatalogRelativePath,
8-
listPersistedPluginModelCatalogs,
8+
loadPersistedPluginModelCatalogs,
99
PLUGIN_MODEL_CATALOG_GENERATED_BY,
1010
replacePersistedPluginModelCatalogs,
1111
} from "../agents/plugin-model-catalog.js";
1212
import type { OpenClawConfig } from "../config/types.openclaw.js";
1313
import type { RuntimeEnv } from "../runtime.js";
1414
import { closeOpenClawAgentDatabasesForTest } from "../state/openclaw-agent-db.js";
1515
import { closeOpenClawStateDatabaseForTest } from "../state/openclaw-state-db.js";
16-
import {
17-
collectLegacyPluginModelCatalogMigrations,
18-
maybeMigrateLegacyPluginModelCatalogs,
19-
} from "./doctor-plugin-model-catalog.js";
16+
import { maybeMigrateLegacyPluginModelCatalogs } from "./doctor-plugin-model-catalog.js";
2017
import type { DoctorPrompter } from "./doctor-prompter.js";
2118

19+
function listPersistedPluginModelCatalogs(agentDir: string) {
20+
return loadPersistedPluginModelCatalogs(agentDir).catalogs;
21+
}
22+
2223
const tempDirs: string[] = [];
2324

2425
function createAgentDir(): string {
@@ -215,9 +216,6 @@ describe("doctor generated plugin model catalog migration", () => {
215216
);
216217
const malformedPath = writeLegacyCatalog(agentDir, "malformed", "{not-json");
217218

218-
await expect(
219-
collectLegacyPluginModelCatalogMigrations({ cfg: {}, agentDirs: [agentDir] }),
220-
).resolves.toEqual([]);
221219
await expect(
222220
maybeMigrateLegacyPluginModelCatalogs(migrationParams([agentDir])),
223221
).resolves.toEqual({ detected: 0, migrated: 0, warnings: [] });

‎src/commands/doctor-plugin-model-catalog.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import type { RuntimeEnv } from "../runtime.js";
1616
import { shortenHomePath } from "../utils.js";
1717
import type { DoctorPrompter } from "./doctor-prompter.js";
1818

19-
export type LegacyPluginModelCatalogMigration = {
19+
type LegacyPluginModelCatalogMigration = {
2020
agentDir: string;
2121
pluginId: string;
2222
relativePath: string;
@@ -49,7 +49,7 @@ async function readLegacyPluginCatalogContents(params: {
4949
}
5050

5151
/** Detects only marker-backed catalogs produced by tagged OpenClaw releases. */
52-
export async function collectLegacyPluginModelCatalogMigrations(params: {
52+
async function collectLegacyPluginModelCatalogMigrations(params: {
5353
cfg: OpenClawConfig;
5454
env?: NodeJS.ProcessEnv;
5555
agentDirs?: readonly string[];

‎src/commands/models/list.manifest-catalog.test.ts‎

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,8 @@ describe("loadStaticManifestCatalogRowsForList", () => {
100100
});
101101
});
102102

103-
it("loads refreshable manifest rows as registry-backed supplements", async () => {
104-
const { loadSupplementalManifestCatalogRowsForList } =
105-
await import("./list.manifest-catalog.js");
103+
it("does not expose refreshable provider previews as prepared models", async () => {
104+
const { loadStaticManifestCatalogRowsForList } = await import("./list.manifest-catalog.js");
106105
const manifestRegistry = {
107106
plugins: [openrouterPlugin, moonshotPlugin],
108107
diagnostics: [],
@@ -114,15 +113,14 @@ describe("loadStaticManifestCatalogRowsForList", () => {
114113
});
115114

116115
expect(
117-
loadSupplementalManifestCatalogRowsForList({
116+
loadStaticManifestCatalogRowsForList({
118117
cfg: {},
119118
}).map((row) => row.ref),
120-
).toEqual(["moonshot/kimi-k2.6", "openrouter/auto"]);
119+
).toEqual(["moonshot/kimi-k2.6"]);
121120
});
122121

123-
it("supplements runtime-owned providers with refreshed rows only", async () => {
124-
const { loadStaticManifestCatalogRowsForList, loadSupplementalManifestCatalogRowsForList } =
125-
await import("./list.manifest-catalog.js");
122+
it("does not expose runtime overlay rows as static manifest models", async () => {
123+
const { loadStaticManifestCatalogRowsForList } = await import("./list.manifest-catalog.js");
126124
const manifestRegistry = {
127125
plugins: [openaiRuntimePlugin],
128126
diagnostics: [],
@@ -144,19 +142,11 @@ describe("loadStaticManifestCatalogRowsForList", () => {
144142
cfg: {},
145143
providerFilter: "openai",
146144
metadataSnapshot: metadataSnapshot as unknown as Parameters<
147-
typeof loadSupplementalManifestCatalogRowsForList
145+
typeof loadStaticManifestCatalogRowsForList
148146
>[0]["metadataSnapshot"],
149147
};
150148

151149
expect(loadStaticManifestCatalogRowsForList(params)).toEqual([]);
152-
expect(loadSupplementalManifestCatalogRowsForList(params)).toMatchObject([
153-
{
154-
provider: "openai",
155-
id: "gpt-refreshed",
156-
ref: "openai/gpt-refreshed",
157-
source: "runtime-refresh",
158-
},
159-
]);
160150
});
161151

162152
it("uses an injected metadata snapshot instead of loading metadata again", async () => {

‎src/commands/models/list.manifest-catalog.ts‎

Lines changed: 4 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22
import { normalizeModelCatalogProviderId } from "@openclaw/model-catalog-core/model-catalog-refs";
33
import type { NormalizedModelCatalogRow } from "@openclaw/model-catalog-core/model-catalog-types";
44
import type { OpenClawConfig } from "../../config/types.openclaw.js";
5-
import {
6-
planEffectiveModelCatalogRows,
7-
type ManifestModelCatalogRowSelection,
8-
} from "../../model-catalog/index.js";
5+
import { planEffectiveModelCatalogRows } from "../../model-catalog/index.js";
96
import { loadManifestMetadataSnapshot } from "../../plugins/manifest-contract-eligibility.js";
107
import type { PluginManifestRegistry } from "../../plugins/manifest-registry.js";
118
import type { PluginMetadataSnapshot } from "../../plugins/plugin-metadata-snapshot.types.js";
@@ -19,7 +16,6 @@ import {
1916
function loadManifestCatalogRowsForPluginIds(params: {
2017
cfg: OpenClawConfig;
2118
registry: PluginManifestRegistry;
22-
mode: ManifestModelCatalogRowSelection;
2319
pluginIds?: readonly string[];
2420
providerFilter?: string;
2521
}): readonly NormalizedModelCatalogRow[] {
@@ -37,7 +33,7 @@ function loadManifestCatalogRowsForPluginIds(params: {
3733
registry,
3834
config: params.cfg,
3935
...(params.providerFilter ? { providerFilter: params.providerFilter } : {}),
40-
selection: params.mode,
36+
selection: "static",
4137
}).rows;
4238
}
4339

@@ -76,17 +72,16 @@ function resolveDeclaredModelCatalogPluginIds(params: {
7672
});
7773
}
7874

79-
function loadManifestCatalogRowsForList(params: {
75+
/** Loads authoritative static manifest catalog rows for model-list output. */
76+
export function loadStaticManifestCatalogRowsForList(params: {
8077
cfg: OpenClawConfig;
8178
providerFilter?: string;
8279
env?: NodeJS.ProcessEnv;
83-
mode?: ManifestModelCatalogRowSelection;
8480
metadataSnapshot?: PluginMetadataSnapshot;
8581
}): readonly NormalizedModelCatalogRow[] {
8682
const providerFilter = params.providerFilter
8783
? normalizeModelCatalogProviderId(params.providerFilter)
8884
: undefined;
89-
const mode = params.mode ?? "static";
9085
const snapshot =
9186
params.metadataSnapshot ??
9287
loadManifestMetadataSnapshot({
@@ -98,13 +93,11 @@ function loadManifestCatalogRowsForList(params: {
9893
return loadManifestCatalogRowsForPluginIds({
9994
cfg: params.cfg,
10095
registry: snapshot.manifestRegistry,
101-
mode,
10296
});
10397
}
10498
const conventionRows = loadManifestCatalogRowsForPluginIds({
10599
cfg: params.cfg,
106100
registry: snapshot.manifestRegistry,
107-
mode,
108101
pluginIds: resolveConventionModelCatalogPluginIds({
109102
cfg: params.cfg,
110103
index,
@@ -118,7 +111,6 @@ function loadManifestCatalogRowsForList(params: {
118111
return loadManifestCatalogRowsForPluginIds({
119112
cfg: params.cfg,
120113
registry: snapshot.manifestRegistry,
121-
mode,
122114
pluginIds: resolveDeclaredModelCatalogPluginIds({
123115
cfg: params.cfg,
124116
index,
@@ -127,29 +119,3 @@ function loadManifestCatalogRowsForList(params: {
127119
providerFilter,
128120
});
129121
}
130-
131-
/** Loads authoritative static manifest catalog rows for model-list output. */
132-
export function loadStaticManifestCatalogRowsForList(params: {
133-
cfg: OpenClawConfig;
134-
providerFilter?: string;
135-
env?: NodeJS.ProcessEnv;
136-
metadataSnapshot?: PluginMetadataSnapshot;
137-
}): readonly NormalizedModelCatalogRow[] {
138-
return loadManifestCatalogRowsForList({
139-
...params,
140-
mode: "static",
141-
});
142-
}
143-
144-
/** Loads supplemental non-runtime manifest catalog rows for fallback list sources. */
145-
export function loadSupplementalManifestCatalogRowsForList(params: {
146-
cfg: OpenClawConfig;
147-
providerFilter?: string;
148-
env?: NodeJS.ProcessEnv;
149-
metadataSnapshot?: PluginMetadataSnapshot;
150-
}): readonly NormalizedModelCatalogRow[] {
151-
return loadManifestCatalogRowsForList({
152-
...params,
153-
mode: "supplemental",
154-
});
155-
}

‎src/model-catalog/index.ts‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// normalized planning APIs instead of reaching into provider-index internals.
33
export { loadOpenClawProviderIndex } from "./provider-index/index.js";
44
export { planManifestModelCatalogSuppressions } from "./manifest-planner.js";
5-
export { planProviderIndexModelCatalogRows } from "./provider-index-planner.js";
65
import type { ModelCatalogProvider } from "@openclaw/model-catalog-core/model-catalog-types";
76
import type { OpenClawConfig } from "../config/types.openclaw.js";
87
import {
@@ -26,8 +25,5 @@ export function planEffectiveModelCatalogRows(params: {
2625
...(params.selection ? { selection: params.selection } : {}),
2726
});
2827
}
29-
export type {
30-
ManifestModelCatalogRowSelection,
31-
ManifestModelCatalogSuppressionEntry,
32-
} from "./manifest-planner.js";
28+
export type { ManifestModelCatalogSuppressionEntry } from "./manifest-planner.js";
3329
export type { OpenClawProviderIndexProvider } from "./provider-index/index.js";

0 commit comments

Comments
 (0)