Skip to content

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

feat(models): answer a custom endpoint's ids with the publishers' consensus

vastsacf0b2b505d7a
diff --git a/apps/desktop/electron/main/models-dev-catalog.ts b/apps/desktop/electron/main/models-dev-catalog.ts
index 1abfce4b0..ddfbae956 100644
--- a/apps/desktop/electron/main/models-dev-catalog.ts
+++ b/apps/desktop/electron/main/models-dev-catalog.ts
@@ -799,12 +799,25 @@ export function catalogModelConfigFor(
input: { vendorKey?: string; baseUrl?: string; apiStyle?: string; modelId: string },
): ModelConfig {
const model = catalog.findModel(input);
- if (model) return modelConfigFromModelsDev(model, input.baseUrl);
- const generic = genericModelConfig(input.modelId, input.baseUrl ?? "");
- const thinking = input.apiStyle === "anthropic_messages"
+ if (!model) {
+ const generic = genericModelConfig(input.modelId, input.baseUrl ?? "");
+ const thinking = input.apiStyle === "anthropic_messages"
+ ? catalog.anthropicThinkingFor(input.modelId)
+ : undefined;
+ return thinking ? { ...generic, ...thinking } : generic;
+ }
+ const config = modelConfigFromModelsDev(model, input.baseUrl);
+ /*
+ A record that states no reasoning shape cannot speak for an Anthropic
+ Messages row: a record borrowed from another publisher has its own options
+ dropped, and a reseller's record describes the reseller's API. Anthropic's
+ own record is what says whether this id takes adaptive or budget thinking,
+ and losing that would put a rejected shape on the wire (#990).
+ */
+ const thinking = input.apiStyle === "anthropic_messages" && !config.reasoningOptions?.length
? catalog.anthropicThinkingFor(input.modelId)
: undefined;
- return thinking ? { ...generic, ...thinking } : generic;
+ return thinking ? { ...config, ...thinking } : config;
}
type IndexedModel = { model: ModelsDevModel; provider: ModelsDevProvider };
@@ -960,6 +973,53 @@ function medianOf(values: readonly (number | undefined)[]): number | undefined {
* publishers state, so neither one host's cap nor one host's round-up
* decides them.
*/
+/**
+ * Whether two ids name one model under different spellings.
+ *
+ * A publisher-prefixed copy (`anthropic/claude-sonnet-4-5` for
+ * `claude-sonnet-4-5`, `mify/mimo-v2.5-pro-0731` for `mimo-v2.5-pro`) and a
+ * dated or variant spelling of one id are the same model, so their records may
+ * be compared with each other. Two unrelated routes that happen to share a leaf
+ * (`provider-a/foo` vs `gateway/foo`) are not: that relation is a coincidence of
+ * naming, and nothing may treat it as identity.
+ *
+ * `catalogModelIdsMatch` stays the matcher of record; this only decides which of
+ * its matches a borrow without a provider identity may average.
+ */
+function sameModelSpelling(catalogId: string, requested: string): boolean {
+ const left = catalogId.trim().toLowerCase();
+ const right = requested.trim().toLowerCase();
+ if (!left || !right) return false;
+ if (left === right) return true;
+ if (left.endsWith(`/${right}`)) 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}`);
+}
+
+/**
+ * Record to use when nothing identifies the row's provider.
+ *
+ * A relay or a gateway the catalog cannot place still serves models the catalog
+ * knows, and asking for one of them by id used to answer nothing at all. What
+ * every publisher of that model agrees on can be claimed instead: the same
+ * intersection and median `borrowedModel` computes for an anchored row.
+ *
+ * One thing is deliberately not claimed. Which *wire shape* a deployment accepts
+ * for reasoning is a property of that deployment — the same model behind an
+ * OpenAI-compatible gateway and behind Anthropic's own API takes different
+ * reasoning fields — so a record borrowed this way drops its `reasoningOptions`
+ * rather than speaking for an endpoint no publisher describes. `catalogModelConfigFor`
+ * still applies Anthropic's own shape to an Anthropic Messages row that is left
+ * without one.
+ */
+function unanchoredConsensus(entries: readonly ModelsDevModel[]): ModelsDevModel | undefined {
+ const consensus = borrowedModel(entries);
+ return consensus ? { ...consensus, reasoningOptions: undefined } : undefined;
+}
+
function borrowedModel(entries: readonly ModelsDevModel[]): ModelsDevModel | undefined {
if (entries.length === 0) return undefined;
const toolCall = entries[0].toolCall;
@@ -1241,11 +1301,25 @@ export class ModelsDevCatalog {
dropping the model to the generic shape.
This only fills a miss the lookup already had — a record the preferred
- provider does publish stays authoritative. Without that anchor the scores
- prove nothing about identity, and an unknown endpoint keeps the existing
- behaviour: a unique unambiguous match, or nothing. */
+ 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 ??
- (preferredProvider ? this.borrowedAcrossProviders(input) : undefined);
+ (preferredProvider
+ ? this.borrowedAcrossProviders(input)
+ : unanchoredConsensus(
+ candidates
+ .filter((candidate) => sameModelSpelling(candidate.model.modelId, requested))
+ .map((candidate) => candidate.model),
+ ));
// 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);
diff --git a/apps/desktop/test/models-dev-catalog.test.mjs b/apps/desktop/test/models-dev-catalog.test.mjs
index 71844bb5a..c2656fe76 100644
--- a/apps/desktop/test/models-dev-catalog.test.mjs
+++ b/apps/desktop/test/models-dev-catalog.test.mjs
@@ -164,7 +164,7 @@ test("cached matches remain scoped to the requested provider and endpoint", asyn
}
});
-test("unknown endpoints do not inherit ambiguous cross-provider metadata", async (t) => {
+test("an unknown endpoint borrows only what every publisher of the id agrees on", async (t) => {
for (const order of [["alpha", "beta"], ["beta", "alpha"]]) {
const fixture = Object.fromEntries(order.map((key) => [key, {
api: `https://${key}.example/v1`,
@@ -177,11 +177,25 @@ test("unknown endpoints do not inherit ambiguous cross-provider metadata", async
},
}]));
const catalog = await loadFixtureCatalog(t, fixture);
- for (const modelId of ["shared-model", "proxy/shared-model"]) {
- const unknown = { vendorKey: "custom", baseUrl: "https://relay.example/v1", modelId };
- assert.equal(catalog.findModel(unknown), undefined, `ambiguous ${modelId} must miss`);
- assert.equal(catalog.findModel(unknown), undefined, "ambiguous misses are cached");
- }
+ /*
+ No provider identity: neither publisher may answer alone. What every one of
+ them states can be claimed, and it under-claims — reasoning only when all
+ report it, limits as the lower median of the claims.
+ */
+ const unknown = { vendorKey: "custom", baseUrl: "https://relay.example/v1", modelId: "shared-model" };
+ const consensus = catalog.findModel(unknown);
+ assert.equal(consensus?.limit.context, 32_000, "the lower median, not the larger claim");
+ assert.equal(consensus?.limit.output, 8_192);
+ 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.
+ */
+ assert.equal(
+ catalog.findModel({ vendorKey: "custom", baseUrl: "https://relay.example/v1", modelId: "proxy/shared-model" }),
+ undefined,
+ );
const alpha = catalog.findModel({
vendorKey: "custom", baseUrl: "https://alpha.example/v1", modelId: "shared-model",
});
@@ -231,7 +245,17 @@ test("a shared catalog API with no vendor key cannot select the first publisher"
limit: { context: key === "alpha" ? 128_000 : 32_000, output: 8_192 } } },
}])));
assert.equal(catalog.providerKeyForRow({ vendorKey: "custom", baseUrl: "https://gateway.example/v1" }), undefined);
- assert.equal(catalog.findModel({ vendorKey: "custom", baseUrl: "https://gateway.example/v1", modelId: "shared-model" }), undefined);
+ /*
+ The row has no publisher of its own, so the id answers with what both
+ publishers of that endpoint state — never with the first one indexed.
+ */
+ const consensus = catalog.findModel({
+ vendorKey: "custom",
+ baseUrl: "https://gateway.example/v1",
+ modelId: "shared-model",
+ });
+ assert.equal(consensus?.reasoning, false);
+ assert.equal(consensus?.limit.context, 32_000);
assert.equal(catalog.findModel({ vendorKey: "beta", baseUrl: "https://gateway.example/v1", modelId: "shared-model" })?.providerKey, "beta");
}
});
@@ -1362,7 +1386,7 @@ const customGateway = {
baseUrl: "https://gateway.example/v1",
};
-test("a custom Anthropic gateway takes Anthropic's thinking options for an exact Claude id", async (t) => {
+test("a custom Anthropic gateway borrows the consensus and keeps Anthropic's thinking shape", async (t) => {
const catalog = await loadFixtureCatalog(t, ambiguousClaudeFixture);
const config = catalogModelConfigFor(catalog, {
...customGateway,
@@ -1370,11 +1394,21 @@ test("a custom Anthropic gateway takes Anthropic's thinking options for an exact
modelId: "claude-opus-5-5",
});
- // The ambiguous record itself is still not borrowed: limits stay generic.
- assert.equal(config.source, "generic");
- assert.equal(config.contextWindow, 128_000);
- assert.equal(config.reasoning, false);
- // Only the thinking wire shape comes from the Anthropic record.
+ /*
+ 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.
+ */
+ assert.equal(config.source, "models.dev");
+ assert.equal(config.contextWindow, 200_000);
+ assert.equal(config.maxTokens, 64_000);
+ assert.equal(config.reasoning, true);
+ /*
+ No publisher describes this endpoint's reasoning wire shape, so the borrowed
+ record states none — and Anthropic's own record is what says whether the id
+ takes adaptive or budget thinking.
+ */
assert.deepEqual(config.reasoningOptions, [
{ type: "effort", values: ["low", "medium", "high", "xhigh", "max"] },
]);
@@ -1480,11 +1514,17 @@ test("an exact record answers an id its shorter siblings would only alias", asyn
const borrowed = catalog.findModel({ vendorKey: "alpha", modelId: "foo-v2-0815" });
assert.equal(borrowed?.modelId, "foo-v2");
- // Two publishers of the alias cannot answer for an unknown endpoint…
- assert.equal(
- catalog.findModel({ vendorKey: "custom", baseUrl: "https://relay.example/v1", modelId: "foo-v2" }),
- undefined,
- );
+ /*
+ An id only its siblings state answers with their consensus rather than with
+ one publisher's record — the dated sibling's claim included, the lower
+ median of the three is what every publisher can be said to support.
+ */
+ const consensus = catalog.findModel({
+ vendorKey: "custom",
+ baseUrl: "https://relay.example/v1",
+ modelId: "foo-v2",
+ });
+ assert.equal(consensus?.limit.context, 64_000);
// …but a record the catalog publishes in full answers for itself.
const published = catalog.findModel({
vendorKey: "custom",
@@ -1532,7 +1572,7 @@ test("a custom endpoint on a uniquely published host inherits that publisher", a
);
});
-test("a host two publishers share stays unresolved rather than guessed", async (t) => {
+test("a host two publishers share borrows only their consensus", async (t) => {
const catalog = await loadFixtureCatalog(t, {
alpha: {
api: "https://shared.example/api/paas/v4",
@@ -1543,15 +1583,25 @@ test("a host two publishers share stays unresolved rather than guessed", async (
models: { "glm-5.3": { id: "glm-5.3", reasoning: false, limit: { context: 32_000 } } },
},
});
- // The path is not published, so the host is the only evidence — and it names
- // two publishers. Missing metadata beats metadata from the wrong one.
- assert.equal(
- catalog.findModel({ vendorKey: "custom", baseUrl: "https://shared.example/v1", modelId: "glm-5.3" }),
- undefined,
- );
- // Naming the publisher still resolves it.
- assert.equal(
- catalog.findModel({ vendorKey: "alpha", baseUrl: "https://shared.example/v1", modelId: "glm-5.3" })?.providerKey,
- "alpha",
- );
+ /*
+ The typed path is not published, so the host is the only evidence — and it
+ names two publishers, neither of which may answer alone. What both state is
+ what a row without an identity gets: reasoning only when both claim it, and
+ the lower median of the limits.
+ */
+ const consensus = catalog.findModel({
+ vendorKey: "custom",
+ baseUrl: "https://shared.example/v1",
+ modelId: "glm-5.3",
+ });
+ assert.equal(consensus?.reasoning, false);
+ assert.equal(consensus?.limit.context, 32_000);
+ // Naming the publisher still resolves it to that publisher's own record.
+ const alpha = catalog.findModel({
+ vendorKey: "alpha",
+ baseUrl: "https://shared.example/v1",
+ modelId: "glm-5.3",
+ });
+ assert.equal(alpha?.providerKey, "alpha");
+ assert.equal(alpha?.limit.context, 1_000_000);
});
diff --git a/apps/desktop/test/provider-endpoint-metadata.test.mjs b/apps/desktop/test/provider-endpoint-metadata.test.mjs
index fbb88c3dd..a8438fdf1 100644
--- a/apps/desktop/test/provider-endpoint-metadata.test.mjs
+++ b/apps/desktop/test/provider-endpoint-metadata.test.mjs
@@ -1,14 +1,16 @@
/**
- * A custom endpoint on a published host still gets that publisher's metadata.
+ * A custom endpoint gets the metadata the catalog can justify for it.
*
- * The reported failure: a custom row pointed at `https://open.bigmodel.cn/api/v1`
- * (the Zhipu OpenAI Responses endpoint) listed its models but showed a generic
- * 128k / 8k text-only row for every one of them, while the same models are fully
- * described in models.dev — the catalog only accepted that host's own published
- * path, and the row declared no publisher of its own.
+ * Two reported failures live here. A custom row pointed at
+ * `https://open.bigmodel.cn/api/v1` (Zhipu's OpenAI Responses endpoint) listed
+ * its models but showed a generic 128k / 8k text-only row for every one of them,
+ * because the catalog only accepted that host's own published path. And a row on
+ * a relay the catalog cannot place got nothing at all for models the catalog
+ * describes, because one publisher's record must never answer for another.
*
- * This drives the real `providersListModels` handler with the bundled snapshot,
- * so it pins the whole chain: discovery, endpoint resolution, catalog anchoring.
+ * This drives the real handlers with the bundled snapshot, so it pins the whole
+ * chain: discovery, endpoint resolution, catalog anchoring, and the hand-typed
+ * id channel.
*/
import assert from "node:assert/strict";
import { register } from "node:module";
@@ -29,8 +31,8 @@ function jsonResponse(body, status = 200) {
});
}
-/** Register the real list-models handler against one row and one served list. */
-async function listModelsFor(t, row, body) {
+/** Register the real handlers against one row and one served model list. */
+async function handlersFor(t, row, body) {
const catalog = new ModelsDevCatalog({ catalogPath });
assert.equal(await catalog.ensureLoaded(), true, "the bundled snapshot must load");
@@ -64,23 +66,40 @@ async function listModelsFor(t, row, body) {
bindingForModel: () => undefined,
});
- const handler = handlers.get(IPC.invoke.providersListModels);
- assert.equal(typeof handler, "function", "list-models handler is not registered");
- return { result: await handler({ providerId: row.id, source: "refresh" }), calls };
+ const listModels = handlers.get(IPC.invoke.providersListModels);
+ assert.equal(typeof listModels, "function", "list-models handler is not registered");
+ const lookupModel = handlers.get(IPC.invoke.providersLookupModel);
+ assert.equal(typeof lookupModel, "function", "model-lookup handler is not registered");
+
+ return {
+ calls,
+ row,
+ result: await listModels({ providerId: row.id, source: "refresh" }),
+ /** The hand-typed id channel a picker uses when a user types an id in. */
+ lookup: (input) => lookupModel(input),
+ };
}
-test("a custom row on a published host gets that publisher's model metadata", async (t) => {
- const row = {
- id: "row-1",
- name: "Zhipu",
+function rowOf(overrides) {
+ return {
+ name: "Row",
vendorKey: "custom",
- baseUrl: "https://open.bigmodel.cn/api/v1",
- apiStyle: "responses",
+ apiStyle: "chat_completions",
models: [],
authKind: "api_key_and_base_url",
headers: {},
+ ...overrides,
};
- const { result, calls } = await listModelsFor(t, row, {
+}
+
+test("a custom row on a published host gets that publisher's model metadata", async (t) => {
+ const row = rowOf({
+ id: "row-1",
+ name: "Zhipu",
+ baseUrl: "https://open.bigmodel.cn/api/v1",
+ apiStyle: "responses",
+ });
+ const { result, calls } = await handlersFor(t, row, {
models: [{ slug: "glm-5.3", display_name: "glm-5.3" }],
});
@@ -98,21 +117,48 @@ test("a custom row on a published host gets that publisher's model metadata", as
}
});
-test("a custom row on a host the catalog does not know keeps generic defaults", async (t) => {
- const row = {
+test("a relay's list gets what every publisher of an id agrees on", async (t) => {
+ const row = rowOf({
id: "row-2",
name: "Relay",
- vendorKey: "custom",
baseUrl: "https://relay.example/v1",
- apiStyle: "chat_completions",
- models: [],
- authKind: "api_key_and_base_url",
- headers: {},
- };
- const { result } = await listModelsFor(t, row, { data: [{ id: "some-private-model" }] });
+ });
+ const { result } = await handlersFor(t, row, {
+ data: [{ id: "claude-sonnet-4-5" }, { id: "some-private-model" }],
+ });
- const [model] = result.models;
- assert.equal(model.catalogSource, undefined);
- assert.equal(model.contextWindow, 128_000);
- assert.deepEqual(model.capabilities, ["text"]);
+ 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);
+ assert.ok(known.capabilities.includes("tools"));
+ // An id no publisher states still lands on the generic seed.
+ const unknown = byId.get("some-private-model");
+ assert.equal(unknown.catalogSource, undefined);
+ assert.equal(unknown.contextWindow, 128_000);
+ assert.deepEqual(unknown.capabilities, ["text"]);
+});
+
+test("a hand-typed id on the same relay answers with the same record", async (t) => {
+ const row = rowOf({
+ id: "row-3",
+ name: "Relay",
+ baseUrl: "https://relay.example/v1",
+ });
+ const { lookup } = await handlersFor(t, row, { data: [] });
+
+ const known = await lookup({
+ modelId: "claude-sonnet-4-5",
+ baseUrl: row.baseUrl,
+ vendorKey: row.vendorKey,
+ providerId: row.id,
+ });
+ assert.ok(known.info, "a typed id the catalog knows must reach its record");
+ assert.equal(known.info.modelId, "claude-sonnet-4-5");
+ assert.ok(known.info.capabilities.includes("tools"));
+
+ // A private id stays generic, and the lookup never contacts the network.
+ const unknown = await lookup({ modelId: "some-private-model", baseUrl: row.baseUrl });
+ assert.equal(unknown.info, null);
});
diff --git a/docs/spec/03-runtime/12-provider-config-schema.md b/docs/spec/03-runtime/12-provider-config-schema.md
index f5762e49b..b3b700630 100644
--- a/docs/spec/03-runtime/12-provider-config-schema.md
+++ b/docs/spec/03-runtime/12-provider-config-schema.md
@@ -732,9 +732,19 @@ matches, the endpoint registry for a known host, then the catalog's own host
when exactly one provider publishes from it. That is what keeps a custom row on
a vendor's alternative API path — `https://open.bigmodel.cn/api/v1` for Zhipu's
OpenAI Responses endpoint — from showing generic 128k / 8k / text-only defaults
-for models the catalog describes in full. A host two publishers share, or a host
-the catalog does not know, resolves to nothing: a missing record stays ahead of
-a wrong one. A model ID never decides which publisher is read.
+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
+(`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.
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
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 8e86aa5b9..726112584 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
@@ -510,8 +510,14 @@ Chat Completions 配置使用同源 Responses。关闭搜索后恢复原配置
行自身没有指明发布方时,按端点能识别的发布方来读,顺序是:已发布基础地址完全匹配的目录记录、
端点注册表中的已知主机、以及该主机在目录里恰好只有一个发布方时的这条记录。这样自定义行指向厂商
的另一个接口路径时(例如智谱 OpenAI Responses 端点 `https://open.bigmodel.cn/api/v1`),不会对
-目录里已有完整描述的模型显示成通用的 128k / 8k / 纯文本默认值。多个发布方共用的主机、或目录不认识
-的主机,一律不做匹配:宁可缺元数据,也不给错元数据。模型 ID 不参与判断该读哪个发布方。
+目录里已有完整描述的模型显示成通用的 128k / 8k / 纯文本默认值。
+
+完全识别不出发布方时(中转站、或目录不认识的主机),不采用任何单个发布方的记录;这类行过去拿不到
+任何元数据。现在改为采用「同一模型的所有发布方都认可的部分」:某项能力只在所有发布方都声明时才保留,
+上下文与输出取各家数值的下中位数,因此只可能低估。各发布方在工具能力上不一致时不借用。仅仅是名字
+末段相同(`provider-a/foo` 与 `gateway/foo`)的两条不同路由不算同一模型,因此身份确实未知的 ID 仍然
+不做匹配。以这种方式借用的记录不声明推理的线上字段形状(那是部署的属性),而 Anthropic Messages 行
+仍使用 Anthropic 自己的形状。模型 ID 不参与判断该读哪个发布方。
元数据匹配可以跟随发布日期后缀:`mify/mimo-v2.5-pro-0731` 会借用 `mimo-v2.5-pro` 的发布记录,
但目录中与该 ID 完全一致的记录仍然优先于这类别名。别名只影响元数据:已保存绑定的线上 ID 保持