Skip to content

Commit bde7033

Browse files
authored
feat(models): dynamic model catalogs via hosted refresh overlay (#113660)
* feat(models): add remote catalog core * feat(config): add model catalog refresh settings * feat(models): wire remote catalog refresh * ci(models): publish hosted catalog * docs(models): document catalog refresh * test(models): allow catalog count growth * refactor(models): preserve safe catalog merge * ci(models): publish catalog through GitHub * docs(models): link public catalog history * fix(model-catalog): enforce Kysely store access * fix(model-catalog): trim unused catalog exports * docs(models): refresh generated docs map
1 parent 31190d6 commit bde7033

46 files changed

Lines changed: 2504 additions & 32 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎config/knip.config.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,21 @@ const config = {
488488
],
489489
project: ["src/**/*.ts!"],
490490
},
491+
"packages/model-catalog-core": {
492+
// Mirror the published export map so package-owned runtime dependencies
493+
// are traced from the TypeScript sources instead of the JS fallback.
494+
entry: [
495+
"src/index.ts!",
496+
"src/configured-model-refs.ts!",
497+
"src/model-catalog-normalize.ts!",
498+
"src/model-catalog-refs.ts!",
499+
"src/model-catalog-types.ts!",
500+
"src/provider-id.ts!",
501+
"src/provider-model-id-normalization.ts!",
502+
"src/provider-model-id-normalize.ts!",
503+
],
504+
project: ["src/**/*.ts!"],
505+
},
491506
"packages/normalization-core": {
492507
// Mirror package.json exports; root and UI builds consume these source subpaths directly.
493508
entry: [
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"core": 2304,
2+
"core": 2307,
33
"channel": 3630,
44
"plugin": 3556
55
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
9228db8de076c307b98fed5c4f9253b05a2604e9022c15baf16ccde86da11953 config-baseline.json
2-
5e4dc33f0419716ec1fd8ac03d85fe3d1a0f2014674c62debdcb5d5c9a869eef config-baseline.core.json
1+
f1956566f629dc6e6d7f0b2ce268e25dede588e352faf3d9c1009d3856eb4d53 config-baseline.json
2+
8824942e998e77a20892b58f27bf739e5566da71fc81c101c73bc37d99c13a47 config-baseline.core.json
33
af6ca0e70007113462270d46fa14ef0551e577e2fa157d2b9f6d0a93d36f96f1 config-baseline.channel.json
4-
85c24c09df92ac432bf22c9ea44e894dec3ffad3a7ee7960612699eec6a42e6e config-baseline.plugin.json
4+
d47f7eb4268480e99ab85b6c1b5ee07f6c570ce0555e3db682ec26037014b47e config-baseline.plugin.json

‎docs/cli/models.md‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Related:
2121
```bash
2222
openclaw models status
2323
openclaw models list
24+
openclaw models refresh
2425
openclaw models set <model-or-alias>
2526
openclaw models set-image <model-or-alias>
2627
openclaw models scan
@@ -64,6 +65,13 @@ For OpenAI ChatGPT/Codex OAuth troubleshooting, `openclaw models status`, `openc
6465

6566
`openclaw models list` is read-only: it reads config, auth profiles, existing catalog state, and provider-owned catalog rows, but never rewrites `models.json`.
6667

68+
`openclaw models refresh [--json]` forces an immediate hosted catalog check.
69+
Updated rows apply to a running Gateway after its next restart. The command
70+
prints a clear disabled result when `models.catalogRefresh.enabled` is `false`.
71+
The catalog's public change history lives in
72+
[`openclaw/catalog`](https://github.com/openclaw/catalog), where each content
73+
update is committed by the scheduled publisher.
74+
6775
Options: `--all` (full catalog), `--local` (filter to local models), `--provider <id>`, `--json`, `--plain`.
6876

6977
Notes:

‎docs/concepts/models.md‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,31 @@ openclaw models auth list|add|login|paste-api-key|paste-token|setup-token|order
212212

213213
## Models registry (`models.json`)
214214

215+
### Hosted catalog updates
216+
217+
OpenClaw can refresh the model metadata shipped by installed provider plugins
218+
without waiting for a new OpenClaw release. The Gateway makes one background
219+
JSON `GET` at startup and then checks at most every six hours. The request sends
220+
no prompts, credentials, model usage, or configuration payload beyond the
221+
normal HTTP user agent and conditional cache headers.
222+
223+
The downloaded bundle is stored in the shared SQLite state database and becomes
224+
visible after the next Gateway restart. Remote data can update or add models
225+
only for providers declared by installed plugin manifests. It cannot supply API
226+
base URLs or request headers, and a catalog older than the installed release's
227+
build stamp is ignored.
228+
229+
The hosted file is published from the public
230+
[`openclaw/catalog`](https://github.com/openclaw/catalog) GitHub repository.
231+
Its scheduled workflow refreshes from OpenClaw's shipped plugin manifests and
232+
pricing sources; every catalog content change is preserved as a public commit.
233+
234+
Run `openclaw models refresh` for an immediate check, or disable every hosted
235+
catalog request with `models.catalogRefresh.enabled: false`. A self-hosted mirror
236+
can be selected with an HTTPS `models.catalogRefresh.url` (or localhost HTTP
237+
for testing); see
238+
[configuration reference](/gateway/configuration-reference#models).
239+
215240
Custom providers configured under `models.providers` are written into `models.json` under the agent directory (default `~/.openclaw/agents/<agentId>/agent/models.json`). Provider-plugin catalogs are stored separately as generated plugin-owned catalog shards and load automatically. This file is merged with config by default; set `models.mode: "replace"` to use only your configured providers.
216241

217242
<AccordionGroup>

‎docs/docs_map.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2761,6 +2761,7 @@ Do not edit it by hand; run `pnpm docs:map:gen`.
27612761
- H2: /model in chat
27622762
- H2: CLI
27632763
- H2: Models registry (models.json)
2764+
- H3: Hosted catalog updates
27642765
- H2: Related
27652766

27662767
## concepts/multi-agent.md

‎docs/gateway/configuration-reference.md‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ The `models` root also owns global model-catalog behavior.
6666
models: {
6767
// Optional. Default: true. Requires a Gateway restart when changed.
6868
pricing: { enabled: false },
69+
// Optional. Hosted catalog updates default on.
70+
catalogRefresh: {
71+
enabled: true,
72+
// url: "https://catalog.example.com/openclaw/catalog.json",
73+
},
6974
},
7075
}
7176
```
@@ -80,6 +85,14 @@ The `models` root also owns global model-catalog behavior.
8085
starts after sidecars and channels reach the Gateway ready path. When `false`,
8186
the Gateway skips OpenRouter and LiteLLM pricing-catalog fetches; configured
8287
`models.providers.*.models[].cost` values still work for local cost estimates.
88+
- `models.catalogRefresh.enabled`: controls the hosted model catalog refresh
89+
(default: `true`). Set it to `false` to prevent all remote catalog requests;
90+
only catalog data shipped in the installed release is then used.
91+
- `models.catalogRefresh.url`: optional HTTPS mirror override (plain HTTP is
92+
accepted only for explicit localhost testing). The Gateway
93+
checks in the background at startup and every six hours. A downloaded catalog
94+
applies on the next Gateway restart; a release whose bundled catalog is newer
95+
always wins.
8396

8497
## MCP
8598

‎packages/model-catalog-core/package.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"main": "./dist/index.mjs",
1010
"types": "./dist/index.d.mts",
1111
"dependencies": {
12-
"@openclaw/normalization-core": "workspace:*"
12+
"@openclaw/normalization-core": "workspace:*",
13+
"zod": "4.4.3"
1314
},
1415
"exports": {
1516
".": {

‎packages/model-catalog-core/src/index.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ export * from "./model-catalog-types.js";
77
export * from "./provider-id.js";
88
export * from "./provider-model-id-normalization.js";
99
export * from "./provider-model-id-normalize.js";
10+
export * from "./remote-catalog-bundle.js";
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import { describe, expect, it } from "vitest";
2+
import {
3+
parseRemoteModelCatalogBundle,
4+
validateAndSanitizeRemoteModelCatalogBundle,
5+
} from "./remote-catalog-bundle.js";
6+
7+
const validBundle = {
8+
schemaVersion: 1,
9+
generatedAt: 1_753_500_000_000,
10+
minVersion: "2026.7.0",
11+
sourceCommit: "abc123",
12+
providers: {
13+
anthropic: {
14+
baseUrl: "https://evil.test",
15+
headers: { Authorization: "bad" },
16+
models: [
17+
{
18+
id: "claude-test",
19+
baseUrl: "https://evil.test/model",
20+
headers: { "X-Evil": "yes" },
21+
compat: { nested: { baseUrl: "https://evil.test/nested", headers: { X: "y" } } },
22+
},
23+
],
24+
},
25+
},
26+
} as const;
27+
28+
describe("remote model catalog bundle", () => {
29+
it("accepts schema v1 and deeply strips endpoint and header fields", () => {
30+
const parsed = validateAndSanitizeRemoteModelCatalogBundle(validBundle);
31+
const anthropic = parsed.providers.anthropic;
32+
expect(anthropic).toBeDefined();
33+
if (!anthropic) {
34+
throw new Error("expected anthropic provider");
35+
}
36+
expect(anthropic).not.toHaveProperty("baseUrl");
37+
expect(anthropic).not.toHaveProperty("headers");
38+
expect(anthropic.models[0]).not.toHaveProperty("baseUrl");
39+
expect(anthropic.models[0]).not.toHaveProperty("headers");
40+
expect(anthropic.models[0]?.compat).toEqual({ nested: {} });
41+
});
42+
43+
it("rejects unsupported versions, invalid timestamps, and malformed providers", () => {
44+
expect(() => parseRemoteModelCatalogBundle({ ...validBundle, schemaVersion: 2 })).toThrow();
45+
expect(() => parseRemoteModelCatalogBundle({ ...validBundle, generatedAt: 0 })).toThrow();
46+
expect(() =>
47+
parseRemoteModelCatalogBundle({
48+
...validBundle,
49+
generatedAt: Date.now() + 2 * 24 * 60 * 60_000,
50+
}),
51+
).toThrow("generatedAt is implausibly far in the future");
52+
expect(() =>
53+
parseRemoteModelCatalogBundle({ ...validBundle, providers: { anthropic: { models: [] } } }),
54+
).toThrow();
55+
expect(() =>
56+
parseRemoteModelCatalogBundle({
57+
...validBundle,
58+
providers: { anthropic: { models: [{ id: " duplicate " }, { id: "duplicate" }] } },
59+
}),
60+
).toThrow("duplicate model id: duplicate");
61+
});
62+
});

0 commit comments

Comments
 (0)