Skip to content

Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins

fix(models): claim a custom endpoint's tool support by majority

vastsa403caf65f079
diff --git a/apps/desktop/electron/main/models-dev-catalog.ts b/apps/desktop/electron/main/models-dev-catalog.ts
index ddfbae956..22ad6cb84 100644
--- a/apps/desktop/electron/main/models-dev-catalog.ts
+++ b/apps/desktop/electron/main/models-dev-catalog.ts
@@ -836,7 +836,13 @@ class ModelsDevLookupIndex {
constructor(providers: ReadonlyMap<string, ModelsDevProvider>) {
for (const provider of providers.values()) {
for (const model of provider.models) {
- if (!isTextAgentModel(model)) continue;
+ /*
+ Every published model is indexed, including the audio-only ones the
+ listing drops: `modelsForProvider` decides which models a row
+ *offers*, while this index answers for an ID a row already lists, and
+ an endpoint that serves a TTS or ASR id has a published record for
+ it. Filtering here is what left such a row on the generic seed.
+ */
const entry: IndexedModel = { model, provider };
for (const key of registrationKeys(model.modelId)) {
let bucket = this.byModelId.get(key);
@@ -962,10 +968,11 @@ function medianOf(values: readonly (number | undefined)[]): number | undefined {
*
* Two rules keep the result honest about what the endpoint will accept:
*
- * - Tool support is the gate. Every publisher of the id must agree, because a
- * wrong `true` puts tool declarations on the wire that the endpoint may
- * reject and break the turn. Publishers that split on this id are describing
- * different deployments, so nothing is borrowed.
+ * - Tool support follows the majority of the publishers that state it. One
+ * dissenting reseller must not decide the claim for a deployment it does not
+ * describe, and neither may one agreeing reseller: an id a relay lists can be
+ * stated by a hundred publishers, which is what left whole model lists on the
+ * generic seed before. An even split states no majority and claims nothing.
* - Every other capability is the *intersection*, so the borrow may only
* under-claim. Reasoning, image input and image/PDF attachment are reported
* only when every publisher states them, and a user who knows the endpoint
@@ -1020,10 +1027,26 @@ function unanchoredConsensus(entries: readonly ModelsDevModel[]): ModelsDevModel
return consensus ? { ...consensus, reasoningOptions: undefined } : undefined;
}
+/**
+ * The value most entries that state one agree on, or undefined when they split.
+ *
+ * A single dissenting publisher must not decide a claim, and a single agreeing
+ * one must not either: an id in a relay's list can be stated by a hundred
+ * resellers, and one reseller's flag is not evidence about the deployment this
+ * row talks to. An even split states no majority, so nothing is claimed.
+ */
+function majorityOf(values: readonly (boolean | undefined)[]): boolean | undefined {
+ const stated = values.filter((value): value is boolean => value !== undefined);
+ if (stated.length === 0) return undefined;
+ const yes = stated.filter(Boolean).length;
+ if (yes * 2 > stated.length) return true;
+ if (yes * 2 < stated.length) return false;
+ return undefined;
+}
+
function borrowedModel(entries: readonly ModelsDevModel[]): ModelsDevModel | undefined {
if (entries.length === 0) return undefined;
- const toolCall = entries[0].toolCall;
- if (entries.some((model) => model.toolCall !== toolCall)) return undefined;
+ const toolCall = majorityOf(entries.map((model) => model.toolCall));
const every = (pick: (model: ModelsDevModel) => boolean | undefined): boolean | undefined =>
entries.every((model) => pick(model) === true) ? true
: entries.every((model) => pick(model) === false) ? false
diff --git a/apps/desktop/test/models-dev-catalog.test.mjs b/apps/desktop/test/models-dev-catalog.test.mjs
index c2656fe76..da61b3fe2 100644
--- a/apps/desktop/test/models-dev-catalog.test.mjs
+++ b/apps/desktop/test/models-dev-catalog.test.mjs
@@ -512,22 +512,31 @@ test("a borrowed record under-claims instead of asserting one publisher's extras
assert.equal(info.capabilities.includes("reasoning"), false);
});
-test("publishers split on tool support are not borrowed from at all", async (t) => {
- // Tool support is the gate: a wrong `true` would put tool declarations on the
- // wire that the endpoint may reject, so a split here refuses the borrow.
+test("an even split on tool support claims no tools but still borrows the limits", async (t) => {
+ /*
+ Tool support follows the majority of the publishers that state it. One
+ dissenting reseller must not decide the claim for a deployment it does not
+ describe, but neither may one agreeing reseller: an id a relay lists can be
+ stated by a hundred publishers. Two publishers that split evenly state no
+ majority, so the borrow keeps the limits and leaves tool support unclaimed
+ instead of refusing outright — refusing is what left whole model lists on
+ the generic seed.
+ */
const catalog = await loadFixtureCatalog(t, {
gateway: { api: "https://gateway.example/v1", models: {} },
publisherA: { models: { "Vendor/Split": { id: "Vendor/Split", tool_call: true, limit: { context: 262_144 } } } },
publisherB: { models: { "Vendor/Split": { id: "Vendor/Split", tool_call: false, limit: { context: 262_144 } } } },
});
- assert.equal(
- catalog.findModel({
- vendorKey: "gateway",
- baseUrl: "https://gateway.example/v1",
- modelId: "Vendor/Split",
- }),
- undefined,
- );
+ const match = catalog.findModel({
+ vendorKey: "gateway",
+ baseUrl: "https://gateway.example/v1",
+ modelId: "Vendor/Split",
+ });
+ assert.ok(match, "a split must not drop the id to the generic shape");
+ assert.equal(match.toolCall, undefined, "an even split claims no tool support");
+ assert.equal(match.limit.context, 262_144);
+ const info = modelInfoFromModelsDev(match, "provider-1");
+ assert.equal(info.capabilities.includes("tools"), false);
});
test("a borrowed record never replaces what the row's own catalog provider publishes", async (t) => {
@@ -549,7 +558,11 @@ test("a borrowed record never replaces what the row's own catalog provider publi
assert.equal(match.toolCall, false);
});
-test("publishers that disagree about capabilities are not borrowed from", async (t) => {
+test("publishers that disagree about capabilities narrow the borrowed record", async (t) => {
+ // A disputed capability shape is never resolved by picking one publisher:
+ // the disagreement narrows the claim instead of voiding the borrow.
+ // Reasoning follows the intersection, so it is reported only when every
+ // publisher states it.
const catalog = await loadFixtureCatalog(t, {
gateway: { api: "https://gateway.example/v1", models: {} },
publisherA: { models: { "Vendor/Disputed": {
@@ -559,15 +572,40 @@ test("publishers that disagree about capabilities are not borrowed from", async
id: "Vendor/Disputed", tool_call: false, reasoning: false, limit: { context: 262_144 },
} } },
});
- assert.equal(
- catalog.findModel({
- vendorKey: "gateway",
- baseUrl: "https://gateway.example/v1",
- modelId: "Vendor/Disputed",
- }),
- undefined,
- "a disputed capability shape must not be resolved by picking one publisher",
- );
+ const match = catalog.findModel({
+ vendorKey: "gateway",
+ baseUrl: "https://gateway.example/v1",
+ modelId: "Vendor/Disputed",
+ });
+ assert.ok(match, "a disputed capability shape must not void the borrow");
+ assert.equal(match.toolCall, undefined);
+ assert.equal(match.reasoning, false);
+ assert.equal(match.limit.context, 262_144);
+});
+
+test("a majority of the publishers that state tool support decides the borrow", async (t) => {
+ // The counterpart of the even split above: with a clear majority the claim
+ // is stated, so a relay listing an id many publishers agree on keeps its
+ // tool support instead of dropping to text-only defaults.
+ const catalog = await loadFixtureCatalog(t, {
+ gateway: { api: "https://gateway.example/v1", models: {} },
+ publisherA: { models: { "Vendor/Majority": { id: "Vendor/Majority", tool_call: true, limit: { context: 262_144 } } } },
+ publisherB: { models: { "Vendor/Majority": { id: "Vendor/Majority", tool_call: true, limit: { context: 1_048_576 } } } },
+ publisherC: { models: { "Vendor/Majority": { id: "Vendor/Majority", tool_call: true, limit: { context: 1_048_576 } } } },
+ publisherD: { models: { "Vendor/Majority": { id: "Vendor/Majority", tool_call: false, limit: { context: 1_048_576 } } } },
+ });
+ const match = catalog.findModel({
+ vendorKey: "gateway",
+ baseUrl: "https://gateway.example/v1",
+ modelId: "Vendor/Majority",
+ });
+ assert.ok(match, "a clear majority still borrows");
+ assert.equal(match.toolCall, true);
+ // Limits are still the lower median, so one small window is not rounded up
+ // and one dissenting publisher does not drag the majority's window down.
+ assert.equal(match.limit.context, 1_048_576);
+ const info = modelInfoFromModelsDev(match, "provider-1");
+ assert.equal(info.capabilities.includes("tools"), true);
});
test("borrowing stays exact-id, provider-scoped and absent for unknown ids", async (t) => {
diff --git a/apps/desktop/test/provider-endpoint-metadata.test.mjs b/apps/desktop/test/provider-endpoint-metadata.test.mjs
index a8438fdf1..cb9d29042 100644
--- a/apps/desktop/test/provider-endpoint-metadata.test.mjs
+++ b/apps/desktop/test/provider-endpoint-metadata.test.mjs
@@ -162,3 +162,48 @@ test("a hand-typed id on the same relay answers with the same record", async (t)
const unknown = await lookup({ modelId: "some-private-model", baseUrl: row.baseUrl });
assert.equal(unknown.info, null);
});
+
+test("a relay's list keeps the tool support a majority of publishers states", async (t) => {
+ /*
+ Reported misses from a relay's own list. `deepseek-v4-flash` is stated by
+ dozens of publishers and `mimo-v2.5-pro` by many, a few of which say
+ `tool_call: false`, so requiring unanimity dropped both to the generic seed
+ even though the id is plainly published. Tool support now follows the
+ majority. A served id whose own record is an audio model resolves with it
+ too, while an id no publisher states still gets nothing.
+ */
+ const row = rowOf({ id: "row-4", name: "Relay", baseUrl: "https://relay.example/v1" });
+ const { result } = await handlersFor(t, row, {
+ data: [
+ { id: "deepseek-v4-flash" },
+ { id: "mimo-v2.5-pro" },
+ { id: "mimo-v2.5-tts" },
+ { id: "gemini-2.5-pro-1m" },
+ ],
+ });
+
+ const byId = new Map(result.models.map((model) => [model.modelId, model]));
+
+ const deepseek = byId.get("deepseek-v4-flash");
+ assert.equal(deepseek.catalogSource, "models.dev");
+ assert.ok(deepseek.capabilities.includes("tools"), "a stated majority must be claimed");
+ assert.equal(deepseek.contextWindow, 1_000_000);
+
+ const mimo = byId.get("mimo-v2.5-pro");
+ assert.equal(mimo.catalogSource, "models.dev");
+ assert.ok(mimo.capabilities.includes("tools"));
+ assert.equal(mimo.contextWindow, 1_048_576);
+
+ // The listing decides which models a row *offers*; the lookup answers for the
+ // ids the service actually serves, audio-only ones included.
+ const tts = byId.get("mimo-v2.5-tts");
+ assert.equal(tts.catalogSource, "models.dev");
+ assert.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.
+ const variant = byId.get("gemini-2.5-pro-1m");
+ assert.equal(variant.catalogSource, undefined);
+ assert.equal(variant.contextWindow, 128_000);
+});
diff --git a/docs/spec/03-runtime/12-provider-config-schema.md b/docs/spec/03-runtime/12-provider-config-schema.md
index b3b700630..58dc3444a 100644
--- a/docs/spec/03-runtime/12-provider-config-schema.md
+++ b/docs/spec/03-runtime/12-provider-config-schema.md
@@ -736,16 +736,24 @@ for 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 *every* publisher of the same model states is claimed instead: a
-capability only when all of them state it, and the lower median of their limits,
-so the answer can only under-claim. Publishers that disagree on tool support are
-not borrowed from at all. Two routes that merely share a name leaf
+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
(`provider-a/foo` vs `gateway/foo`) are not one model, so an ID whose identity is
genuinely unknown still resolves to nothing. A record borrowed this way states no
reasoning wire shape — that is a property of the deployment — and an Anthropic
Messages row keeps Anthropic's own shape. A model ID never decides which
publisher is read.
+The lookup answers for the IDs a row already lists, so a served ID whose published
+record is an audio model — a TTS or ASR sibling — resolves to that record too.
+Only the catalog listing is scoped to text/agent models, because it decides which
+models a row offers.
+
Metadata matching may follow a release stamp: `mify/mimo-v2.5-pro-0731` borrows
the published record of `mimo-v2.5-pro`, and a record the catalog publishes
under exactly the requested ID still wins over such an alias. The alias is
diff --git a/docs/zh-CN/spec/03-runtime/12-provider-config-schema.md b/docs/zh-CN/spec/03-runtime/12-provider-config-schema.md
index 726112584..713f1b2aa 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
@@ -513,12 +513,17 @@ Chat Completions 配置使用同源 Responses。关闭搜索后恢复原配置
目录里已有完整描述的模型显示成通用的 128k / 8k / 纯文本默认值。
完全识别不出发布方时(中转站、或目录不认识的主机),不采用任何单个发布方的记录;这类行过去拿不到
-任何元数据。现在改为采用「同一模型的所有发布方都认可的部分」:某项能力只在所有发布方都声明时才保留,
-上下文与输出取各家数值的下中位数,因此只可能低估。各发布方在工具能力上不一致时不借用。仅仅是名字
+任何元数据。现在改为采用「同一模型的各发布方共同认可的部分」:上下文与输出取各家数值的下中位数;
+除工具能力外的各项能力,只在所有发布方都声明时才保留,因此只可能低估。工具能力按声明该能力的发布方
+的多数决:中转站列出的一个 ID 可能被上百个发布方声明,某个并不描述该部署的中转商既不应替它下结论,
+也不应让整条记录作废;票数持平则不声明。仅仅是名字
末段相同(`provider-a/foo` 与 `gateway/foo`)的两条不同路由不算同一模型,因此身份确实未知的 ID 仍然
不做匹配。以这种方式借用的记录不声明推理的线上字段形状(那是部署的属性),而 Anthropic Messages 行
仍使用 Anthropic 自己的形状。模型 ID 不参与判断该读哪个发布方。
+查找针对的是行已经列出的 ID:服务返回的 ID 若自身记录是音频模型(TTS/ASR 同类),也会命中该记录。
+只有目录列表本身限定为文本 / Agent 模型,因为它决定一行「提供」哪些模型。
+
元数据匹配可以跟随发布日期后缀:`mify/mimo-v2.5-pro-0731` 会借用 `mimo-v2.5-pro` 的发布记录,
但目录中与该 ID 完全一致的记录仍然优先于这类别名。别名只影响元数据:已保存绑定的线上 ID 保持
服务实际返回的原值。