Skip to content

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

fix(catalog): resolve proxy-prefixed model ids and thinking suffixes

aurorax-neoaea9b913f63b
diff --git a/apps/desktop/electron/main/models-dev-catalog.ts b/apps/desktop/electron/main/models-dev-catalog.ts
index 99e9116a1..c48f21c6f 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 { modelIdsMatch } from "@pi-desktop/shared";
+import { MODEL_VENDOR_PREFIXES, isProxyPrefix, modelIdsMatch, stripThinkingSuffix, stripVariantSuffix } from "@pi-desktop/shared";
import type {
ModelCost,
ModelCostTier,
@@ -501,28 +501,6 @@ function normalizedModelId(value: string): string {
return value.trim().toLowerCase();
}
-const MODEL_VENDOR_PREFIXES = new Set([
- "anthropic",
- "amazon",
- "aws",
- "cohere",
- "deepseek",
- "deepseek-ai",
- "gemini",
- "google",
- "meta",
- "minimax",
- "mistral",
- "moonshot",
- "moonshotai",
- "openai",
- "qwen",
- "z-ai",
- "zai",
- "zhipuai",
- "x-ai",
- "xai",
-]);
function modelVendorPrefixes(model: ModelsDevModel): string[] {
const prefixes = new Set<string>();
@@ -813,30 +791,121 @@ class ModelsDevLookupIndex {
}
candidates(requested: string): readonly IndexedModel[] {
- return this.byModelId.get(requested) ?? EMPTY_CANDIDATES;
+ const keys = lookupCandidateKeys(requested);
+ if (keys.length === 0) return EMPTY_CANDIDATES;
+ if (keys.length === 1) {
+ return this.byModelId.get(keys[0]) ?? EMPTY_CANDIDATES;
+ }
+ const result: IndexedModel[] = [];
+ const seen = new Set<IndexedModel>();
+ for (const key of keys) {
+ const bucket = this.byModelId.get(key);
+ if (!bucket) continue;
+ for (const entry of bucket) {
+ if (!seen.has(entry)) {
+ seen.add(entry);
+ result.push(entry);
+ }
+ }
+ }
+ return result;
}
}
-/** The normalized id, the `@region`-less 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. */
+/** 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[] {
const keys = new Set<string>();
const raw = modelId.trim();
- keys.add(normalizedModelId(raw));
- const at = raw.indexOf("@");
- if (at > 0) keys.add(normalizedModelId(raw.slice(0, at)));
+ const normalized = normalizedModelId(raw);
+ keys.add(normalized);
+
+ const at = normalized.indexOf("@");
+ if (at > 0) keys.add(normalized.slice(0, at));
+
+ 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 (raw.startsWith(head) && raw.length > head.length) {
- keys.add(normalizedModelId(raw.slice(head.length)));
+ 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);
}
}
}
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("/"));
+ }
+ }
+
+ 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);
+ }
+ }
+ }
+
+ return [...keys];
+}
+
const EMPTY_CANDIDATES: readonly IndexedModel[] = [];
diff --git a/apps/desktop/test/models-dev-catalog.test.mjs b/apps/desktop/test/models-dev-catalog.test.mjs
index 352b0806f..ecc61e657 100644
--- a/apps/desktop/test/models-dev-catalog.test.mjs
+++ b/apps/desktop/test/models-dev-catalog.test.mjs
@@ -208,6 +208,82 @@ test("model IDs match provider namespaces without matching model variants", () =
assert.equal(modelIdsMatch("claude-opus-5@default", "claude-opus-5"), true);
assert.equal(modelIdsMatch("claude-opus-5-fast", "claude-opus-5"), false);
});
+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("matches custom proxy model IDs and reasoning variants in catalog lookup", async (t) => {
+ const catalog = await loadFixtureCatalog(t);
+
+ // 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("models.dev records retain all published model parameters and modalities", () => {
const [provider] = parseModelsDevCatalog(catalogFixture);
diff --git a/packages/shared/src/types/models.ts b/packages/shared/src/types/models.ts
index c91f044e1..863412fce 100644
--- a/packages/shared/src/types/models.ts
+++ b/packages/shared/src/types/models.ts
@@ -21,34 +21,131 @@ export type SubagentThinkingLevel = SessionThinkingLevel;
export type ModelProviderMetadata = string | Record<string, unknown>;
export type ModelExperimentalMetadata = boolean | Record<string, unknown>;
-const MODEL_VENDOR_PREFIXES = new Set([
- "anthropic",
+export const MODEL_VENDOR_PREFIXES = new Set([
"amazon",
+ "anthropic",
"aws",
+ "azure",
"cohere",
"deepseek",
"deepseek-ai",
"gemini",
"google",
"meta",
+ "meta-llama",
"minimax",
"mistral",
"moonshot",
"moonshotai",
"openai",
"qwen",
+ "tencent",
+ "x-ai",
+ "xai",
"z-ai",
"zai",
"zhipuai",
- "x-ai",
- "xai",
]);
-/** Match a configured model ID with a namespaced models.dev ID. */
-export function modelIdsMatch(candidate: string, requested: string): boolean {
- const left = candidate.trim().toLowerCase();
- const right = requested.trim().toLowerCase();
- if (!left || !right) return false;
+const THINKING_SUFFIX_REGEX = /[-:](?:thinking|think|minimal|low|high|xhigh|max)$/i;
+const ENDPOINT_SUFFIX_REGEX = /[-:](?:agent|latest)$/i;
+
+function stripRegion(value: string): string {
+ const at = value.indexOf("@");
+ return at > 0 ? value.slice(0, at) : value;
+}
+
+export function stripThinkingSuffix(value: string): string {
+ let current = value;
+ while (THINKING_SUFFIX_REGEX.test(current)) {
+ current = current.replace(THINKING_SUFFIX_REGEX, "");
+ }
+ return current;
+}
+
+export function stripEndpointSuffix(value: string): string {
+ let current = value;
+ while (ENDPOINT_SUFFIX_REGEX.test(current)) {
+ current = current.replace(ENDPOINT_SUFFIX_REGEX, "");
+ }
+ return current;
+}
+
+export function stripVariantSuffix(value: string): string {
+ let current = value;
+ let changed = true;
+ while (changed) {
+ const next = current
+ .replace(THINKING_SUFFIX_REGEX, "")
+ .replace(ENDPOINT_SUFFIX_REGEX, "");
+ changed = next !== current;
+ current = next;
+ }
+ return current;
+}
+
+function canonicalVendor(prefix: string): string {
+ if (prefix === "deepseek-ai") return "deepseek";
+ if (prefix === "gemini") return "google";
+ if (prefix === "x-ai") return "xai";
+ if (prefix === "z-ai" || prefix === "zhipuai") return "zai";
+ if (prefix === "moonshotai") return "moonshot";
+ if (prefix === "meta-llama") return "meta";
+ if (prefix === "aws") return "amazon";
+ return prefix;
+}
+
+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);
+ }
+ }
+ const lastPart = parts[parts.length - 1];
+ for (const separator of ["-", "."] as const) {
+ const prefix = lastPart.split(separator)[0];
+ if (MODEL_VENDOR_PREFIXES.has(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;
+}
+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 normalizedMatch(left: string, right: string): boolean {
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
@@ -58,18 +155,86 @@ export function modelIdsMatch(candidate: string, requested: string): boolean {
const leftPrefix = left.split(`${separator}${right}`, 1)[0];
if (
left.startsWith(`${leftPrefix}${separator}${right}`) &&
- MODEL_VENDOR_PREFIXES.has(leftPrefix)
+ (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)
+ (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;
+ }
+ }
+ }
+
+ return false;
+}
+
+/** Match a configured model ID with a namespaced models.dev ID. */
+export function modelIdsMatch(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)) 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;
}