dsh-model-capability-sync 0.1.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +66 -0
- package/README.md +275 -114
- package/lib/client.js +486 -64
- package/lib/client.js.map +4 -4
- package/lib/index.js +144 -31
- package/lib/index.js.map +3 -3
- package/package.json +10 -3
- package/scripts/test-fields.mjs +56 -0
- package/scripts/test-locale.mjs +54 -0
- package/scripts/test-match.mjs +268 -0
- package/scripts/test-rename.mjs +88 -0
- package/scripts/test-sort.mjs +82 -0
- package/scripts/test-write-merge.mjs +104 -0
- package/src/client/SyncSection.tsx +364 -144
- package/src/client/apply.ts +41 -7
- package/src/client/locale.ts +38 -4
- package/src/client/rename.ts +157 -0
- package/src/client/shared.ts +197 -0
- package/src/index.ts +9 -7
- package/src/mapping.ts +3 -1
- package/src/match.ts +329 -28
- package/src/sort.ts +118 -6
- package/src/types.ts +17 -1
package/lib/index.js
CHANGED
|
@@ -144,7 +144,23 @@ function capabilitiesOf(entry) {
|
|
|
144
144
|
}
|
|
145
145
|
|
|
146
146
|
// src/match.ts
|
|
147
|
-
var VARIANT_SUFFIX =
|
|
147
|
+
var VARIANT_SUFFIX = /[-_](high|low|medium|minimal|max|xhigh|thinking|preview|latest|chat|tiered|disabled|trial|official|free|stable|experimental|reasoning|it|instruct|base|pro|flash|mini|nano|small|large)$/i;
|
|
148
|
+
var ROUTE_TAG = /:[a-z0-9][a-z0-9_-]*$/i;
|
|
149
|
+
var BUILD_NUMBER = /-\d{1,2}$/;
|
|
150
|
+
var VENDOR_PREFIX = /^([a-z]{2,4})-(.+)$/i;
|
|
151
|
+
function stripMarkers(key) {
|
|
152
|
+
let current = key;
|
|
153
|
+
for (let pass = 0; pass < 6; pass += 1) {
|
|
154
|
+
const next = current.replace(ROUTE_TAG, "").replace(VARIANT_SUFFIX, "").replace(BUILD_NUMBER, "");
|
|
155
|
+
if (next === current || next.length === 0) break;
|
|
156
|
+
current = next;
|
|
157
|
+
}
|
|
158
|
+
return current === key ? void 0 : current;
|
|
159
|
+
}
|
|
160
|
+
var SOURCE_ANNOTATION = /【[^】]*】|\([^)]*\)|\[[^\]]*\]/g;
|
|
161
|
+
function cleanDisplayName(name2) {
|
|
162
|
+
return name2.replace(SOURCE_ANNOTATION, " ").replace(/\s+/g, " ").trim();
|
|
163
|
+
}
|
|
148
164
|
var FIRST_PARTY = /* @__PURE__ */ new Set([
|
|
149
165
|
"openai",
|
|
150
166
|
"anthropic",
|
|
@@ -205,11 +221,38 @@ function basename(id) {
|
|
|
205
221
|
}
|
|
206
222
|
function lookup(catalog, key) {
|
|
207
223
|
const exact = catalog.byId.get(key);
|
|
208
|
-
if (exact !== void 0)
|
|
224
|
+
if (exact !== void 0) {
|
|
225
|
+
const folded2 = catalog.byFolded.get(key.toLowerCase());
|
|
226
|
+
return { entries: folded2 !== void 0 && folded2.length > exact.length ? folded2 : exact, via: "exact" };
|
|
227
|
+
}
|
|
209
228
|
const folded = catalog.byFolded.get(key.toLowerCase());
|
|
210
229
|
if (folded !== void 0) return { entries: folded, via: "folded" };
|
|
211
230
|
return void 0;
|
|
212
231
|
}
|
|
232
|
+
function buildPrefixIndex(catalog) {
|
|
233
|
+
const index = /* @__PURE__ */ new Map();
|
|
234
|
+
for (const [id, entries] of catalog.byFolded) {
|
|
235
|
+
for (let length = 4; length <= id.length; length += 1) {
|
|
236
|
+
const key = id.slice(0, length);
|
|
237
|
+
const bucket = index.get(key);
|
|
238
|
+
if (bucket === void 0) index.set(key, [...entries]);
|
|
239
|
+
else bucket.push(...entries);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
return index;
|
|
243
|
+
}
|
|
244
|
+
var prefixCache;
|
|
245
|
+
function prefixesOf(catalog) {
|
|
246
|
+
if (prefixCache !== void 0 && prefixCache.catalog === catalog) return prefixCache.index;
|
|
247
|
+
const index = buildPrefixIndex(catalog);
|
|
248
|
+
prefixCache = { catalog, index };
|
|
249
|
+
return index;
|
|
250
|
+
}
|
|
251
|
+
function versionSpellings(key) {
|
|
252
|
+
const dashed = key.replace(/(\d)[-_.](\d)/g, "$1-$2");
|
|
253
|
+
const dotted = key.replace(/(\d)[-_.](\d)/g, "$1.$2");
|
|
254
|
+
return [.../* @__PURE__ */ new Set([key, dashed, dotted])];
|
|
255
|
+
}
|
|
213
256
|
function describe(entry, via) {
|
|
214
257
|
return {
|
|
215
258
|
provider: entry.provider,
|
|
@@ -219,34 +262,102 @@ function describe(entry, via) {
|
|
|
219
262
|
...entry.model.name === void 0 ? {} : { name: entry.model.name }
|
|
220
263
|
};
|
|
221
264
|
}
|
|
222
|
-
function
|
|
265
|
+
function lookupSpelling(catalog, key) {
|
|
266
|
+
const exact = lookupExact(catalog, key);
|
|
267
|
+
if (exact !== void 0) return exact;
|
|
268
|
+
const dashed = spellGapsAsDashes(key);
|
|
269
|
+
if (dashed === void 0) return void 0;
|
|
270
|
+
const hit = lookupExact(catalog, dashed);
|
|
271
|
+
return hit === void 0 ? void 0 : { entry: hit.entry, via: "spelling" };
|
|
272
|
+
}
|
|
273
|
+
function resolveId(catalog, key) {
|
|
274
|
+
const exact = lookupSpelling(catalog, key);
|
|
275
|
+
if (exact !== void 0) return exact;
|
|
276
|
+
const withoutMarkers = stripMarkers(key);
|
|
277
|
+
if (withoutMarkers !== void 0) {
|
|
278
|
+
const hit = lookupSpelling(catalog, withoutMarkers);
|
|
279
|
+
if (hit !== void 0) return { entry: hit.entry, via: hit.via === "spelling" ? "spelling" : "suffix" };
|
|
280
|
+
const prefixes = prefixesOf(catalog);
|
|
281
|
+
for (const candidate of [withoutMarkers, spellGapsAsDashes(withoutMarkers)]) {
|
|
282
|
+
if (candidate === void 0) continue;
|
|
283
|
+
const prefixed = prefixes.get(candidate.toLowerCase());
|
|
284
|
+
if (prefixed === void 0) continue;
|
|
285
|
+
const entry = pickBest(prefixed);
|
|
286
|
+
if (entry !== void 0) return { entry, via: "prefix" };
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
const peeled = peelVendorNamespace(key);
|
|
290
|
+
if (peeled !== void 0) {
|
|
291
|
+
const hit = lookupSpelling(catalog, peeled);
|
|
292
|
+
if (hit !== void 0) return { entry: hit.entry, via: "vendor" };
|
|
293
|
+
const peeledStripped = stripMarkers(peeled);
|
|
294
|
+
if (peeledStripped !== void 0) {
|
|
295
|
+
const again = lookupSpelling(catalog, peeledStripped);
|
|
296
|
+
if (again !== void 0) return { entry: again.entry, via: "vendor" };
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
return void 0;
|
|
300
|
+
}
|
|
301
|
+
function spellGapsAsDashes(key) {
|
|
302
|
+
const dashed = key.replace(/\s+/g, "-");
|
|
303
|
+
return dashed === key ? void 0 : dashed;
|
|
304
|
+
}
|
|
305
|
+
function lookupExact(catalog, key) {
|
|
306
|
+
const spellings = versionSpellings(key);
|
|
307
|
+
for (const [position, spelling] of spellings.entries()) {
|
|
308
|
+
const hit = lookup(catalog, spelling);
|
|
309
|
+
if (hit === void 0) continue;
|
|
310
|
+
const entry = pickBest(hit.entries);
|
|
311
|
+
if (entry === void 0) continue;
|
|
312
|
+
return { entry, via: position === 0 ? hit.via : "folded" };
|
|
313
|
+
}
|
|
314
|
+
return void 0;
|
|
315
|
+
}
|
|
316
|
+
function peelVendorNamespace(key) {
|
|
317
|
+
const match = VENDOR_PREFIX.exec(key);
|
|
318
|
+
if (match === null) return void 0;
|
|
319
|
+
const rest = match[2];
|
|
320
|
+
if (rest === void 0 || rest.length < 3) return void 0;
|
|
321
|
+
return rest;
|
|
322
|
+
}
|
|
323
|
+
function matchModel(catalog, id, aliases = {}, name2 = "") {
|
|
324
|
+
const onId = resolveId(catalog, id);
|
|
325
|
+
if (onId !== void 0) return describe(onId.entry, onId.via);
|
|
326
|
+
const segments = id.split("/");
|
|
327
|
+
for (let drop = 1; drop < segments.length; drop += 1) {
|
|
328
|
+
const rest = segments.slice(drop).join("/");
|
|
329
|
+
if (rest.length === 0) continue;
|
|
330
|
+
const onRest = resolveId(catalog, rest);
|
|
331
|
+
if (onRest !== void 0) return describe(onRest.entry, onRest.via === "exact" ? "basename" : onRest.via);
|
|
332
|
+
}
|
|
333
|
+
const label = cleanDisplayName(name2);
|
|
334
|
+
if (label.length > 0) {
|
|
335
|
+
const onName = resolveId(catalog, label);
|
|
336
|
+
if (onName !== void 0) {
|
|
337
|
+
return {
|
|
338
|
+
...describe(onName.entry, onName.via === "exact" ? "name" : onName.via === "folded" ? "name" : "nameSuffix"),
|
|
339
|
+
matchedName: label,
|
|
340
|
+
nameSource: "name"
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
const tail = basename(label);
|
|
344
|
+
if (tail !== label && tail.length > 0) {
|
|
345
|
+
const onTail = resolveId(catalog, tail);
|
|
346
|
+
if (onTail !== void 0) {
|
|
347
|
+
return {
|
|
348
|
+
...describe(onTail.entry, onTail.via === "exact" ? "name" : onTail.via === "folded" ? "name" : "nameSuffix"),
|
|
349
|
+
matchedName: tail,
|
|
350
|
+
nameSource: "name"
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
}
|
|
223
355
|
const alias = aliases[id];
|
|
224
356
|
if (alias !== void 0 && alias.length > 0) {
|
|
225
357
|
const hit = lookup(catalog, alias);
|
|
226
358
|
const entry = hit === void 0 ? void 0 : pickBest(hit.entries);
|
|
227
359
|
if (entry !== void 0) return describe(entry, "alias");
|
|
228
360
|
}
|
|
229
|
-
const exact = lookup(catalog, id);
|
|
230
|
-
if (exact !== void 0) {
|
|
231
|
-
const entry = pickBest(exact.entries);
|
|
232
|
-
if (entry !== void 0) return describe(entry, exact.via);
|
|
233
|
-
}
|
|
234
|
-
const base = basename(id);
|
|
235
|
-
if (base !== id) {
|
|
236
|
-
const hit = lookup(catalog, base);
|
|
237
|
-
if (hit !== void 0) {
|
|
238
|
-
const entry = pickBest(hit.entries);
|
|
239
|
-
if (entry !== void 0) return describe(entry, "basename");
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
const stripped = base.replace(VARIANT_SUFFIX, "");
|
|
243
|
-
if (stripped !== base && stripped.length > 0) {
|
|
244
|
-
const hit = lookup(catalog, stripped);
|
|
245
|
-
if (hit !== void 0) {
|
|
246
|
-
const entry = pickBest(hit.entries);
|
|
247
|
-
if (entry !== void 0) return describe(entry, "suffix");
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
361
|
return void 0;
|
|
251
362
|
}
|
|
252
363
|
|
|
@@ -254,24 +365,26 @@ function matchModel(catalog, id, aliases = {}) {
|
|
|
254
365
|
var name = "model-capability-sync";
|
|
255
366
|
var inject = ["connection", "webServer", "llm"];
|
|
256
367
|
var CHANNEL = "/model-capability-sync";
|
|
257
|
-
function previewOne(catalog, id, aliases) {
|
|
258
|
-
const
|
|
259
|
-
|
|
368
|
+
function previewOne(catalog, id, aliases, name2 = "") {
|
|
369
|
+
const named = name2 === "" ? {} : { name: name2 };
|
|
370
|
+
const match = matchModel(catalog, id, aliases, name2);
|
|
371
|
+
if (match === void 0) return { id, ...named, reason: "not in the models.dev catalog" };
|
|
260
372
|
const entry = catalog.byId.get(match.modelId)?.find((candidate) => candidate.provider === match.provider);
|
|
261
|
-
if (entry === void 0) return { id, match, reason: "catalog entry vanished between match and read" };
|
|
373
|
+
if (entry === void 0) return { id, ...named, match, reason: "catalog entry vanished between match and read" };
|
|
262
374
|
const fields = capabilitiesOf(entry);
|
|
263
|
-
if (Object.keys(fields).length === 0) return { id, match, reason: "catalog entry states no capability facts" };
|
|
264
|
-
return { id, match, fields };
|
|
375
|
+
if (Object.keys(fields).length === 0) return { id, ...named, match, reason: "catalog entry states no capability facts" };
|
|
376
|
+
return { id, ...named, match, fields };
|
|
265
377
|
}
|
|
266
378
|
async function preview(request, signal) {
|
|
267
379
|
const ids = Array.isArray(request.ids) ? request.ids.filter((id) => typeof id === "string" && id.length > 0) : [];
|
|
268
380
|
const catalog = await loadCatalog({ refresh: request.refresh === true, proxyUrl: request.proxyUrl }, signal);
|
|
269
381
|
const aliases = request.aliases ?? {};
|
|
382
|
+
const names = request.names ?? {};
|
|
270
383
|
return {
|
|
271
384
|
fetchedAt: catalog.fetchedAt,
|
|
272
385
|
catalogModels: catalog.modelCount,
|
|
273
386
|
...catalog.stale === true ? { stale: true } : {},
|
|
274
|
-
rows: ids.map((id) => previewOne(catalog, id, aliases))
|
|
387
|
+
rows: ids.map((id) => previewOne(catalog, id, aliases, typeof names[id] === "string" ? names[id] : ""))
|
|
275
388
|
};
|
|
276
389
|
}
|
|
277
390
|
function failure(message) {
|
package/lib/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/catalog.ts", "../src/mapping.ts", "../src/match.ts", "../src/index.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * The models.dev catalog: download, cache, and index for lookup.\n *\n * One shared `api.json` carries every provider's model facts. The download\n * happens host-side so the browser never makes a cross-origin request, and a\n * forward proxy stays a plain HTTP proxy the host can use.\n *\n * A copy also lands on disk. The host process may sit behind a network the\n * command line does not share \u2014 a proxy, a firewall, a flaky route \u2014 and a\n * settings page that cannot open because one download failed is worse than a\n * page reading a slightly old catalog. The disk copy is the fallback; its age\n * is reported so the answer is never silently stale.\n * @module dsh-model-capability-sync/catalog\n */\nimport { mkdir, readFile, writeFile } from 'node:fs/promises'\nimport { homedir } from 'node:os'\nimport { dirname, join } from 'node:path'\n\nconst CATALOG_URL = 'https://models.dev/api.json'\n/** Reuse one download for this long; a `refresh` request bypasses it. */\nconst CACHE_TTL_MS = 6 * 60 * 60 * 1000\n/** Attempts per download before falling back to the disk copy. */\nconst DOWNLOAD_ATTEMPTS = 3\n/** Pause between attempts: long enough to outlast a reset connection. */\nconst RETRY_DELAY_MS = 600\n\n/** One model entry as models.dev publishes it (only the fields we read). */\nexport interface ModelsDevModel {\n id?: string\n name?: string\n description?: string\n /** Whether the model accepts reasoning control at all. */\n reasoning?: boolean\n /** Accepted input/output media; `input` is the modality list we map. */\n modalities?: { input?: string[]; output?: string[] }\n /** Capacity facts: token counts. */\n limit?: { context?: number; input?: number; output?: number }\n /** Reasoning control shapes; the `effort` type carries the selectable levels. */\n reasoning_options?: Array<{ type?: string; values?: Array<string | null> }>\n}\n\n/** One catalog entry with its provider id attached. */\nexport interface CatalogEntry {\n provider: string\n id: string\n model: ModelsDevModel\n}\n\n/** A loaded catalog plus its lookup indexes. */\nexport interface Catalog {\n fetchedAt: number\n modelCount: number\n /** True when this copy came from disk because the download failed. */\n stale?: boolean\n /** Exact id \u2192 entries (a bare id can appear under several providers). */\n byId: Map<string, CatalogEntry[]>\n /** Lower-cased id \u2192 entries, for case-insensitive vendor spellings. */\n byFolded: Map<string, CatalogEntry[]>\n}\n\nlet cache: { catalog: Catalog; proxyUrl: string | undefined } | undefined\n\n/** Where the on-disk copy lives, mirroring the other plugins' data roots. */\nconst CACHE_FILE = join(homedir(), '.dsh', 'model-capability-sync', 'catalog.json')\n\n/** The on-disk envelope: the raw catalog body plus when it was fetched. */\ninterface DiskCache {\n fetchedAt: number\n source: string\n body: unknown\n}\n\n/** Persist one successful download; a cache write must never fail the request. */\nasync function writeDiskCache(body: unknown): Promise<void> {\n try {\n const envelope: DiskCache = { fetchedAt: Date.now(), source: CATALOG_URL, body }\n await mkdir(dirname(CACHE_FILE), { recursive: true })\n await writeFile(CACHE_FILE, JSON.stringify(envelope), 'utf8')\n } catch {\n // A read-only or full home directory only costs the fallback, not the answer.\n }\n}\n\n/** Read the on-disk copy, or undefined when there is none to trust. */\nasync function readDiskCache(): Promise<DiskCache | undefined> {\n try {\n const parsed = JSON.parse(await readFile(CACHE_FILE, 'utf8')) as Partial<DiskCache>\n if (typeof parsed.fetchedAt !== 'number' || parsed.body === undefined) return undefined\n return { fetchedAt: parsed.fetchedAt, source: typeof parsed.source === 'string' ? parsed.source : CATALOG_URL, body: parsed.body }\n } catch {\n return undefined\n }\n}\n\n/** Wait between download attempts. */\nfunction pause(ms: number): Promise<void> {\n return new Promise((resolve) => { setTimeout(resolve, ms) })\n}\n\n/** Push one entry into an index bucket. */\nfunction push(index: Map<string, CatalogEntry[]>, key: string, entry: CatalogEntry): void {\n const bucket = index.get(key)\n if (bucket === undefined) index.set(key, [entry])\n else bucket.push(entry)\n}\n\n/** Build both indexes from the raw catalog body. */\nfunction buildCatalog(body: unknown, fetchedAt: number): Catalog {\n const byId = new Map<string, CatalogEntry[]>()\n const byFolded = new Map<string, CatalogEntry[]>()\n let modelCount = 0\n if (typeof body === 'object' && body !== null) {\n for (const [provider, value] of Object.entries(body as Record<string, unknown>)) {\n const models = (value as { models?: Record<string, ModelsDevModel> } | undefined)?.models\n if (typeof models !== 'object' || models === null) continue\n for (const [id, model] of Object.entries(models)) {\n if (id.length === 0) continue\n modelCount += 1\n const entry: CatalogEntry = { provider, id, model }\n push(byId, id, entry)\n push(byFolded, id.toLowerCase(), entry)\n }\n }\n }\n if (modelCount === 0) throw new Error('models.dev returned a catalog with no models')\n return { fetchedAt, modelCount, byId, byFolded }\n}\n\n/** Download the catalog body, optionally through a forward proxy. */\nasync function download(proxyUrl: string | undefined, signal: AbortSignal | undefined): Promise<unknown> {\n if (proxyUrl === undefined || proxyUrl.length === 0) {\n const response = await fetch(CATALOG_URL, { signal })\n if (!response.ok) throw new Error(`models.dev download failed (HTTP ${String(response.status)})`)\n return await response.json()\n }\n // The proxy path needs undici's dispatcher. It ships with the harness\n // runtime; a missing copy is reported instead of silently going direct. The\n // specifier stays a runtime value so this package needs no undici types.\n interface UndiciFace {\n fetch(input: string, init?: Record<string, unknown>): Promise<Response>\n ProxyAgent: new (url: string) => unknown\n }\n const specifier: string = 'undici'\n let undici: UndiciFace\n try {\n undici = await import(specifier) as UndiciFace\n } catch {\n throw new Error('a proxy URL was set but the host cannot load \"undici\"; clear the proxy or install it')\n }\n const dispatcher = new undici.ProxyAgent(proxyUrl)\n const response = await undici.fetch(CATALOG_URL, { signal, dispatcher })\n if (!response.ok) throw new Error(`models.dev download through the proxy failed (HTTP ${String(response.status)})`)\n return await response.json()\n}\n\n/**\n * Load the catalog, reusing the cached copy unless it expired or the caller\n * asked for a refresh.\n *\n * A failed download is retried, then answered from the on-disk copy with\n * `stale` set. Only when both paths fail does this throw, and the message\n * names the network reason so the page can show something actionable.\n * @param options - refresh flag and optional proxy URL.\n * @param signal - caller cancellation.\n * @returns the indexed catalog.\n */\nexport async function loadCatalog(\n options: { refresh?: boolean; proxyUrl?: string } = {},\n signal?: AbortSignal,\n): Promise<Catalog> {\n const now = Date.now()\n const fresh = cache !== undefined\n && cache.proxyUrl === options.proxyUrl\n && now - cache.catalog.fetchedAt < CACHE_TTL_MS\n if (options.refresh !== true && fresh && cache !== undefined) return cache.catalog\n\n let lastError: unknown\n for (let attempt = 1; attempt <= DOWNLOAD_ATTEMPTS; attempt += 1) {\n try {\n const body = await download(options.proxyUrl, signal)\n const catalog = buildCatalog(body, Date.now())\n cache = { catalog, proxyUrl: options.proxyUrl }\n void writeDiskCache(body)\n return catalog\n } catch (error) {\n if (signal?.aborted === true) throw error\n lastError = error\n if (attempt < DOWNLOAD_ATTEMPTS) await pause(RETRY_DELAY_MS)\n }\n }\n\n const disk = await readDiskCache()\n if (disk !== undefined) {\n try {\n const catalog: Catalog = { ...buildCatalog(disk.body, disk.fetchedAt), stale: true }\n cache = { catalog, proxyUrl: options.proxyUrl }\n return catalog\n } catch {\n // A corrupt copy is no better than no copy; report the download failure.\n }\n }\n const reason = lastError instanceof Error ? lastError.message : String(lastError)\n throw new Error(`models.dev catalog unavailable (${reason}) and no local copy exists`)\n}\n", "/**\n * Turning one catalog entry into the capability fields a provider model entry\n * accepts.\n *\n * Everything here is a pure function of catalog data: no gateway call, no\n * guessing beyond the catalog's own facts. A field the catalog does not state\n * stays absent, so the writer never invents a value.\n * @module dsh-model-capability-sync/mapping\n */\nimport type { CatalogEntry } from './catalog.ts'\nimport type { CapabilityFields, Modality } from './types.ts'\n\n/** Thinking levels the harness recognizes, strongest last. */\nconst THINKING_LEVELS = new Set(['off', 'minimal', 'low', 'medium', 'high', 'xhigh', 'max'])\n\n/** A positive integer or nothing. */\nfunction positive(value: unknown): number | undefined {\n return typeof value === 'number' && Number.isFinite(value) && value > 0 ? Math.round(value) : undefined\n}\n\n/** Map the catalog's media list onto the harness's two modalities. */\nfunction modalitiesOf(entry: CatalogEntry): Modality[] | undefined {\n const declared = entry.model.modalities?.input\n if (declared === undefined) return undefined\n const accepted: Modality[] = []\n for (const media of declared) {\n if (media === 'image' && !accepted.includes('image')) accepted.push('image')\n }\n // A model that lists only images still reads text in practice; the harness\n // always sends text, so `text` is never dropped.\n return ['text', ...accepted]\n}\n\n/**\n * Build the reasoning-effort map from the catalog's `effort` option.\n * @returns the dict, `false` when the catalog says the model cannot reason, or\n * `undefined` when the catalog is silent.\n */\nfunction reasoningOf(entry: CatalogEntry): Record<string, string> | false | undefined {\n const model = entry.model\n if (model.reasoning === false) return false\n const option = model.reasoning_options?.find(candidate => candidate.type === 'effort')\n const values = option?.values ?? []\n const efforts: Record<string, string> = {}\n for (const value of values) {\n if (typeof value !== 'string') continue\n if (!THINKING_LEVELS.has(value)) continue\n efforts[value] = value\n }\n return Object.keys(efforts).length > 0 ? efforts : undefined\n}\n\n/**\n * Read every capability the catalog states for one entry.\n *\n * The catalog's display name is deliberately not returned: this plugin fills\n * facts, it never renames a model entry.\n * @param entry - the matched catalog entry.\n * @returns only the fields the catalog actually declares.\n */\nexport function capabilitiesOf(entry: CatalogEntry): CapabilityFields {\n const model = entry.model\n const input = modalitiesOf(entry)\n const reasoningEfforts = reasoningOf(entry)\n return {\n ...positive(model.limit?.context) === undefined ? {} : { contextWindow: positive(model.limit?.context) as number },\n ...positive(model.limit?.output) === undefined ? {} : { maxTokens: positive(model.limit?.output) as number },\n ...input === undefined ? {} : { input },\n ...reasoningEfforts === undefined ? {} : { reasoningEfforts },\n }\n}\n", "/**\n * Matching one configured gateway model id against the models.dev catalog.\n *\n * A gateway aggregates arbitrary upstreams and invents its own ids, so the\n * match walks from strict to loose and reports which rule fired \u2014 the UI shows\n * it, and an explicit alias always wins.\n * @module dsh-model-capability-sync/match\n */\nimport type { Catalog, CatalogEntry } from './catalog.ts'\nimport type { MatchInfo, MatchVia } from './types.ts'\n\n/**\n * Variant suffixes a gateway appends to one upstream model. Stripping them\n * turns `gemini-3.8-flash-high` back into the catalog's `gemini-3.8-flash`.\n */\nconst VARIANT_SUFFIX = /-(high|low|medium|minimal|max|xhigh|thinking|preview|latest|chat)$/\n\n/**\n * First-party vendor provider ids in the models.dev catalog. The same model\n * appears under dozens of aggregators whose capacity numbers disagree, so a\n * vendor entry outranks every reseller when both exist.\n */\nconst FIRST_PARTY = new Set([\n 'openai', 'anthropic', 'google', 'deepseek', 'xai', 'meta', 'mistral', 'cohere',\n 'moonshotai', 'moonshotai-cn', 'zai', 'zhipuai', 'alibaba', 'alibaba-cn', 'qwen',\n 'sensenova', 'minimax', 'stepfun', 'bytedance', 'baidu', 'nvidia', 'microsoft',\n 'amazon', 'ai21', 'perplexity', 'upstage', '01-ai', 'inclusionai', 'tencent', 'kuaishou',\n])\n\n/** How complete an entry's facts are; the most complete wins a tie. */\nfunction score(entry: CatalogEntry): number {\n const model = entry.model\n let value = 0\n if (FIRST_PARTY.has(entry.provider)) value += 5\n if (model.limit?.context !== undefined || model.limit?.output !== undefined) value += 2\n if (model.modalities?.input !== undefined) value += 2\n if (model.reasoning_options !== undefined) value += 1\n if (model.name !== undefined) value += 1\n return value\n}\n\n/**\n * Pick the best of several provider entries for the same id: the one carrying\n * the most facts, then the alphabetically first provider so repeated runs are\n * stable.\n */\nfunction pickBest(entries: readonly CatalogEntry[]): CatalogEntry | undefined {\n let best: CatalogEntry | undefined\n let bestScore = -1\n for (const entry of entries) {\n const value = score(entry)\n if (value > bestScore || value === bestScore && best !== undefined && entry.provider < best.provider) {\n best = entry\n bestScore = value\n }\n }\n return best\n}\n\n/** The id without its vendor path prefix (`qoder-gj/DeepSeek-Flash` \u2192 `DeepSeek-Flash`). */\nfunction basename(id: string): string {\n const slash = id.lastIndexOf('/')\n return slash === -1 ? id : id.slice(slash + 1)\n}\n\n/** Look one key up exactly, then case-insensitively. */\nfunction lookup(catalog: Catalog, key: string): { entries: readonly CatalogEntry[]; via: MatchVia } | undefined {\n const exact = catalog.byId.get(key)\n if (exact !== undefined) return { entries: exact, via: 'exact' }\n const folded = catalog.byFolded.get(key.toLowerCase())\n if (folded !== undefined) return { entries: folded, via: 'folded' }\n return undefined\n}\n\n/** Build the public match record for one chosen entry. */\nfunction describe(entry: CatalogEntry, via: MatchVia): MatchInfo {\n return {\n provider: entry.provider,\n modelId: entry.id,\n via,\n firstParty: FIRST_PARTY.has(entry.provider),\n ...entry.model.name === undefined ? {} : { name: entry.model.name },\n }\n}\n\n/**\n * Resolve one gateway model id.\n * @param catalog - the indexed catalog.\n * @param id - the gateway model id exactly as configured.\n * @param aliases - explicit gateway id \u2192 catalog id overrides.\n * @returns the match, or `undefined` when nothing fits.\n */\nexport function matchModel(\n catalog: Catalog,\n id: string,\n aliases: Readonly<Record<string, string>> = {},\n): MatchInfo | undefined {\n const alias = aliases[id]\n if (alias !== undefined && alias.length > 0) {\n const hit = lookup(catalog, alias)\n const entry = hit === undefined ? undefined : pickBest(hit.entries)\n if (entry !== undefined) return describe(entry, 'alias')\n }\n\n const exact = lookup(catalog, id)\n if (exact !== undefined) {\n const entry = pickBest(exact.entries)\n if (entry !== undefined) return describe(entry, exact.via)\n }\n\n const base = basename(id)\n if (base !== id) {\n const hit = lookup(catalog, base)\n if (hit !== undefined) {\n const entry = pickBest(hit.entries)\n if (entry !== undefined) return describe(entry, 'basename')\n }\n }\n\n const stripped = base.replace(VARIANT_SUFFIX, '')\n if (stripped !== base && stripped.length > 0) {\n const hit = lookup(catalog, stripped)\n if (hit !== undefined) {\n const entry = pickBest(hit.entries)\n if (entry !== undefined) return describe(entry, 'suffix')\n }\n }\n\n return undefined\n}\n", "/**\n * Host half: one RPC channel that answers \"what does the catalog say about\n * these model ids?\".\n *\n * The plugin registers no LLM provider route on purpose \u2014 it only supplies\n * facts. The browser half decides which provider entry to write and performs\n * the write through the official settings service, so this half never touches\n * configuration.\n * @module dsh-model-capability-sync\n */\nimport { loadCatalog } from './catalog.ts'\nimport type { Catalog } from './catalog.ts'\nimport { capabilitiesOf } from './mapping.ts'\nimport { matchModel } from './match.ts'\nimport type { LiveRequest, LiveResponse, LiveRow, PreviewRequest, PreviewResponse, PreviewRow, RpcEnvelope } from './types.ts'\n\n/** Cordis plugin name; the profile entry id matches. */\nexport const name = 'model-capability-sync'\n\n/** The channel is served over the web server, so both services are required. */\nexport const inject = ['connection', 'webServer', 'llm']\n\n/** Own RPC channel; the browser half calls this exact path. */\nconst CHANNEL = '/model-capability-sync'\n\n/** The slice of the host context this plugin uses. */\ninterface HostContext {\n get(service: string): unknown\n effect(callback: () => (() => void | Promise<void>) | void, label?: string): void\n logger: { warn(message: string): void; error(message: unknown): void }\n}\n\ntype Handler = (endpoint: string, payload: unknown, signal: AbortSignal) => Promise<RpcEnvelope<unknown>>\n\n/** The connection service's owner-taking registration (see DESIGN in llm-newapi). */\ninterface Registrar {\n register(owner: unknown, channel: string, handler: Handler): () => Promise<void>\n}\n\n/** Resolve one id against the catalog into a preview row. */\nfunction previewOne(catalog: Catalog, id: string, aliases: Readonly<Record<string, string>>): PreviewRow {\n const match = matchModel(catalog, id, aliases)\n if (match === undefined) return { id, reason: 'not in the models.dev catalog' }\n const entry = catalog.byId.get(match.modelId)?.find(candidate => candidate.provider === match.provider)\n if (entry === undefined) return { id, match, reason: 'catalog entry vanished between match and read' }\n const fields = capabilitiesOf(entry)\n if (Object.keys(fields).length === 0) return { id, match, reason: 'catalog entry states no capability facts' }\n return { id, match, fields }\n}\n\n/** Serve one `preview` request. */\nasync function preview(request: PreviewRequest, signal: AbortSignal): Promise<PreviewResponse> {\n const ids = Array.isArray(request.ids) ? request.ids.filter(id => typeof id === 'string' && id.length > 0) : []\n const catalog = await loadCatalog({ refresh: request.refresh === true, proxyUrl: request.proxyUrl }, signal)\n const aliases = request.aliases ?? {}\n return {\n fetchedAt: catalog.fetchedAt,\n catalogModels: catalog.modelCount,\n ...catalog.stale === true ? { stale: true } : {},\n rows: ids.map(id => previewOne(catalog, id, aliases)),\n }\n}\n\n/** One RPC envelope, never a thrown value: the transport would turn that into an opaque 500. */\nfunction failure(message: string): RpcEnvelope<never> {\n return { ok: false, error: { code: 'internal', message, details: {} } }\n}\n\n/** The LLM registry face this half reads live model metadata through. */\ninterface LlmFace {\n resolveModelInfo(provider: string, model: string, signal?: AbortSignal): Promise<{\n inputModalities?: readonly string[]\n context?: { contextWindow: number }\n defaultMaxTokens?: number\n }>\n}\n\n/**\n * Read what the adapter that owns `provider` reports right now.\n *\n * A configuration entry and the route a chat request takes can disagree: two\n * plugins may claim one provider route, and only the first registration serves\n * it. This answer is what a request would see, so a filled-in `input` that\n * never takes effect becomes visible instead of inferred.\n * @param llm - the LLM registry.\n * @param request - route and model ids to resolve.\n * @param signal - cancellation for adapter-owned lookups.\n * @returns one row per requested id, in request order.\n */\nasync function live(llm: LlmFace, request: LiveRequest, signal: AbortSignal): Promise<LiveResponse> {\n const provider = typeof request.provider === 'string' ? request.provider : ''\n const ids = Array.isArray(request.ids) ? request.ids.filter(id => typeof id === 'string' && id.length > 0) : []\n const rows: LiveRow[] = []\n for (const id of ids) {\n try {\n const info = await llm.resolveModelInfo(provider, id, signal)\n rows.push({\n id,\n ...info.inputModalities === undefined ? {} : { input: [...info.inputModalities] },\n ...info.context === undefined ? {} : { contextWindow: info.context.contextWindow },\n ...info.defaultMaxTokens === undefined ? {} : { maxTokens: info.defaultMaxTokens },\n })\n } catch (error) {\n rows.push({ id, error: error instanceof Error ? error.message : String(error) })\n }\n }\n return { rows }\n}\n\n/**\n * Build the channel handler bound to one LLM registry.\n * @param llm - the LLM registry the `live` endpoint reads through, when present.\n * @returns the endpoint dispatcher.\n */\nfunction createHandler(llm: LlmFace | undefined): Handler {\n return async (endpoint, payload, signal) => {\n try {\n if (endpoint === 'preview') {\n return { ok: true, value: await preview(payload as PreviewRequest, signal) }\n }\n if (endpoint === 'live') {\n if (llm === undefined) return failure('model-capability-sync: no llm service to resolve the live route')\n return { ok: true, value: await live(llm, payload as LiveRequest, signal) }\n }\n return failure(`model-capability-sync: unknown endpoint ${JSON.stringify(endpoint)}`)\n } catch (error) {\n return failure(error instanceof Error ? error.message : String(error))\n }\n }\n}\n\n/**\n * Register the channel. The registration rides the calling fiber, so a plugin\n * reload removes the route with it.\n * @param ctx - host context carrying `connection`, `webServer` and `llm`.\n */\nexport function apply(ctx: HostContext): void {\n const connection = ctx.get('connection')\n const llm = ctx.get('llm') as LlmFace | undefined\n if (connection === undefined) {\n ctx.logger.warn('model-capability-sync: no connection service; the capability channel is unavailable')\n return\n }\n if (llm === undefined) ctx.logger.warn('model-capability-sync: no llm service; the live route check is unavailable')\n const registrar = connection as Registrar\n const handler = createHandler(llm)\n ctx.effect(() => registrar.register(ctx, CHANNEL, handler), 'model-capability-sync: RPC channel')\n}\n"],
|
|
5
|
-
"mappings": ";AAcA,SAAS,OAAO,UAAU,iBAAiB;AAC3C,SAAS,eAAe;AACxB,SAAS,SAAS,YAAY;AAE9B,IAAM,cAAc;AAEpB,IAAM,eAAe,IAAI,KAAK,KAAK;AAEnC,IAAM,oBAAoB;AAE1B,IAAM,iBAAiB;AAoCvB,IAAI;AAGJ,IAAM,aAAa,KAAK,QAAQ,GAAG,QAAQ,yBAAyB,cAAc;AAUlF,eAAe,eAAe,MAA8B;AAC1D,MAAI;AACF,UAAM,WAAsB,EAAE,WAAW,KAAK,IAAI,GAAG,QAAQ,aAAa,KAAK;AAC/E,UAAM,MAAM,QAAQ,UAAU,GAAG,EAAE,WAAW,KAAK,CAAC;AACpD,UAAM,UAAU,YAAY,KAAK,UAAU,QAAQ,GAAG,MAAM;AAAA,EAC9D,QAAQ;AAAA,EAER;AACF;AAGA,eAAe,gBAAgD;AAC7D,MAAI;AACF,UAAM,S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Q,MAAM,UAAU,OAAO,KAAK,EAAE,CAAC;AAAA,IACjF;AAAA,EACF;AACA,SAAO,EAAE,KAAK;AAChB;AAOA,SAAS,cAAc,KAAmC;AACxD,SAAO,OAAO,UAAU,SAAS,WAAW;AAC1C,QAAI;AACF,UAAI,aAAa,WAAW;AAC1B,eAAO,EAAE,IAAI,MAAM,OAAO,MAAM,QAAQ,SAA2B,MAAM,EAAE;AAAA,MAC7E;AACA,UAAI,aAAa,QAAQ;AACvB,YAAI,QAAQ,OAAW,QAAO,QAAQ,iEAAiE;AACvG,eAAO,EAAE,IAAI,MAAM,OAAO,MAAM,KAAK,KAAK,SAAwB,MAAM,EAAE;AAAA,MAC5E;AACA,aAAO,QAAQ,2CAA2C,KAAK,UAAU,QAAQ,CAAC,EAAE;AAAA,IACtF,SAAS,OAAO;AACd,aAAO,QAAQ,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CAAC;AAAA,IACvE;AAAA,EACF;AACF;AAOO,SAAS,MAAM,KAAwB;AAC5C,QAAM,aAAa,IAAI,IAAI,YAAY;AACvC,QAAM,MAAM,IAAI,IAAI,KAAK;AACzB,MAAI,eAAe,QAAW;AAC5B,QAAI,OAAO,KAAK,qFAAqF;AACrG;AAAA,EACF;AACA,MAAI,QAAQ,OAAW,KAAI,OAAO,KAAK,4EAA4E;AACnH,QAAM,YAAY;AAClB,QAAM,UAAU,cAAc,GAAG;AACjC,MAAI,OAAO,MAAM,UAAU,SAAS,KAAK,SAAS,OAAO,GAAG,oCAAoC;AAClG;",
|
|
6
|
-
"names": ["response"]
|
|
4
|
+
"sourcesContent": ["/**\n * The models.dev catalog: download, cache, and index for lookup.\n *\n * One shared `api.json` carries every provider's model facts. The download\n * happens host-side so the browser never makes a cross-origin request, and a\n * forward proxy stays a plain HTTP proxy the host can use.\n *\n * A copy also lands on disk. The host process may sit behind a network the\n * command line does not share \u2014 a proxy, a firewall, a flaky route \u2014 and a\n * settings page that cannot open because one download failed is worse than a\n * page reading a slightly old catalog. The disk copy is the fallback; its age\n * is reported so the answer is never silently stale.\n * @module dsh-model-capability-sync/catalog\n */\nimport { mkdir, readFile, writeFile } from 'node:fs/promises'\nimport { homedir } from 'node:os'\nimport { dirname, join } from 'node:path'\n\nconst CATALOG_URL = 'https://models.dev/api.json'\n/** Reuse one download for this long; a `refresh` request bypasses it. */\nconst CACHE_TTL_MS = 6 * 60 * 60 * 1000\n/** Attempts per download before falling back to the disk copy. */\nconst DOWNLOAD_ATTEMPTS = 3\n/** Pause between attempts: long enough to outlast a reset connection. */\nconst RETRY_DELAY_MS = 600\n\n/** One model entry as models.dev publishes it (only the fields we read). */\nexport interface ModelsDevModel {\n id?: string\n name?: string\n description?: string\n /** Whether the model accepts reasoning control at all. */\n reasoning?: boolean\n /** Accepted input/output media; `input` is the modality list we map. */\n modalities?: { input?: string[]; output?: string[] }\n /** Capacity facts: token counts. */\n limit?: { context?: number; input?: number; output?: number }\n /** Reasoning control shapes; the `effort` type carries the selectable levels. */\n reasoning_options?: Array<{ type?: string; values?: Array<string | null> }>\n}\n\n/** One catalog entry with its provider id attached. */\nexport interface CatalogEntry {\n provider: string\n id: string\n model: ModelsDevModel\n}\n\n/** A loaded catalog plus its lookup indexes. */\nexport interface Catalog {\n fetchedAt: number\n modelCount: number\n /** True when this copy came from disk because the download failed. */\n stale?: boolean\n /** Exact id \u2192 entries (a bare id can appear under several providers). */\n byId: Map<string, CatalogEntry[]>\n /** Lower-cased id \u2192 entries, for case-insensitive vendor spellings. */\n byFolded: Map<string, CatalogEntry[]>\n}\n\nlet cache: { catalog: Catalog; proxyUrl: string | undefined } | undefined\n\n/** Where the on-disk copy lives, mirroring the other plugins' data roots. */\nconst CACHE_FILE = join(homedir(), '.dsh', 'model-capability-sync', 'catalog.json')\n\n/** The on-disk envelope: the raw catalog body plus when it was fetched. */\ninterface DiskCache {\n fetchedAt: number\n source: string\n body: unknown\n}\n\n/** Persist one successful download; a cache write must never fail the request. */\nasync function writeDiskCache(body: unknown): Promise<void> {\n try {\n const envelope: DiskCache = { fetchedAt: Date.now(), source: CATALOG_URL, body }\n await mkdir(dirname(CACHE_FILE), { recursive: true })\n await writeFile(CACHE_FILE, JSON.stringify(envelope), 'utf8')\n } catch {\n // A read-only or full home directory only costs the fallback, not the answer.\n }\n}\n\n/** Read the on-disk copy, or undefined when there is none to trust. */\nasync function readDiskCache(): Promise<DiskCache | undefined> {\n try {\n const parsed = JSON.parse(await readFile(CACHE_FILE, 'utf8')) as Partial<DiskCache>\n if (typeof parsed.fetchedAt !== 'number' || parsed.body === undefined) return undefined\n return { fetchedAt: parsed.fetchedAt, source: typeof parsed.source === 'string' ? parsed.source : CATALOG_URL, body: parsed.body }\n } catch {\n return undefined\n }\n}\n\n/** Wait between download attempts. */\nfunction pause(ms: number): Promise<void> {\n return new Promise((resolve) => { setTimeout(resolve, ms) })\n}\n\n/** Push one entry into an index bucket. */\nfunction push(index: Map<string, CatalogEntry[]>, key: string, entry: CatalogEntry): void {\n const bucket = index.get(key)\n if (bucket === undefined) index.set(key, [entry])\n else bucket.push(entry)\n}\n\n/** Build both indexes from the raw catalog body. */\nfunction buildCatalog(body: unknown, fetchedAt: number): Catalog {\n const byId = new Map<string, CatalogEntry[]>()\n const byFolded = new Map<string, CatalogEntry[]>()\n let modelCount = 0\n if (typeof body === 'object' && body !== null) {\n for (const [provider, value] of Object.entries(body as Record<string, unknown>)) {\n const models = (value as { models?: Record<string, ModelsDevModel> } | undefined)?.models\n if (typeof models !== 'object' || models === null) continue\n for (const [id, model] of Object.entries(models)) {\n if (id.length === 0) continue\n modelCount += 1\n const entry: CatalogEntry = { provider, id, model }\n push(byId, id, entry)\n push(byFolded, id.toLowerCase(), entry)\n }\n }\n }\n if (modelCount === 0) throw new Error('models.dev returned a catalog with no models')\n return { fetchedAt, modelCount, byId, byFolded }\n}\n\n/** Download the catalog body, optionally through a forward proxy. */\nasync function download(proxyUrl: string | undefined, signal: AbortSignal | undefined): Promise<unknown> {\n if (proxyUrl === undefined || proxyUrl.length === 0) {\n const response = await fetch(CATALOG_URL, { signal })\n if (!response.ok) throw new Error(`models.dev download failed (HTTP ${String(response.status)})`)\n return await response.json()\n }\n // The proxy path needs undici's dispatcher. It ships with the harness\n // runtime; a missing copy is reported instead of silently going direct. The\n // specifier stays a runtime value so this package needs no undici types.\n interface UndiciFace {\n fetch(input: string, init?: Record<string, unknown>): Promise<Response>\n ProxyAgent: new (url: string) => unknown\n }\n const specifier: string = 'undici'\n let undici: UndiciFace\n try {\n undici = await import(specifier) as UndiciFace\n } catch {\n throw new Error('a proxy URL was set but the host cannot load \"undici\"; clear the proxy or install it')\n }\n const dispatcher = new undici.ProxyAgent(proxyUrl)\n const response = await undici.fetch(CATALOG_URL, { signal, dispatcher })\n if (!response.ok) throw new Error(`models.dev download through the proxy failed (HTTP ${String(response.status)})`)\n return await response.json()\n}\n\n/**\n * Load the catalog, reusing the cached copy unless it expired or the caller\n * asked for a refresh.\n *\n * A failed download is retried, then answered from the on-disk copy with\n * `stale` set. Only when both paths fail does this throw, and the message\n * names the network reason so the page can show something actionable.\n * @param options - refresh flag and optional proxy URL.\n * @param signal - caller cancellation.\n * @returns the indexed catalog.\n */\nexport async function loadCatalog(\n options: { refresh?: boolean; proxyUrl?: string } = {},\n signal?: AbortSignal,\n): Promise<Catalog> {\n const now = Date.now()\n const fresh = cache !== undefined\n && cache.proxyUrl === options.proxyUrl\n && now - cache.catalog.fetchedAt < CACHE_TTL_MS\n if (options.refresh !== true && fresh && cache !== undefined) return cache.catalog\n\n let lastError: unknown\n for (let attempt = 1; attempt <= DOWNLOAD_ATTEMPTS; attempt += 1) {\n try {\n const body = await download(options.proxyUrl, signal)\n const catalog = buildCatalog(body, Date.now())\n cache = { catalog, proxyUrl: options.proxyUrl }\n void writeDiskCache(body)\n return catalog\n } catch (error) {\n if (signal?.aborted === true) throw error\n lastError = error\n if (attempt < DOWNLOAD_ATTEMPTS) await pause(RETRY_DELAY_MS)\n }\n }\n\n const disk = await readDiskCache()\n if (disk !== undefined) {\n try {\n const catalog: Catalog = { ...buildCatalog(disk.body, disk.fetchedAt), stale: true }\n cache = { catalog, proxyUrl: options.proxyUrl }\n return catalog\n } catch {\n // A corrupt copy is no better than no copy; report the download failure.\n }\n }\n const reason = lastError instanceof Error ? lastError.message : String(lastError)\n throw new Error(`models.dev catalog unavailable (${reason}) and no local copy exists`)\n}\n", "/**\n * Turning one catalog entry into the capability fields a provider model entry\n * accepts.\n *\n * Everything here is a pure function of catalog data: no gateway call, no\n * guessing beyond the catalog's own facts. A field the catalog does not state\n * stays absent, so the writer never invents a value.\n * @module dsh-model-capability-sync/mapping\n */\nimport type { CatalogEntry } from './catalog.ts'\nimport type { CapabilityFields, Modality } from './types.ts'\n\n/** Thinking levels the harness recognizes, strongest last. */\nconst THINKING_LEVELS = new Set(['off', 'minimal', 'low', 'medium', 'high', 'xhigh', 'max'])\n\n/** A positive integer or nothing. */\nfunction positive(value: unknown): number | undefined {\n return typeof value === 'number' && Number.isFinite(value) && value > 0 ? Math.round(value) : undefined\n}\n\n/** Map the catalog's media list onto the harness's two modalities. */\nfunction modalitiesOf(entry: CatalogEntry): Modality[] | undefined {\n const declared = entry.model.modalities?.input\n if (declared === undefined) return undefined\n const accepted: Modality[] = []\n for (const media of declared) {\n if (media === 'image' && !accepted.includes('image')) accepted.push('image')\n }\n // A model that lists only images still reads text in practice; the harness\n // always sends text, so `text` is never dropped.\n return ['text', ...accepted]\n}\n\n/**\n * Build the reasoning-effort map from the catalog's `effort` option.\n * @returns the dict, `false` when the catalog says the model cannot reason, or\n * `undefined` when the catalog is silent.\n */\nfunction reasoningOf(entry: CatalogEntry): Record<string, string> | false | undefined {\n const model = entry.model\n if (model.reasoning === false) return false\n const option = model.reasoning_options?.find(candidate => candidate.type === 'effort')\n const values = option?.values ?? []\n const efforts: Record<string, string> = {}\n for (const value of values) {\n if (typeof value !== 'string') continue\n if (!THINKING_LEVELS.has(value)) continue\n efforts[value] = value\n }\n return Object.keys(efforts).length > 0 ? efforts : undefined\n}\n\n/**\n * Read every capability the catalog states for one entry.\n *\n * The catalog's display name is deliberately not returned: this plugin fills\n * facts, it never renames a model entry. Renaming has its own section, and the\n * two must stay separable \u2014 a fill that also renamed would make the redirect\n * undoable.\n * @param entry - the matched catalog entry.\n * @returns only the fields the catalog actually declares.\n */\nexport function capabilitiesOf(entry: CatalogEntry): CapabilityFields {\n const model = entry.model\n const input = modalitiesOf(entry)\n const reasoningEfforts = reasoningOf(entry)\n return {\n ...positive(model.limit?.context) === undefined ? {} : { contextWindow: positive(model.limit?.context) as number },\n ...positive(model.limit?.output) === undefined ? {} : { maxTokens: positive(model.limit?.output) as number },\n ...input === undefined ? {} : { input },\n ...reasoningEfforts === undefined ? {} : { reasoningEfforts },\n }\n}\n", "/**\n * Matching one configured gateway model id against the models.dev catalog.\n *\n * A gateway aggregates arbitrary upstreams and invents its own ids, so the\n * match walks from strict to loose and reports which rule fired \u2014 the UI shows\n * it, and an explicit alias always wins.\n * @module dsh-model-capability-sync/match\n */\nimport type { Catalog, CatalogEntry } from './catalog.ts'\nimport type { MatchInfo, MatchVia } from './types.ts'\n\n/**\n * Variant suffixes a gateway appends to one upstream model.\n *\n * A gateway re-labels the same upstream with its own selling point: `-high`,\n * `-max` (a bigger window), `-tiered`, `-trial` (a trial tier), `-official`\n * (the vendor's own route rather than an aggregator's), `-free`, `-it` (an\n * instruction-tuned build), `-reasoning`, `-disabled` (a model the vendor\n * publishes but will not serve). None of these changes what the model *is*, so\n * stripping them turns `gemini-3.8-flash-tiered` back into the catalog's\n * `gemini-3.8-flash` \u2014 which is what its capability facts describe.\n */\nconst VARIANT_SUFFIX = /[-_](high|low|medium|minimal|max|xhigh|thinking|preview|latest|chat|tiered|disabled|trial|official|free|stable|experimental|reasoning|it|instruct|base|pro|flash|mini|nano|small|large)$/i\n\n/**\n * A reseller's route tag: `:free`, `:beta`, `:nitro`. It rides on the end of an\n * id and says how the model is sold, never what it is.\n */\nconst ROUTE_TAG = /:[a-z0-9][a-z0-9_-]*$/i\n\n/**\n * A trailing build number: `kimi-k3-1`, `deepseek-v4-2`.\n *\n * Gateways stamp a revision onto an id without changing the model, and the\n * catalog usually holds only the unnumbered one. Only a bare integer tail is\n * stripped, so `claude-sonnet-4-5` (where `5` is part of the version) is left\n * for the dotted/named rules to handle first.\n */\nconst BUILD_NUMBER = /-\\d{1,2}$/\n\n/**\n * A reseller's own namespace wrapped around an upstream id: `sn-glm-5-3`.\n *\n * Aggregators (raccoon and friends) put a two-to-four letter tag in front of the\n * upstream id to mark which of their pools it comes from. `sn` is not a provider\n * id in the catalog \u2014 it is the reseller's abbreviation \u2014 so the tag carries no\n * information about the model. Only a tag that, once removed, leaves the exact\n * upstream id is accepted (see {@link resolveVendorPrefix}), which is what keeps\n * a genuinely namespaced id like `kimi-k3` from being mistaken for a prefixed\n * one.\n */\nconst VENDOR_PREFIX = /^([a-z]{2,4})-(.+)$/i\n\n/**\n * Strip every variant marker from one key, repeatedly.\n *\n * Gateways stack markers (`gemma-4-26b-a4b-it:free` carries both `-it` and\n * `:free`, `nemotron-3-nano-omni-30b-a3b-reasoning:free` both again), so one\n * pass is not enough. The loop is bounded: each pass must shorten the key, and\n * a key stripped to nothing is abandoned rather than searched as `''`.\n * @param key - one candidate id.\n * @returns the shortest key the markers allow, or undefined when none came off.\n */\nfunction stripMarkers(key: string): string | undefined {\n let current = key\n for (let pass = 0; pass < 6; pass += 1) {\n const next = current.replace(ROUTE_TAG, '').replace(VARIANT_SUFFIX, '').replace(BUILD_NUMBER, '')\n if (next === current || next.length === 0) break\n current = next\n }\n return current === key ? undefined : current\n}\n\n/**\n * How a display name is reduced to the thing worth looking up.\n *\n * The name-redirect section appends `\u3010qoder\u3011` to a label, and people annotate\n * by hand in other ways (`Qwen3.8-Flash (qoder)`, `[cn] Qwen3.8-Flash`). Those\n * annotations are provenance, not model identity: `qoder` is a gateway, and if\n * the annotation were left in, this plugin's own renaming would change what it\n * resolves. Bracketed segments go; the rest is trimmed to one line.\n */\nconst SOURCE_ANNOTATION = /\u3010[^\u3011]*\u3011|\\([^)]*\\)|\\[[^\\]]*\\]/g\n\n/**\n * Reduce a display name to its model part.\n * @param name - the configured label.\n * @returns the label without source annotations or stray whitespace.\n */\nexport function cleanDisplayName(name: string): string {\n return name.replace(SOURCE_ANNOTATION, ' ').replace(/\\s+/g, ' ').trim()\n}\n\n/**\n * First-party vendor provider ids in the models.dev catalog. The same model\n * appears under dozens of aggregators whose capacity numbers disagree, so a\n * vendor entry outranks every reseller when both exist.\n */\nconst FIRST_PARTY = new Set([\n 'openai', 'anthropic', 'google', 'deepseek', 'xai', 'meta', 'mistral', 'cohere',\n 'moonshotai', 'moonshotai-cn', 'zai', 'zhipuai', 'alibaba', 'alibaba-cn', 'qwen',\n 'sensenova', 'minimax', 'stepfun', 'bytedance', 'baidu', 'nvidia', 'microsoft',\n 'amazon', 'ai21', 'perplexity', 'upstage', '01-ai', 'inclusionai', 'tencent', 'kuaishou',\n])\n\n/** How complete an entry's facts are; the most complete wins a tie. */\nfunction score(entry: CatalogEntry): number {\n const model = entry.model\n let value = 0\n if (FIRST_PARTY.has(entry.provider)) value += 5\n if (model.limit?.context !== undefined || model.limit?.output !== undefined) value += 2\n if (model.modalities?.input !== undefined) value += 2\n if (model.reasoning_options !== undefined) value += 1\n if (model.name !== undefined) value += 1\n return value\n}\n\n/**\n * Pick the best of several provider entries for the same id: the one carrying\n * the most facts, then the alphabetically first provider so repeated runs are\n * stable.\n */\nfunction pickBest(entries: readonly CatalogEntry[]): CatalogEntry | undefined {\n let best: CatalogEntry | undefined\n let bestScore = -1\n for (const entry of entries) {\n const value = score(entry)\n if (value > bestScore || value === bestScore && best !== undefined && entry.provider < best.provider) {\n best = entry\n bestScore = value\n }\n }\n return best\n}\n\n/** The id without its vendor path prefix (`qoder-gj/DeepSeek-Flash` \u2192 `DeepSeek-Flash`). */\nfunction basename(id: string): string {\n const slash = id.lastIndexOf('/')\n return slash === -1 ? id : id.slice(slash + 1)\n}\n\n/**\n * Look one key up exactly, then case-insensitively.\n *\n * When the key exists verbatim, every entry with the same id ignoring case is\n * offered as well. Providers disagree about casing for the same model\n * (`alibaba` publishes `qwen3.8-flash` while `scnet-token-plan` publishes\n * `Qwen3.8-Flash`), and picking from the verbatim set alone would hand the\n * choice to whichever reseller happens to capitalise like the label \u2014 even when\n * a first-party entry with better facts exists. The rule reported is still\n * `exact`: the id did match verbatim, it just is not the only candidate.\n * @param catalog - the indexed catalog.\n * @param key - one candidate id.\n * @returns the entries to choose from and the rule that found them.\n */\nfunction lookup(catalog: Catalog, key: string): { entries: readonly CatalogEntry[]; via: MatchVia } | undefined {\n const exact = catalog.byId.get(key)\n if (exact !== undefined) {\n const folded = catalog.byFolded.get(key.toLowerCase())\n // `folded` is the same ids with any casing, so it always covers `exact`\n // when both exist; prefer it to widen the choice, never to narrow it.\n return { entries: folded !== undefined && folded.length > exact.length ? folded : exact, via: 'exact' }\n }\n const folded = catalog.byFolded.get(key.toLowerCase())\n if (folded !== undefined) return { entries: folded, via: 'folded' }\n return undefined\n}\n\n/**\n * Index the catalog's ids by their leading text, so a truncated key can find\n * the full ids that begin with it.\n *\n * A gateway trims the tail of an upstream id: `nemotron-3.5-lightning` for the\n * catalog's `nemotron-3.5-lightning-30b-a3b`, `north-mini-code` for\n * `north-mini-code-1-0`. That tail is a parameter count or a build stamp, which\n * does not change the capability facts, so a prefix hit is a real match.\n * @param catalog - the indexed catalog.\n * @returns prefix \u2192 the entries whose id starts with it.\n */\nfunction buildPrefixIndex(catalog: Catalog): Map<string, CatalogEntry[]> {\n const index = new Map<string, CatalogEntry[]>()\n for (const [id, entries] of catalog.byFolded) {\n for (let length = 4; length <= id.length; length += 1) {\n const key = id.slice(0, length)\n const bucket = index.get(key)\n if (bucket === undefined) index.set(key, [...entries])\n else bucket.push(...entries)\n }\n }\n return index\n}\n\n/** The prefix index of the last catalog it was built for. */\nlet prefixCache: { catalog: Catalog; index: Map<string, CatalogEntry[]> } | undefined\n\n/**\n * The prefix index for one catalog, built on first use and reused afterwards.\n * @param catalog - the indexed catalog.\n * @returns the prefix \u2192 entries map.\n */\nfunction prefixesOf(catalog: Catalog): Map<string, CatalogEntry[]> {\n if (prefixCache !== undefined && prefixCache.catalog === catalog) return prefixCache.index\n const index = buildPrefixIndex(catalog)\n prefixCache = { catalog, index }\n return index\n}\n\n/**\n * Every spelling of a version inside one key: dash form and dot form.\n *\n * Vendors publish either spelling for the same model and the catalog holds only\n * one of them: `claude-sonnet-4.5` sits beside `claude-sonnet-4-5`, and a\n * reseller may use the opposite one from the entry it wraps\n * (`sn-sensenova-6-8-flash-lite` against the catalog's\n * `sensenova-6.8-flash-lite`). Only a separator between two digits is rewritten,\n * so `gpt-4.1-mini` folds while a word boundary like `gpt-4-mini` is untouched.\n * @param key - one candidate id.\n * @returns the key first, then its folded spellings.\n */\nfunction versionSpellings(key: string): string[] {\n const dashed = key.replace(/(\\d)[-_.](\\d)/g, '$1-$2')\n const dotted = key.replace(/(\\d)[-_.](\\d)/g, '$1.$2')\n return [...new Set([key, dashed, dotted])]\n}\n\n/** Build the public match record for one chosen entry. */\nfunction describe(entry: CatalogEntry, via: MatchVia): MatchInfo {\n return {\n provider: entry.provider,\n modelId: entry.id,\n via,\n firstParty: FIRST_PARTY.has(entry.provider),\n ...entry.model.name === undefined ? {} : { name: entry.model.name },\n }\n}\n\n/**\n * Look one key up, then the same key with its word gaps written as dashes.\n * @param catalog - the indexed catalog.\n * @param key - one candidate id.\n * @returns the chosen entry and the rule, or undefined.\n */\nfunction lookupSpelling(catalog: Catalog, key: string): { entry: CatalogEntry; via: MatchVia } | undefined {\n const exact = lookupExact(catalog, key)\n if (exact !== undefined) return exact\n const dashed = spellGapsAsDashes(key)\n if (dashed === undefined) return undefined\n const hit = lookupExact(catalog, dashed)\n return hit === undefined ? undefined : { entry: hit.entry, via: 'spelling' }\n}\n\n/**\n * Look a key up through every id-only rule, strictest first.\n *\n * The ladder is: exact \u2192 version spelled the other way \u2192 variant markers\n * stripped \u2192 a reseller's namespace peeled off, then the same rules again on\n * what is left. Each step only widens the net, and the step that fired is\n * reported so the table can say how sure the answer is.\n * @param catalog - the indexed catalog.\n * @param key - one candidate id.\n * @returns the chosen entry and the rule that found it, or undefined.\n */\nfunction resolveId(catalog: Catalog, key: string): { entry: CatalogEntry; via: MatchVia } | undefined {\n const exact = lookupSpelling(catalog, key)\n if (exact !== undefined) return exact\n\n const withoutMarkers = stripMarkers(key)\n if (withoutMarkers !== undefined) {\n const hit = lookupSpelling(catalog, withoutMarkers)\n if (hit !== undefined) return { entry: hit.entry, via: hit.via === 'spelling' ? 'spelling' : 'suffix' }\n\n // A gateway that truncates the tail (`nemotron-3.5-lightning` for the\n // catalog's `nemotron-3.5-lightning-30b-a3b`) leaves a prefix of a longer\n // catalog id. A label's word gaps count as dashes here too, so\n // `Nemotron 3.5 Lightning` reaches the same entry.\n const prefixes = prefixesOf(catalog)\n for (const candidate of [withoutMarkers, spellGapsAsDashes(withoutMarkers)]) {\n if (candidate === undefined) continue\n const prefixed = prefixes.get(candidate.toLowerCase())\n if (prefixed === undefined) continue\n const entry = pickBest(prefixed)\n if (entry !== undefined) return { entry, via: 'prefix' }\n }\n }\n\n // A reseller wraps the upstream id in its own namespace (`sn-glm-5-3` for\n // `glm-5-3`). This runs last among the id rules because it removes real text:\n // the guard is that only a key which then resolves *exactly* is accepted, so\n // `raccoon-19b265` is not silently turned into `19b265`.\n const peeled = peelVendorNamespace(key)\n if (peeled !== undefined) {\n const hit = lookupSpelling(catalog, peeled)\n if (hit !== undefined) return { entry: hit.entry, via: 'vendor' }\n\n const peeledStripped = stripMarkers(peeled)\n if (peeledStripped !== undefined) {\n const again = lookupSpelling(catalog, peeledStripped)\n if (again !== undefined) return { entry: again.entry, via: 'vendor' }\n }\n }\n\n return undefined\n}\n\n/**\n * Write a label's word gaps as dashes: `Qwen3.8 Flash` \u2192 `Qwen3.8-Flash`.\n *\n * A display name is prose and uses spaces where the catalog uses separators.\n * `Qwen3.8 Flash` is the catalog's `qwen3.8-flash`, and no case, version or\n * marker rule can bridge a space \u2014 the two strings share no common form. Only\n * the candidate is rewritten, and the result still has to match exactly, so a\n * name whose words carry meaning (`Dots Studio: \u2026`) is left unmatched rather\n * than bent into something else.\n * @param key - one candidate id.\n * @returns the gap-free spelling, or undefined when there was no space.\n */\nfunction spellGapsAsDashes(key: string): string | undefined {\n const dashed = key.replace(/\\s+/g, '-')\n return dashed === key ? undefined : dashed\n}\n\n/**\n * Exact, case-folded, and version-spelled-the-other-way lookup, in that order.\n * @param catalog - the indexed catalog.\n * @param key - one candidate id.\n * @returns the chosen entry and the rule, or undefined.\n */\nfunction lookupExact(catalog: Catalog, key: string): { entry: CatalogEntry; via: MatchVia } | undefined {\n const spellings = versionSpellings(key)\n for (const [position, spelling] of spellings.entries()) {\n const hit = lookup(catalog, spelling)\n if (hit === undefined) continue\n const entry = pickBest(hit.entries)\n if (entry === undefined) continue\n // The key's own spelling keeps the rule that matched it; a folded spelling\n // is reported as `folded`.\n return { entry, via: position === 0 ? hit.via : 'folded' }\n }\n return undefined\n}\n\n/**\n * Remove a reseller's leading namespace from one id.\n *\n * Only the shape `xxx-rest` is considered, where `xxx` is two to four letters \u2014\n * long enough to be an abbreviation, short enough to not be a model family.\n * The caller must verify the result resolves exactly; without that check this\n * would happily split `raccoon-chat-ml-5-5` into the meaningless `chat-ml-5-5`.\n * @param key - one candidate id.\n * @returns the id without its namespace, or undefined when there is none.\n */\nfunction peelVendorNamespace(key: string): string | undefined {\n const match = VENDOR_PREFIX.exec(key)\n if (match === null) return undefined\n const rest: string | undefined = match[2]\n if (rest === undefined || rest.length < 3) return undefined\n return rest\n}\n\n/**\n * Resolve one gateway model id.\n *\n * The walk is strict to loose: the id itself, then the id without its vendor\n * prefix, then the configured display name \u2014 each of those through the full\n * ladder in {@link resolveId}. An explicit alias is tried last: it is a\n * hand-made fallback, and an alias applied to a name would be inherited by\n * every row that name resolves, which is the opposite of an override.\n * @param catalog - the indexed catalog.\n * @param id - the gateway model id exactly as configured.\n * @param aliases - explicit gateway id \u2192 catalog id overrides.\n * @param name - the configured display name, when there is one.\n * @returns the match, or `undefined` when nothing fits.\n */\nexport function matchModel(\n catalog: Catalog,\n id: string,\n aliases: Readonly<Record<string, string>> = {},\n name = '',\n): MatchInfo | undefined {\n const onId = resolveId(catalog, id)\n if (onId !== undefined) return describe(onId.entry, onId.via)\n\n // Peel the vendor prefix one segment at a time. A gateway nests its own\n // namespace in front of the upstream's path (`cline/dots-studio/dots-3-note\n // -preview:free` around the catalog's `dots-studio/dots-3-note-preview`), so\n // the useful key is not always the basename: sometimes it is everything after\n // the first segment, sometimes after the second.\n const segments = id.split('/')\n for (let drop = 1; drop < segments.length; drop += 1) {\n const rest = segments.slice(drop).join('/')\n if (rest.length === 0) continue\n const onRest = resolveId(catalog, rest)\n if (onRest !== undefined) return describe(onRest.entry, onRest.via === 'exact' ? 'basename' : onRest.via)\n }\n\n // From here the name speaks for the id: try it as-is, then its last segment\n // (`qoder/DeepSeek-Flash\u3010qoder\u3011` \u2192 `DeepSeek-Flash`). The bracketed\n // annotation is dropped first, so whether the name-redirect section ran never\n // changes the answer.\n const label = cleanDisplayName(name)\n if (label.length > 0) {\n const onName = resolveId(catalog, label)\n if (onName !== undefined) {\n return {\n ...describe(onName.entry, onName.via === 'exact' ? 'name' : onName.via === 'folded' ? 'name' : 'nameSuffix'),\n matchedName: label,\n nameSource: 'name',\n }\n }\n const tail = basename(label)\n if (tail !== label && tail.length > 0) {\n const onTail = resolveId(catalog, tail)\n if (onTail !== undefined) {\n return {\n ...describe(onTail.entry, onTail.via === 'exact' ? 'name' : onTail.via === 'folded' ? 'name' : 'nameSuffix'),\n matchedName: tail,\n nameSource: 'name',\n }\n }\n }\n }\n\n const alias = aliases[id]\n if (alias !== undefined && alias.length > 0) {\n const hit = lookup(catalog, alias)\n const entry = hit === undefined ? undefined : pickBest(hit.entries)\n if (entry !== undefined) return describe(entry, 'alias')\n }\n\n return undefined\n}\n", "/**\n * Host half: one RPC channel that answers \"what does the catalog say about\n * these model ids?\".\n *\n * The plugin registers no LLM provider route on purpose \u2014 it only supplies\n * facts. The browser half decides which provider entry to write and performs\n * the write through the official settings service, so this half never touches\n * configuration.\n * @module dsh-model-capability-sync\n */\nimport { loadCatalog } from './catalog.ts'\nimport type { Catalog } from './catalog.ts'\nimport { capabilitiesOf } from './mapping.ts'\nimport { matchModel } from './match.ts'\nimport type { LiveRequest, LiveResponse, LiveRow, PreviewRequest, PreviewResponse, PreviewRow, RpcEnvelope } from './types.ts'\n\n/** Cordis plugin name; the profile entry id matches. */\nexport const name = 'model-capability-sync'\n\n/** The channel is served over the web server, so both services are required. */\nexport const inject = ['connection', 'webServer', 'llm']\n\n/** Own RPC channel; the browser half calls this exact path. */\nconst CHANNEL = '/model-capability-sync'\n\n/** The slice of the host context this plugin uses. */\ninterface HostContext {\n get(service: string): unknown\n effect(callback: () => (() => void | Promise<void>) | void, label?: string): void\n logger: { warn(message: string): void; error(message: unknown): void }\n}\n\ntype Handler = (endpoint: string, payload: unknown, signal: AbortSignal) => Promise<RpcEnvelope<unknown>>\n\n/** The connection service's owner-taking registration (see DESIGN in llm-newapi). */\ninterface Registrar {\n register(owner: unknown, channel: string, handler: Handler): () => Promise<void>\n}\n\n/** Resolve one id against the catalog into a preview row. */\nfunction previewOne(catalog: Catalog, id: string, aliases: Readonly<Record<string, string>>, name = ''): PreviewRow {\n const named = name === '' ? {} : { name }\n const match = matchModel(catalog, id, aliases, name)\n if (match === undefined) return { id, ...named, reason: 'not in the models.dev catalog' }\n const entry = catalog.byId.get(match.modelId)?.find(candidate => candidate.provider === match.provider)\n if (entry === undefined) return { id, ...named, match, reason: 'catalog entry vanished between match and read' }\n const fields = capabilitiesOf(entry)\n if (Object.keys(fields).length === 0) return { id, ...named, match, reason: 'catalog entry states no capability facts' }\n return { id, ...named, match, fields }\n}\n\n/** Serve one `preview` request. */\nasync function preview(request: PreviewRequest, signal: AbortSignal): Promise<PreviewResponse> {\n const ids = Array.isArray(request.ids) ? request.ids.filter(id => typeof id === 'string' && id.length > 0) : []\n const catalog = await loadCatalog({ refresh: request.refresh === true, proxyUrl: request.proxyUrl }, signal)\n const aliases = request.aliases ?? {}\n const names = request.names ?? {}\n return {\n fetchedAt: catalog.fetchedAt,\n catalogModels: catalog.modelCount,\n ...catalog.stale === true ? { stale: true } : {},\n rows: ids.map(id => previewOne(catalog, id, aliases, typeof names[id] === 'string' ? names[id] : '')),\n }\n}\n\n/** One RPC envelope, never a thrown value: the transport would turn that into an opaque 500. */\nfunction failure(message: string): RpcEnvelope<never> {\n return { ok: false, error: { code: 'internal', message, details: {} } }\n}\n\n/** The LLM registry face this half reads live model metadata through. */\ninterface LlmFace {\n resolveModelInfo(provider: string, model: string, signal?: AbortSignal): Promise<{\n inputModalities?: readonly string[]\n context?: { contextWindow: number }\n defaultMaxTokens?: number\n }>\n}\n\n/**\n * Read what the adapter that owns `provider` reports right now.\n *\n * A configuration entry and the route a chat request takes can disagree: two\n * plugins may claim one provider route, and only the first registration serves\n * it. This answer is what a request would see, so a filled-in `input` that\n * never takes effect becomes visible instead of inferred.\n * @param llm - the LLM registry.\n * @param request - route and model ids to resolve.\n * @param signal - cancellation for adapter-owned lookups.\n * @returns one row per requested id, in request order.\n */\nasync function live(llm: LlmFace, request: LiveRequest, signal: AbortSignal): Promise<LiveResponse> {\n const provider = typeof request.provider === 'string' ? request.provider : ''\n const ids = Array.isArray(request.ids) ? request.ids.filter(id => typeof id === 'string' && id.length > 0) : []\n const rows: LiveRow[] = []\n for (const id of ids) {\n try {\n const info = await llm.resolveModelInfo(provider, id, signal)\n rows.push({\n id,\n ...info.inputModalities === undefined ? {} : { input: [...info.inputModalities] },\n ...info.context === undefined ? {} : { contextWindow: info.context.contextWindow },\n ...info.defaultMaxTokens === undefined ? {} : { maxTokens: info.defaultMaxTokens },\n })\n } catch (error) {\n rows.push({ id, error: error instanceof Error ? error.message : String(error) })\n }\n }\n return { rows }\n}\n\n/**\n * Build the channel handler bound to one LLM registry.\n * @param llm - the LLM registry the `live` endpoint reads through, when present.\n * @returns the endpoint dispatcher.\n */\nfunction createHandler(llm: LlmFace | undefined): Handler {\n return async (endpoint, payload, signal) => {\n try {\n if (endpoint === 'preview') {\n return { ok: true, value: await preview(payload as PreviewRequest, signal) }\n }\n if (endpoint === 'live') {\n if (llm === undefined) return failure('model-capability-sync: no llm service to resolve the live route')\n return { ok: true, value: await live(llm, payload as LiveRequest, signal) }\n }\n return failure(`model-capability-sync: unknown endpoint ${JSON.stringify(endpoint)}`)\n } catch (error) {\n return failure(error instanceof Error ? error.message : String(error))\n }\n }\n}\n\n/**\n * Register the channel. The registration rides the calling fiber, so a plugin\n * reload removes the route with it.\n * @param ctx - host context carrying `connection`, `webServer` and `llm`.\n */\nexport function apply(ctx: HostContext): void {\n const connection = ctx.get('connection')\n const llm = ctx.get('llm') as LlmFace | undefined\n if (connection === undefined) {\n ctx.logger.warn('model-capability-sync: no connection service; the capability channel is unavailable')\n return\n }\n if (llm === undefined) ctx.logger.warn('model-capability-sync: no llm service; the live route check is unavailable')\n const registrar = connection as Registrar\n const handler = createHandler(llm)\n ctx.effect(() => registrar.register(ctx, CHANNEL, handler), 'model-capability-sync: RPC channel')\n}\n"],
|
|
5
|
+
"mappings": ";AAcA,SAAS,OAAO,UAAU,iBAAiB;AAC3C,SAAS,eAAe;AACxB,SAAS,SAAS,YAAY;AAE9B,IAAM,cAAc;AAEpB,IAAM,eAAe,IAAI,KAAK,KAAK;AAEnC,IAAM,oBAAoB;AAE1B,IAAM,iBAAiB;AAoCvB,IAAI;AAGJ,IAAM,aAAa,KAAK,QAAQ,GAAG,QAAQ,yBAAyB,cAAc;AAUlF,eAAe,eAAe,MAA8B;AAC1D,MAAI;AACF,UAAM,WAAsB,EAAE,WAAW,KAAK,IAAI,GAAG,QAAQ,aAAa,KAAK;AAC/E,UAAM,MAAM,QAAQ,UAAU,GAAG,EAAE,WAAW,KAAK,CAAC;AACpD,UAAM,UAAU,YAAY,KA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folded", "name"]
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-model-capability-sync",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Fill model capabilities (context window, output cap, input modalities, reasoning efforts) into an already-configured DeepSeek Harness LLM provider by matching gateway model ids against the models.dev catalog. Host half fetches and matches; browser half previews and writes through the official settings service.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -16,7 +16,8 @@
|
|
|
16
16
|
"scripts",
|
|
17
17
|
"cordis.patch.yml",
|
|
18
18
|
"LICENSE",
|
|
19
|
-
"README.md"
|
|
19
|
+
"README.md",
|
|
20
|
+
"CHANGELOG.md"
|
|
20
21
|
],
|
|
21
22
|
"engines": {
|
|
22
23
|
"dsh": "^0.2.1-rc.2"
|
|
@@ -41,11 +42,17 @@
|
|
|
41
42
|
"build:host": "node scripts/build-host.mjs",
|
|
42
43
|
"build:client": "node scripts/build-client.mjs",
|
|
43
44
|
"typecheck": "npm run typecheck:host && npm run typecheck:client",
|
|
45
|
+
"test:rename": "node --experimental-strip-types --test scripts/test-rename.mjs",
|
|
46
|
+
"test:match": "node --experimental-strip-types --test scripts/test-match.mjs",
|
|
47
|
+
"test:sort": "node --experimental-strip-types --test scripts/test-sort.mjs",
|
|
44
48
|
"typecheck:host": "tsc -p tsconfig.json --noEmit",
|
|
45
49
|
"typecheck:client": "tsc -p tsconfig.client.json --noEmit",
|
|
46
50
|
"prepublishOnly": "npm run typecheck && npm run build && npm run verify:package",
|
|
47
51
|
"verify:package": "node scripts/verify-package.mjs",
|
|
48
|
-
"pack:check": "npm pack --dry-run"
|
|
52
|
+
"pack:check": "npm pack --dry-run",
|
|
53
|
+
"test:write-merge": "node --experimental-strip-types --test scripts/test-write-merge.mjs",
|
|
54
|
+
"test:locale": "node --experimental-strip-types --test scripts/test-locale.mjs",
|
|
55
|
+
"test:fields": "node --experimental-strip-types --test scripts/test-fields.mjs"
|
|
49
56
|
},
|
|
50
57
|
"keywords": [
|
|
51
58
|
"dsh",
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unit tests for hand-typed capability values.
|
|
3
|
+
*
|
|
4
|
+
* Run with `node --experimental-strip-types --test scripts/test-fields.mjs`.
|
|
5
|
+
*
|
|
6
|
+
* The table shows token counts in short form (`1M`) and those same cells are
|
|
7
|
+
* typeable, so the short form has to parse back to the number it stands for.
|
|
8
|
+
* The overlay rule matters too: a typed value wins over the catalog even when
|
|
9
|
+
* "overwrite" is off, because that switch is about the catalog replacing what
|
|
10
|
+
* is stored, not about a person deciding what the entry should say.
|
|
11
|
+
*/
|
|
12
|
+
import test from 'node:test'
|
|
13
|
+
import assert from 'node:assert/strict'
|
|
14
|
+
import { mergeFields, parseTokenCount } from '../src/client/shared.ts'
|
|
15
|
+
|
|
16
|
+
test('a short token count parses to its number', () => {
|
|
17
|
+
assert.equal(parseTokenCount('128K'), 128_000)
|
|
18
|
+
assert.equal(parseTokenCount('1M'), 1_000_000)
|
|
19
|
+
assert.equal(parseTokenCount('1.5M'), 1_500_000)
|
|
20
|
+
assert.equal(parseTokenCount('1.5m'), 1_500_000)
|
|
21
|
+
assert.equal(parseTokenCount('262k'), 262_000)
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
test('a plain or punctuated count parses', () => {
|
|
25
|
+
assert.equal(parseTokenCount('128000'), 128_000)
|
|
26
|
+
assert.equal(parseTokenCount('1,000,000'), 1_000_000)
|
|
27
|
+
assert.equal(parseTokenCount(' 1000000 '), 1_000_000)
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
test('anything that is not a count reads as no value', () => {
|
|
31
|
+
// Empty means "drop the manual value", not zero.
|
|
32
|
+
for (const text of ['', ' ', 'abc', '1M2', '-5', '0', 'K', '1 T']) {
|
|
33
|
+
assert.equal(parseTokenCount(text), undefined, JSON.stringify(text))
|
|
34
|
+
}
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
test('a typed value overlays the catalog value', () => {
|
|
38
|
+
const merged = mergeFields(
|
|
39
|
+
{ contextWindow: 1_000_000, maxTokens: 128_000, input: ['text', 'image'] },
|
|
40
|
+
{ contextWindow: 200_000 },
|
|
41
|
+
)
|
|
42
|
+
assert.equal(merged.contextWindow, 200_000)
|
|
43
|
+
assert.equal(merged.maxTokens, 128_000)
|
|
44
|
+
assert.deepEqual(merged.input, ['text', 'image'])
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
test('a model the catalog never listed keeps only what was typed', () => {
|
|
48
|
+
const merged = mergeFields(undefined, { contextWindow: 64_000, input: ['text'] })
|
|
49
|
+
assert.deepEqual(merged, { contextWindow: 64_000, input: ['text'] })
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
test('no typed values leaves the catalog fields untouched', () => {
|
|
53
|
+
const catalog = { contextWindow: 1_000_000 }
|
|
54
|
+
assert.deepEqual(mergeFields(catalog, undefined), catalog)
|
|
55
|
+
assert.equal(mergeFields(undefined, undefined), undefined)
|
|
56
|
+
})
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unit tests for copy-table completeness.
|
|
3
|
+
*
|
|
4
|
+
* Run with `node --experimental-strip-types --test scripts/test-locale.mjs`.
|
|
5
|
+
*
|
|
6
|
+
* This exists because a column header shipped as the raw key `colName`: the
|
|
7
|
+
* dictionary was missing it, `t()` fell back to the key itself, and nothing
|
|
8
|
+
* failed — the UI just read "colName" where a label belonged. A missing key is
|
|
9
|
+
* silent at runtime, so it has to be loud here.
|
|
10
|
+
*/
|
|
11
|
+
import test from 'node:test'
|
|
12
|
+
import assert from 'node:assert/strict'
|
|
13
|
+
import { readFileSync } from 'node:fs'
|
|
14
|
+
import { fileURLToPath } from 'node:url'
|
|
15
|
+
import { dirname, join } from 'node:path'
|
|
16
|
+
import { en, zh } from '../src/client/locale.ts'
|
|
17
|
+
|
|
18
|
+
const here = dirname(fileURLToPath(import.meta.url))
|
|
19
|
+
const clientDir = join(here, '..', 'src', 'client')
|
|
20
|
+
|
|
21
|
+
/** Every client module that calls `t('…')`. */
|
|
22
|
+
const CALLERS = ['SyncSection.tsx', 'apply.ts']
|
|
23
|
+
|
|
24
|
+
/** The copy keys the UI asks for, as written in the source. */
|
|
25
|
+
function keysUsed() {
|
|
26
|
+
const found = new Set()
|
|
27
|
+
for (const file of CALLERS) {
|
|
28
|
+
const text = readFileSync(join(clientDir, file), 'utf8')
|
|
29
|
+
for (const match of text.matchAll(/\bt\('([A-Za-z][A-Za-z0-9]*)'/g)) found.add(match[1])
|
|
30
|
+
}
|
|
31
|
+
return [...found].sort()
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
test('every key the UI asks for exists in both dictionaries', () => {
|
|
35
|
+
const used = keysUsed()
|
|
36
|
+
assert.ok(used.length > 20, `expected the UI to use many keys, found ${used.length}`)
|
|
37
|
+
const missingZh = used.filter(key => !(key in zh))
|
|
38
|
+
const missingEn = used.filter(key => !(key in en))
|
|
39
|
+
assert.deepEqual(missingZh, [], `missing from zh: ${missingZh.join(', ')}`)
|
|
40
|
+
assert.deepEqual(missingEn, [], `missing from en: ${missingEn.join(', ')}`)
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
test('the two dictionaries hold the same keys', () => {
|
|
44
|
+
const zhOnly = Object.keys(zh).filter(key => !(key in en))
|
|
45
|
+
const enOnly = Object.keys(en).filter(key => !(key in zh))
|
|
46
|
+
assert.deepEqual(zhOnly, [], `only in zh: ${zhOnly.join(', ')}`)
|
|
47
|
+
assert.deepEqual(enOnly, [], `only in en: ${enOnly.join(', ')}`)
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
test('the name column is present', () => {
|
|
51
|
+
// The specific key that shipped as a raw identifier.
|
|
52
|
+
assert.equal(zh.colName, '名称')
|
|
53
|
+
assert.equal(en.colName, 'Name')
|
|
54
|
+
})
|