Skip to content

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

fix(composer): display and match models by their complete wire ID

aurorax-neo614ac4bddfb9
diff --git a/apps/desktop/electron/main/models-dev-catalog.ts b/apps/desktop/electron/main/models-dev-catalog.ts
index 11ff33580..c457f5656 100644
--- a/apps/desktop/electron/main/models-dev-catalog.ts
+++ b/apps/desktop/electron/main/models-dev-catalog.ts
@@ -974,9 +974,11 @@ export class ModelsDevCatalog {
apiMatches(input.baseUrl, provider.api),
);
if (apiProviders.length > 0) {
+ // A shared API endpoint does not identify which publisher owns a custom
+ // model. Never pick the first provider simply because it was indexed first.
return apiProviders.find((provider) =>
candidates.has(normalizedProviderKey(provider.providerKey)),
- ) ?? apiProviders[0];
+ ) ?? (apiProviders.length === 1 ? apiProviders[0] : undefined);
}
const knownKey = Object.entries(KNOWN_PROVIDER_BASE_URLS).find(([, urls]) =>
urls.some((url) => apiMatches(input.baseUrl, url)),
@@ -1028,7 +1030,12 @@ export class ModelsDevCatalog {
candidates.sort((left, right) =>
right.score - left.score || left.model.modelId.length - right.model.modelId.length,
);
- const result = candidates[0]?.model;
+ // An unknown endpoint can use a unique catalog match (including supported
+ // proxy aliases), but scores are not proof of provider identity. If two
+ // providers publish the same ID, do not borrow either one's metadata.
+ const result = preferredProvider || candidates.length === 1
+ ? candidates[0]?.model
+ : undefined;
// 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, result);
diff --git a/apps/desktop/electron/main/runtime/provider-catalog.ts b/apps/desktop/electron/main/runtime/provider-catalog.ts
index e3d0eccd4..00b510f50 100644
--- a/apps/desktop/electron/main/runtime/provider-catalog.ts
+++ b/apps/desktop/electron/main/runtime/provider-catalog.ts
@@ -3,7 +3,6 @@ import {
SESSION_THINKING_LEVELS,
defaultCommandShellForPlatform,
isCommandShellId,
- modelIdsMatch,
resolveBindingContextWindow,
validateNetworkProxy,
validateSpeechSettings,
@@ -74,7 +73,9 @@ export function createProviderCatalogRuntime({
provider: Pick<RuntimeProvider, "models">,
modelId: string,
): ModelBinding | undefined =>
- provider.models?.find((binding) => modelIdsMatch(binding.id, modelId));
+ provider.models?.find((binding) =>
+ binding.id.trim().toLowerCase() === modelId.trim().toLowerCase(),
+ );
const modelsDevModelFor = (provider: RuntimeProvider, modelId: string) =>
modelsDevCatalog.findModel({
diff --git a/apps/desktop/src/components/Composer.tsx b/apps/desktop/src/components/Composer.tsx
index 68325433c..17f110aae 100644
--- a/apps/desktop/src/components/Composer.tsx
+++ b/apps/desktop/src/components/Composer.tsx
@@ -14,7 +14,6 @@ import {
initialThinkingLevelForBinding,
imageGenerationBindings,
isImageGenerationModel,
- modelIdsMatch,
normalizeLargePasteThreshold,
stripInlineComposerFileReferenceTokens,
} from "@pi-desktop/shared";
@@ -24,8 +23,7 @@ import { isActivePlanExecution } from "../lib/plan-mode-state";
import { headAsk, queuedAskCount } from "../lib/pending-asks";
import type { QueuedPrompt } from "../lib/queued-prompts";
import {
- composerModelDisplayName,
- composerModelsForProvider,
+ sameComposerModelId,
} from "../lib/composer-models";
import {
providerThinkingLevels,
@@ -340,8 +338,7 @@ export function Composer({
const modelId =
activeSession?.modelId ??
(!activeSession ? draftConfiguration?.modelId : undefined) ??
- settings?.defaultModelId ??
- provider?.defaultModelId;
+ (settings?.defaultModelId?.trim() || provider?.models?.[0]?.id || provider?.defaultModelId);
const selectedModelCatalog = provider ? providerModels[provider.id] : undefined;
const catalogThinkingProvider = thinkingProviderForModel(
provider,
@@ -355,7 +352,7 @@ export function Composer({
catalogThinkingProvider,
});
const selectedBinding = provider?.models.find((candidate) =>
- modelIdsMatch(candidate.id, modelId ?? ""),
+ sameComposerModelId(candidate.id, modelId ?? ""),
);
// A draft without a session starts at the selected model's stored default
// thinking level, clamped onto that binding's enabled ladder.
@@ -376,14 +373,7 @@ export function Composer({
configuredThinkingLevel,
);
const thinkingLabel = thinkingLevel;
- const selectedModel = provider?.id
- ? composerModelsForProvider(provider, providerModels[provider.id], imageGenerationCandidates).find(
- (model) => modelIdsMatch(model.modelId, modelId ?? ""),
- )
- : undefined;
- const modelLabel = provider && modelId
- ? composerModelDisplayName(provider, modelId, selectedModel?.displayName)
- : selectedModel?.displayName || modelId || t("chat.model");
+ const modelLabel = modelId || t("chat.model");
const modelMenu = useComposerModelMenu({
configureActiveSession,
mode,
diff --git a/apps/desktop/src/components/settings/EnhancementModelCard.tsx b/apps/desktop/src/components/settings/EnhancementModelCard.tsx
index f0c641e00..8e6f977a9 100644
--- a/apps/desktop/src/components/settings/EnhancementModelCard.tsx
+++ b/apps/desktop/src/components/settings/EnhancementModelCard.tsx
@@ -14,7 +14,6 @@ import { useTranslation } from "react-i18next";
import {
THINKING_LEVELS,
canonicalThinkingLevel,
- modelIdsMatch,
type AppSettings,
type ThinkingLevel,
} from "@pi-desktop/shared";
@@ -25,6 +24,7 @@ import {
import { useAppStore } from "../../stores/app-store";
import { api } from "../../lib/api";
import { providerDisplayName, providerSearchText } from "../../lib/provider-display";
+import { sameComposerModelId } from "../../lib/composer-models";
import { Button, Input, cx } from "../ui";
import { IconCheck, IconChevronDown, IconSearch } from "../icons";
import { AnchoredMenu } from "./AnchoredMenu";
@@ -255,7 +255,7 @@ export function EnhancementModelCard() {
{visible.map(({ provider, modelId }, index) => {
const isCurrent =
settings.promptEnhancementProviderId === provider.id &&
- modelIdsMatch(settings.promptEnhancementModelId ?? "", modelId);
+ sameComposerModelId(settings.promptEnhancementModelId ?? "", modelId);
const previous = visible[index - 1];
const startsGroup = !previous || previous.provider.id !== provider.id;
return (
diff --git a/apps/desktop/src/components/settings/ImageGenerationModelRow.tsx b/apps/desktop/src/components/settings/ImageGenerationModelRow.tsx
index 09f37b6e3..aa69391c2 100644
--- a/apps/desktop/src/components/settings/ImageGenerationModelRow.tsx
+++ b/apps/desktop/src/components/settings/ImageGenerationModelRow.tsx
@@ -1,11 +1,11 @@
import { useTranslation } from "react-i18next";
import {
imageGenerationBindings,
- modelIdsMatch,
type AppSettings,
type ImageGenerationBinding,
type ProviderPublic,
} from "@pi-desktop/shared";
+import { sameComposerModelId } from "../../lib/composer-models";
import { SettingsMenuSelect } from "./SettingsMenuSelect";
import { imageGenerationBindingAvailable } from "./image-generation-default";
@@ -37,7 +37,7 @@ export function ImageGenerationModelRow({
const activeCandidate = binding
? candidates.find((candidate) =>
candidate.providerId === binding.providerId &&
- modelIdsMatch(candidate.modelId, binding.modelId),
+ sameComposerModelId(candidate.modelId, binding.modelId),
)
: undefined;
const provider = binding
diff --git a/apps/desktop/src/components/settings/ModelConfigPage.tsx b/apps/desktop/src/components/settings/ModelConfigPage.tsx
index 3f9a015ac..04142c749 100644
--- a/apps/desktop/src/components/settings/ModelConfigPage.tsx
+++ b/apps/desktop/src/components/settings/ModelConfigPage.tsx
@@ -11,9 +11,6 @@ import { useEffect, useMemo, useRef, useState } from "react";
import { useTranslation } from "react-i18next";
import {
OAUTH_AUTH_KIND,
- imageGenerationBindings,
- isImageGenerationModel,
- modelIdsMatch,
type ImageGenerationBinding,
type ModelBinding,
type ProviderPublic,
@@ -36,12 +33,7 @@ import {
IconTrash,
} from "../icons";
import { AnchoredMenu } from "./AnchoredMenu";
-import {
- defaultModelOptions,
- displayedDefaultModelId,
- keepsAppDefaultModel,
- providerServesChatModels,
-} from "./default-model";
+import { providerServesChatModels } from "./default-model";
import { planImageGenerationDefaults } from "./image-generation-default";
import { copyProviderConfiguration, type ProviderCopyDraft } from "./provider-copy";
import { ImageGenerationModelRow } from "./ImageGenerationModelRow";
@@ -71,6 +63,51 @@ function hostFromBaseUrl(baseUrl?: string | null): string {
}
}
+const sameWireId = (left: string, right: string) => left.toLowerCase() === right.toLowerCase();
+
+/** Image candidates and chat choices are keyed by complete provider + wire id. */
+function imageCandidates(
+ candidates: readonly ImageGenerationBinding[] | null | undefined,
+ active: ImageGenerationBinding | null | undefined,
+): ImageGenerationBinding[] {
+ const source = candidates === undefined ? (active ? [active] : []) : candidates ?? [];
+ const result: ImageGenerationBinding[] = [];
+ for (const entry of source) {
+ if (!result.some((other) =>
+ other.providerId === entry.providerId && sameWireId(other.modelId, entry.modelId)
+ )) result.push(entry);
+ }
+ if (active && !result.some((entry) =>
+ entry.providerId === active.providerId && sameWireId(entry.modelId, active.modelId)
+ )) result.push(active);
+ return result;
+}
+
+function isImageCandidate(candidates: readonly ImageGenerationBinding[], providerId: string, modelId: string) {
+ return candidates.some((entry) => entry.providerId === providerId && sameWireId(entry.modelId, modelId));
+}
+
+function chatModelOptions(providers: readonly ProviderPublic[], imageModels: readonly ImageGenerationBinding[]) {
+ return providers.flatMap((provider) => {
+ const ids = provider.models?.length
+ ? provider.models.map((model) => model.id)
+ : [provider.defaultModelId ?? ""];
+ return ids.filter((id) => !!id.trim() && !isImageCandidate(imageModels, provider.id, id))
+ .map((modelId) => ({ provider, modelId }));
+ });
+}
+
+
+function displayedChatModelId(
+ provider: ProviderPublic,
+ selected: string | undefined,
+ imageModels: readonly ImageGenerationBinding[],
+) {
+ const configured = chatModelOptions([provider], imageModels).map(({ modelId }) => modelId);
+ // Never display a different configured model in place of the saved wire ID.
+ return selected?.trim() || configured[0];
+}
+
export function ModelConfigPage() {
const { t, i18n } = useTranslation();
const providers = useAppStore((s) => s.providers);
@@ -118,11 +155,9 @@ export function ModelConfigPage() {
}, []);
const imageGenerationCandidates = useMemo(
- () => imageGenerationBindings(settings?.imageGenerationModels, settings?.imageGeneration),
+ () => imageCandidates(settings?.imageGenerationModels, settings?.imageGeneration),
[settings?.imageGenerationModels, settings?.imageGeneration],
);
- // One readiness rule for the picker, the provider rows and the add-provider
- // guard: both call `providerServesChatModels`.
const providerReady = (provider: ProviderPublic) =>
providerServesChatModels(provider, imageGenerationCandidates);
@@ -132,7 +167,7 @@ export function ModelConfigPage() {
);
const reorder = useProviderReorder(aiProviders, busyId !== null || testingId !== null || setupFor !== null);
const readyProviders = providers.filter(providerReady);
- const defaultModelOptionsList = defaultModelOptions(readyProviders, imageGenerationCandidates);
+ const defaultModelOptionsList = chatModelOptions(readyProviders, imageGenerationCandidates);
const visibleDefaultModelOptions = useMemo(() => {
const query = defaultModelQuery.trim().toLowerCase();
if (!query) return defaultModelOptionsList;
@@ -148,14 +183,17 @@ export function ModelConfigPage() {
providers.find((provider) => provider.id === settings.defaultProviderId) ?? null;
const editingProvider =
setupFor ? providers.find((provider) => provider.id === setupFor) ?? null : null;
+ const effectiveDefaultModelId = settings.defaultModelId?.trim() ||
+ defaultProvider?.models?.[0]?.id || defaultProvider?.defaultModelId;
const defaultProviderReady = defaultProvider !== null && providerReady(defaultProvider) &&
- !isImageGenerationModel(imageGenerationCandidates, defaultProvider.id,
- displayedDefaultModelId(defaultProvider, settings.defaultModelId));
+ chatModelOptions([defaultProvider], imageGenerationCandidates).some(
+ ({ modelId }) => sameWireId(modelId, effectiveDefaultModelId ?? ""),
+ );
const setDefaultModel = async (provider: ProviderPublic, modelId: string) => {
- if (isImageGenerationModel(
- imageGenerationBindings(
+ if (isImageCandidate(
+ imageCandidates(
useAppStore.getState().settings?.imageGenerationModels,
useAppStore.getState().settings?.imageGeneration,
),
@@ -191,10 +229,16 @@ export function ModelConfigPage() {
models: ModelBinding[],
imageModelIds?: string[],
) => {
- const firstModelId = models[0]?.id;
+ const selectedImageIds = imageModelIds ?? imageGenerationCandidates
+ .filter((entry) => entry.providerId === saved.id)
+ .map((entry) => entry.modelId);
+ const firstModelId = models.find((model) =>
+ !selectedImageIds.some((id) => sameWireId(id, model.id)),
+ )?.id;
const replacementChatModelId =
settings.defaultProviderId === saved.id && firstModelId &&
- !models.some((model) => modelIdsMatch(model.id, settings.defaultModelId ?? ""))
+ !models.some((model) => sameWireId(model.id, settings.defaultModelId ?? "") &&
+ !selectedImageIds.some((id) => sameWireId(id, model.id)))
? firstModelId
: undefined;
try {
@@ -206,7 +250,8 @@ export function ModelConfigPage() {
imageModelIds,
[...providers.filter((provider) => provider.id !== saved.id), saved],
current.imageGeneration?.providerId === saved.id &&
- !saved.models.some((model) => modelIdsMatch(model.id, current.imageGeneration?.modelId ?? "")),
+ (!imageModelIds.some((id) => sameWireId(id, current.imageGeneration?.modelId ?? "")) ||
+ !models.some((model) => sameWireId(model.id, current.imageGeneration?.modelId ?? ""))),
);
const nextSettings = {
...current,
@@ -224,13 +269,12 @@ export function ModelConfigPage() {
// A freshly added provider must not take over the app default: whatever
// the user already picked keeps running — as long as that default's own
// provider is still runnable — until they change it themselves.
- const keepsCurrentDefault = keepsAppDefaultModel(
- providers,
- settings.defaultProviderId,
- settings.defaultModelId,
- imageGenerationCandidates,
- );
- if (!keepsCurrentDefault) {
+ const currentProvider = providers.find((provider) => provider.id === settings.defaultProviderId);
+ const keepsCurrentDefault = !!currentProvider && providerReady(currentProvider) &&
+ chatModelOptions([currentProvider], imageGenerationCandidates).some(
+ ({ modelId }) => sameWireId(modelId, settings.defaultModelId ?? ""),
+ );
+ if (!keepsCurrentDefault && firstModelId) {
await api.setSettings({
...settings,
defaultProviderId: saved.id,
@@ -258,11 +302,11 @@ export function ModelConfigPage() {
setChangingImageModel(true);
try {
const current = await api.getSettings();
- const candidates = imageGenerationBindings(
+ const candidates = imageCandidates(
current.imageGenerationModels,
current.imageGeneration,
);
- if (!isImageGenerationModel(candidates, binding.providerId, binding.modelId)) return;
+ if (!isImageCandidate(candidates, binding.providerId, binding.modelId)) return;
const nextSettings = { ...current, imageGeneration: binding };
await api.setSettings(nextSettings);
useAppStore.setState({ settings: nextSettings });
@@ -411,17 +455,28 @@ export function ModelConfigPage() {
·
</span>
<span className="model-default-model font-mono">
- {displayedDefaultModelId(defaultProvider, settings.defaultModelId) ||
+ {displayedChatModelId(defaultProvider, effectiveDefaultModelId, imageGenerationCandidates) ||
t("settings.noModel")}
</span>
</div>
) : (
<div className="settings-row-detail model-default-value">
- <span className="model-default-empty">
- {readyProviders.length === 0
- ? t("settings.defaultModelNone")
- : t("settings.noDefaultProvider")}
- </span>
+ {defaultProvider && settings.defaultModelId ? (
+ <>
+ <span className="model-default-provider">{providerDisplayName(defaultProvider)}</span>
+ <span className="model-default-sep" aria-hidden>·</span>
+ <span className="model-default-model font-mono" title={t("settings.noDefaultProvider")}>
+ {settings.defaultModelId}
+ </span>
+ <span className="model-default-empty">{t("settings.noDefaultProvider")}</span>
+ </>
+ ) : (
+ <span className="model-default-empty">
+ {readyProviders.length === 0
+ ? t("settings.defaultModelNone")
+ : t("settings.noDefaultProvider")}
+ </span>
+ )}
</div>
)}
</div>
@@ -468,7 +523,7 @@ export function ModelConfigPage() {
{visibleDefaultModelOptions.map(({ provider, modelId }, index) => {
const isCurrent =
provider.id === settings.defaultProviderId &&
- modelIdsMatch(settings.defaultModelId ?? "", modelId);
+ sameWireId(settings.defaultModelId ?? "", modelId);
const previous = visibleDefaultModelOptions[index - 1];
const startsGroup = !previous || previous.provider.id !== provider.id;
return (
@@ -613,7 +668,7 @@ export function ModelConfigPage() {
variant="ghost"
disabled={rowBusy || !providerReady(provider)}
onClick={() =>
- void setDefaultModel(provider, defaultModelOptions([provider], imageGenerationCandidates)[0]?.modelId ?? "")
+ void setDefaultModel(provider, chatModelOptions([provider], imageGenerationCandidates)[0]?.modelId ?? "")
}
>
{t("settings.makeDefault")}
diff --git a/apps/desktop/src/components/settings/ModelSelectionPanes.tsx b/apps/desktop/src/components/settings/ModelSelectionPanes.tsx
index 3828c2fa5..fd483ec10 100644
--- a/apps/desktop/src/components/settings/ModelSelectionPanes.tsx
+++ b/apps/desktop/src/components/settings/ModelSelectionPanes.tsx
@@ -14,9 +14,9 @@ import {
THINKING_LEVELS,
bindingDefaultThinkingMenuLevels,
bindingForCustomModel,
+ bindingForCustomModelInfo,
bindingFromModelInfo,
formatTokenCount,
- modelIdsMatch,
modelMatchesFilter,
nativeWebSearchSupportedOn,
publishedThinkingLevels,
@@ -180,7 +180,7 @@ export function applyVisibleModelSelection(
for (const row of visibleRows) {
if (selected.has(row.id.toLowerCase())) continue;
additions.push(
- row.info ? bindingFromModelInfo(row.info) : bindingForCustomModel(row.id),
+ row.info ? { ...bindingFromModelInfo(row.info), id: row.id } : bindingForCustomModel(row.id),
);
}
return additions.length === 0 ? current : [...current, ...additions];
@@ -294,9 +294,9 @@ export function ModelSelectionPanes({
);
const reorder = useModelReorder(visibleChosen, setModels, busy);
- /** A discovered row arrives enriched; a hand-typed id gets generic limits. */
+ /** Keep the wire id of the selected row, even if catalog spelling differs. */
const bindingForRow = (row: ModelRow): ModelBinding =>
- row.info ? bindingFromModelInfo(row.info) : bindingForCustomModel(row.id);
+ row.info ? bindingForCustomModelInfo(row.id, row.info) : bindingForCustomModel(row.id);
/**
* The rule for a model that is being added: a filter is kept while it still
@@ -358,6 +358,8 @@ export function ModelSelectionPanes({
} catch {
return;
}
+ // A catalog hit for a different wire id is not metadata for this row.
+ if (info && info.modelId.toLowerCase() !== seed.id.toLowerCase()) return;
setModels((current) => applyCustomModelLookup(current, seed, info));
};
@@ -378,10 +380,11 @@ export function ModelSelectionPanes({
return;
}
const discovered = rows.find((row) => row.id.toLowerCase() === id.toLowerCase());
- const binding = customModelSeedBinding(id, discovered?.info);
+ const binding = discovered?.info
+ ? bindingForCustomModelInfo(id, discovered.info)
+ : customModelSeedBinding(id);
setModels((current) => [...current, binding]);
- // Expand the row under the id it is stored with: a discovered row keeps the
- // service's spelling, which can differ from what the user typed.
+ // Expand the stored wire id, not a catalog spelling that may differ.
setExpandedModelId(binding.id);
setCustomModelId("");
setCustomModelError("");
@@ -584,7 +587,7 @@ export function ModelSelectionPanes({
const publishedDocuments = info ? modelMatchesFilter(info, "pdf") : false;
const expanded = expandedModelId === binding.id;
const imageModelSelected = imageModelIds?.some((modelId) =>
- modelIdsMatch(modelId, binding.id),
+ modelId.toLowerCase() === binding.id.toLowerCase(),
) ?? false;
const advancedId = `model-advanced-${binding.id}`;
return (
diff --git a/apps/desktop/src/components/settings/ProviderSetupDialog.tsx b/apps/desktop/src/components/settings/ProviderSetupDialog.tsx
index 4be61202d..7fd61eb1a 100644
--- a/apps/desktop/src/components/settings/ProviderSetupDialog.tsx
+++ b/apps/desktop/src/components/settings/ProviderSetupDialog.tsx
@@ -9,7 +9,6 @@ import { useTranslation } from "react-i18next";
import {
NAMED_ENDPOINT_PRESETS,
OPENCODE_GO_API_STYLE,
- modelIdsMatch,
normalizeApiStyle,
type CatalogApiStyle,
type ModelBinding,
@@ -268,7 +267,7 @@ export function ProviderSetupDialog({
// existing save path when the image selection did not change.
const imageSelection = imageModelDraft ?? imageModelIds;
const remainingImageModels = imageSelection?.filter((imageModelId) =>
- persisted.some((model) => modelIdsMatch(model.id, imageModelId)),
+ persisted.some((model) => model.id.toLowerCase() === imageModelId.toLowerCase()),
);
const imageModelIdsToSave = imageModelDraft !== undefined ||
remainingImageModels?.length !== imageSelection?.length
@@ -317,9 +316,9 @@ export function ProviderSetupDialog({
setImageModelDraft((current) => {
const next = current ?? imageModelIds ?? [];
if (selected) {
- return next.some((entry) => modelIdsMatch(entry, id)) ? next : [...next, id];
+ return next.some((entry) => entry.toLowerCase() === id.toLowerCase()) ? next : [...next, id];
}
- return next.filter((entry) => !modelIdsMatch(entry, id));
+ return next.filter((entry) => entry.toLowerCase() !== id.toLowerCase());
});
};
diff --git a/apps/desktop/src/components/settings/default-model.ts b/apps/desktop/src/components/settings/default-model.ts
index 025225895..da726755f 100644
--- a/apps/desktop/src/components/settings/default-model.ts
+++ b/apps/desktop/src/components/settings/default-model.ts
@@ -7,7 +7,7 @@
* is not configured, so these helpers keep the two notions apart: what a
* provider itself offers, and what is safe to display for it.
*/
-import { isImageGenerationModel, modelIdsMatch, type ImageGenerationBindings, type ProviderPublic } from "@pi-desktop/shared";
+import { isImageGenerationModel, modelWireIdsEqual as sameComposerModelId, type ImageGenerationBindings, type ProviderPublic } from "@pi-desktop/shared";
export type DefaultModelOption = {
provider: ProviderPublic;
@@ -46,12 +46,12 @@ export function providerOffersModel(
): boolean {
if (!modelId) return false;
const bindings = provider.models ?? [];
- if (bindings.some((binding) => modelIdsMatch(binding.id, modelId))) return true;
+ if (bindings.some((binding) => sameComposerModelId(binding.id, modelId))) return true;
// A legacy/OAuth row may carry only `defaultModelId` with no bindings yet.
return (
bindings.length === 0 &&
!!provider.defaultModelId &&
- modelIdsMatch(provider.defaultModelId, modelId)
+ sameComposerModelId(provider.defaultModelId, modelId)
);
}
diff --git a/apps/desktop/src/components/settings/image-generation-default.ts b/apps/desktop/src/components/settings/image-generation-default.ts
index 55b855e91..cb2403228 100644
--- a/apps/desktop/src/components/settings/image-generation-default.ts
+++ b/apps/desktop/src/components/settings/image-generation-default.ts
@@ -20,9 +20,9 @@
import {
MAX_IMAGE_GENERATION_MODELS,
imageGenerationBindings,
- modelIdsMatch,
type ImageGenerationBinding,
type ProviderPublic,
+ modelWireIdsEqual as sameComposerModelId,
} from "@pi-desktop/shared";
/**
@@ -41,6 +41,8 @@ export function imageGenerationBindingAvailable(
provider.authKind !== "oauth" &&
!!provider.baseUrl &&
(provider.hasSecret || provider.authKind === "none") &&
+ // Mirror image-generation-service's exact availability guard. A different
+ // case is a different outbound wire ID for a case-sensitive endpoint.
provider.models.some((model) => model.id === modelId)
);
}
@@ -78,7 +80,7 @@ function cappedImageGenerationCandidates(
const activeIndex = active
? candidates.findIndex((candidate) =>
candidate.providerId === active.providerId &&
- modelIdsMatch(candidate.modelId, active.modelId),
+ sameComposerModelId(candidate.modelId, active.modelId),
)
: -1;
if (activeIndex < MAX_IMAGE_GENERATION_MODELS - 1) {
@@ -120,7 +122,7 @@ export function planImageGenerationDefaults(
}));
const previous = current.imageGeneration ?? null;
const active = previous?.providerId === savedProviderId &&
- !selected.some((binding) => modelIdsMatch(binding.modelId, previous.modelId))
+ !selected.some((binding) => sameComposerModelId(binding.modelId, previous.modelId))
? null
: previous;
const imageGenerationModels = cappedImageGenerationCandidates(
diff --git a/apps/desktop/src/components/settings/subagent-models.ts b/apps/desktop/src/components/settings/subagent-models.ts
index ebf4f9b6b..ecbd11446 100644
--- a/apps/desktop/src/components/settings/subagent-models.ts
+++ b/apps/desktop/src/components/settings/subagent-models.ts
@@ -5,7 +5,7 @@
* session). The sheet lists the same configured, runnable models as the
* Composer rather than asking the user to type that string.
*/
-import { modelIdsMatch, type ProviderPublic } from "@pi-desktop/shared";
+import { modelWireIdsEqual as sameComposerModelId, type ProviderPublic } from "@pi-desktop/shared";
import { defaultModelOptions } from "./default-model";
export type SubagentModelChoice = {
@@ -79,7 +79,7 @@ export function subagentModelPinParts(
export function pinMatchesChoice(pin: string, choice: SubagentModelChoice): boolean {
const parts = subagentModelPinParts(pin);
if (!parts) return false;
- if (!modelIdsMatch(parts.modelId, choice.modelId)) return false;
+ if (!sameComposerModelId(parts.modelId, choice.modelId)) return false;
if (parts.providerPart === choice.providerId) return true;
const alias = providerAlias(parts.providerPart);
if (!alias) return false;
diff --git a/apps/desktop/src/features/chat/composer/ComposerModelList.tsx b/apps/desktop/src/features/chat/composer/ComposerModelList.tsx
index 73cafc366..80ee3c14f 100644
--- a/apps/desktop/src/features/chat/composer/ComposerModelList.tsx
+++ b/apps/desktop/src/features/chat/composer/ComposerModelList.tsx
@@ -1,8 +1,8 @@
import type { RefObject } from "react";
import type { TFunction } from "i18next";
-import { formatTokenCount, modelIdsMatch, type ModelInfo, type ProviderPublic } from "@pi-desktop/shared";
+import { formatTokenCount, type ModelInfo, type ProviderPublic } from "@pi-desktop/shared";
import { IconCheck, IconSearch } from "../../../components/icons";
-import { composerModelBadges } from "../../../lib/composer-models";
+import { composerModelBadges, sameComposerModelId } from "../../../lib/composer-models";
export type ComposerModelGroup = {
provider: ProviderPublic;
@@ -59,8 +59,8 @@ export function ComposerModelList({
const index = flatIndex++;
const active =
selectedProviderId === group.provider.id &&
- modelIdsMatch(selectedModelId ?? "", model.modelId);
- const optionTitle = model.displayName || model.modelId;
+ sameComposerModelId(selectedModelId ?? "", model.modelId);
+ const optionTitle = model.modelId;
return (
<button
key={`${group.provider.id}:${model.modelId}`}
@@ -74,7 +74,7 @@ export function ComposerModelList({
onClick={() => void selectModel(group.provider, model.modelId)}
>
<span className="composer-model-option-main">
- <span className="truncate">{optionTitle}</span>
+ <span className="composer-model-full-id">{optionTitle}</span>
<span className="composer-model-option-meta">
{composerModelBadges(model, group.provider).map((badge) => (
<span
diff --git a/apps/desktop/src/features/chat/composer/hooks/useComposerModelMenu.ts b/apps/desktop/src/features/chat/composer/hooks/useComposerModelMenu.ts
index 5653d3b4b..3c1ce1892 100644
--- a/apps/desktop/src/features/chat/composer/hooks/useComposerModelMenu.ts
+++ b/apps/desktop/src/features/chat/composer/hooks/useComposerModelMenu.ts
@@ -8,12 +8,12 @@ import {
initialThinkingLevelForBinding,
imageGenerationBindings,
isImageGenerationModel,
- modelIdsMatch,
} from "@pi-desktop/shared";
import { useAppStore } from "../../../../stores/app-store";
import {
composerModelMatchesQuery,
composerModelsForProvider,
+ sameComposerModelId,
} from "../../../../lib/composer-models";
import {
providerDisplayName,
@@ -276,7 +276,7 @@ export function useComposerModelMenu({
providerModels[candidate.id],
);
const nextBinding = candidate.models.find((entry) =>
- modelIdsMatch(entry.id, nextModelId),
+ sameComposerModelId(entry.id, nextModelId),
);
const nextThinkingLevel = activeSessionId
? thinkingLevelForProvider(nextModelProvider, thinkingLevel)
diff --git a/apps/desktop/src/features/chat/composer/model.ts b/apps/desktop/src/features/chat/composer/model.ts
index 63a3f7a81..a6cc26257 100644
--- a/apps/desktop/src/features/chat/composer/model.ts
+++ b/apps/desktop/src/features/chat/composer/model.ts
@@ -8,10 +8,10 @@ import type {
} from "@pi-desktop/shared";
import {
isSessionThinkingLevel,
- modelIdsMatch,
PERMISSION_MODES,
sessionThinkingMenuLevels,
} from "@pi-desktop/shared";
+import { sameComposerModelId } from "../../../lib/composer-models";
import { providerThinkingLevels } from "../../../lib/session-thinking";
export const COMPOSER_MIN_HEIGHT_PX = 28;
@@ -126,11 +126,11 @@ export function thinkingProviderForModel(
modelCatalog: readonly ModelInfo[] | undefined,
): ProviderPublic | null | undefined {
if (!provider || !modelId) return provider;
- const model = modelCatalog?.find((candidate) => modelIdsMatch(candidate.modelId, modelId));
+ const model = modelCatalog?.find((candidate) => sameComposerModelId(candidate.modelId, modelId));
if (!model) return provider;
const binding = provider.models.find((candidate) =>
- modelIdsMatch(candidate.id, model.modelId),
+ sameComposerModelId(candidate.id, model.modelId),
);
const configuredLevels = binding
? THINKING_LEVELS.filter((level) => binding.thinkingLevels.includes(level))
diff --git a/apps/desktop/src/features/scheduled/ScheduledModelPicker.tsx b/apps/desktop/src/features/scheduled/ScheduledModelPicker.tsx
index 7a3abc2dd..73925f809 100644
--- a/apps/desktop/src/features/scheduled/ScheduledModelPicker.tsx
+++ b/apps/desktop/src/features/scheduled/ScheduledModelPicker.tsx
@@ -1,8 +1,8 @@
import { useMemo } from "react";
import { useTranslation } from "react-i18next";
-import { imageGenerationBindings, modelIdsMatch } from "@pi-desktop/shared";
+import { imageGenerationBindings } from "@pi-desktop/shared";
import { useAppStore } from "../../stores/app-store";
-import { composerModelDisplayName, composerModelsForProvider } from "../../lib/composer-models";
+import { composerModelsForProvider, sameComposerModelId } from "../../lib/composer-models";
import { ComposerModelPicker } from "../chat/composer/ComposerModelPicker";
import { useComposerModelMenu } from "../chat/composer/hooks/useComposerModelMenu";
import { thinkingLevelForProvider, thinkingProviderForModel } from "../chat/composer/model";
@@ -22,7 +22,7 @@ export function ScheduledModelPicker({ value, disabled, onChange }: {
const images = useMemo(() => imageGenerationBindings(settings?.imageGenerationModels,
settings?.imageGeneration), [settings?.imageGenerationModels, settings?.imageGeneration]);
const selected = provider && composerModelsForProvider(provider, providerModels[provider.id], images)
- .find(model => modelIdsMatch(model.modelId, value.modelId ?? ""));
+ .find(model => sameComposerModelId(model.modelId, value.modelId ?? ""));
const thinkingProvider = thinkingProviderForModel(provider, value.modelId,
provider ? providerModels[provider.id] : undefined);
const thinkingLevel = thinkingLevelForProvider(thinkingProvider, value.thinkingLevel ?? "off");
@@ -36,7 +36,9 @@ export function ScheduledModelPicker({ value, disabled, onChange }: {
},
});
const label = selected && provider?.enabled
- ? composerModelDisplayName(provider, selected.modelId, selected.displayName)
+ ? `${provider.name}${providers.some(p => p.id !== provider.id &&
+ p.name.toLowerCase() === provider.name.toLowerCase())
+ ? ` (${provider.id})` : ""} · ${value.modelId}`
: value.providerId && value.modelId
? t("scheduled.unavailableModel", {provider: value.providerId, model: value.modelId})
: t("settings.defaultModel");
diff --git a/apps/desktop/src/lib/chat-launch-error.ts b/apps/desktop/src/lib/chat-launch-error.ts
index 2803554ca..a860b8b98 100644
--- a/apps/desktop/src/lib/chat-launch-error.ts
+++ b/apps/desktop/src/lib/chat-launch-error.ts
@@ -1,4 +1,5 @@
-import { modelIdsMatch, OAUTH_AUTH_KIND } from "@pi-desktop/shared";
+import { OAUTH_AUTH_KIND } from "@pi-desktop/shared";
+import { sameComposerModelId } from "./composer-models";
type TranscriptMessage = {
role: string;
@@ -45,5 +46,5 @@ export function vendorAccountOmitsSessionModel(
if (!provider || provider.authKind !== OAUTH_AUTH_KIND) return false;
const models = provider.models ?? [];
if (models.length === 0) return false;
- return !models.some((model) => modelIdsMatch(model.id, modelId));
+ return !models.some((model) => sameComposerModelId(model.id, modelId));
}
diff --git a/apps/desktop/src/lib/composer-models.ts b/apps/desktop/src/lib/composer-models.ts
index 8671aa0bf..ed2655613 100644
--- a/apps/desktop/src/lib/composer-models.ts
+++ b/apps/desktop/src/lib/composer-models.ts
@@ -2,8 +2,8 @@ import {
bindingSupportsImages,
isImageGenerationModel,
type ImageGenerationBindings,
- modelIdsMatch,
modelMatchesFilter,
+ modelWireIdsEqual,
type ModelBinding,
type ModelInfo,
type ProviderPublic,
@@ -11,6 +11,11 @@ import {
type ConfiguredProvider = Pick<ProviderPublic, "id" | "models" | "defaultModelId">;
+/** UI identity is the complete wire id, not a catalog alias or a route suffix. */
+export function sameComposerModelId(left: string, right: string): boolean {
+ return modelWireIdsEqual(left, right);
+}
+
function configuredModelIds(provider: ConfiguredProvider): string[] {
const ids = (provider.models ?? [])
.map((binding) => binding.id.trim())
@@ -23,8 +28,9 @@ function configuredModelIds(provider: ConfiguredProvider): string[] {
/**
* Build the Composer model list from the models explicitly enabled in
- * provider settings. Discovery only enriches those configured rows; it does
- * not grant every discovered model access to the conversation picker.
+ * provider settings. Discovery only enriches an exact configured id; it does
+ * not grant every discovered model access to the conversation picker or lend
+ * another route's capabilities to this binding.
*/
export function composerModelsForProvider(
provider: ConfiguredProvider,
@@ -35,10 +41,10 @@ export function composerModelsForProvider(
!isImageGenerationModel(imageGeneration, provider.id, modelId),
).map((modelId) => {
const metadata = (discovered ?? []).find((model) =>
- modelIdsMatch(model.modelId, modelId),
+ sameComposerModelId(model.modelId, modelId),
);
- const row: ModelInfo = metadata
- ? { ...metadata, modelId, providerId: provider.id }
+ return metadata
+ ? { ...metadata, modelId, displayName: modelId, providerId: provider.id }
: {
modelId,
displayName: modelId,
@@ -46,40 +52,25 @@ export function composerModelsForProvider(
capabilities: ["text"],
source: "user" as const,
};
- const displayName = composerModelDisplayName(provider, modelId, row.displayName);
- return displayName === row.displayName ? row : { ...row, displayName };
});
}
-/**
- * Resolve the one visible model name used by the Composer.
- *
- * Bindings and discovery can use equivalent namespaced or regional IDs. Use
- * the same tolerant identity match for aliases so a refresh cannot briefly
- * fall back to the wire ID before the configured label is reapplied.
- */
+/** The Composer always shows the complete selected wire id, even before discovery. */
export function composerModelDisplayName(
- provider: ConfiguredProvider,
+ _provider: ConfiguredProvider,
modelId: string,
- fallback?: string,
+ _fallback?: string,
): string {
- const alias = composerModelBinding(provider, modelId)?.alias?.trim();
- return alias || fallback?.trim() || modelId;
+ return modelId;
}
-/**
- * The provider's configured binding for a model, matched the same tolerant way
- * as the display name so a namespaced or regional ID still finds its settings.
- */
+/** Find only the binding for this complete wire id. */
export function composerModelBinding(
provider: ConfiguredProvider,
modelId: string,
): ModelBinding | undefined {
- const normalizedModelId = modelId.trim().toLowerCase();
- const bindings = provider.models ?? [];
- return (
- bindings.find((candidate) => candidate.id.trim().toLowerCase() === normalizedModelId) ??
- bindings.find((candidate) => modelIdsMatch(candidate.id, modelId))
+ return (provider.models ?? []).find((candidate) =>
+ sameComposerModelId(candidate.id, modelId),
);
}
@@ -87,11 +78,8 @@ export function composerModelBinding(
export type ComposerModelBadge = "reasoning" | "vision";
/**
- * Capability markers for one configured model. The composer shows these so a
- * model can be chosen on capability rather than on name alone. Vision follows
- * the effective image input: the binding's Advanced "Image input" override
- * when set, the published capability otherwise, the same answer the transport
- * gate and the settings switch give (#214).
+ * Capability markers for one configured model. Vision follows the binding's
+ * image-input override when set, the published capability otherwise.
*/
export function composerModelBadges(
model: ModelInfo,
@@ -104,11 +92,7 @@ export function composerModelBadges(
return badges;
}
-/**
- * Match a composer model row against the picker query. Model id, display name,
- * published family and the owning provider name are all searchable, so
- * "sonnet", "anthropic" and "claude-3" all reach the same row.
- */
+/** Search the full id, published family and owning provider name. */
export function composerModelMatchesQuery(
model: ModelInfo,
providerName: string,
diff --git a/apps/desktop/src/lib/context-usage.ts b/apps/desktop/src/lib/context-usage.ts
index d078d9c6d..8d8e6d163 100644
--- a/apps/desktop/src/lib/context-usage.ts
+++ b/apps/desktop/src/lib/context-usage.ts
@@ -67,7 +67,7 @@ function bindingContextWindow(
): Pick<ModelBinding, "contextWindow" | "contextWindowSource"> | undefined {
if (!provider || !modelId) return undefined;
const binding = provider.models?.find((candidate) =>
- modelIdsMatch(candidate.id, modelId),
+ candidate.id.trim().toLowerCase() === modelId.trim().toLowerCase(),
);
if (!binding) return undefined;
const value = positiveTokenCount(binding.contextWindow);
@@ -102,7 +102,10 @@ export function resolveContextWindow(
);
if (configuredWindow) return configuredWindow;
- const providerWindow = providerContextWindow(provider);
+ // An enriched provider window may describe a different configured model.
+ const providerWindow = !modelId || !provider?.models?.length
+ ? providerContextWindow(provider)
+ : undefined;
return providerWindow ?? DEFAULT_CONTEXT_WINDOW;
}
diff --git a/apps/desktop/src/stores/runtime/session-coordination.ts b/apps/desktop/src/stores/runtime/session-coordination.ts
index d99734139..9b0cc9b6b 100644
--- a/apps/desktop/src/stores/runtime/session-coordination.ts
+++ b/apps/desktop/src/stores/runtime/session-coordination.ts
@@ -7,10 +7,10 @@ import type {
import {
contextCompactionMark,
initialThinkingLevelForBinding,
- modelIdsMatch,
normalizeMode,
} from "@pi-desktop/shared";
import { api } from "../../lib/api";
+import { sameComposerModelId } from "../../lib/composer-models";
import { scheduleHomeDraftAdopt } from "../../lib/composer-draft-cache";
import {
commitForkedSessionState,
@@ -289,7 +289,7 @@ export function createSessionCoordination({
(provider) => provider.id === inherited.providerId,
);
const inheritedBinding = defaultProvider?.models.find((candidate) =>
- modelIdsMatch(candidate.id, inherited.modelId ?? ""),
+ sameComposerModelId(candidate.id, inherited.modelId ?? ""),
);
const defaultThinkingLevel = initialThinkingLevelForBinding(
inheritedBinding,
diff --git a/apps/desktop/src/styles/composer-menus.css b/apps/desktop/src/styles/composer-menus.css
index e2a9fe9f4..2aea94971 100644
--- a/apps/desktop/src/styles/composer-menus.css
+++ b/apps/desktop/src/styles/composer-menus.css
@@ -513,17 +513,21 @@
font-weight: var(--font-weight-normal);
}
-/* A model row carries its published capability markers and context window on
- the same line as the name, so a model can be chosen on what it can do rather
- than on its name alone. The meta cluster never squeezes the name: the name
- truncates first and the markers keep their intrinsic width. */
+/* The full wire id is the identity. Wrap long route names instead of hiding
+ the part that distinguishes two configured models. */
.composer-model-option-main {
display: flex;
min-width: 0;
flex: 1;
- align-items: center;
- gap: 8px;
- overflow: hidden;
+ flex-direction: column;
+ align-items: flex-start;
+ gap: 4px;
+}
+
+.composer-model-full-id {
+ max-width: 100%;
+ overflow-wrap: anywhere;
+ white-space: normal;
}
.composer-model-option-meta {
diff --git a/apps/desktop/test/chat-launch-error.test.mjs b/apps/desktop/test/chat-launch-error.test.mjs
index 008fe1f04..37c0efd7b 100644
--- a/apps/desktop/test/chat-launch-error.test.mjs
+++ b/apps/desktop/test/chat-launch-error.test.mjs
@@ -1,10 +1,12 @@
import assert from "node:assert/strict";
+import { register } from "node:module";
import test from "node:test";
+register(new URL("./helpers/ts-import-hooks.mjs", import.meta.url));
-import {
+const {
messageHasTranscriptContent,
vendorAccountOmitsSessionModel,
-} from "../src/lib/chat-launch-error.ts";
+} = await import("../src/lib/chat-launch-error.ts");
const oauth = (models) => [{ id: "chatgpt", authKind: "oauth", models }];
@@ -35,9 +37,15 @@ test("an empty vendor chat names a model the account did not return", () => {
);
assert.equal(
vendorAccountOmitsSessionModel(session, oauth([{ id: "openai/gpt-6-luna" }])),
- false,
+ true,
);
assert.equal(vendorAccountOmitsSessionModel(session, oauth([])), false);
+ assert.equal(vendorAccountOmitsSessionModel(
+ { providerId: "chatgpt", modelId: "model" }, oauth([{ id: "generic/model" }]),
+ ), true);
+ assert.equal(vendorAccountOmitsSessionModel(
+ { providerId: "chatgpt", modelId: "GENERIC/MODEL" }, oauth([{ id: "generic/model" }]),
+ ), false);
assert.equal(
vendorAccountOmitsSessionModel(session, [
{ id: "chatgpt", authKind: "api_key", models: [{ id: "gpt-5.6-luna" }] },
diff --git a/apps/desktop/test/composer-chip-descenders.test.mjs b/apps/desktop/test/composer-chip-descenders.test.mjs
index d439ecb18..d8ae43646 100644
--- a/apps/desktop/test/composer-chip-descenders.test.mjs
+++ b/apps/desktop/test/composer-chip-descenders.test.mjs
@@ -30,10 +30,10 @@ test("model chip label avoids leading-none under truncation", () => {
);
});
-test("model menu options show one complete display name on hover", () => {
+test("model menu options show the complete wire id without truncation", () => {
assert.match(
composerSource,
- /const optionTitle =\s*model\.displayName \|\| model\.modelId;/,
+ /const optionTitle = model\.modelId;/,
);
assert.match(composerSource, /title=\{optionTitle\}/);
const optionBlock =
diff --git a/apps/desktop/test/composer-model-thinking-menu.test.mjs b/apps/desktop/test/composer-model-thinking-menu.test.mjs
index bd1020434..4da702dc0 100644
--- a/apps/desktop/test/composer-model-thinking-menu.test.mjs
+++ b/apps/desktop/test/composer-model-thinking-menu.test.mjs
@@ -137,3 +137,18 @@ test("provider headings establish a stronger type level than model rows", () =>
/:lang\(zh-CN\) \.composer-model-group-label\s*\{[\s\S]*?text-transform:\s*none/,
);
});
+
+test("composer shows and selects the full saved wire id, not a metadata title", async () => {
+ const chipSource = await readFile(new URL("../src/components/Composer.tsx", import.meta.url), "utf8");
+ assert.match(chipSource, /const modelLabel = modelId \|\| t\("chat\.model"\)/);
+ assert.match(listSource, /const optionTitle = model\.modelId/);
+ assert.match(listSource, /sameComposerModelId\(selectedModelId \?\? "", model\.modelId\)/);
+ assert.match(modelMenuSource, /modelId: nextModelId/);
+ assert.match(modelMenuSource, /sameComposerModelId\(entry\.id, nextModelId\)/);
+});
+
+test("reasoning projection uses the selected exact catalog row and binding", async () => {
+ const source = await readComposerModule("model.ts");
+ assert.match(source, /sameComposerModelId\(candidate\.modelId, modelId\)/);
+ assert.match(source, /sameComposerModelId\(candidate\.id, model\.modelId\)/);
+});
diff --git a/apps/desktop/test/composer-models.test.mjs b/apps/desktop/test/composer-models.test.mjs
index 7b1e56741..5d0f01899 100644
--- a/apps/desktop/test/composer-models.test.mjs
+++ b/apps/desktop/test/composer-models.test.mjs
@@ -3,9 +3,11 @@ import test from "node:test";
import {
composerModelBadges,
+ composerModelBinding,
composerModelDisplayName,
composerModelMatchesQuery,
composerModelsForProvider,
+ sameComposerModelId,
} from "../src/lib/composer-models.ts";
const binding = (id) => ({
@@ -40,8 +42,8 @@ test("Composer only lists models configured for the provider", () => {
assert.deepEqual(
models.map(({ modelId, displayName }) => ({ modelId, displayName })),
[
- { modelId: "claude-opus-4-6", displayName: "Claude Opus 4.6" },
- { modelId: "x-ai/grok-4.6", displayName: "Grok 4.6" },
+ { modelId: "claude-opus-4-6", displayName: "claude-opus-4-6" },
+ { modelId: "x-ai/grok-4.6", displayName: "x-ai/grok-4.6" },
],
);
});
@@ -76,7 +78,7 @@ test("legacy providers fall back to their default model binding", () => {
);
assert.deepEqual(models.map((item) => item.modelId), ["legacy-model"]);
- assert.equal(models[0].displayName, "Legacy model");
+ assert.equal(models[0].displayName, "legacy-model");
});
test("a configured alias renames the composer row without changing its id", () => {
@@ -89,7 +91,7 @@ test("a configured alias renames the composer row without changing its id", () =
);
assert.equal(models[0].modelId, "deepseek-v4-pro");
- assert.equal(models[0].displayName, "pro");
+ assert.equal(models[0].displayName, "deepseek-v4-pro");
});
test("a configured alias is visible before discovery data is available", () => {
@@ -101,20 +103,17 @@ test("a configured alias is visible before discovery data is available", () => {
undefined,
);
- assert.equal(models[0].displayName, "Spark");
+ assert.equal(models[0].displayName, "gpt-5.3-codex-spark");
});
-test("the selected label keeps its alias across equivalent model ids", () => {
+test("the selected label shows its complete wire id even with an alias", () => {
assert.equal(
composerModelDisplayName(
- {
- id: "openai",
- models: [{ ...binding("openai/gpt-5.3-codex-spark"), alias: "Spark" }],
- },
+ { id: "openai", models: [{ ...binding("openai/gpt-5.3-codex-spark"), alias: "Spark" }] },
"gpt-5.3-codex-spark",
"GPT-5.3 Codex Spark",
),
- "Spark",
+ "gpt-5.3-codex-spark",
);
});
@@ -131,7 +130,7 @@ test("an exact binding alias wins over a broader equivalent id match", () => {
"openai/gpt-5.3-codex-spark",
"GPT-5.3 Codex Spark",
),
- "Namespaced",
+ "openai/gpt-5.3-codex-spark",
);
});
@@ -144,7 +143,7 @@ test("a blank alias leaves the published display name alone", () => {
[model("deepseek-v4-pro", "DeepSeek V4 Pro")],
);
- assert.equal(models[0].displayName, "DeepSeek V4 Pro");
+ assert.equal(models[0].displayName, "deepseek-v4-pro");
});
test("composer model rows expose published reasoning and vision markers", () => {
@@ -221,3 +220,36 @@ test("composer model search matches id, name, family and provider", () => {
}
assert.equal(composerModelMatchesQuery(model, "Anthropic", "gemini"), false);
});
+
+test("prefixed and unprefixed wire ids remain separate even with one catalog name", () => {
+ const provider = {
+ id: "relay",
+ models: [
+ { ...binding("proxy/model"), alias: "Short", supportsImages: false },
+ { ...binding("model"), supportsImages: true },
+ ],
+ };
+ const rows = composerModelsForProvider(provider, [
+ { ...model("model", "Friendly"), reasoning: true, capabilities: ["text", "reasoning"] },
+ { ...model("proxy/model", "Friendly"), capabilities: ["text", "vision"] },
+ ]);
+ assert.deepEqual(rows.map(({ modelId, displayName }) => [modelId, displayName]), [
+ ["proxy/model", "proxy/model"],
+ ["model", "model"],
+ ]);
+ assert.deepEqual(composerModelBadges(rows[0], provider), []);
+ assert.deepEqual(composerModelBadges(rows[1], provider), ["reasoning", "vision"]);
+ assert.equal(composerModelBinding(provider, "proxy/model"), provider.models[0]);
+ assert.equal(composerModelBinding(provider, "model"), provider.models[1]);
+ assert.equal(sameComposerModelId("proxy/model", "model"), false);
+ assert.equal(sameComposerModelId("proxy/model", "PROXY/MODEL"), true);
+});
+
+test("legacy unprefixed selection does not borrow a prefixed route's metadata", () => {
+ const provider = { id: "relay", models: [binding("proxy/model")] };
+ const rows = composerModelsForProvider(provider, [model("model", "Friendly")]);
+ assert.equal(rows[0].displayName, "proxy/model");
+ assert.deepEqual(rows[0].capabilities, ["text"]);
+ assert.equal(composerModelBinding(provider, "model"), undefined);
+ assert.equal(composerModelDisplayName(provider, "model", rows[0].displayName), "model");
+});
diff --git a/apps/desktop/test/context-usage.test.mjs b/apps/desktop/test/context-usage.test.mjs
index 2cd283b19..29424c8e3 100644
--- a/apps/desktop/test/context-usage.test.mjs
+++ b/apps/desktop/test/context-usage.test.mjs
@@ -104,7 +104,7 @@ test("context window prefers the selected model catalog over provider fallback",
);
assert.equal(
resolveContextWindow("provider", "unknown-model", providerModels, providers),
- 64_000,
+ 128_000,
);
});
@@ -130,6 +130,22 @@ test("context window uses the selected binding before the model list loads", ()
);
});
+test("context window does not borrow a sibling route's configured binding", () => {
+ const providers = [{
+ id: "provider",
+ contextWindow: 64_000,
+ models: [
+ { id: "model", contextWindow: 16_000, contextWindowSource: "user" },
+ { id: " PROXY/MODEL ", contextWindow: 32_000, contextWindowSource: "user" },
+ ],
+ }];
+ assert.equal(resolveContextWindow("provider", "proxy/model", {}, providers), 32_000);
+ assert.equal(resolveContextWindow("provider", "model", {}, providers), 16_000);
+ providers[0].models = [providers[0].models[0]];
+ assert.equal(resolveContextWindow("provider", "proxy/model", {}, providers), 128_000);
+ assert.equal(resolveContextWindow("other-provider", "model", {}, providers), 128_000);
+});
+
test("context usage falls back to input and output when total is absent", () => {
assert.equal(
usageTokenTotal({ inputTokens: 12, outputTokens: 8, totalTokens: 0 }),
diff --git a/apps/desktop/test/default-model-display.test.mjs b/apps/desktop/test/default-model-display.test.mjs
index 6d7848364..a8391058e 100644
--- a/apps/desktop/test/default-model-display.test.mjs
+++ b/apps/desktop/test/default-model-display.test.mjs
@@ -8,15 +8,17 @@
* that adding a provider only claims the default while none resolves.
*/
import assert from "node:assert/strict";
+import { register } from "node:module";
import test from "node:test";
-import {
+register(new URL("./helpers/ts-import-hooks.mjs", import.meta.url));
+const {
defaultModelIdOf,
displayedDefaultModelId,
keepsAppDefaultModel,
providerOffersModel,
providerServesChatModels,
hasResolvedDefaultModel,
-} from "../src/components/settings/default-model.ts";
+} = await import("../src/components/settings/default-model.ts");
/** Minimal provider row; only the fields these resolvers read. */
const provider = (over = {}) => ({
@@ -73,16 +75,14 @@ test("a global default the provider does serve is displayed as-is", () => {
assert.equal(displayedDefaultModelId(p, "gpt-5-mini"), "gpt-5-mini");
});
-test("model ids are matched tolerantly, not by raw equality", () => {
- // modelIdsMatch accepts the vendor-prefixed and region-suffixed spellings of
- // the same published model, so these must not be treated as a mismatch.
- const prefixed = provider({ models: [binding("openai/gpt-5")] });
- assert.equal(displayedDefaultModelId(prefixed, "gpt-5"), "gpt-5");
- const regional = provider({ models: [binding("claude-opus-4.6")] });
- assert.equal(
- displayedDefaultModelId(regional, "claude-opus-4.6@us-east"),
- "claude-opus-4.6@us-east",
- );
+test("configured default identity uses the full wire id, not a route suffix", () => {
+ const p = provider({ models: [binding("generic/model"), binding("model")] });
+ assert.equal(providerOffersModel(p, "MODEL"), true);
+ assert.equal(displayedDefaultModelId(p, "model"), "model");
+ assert.equal(providerOffersModel(provider({ models: [binding("generic/model")] }), "model"), false);
+ assert.equal(displayedDefaultModelId(provider({ models: [binding("generic/model")] }), "model"), "generic/model");
+ assert.equal(providerOffersModel(p, "generic/MODEL"), true);
+ assert.equal(providerOffersModel(p, "generic/model@region"), false);
});
test("an empty or missing global default falls back to the provider", () => {
diff --git a/apps/desktop/test/image-generation-default.test.mjs b/apps/desktop/test/image-generation-default.test.mjs
index 5fd405e7f..504fe7d46 100644
--- a/apps/desktop/test/image-generation-default.test.mjs
+++ b/apps/desktop/test/image-generation-default.test.mjs
@@ -24,7 +24,7 @@ const {
planImageGenerationDefaults,
resolvesImageGenerationDefault,
} = await import("../src/components/settings/image-generation-default.ts");
-const { MAX_IMAGE_GENERATION_MODELS } = await import("@pi-desktop/shared");
+const { MAX_IMAGE_GENERATION_MODELS, imageGenerationBindings, isImageGenerationModel } = await import("@pi-desktop/shared");
/** A runnable image provider row; `over` overrides any field. */
const provider = (id, modelIds, over = {}) => ({
@@ -41,6 +41,21 @@ const provider = (id, modelIds, over = {}) => ({
const binding = (providerId, modelId) => ({ providerId, modelId });
+test("image bindings distinguish full routes and providers while ignoring case", () => {
+ const prefixed = binding("x", "generic/model");
+ const plain = binding("x", "model");
+ assert.deepEqual(imageGenerationBindings([prefixed, plain, binding("x", "GENERIC/MODEL")], null),
+ [prefixed, plain]);
+ assert.equal(isImageGenerationModel([prefixed], "x", "model"), false);
+ assert.equal(isImageGenerationModel([prefixed], "y", "generic/model"), false);
+ assert.equal(isImageGenerationModel([prefixed], "x", "GENERIC/MODEL"), true);
+ assert.equal(imageGenerationBindingAvailable(provider("x", ["generic/model"]), "model"), false);
+ assert.equal(imageGenerationBindingAvailable(provider("x", ["generic/model"]), "GENERIC/MODEL"), false);
+ const plan = planImageGenerationDefaults({ imageGeneration: prefixed }, "x", ["model"],
+ [provider("x", ["generic/model", "model"])]);
+ assert.deepEqual(plan.imageGeneration, plain);
+});
+
test("a saved image selection extends the candidates without taking the default", () => {
const plan = planImageGenerationDefaults(
{
diff --git a/apps/desktop/test/model-advanced-capabilities.test.mjs b/apps/desktop/test/model-advanced-capabilities.test.mjs
index ba386e252..c04835eee 100644
--- a/apps/desktop/test/model-advanced-capabilities.test.mjs
+++ b/apps/desktop/test/model-advanced-capabilities.test.mjs
@@ -88,7 +88,7 @@ test("image generation selection hides the summary when nothing can be chosen",
pickerSource,
/className="provider-chosen-advanced-toggle"[^\n]*settings\.setImageModel/,
);
- assert.match(pickerSource, /imageModelIds\?\.some\([\s\S]*?modelIdsMatch/);
+ assert.match(pickerSource, /imageModelIds\?\.some\([\s\S]*?modelId\.toLowerCase\(\) === binding\.id\.toLowerCase\(\)/);
assert.match(pickerSource, /onImageModelChange\(binding\.id, event\.target\.checked\)/);
assert.match(imageModelRowSource, /imageGenerationBindings\(settings\.imageGenerationModels, null\)/);
assert.match(imageModelRowSource, /if \(!options\.some\(\(option\) => !option\.disabled\)\) return null;/);
diff --git a/apps/desktop/test/models-dev-catalog.test.mjs b/apps/desktop/test/models-dev-catalog.test.mjs
index 8281f1fc0..9922603a2 100644
--- a/apps/desktop/test/models-dev-catalog.test.mjs
+++ b/apps/desktop/test/models-dev-catalog.test.mjs
@@ -159,6 +159,46 @@ test("cached matches remain scoped to the requested provider and endpoint", asyn
}
});
+test("unknown endpoints do not inherit ambiguous cross-provider metadata", async (t) => {
+ for (const order of [["alpha", "beta"], ["beta", "alpha"]]) {
+ const fixture = Object.fromEntries(order.map((key) => [key, {
+ api: `https://${key}.example/v1`,
+ models: {
+ "shared-model": {
+ id: "shared-model",
+ reasoning: key === "alpha",
+ limit: { context: key === "alpha" ? 128_000 : 32_000, output: 8_192 },
+ },
+ },
+ }]));
+ 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");
+ }
+ const alpha = catalog.findModel({
+ vendorKey: "custom", baseUrl: "https://alpha.example/v1", modelId: "shared-model",
+ });
+ assert.equal(alpha?.providerKey, "alpha", "an exact endpoint scopes the lookup");
+ assert.equal(alpha?.reasoning, true);
+ assert.equal(alpha?.limit.context, 128_000);
+ const beta = catalog.findModel({ vendorKey: "beta", modelId: "shared-model" });
+ assert.equal(beta?.providerKey, "beta", "a known provider key scopes the lookup");
+ assert.equal(beta?.reasoning, false);
+ assert.equal(beta?.limit.context, 32_000);
+ }
+});
+
+test("an unknown endpoint can use a unique supported proxy alias", async (t) => {
+ const catalog = await loadFixtureCatalog(t, {
+ alpha: { models: { "shared-model": { id: "shared-model", reasoning: true } } },
+ });
+ assert.equal(catalog.findModel({
+ vendorKey: "custom", baseUrl: "https://relay.example/v1", modelId: "proxy/shared-model-thinking",
+ })?.providerKey, "alpha");
+});
+
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" } } },
@@ -178,6 +218,19 @@ test("a shared catalog API prefers the explicitly selected vendor", async (t) =>
assert.equal(catalog.findModel({ ...input, modelId: "alpha-only" }), undefined);
});
+test("a shared catalog API with no vendor key cannot select the first publisher", async (t) => {
+ for (const order of [["alpha", "beta"], ["beta", "alpha"]]) {
+ const catalog = await loadFixtureCatalog(t, Object.fromEntries(order.map((key) => [key, {
+ api: "https://gateway.example/v1",
+ models: { "shared-model": { id: "shared-model", reasoning: key === "alpha",
+ 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);
+ assert.equal(catalog.findModel({ vendorKey: "beta", baseUrl: "https://gateway.example/v1", modelId: "shared-model" })?.providerKey, "beta");
+ }
+});
+
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" } } },
diff --git a/apps/desktop/test/provider-catalog-runtime.test.mjs b/apps/desktop/test/provider-catalog-runtime.test.mjs
index f5a37f210..51ef5f2bf 100644
--- a/apps/desktop/test/provider-catalog-runtime.test.mjs
+++ b/apps/desktop/test/provider-catalog-runtime.test.mjs
@@ -2,6 +2,7 @@ import assert from "node:assert/strict";
import { registerHooks } from "node:module";
import test from "node:test";
+import { genericModelConfig } from "@pi-desktop/agent-runtime";
import { ModelsDevCatalog } from "../electron/main/models-dev-catalog.ts";
const runtimeModule = new URL("../electron/main/runtime/provider-catalog.ts", import.meta.url);
@@ -151,3 +152,39 @@ test("a bulk session refresh reuses catalog matches while preserving each sessio
}
assert.equal(modelReads, 0, "session list refreshes must not repeat catalog matching work");
});
+
+test("full wire IDs isolate configured bindings while catalog aliases remain metadata-only", async () => {
+ const { runtime } = await fixtureRuntime();
+ const modelId = "proxy/catalog-model";
+ const binding = (id, contextWindow, thinkingLevels) => ({
+ id, contextWindow, contextWindowSource: "user", maxTokens: 4_096, thinkingLevels,
+ });
+ const provider = {
+ id: "provider-row", name: "Example", vendorKey: "example",
+ baseUrl: "https://models.example/v1",
+ models: [
+ binding("catalog-model", 16_000, ["off"]),
+ binding("PROXY/CATALOG-MODEL ", 32_000, ["high"]),
+ ],
+ };
+ const catalogConfig = genericModelConfig(modelId, provider.baseUrl);
+ assert.equal(runtime.bindingForModel(provider, ` ${modelId} `), provider.models[1]);
+ assert.equal(runtime.modelsDevModelFor(provider, modelId)?.modelId, "catalog-model");
+ const selected = runtime.effectiveSubagentModelConfig(provider, modelId, catalogConfig);
+ assert.equal(selected.modelConfig.name, modelId, "request wire ID is not rewritten");
+ assert.equal(selected.modelConfig.contextWindow, 32_000);
+ assert.deepEqual(selected.capabilities.supportedThinkingLevels, ["high"]);
+ const session = { providerId: provider.id, modelId };
+ assert.deepEqual(runtime.enrichSession(session, [provider]).supportedThinkingLevels, ["high"]);
+ assert.equal(runtime.enrichProvider(provider, modelId).contextWindow, 32_000);
+ assert.equal(runtime.enrichProvider(provider, "catalog-model").contextWindow, 16_000);
+ assert.equal(session.modelId, modelId);
+
+ provider.models = [provider.models[0]];
+ assert.equal(runtime.bindingForModel(provider, modelId), undefined);
+ assert.equal(runtime.effectiveSubagentModelConfig(provider, modelId, catalogConfig).modelConfig.contextWindow, 128_000);
+ assert.deepEqual(runtime.enrichSession(session, [provider]).supportedThinkingLevels, ["low", "medium", "high"]);
+ assert.equal(runtime.enrichProvider(provider, modelId).contextWindow, 128_000);
+ const otherProvider = { ...provider, id: "other-provider", models: [binding(modelId, 48_000, ["off"])] };
+ assert.deepEqual(runtime.enrichSession(session, [otherProvider, provider]).supportedThinkingLevels, ["low", "medium", "high"]);
+});
diff --git a/apps/desktop/test/provider-model-config.test.mjs b/apps/desktop/test/provider-model-config.test.mjs
index 8aae8f2b4..fb2723578 100644
--- a/apps/desktop/test/provider-model-config.test.mjs
+++ b/apps/desktop/test/provider-model-config.test.mjs
@@ -196,14 +196,14 @@ test("default model selection saves the exact model and provider", () => {
assert.match(pageSource, /defaultProviderId: provider.id,[\s\S]*defaultModelId: modelId/);
assert.match(pageSource, /onClick=\{\(\) => void setDefaultModel\(provider, modelId\)\}/);
assert.match(pageSource, /visibleDefaultModelOptions\.map/);
- assert.match(pageSource, /provider\.id === settings\.defaultProviderId &&[\s\S]*modelIdsMatch/);
+ assert.match(pageSource, /provider\.id === settings\.defaultProviderId &&[\s\S]*sameWireId/);
assert.match(pageSource, /defaultModelId: firstModelId \?\? ""/);
assert.match(
pageSource,
/settings\.defaultProviderId === saved\.id && firstModelId[\s\S]*defaultModelId: firstModelId/,
);
- // The summary line must go through the ownership-aware resolver.
- assert.match(pageSource, /displayedDefaultModelId\(/);
+ // The summary line must resolve a configured complete wire id.
+ assert.match(pageSource, /displayedChatModelId\(/);
assert.doesNotMatch(pageSource, /\{settings\.defaultModelId \|\|/);
});
@@ -306,7 +306,7 @@ test("adding a service only claims the app default while none resolves", () => {
/\} else if \(!editingProvider\) \{([\s\S]*?)\n \} else \{/,
);
assert.ok(branch, "the add-provider branch moved");
- const guard = branch[1].indexOf("keepsAppDefaultModel(");
+ const guard = branch[1].indexOf("const keepsCurrentDefault =");
const write = branch[1].indexOf("api.setSettings(");
assert.ok(guard >= 0, "the add branch must ask whether a default already resolves");
assert.ok(write > guard, "the default write must sit inside that guard");
@@ -314,10 +314,9 @@ test("adding a service only claims the app default while none resolves", () => {
// pinned by default-model-display.test.mjs. That resolver also requires the
// default provider to be runnable (enabled, credentialed, a chat model
// configured), so a keyless default row cannot block the new provider.
- assert.match(pageSource, /keepsAppDefaultModel,[\s\S]{0,80}\} from "\.\/default-model"/);
- // Provider readiness is one rule for the picker and the add guard.
- assert.match(pageSource, /const providerReady = \(provider: ProviderPublic\) =>\n\s+providerServesChatModels\(provider, imageGenerationCandidates\)/);
- assert.doesNotMatch(pageSource, /provider\.hasOauth \|\|/);
+ // Provider readiness and default selection use the same exact chat choices.
+ assert.match(pageSource, /chatModelOptions\(\[currentProvider\], imageGenerationCandidates\)/);
+ assert.match(pageSource, /providerServesChatModels\(provider, imageGenerationCandidates\)/);
});
test("a saved image selection never takes the app's image default", () => {
@@ -333,9 +332,41 @@ test("a hand-typed id is seeded from the model library, not only from generic de
// answers, so a slow or offline catalog never leaves the list without it. The
// rule itself is pinned by model-custom-lookup.test.mjs, and the channel
// contract by provider-lookup-model-handler.test.mjs.
- assert.match(pickerSource, /customModelSeedBinding\(id, discovered\?\.info\)/);
+ assert.match(pickerSource, /bindingForCustomModelInfo\(id, discovered\.info\)/);
assert.match(pickerSource, /applyCustomModelLookup\(current, seed, info\)/);
assert.match(pickerSource, /api\.lookupProviderModel\(/);
// An id the current discovery already described needs no round trip.
assert.match(pickerSource, /if \(!discovered\?\.info\) void enrichCustomModel\(binding\)/);
});
+
+test("settings match complete case-normalized wire ids, not proxy suffixes", () => {
+ const identity = pageSource.match(/const sameWireId = \(left: string, right: string\) => ([^;]+);/);
+ assert.ok(identity);
+ const sameWireId = new Function("left", "right", `return ${identity[1]}`);
+ assert.equal(sameWireId("PROXY/model", "proxy/MODEL"), true);
+ assert.equal(sameWireId("proxy/model", "model"), false);
+ assert.match(pageSource, /isImageCandidate\(imageModels, provider\.id, id\)/);
+ assert.match(pageSource, /sameWireId\(settings\.defaultModelId \?\? "", modelId\)/);
+ assert.match(pageSource, /!models\.some\(\(model\) => sameWireId\(model\.id, settings\.defaultModelId/);
+ assert.doesNotMatch(pageSource, /modelIdsMatch|isImageGenerationModel/);
+ assert.doesNotMatch(setupSource, /modelIdsMatch/);
+ assert.doesNotMatch(pickerSource, /modelIdsMatch/);
+ assert.match(pickerSource, /info\.modelId\.toLowerCase\(\) !== seed\.id\.toLowerCase\(\)/);
+ assert.match(pickerSource, /bindingForCustomModelInfo\(row\.id, row\.info\)/);
+ assert.match(setupSource, /model\.id\.toLowerCase\(\) === imageModelId\.toLowerCase\(\)/);
+ assert.match(setupSource, /entry\.toLowerCase\(\) !== id\.toLowerCase\(\)/);
+});
+
+test("new chat default skips an image-only first model", () => {
+ assert.match(pageSource, /const firstModelId = models\.find\(\(model\) =>\s*!selectedImageIds\.some\(\(id\) => sameWireId\(id, model\.id\)\)/);
+ assert.match(pageSource, /if \(!keepsCurrentDefault && firstModelId\)/);
+});
+
+test("stale image-valued chat default remains visible but is not marked ready", () => {
+ assert.match(pageSource, /const defaultProviderReady = defaultProvider !== null && providerReady\(defaultProvider\) &&[\s\S]*?chatModelOptions\(\[defaultProvider\], imageGenerationCandidates\)\.some/);
+ assert.match(pageSource, /const effectiveDefaultModelId = settings\.defaultModelId\?\.trim\(\) \|\|\s*defaultProvider\?\.models\?\.\[0\]\?\.id \|\| defaultProvider\?\.defaultModelId/);
+ assert.match(pageSource, /sameWireId\(modelId, effectiveDefaultModelId \?\? ""\)/);
+ assert.match(pageSource, /return selected\?\.trim\(\) \|\| configured\[0\]/);
+ assert.match(pageSource, /className="model-default-model font-mono" title=\{t\("settings\.noDefaultProvider"\)\}/);
+ assert.match(pageSource, /\{settings\.defaultModelId\}/);
+});
diff --git a/apps/desktop/test/subagent-models.test.mjs b/apps/desktop/test/subagent-models.test.mjs
index 19685b78b..83d8d2735 100644
--- a/apps/desktop/test/subagent-models.test.mjs
+++ b/apps/desktop/test/subagent-models.test.mjs
@@ -266,6 +266,15 @@ test("a pin that is no longer configured stays selectable", () => {
assert.equal(subagentModelOrphanPin("openai/gpt-5", choices), "openai/gpt-5");
});
+test("a pin keeps the full configured model id even when its suffix is another model", () => {
+ const choices = subagentModelChoices([provider({ models: [binding("generic/model"), binding("model")] })]);
+ assert.equal(subagentModelSelectValue("anthropic/model", choices), "anthropic/model");
+ assert.equal(subagentModelSelectValue("anthropic/GENERIC/MODEL", choices), "anthropic/generic/model");
+ assert.equal(subagentModelOrphanPin("anthropic/other/model", choices), "anthropic/other/model");
+ const prefixedOnly = choices.slice(0, 1);
+ assert.equal(subagentModelOrphanPin("anthropic/model", prefixedOnly), "anthropic/model");
+});
+
test("the editor model field is a configured-only searchable picker with an empty-state action", async () => {
const source = await readFile(
new URL("../src/components/settings/SubagentEditorSheet.tsx", import.meta.url),
diff --git a/packages/host-runtime/src/launch-resolver.test.ts b/packages/host-runtime/src/launch-resolver.test.ts
index 5f1e08ca9..1a8e4679b 100644
--- a/packages/host-runtime/src/launch-resolver.test.ts
+++ b/packages/host-runtime/src/launch-resolver.test.ts
@@ -77,6 +77,34 @@ describe("createHeadlessLaunchResolver", () => {
expect(calls.some((call) => call.method === "providers.getSecret")).toBe(true);
});
+ it("uses only the full wire ID binding for a routed model, retaining its request ID", async () => {
+ const routedId = "proxy/model";
+ const row: HostProviderRecord = {
+ ...provider,
+ models: [
+ { id: "model", contextWindow: 16_000, contextWindowSource: "user", maxTokens: 2_048, thinkingLevels: ["off"], defaultThinkingLevel: "off" },
+ { id: " PROXY/MODEL ", contextWindow: 32_000, contextWindowSource: "user", maxTokens: 4_096, thinkingLevels: ["high"], defaultThinkingLevel: "high" },
+ ],
+ };
+ const { host } = hostWith([row], { p1: "sk-test" });
+ const resolver = createHeadlessLaunchResolver({ getHost: () => host, dataDir: "/data", log: () => undefined });
+ const routed = await resolver.resolve("s1", { providerId: "p1", modelId: routedId }, {});
+ expect(routed.modelId).toBe(routedId);
+ expect(routed.sidecarParams.provider.modelId).toBe(routedId);
+ expect(routed.sidecarParams.provider.modelConfig).toMatchObject({ name: routedId, contextWindow: 32_000, maxTokens: 4_096 });
+ expect(routed.sidecarParams.thinkingLevel).toBe("high");
+
+ const plain = await resolver.resolve("s1", { providerId: "p1", modelId: "model" }, {});
+ expect(plain.sidecarParams.provider.modelConfig).toMatchObject({ name: "model", contextWindow: 16_000, maxTokens: 2_048 });
+ expect(plain.sidecarParams.thinkingLevel).toBe("off");
+
+ row.models = [row.models![0]];
+ const unbound = await resolver.resolve("s1", { providerId: "p1", modelId: routedId }, {});
+ expect(unbound.sidecarParams.provider.modelConfig).toMatchObject({ name: routedId, contextWindow: 128_000, maxTokens: 8_192 });
+ expect(unbound.sidecarParams.thinkingLevel).toBe("off");
+ expect(unbound.sidecarParams.provider.modelId).toBe(routedId);
+ });
+
it("forwards the opt-in infinite provider retry setting", async () => {
const { host } = hostWith([provider], { p1: "sk-test" });
const resolver = createHeadlessLaunchResolver({ getHost: () => host, dataDir: "/data", log: () => undefined });
diff --git a/packages/host-runtime/src/launch-resolver.ts b/packages/host-runtime/src/launch-resolver.ts
index 5dc1003c4..6ede465f0 100644
--- a/packages/host-runtime/src/launch-resolver.ts
+++ b/packages/host-runtime/src/launch-resolver.ts
@@ -189,7 +189,7 @@ export function createHeadlessLaunchResolver(options: HeadlessLaunchResolverOpti
}
function bindingForModel(provider: Pick<HostProviderRecord, "models">, modelId: string): ModelBinding | undefined {
- return provider.models?.find((binding) => binding.id === modelId);
+ return provider.models?.find((binding) => binding.id.trim().toLowerCase() === modelId.trim().toLowerCase());
}
function effectiveModelConfig(provider: HostProviderRecord, modelId: string, baseUrl: string | undefined) {
diff --git a/packages/shared/src/image-generation.ts b/packages/shared/src/image-generation.ts
index ad26cab3f..d00905500 100644
--- a/packages/shared/src/image-generation.ts
+++ b/packages/shared/src/image-generation.ts
@@ -1,4 +1,8 @@
-import { modelIdsMatch } from "./types/models.js";
+/** Image bindings use complete wire ids; catalog alias matching is not identity. */
+function sameImageModelId(left: string, right: string): boolean {
+ const requested = right.trim().toLowerCase();
+ return requested.length > 0 && left.trim().toLowerCase() === requested;
+}
/** A single host-owned binding, independent of the default conversation model. */
export type ImageGenerationBinding = { providerId: string; modelId: string };
@@ -10,7 +14,7 @@ function sameImageGenerationBinding(
left: ImageGenerationBinding,
right: ImageGenerationBinding,
): boolean {
- return left.providerId === right.providerId && modelIdsMatch(left.modelId, right.modelId);
+ return left.providerId === right.providerId && sameImageModelId(left.modelId, right.modelId);
}
/** Resolve the multi-select candidates, with legacy single-binding fallback. */
@@ -38,7 +42,7 @@ export function isImageGenerationModel(
): boolean {
const bindings = Array.isArray(binding) ? binding : binding ? [binding] : [];
return !!providerId && !!modelId && bindings.some((entry) =>
- entry.providerId === providerId && modelIdsMatch(entry.modelId, modelId),
+ entry.providerId === providerId && sameImageModelId(entry.modelId, modelId),
);
}
export const MAX_GENERATED_IMAGES = 10;
diff --git a/packages/shared/src/types/models.ts b/packages/shared/src/types/models.ts
index d3942f34b..236ce2598 100644
--- a/packages/shared/src/types/models.ts
+++ b/packages/shared/src/types/models.ts
@@ -143,6 +143,12 @@ function normalizedMatch(left: string, right: string, allowPathLeaf = false): bo
return allowPathLeaf && exactPathAliasMatch(left, right);
}
+/** Configured-model identity: compare the complete wire ID, not catalog aliases. */
+export function modelWireIdsEqual(left: string, right: string): boolean {
+ const requested = right.trim().toLowerCase();
+ return requested.length > 0 && left.trim().toLowerCase() === requested;
+}
+
/** Compare configured binding IDs without collapsing distinct route paths or variants. */
export function modelIdsMatch(candidate: string, requested: string): boolean {
const left = candidate.trim().toLowerCase();