Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins
TypeScript ai-agentcoding-agentdesktop-appelectronglobali18nlocal-firstmcppipi-agentpi-desktoppluginsreactrusttypescript
fix(catalog): confine proxy aliases to provider-scoped metadata
aurorax-neo09455bfb526b
diff --git a/apps/desktop/electron/main/models-dev-catalog.ts b/apps/desktop/electron/main/models-dev-catalog.tsindex c48f21c6f..11ff33580 100644--- a/apps/desktop/electron/main/models-dev-catalog.ts+++ b/apps/desktop/electron/main/models-dev-catalog.ts@@ -1,5 +1,5 @@import { readFile } from "node:fs/promises";-import { MODEL_VENDOR_PREFIXES, isProxyPrefix, modelIdsMatch, stripThinkingSuffix, stripVariantSuffix } from "@pi-desktop/shared";+import { MODEL_VENDOR_PREFIXES, catalogModelIdsMatch, stripVariantSuffix } from "@pi-desktop/shared";import type {ModelCost,ModelCostTier,@@ -812,98 +812,47 @@ class ModelsDevLookupIndex {}}-/** The normalized id, the `@region`-less base, the thinking-suffix stripped base,- * and every vendor-prefixed form `modelIdsMatch` treats as equivalent, so a query- * finds all matching catalog models through the index without a full scan. */-function registrationKeys(modelId: string): string[] {+/** Index only aliases the matcher can accept: exact IDs, full slash-path+ * leaves, known-vendor dash/dot prefixes, and the supported suffix variants.+ * The matcher remains the final authority (including known-vendor conflicts). */+function candidateKeys(modelId: string): string[] {+ const normalized = normalizedModelId(modelId);+ if (!normalized) return [];const keys = new Set<string>();- const raw = modelId.trim();- const normalized = normalizedModelId(raw);- keys.add(normalized);-const at = normalized.indexOf("@");- if (at > 0) keys.add(normalized.slice(0, at));+ const base = at > 0 ? normalized.slice(0, at) : normalized;- const strippedVariant = stripVariantSuffix(normalized);- if (strippedVariant !== normalized) {- keys.add(strippedVariant);- const strippedAt = strippedVariant.indexOf("@");- if (strippedAt > 0) keys.add(strippedVariant.slice(0, strippedAt));- }-- const lastSlash = normalized.lastIndexOf("/");- if (lastSlash > 0 && lastSlash < normalized.length - 1) {- const base = normalized.slice(lastSlash + 1);- keys.add(base);- const baseStripped = stripVariantSuffix(base);- if (baseStripped !== base) keys.add(baseStripped);- }-- for (const separator of ["/", "-", "."] as const) {- for (const prefix of MODEL_VENDOR_PREFIXES) {- const head = `${prefix}${separator}`;- if (normalized.startsWith(head) && normalized.length > head.length) {- const rest = normalized.slice(head.length);- keys.add(rest);- const restStripped = stripVariantSuffix(rest);- if (restStripped !== rest) keys.add(restStripped);+ const add = (value: string) => {+ if (!value) return;+ keys.add(value);+ const slash = value.lastIndexOf("/");+ if (slash >= 0 && slash < value.length - 1) keys.add(value.slice(slash + 1));+ for (const separator of ["-", "."] as const) {+ for (const vendor of MODEL_VENDOR_PREFIXES) {+ const head = `${vendor}${separator}`;+ if (value.startsWith(head) && value.length > head.length) {+ keys.add(value.slice(head.length));+ }}}- }- return [...keys];-}--/** Candidate keys derived from a requested model ID to search in the catalog index,- * covering proxy routing paths, vendor dash/dot prefixes, and thinking suffixes. */-function lookupCandidateKeys(requested: string): string[] {- const raw = requested.trim();- if (!raw) return [];- const normalized = normalizedModelId(raw);- const keys = new Set<string>();-- const addVariants = (str: string) => {- if (!str) return;- keys.add(str);- const at = str.indexOf("@");- if (at > 0) keys.add(str.slice(0, at));- const strippedVariant = stripVariantSuffix(str);- if (strippedVariant !== str) {- keys.add(strippedVariant);- const strippedAt = strippedVariant.indexOf("@");- if (strippedAt > 0) keys.add(strippedVariant.slice(0, strippedAt));- }};- addVariants(normalized);-- const slashParts = normalized.split("/");- if (slashParts.length > 1) {- for (let i = 1; i < slashParts.length; i++) {- addVariants(slashParts.slice(i).join("/"));- }+ // Strip a suffix only after the region, just as catalogModelIdsMatch does. Add+ // aliases from both sides so a suffixed catalog ID or request can find its peer.+ for (const value of new Set([normalized, base, stripVariantSuffix(base)])) {+ add(value);+ const slash = value.lastIndexOf("/");+ if (slash >= 0 && slash < value.length - 1) add(value.slice(slash + 1));}+ return [...keys];+}- for (const key of [...keys]) {- for (const separator of ["-", "."] as const) {- for (const prefix of MODEL_VENDOR_PREFIXES) {- const head = `${prefix}${separator}`;- if (key.startsWith(head) && key.length > head.length) {- addVariants(key.slice(head.length));- }- }- let pos = key.indexOf(separator);- while (pos > 0 && pos < key.length - 1) {- const prefix = key.slice(0, pos);- const rest = key.slice(pos + 1);- if (isProxyPrefix(prefix, rest)) {- addVariants(rest);- }- pos = key.indexOf(separator, pos + 1);- }- }- }+function registrationKeys(modelId: string): string[] {+ return candidateKeys(modelId);+}- return [...keys];+function lookupCandidateKeys(requested: string): string[] {+ return candidateKeys(requested);}const EMPTY_CANDIDATES: readonly IndexedModel[] = [];@@ -1020,21 +969,27 @@ export class ModelsDevCatalog {}private providerFor(input: { vendorKey?: string; baseUrl?: string }): ModelsDevProvider | undefined {- const byApi = [...this.providers.values()].find((provider) =>+ const candidates = new Set(providerKeyCandidates(input.vendorKey));+ const apiProviders = [...this.providers.values()].filter((provider) =>apiMatches(input.baseUrl, provider.api),);- if (byApi) return byApi;- const candidates = new Set(providerKeyCandidates(input.vendorKey));- for (const provider of this.providers.values()) {- if (candidates.has(normalizedProviderKey(provider.providerKey))) return provider;+ if (apiProviders.length > 0) {+ return apiProviders.find((provider) =>+ candidates.has(normalizedProviderKey(provider.providerKey)),+ ) ?? apiProviders[0];}const knownKey = Object.entries(KNOWN_PROVIDER_BASE_URLS).find(([, urls]) =>urls.some((url) => apiMatches(input.baseUrl, url)),)?.[0];- if (!knownKey) return undefined;- const knownCandidates = new Set(providerKeyCandidates(knownKey));+ if (knownKey) {+ const knownCandidates = new Set(providerKeyCandidates(knownKey));+ const knownProvider = [...this.providers.values()].find((provider) =>+ knownCandidates.has(normalizedProviderKey(provider.providerKey)),+ );+ if (knownProvider) return knownProvider;+ }return [...this.providers.values()].find((provider) =>- knownCandidates.has(normalizedProviderKey(provider.providerKey)),+ candidates.has(normalizedProviderKey(provider.providerKey)),);}@@ -1061,7 +1016,9 @@ export class ModelsDevCatalog {}const candidates: Array<{ model: ModelsDevModel; score: number }> = [];for (const { model, provider } of [...preferred, ...rest]) {- if (!modelIdsMatch(model.modelId, requested)) continue;+ // A known endpoint must not inherit another provider's capabilities.+ if (preferredProvider && provider !== preferredProvider) continue;+ if (!catalogModelIdsMatch(model.modelId, requested)) continue;let score = model.modelId.toLowerCase() === requested ? 20 : 10;if (provider === preferredProvider) score += 100;if (apiMatches(input.baseUrl, provider.api)) score += 80;diff --git a/apps/desktop/test/models-dev-catalog.test.mjs b/apps/desktop/test/models-dev-catalog.test.mjsindex ecc61e657..8041e41cf 100644--- a/apps/desktop/test/models-dev-catalog.test.mjs+++ b/apps/desktop/test/models-dev-catalog.test.mjs@@ -3,7 +3,7 @@ import { mkdtemp, readFile, rm, writeFile } from "node:fs/promises";import { tmpdir } from "node:os";import { join } from "node:path";import test from "node:test";-import { apiStyleForAdapter, modelIdsMatch } from "@pi-desktop/shared";+import { apiStyleForAdapter, catalogModelIdsMatch, modelIdsMatch } from "@pi-desktop/shared";import {MODELS_DEV_API_URL,@@ -158,6 +158,37 @@ test("cached matches remain scoped to the requested provider and endpoint", asyn}});+test("a known endpoint cannot borrow another provider's catalog model", async (t) => {+ const catalog = await loadFixtureCatalog(t, {+ alpha: { api: "https://alpha.example/v1", models: { "alpha-only": { id: "alpha-only" } } },+ beta: { api: "https://beta.example/v1", models: { "proxy/shared-model": { id: "proxy/shared-model", reasoning: true } } },+ });+ assert.equal(catalog.findModel({ baseUrl: "https://alpha.example/v1", modelId: "shared-model" }), undefined);+ assert.equal(catalog.findModel({ baseUrl: "https://beta.example/v1", modelId: "shared-model" })?.providerKey, "beta");+});++test("a shared catalog API prefers the explicitly selected vendor", async (t) => {+ const catalog = await loadFixtureCatalog(t, {+ alpha: { api: "https://gateway.example/v1", models: { "alpha-only": { id: "alpha-only" } } },+ beta: { api: "https://gateway.example/v1", models: { "beta-only": { id: "beta-only" } } },+ });+ const input = { vendorKey: "beta", baseUrl: "https://gateway.example/v1" };+ assert.equal(catalog.findModel({ ...input, modelId: "beta-only" })?.providerKey, "beta");+ assert.equal(catalog.findModel({ ...input, modelId: "alpha-only" }), undefined);+});++test("a recognized endpoint takes priority over an unrelated vendor fallback", async (t) => {+ const catalog = await loadFixtureCatalog(t, {+ openai: { models: { "shared-model": { id: "shared-model" } } },+ deepseek: { models: { "shared-model": { id: "shared-model" } } },+ });+ assert.equal(catalog.findModel({+ vendorKey: "openai",+ baseUrl: "https://api.deepseek.com",+ modelId: "shared-model",+ })?.providerKey, "deepseek");+});+test("model lookup memory is bounded by the catalog, not by query count", async (t) => {const catalog = await loadFixtureCatalog(t);const input = { vendorKey: "anthropic", modelId: "claude-opus-4.6" };@@ -207,82 +238,120 @@ test("model IDs match provider namespaces without matching model variants", () =assert.equal(modelIdsMatch("anthropic/claude-opus-5", "claude-opus-5"), true);assert.equal(modelIdsMatch("claude-opus-5@default", "claude-opus-5"), true);assert.equal(modelIdsMatch("claude-opus-5-fast", "claude-opus-5"), false);+ for (const suffix of ["agent", "latest", "thinking", "think"]) {+ assert.equal(modelIdsMatch("foo", `foo-${suffix}`), false);+ assert.equal(modelIdsMatch(`foo-${suffix}`, "foo"), false);+ }+ assert.equal(modelIdsMatch("gateway-a/foo", "gateway-b/foo"), false);+ assert.equal(modelIdsMatch("foo@us-east", "foo@eu-west"), false);+ assert.equal(modelIdsMatch("proxy/openai/gpt-4o", "openai/gpt-4o"), true);+ assert.equal(modelIdsMatch("openai/gpt-4o", "proxy/gpt-4o"), false);+});+test("catalog metadata IDs match exact proxy paths and supported variants", () => {+ for (const [catalogId, request] of [+ ["claude-opus-4.6", "proxy/claude-opus-4.6"],+ ["claude-opus-4.6", "custom/claude-opus-4.6"],+ ["claude-opus-4.6", "relay/claude-opus-4.6"],+ ["claude-opus-4.6", "gateway-01/claude-opus-4.6"],+ ["openai/gpt-4o", "hub/openai/gpt-4o"],+ ["claude-opus-4.6", "proxy/claude-opus-4.6-thinking"],+ ["claude-opus-4.6", "claude-opus-4.6:thinking"],+ ["claude-opus-4.6", "proxy/claude-opus-4.6-agent"],+ ["claude-opus-4.6", "proxy/claude-opus-4.6-latest"],+ ["claude-opus-4.6", "proxy/claude-opus-4.6-agent-thinking"],+ ["proxy/nested/claude-opus-4.6@us-east", "claude-opus-4.6-thinking"],+ ["anthropic-claude-opus-4.6", "claude-opus-4.6@us-east"],+ ["google/gemini-pro-latest", "gemini-pro"],+ ]) {+ assert.equal(catalogModelIdsMatch(catalogId, request), true, `${catalogId} / ${request}`);+ assert.equal(catalogModelIdsMatch(request, catalogId), true, `${request} / ${catalogId}`);+ }++ for (const [catalogId, request] of [+ ["google/gemini-2.5-flash", "openai/gemini-2.5-flash"],+ ["claude-opus-4.6", "myproxy-claude-opus-4.6"],+ ["claude-opus-4.6", "myproxy-claude-opus-4.6-thinking"],+ ["google/gemini-2.5-flash", "gemini-2.5-flash-high"],+ ["google/gemini-2.5-flash", "gemini-2.5-flash-low"],+ ["google/gemini-2.5-flash", "gemini-2.5-flash:minimal"],+ ["claude-opus-5", "claude-opus-5-fast"],+ ["gpt-4o", "gpt-4o-mini"],+ ["gpt-4", "gpt-4o"],+ ["model", "other-model"],+ ["custom", "gemini-3.1-pro-preview-customtools"],+ ["groq/whisper-large-v3", "deepseek-v3"],+ ["vercel/bfl/flux-kontext-max", "qwen-max"],+ ["alibaba/qwen3-asr-flash", "qwen-flash"],+ ["openai/gpt-4o", "proxy/gpt-4o"],+ ["google/gemini-2.5-flash", "proxy/gemini-2.5-flash"],+ ["proxy/nested/claude-opus-4.6", "other/claude-opus-4.6"],+ ["claude-opus-4-6-max", "qwen-max"],+ ]) {+ assert.equal(catalogModelIdsMatch(catalogId, request), false, `${catalogId} / ${request}`);+ assert.equal(catalogModelIdsMatch(request, catalogId), false, `${request} / ${catalogId}`);+ }+ assert.equal(catalogModelIdsMatch("gateway-a/foo", "gateway-b/foo"), false);+ assert.equal(catalogModelIdsMatch("foo", "foo-think"), true);+ assert.equal(catalogModelIdsMatch("foo", "foo-agent"), true);+ assert.equal(catalogModelIdsMatch("foo", "foo-latest"), true);});-test("model IDs match proxy routing prefixes, reasoning effort suffixes, and endpoint aliases", () => {- // Proxy routing path prefixes- assert.equal(modelIdsMatch("claude-opus-4.6", "proxy/claude-opus-4.6"), true);- assert.equal(modelIdsMatch("claude-opus-4.6", "custom/claude-opus-4.6"), true);- assert.equal(modelIdsMatch("claude-opus-4.6", "relay/claude-opus-4.6"), true);- assert.equal(modelIdsMatch("claude-opus-4.6", "gateway-01/claude-opus-4.6"), true);- assert.equal(modelIdsMatch("openai/gpt-4o", "hub/openai/gpt-4o"), true);- assert.equal(modelIdsMatch("openai/gpt-4o", "proxy/gpt-4o"), true);-- // Proxy dash prefixes- assert.equal(modelIdsMatch("claude-opus-4.6", "myproxy-claude-opus-4.6"), true);-- // Cross-namespace matching when one side has custom proxy routing- assert.equal(modelIdsMatch("google/gemini-2.5-flash", "proxy/gemini-2.5-flash"), true);-- // Conflicting known vendors must not match- assert.equal(modelIdsMatch("google/gemini-2.5-flash", "openai/gemini-2.5-flash"), false);-- // Reasoning effort / thinking suffixes- assert.equal(modelIdsMatch("claude-opus-4.6", "proxy/claude-opus-4.6-thinking"), true);- assert.equal(modelIdsMatch("claude-opus-4.6", "myproxy-claude-opus-4.6-thinking"), true);- assert.equal(modelIdsMatch("claude-opus-4.6", "claude-opus-4.6:thinking"), true);- assert.equal(modelIdsMatch("google/gemini-2.5-flash", "gemini-2.5-flash-high"), true);- assert.equal(modelIdsMatch("google/gemini-2.5-flash", "gemini-2.5-flash-low"), true);- assert.equal(modelIdsMatch("google/gemini-2.5-flash", "gemini-2.5-flash:minimal"), true);-- // Endpoint and release variant suffixes (-agent, -latest)- assert.equal(modelIdsMatch("claude-opus-4.6", "proxy/claude-opus-4.6-agent"), true);- assert.equal(modelIdsMatch("claude-opus-4.6", "proxy/claude-opus-4.6-latest"), true);- assert.equal(modelIdsMatch("google/gemini-pro-latest", "proxy/gemini-pro-agent"), true);- assert.equal(modelIdsMatch("google/gemini-pro-latest", "gemini-pro"), true);- assert.equal(modelIdsMatch("claude-opus-4.6", "proxy/claude-opus-4.6-agent-thinking"), true);-- // Legitimate model speed/size tiers must NOT be stripped as thinking or endpoint suffixes- assert.equal(modelIdsMatch("claude-opus-5", "claude-opus-5-fast"), false);- assert.equal(modelIdsMatch("gpt-4o", "gpt-4o-mini"), false);- assert.equal(modelIdsMatch("gpt-4", "gpt-4o"), false);++test("catalog lookup indexes exact path leaves and known vendor variants without broad aliases", async (t) => {+ const ids = [+ "model", "custom", "groq/whisper-large-v3", "vercel/bfl/flux-kontext-max",+ "alibaba/qwen3-asr-flash", "proxy/nested/claude-opus-4.6@us-east",+ "anthropic-claude-sonnet-4", "openai.gpt-4o", "google/gemini-2.5-flash",+ ];+ const catalog = await loadFixtureCatalog(t, {+ gateway: { models: Object.fromEntries(ids.map((id) => [id, { id }])) },+ });+ for (const [request, expected] of [+ ["other-model", undefined],+ ["gemini-3.1-pro-preview-customtools", undefined],+ ["deepseek-v3", undefined],+ ["qwen-max", undefined],+ ["qwen-flash", undefined],+ ["myproxy-claude-opus-4.6", undefined],+ ["gemini-2.5-flash-high", undefined],+ ["gemini-2.5-flash-low", undefined],+ ["claude-opus-4.6-thinking", "proxy/nested/claude-opus-4.6@us-east"],+ ["proxy/claude-opus-4.6-thinking", undefined],+ ["claude-sonnet-4-agent", "anthropic-claude-sonnet-4"],+ ["proxy/gemini-2.5-flash", undefined],+ ["gpt-4o@eu", "openai.gpt-4o"],+ ]) {+ assert.equal(catalog.findModel({ vendorKey: "custom", modelId: request })?.modelId, expected, request);+ }+ assert.equal(catalog.findModel({ vendorKey: "custom", modelId: "openai/gemini-2.5-flash" }), undefined);});-test("matches custom proxy model IDs and reasoning variants in catalog lookup", async (t) => {+test("matches supported proxy path and reasoning variants in catalog lookup", async (t) => {const catalog = await loadFixtureCatalog(t);+ for (const modelId of [+ "proxy/claude-opus-4.6", "proxy/claude-opus-4.6-thinking",+ "proxy/claude-opus-4.6-agent", "claude-opus-4.6:thinking",+ "anthropic-claude-opus-4.6",+ ]) {+ const match = catalog.findModel({ vendorKey: "custom", modelId });+ assert.equal(match?.modelId, "claude-opus-4.6", modelId);+ assert.equal(match.reasoning, true);+ }+ for (const modelId of ["myproxy-claude-opus-4.6", "myproxy-claude-opus-4.6-thinking"]) {+ assert.equal(catalog.findModel({ vendorKey: "custom", modelId }), undefined);+ }+});- // Proxy routing path prefix- const pathMatch = catalog.findModel({ vendorKey: "custom", modelId: "proxy/claude-opus-4.6" });- assert.ok(pathMatch);- assert.equal(pathMatch?.modelId, "claude-opus-4.6");- assert.equal(pathMatch?.reasoning, true);- assert.deepEqual(pathMatch?.reasoningOptions?.[0]?.values, ["low", "medium", "high", "xhigh", "max"]);-- // Proxy routing path prefix with thinking suffix- const pathThinkingMatch = catalog.findModel({ vendorKey: "custom", modelId: "proxy/claude-opus-4.6-thinking" });- assert.ok(pathThinkingMatch);- assert.equal(pathThinkingMatch?.modelId, "claude-opus-4.6");- assert.equal(pathThinkingMatch?.reasoning, true);-- // Proxy routing path prefix with endpoint suffix (-agent)- const pathAgentMatch = catalog.findModel({ vendorKey: "custom", modelId: "proxy/claude-opus-4.6-agent" });- assert.ok(pathAgentMatch);- assert.equal(pathAgentMatch?.modelId, "claude-opus-4.6");- assert.equal(pathAgentMatch?.reasoning, true);-- // Proxy dash prefix- const dashMatch = catalog.findModel({ vendorKey: "custom", modelId: "myproxy-claude-opus-4.6" });- assert.ok(dashMatch);- assert.equal(dashMatch?.modelId, "claude-opus-4.6");-- // Proxy dash prefix with thinking suffix- const dashThinkingMatch = catalog.findModel({ vendorKey: "custom", modelId: "myproxy-claude-opus-4.6-thinking" });- assert.ok(dashThinkingMatch);- assert.equal(dashThinkingMatch?.modelId, "claude-opus-4.6");-- // Colon thinking suffix- const colonMatch = catalog.findModel({ vendorKey: "custom", modelId: "claude-opus-4.6:thinking" });- assert.ok(colonMatch);- assert.equal(colonMatch?.modelId, "claude-opus-4.6");+test("metadata lookup can share routed leaves and narrow suffix aliases without merging bindings", async (t) => {+ const catalog = await loadFixtureCatalog(t, {+ gateway: { models: {+ "gateway-a/foo": { id: "gateway-a/foo" },+ "bar-agent": { id: "bar-agent" },+ } },+ });+ assert.equal(modelIdsMatch("gateway-a/foo", "gateway-b/foo"), false);+ assert.equal(modelIdsMatch("bar", "bar-agent"), false);+ assert.equal(catalog.findModel({ modelId: "gateway-b/foo" }), undefined);+ assert.equal(catalog.findModel({ modelId: "bar-thinking" })?.modelId, "bar-agent");});test("models.dev records retain all published model parameters and modalities", () => {diff --git a/docs/spec/03-runtime/13-model-catalog-and-selection.md b/docs/spec/03-runtime/13-model-catalog-and-selection.mdindex f0d9a7b60..afceb37ae 100644--- a/docs/spec/03-runtime/13-model-catalog-and-selection.md+++ b/docs/spec/03-runtime/13-model-catalog-and-selection.md@@ -235,10 +235,10 @@ current process's in-memory models.dev catalog and never writes user data.Repeated metadata lookups use a bounded process-local cache keyed by theconfigured vendor key, base URL, and case-insensitive, trimmed model ID. Both-matches and misses are cached; the original provider preference, alias-matching, and candidate ranking remain unchanged. Replacing the catalog after-a successful bundled load or Settings refresh invalidates the cache. A failed-refresh preserves the previous catalog and its results. Session capability+matches and misses are cached; provider/API preference and candidate ranking+still apply. Replacing the catalog after a successful bundled load or Settings+refresh invalidates the cache. A failed refresh preserves the previous catalog+and its results. Session capabilityenrichment resolves a matching catalog record once per session and then appliesthe current provider/model binding and session defaults, so user overrides arenever retained as stale cached capabilities. Refreshing a large session list@@ -414,10 +414,9 @@ Warnings are non-blocking unless execution is impossible.### 11.1 Reasoning capability resolution-1. Resolve the models.dev metadata for the matching provider/API URL and exact- `modelId`. Matching also accepts a catalog vendor prefix when the configured- provider uses an unprefixed ID (for example `deepseek-v4` matches- `deepseek/deepseek-v4` only under the matching provider identity).+1. Resolve models.dev metadata under the matching provider/API URL using the+ metadata-only ID lookup described in §11.3. This lookup does not change+ configured model binding identity.2. The models.dev record is authoritative for published `reasoning` and`reasoning_options`; cached/provider capability claims cannot replace it.3. The provider's exact `ModelBinding.thinkingLevels` is authoritative for the@@ -469,6 +468,25 @@ manual token entry. The enrichment lookup is:3. The lookup does not send API keys to models.dev. Runtime model resolutionuses the same models.dev record and the selected pi-ai transport adapter.+Catalog enrichment uses `catalogModelIdsMatch`, not the shared+`modelIdsMatch` used to resolve an exact configured binding. Binding identity+accepts case-insensitive exact IDs, full slash-path suffixes, known vendor+`-`/`.` prefixes and a one-sided `@region` alias; it does not collapse two+different regions, arbitrary routing prefixes or endpoint/thinking suffixes.+Metadata lookup additionally accepts a complete bare leaf ID through a generic+route such as `proxy/` or `custom/`, subject to known-vendor conflicts; two+different full route paths never match solely because they share a leaf. It+narrowly strips trailing `-` or `:` `thinking`, `think`, `agent` or `latest`+tokens (including before `@region`). It does not strip arbitrary+dash-separated proxy prefixes or effort tokens such as `low`, `high` or `max`.+The catalog index uses bounded candidate keys for these aliases, then checks+the matcher; a known catalog provider selected by vendor key or API URL limits+the lookup to that provider, never borrowing another provider's capabilities.+These aliases attach published metadata only: they do not alter the configured+wire model ID or prove that a suffix enables reasoning. An unmatched free-form+ID remains an unknown generic model with no inferred capabilities; only a+published record or explicit binding settings can supply them.+## 12. Refresh strategy- manual refresh button in settings/model pickerdiff --git a/docs/spec/08-meta/decisions-log.md b/docs/spec/08-meta/decisions-log.mdindex 9195185c8..cfbcc32ca 100644--- a/docs/spec/08-meta/decisions-log.md+++ b/docs/spec/08-meta/decisions-log.md@@ -6988,3 +6988,21 @@ must keep splitting are covered by `markdown-blocks.test.mjs`.(a query parameter, a SigV4 signature). A key that is still not Latin-1 keepsfailing at request time; refusing it would block a save this writer cannotjudge.++## 2026-09-22 — Catalog aliases enrich metadata without changing model identity (D622)++- Keep `modelIdsMatch` strict for configured bindings: exact IDs, full path+ suffixes, known vendor `-`/`.` prefixes and one-sided `@region` aliases;+ distinct regions, arbitrary proxy prefixes and thinking/endpoint suffixes do+ not merge bindings. PR #870 was closed because the frozen spec promised only+ exact IDs/vendor prefixes, without a recorded decision to widen lookup.+- For models.dev metadata only, `catalogModelIdsMatch` also accepts a complete+ bare leaf through a full route (e.g. `proxy/` or `custom/`) without known-vendor+ conflict; two distinct full routes do not match solely by leaf. It also strips+ trailing `thinking`/`think`/`agent`/`latest` tokens separated by `-` or `:`.+ No arbitrary dash proxy prefix or effort `low`/`high`/`max` stripping.+ Indexed candidate keys still require a matcher hit; a known provider/API+ scopes matches to its own catalog. No suffix alone grants reasoning:+ unmatched free-form IDs stay generic unknown, while published capabilities+ and explicit binding overrides retain their existing precedence. See+ `03-runtime/13-model-catalog-and-selection.md` §11.3.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 1e204f516..5aaaabfda 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@@ -272,6 +272,23 @@ type ModelCatalogItem = {6. 更改为非推理提供商仍然存在 `off`;没有不支持的级别泄漏到下一个请求中。+### 11.2 目录元数据的模型 ID 匹配++目录补全使用 `catalogModelIdsMatch`,不使用解析已配置绑定身份的共享+`modelIdsMatch`。绑定身份接受不区分大小写的完整 ID、完整斜杠路径后缀、+已知厂商的 `-`/`.` 前缀,以及仅有一侧带 `@region` 的别名;两个不同地区、+任意路由前缀或思考/端点后缀不会合并为同一绑定。+元数据查询还可以匹配 `proxy/` 或 `custom/` 等通用路由下的完整裸叶子 ID,+但必须避免已知厂商冲突;两个不同的完整路由路径不会仅因叶子相同而匹配。+它只会剥离末尾以 `-` 或 `:` 分隔的 `thinking`、+`think`、`agent`、`latest`(也可在 `@region` 之前),不会剥离任意短横线代理+前缀或 `low`、`high`、`max` 等 effort 后缀。目录索引用这些别名生成有界+候选键,再由匹配器确认;若厂商键或 API URL 已选中已知目录提供商,+查询仅限该提供商,不能借用别家能力。+这些别名只用于附加已发布的元数据,不改变配置的请求模型 ID,后缀本身也+不证明模型有推理能力。未命中的自由格式 ID 仍是无推断能力的未知通用模型;+只有已发布的记录或显式绑定设置可提供能力。+## 12. 刷新策略- settings/model 选择器中的手动刷新按钮diff --git a/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md b/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.mdindex bb10fca3e..0bc53f0a0 100644--- a/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md+++ b/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md@@ -5282,6 +5282,7 @@ eleven-tool-round desktop paths are verified by| C / G / Quality — Plugins navigation | E2E-NAV-plugins-button-goes-back || C / D / Quality — 侧边栏行状态 | E2E-LAYOUT-sidebar-row-states || A / C / Quality — 侧栏材质与设置返回 | E2E-LAYOUT-sidebar-settings |+| A / H / Quality — 渲染进程崩溃恢复 | E2E-RUNTIME-renderer-crash-recovery || B / F / Security — 提供商复制 | E2E-PROVIDER-copy-config-without-credentials || B / F / Quality — 已选模型顺序 | E2E-MODEL-selected-order-persists || A — 应用程序启动 | E2E-001、E2E-002、E2E-003、E2E-004、E2E-067、E2E-076、E2E-079、E2E-092、E2E-097、E2E-143、E2E-150、E2E-168、E2E-204、E2E-217 |diff --git a/docs/zh-CN/spec/08-meta/decisions-log.md b/docs/zh-CN/spec/08-meta/decisions-log.mdindex 3217901b1..f15a537ac 100644--- a/docs/zh-CN/spec/08-meta/decisions-log.md+++ b/docs/zh-CN/spec/08-meta/decisions-log.md@@ -4943,3 +4943,18 @@ Markdown 源码,不是 `text/html` 负载;对禁用行内 HTML 的外部编得知结果。一份规则、两处实现:`packages/shared/src/header-value.ts` 与`crates/host-core/src/providers/validation.rs`。参见`03-runtime/12-provider-config-schema.md`、ADR 0178、E2E-005G。++## 2026-09-22 —— 目录别名只补全元数据,不更改模型身份(D622)++- 已配置绑定继续使用严格的 `modelIdsMatch`:完整 ID、完整路径后缀、已知厂商的+ `-`/`.` 前缀和仅单侧带 `@region` 的别名;不同地区、任意代理前缀及思考/端点+ 后缀都不合并绑定。PR #870 因冻结规格仅承诺精确 ID 和厂商前缀、且无决策记录+ 支持扩大匹配范围而关闭。+- 仅 models.dev 元数据使用 `catalogModelIdsMatch`:还可匹配无已知厂商冲突的+ 裸叶子 ID 与 `proxy/` 或 `custom/` 等完整路由路径,但不同完整路径不会仅凭+ 相同叶子互认;另可剥离由 `-` 或 `:` 分隔的末尾+ `thinking`/`think`/`agent`/`latest`。不剥离任意短横线代理前缀或+ `low`/`high`/`max` effort 后缀。索引候选键仍须经匹配器核实;已知厂商/API+ 只查自身目录。后缀本身不赋予推理能力:未命中的自由格式 ID 仍是未知通用+ 模型,已发布能力和显式绑定覆盖沿用既有优先级。见+ `03-runtime/13-model-catalog-and-selection.md` §11.2。diff --git a/packages/shared/src/types/models.ts b/packages/shared/src/types/models.tsindex 863412fce..d3942f34b 100644--- a/packages/shared/src/types/models.ts+++ b/packages/shared/src/types/models.ts@@ -47,7 +47,7 @@ export const MODEL_VENDOR_PREFIXES = new Set(["zhipuai",]);-const THINKING_SUFFIX_REGEX = /[-:](?:thinking|think|minimal|low|high|xhigh|max)$/i;+const THINKING_SUFFIX_REGEX = /[-:](?:thinking|think)$/i;const ENDPOINT_SUFFIX_REGEX = /[-:](?:agent|latest)$/i;function stripRegion(value: string): string {@@ -99,143 +99,73 @@ function extractKnownVendor(id: string): string | undefined {const parts = id.split("/");for (let i = 0; i < parts.length - 1; i++) {const part = parts[i];- if (MODEL_VENDOR_PREFIXES.has(part)) {- return canonicalVendor(part);- }+ if (MODEL_VENDOR_PREFIXES.has(part)) return canonicalVendor(part);}+const lastPart = parts[parts.length - 1];- for (const separator of ["-", "."] as const) {- const prefix = lastPart.split(separator)[0];- if (MODEL_VENDOR_PREFIXES.has(prefix)) {+ for (const prefix of MODEL_VENDOR_PREFIXES) {+ if (lastPart === prefix || lastPart.startsWith(`${prefix}-`) || lastPart.startsWith(`${prefix}.`)) {return canonicalVendor(prefix);}}return undefined;}-function stripVendorPrefix(id: string): string {- for (const separator of ["-", "."] as const) {- for (const prefix of MODEL_VENDOR_PREFIXES) {- const head = `${prefix}${separator}`;- if (id.startsWith(head) && id.length > head.length) {- return id.slice(head.length);- }- }- }- return id;+function pathLeaf(id: string): string {+ const slash = id.lastIndexOf("/");+ return slash >= 0 ? id.slice(slash + 1) : id;}-const KNOWN_TIER_SUFFIXES = new Set([- "fast",- "mini",- "nano",- "small",- "medium",- "large",- "turbo",- "instruct",-]);-export function isProxyPrefix(prefix: string, model: string): boolean {- if (!prefix || prefix.includes("/")) return false;- if (KNOWN_TIER_SUFFIXES.has(model)) return false;- const prefixVendor = extractKnownVendor(prefix);- const modelVendor = extractKnownVendor(model);- if (prefixVendor && modelVendor && prefixVendor !== modelVendor) return false;- return true;-}+function exactPathAliasMatch(left: string, right: string): boolean {+ // Two independently routed paths cannot be identified by their leaf alone.+ if (left.includes("/") === right.includes("/")) return false;+ if (pathLeaf(left) !== pathLeaf(right)) return false;+ const leftVendor = extractKnownVendor(left);+ const rightVendor = extractKnownVendor(right);+ return !leftVendor || !rightVendor || leftVendor === rightVendor;+}-function normalizedMatch(left: string, right: string): boolean {+function normalizedMatch(left: string, right: string, allowPathLeaf = false): boolean {+ const leftVendor = extractKnownVendor(left);+ const rightVendor = extractKnownVendor(right);+ if (leftVendor && rightVendor && leftVendor !== rightVendor) return false;if (left === right) return true;if (left.endsWith(`/${right}`) || right.endsWith(`/${left}`)) return true;- // Some providers use `model@region` aliases; the base model remains the- // same published record for matching purposes.- if (left.startsWith(`${right}@`) || right.startsWith(`${left}@`)) return true;- for (const separator of ["-", "."] as const) {- const leftPrefix = left.split(`${separator}${right}`, 1)[0];- if (- left.startsWith(`${leftPrefix}${separator}${right}`) &&- (MODEL_VENDOR_PREFIXES.has(leftPrefix) || isProxyPrefix(leftPrefix, right))- ) {- return true;- }- const rightPrefix = right.split(`${separator}${left}`, 1)[0];- if (- right.startsWith(`${rightPrefix}${separator}${left}`) &&- (MODEL_VENDOR_PREFIXES.has(rightPrefix) || isProxyPrefix(rightPrefix, left))- ) {- return true;- }- }- // Cross-namespace matching for custom proxy paths:- // e.g. `google/gemini-2.5-flash` vs `proxy/gemini-2.5-flash`- const bareLeft = stripVendorPrefix(left.includes("/") ? left.slice(left.lastIndexOf("/") + 1) : left);- const bareRight = stripVendorPrefix(right.includes("/") ? right.slice(right.lastIndexOf("/") + 1) : right);-- if (bareLeft && bareRight) {- if (bareLeft === bareRight) {- const leftVendor = extractKnownVendor(left);- const rightVendor = extractKnownVendor(right);- if (leftVendor && rightVendor && leftVendor !== rightVendor) {- return false;- }- return true;- }-- for (const separator of ["-", "."] as const) {- const leftPrefix = bareLeft.split(`${separator}${bareRight}`, 1)[0];- if (- bareLeft.startsWith(`${leftPrefix}${separator}${bareRight}`) &&- (MODEL_VENDOR_PREFIXES.has(leftPrefix) || isProxyPrefix(leftPrefix, bareRight))- ) {- const leftVendor = extractKnownVendor(left);- const rightVendor = extractKnownVendor(right);- if (leftVendor && rightVendor && leftVendor !== rightVendor) return false;- return true;- }- const rightPrefix = bareRight.split(`${separator}${bareLeft}`, 1)[0];- if (- bareRight.startsWith(`${rightPrefix}${separator}${bareLeft}`) &&- (MODEL_VENDOR_PREFIXES.has(rightPrefix) || isProxyPrefix(rightPrefix, bareLeft))- ) {- const leftVendor = extractKnownVendor(left);- const rightVendor = extractKnownVendor(right);- if (leftVendor && rightVendor && leftVendor !== rightVendor) return false;- return true;- }+ for (const separator of ["-", "."] as const) {+ for (const prefix of MODEL_VENDOR_PREFIXES) {+ if (left === `${prefix}${separator}${right}`) return true;+ if (right === `${prefix}${separator}${left}`) return true;}}- return false;+ return allowPathLeaf && exactPathAliasMatch(left, right);}-/** Match a configured model ID with a namespaced models.dev ID. */+/** Compare configured binding IDs without collapsing distinct route paths or variants. */export function modelIdsMatch(candidate: string, requested: string): boolean {const left = candidate.trim().toLowerCase();const right = requested.trim().toLowerCase();if (!left || !right) return false;+ if (left.includes("@") && right.includes("@") && left !== right) return false;+ return normalizedMatch(stripRegion(left), stripRegion(right));+}++/** Broader metadata-only aliases; never use for configured binding identity. */+export function catalogModelIdsMatch(candidate: string, requested: string): boolean {+ const left = candidate.trim().toLowerCase();+ const right = requested.trim().toLowerCase();+ if (!left || !right) return false;const cleanLeft = stripRegion(left);const cleanRight = stripRegion(right);+ if (normalizedMatch(cleanLeft, cleanRight, true)) return true;- if (normalizedMatch(cleanLeft, cleanRight)) return true;-- // Suffixes indicating thinking mode or reasoning effort (e.g. -thinking, -high, -low)- const deThunkLeft = stripThinkingSuffix(cleanLeft);- const deThunkRight = stripThinkingSuffix(cleanRight);- if (deThunkLeft !== cleanLeft || deThunkRight !== cleanRight) {- if (normalizedMatch(deThunkLeft, deThunkRight)) return true;- }-- // Suffixes indicating deployment variants or endpoints (e.g. -agent, -latest)const strippedLeft = stripVariantSuffix(cleanLeft);const strippedRight = stripVariantSuffix(cleanRight);- if (strippedLeft !== deThunkLeft || strippedRight !== deThunkRight) {- if (normalizedMatch(strippedLeft, strippedRight)) return true;- }-- return false;+ if (strippedLeft === cleanLeft && strippedRight === cleanRight) return false;+ return normalizedMatch(strippedLeft, strippedRight, true);}/**