Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions apps/kimi-code/scripts/update-catalog.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
* Fetches models.dev/api.json, strips fields not needed by kimi-code, and
* writes the result as raw JSON for release builds to inline.
*
* This script intentionally does not write into src/. The source tree keeps a
* placeholder so the generated catalog is not committed.
* Release builds pass --out to a scratch file and inline it through the
* __KIMI_CODE_BUILT_IN_CATALOG__ define. The same output is also checked in
* at packages/agent-core-v2/src/app/kosongConfig/builtInModelsDev.snapshot.json
* as the fallback for builds from source (dev, the desktop app); regenerate
* it with `pnpm --filter @moonshot-ai/agent-core-v2 catalog:update`.
*/

import { mkdirSync, writeFileSync } from "node:fs";
Expand Down
1 change: 1 addition & 0 deletions packages/agent-core-v2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"test": "vitest run",
"typecheck": "tsc -p tsconfig.json --noEmit",
"gen:contract-types": "node scripts/gen-contract-types.mjs",
"catalog:update": "node ../../apps/kimi-code/scripts/update-catalog.mjs --out src/app/kosongConfig/builtInModelsDev.snapshot.json",
"gen:config-manifest": "tsx --import ../../build/register-raw-text-loader.mjs scripts/gen-config-manifest.mts",
"gen:wire-manifest": "tsx --import ../../build/register-raw-text-loader.mjs scripts/gen-wire-manifest.mts",
"gen:state-manifest": "tsx scripts/gen-state-manifest.mts",
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import BUILT_IN_SNAPSHOT_JSON from './builtInModelsDev.snapshot.json?raw';

declare const __KIMI_CODE_BUILT_IN_CATALOG__: string | undefined;

export const BUILT_IN_MODELS_DEV_JSON: string | undefined =
typeof __KIMI_CODE_BUILT_IN_CATALOG__ === 'string'
? __KIMI_CODE_BUILT_IN_CATALOG__
: undefined;
: BUILT_IN_SNAPSHOT_JSON;
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@ let nowImpl: () => number = Date.now;
export function setModelsDevUpstreamForTest(options: {
fetchImpl?: typeof fetch;
now?: () => number;
builtInCatalog?: ModelsDevCatalog;
}): void {
if (options.fetchImpl !== undefined) fetchImpl = options.fetchImpl;
if (options.now !== undefined) nowImpl = options.now;
if ('builtInCatalog' in options) builtInMemo = options.builtInCatalog;
}

export function resetModelsDevUpstreamForTest(): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,27 @@ describe('IModelsDevImportService', () => {
});

it('throws provider.catalog_unavailable when the fetch fails without a snapshot', async () => {
setModelsDevUpstreamForTest({ fetchImpl: fetchFail() });
setModelsDevUpstreamForTest({ fetchImpl: fetchFail(), builtInCatalog: undefined });
const { imports } = createHost();
const err = await expectError2(imports.listModelsDevProviders(), codes.CATALOG_UNAVAILABLE);
expect(err.message).toContain('models.dev catalog unavailable');
});

it('falls back to the checked-in snapshot when the fetch fails', async () => {
setModelsDevUpstreamForTest({ fetchImpl: fetchFail() });
const { imports } = createHost();
const items = await imports.listModelsDevProviders();
const byId = new Map(items.map((item) => [item.id, item]));

expect(items.length).toBeGreaterThan(0);
expect(byId.get('openai')).toMatchObject({
wire_type: 'openai',
rejected: false,
env_key: 'OPENAI_API_KEY',
});
expect(byId.get('openai')?.models.length).toBeGreaterThan(0);
});

it('imports a catalog entry as provider + aliases without touching the default pointers', async () => {
setModelsDevUpstreamForTest({ fetchImpl: fetchJson(CATALOG) });
const { config, imports } = createHost({
Expand Down
Loading