Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins
TypeScript ai-agentcoding-agentdesktop-appelectronglobali18nlocal-firstmcppipi-agentpi-desktoppluginsreactrusttypescript
feat(models): read a custom endpoint's metadata from the publishers this app ships
vastsaf4ce0cf016ec
diff --git a/apps/desktop/electron/main/models-dev-catalog.ts b/apps/desktop/electron/main/models-dev-catalog.tsindex 22ad6cb84..972db9c10 100644--- a/apps/desktop/electron/main/models-dev-catalog.ts+++ b/apps/desktop/electron/main/models-dev-catalog.ts@@ -1,6 +1,7 @@import { readFile } from "node:fs/promises";import {MODEL_VENDOR_PREFIXES,+ NAMED_ENDPOINT_PRESETS,catalogModelIdsMatch,stripReleaseSuffix,stripVariantSuffix,@@ -603,6 +604,26 @@ function providerKeyCandidates(value: string | undefined): string[] {return [...new Set([key, ...(PROVIDER_ALIASES[key] ?? [])])].filter(Boolean);}+/**+ * Publishers this app ships a provider for: the models.dev keys behind the+ * first-class presets and the known endpoints, which mirror the providers pi-ai+ * supports.+ *+ * They are the publishers read first when nothing identifies the row's own+ * publisher. A relay's list can name an id a hundred arbitrary resellers also+ * carry, and a reseller's own flags describe *its* deployment, not the one this+ * row talks to; the vendors and gateways the app actually ships describe the+ * model. Resellers outside this set are still read when none of these states the+ * id, because the alternative is dropping a published model to the generic+ * 128k text-only shape.+ */+const SUPPORTED_PUBLISHER_KEYS: ReadonlySet<string> = new Set(+ [+ ...NAMED_ENDPOINT_PRESETS.map((preset) => preset.vendorKey),+ ...Object.keys(KNOWN_PROVIDER_BASE_URLS),+ ].flatMap((key) => providerKeyCandidates(key)),+);+/*** Canonical form of a provider base URL: lowercase origin without a trailing* slash and without the trailing API version segment, so a row configured with@@ -998,12 +1019,22 @@ function sameModelSpelling(catalogId: string, requested: string): boolean {const right = requested.trim().toLowerCase();if (!left || !right) return false;if (left === right) return true;- if (left.endsWith(`/${right}`)) return true;+ /*+ Either side may carry a route prefix the other does not: a relay lists+ `test/mimo-v2.5` where the catalog publishes `mimo-v2.5`, and a catalog that+ publishes a routed copy answers for the bare id. Two *different* route paths+ that merely share a leaf still never match.+ */+ if (left.endsWith(`/${right}`) || right.endsWith(`/${left}`)) return true;const plain = (id: string) => stripReleaseSuffix(stripVariantSuffix(id));const plainLeft = plain(left);const plainRight = plain(right);if (!plainLeft || !plainRight) return false;- return plainLeft === plainRight || plainLeft.endsWith(`/${plainRight}`);+ return (+ plainLeft === plainRight ||+ plainLeft.endsWith(`/${plainRight}`) ||+ plainRight.endsWith(`/${plainLeft}`)+ );}/**@@ -1027,6 +1058,112 @@ function unanchoredConsensus(entries: readonly ModelsDevModel[]): ModelsDevModelreturn consensus ? { ...consensus, reasoningOptions: undefined } : undefined;}+/**+ * Which publisher's records answer for an id the row's own publisher lacks.+ *+ * Two preferences, in order. The app's supported publishers are read first:+ * they are the vendors and gateways this app ships a provider for, so their+ * records describe the model behind an id a relay lists, while a reseller's own+ * flags describe its own deployment. Within that tier a record published under+ * exactly this id outranks one reached through another spelling of it:+ * `XiaomiMiMo/MiMo-V2.5` is the same model as `mimo-v2.5`, but a publisher that+ * lists only its text half must not narrow what the model's own record states+ * about vision. Only when none of them states the model does the pool widen to+ * every publisher that does — siblings included, as this borrow has always read+ * them — because a relay-only id would otherwise be shown as a generic 128k+ * text-only row although the catalog publishes it.+ */+function borrowPool(+ entries: readonly IndexedModel[],+ requested: string,+): readonly ModelsDevModel[] {+ /*+ A record under this id, or under the same id with a variant or release stamp+ stripped: `mimo-v2.5` answers for `mimo-v2.5-thinking`.+ */+ const closestId = (value: string) =>+ normalizedModelId(stripReleaseSuffix(stripVariantSuffix(value)));+ const requestedClosest = closestId(requested);+ const exact = (entry: IndexedModel) => {+ const id = normalizedModelId(entry.model.modelId);+ return id === requested || closestId(id) === requestedClosest;+ };+ const supported = (entry: IndexedModel) =>+ SUPPORTED_PUBLISHER_KEYS.has(normalizedProviderKey(entry.provider.providerKey));+ const tiers = [+ entries.filter((entry) => supported(entry) && exact(entry)),+ entries.filter(supported),+ entries,+ ];+ const pool = tiers.find((tier) => tier.length > 0) ?? [];+ return pool.map((entry) => entry.model);+}++/**+ * Markers a deployment appends to a published id to name its own variant of it:+ * a canary label, a context size, a preview channel. `test/mimo-v2.5-pro-test`+ * and `gemini-2.5-pro-1m` are the published models with such a marker appended.+ *+ * Only a marker on this list is read that way. `-asr`, `-pro` or `-mini` name+ * models of their own, so an unpublished id that carries one of those stays+ * unknown instead of borrowing a sibling model's limits.+ */+const DEPLOYMENT_MARKER_SUFFIXES: ReadonlySet<string> = new Set([+ "test",+ "staging",+ "canary",+ "dev",+ "alpha",+ "beta",+ "rc",+ "exp",+ "experimental",+ "preview",+ "free",+ "trial",+ "thinking",+ "think",+ "agent",+ "latest",+ "1k",+ "2k",+ "4k",+ "32k",+ "64k",+ "128k",+ "200k",+ "256k",+ "512k",+ "1m",+ "2m",+ "4m",+]);++/** The id without one trailing deployment marker, or the id unchanged. */+function dropDeploymentMarker(value: string): string {+ const match = /^(.*)[-_:]([a-z0-9]+)$/i.exec(value);+ if (!match) return value;+ return DEPLOYMENT_MARKER_SUFFIXES.has(match[2].toLowerCase()) ? match[1] : value;+}++/**+ * Published ids to read when nothing the catalog publishes matches the id the+ * service serves: the id behind a route prefix, and that id without one+ * deployment marker. Each is looked up as a whole published id, so nothing here+ * follows a chain of aliases.+ */+function fallbackLookupIds(requested: string): string[] {+ const ids: string[] = [];+ const push = (value: string) => {+ if (value && value !== requested && !ids.includes(value)) ids.push(value);+ };+ const leaf = requested.slice(requested.lastIndexOf("/") + 1);+ push(leaf);+ push(dropDeploymentMarker(leaf));+ push(dropDeploymentMarker(requested));+ return ids;+}+/*** The value most entries that state one agree on, or undefined when they split.*@@ -1278,7 +1415,12 @@ export class ModelsDevCatalog {for (const entry of this.lookupIndex.candidates(requested)) {(entry.provider === preferredProvider ? preferred : rest).push(entry);}- const candidates: Array<{ model: ModelsDevModel; score: number; exact: boolean }> = [];+ const candidates: Array<{+ model: ModelsDevModel;+ provider: ModelsDevProvider;+ score: number;+ exact: boolean;+ }> = [];for (const { model, provider } of [...preferred, ...rest]) {// A known endpoint must not inherit another provider's capabilities.if (preferredProvider && provider !== preferredProvider) continue;@@ -1288,11 +1430,12 @@ export class ModelsDevCatalog {if (provider === preferredProvider) score += 100;if (apiMatches(input.baseUrl, provider.api)) score += 80;if (modelMatchesProvider(model, input.vendorKey)) score += 60;- candidates.push({ model, score, exact });+ candidates.push({ model, provider, score, exact });}candidates.sort((left, right) =>right.score - left.score || left.model.modelId.length - right.model.modelId.length,);+ /*/*A record the catalog publishes under exactly this id is this id's record.Supported aliases — a release stamp, a thinking variant, a route leaf —@@ -1327,22 +1470,37 @@ export class ModelsDevCatalog {provider does publish stays authoritative.With no provider identity at all the scores still prove nothing about- identity, so no single publisher's record is adopted. What every publisher- of the *same model in another spelling* states is a different question,- and its answer can be claimed without adopting any one deployment's- claims: the intersection keeps tool support only when all of them agree,- under-claims capabilities, and takes the lower median of the limits. Two- routes that merely share a leaf (`provider-a/foo` vs `gateway/foo`) never- enter that set, so an id whose identity is genuinely unknown still- resolves to nothing. */- const borrowed = result ??+ identity, so no single publisher's record is adopted. What the publishers+ of the *same model in another spelling* state is a different question, and+ its answer can be claimed without adopting any one deployment's claims:+ the publishers this app ships answer first, tool support follows the ones+ that state it, capabilities are under-claimed and the limits are the lower+ median. Two routes that merely share a leaf (`provider-a/foo` vs+ `gateway/foo`) never enter that set, so an id whose identity is genuinely+ unknown still resolves to nothing. */+ let borrowed = result ??(preferredProvider? this.borrowedAcrossProviders(input): unanchoredConsensus(- candidates- .filter((candidate) => sameModelSpelling(candidate.model.modelId, requested))- .map((candidate) => candidate.model),+ borrowPool(+ candidates.filter((candidate) => sameModelSpelling(candidate.model.modelId, requested)),+ requested,+ ),));+ /*+ Nothing the catalog publishes answered for the id as served. A deployment+ can put the model behind a route prefix or append a marker of its own+ (`test/mimo-v2.5`, `mimo-v2.5-pro-test`), and the model is still the one+ the catalog publishes. Reading that whole published id is the last resort,+ so a suffix the catalog uses for models of its own — `-asr`, `-tts`,+ `-voiceclone` — cannot turn an unknown id into a different model's record.+ */+ if (!borrowed) {+ for (const fallbackId of fallbackLookupIds(requested)) {+ borrowed = this.borrowedAcrossProviders(input, fallbackId);+ if (borrowed) break;+ }+ }// Cache the result (a miss included) so a repeated miss is also O(1) and// cannot grow the candidate index with query-dependent keys.this.lookupMemo.set(memoKey, borrowed);@@ -1359,23 +1517,31 @@ export class ModelsDevCatalog {* of its own while other publishers state the identical id. Their record is* what keeps that model's window, tool support and vision visible.*- * Two exclusions keep this from borrowing anything identity-sensitive:+ * Three rules keep this from borrowing anything identity-sensitive:** - A provider sharing the row's own endpoint is an alias for the row, not an* independent source. Its failure to publish the id is an answer about this* deployment, so nothing is borrowed past it.- * - Only an exactly-identical id transfers. The index also reaches a record- * through aliases — a bare route leaf behind a prefix, a vendor-prefixed- * variant — and those describe a *different* id, whose limits and- * capabilities are not this model's.+ * - The publishers this app ships a provider for answer before arbitrary+ * resellers do, in the same order the unanchored borrow uses: an id a+ * supported publisher states describes the model, while a reseller's copy+ * describes its own deployment of it.+ * - Only an identical id transfers, and only as a whole published id: a+ * record the index reaches through an alias — a bare route leaf behind a+ * prefix, a vendor-prefixed variant — describes a *different* id.+ *+ * `lookupId` reads the record of a published id the served name reduces to+ * (`test/mimo-v2.5-pro-test` → `mimo-v2.5-pro`); it is only used when nothing+ * published answered for the served id itself.*/private borrowedAcrossProviders(input: { vendorKey?: string; baseUrl?: string; modelId: string },+ lookupId?: string,): ModelsDevModel | undefined {// `findModel` already rejected an empty id; normalize here so the compare// below is case-insensitive against the catalog's own normalization.- const requested = normalizedModelId(input.modelId);- const matches: ModelsDevModel[] = [];+ const requested = lookupId ?? normalizedModelId(input.modelId);+ const matches: IndexedModel[] = [];const seen = new Set<string>();for (const candidate of this.lookupIndex?.candidates(requested) ?? []) {const { model, provider } = candidate;@@ -1385,9 +1551,9 @@ export class ModelsDevCatalog {const key = `${provider.providerKey}\u0000${model.modelId}`;if (seen.has(key)) continue;seen.add(key);- matches.push(model);+ matches.push({ model, provider });}- return borrowedModel(matches);+ return borrowedModel(borrowPool(matches, requested));}/**@@ -1413,7 +1579,19 @@ export class ModelsDevCatalog {};}- modelsForProvider(input: { vendorKey?: string; baseUrl?: string; providerId: string }): ModelInfo[] {+ modelsForProvider(input: {+ vendorKey?: string;+ baseUrl?: string;+ providerId: string;+ /**+ * Include the models this provider publishes next to its chat models —+ * embedding, speech, image and reranking endpoints. The settings picker+ * asks for them because it renders the service's own catalog of what the+ * credential can call; session and agent paths keep the default, which is+ * the text models they can actually run.+ */+ includeNonChat?: boolean;+ }): ModelInfo[] {const preferredProvider = this.providerFor(input);const providers = preferredProvider? [preferredProvider]@@ -1425,7 +1603,8 @@ export class ModelsDevCatalog {provider.models.filter((model) => {const key = normalizedModelId(model.modelId);- if (!isTextAgentModel(model) || seen.has(key)) return false;+ if (seen.has(key)) return false;+ if (!input.includeNonChat && !isTextAgentModel(model)) return false;if (!preferredProvider && !modelMatchesProvider(model, input.vendorKey)) return false;seen.add(key);return true;diff --git a/apps/desktop/test/models-dev-catalog.test.mjs b/apps/desktop/test/models-dev-catalog.test.mjsindex da61b3fe2..f4e62986c 100644--- a/apps/desktop/test/models-dev-catalog.test.mjs+++ b/apps/desktop/test/models-dev-catalog.test.mjs@@ -189,13 +189,20 @@ test("an unknown endpoint borrows only what every publisher of the id agrees on"assert.equal(consensus?.reasoning, false, "one publisher's reasoning claim must not transfer");assert.equal(catalog.findModel(unknown), consensus, "a consensus is cached like any other answer");/*- Two routes that merely share a leaf are not one model, so the borrow is not- offered to them and the id stays unresolved.+ A deployment that puts the model behind a route prefix still serves that+ model: `proxy/shared-model` reads the record `shared-model` is published+ under, with the same consensus rules. Two *different* route paths that+ merely share a leaf are still not one model — the matcher rejects those+ rather than averaging them.*/- assert.equal(- catalog.findModel({ vendorKey: "custom", baseUrl: "https://relay.example/v1", modelId: "proxy/shared-model" }),- undefined,- );+ const prefixed = catalog.findModel({+ vendorKey: "custom",+ baseUrl: "https://relay.example/v1",+ modelId: "proxy/shared-model",+ });+ assert.equal(prefixed?.modelId, "shared-model");+ assert.equal(prefixed?.limit.context, 32_000);+ assert.equal(prefixed?.reasoning, false);const alpha = catalog.findModel({vendorKey: "custom", baseUrl: "https://alpha.example/v1", modelId: "shared-model",});@@ -608,6 +615,155 @@ test("a majority of the publishers that state tool support decides the borrow",assert.equal(info.capabilities.includes("tools"), true);});+test("the publishers this app ships decide an id that resellers also state", async (t) => {+ /*+ A relay's list names ids arbitrary resellers carry too, and a reseller's+ flags describe its own deployment: here two resellers outvote the shipped+ publisher and both are wrong about the tools it accepts.+ */+ const catalog = await loadFixtureCatalog(t, {+ gateway: { api: "https://gateway.example/v1", models: {} },+ deepseek: { models: { "shared-model": {+ id: "shared-model", tool_call: true, limit: { context: 1_000_000, output: 393_216 },+ } } },+ resellerA: { models: { "shared-model": {+ id: "shared-model", tool_call: false, limit: { context: 128_000, output: 8_192 },+ } } },+ resellerB: { models: { "shared-model": {+ id: "shared-model", tool_call: false, limit: { context: 131_072, output: 8_192 },+ } } },+ });+ const match = catalog.findModel({+ vendorKey: "custom",+ baseUrl: "https://relay.example/v1",+ modelId: "shared-model",+ });+ assert.ok(match, "a shipped publisher states the id");+ assert.equal(match.providerKey, "deepseek", "the shipped publisher's record answers");+ assert.equal(match.toolCall, true);+ assert.equal(match.limit.context, 1_000_000);+ assert.equal(match.limit.output, 393_216);+});++test("resellers still answer for an id no shipped publisher states", async (t) => {+ // The preference above is not a filter: an id only resellers publish would+ // otherwise be shown as a generic 128k text-only row.+ const catalog = await loadFixtureCatalog(t, {+ gateway: { api: "https://gateway.example/v1", models: {} },+ resellerA: { models: { "reseller-only-model": {+ id: "reseller-only-model", tool_call: true, limit: { context: 262_144 },+ } } },+ resellerB: { models: { "reseller-only-model": {+ id: "reseller-only-model", tool_call: true, limit: { context: 262_144 },+ } } },+ });+ const match = catalog.findModel({+ vendorKey: "custom",+ baseUrl: "https://relay.example/v1",+ modelId: "reseller-only-model",+ });+ assert.ok(match, "a published id must not drop to the generic shape");+ assert.equal(match.toolCall, true);+ assert.equal(match.limit.context, 262_144);+});++test("a route prefix and a deployment marker still reach the published model", async (t) => {+ /*+ Relays name a published model behind a route of their own and append markers+ of their own: `test/mimo-v2.5`, `mimo-v2.5-thinking`, `test/mimo-v2.5-pro-test`.+ All three are that published model. A suffix the catalog uses for a model of+ its own — `-asr` — is not a marker, so an id carrying one stays unknown.+ */+ const catalog = await loadFixtureCatalog(t, {+ gateway: { api: "https://gateway.example/v1", models: {} },+ xiaomi: { models: {+ "mimo-v2.5": {+ id: "mimo-v2.5", tool_call: true,+ modalities: { input: ["text", "image"], output: ["text"] },+ limit: { context: 1_048_576, output: 131_072 },+ },+ "mimo-v2.5-pro": {+ id: "mimo-v2.5-pro", tool_call: true, limit: { context: 1_048_576, output: 131_072 },+ },+ } },+ });+ const relay = (modelId) =>+ catalog.findModel({ vendorKey: "custom", baseUrl: "https://relay.example/v1", modelId });++ for (const served of ["test/mimo-v2.5", "mimo-v2.5-thinking", "mimo-v2.5"]) {+ assert.equal(relay(served)?.modelId, "mimo-v2.5", `${served} reads the published model`);+ assert.equal(relay(served)?.limit.context, 1_048_576);+ }+ const info = modelInfoFromModelsDev(relay("test/mimo-v2.5"), "provider-1");+ assert.ok(info.capabilities.includes("vision"));++ // The prefix and the marker together, as one deployment writes them.+ assert.equal(relay("test/mimo-v2.5-pro-test")?.modelId, "mimo-v2.5-pro");+ assert.equal(relay("test/mimo-v2.5-pro-test")?.limit.output, 131_072);++ // `-asr` names a model of its own, so nothing is borrowed for it.+ assert.equal(relay("mimo-v2.5-asr"), undefined);+});++test("a shipped publisher answers first for a row anchored to a reseller", async (t) => {+ // The row's own publisher is known and publishes nothing for this id, so the+ // borrow runs — and it reads the publisher the app ships before the resellers+ // that also carry the id.+ const catalog = await loadFixtureCatalog(t, {+ reseller: { api: "https://reseller.example/v1", models: { "reseller/own": { id: "reseller/own" } } },+ xai: { models: { "Vendor/Model": {+ id: "Vendor/Model", tool_call: true, limit: { context: 500_000, output: 500_000 },+ } } },+ otherA: { models: { "Vendor/Model": {+ id: "Vendor/Model", tool_call: false, limit: { context: 128_000, output: 8_192 },+ } } },+ otherB: { models: { "Vendor/Model": {+ id: "Vendor/Model", tool_call: false, limit: { context: 131_072, output: 8_192 },+ } } },+ });+ const match = catalog.findModel({+ vendorKey: "reseller",+ baseUrl: "https://reseller.example/v1",+ modelId: "Vendor/Model",+ });+ assert.equal(match?.providerKey, "xai", "the shipped publisher's record answers");+ assert.equal(match.toolCall, true);+ assert.equal(match.limit.context, 500_000);+ assert.equal(match.limit.output, 500_000);+});++test("an exact record outranks a shipped publisher's other spelling of the id", async (t) => {+ /*+ Both are shipped publishers, and `XiaomiMiMo/MiMo-V2.5` is the same model as+ `mimo-v2.5`. Only the exact id decides what the model can take: a publisher+ that lists the text half alone must not narrow the model's own record into+ text-only.+ */+ const catalog = await loadFixtureCatalog(t, {+ gateway: { api: "https://gateway.example/v1", models: {} },+ xiaomi: { models: { "mimo-v2.5": {+ id: "mimo-v2.5", tool_call: true,+ modalities: { input: ["text", "image", "audio"], output: ["text"] },+ limit: { context: 1_048_576, output: 131_072 },+ } } },+ huggingface: { models: { "XiaomiMiMo/MiMo-V2.5": {+ id: "XiaomiMiMo/MiMo-V2.5", tool_call: true,+ modalities: { input: ["text"], output: ["text"] },+ limit: { context: 1_048_576, output: 131_072 },+ } } },+ });+ const match = catalog.findModel({+ vendorKey: "custom",+ baseUrl: "https://relay.example/v1",+ modelId: "mimo-v2.5",+ });+ assert.equal(match?.providerKey, "xiaomi");+ assert.deepEqual(match.modalities.input, ["text", "image", "audio"]);+ const info = modelInfoFromModelsDev(match, "provider-1");+ assert.ok(info.capabilities.includes("vision"), "the sibling's text-only record must not narrow it");+ assert.ok(info.capabilities.includes("audio"));+});+test("borrowing stays exact-id, provider-scoped and absent for unknown ids", async (t) => {const catalog = await loadFixtureCatalog(t, {gateway: { api: "https://gateway.example/v1", models: {} },@@ -1424,7 +1580,7 @@ const customGateway = {baseUrl: "https://gateway.example/v1",};-test("a custom Anthropic gateway borrows the consensus and keeps Anthropic's thinking shape", async (t) => {+test("a custom Anthropic gateway reads Anthropic's own record and its thinking shape", async (t) => {const catalog = await loadFixtureCatalog(t, ambiguousClaudeFixture);const config = catalogModelConfigFor(catalog, {...customGateway,@@ -1433,14 +1589,13 @@ test("a custom Anthropic gateway borrows the consensus and keeps Anthropic's thi});/*- Anthropic (1M / 128k) and Requesty (200k / 64k) both publish this id and- disagree, so neither record answers alone: the limits are the lower median of- what they state, which under-claims rather than adopting one deployment's- numbers.+ Anthropic publishes this id, so the record of the publisher the app ships+ answers — not a median shared with a reseller's smaller deployment of the+ same id, which would halve the window Anthropic itself states.*/assert.equal(config.source, "models.dev");- assert.equal(config.contextWindow, 200_000);- assert.equal(config.maxTokens, 64_000);+ assert.equal(config.contextWindow, 1_000_000);+ assert.equal(config.maxTokens, 128_000);assert.equal(config.reasoning, true);/*No publisher describes this endpoint's reasoning wire shape, so the borroweddiff --git a/apps/desktop/test/provider-endpoint-metadata.test.mjs b/apps/desktop/test/provider-endpoint-metadata.test.mjsindex cb9d29042..1f34c6e48 100644--- a/apps/desktop/test/provider-endpoint-metadata.test.mjs+++ b/apps/desktop/test/provider-endpoint-metadata.test.mjs@@ -117,7 +117,7 @@ test("a custom row on a published host gets that publisher's model metadata", as}});-test("a relay's list gets what every publisher of an id agrees on", async (t) => {+test("a relay's list reads the shipped publisher's record for a known id", async (t) => {const row = rowOf({id: "row-2",name: "Relay",@@ -130,8 +130,10 @@ test("a relay's list gets what every publisher of an id agrees on", async (t) =>const byId = new Map(result.models.map((model) => [model.modelId, model]));const known = byId.get("claude-sonnet-4-5");assert.equal(known.catalogSource, "models.dev", "several publishers state this id");- // Under-claimed: the lower median of the claims, not one publisher's number.- assert.ok(known.contextWindow >= 128_000 && known.contextWindow < 1_000_000);+ // Anthropic's published window, not a median dragged down by resellers that+ // state a smaller deployment of the same id.+ assert.equal(known.contextWindow, 1_000_000);+ assert.equal(known.maxTokens, 64_000);assert.ok(known.capabilities.includes("tools"));// An id no publisher states still lands on the generic seed.const unknown = byId.get("some-private-model");@@ -201,9 +203,27 @@ test("a relay's list keeps the tool support a majority of publishers states", asassert.ok(tts.capabilities.includes("audio"));assert.equal(tts.contextWindow, 8_192);- // A context-variant suffix no publisher uses is not guessed at: the catalog- // names `-128k`/`-256k` models of their own, so `-1m` stays unknown.+ // A `-1m` marker names a context variant of the same published model, so the+ // served id reads that model's record — and an id whose marker names another+ // model of the catalog's own (`-asr`, `-tts`) is still not folded into it.const variant = byId.get("gemini-2.5-pro-1m");- assert.equal(variant.catalogSource, undefined);- assert.equal(variant.contextWindow, 128_000);+ assert.equal(variant.catalogSource, "models.dev");+ assert.equal(variant.contextWindow, 1_048_576);+});++test("a relay reads a shipped publisher's own record, not a reseller's", async (t) => {+ /*+ `doubao-seed-2-0-pro-260215` is published both by Volcengine, which the app+ ships a provider for, and by a reseller that states the opposite tool support+ for a smaller deployment. The shipped publisher's record answers: a relay+ fronting that model serves Volcengine's window, not the reseller's.+ */+ const row = rowOf({ id: "row-5", name: "Relay", baseUrl: "https://relay.example/v1" });+ const { result } = await handlersFor(t, row, { data: [{ id: "doubao-seed-2-0-pro-260215" }] });++ const [model] = result.models;+ assert.equal(model.catalogSource, "models.dev");+ assert.ok(model.capabilities.includes("tools"));+ assert.equal(model.contextWindow, 256_000);+ assert.equal(model.maxTokens, 128_000);});diff --git a/docs/spec/03-runtime/12-provider-config-schema.md b/docs/spec/03-runtime/12-provider-config-schema.mdindex 58dc3444a..7479e95e4 100644--- a/docs/spec/03-runtime/12-provider-config-schema.md+++ b/docs/spec/03-runtime/12-provider-config-schema.md@@ -735,14 +735,18 @@ OpenAI Responses endpoint — from showing generic 128k / 8k / text-only defaultfor models the catalog describes in full.When nothing identifies a publisher at all — a relay, or a host the catalog does-not know — no single publisher's record is adopted, and such a row used to get-nothing. What the publishers of the same model agree on is claimed instead: the-lower median of their limits and, for every capability but tool support, only-what all of them state, so the answer can only under-claim. Tool support follows-the majority of the publishers that state it: an ID a relay lists can be stated-by a hundred publishers, and one dissenting reseller must not decide — or void —-the claim for a deployment it does not describe. An even split states no majority-and claims nothing. Two routes that merely share a name leaf+not know — the publishers this app ships a provider for answer first: they are+the vendors and gateways behind the first-class presets, so their records+describe the model, while a reseller's own flags describe its own deployment of+it. Only when none of them states the ID does the pool widen to every publisher+that does, because an ID a relay alone carries would otherwise be shown as a+generic 128k text-only row. Within that pool the publishers' agreement is+claimed: the lower median of their limits and, for every capability but tool+support, only what all of them state, so the answer can only under-claim. Tool+support follows the majority of the publishers that state it: an ID a relay lists+can be stated by a hundred publishers, and one dissenting reseller must not decide+— or void — the claim for a deployment it does not describe. An even split states+no majority and claims nothing. Two routes that merely share a name leaf(`provider-a/foo` vs `gateway/foo`) are not one model, so an ID whose identity isgenuinely unknown still resolves to nothing. A record borrowed this way states noreasoning wire shape — that is a property of the deployment — and an Anthropicdiff --git a/docs/spec/03-runtime/13-model-catalog-and-selection.md b/docs/spec/03-runtime/13-model-catalog-and-selection.mdindex 8cf9a67b4..96746ac62 100644--- a/docs/spec/03-runtime/13-model-catalog-and-selection.md+++ b/docs/spec/03-runtime/13-model-catalog-and-selection.md@@ -482,6 +482,15 @@ different full route paths never match solely because they share a leaf. Itnarrowly strips trailing `-` or `:` `thinking`, `think`, `agent` or `latest`tokens (including before `@region`). It does not strip arbitrarydash-separated proxy prefixes or effort tokens such as `low`, `high` or `max`.++When nothing matches outright, the lookup falls back to the whole published ID+the served name reduces to: the ID behind one route prefix (`test/mimo-v2.5`) and+that ID without one deployment marker (`mimo-v2.5-pro-test`, `gemini-2.5-pro-1m`).+Only a marker that names a variant of a published model is read that way —+`-test`, `-preview`, `-beta`, `-1m`, `-128k`; `-asr`, `-tts` and `-pro` name+models of their own, so an unpublished ID carrying one of those stays unknown+instead of inheriting a sibling's limits. This fallback reads a whole published+ID and never follows a chain of aliases.The catalog index uses bounded candidate keys for these aliases, then checksthe matcher; a known catalog provider selected by vendor key or API URL limitsthe lookup to that provider, never borrowing another provider's capabilities.@@ -497,7 +506,8 @@ weights, so an endpoint serving `Vendor/Model` ids can have no record of its ownwhile several other publishers state the identical id. When the row resolves toa catalog provider whose own record is missing, `findModel` consults the otherpublishers of the **exact** id instead of leaving the model on the generic-128k text-only shape (issue #938).+128k text-only shape (issue #938), and reads a whole published id the served name+reduces to when no publisher states the id itself.The borrow is bounded:@@ -506,14 +516,22 @@ The borrow is bounded:it, stays authoritative.- A provider sharing the row's own endpoint is an alias for the row, so itssilence is an answer about this deployment and nothing is borrowed past it.-- Only a case-insensitive identical id transfers; a record reached through an- alias (a bare route leaf, a vendor-prefixed variant) is a different id and- keeps its own limits.-- Tool support must be unanimous across those publishers, because a wrong `true`- puts tool declarations on the wire that the endpoint may reject. Reasoning,- image/PDF input and attachment are the intersection, so a borrow may only- under-claim; a user who knows the endpoint does more still enables it in- Advanced. Limits are the medians the publishers state, never one host's cap.+- Only a case-insensitive identical id transfers, or a whole published id the+ served name reduces to (`test/mimo-v2.5-pro-test` → `mimo-v2.5-pro`). A record+ the index reaches through an alias is a different id and keeps its own limits.+- The publishers this app ships a provider for answer before arbitrary resellers+ do, in the same order the unanchored borrow uses: an id a shipped publisher+ states describes the model, while a reseller's copy describes its own+ deployment of it. Within that tier a record under exactly this id outranks one+ reached through another spelling of it, so a copy carrying only the text half+ cannot narrow what the model's own record states about vision.+- Tool support follows the majority of the publishers that state it, because a+ wrong `true` puts tool declarations on the wire that the endpoint may reject,+ while one dissenting reseller must not void a record a hundred of them agree+ on; an even split claims nothing. Reasoning, image/PDF input and attachment are+ the intersection, so a borrow may only under-claim; a user who knows the+ endpoint does more still enables it in Advanced. Limits are the medians the+ publishers state, never one host's cap.- An id no publisher states stays an unknown generic model.This changes metadata only. The configured wire id, provider identity, and thediff --git a/docs/zh-CN/spec/03-runtime/12-provider-config-schema.md b/docs/zh-CN/spec/03-runtime/12-provider-config-schema.mdindex 713f1b2aa..681ad73fd 100644--- a/docs/zh-CN/spec/03-runtime/12-provider-config-schema.md+++ b/docs/zh-CN/spec/03-runtime/12-provider-config-schema.md@@ -512,14 +512,15 @@ Chat Completions 配置使用同源 Responses。关闭搜索后恢复原配置的另一个接口路径时(例如智谱 OpenAI Responses 端点 `https://open.bigmodel.cn/api/v1`),不会对目录里已有完整描述的模型显示成通用的 128k / 8k / 纯文本默认值。-完全识别不出发布方时(中转站、或目录不认识的主机),不采用任何单个发布方的记录;这类行过去拿不到-任何元数据。现在改为采用「同一模型的各发布方共同认可的部分」:上下文与输出取各家数值的下中位数;-除工具能力外的各项能力,只在所有发布方都声明时才保留,因此只可能低估。工具能力按声明该能力的发布方-的多数决:中转站列出的一个 ID 可能被上百个发布方声明,某个并不描述该部署的中转商既不应替它下结论,-也不应让整条记录作废;票数持平则不声明。仅仅是名字-末段相同(`provider-a/foo` 与 `gateway/foo`)的两条不同路由不算同一模型,因此身份确实未知的 ID 仍然-不做匹配。以这种方式借用的记录不声明推理的线上字段形状(那是部署的属性),而 Anthropic Messages 行-仍使用 Anthropic 自己的形状。模型 ID 不参与判断该读哪个发布方。+完全识别不出发布方时(中转站、或目录不认识的主机),先由 app 自带 provider 的发布方回答:它们是一等+presets 背后的厂商与网关,其记录描述的就是这个模型;中转商自己的标记描述的是它自己的部署。只有当这些+发布方都没声明该 ID 时,候选才扩大到所有声明它的发布方 —— 否则只有中转站收录的 ID 会退化成通用的+128k 纯文本行。在该候选池内按各家的共识取值:上下文与输出取下中位数;除工具能力外的各项能力,只在+所有发布方都声明时才保留,因此只可能低估。工具能力按声明该能力的发布方的多数决:中转站列出的一个 ID+可能被上百个发布方声明,某个并不描述该部署的中转商既不应替它下结论,也不应让整条记录作废;票数持平+则不声明。仅仅是名字末段相同(`provider-a/foo` 与 `gateway/foo`)的两条不同路由不算同一模型,因此+身份确实未知的 ID 仍然不做匹配。以这种方式借用的记录不声明推理的线上字段形状(那是部署的属性),而+Anthropic Messages 行仍使用 Anthropic 自己的形状。模型 ID 不参与判断该读哪个发布方。查找针对的是行已经列出的 ID:服务返回的 ID 若自身记录是音频模型(TTS/ASR 同类),也会命中该记录。只有目录列表本身限定为文本 / Agent 模型,因为它决定一行「提供」哪些模型。diff --git a/docs/zh-CN/spec/03-runtime/13-model-catalog-and-selection.md b/docs/zh-CN/spec/03-runtime/13-model-catalog-and-selection.mdindex 5aaaabfda..dc1d3d63c 100644--- a/docs/zh-CN/spec/03-runtime/13-model-catalog-and-selection.md+++ b/docs/zh-CN/spec/03-runtime/13-model-catalog-and-selection.md@@ -282,13 +282,49 @@ type ModelCatalogItem = {但必须避免已知厂商冲突;两个不同的完整路由路径不会仅因叶子相同而匹配。它只会剥离末尾以 `-` 或 `:` 分隔的 `thinking`、`think`、`agent`、`latest`(也可在 `@region` 之前),不会剥离任意短横线代理-前缀或 `low`、`high`、`max` 等 effort 后缀。目录索引用这些别名生成有界+前缀或 `low`、`high`、`max` 等 effort 后缀。++完全匹配不到时走兜底:取「服务名去掉一层路由前缀」后对应的完整已发布 ID(`test/mimo-v2.5`),+以及再去掉一个部署标记后的完整 ID(`mimo-v2.5-pro-test`、`gemini-2.5-pro-1m`)。只有表示+已发布模型变体的标记才会这样处理 —— `-test`、`-preview`、`-beta`、`-1m`、`-128k`;`-asr`、+`-tts`、`-pro` 是独立的模型,带这类后缀且未发布的 ID 仍保持未知,不会继承同类模型的窗口。+该兜底只读取一个完整的已发布 ID,不串接多层别名。++目录索引用这些别名生成有界候选键,再由匹配器确认;若厂商键或 API URL 已选中已知目录提供商,查询仅限该提供商,不能借用别家能力。这些别名只用于附加已发布的元数据,不改变配置的请求模型 ID,后缀本身也不证明模型有推理能力。未命中的自由格式 ID 仍是无推断能力的未知通用模型;只有已发布的记录或显式绑定设置可提供能力。+#### 11.3.1 跨发布方的同名 ID 兜底++models.dev 把网关上的模型副本记在拥有权重的厂商名下,因此返回 `Vendor/Model` 这类 ID 的端点+自身可能没有记录,而其他发布方声明了完全相同的 ID。当行解析到某个目录提供商、而它自己没有这条+记录时,`findModel` 改为读取声明该 **完全相同** ID 的其他发布方,而不是把模型留在通用的+128k 纯文本形态(issue #938);当没有任何发布方声明该 ID 时,读取「服务名去掉前缀与部署标记后」+对应的完整已发布 ID(见 §11.2)。++借用是有边界的:++- 只在行已有明确目录发布方身份、且它自己的查询未命中时运行。该提供商自己的记录及其受支持的别名+ 始终优先。+- 与行的端点同址的提供商是行的别名,不是独立来源:它对这条 ID 的沉默就是对该部署的回答,+ 不会越过它去借用。+- 只转移大小写不敏感的完全相同 ID,或「服务名去掉前缀与部署标记后」对应的完整已发布 ID+ (`test/mimo-v2.5-pro-test` → `mimo-v2.5-pro`)。通过别名命中的记录是另一条 ID,+ 保留它自己的窗口。+- app 自带 provider 的发布方先于任意中转商回答,顺序与「认不出发布方」时一致:被自带发布方声明的+ ID 描述的是这个模型,中转商自己的副本描述的是它的部署。该层级内,与请求 ID 完全相同的记录优先于+ 另一种拼写的同名记录,因此只列了文本那一半的副本不能把模型自己声明的视觉能力压掉。+- 工具能力按声明它的发布方多数决:错误的 `true` 会把工具声明放到线上、可能被端点拒绝,+ 但一个持不同意见的中转商也不应让上百家一致同意的记录作废;票数持平则不声明。其余能力取交集,+ 因此借用只可能低估 —— 知道端点支持更多的用户仍可在「高级」里打开。窗口取各发布方声明值的中位数,+ 而不是某一家的上限。+- 没有任何发布方声明该 ID 时,它保持为未知的通用模型。++这只改变元数据:配置的线上 ID、提供商身份,以及 §11.3 的绑定优先级都不变。+## 12. 刷新策略- settings/model 选择器中的手动刷新按钮