Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins
TypeScript ai-agentcoding-agentdesktop-appelectronglobali18nlocal-firstmcppipi-agentpi-desktoppluginsreactrusttypescript
fix(models): scope unmatched thinking defaults
vastsaf1063b68e4e5
diff --git a/apps/desktop/src/components/Composer.tsx b/apps/desktop/src/components/Composer.tsxindex 5cfe2b262..a01675b8e 100644--- a/apps/desktop/src/components/Composer.tsx+++ b/apps/desktop/src/components/Composer.tsx@@ -12,6 +12,7 @@ import type {} from "@pi-desktop/shared";import {initialThinkingLevelForBinding,+ initialThinkingLevelForUnmatchedModel,imageGenerationBindings,isImageGenerationModel,normalizeLargePasteThreshold,@@ -353,12 +354,20 @@ export function Composer({const selectedBinding = provider?.models.find((candidate) =>sameComposerModelId(candidate.id, modelId ?? ""),);+ const selectedModelInfo = selectedModelCatalog?.find((candidate) =>+ sameComposerModelId(candidate.modelId, modelId ?? ""),+ );// A draft without a session starts at the selected model's stored default// thinking level, clamped onto that binding's enabled ladder.- const draftThinkingLevel = initialThinkingLevelForBinding(- selectedBinding,- thinkingProvider?.supportedThinkingLevels,- );+ const draftThinkingLevel = selectedModelInfo+ ? initialThinkingLevelForBinding(+ selectedBinding,+ thinkingProvider?.supportedThinkingLevels,+ )+ : initialThinkingLevelForUnmatchedModel(+ selectedBinding,+ thinkingProvider?.supportedThinkingLevels,+ );const sessionThinkingLevel =activeSession?.thinkingLevel ??(!activeSession ? draftConfiguration?.thinkingLevel : undefined) ??@@ -371,9 +380,6 @@ export function Composer({configuredThinkingLevel,);const thinkingLabel = thinkingLevel;- const selectedModelInfo = selectedModelCatalog?.find((candidate) =>- sameComposerModelId(candidate.modelId, modelId ?? ""),- );const modelLabel = modelId? composerModelDisplayName(provider, modelId, selectedModelInfo?.displayName): t("chat.model");diff --git a/apps/desktop/src/features/chat/composer/hooks/useComposerModelMenu.ts b/apps/desktop/src/features/chat/composer/hooks/useComposerModelMenu.tsindex 650d6128a..7fe14ed9a 100644--- a/apps/desktop/src/features/chat/composer/hooks/useComposerModelMenu.ts+++ b/apps/desktop/src/features/chat/composer/hooks/useComposerModelMenu.ts@@ -6,6 +6,7 @@ import type {import {imageGenerationBindings,initialThinkingLevelForBinding,+ initialThinkingLevelForUnmatchedModel,isImageGenerationModel,} from "@pi-desktop/shared";import { type KeyboardEvent, useEffect, useMemo, useRef, useState } from "react";@@ -256,16 +257,24 @@ export function useComposerModelMenu({const nextBinding = candidate.models.find((entry) =>sameComposerModelId(entry.id, nextModelId),);+ const nextModel = providerModels[candidate.id]?.find((entry) =>+ sameComposerModelId(entry.modelId, nextModelId),+ );const selectedSameModel =activeSessionId &&candidate.id === provider?.id &&sameComposerModelId(modelId ?? "", nextModelId);const nextThinkingLevel = selectedSameModel? thinkingLevelForProvider(nextModelProvider, thinkingLevel)- : initialThinkingLevelForBinding(- nextBinding,- nextModelProvider?.supportedThinkingLevels,- );+ : (nextModel+ ? initialThinkingLevelForBinding(+ nextBinding,+ nextModelProvider?.supportedThinkingLevels,+ )+ : initialThinkingLevelForUnmatchedModel(+ nextBinding,+ nextModelProvider?.supportedThinkingLevels,+ ));await configureActiveSession({mode,providerId: candidate.id,diff --git a/apps/desktop/src/features/chat/composer/model.ts b/apps/desktop/src/features/chat/composer/model.tsindex a38f71e40..d8f3d2347 100644--- a/apps/desktop/src/features/chat/composer/model.ts+++ b/apps/desktop/src/features/chat/composer/model.ts@@ -138,14 +138,17 @@ export function thinkingProviderForModel(if (!model) {// No catalog match: all thinking levels selectable, default off.// A binding override still takes precedence when present.- const supportsReasoning = configuredLevels- ? configuredLevels.some((level) => level !== "off")+ // An empty binding is the generic seed for an unknown model, not an+ // explicit disable; `off` is the persisted opt-out for that case.+ const unmatchedLevels = configuredLevels?.length ? configuredLevels : undefined;+ const supportsReasoning = unmatchedLevels+ ? unmatchedLevels.some((level) => level !== "off"): true;return {...provider,supportsReasoning,supportedThinkingLevels:- configuredLevels ?? [...THINKING_LEVELS],+ unmatchedLevels ?? [...THINKING_LEVELS],};}diff --git a/apps/desktop/src/stores/runtime/session-coordination.ts b/apps/desktop/src/stores/runtime/session-coordination.tsindex aa4c5e55c..34881d764 100644--- a/apps/desktop/src/stores/runtime/session-coordination.ts+++ b/apps/desktop/src/stores/runtime/session-coordination.ts@@ -7,6 +7,7 @@ import type {import {contextCompactionMark,initialThinkingLevelForBinding,+ initialThinkingLevelForUnmatchedModel,normalizeMode,} from "@pi-desktop/shared";import { api } from "../../lib/api";@@ -291,10 +292,20 @@ export function createSessionCoordination({const inheritedBinding = defaultProvider?.models.find((candidate) =>sameComposerModelId(candidate.id, inherited.modelId ?? ""),);- const defaultThinkingLevel = initialThinkingLevelForBinding(- inheritedBinding,- defaultProvider?.supportedThinkingLevels,- );+ const catalogModel = inherited.providerId && inherited.modelId+ ? state.providerModels[inherited.providerId]?.find((candidate) =>+ sameComposerModelId(candidate.modelId, inherited.modelId ?? ""),+ )+ : undefined;+ const defaultThinkingLevel = catalogModel+ ? initialThinkingLevelForBinding(+ inheritedBinding,+ defaultProvider?.supportedThinkingLevels,+ )+ : initialThinkingLevelForUnmatchedModel(+ inheritedBinding,+ defaultProvider?.supportedThinkingLevels,+ );const previousSessionId = state.activeSessionId;revealEmptyCreatingSession(active);let created: Awaited<ReturnType<typeof api.createSession>>;diff --git a/apps/desktop/test/composer-model-thinking-menu.test.mjs b/apps/desktop/test/composer-model-thinking-menu.test.mjsindex 6eb88adef..6fb7f8ae5 100644--- a/apps/desktop/test/composer-model-thinking-menu.test.mjs+++ b/apps/desktop/test/composer-model-thinking-menu.test.mjs@@ -33,7 +33,10 @@ test("model selection returns to the root without closing", () => {});test("switching models adopts the target default without resetting same-model overrides", () => {assert.match(modelMenuSource, /const selectedSameModel =\s*activeSessionId &&\s*candidate\.id === provider\?\.id &&\s*sameComposerModelId\(modelId \?\? "", nextModelId\);/);- assert.match(modelMenuSource, /const nextThinkingLevel = selectedSameModel\s*\?\s*thinkingLevelForProvider\(nextModelProvider, thinkingLevel\)\s*:\s*initialThinkingLevelForBinding\(\s*nextBinding,\s*nextModelProvider\?\.supportedThinkingLevels,\s*\)/);+ assert.match(+ modelMenuSource,+ /const nextThinkingLevel = selectedSameModel\s*\?\s*thinkingLevelForProvider\(nextModelProvider, thinkingLevel\)[\s\S]*?initialThinkingLevelForBinding\(\s*nextBinding,\s*nextModelProvider\?\.supportedThinkingLevels,\s*\)[\s\S]*?initialThinkingLevelForUnmatchedModel\(\s*nextBinding,\s*nextModelProvider\?\.supportedThinkingLevels,\s*\)/,+ );});test("the menu root carries the reasoning slider itself", () => {// The root view renders the slider and nothing else for the level: there isdiff --git a/apps/desktop/test/composer-models.test.mjs b/apps/desktop/test/composer-models.test.mjsindex 1d55fcc41..4001eca82 100644--- a/apps/desktop/test/composer-models.test.mjs+++ b/apps/desktop/test/composer-models.test.mjs@@ -9,6 +9,7 @@ import {composerModelsForProvider,sameComposerModelId,} from "../src/lib/composer-models.ts";+import { thinkingProviderForModel } from "../src/features/chat/composer/model.ts";const binding = (id) => ({id,@@ -62,6 +63,57 @@ test("configured models remain selectable when discovery is unavailable", () =>assert.equal(models[0].displayName, "my-model-v2");});+test("unmatched models expose the full thinking ladder unless a binding overrides it", () => {+ const provider = {+ id: "custom",+ models: [],+ supportsReasoning: false,+ supportedThinkingLevels: ["off"],+ };+ const unmatched = thinkingProviderForModel(provider, "route/model", undefined);++ assert.deepEqual(unmatched?.supportedThinkingLevels, [+ "off",+ "minimal",+ "low",+ "medium",+ "high",+ "xhigh",+ "max",+ ]);+ assert.equal(unmatched?.supportsReasoning, true);++ const emptyBinding = thinkingProviderForModel(+ {+ ...provider,+ models: [binding("route/model")],+ },+ "route/model",+ undefined,+ );+ assert.deepEqual(emptyBinding?.supportedThinkingLevels, [+ "off",+ "minimal",+ "low",+ "medium",+ "high",+ "xhigh",+ "max",+ ]);+ assert.equal(emptyBinding?.supportsReasoning, true);++ const constrained = thinkingProviderForModel(+ {+ ...provider,+ models: [{ ...binding("route/model"), thinkingLevels: ["off"] }],+ },+ "route/model",+ undefined,+ );+ assert.deepEqual(constrained?.supportedThinkingLevels, ["off"]);+ assert.equal(constrained?.supportsReasoning, false);+});+test("Composer preserves configured order even when discovery returns another order", () => {const configured = ["z-custom", "gpt-6-astra", "claude-opus-4-6"];const models = composerModelsForProvider(diff --git a/apps/desktop/test/thinking-ui.test.mjs b/apps/desktop/test/thinking-ui.test.mjsindex 73ca3af42..84ca774c1 100644--- a/apps/desktop/test/thinking-ui.test.mjs+++ b/apps/desktop/test/thinking-ui.test.mjs@@ -38,6 +38,13 @@ const sessionIpcSource = await readMainModule("ipc/session-ipc.ts");const sessionLaunchSource = await readMainModule("runtime/session-launch.ts");const storeSource = await readStoreSource();const sessionCoordinationSource = await readStoreModule("runtime/session-coordination.ts");+const modelMenuSource = await readFile(+ new URL(+ "../src/features/chat/composer/hooks/useComposerModelMenu.ts",+ import.meta.url,+ ),+ "utf8",+);// Agent/Plan mode and model selection are owned by the Composer; the// conversation top bar only hosts the task title and window actions.const topbarSource = await readFile(@@ -187,10 +194,16 @@ test("draft Composer thinking follows the exact model selected in its menu", ());assert.match(composerSource,- /const nextThinkingLevel = selectedSameModel\s*\?\s*thinkingLevelForProvider\(nextModelProvider, thinkingLevel\)\s*:\s*initialThinkingLevelForBinding\(/,+ /const nextThinkingLevel = selectedSameModel\s*\?\s*thinkingLevelForProvider\(nextModelProvider, thinkingLevel\)[\s\S]*?initialThinkingLevelForBinding\([\s\S]*?initialThinkingLevelForUnmatchedModel\(/,);assert.match(composerSource, /const selectedBinding = provider\?\.models\.find/);- assert.match(composerSource, /const draftThinkingLevel = initialThinkingLevelForBinding\(/);+ assert.match(+ composerSource,+ /const draftThinkingLevel = selectedModelInfo\s*\?\s*initialThinkingLevelForBinding\(/,+ );+ assert.match(composerSource, /initialThinkingLevelForUnmatchedModel\(/);+ assert.match(modelMenuSource, /initialThinkingLevelForUnmatchedModel\(/);+ assert.match(sessionCoordinationSource, /initialThinkingLevelForUnmatchedModel\(/);assert.doesNotMatch(composerSource, /highestSupportedThinkingLevel/);});diff --git a/docs/spec/03-runtime/11-provider-model-system.md b/docs/spec/03-runtime/11-provider-model-system.mdindex 4002f04b4..433ef74cd 100644--- a/docs/spec/03-runtime/11-provider-model-system.md+++ b/docs/spec/03-runtime/11-provider-model-system.md@@ -222,8 +222,10 @@ PI-Desktop must not permanently restrict users to a short fixed model list.7. User-edited `ModelBinding` values remain explicit provider configuration:they control selected request limits, enabled thinking levels, the defaultthinking level applied to a new home draft and newly persisted session- (clamped onto the enabled set; strongest-enabled only when the default is- unset), and the attachment capability overrides. `models.dev` supplies published metadata and seeds the initial+ (clamped onto the enabled set; a known catalog match uses the+ strongest-enabled level when the default is unset, while an unmatched+ model starts at `off`), and the attachment capability overrides.+ `models.dev` supplies published metadata and seeds the initialthinking selection for a newly added known model; it is not a runtime gateon a level the user explicitly enables for the endpoint. For compatibility,a binding that still contains the legacy generic `128,000` context seed@@ -405,7 +407,8 @@ surface for older clients. PI-Desktop no longer reads them as runtime modeloverrides. `ModelInfo` reasoning support and supported thinking levels describethe resolved models.dev record; effective provider/session capability comes fromthe exact `ModelBinding`. Unknown free-form ids start with the generic shape and-no inferred reasoning capability, but an explicit binding may opt into levels.+no inferred reasoning capability; an empty binding level array is the generic+seed, while a non-empty explicit binding may opt into or disable levels.The provider dialog persists one `ModelBinding` for every selected model. Thefirst binding is the effective model for current conversations and legacydiff --git a/docs/spec/03-runtime/13-model-catalog-and-selection.md b/docs/spec/03-runtime/13-model-catalog-and-selection.mdindex b9066c2d5..0bcf95d5b 100644--- a/docs/spec/03-runtime/13-model-catalog-and-selection.md+++ b/docs/spec/03-runtime/13-model-catalog-and-selection.md@@ -203,14 +203,14 @@ sends no thinking override. An empty binding or a binding containing only`off` resolves to `off`.For a newly created session or explicit model switch, the renderer resolves the-selected (or app-default) model's `ModelBinding`. A reasoning model starts at-that binding's `defaultThinkingLevel` (`omit` is preserved; other values are-clamped onto the enabled levels). When the default is unset it falls back to-the highest enabled level seeded from published `supportedThinkingLevels`. A-non-reasoning or unknown model starts at `off` until the user enables a-non-`off` level. Changing a default in Settings does not rewrite existing-sessions; an existing session keeps its stored choice until a different model-is explicitly selected.+selected (or app-default) model's `ModelBinding`. A catalog-matched reasoning+model starts at that binding's `defaultThinkingLevel` (`omit` is preserved;+other values are clamped onto the enabled levels); when the default is unset it+falls back to the highest enabled level. An unmatched model starts at `off`+unless its binding stores an explicit default, while its Composer ladder stays+available for manual opt-in. Changing a default in Settings does not rewrite+existing sessions; an existing session keeps its stored choice until a+different model is explicitly selected.Unpinned sessions still advertise that inherited default model's reasoningcapability on session list/get/create/fork/configure. Enrichment does not pin@@ -382,8 +382,9 @@ wins over the published record; an absent or `null` value follows it. This letsa configured custom or proxied model show the capability the endpoint wasexplicitly configured to use without shaping the published `ModelInfo`.An OAuth provider heading uses its non-secret account label when present, so-duplicate accounts from one vendor remain distinguishable; model rows still-use the configured model alias or published model name.+duplicate accounts from one vendor remain distinguishable; Composer model rows+show the configured wire model ID, while a configured alias remains available+as the compact selected-chip label.## 10. Default model policy@@ -407,9 +408,11 @@ Session-level:- inherits app default at creation and stores that `providerId`/`modelId` pair- later Settings default-model changes apply only to new sessions and theunpersisted home draft, not to already created sessions-- initializes thinking to the highest level enabled by the inherited model's- binding; published levels seed a new binding, while an empty or `off`-only- binding starts at `off`+- initializes thinking from the inherited model's binding default. A known+ reasoning model with no stored default falls back to its highest enabled+ level; an unmatched model with no stored default starts at `off` while its+ canonical thinking levels remain selectable in Composer. An empty or+ `off`-only binding starts at `off`- can override independently## 11. Capability gating@@ -433,12 +436,15 @@ Warnings are non-blocking unless execution is impossible.3. The provider's exact `ModelBinding.thinkingLevels` is authoritative for theuser's effective selection. It may explicitly enable a canonical level thatthe catalog does not publish.-4. A free-form ID absent from models.dev starts as an unknown generic model and- exposes only `off`; Settings can promote it only after an explicit binding- selection, never through discovery or an automatic inference.+4. A free-form ID absent from models.dev starts as an unknown generic model in+ the host capability snapshot. Composer still exposes the seven canonical+ thinking levels for an unmatched model so the user can opt in manually;+ an empty binding level array is the generic seed and does not override that+ ladder; a non-empty binding override remains authoritative. Without a+ stored binding default its draft/session level is `off`.5. The Composer renders the effective binding levels in canonical order. If no- binding exists, it falls back to the published model levels and provider- defaults.+ binding exists, a catalog match supplies the published model levels; an+ unmatched model exposes the canonical ladder instead.6. If a stored/requested level is unavailable, choose the nearest enabledbinding level by scanning upward first and then downward. A binding with nonon-`off` level resolves to `off`.@@ -481,41 +487,38 @@ manual token entry. The enrichment lookup is:Catalog enrichment uses `catalogModelIdsMatch`, not the shared`modelIdsMatch` used to resolve an exact configured binding. Binding identity-accepts case-insensitive exact IDs, full slash-path suffixes, known vendor-`-`/`.` prefixes and a one-sided `@region` alias; it does not collapse two-different regions, arbitrary routing prefixes or endpoint/thinking suffixes.-Metadata lookup additionally accepts a complete bare leaf ID through a generic-route such as `proxy/` or `custom/`, subject to known-vendor conflicts; two-different full route paths never match solely because they share a leaf. It-narrowly strips trailing `-` or `:` `thinking`, `think`, `agent` or `latest`-tokens (including before `@region`). It does not strip arbitrary-dash-separated proxy prefixes or effort tokens such as `low`, `high` or `max`.--When nothing matches outright, the lookup falls back to the whole published ID-the served name reduces to: the ID behind one route prefix (`test/mimo-v2.5`) and-that ID without one deployment marker (`mimo-v2.5-pro-test`, `gemini-2.5-pro-1m`).-Only a marker that names a variant of a published model is read that way —-`-test`, `-preview`, `-beta`, `-1m`, `-128k`; `-asr`, `-tts` and `-pro` name-models of their own, so an unpublished ID carrying one of those stays unknown-instead of inheriting a sibling's limits. This fallback reads a whole published-ID and never follows a chain of aliases.-The catalog index uses bounded candidate keys for these aliases, then checks-the matcher; a known catalog provider selected by vendor key or API URL limits-the lookup to that provider, never borrowing another provider's capabilities.-These aliases attach published metadata only: they do not alter the configured-wire model ID or prove that a suffix enables reasoning. An unmatched free-form-ID remains an unknown generic model with no inferred capabilities; only a-published record or explicit binding settings can supply them.+retains its existing case-insensitive wire-ID, region, route-suffix and known+vendor-prefix rules. Metadata lookup itself uses only the lower-cased final+`/` segment: `route/model` can reach a catalog row for `model`, but the route+prefix is not treated as model identity. The candidate index uses the same+last-segment key, so two routes sharing a leaf become competing candidates+rather than an automatic match.++Resolution is deliberately conservative. Zero candidates stays unmatched; one+candidate enriches the row. When there are multiple candidates, a unique+official/source provider is preferred only when its provider family agrees with+an explicit source prefix (`anthropic`, `openai`, `google*`, `xai`/`x-ai`). If+there is no unique official hit, enrichment is allowed only when every+candidate has the same published capabilities and thinking metadata; otherwise+the row stays unmatched. The matcher no longer strips `thinking`, `think`,+`agent`, `latest`, release-date or deployment-marker suffixes, and it does not+collapse vendor-dash aliases. A known provider may still borrow an exact ID+from another catalog publisher when its own record is absent; an unknown+provider does not use unanchored consensus or deployment-marker fallback.++These rules attach published metadata only: they never rewrite the configured+wire model ID or infer reasoning from a suffix. An unmatched free-form ID keeps+the host's generic capability snapshot, while Composer exposes the canonical+thinking ladder for explicit manual opt-in.#### 11.3.1 Cross-provider exact-id fallbackmodels.dev indexes a gateway's copy of a model under the vendor that owns theweights, so an endpoint serving `Vendor/Model` ids can have no record of its own-while several other publishers state the identical id. When the row resolves to-a catalog provider whose own record is missing, `findModel` consults the other-publishers of the **exact** id instead of leaving the model on the generic-128k text-only shape (issue #938), and reads a whole published id the served name-reduces to when no publisher states the id itself.+while another publisher states the identical id. When the row resolves to a+known catalog provider whose own record is missing, `findModel` may consult the+other publishers of the **exact** id instead of leaving the model on the generic+128k text-only shape (issue #938).The borrow is bounded:@@ -524,15 +527,13 @@ The borrow is bounded:it, stays authoritative.- A provider sharing the row's own endpoint is an alias for the row, so itssilence is an answer about this deployment and nothing is borrowed past it.-- Only a case-insensitive identical id transfers, or a whole published id the- served name reduces to (`test/mimo-v2.5-pro-test` → `mimo-v2.5-pro`). A record- the index reaches through an alias is a different id and keeps its own limits.+- Only a case-insensitive identical id transfers. A record the index reaches+ through a last-segment candidate or other non-exact spelling is not borrowed+ by this fallback.- The publishers this app ships a provider for answer before arbitrary resellers- do, in the same order the unanchored borrow uses: an id a shipped publisher- states describes the model, while a reseller's copy describes its own- deployment of it. Within that tier a record under exactly this id outranks one- reached through another spelling of it, so a copy carrying only the text half- cannot narrow what the model's own record states about vision.+ do, but only for the exact requested ID. A copy reached through a different+ spelling cannot narrow or expand what the model's own record states about+ vision.- Tool support follows the majority of the publishers that state it, because awrong `true` puts tool declarations on the wire that the endpoint may reject,while one dissenting reseller must not void a record a hundred of them agree@@ -540,7 +541,8 @@ The borrow is bounded:the intersection, so a borrow may only under-claim; a user who knows theendpoint does more still enables it in Advanced. Limits are the medians thepublishers state, never one host's cap.-- An id no publisher states stays an unknown generic model.+- An id no publisher states stays an unknown generic model; there is no+ deployment-marker or unanchored-consensus fallback.This changes metadata only. The configured wire id, provider identity, and thebinding precedence in §11.3 are unchanged.@@ -601,9 +603,11 @@ same model to the check mark, the toggle and the duplicate guard.- [ ] capability badges visible- [ ] session model change applies to next turn only- [ ] a newly created session stores the then-current default provider/model, and later default-model changes do not rewrite that session-- [ ] a new session defaults a reasoning-capable inherited model to that- binding's stored default thinking level (clamped onto the enabled set;- strongest-enabled only when unset) and otherwise defaults to `off`+- [ ] a catalog-matched reasoning model defaults a new session to that+ binding's stored thinking level (clamped onto the enabled set;+ strongest-enabled only when unset); an unmatched model starts at `off`+ without an explicit binding default while retaining the manual thinking+ ladder in Composer- [ ] the settings picker always exposes the canonical thinking ladder;published levels seed known models and explicit binding levels clamp thesame way in Composer, Electron main, and the pi sidecardiff --git a/docs/spec/04-ux/08-component-spec.md b/docs/spec/04-ux/08-component-spec.mdindex 63ec1467f..e4353c914 100644--- a/docs/spec/04-ux/08-component-spec.md+++ b/docs/spec/04-ux/08-component-spec.md@@ -2806,7 +2806,7 @@ reasoning-level control.| Idle (no model) | textarea active, send button disabled + tooltip "Configure a model first" | Agent link remains available in model menu || Idle (ready) | textarea active; Send requires draft content | Send active when content exists || Home/new-session initialization | textarea and mode/model × reasoning/permission triggers remain available while the durable empty session is loading; the session row is already present and the first configuration selection applies to that session | Configure the session, then send |-| New session (reasoning model) | Combined model × reasoning chip shows the model and its binding default thinking level | User may select any level enabled in the model binding, including Off when enabled |+| New session (reasoning model) | Combined model × reasoning chip shows the model and its binding default thinking level; an unmatched model starts at Off while keeping the manual ladder available | User may select any level enabled in the model binding, or any canonical level for an unmatched model || New session / switch while another session is running | textarea active, send button enabled for the destination session's own run state | Send active, Stop hidden unless the destination session itself is running with an empty draft || Running | textarea and mode/model × reasoning/permission controls remain editable for the next turn; the single submit slot shows Stop only with an empty draft | Send queues text or attachments; Stop when both are empty || Context checkpoint | Same as Running until durable checkpoint completion; intermediate `turn_end` does not reactivate controls. A retained-tail fallback remains Running and shows a warning toast | Same single-slot Stop/Send behavior as Running |@@ -2959,15 +2959,16 @@ reasoning-level control.model therefore updates the draft Composer's available levels and bindingdefault thinking level immediately; the persisted session keeps the sameexact-model capability after materialization.-- A new session whose inherited default model supports reasoning starts with- Thinking enabled at that model's stored default thinking level, clamped onto- the enabled set. When the binding has no default, it falls back to the- highest enabled level. Published levels seed a new binding; an explicit- binding can opt into a level the catalog omits. Non-reasoning models and- missing capability metadata start at `off` until a user enables a non-`off`- level. Reopening an existing session preserves its durable selection;- explicitly switching to a different model applies that binding's default,- while selecting the already-active model preserves a manually chosen level.+- A new session whose catalog-matched default model supports reasoning starts+ with Thinking enabled at that model's stored default thinking level, clamped+ onto the enabled set. When the binding has no default, it falls back to the+ highest enabled level. An unmatched model starts at `off` unless its binding+ stores an explicit default, while the Composer keeps the canonical ladder+ available for manual opt-in. Published levels seed a new binding; an+ explicit binding can opt into a level the catalog omits. Reopening an+ existing session preserves its durable selection; explicitly switching to a+ different model applies that binding's default, while selecting the+ already-active model preserves a manually chosen level.- The model menu lists only enabled, runnable providers with configured modelbindings. Cached or freshly discovered rows may enrich those configuredmodels, but unconfigured discovery results never appear in the conversationdiff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.mdindex 2cbcbec72..c9d2fef5c 100644--- a/docs/spec/06-delivery/04-e2e-test-plan.md+++ b/docs/spec/06-delivery/04-e2e-test-plan.md@@ -11099,9 +11099,10 @@ This test plan spec is accepted when:generic 128,000 / 8,192 / no-reasoning defaults. The authenticated ChatGPTlist comes from `GET {base}/codex/models` on the account token, so an id thepin does not know yet is selectable when that response includes it; pi-ai is- only the fallback when the request fails. models.dev cannot add a missing OAuth ID. A model with no published- record keeps its explicit levels and starts with all choices available for- manual opt-in. The account's default model stays the head binding.+ only the fallback when the request fails. models.dev cannot add a missing+ OAuth ID. A model with no published record keeps its explicit levels, starts+ at `off` when no binding default is stored, and keeps all choices available+ for manual opt-in. The account's default model stays the head binding.- **Specs linked**: `04-ux/06-settings-ia.md`,`04-ux/08-component-spec.md` §19, `03-runtime/11-provider-model-system.md`§10, `08-meta/decisions-log.md` (D270 refines D237/D240)diff --git a/docs/spec/08-meta/decisions-log.md b/docs/spec/08-meta/decisions-log.mdindex 0c0cdcd5e..085348d9e 100644--- a/docs/spec/08-meta/decisions-log.md+++ b/docs/spec/08-meta/decisions-log.md@@ -7172,3 +7172,27 @@ must keep splitting are covered by `markdown-blocks.test.mjs`.migration or host protocol version change is required.- Covered by `apps/desktop/test/update-preference.test.mjs`, the updated`apps/desktop/test/auto-update.test.mjs`, and E2E-UPDATE-preference-and-once-only-reminder.++## 2026-09-27 — Routed model metadata uses conservative last-segment matching (D629, PR #1047)++- Supersede D622's broad catalog aliases for runtime enrichment. Compare only+ the case-insensitive final `/` segment, so a routed or gateway wire ID can+ reach a catalog row without treating arbitrary thinking, release-date,+ deployment-marker, or vendor-dash suffixes as model identity.+- When a leaf has multiple catalog candidates, select a unique official/source+ provider only when its provider family agrees with an explicit model source;+ otherwise borrow metadata only when all candidates expose identical+ capabilities and thinking metadata. If neither rule proves identity, leave+ the row unmatched. A known provider may still borrow the exact ID from other+ publishers; unknown providers do not use unanchored consensus or marker+ fallback.+- Composer keeps the complete configured wire ID on model rows. Unmatched+ models expose the canonical thinking ladder for manual opt-in, but start a+ new draft/session at `off` unless an explicit binding default exists. An+ empty binding level array is the generic unknown-model seed, not an explicit+ disable; a non-empty binding override remains authoritative. Known catalog+ matches retain the D303 binding-default/highest-enabled behavior.+- The change is metadata/UI projection only: it does not rewrite persisted wire+ IDs, provider identity, or host capability ownership. See+ `03-runtime/13-model-catalog-and-selection.md` §11.3 and+ `04-ux/08-component-spec.md` §11.diff --git a/docs/zh-CN/spec/03-runtime/11-provider-model-system.md b/docs/zh-CN/spec/03-runtime/11-provider-model-system.mdindex 8d50a733c..afd48c05c 100644--- a/docs/zh-CN/spec/03-runtime/11-provider-model-system.md+++ b/docs/zh-CN/spec/03-runtime/11-provider-model-system.md@@ -200,8 +200,9 @@ PI-Desktop 不得把用户永久限制在一份简短的固定模型列表上。PDF 附件仍然是有界的文件引用,而不会被错误地编码成图片。7. 用户编辑过的 `ModelBinding` 值仍属于显式的提供商配置:它们控制选定的请求上限、启用的思考级别、应用到新的主页草稿与新持久化会话的默认思考级别- (会被钳制到已启用集合上;只有在默认值未设置时才取已启用中最强的那个),- 以及附件能力覆盖。`models.dev` 提供已发布的元数据,并为新添加的已知模型+ (会被钳制到已启用集合上;已匹配目录的模型在默认值未设置时取已启用中最强的+ 那个,未匹配模型则从 `off` 开始),以及附件能力覆盖。`models.dev` 提供已发布的+ 元数据,并为新添加的已知模型播下初始的思考级别选择;它不是对用户为该端点显式启用的级别的运行时闸门。出于兼容考虑,仍然带着旧的通用 `128,000` 上下文种子的 binding 会跟随新发布的 `limit.context`;非默认的 Advanced 值仍保持显式。这样目录刷新之后,@@ -337,8 +338,8 @@ type ThinkingLevel =上面这些兼容性字段,是为老客户端保留的持久化模式兼容面。PI-Desktop 不再把它们当作运行时的模型覆盖来读取。`ModelInfo` 的推理支持与受支持的思考级别描述的是解析出的 models.dev 记录;有效的 provider/会话能力则来自那个确切的-`ModelBinding`。未知的自由格式 id 以通用形态起步,不带任何推断出的推理能力,-但显式的 binding 可以主动启用相应级别。+`ModelBinding`。未知的自由格式 id 以通用形态起步,不带任何推断出的推理能力;+空的绑定等级数组是通用种子,非空的显式 binding 才会主动启用或禁用相应级别。提供商对话框会为每个选中的模型持久化一条 `ModelBinding`。第一条 binding 是当前对话以及旧版运行时消费方的有效模型。对话级别的模型切换与跨数组路由仍属diff --git a/docs/zh-CN/spec/03-runtime/13-model-catalog-and-selection.md b/docs/zh-CN/spec/03-runtime/13-model-catalog-and-selection.mdindex 49e9b759e..38392600a 100644--- a/docs/zh-CN/spec/03-runtime/13-model-catalog-and-selection.md+++ b/docs/zh-CN/spec/03-runtime/13-model-catalog-and-selection.md@@ -114,10 +114,10 @@ type RecentModelRef = {且不发送思考覆盖。对于新创建的会话,渲染器会解析所选(或应用默认)模型的 `ModelBinding`。-具有推理能力的模型始于该绑定的 `defaultThinkingLevel`(`omit` 保留;其它值-钳位到已启用档位);当默认值未设置时,才回落到已发布-`supportedThinkingLevels` 中的最高已启用档。非推理模型或缺失的能力元数据从-`off` 开始。这是一个仅创建时的默认值,绝不会重写现有会话的存储选择。+已匹配目录的推理模型始于该绑定的 `defaultThinkingLevel`(`omit` 保留;其它值+钳位到已启用档位);当默认值未设置时,才回落到已启用档中的最高等级。未匹配+模型在没有显式绑定默认值时从 `off` 开始,但 Composer 仍提供完整思考等级供用户+手动启用。这是一个仅创建时的默认值,绝不会重写现有会话的存储选择。未固定的会话仍在 list/get/create/fork/configure 上展示该继承默认模型的推理能力;丰富步骤不会写入 `providerId`/`modelId`。桌面创建会话时会把当时的@@ -243,8 +243,9 @@ type ModelCatalogItem = {有资格出现在 Composer 中。组合 Composer 菜单打开时,渲染器会在进入“模型”子菜单前开始加载提供商模型。-因此首个可见行优先来自缓存目录或已配置绑定,实时发现仍在后台更新。非空的已配置-别名会根据等价模型 ID 从绑定中解析,并在目录刷新期间保持为唯一可见的模型名称。+因此首个可见行优先来自缓存目录或已配置绑定,实时发现仍在后台更新。模型行显示+配置的线上模型 ID;非空的已配置别名仍会根据准确的绑定解析,并作为选中芯片的+紧凑名称,而不会替换模型身份。## 10. 默认模型策略@@ -260,8 +261,9 @@ type ModelCatalogItem = {会话级别:- 创建时继承应用默认,并写入该 `providerId`/`modelId`- 之后改设置里的默认模型只作用于新会话和未持久化的首页草稿,不改已创建会话-- 将思维初始化到所选模型绑定的默认思考等级(钳位到已启用档;- 未设置时才回落最高已启用档),当它支持推理时,否则 `off`+- 已匹配目录的推理模型从绑定默认思考等级开始(钳位到已启用档;未设置时回落+ 最高已启用档);未匹配模型在没有显式绑定默认值时从 `off` 开始,但 Composer+ 仍提供思考等级供手动启用- 可以独立覆盖## 11. 能力门控@@ -282,10 +284,12 @@ type ModelCatalogItem = {2、完整的pi模型记录,权威; cached/discovered 模型功能和遗留提供程序覆盖不能取代其推理旗帜或思维层面的地图。-3. pi 中不存在的自由格式 id 是未知的通用模型,并且仅公开- `off`; UI 无法将其提升为具有推理能力。-4. 仅当解析的 pi 模型支持时,Composer 才会渲染选择器- 推理并仅列出已解析的 `supportedThinkingLevels`。+3. pi 中不存在的自由格式 id 在 host 能力快照中仍是未知通用模型。Composer 对+ 未匹配模型提供七个规范思考等级供用户手动启用;没有存储的绑定默认值时,草稿+ 和新会话从 `off` 开始。空的绑定等级数组只是未知模型的通用种子,不会覆盖这条+ 阶梯;非空的显式 binding 覆盖仍然优先。+4. Composer 按规范顺序渲染有效的绑定等级;目录命中时使用已发布的模型等级,+ 未命中时使用完整规范阶梯。5. 如果 stored/requested 级别不可用,请选择最近支持的级别通过先向上然后向下扫描来调整水平。非推理模型始终解析为 `off`。@@ -295,35 +299,29 @@ type ModelCatalogItem = {### 11.2 目录元数据的模型 ID 匹配目录补全使用 `catalogModelIdsMatch`,不使用解析已配置绑定身份的共享-`modelIdsMatch`。绑定身份接受不区分大小写的完整 ID、完整斜杠路径后缀、-已知厂商的 `-`/`.` 前缀,以及仅有一侧带 `@region` 的别名;两个不同地区、-任意路由前缀或思考/端点后缀不会合并为同一绑定。-元数据查询还可以匹配 `proxy/` 或 `custom/` 等通用路由下的完整裸叶子 ID,-但必须避免已知厂商冲突;两个不同的完整路由路径不会仅因叶子相同而匹配。-它只会剥离末尾以 `-` 或 `:` 分隔的 `thinking`、-`think`、`agent`、`latest`(也可在 `@region` 之前),不会剥离任意短横线代理-前缀或 `low`、`high`、`max` 等 effort 后缀。--完全匹配不到时走兜底:取「服务名去掉一层路由前缀」后对应的完整已发布 ID(`test/mimo-v2.5`),-以及再去掉一个部署标记后的完整 ID(`mimo-v2.5-pro-test`、`gemini-2.5-pro-1m`)。只有表示-已发布模型变体的标记才会这样处理 —— `-test`、`-preview`、`-beta`、`-1m`、`-128k`;`-asr`、-`-tts`、`-pro` 是独立的模型,带这类后缀且未发布的 ID 仍保持未知,不会继承同类模型的窗口。-该兜底只读取一个完整的已发布 ID,不串接多层别名。--目录索引用这些别名生成有界-候选键,再由匹配器确认;若厂商键或 API URL 已选中已知目录提供商,-查询仅限该提供商,不能借用别家能力。-这些别名只用于附加已发布的元数据,不改变配置的请求模型 ID,后缀本身也-不证明模型有推理能力。未命中的自由格式 ID 仍是无推断能力的未知通用模型;-只有已发布的记录或显式绑定设置可提供能力。+`modelIdsMatch`。绑定身份保留原有的不区分大小写 wire ID、区域、路径后缀与已知+厂商前缀规则。元数据查询本身只取 ID 最后一个 `/` 段并按小写精确比较:+`route/model` 可以命中 `model` 的目录记录,但路由前缀不等于模型身份。索引使用+同一个末段键,因此共享叶子的不同路由会成为候选竞争,而不会自动认定为同一模型。++解析采用保守规则:零个候选保持未匹配,一个候选用于补全;多个候选时,仅当唯一+官方/来源提供商的提供商族与显式来源前缀(`anthropic`、`openai`、`google*`、+`xai`/`x-ai`)一致时优先采用。没有唯一官方命中时,只有所有候选的能力和思考元数据+完全一致才允许补全,否则保持未匹配。匹配器不再剥离 `thinking`、`think`、`agent`、+`latest`、发布日期或部署标记后缀,也不再折叠厂商短横线别名。已知提供商自己的记录+缺失时仍可从其他目录发布方借用完全相同的 ID;未知提供商不再使用无锚点共识或部署+标记兜底。++这些规则只附加已发布元数据,不改写配置中的 wire ID,也不从后缀推断推理能力。未匹配+的自由格式 ID 在 host 侧保留通用能力快照,而 Composer 提供完整规范思考阶梯供用户+手动启用。#### 11.3.1 跨发布方的同名 ID 兜底models.dev 把网关上的模型副本记在拥有权重的厂商名下,因此返回 `Vendor/Model` 这类 ID 的端点-自身可能没有记录,而其他发布方声明了完全相同的 ID。当行解析到某个目录提供商、而它自己没有这条-记录时,`findModel` 改为读取声明该 **完全相同** ID 的其他发布方,而不是把模型留在通用的-128k 纯文本形态(issue #938);当没有任何发布方声明该 ID 时,读取「服务名去掉前缀与部署标记后」-对应的完整已发布 ID(见 §11.2)。+自身可能没有记录,而其他发布方声明了完全相同的 ID。当行解析到明确的目录提供商、而它自己没有这条+记录时,`findModel` 可以读取声明该 **完全相同** ID 的其他发布方,而不是把模型留在通用的+128k 纯文本形态(issue #938)。借用是有边界的:@@ -331,17 +329,14 @@ models.dev 把网关上的模型副本记在拥有权重的厂商名下,因此始终优先。- 与行的端点同址的提供商是行的别名,不是独立来源:它对这条 ID 的沉默就是对该部署的回答,不会越过它去借用。-- 只转移大小写不敏感的完全相同 ID,或「服务名去掉前缀与部署标记后」对应的完整已发布 ID- (`test/mimo-v2.5-pro-test` → `mimo-v2.5-pro`)。通过别名命中的记录是另一条 ID,- 保留它自己的窗口。-- app 自带 provider 的发布方先于任意中转商回答,顺序与「认不出发布方」时一致:被自带发布方声明的- ID 描述的是这个模型,中转商自己的副本描述的是它的部署。该层级内,与请求 ID 完全相同的记录优先于- 另一种拼写的同名记录,因此只列了文本那一半的副本不能把模型自己声明的视觉能力压掉。+- 只转移大小写不敏感的完全相同 ID。通过末段候选或其他非精确拼写命中的记录不参与该兜底。+- app 自带 provider 的发布方先于任意中转商回答,但只针对完全相同的请求 ID。通过另一种拼写命中的+ 副本不能收窄或扩张模型自身声明的视觉能力。- 工具能力按声明它的发布方多数决:错误的 `true` 会把工具声明放到线上、可能被端点拒绝,但一个持不同意见的中转商也不应让上百家一致同意的记录作废;票数持平则不声明。其余能力取交集,因此借用只可能低估 —— 知道端点支持更多的用户仍可在「高级」里打开。窗口取各发布方声明值的中位数,而不是某一家的上限。-- 没有任何发布方声明该 ID 时,它保持为未知的通用模型。+- 没有任何发布方声明该 ID 时,它保持为未知的通用模型,不再走部署标记或无锚点共识兜底。这只改变元数据:配置的线上 ID、提供商身份,以及 §11.3 的绑定优先级都不变。@@ -391,8 +386,9 @@ Electron 使用本地 `models.dev` 记录装饰缓存和新发现的模型行。刷新使缓存的选择器保持填充状态- [ ] 能力徽章可见- [ ] 会话模型更改仅适用于下一回合-- [ ] 新会话将具有推理能力的继承模型默认为该绑定存储的默认- 思考等级(钳位到已启用档;未设置时才用最高已启用档),否则默认为 `off`+- [ ] 目录命中的推理模型新会话默认为该绑定存储的思考等级+ (钳位到已启用档;未设置时才用最高已启用档);未匹配模型没有显式绑定默认值+ 时从 `off` 开始,但 Composer 仍保留手动思考阶梯- [ ] 推理选择器是能力门控和 pi 发布的稀疏级别在 Composer、Electron main 和 pi sidecar 中以相同的方式设置钳位- [ ] 提供程序设置和缓存发现无法覆盖已知的 pi 模型diff --git a/docs/zh-CN/spec/04-ux/08-component-spec.md b/docs/zh-CN/spec/04-ux/08-component-spec.mdindex c70ad4e8d..2d0621f10 100644--- a/docs/zh-CN/spec/04-ux/08-component-spec.md+++ b/docs/zh-CN/spec/04-ux/08-component-spec.md@@ -2003,7 +2003,7 @@ MainChat 底部的输入区域,用于撰写和发送提示。支持多行输| 闲置(无模型) | 文本区域处于活动状态,发送按钮已禁用 + 工具提示“首先配置模型” | Agent 链接在模型菜单中仍然可用 || 空闲(就绪) | 文本区域处于活动状态,发送按钮已启用 | 发送活动 || Home/new-session 初始化 | 当没有投影活动会话时,textarea 和 mode/thinking/permission 触发器仍然可用;第一个配置选择保留在未持久化的草稿上,并在第一条消息创建会话时应用 | 配置草稿,然后发送 |-| 新会话(推理模型) | 模型 × 推理芯片显示模型及其绑定的默认思考等级 | 用户可以选择绑定已启用的任何级别,包括支持时关闭 |+| 新会话(推理模型) | 模型 × 推理芯片显示模型及其绑定的默认思考等级;未匹配模型从关闭开始但保留手动阶梯 | 用户可以选择绑定已启用的任何级别,未匹配模型可以选择任意规范级别 || 新会话/在另一个会话运行时切换 | 文本区域处于活动状态,为目标会话自己的运行状态启用发送按钮 | 发送活动;除非目标会话正在运行且草稿为空,否则停止隐藏 || 跑步 | textarea 和 mode/thinking/permission 控件在下一回合中保持可编辑状态;单一提交槽位在草稿为空时显示停止,有内容时显示发送 | 草稿为空时停止活动;有内容时发送活动;配置已排队 || 上下文检查点 | 与运行直到持久检查点完成相同;中间 `turn_end` 不会重新激活控件。保留尾部回退保持运行并显示警告 toast | 与运行状态相同的单一停止/发送槽位行为 |@@ -2103,10 +2103,10 @@ MainChat 底部的输入区域,用于撰写和发送提示。支持多行输已启用;第一个配置操作创建或重用目标草稿,然后保留所选模式、思维级别或权限模式。正在运行的回合或等待批准仍然会限制这些控制。-- 继承默认模型支持推理的新会话以该模型存储的默认思考等级启用,- 并钳位到已启用档;绑定没有默认值时才回落到最高已启用档。非推理- 模型和缺失的功能元数据从 `off` 开始;重新打开或重复使用- 现有会话保留其持久选择。+- 目录命中的继承默认模型支持推理时,新会话以该模型存储的默认思考等级启用,+ 并钳位到已启用档;绑定没有默认值时才回落到最高已启用档。未匹配模型没有+ 显式绑定默认值时从 `off` 开始,但 Composer 仍保留完整规范阶梯供手动启用。+ 重新打开或重复使用现有会话保留其持久选择。- 模型菜单仅列出已启用、可运行且已配置模型绑定的提供商。缓存或实时发现的结果可以为这些已配置模型补充信息,但未配置的发现结果不会出现在对话区列表中;发现不可用时仍显示已配置的模型 ID。diff --git a/docs/zh-CN/spec/08-meta/decisions-log.md b/docs/zh-CN/spec/08-meta/decisions-log.mdindex a17e6eacd..a9dc2f3fc 100644--- a/docs/zh-CN/spec/08-meta/decisions-log.md+++ b/docs/zh-CN/spec/08-meta/decisions-log.md@@ -5077,3 +5077,20 @@ Markdown 源码,不是 `text/html` 负载;对禁用行内 HTML 的外部编无需数据库迁移或 Host 协议版本变更。- 覆盖:`apps/desktop/test/update-preference.test.mjs`、更新后的`apps/desktop/test/auto-update.test.mjs` 与 E2E-UPDATE-preference-and-once-only-reminder。++## 2026-09-27 —— 路由模型元数据采用保守的末段匹配(D629,PR #1047)++- 取代 D622 中用于运行期补全的宽泛目录别名。只比较大小写不敏感的最后一个 `/` 段,+ 让路由或网关 wire ID 可以命中目录记录,同时不再把任意 thinking、发布日期、部署标记+ 或厂商短横线后缀当作模型身份。+- 一个叶子对应多个目录候选时,只有官方/来源提供商的提供商族与显式模型来源一致才优先+ 采用唯一官方命中;否则只有所有候选的能力和思考元数据完全一致时才借用。两条规则都+ 无法证明身份时保持未匹配。已知提供商仍可从其他发布方借用完全相同的 ID;未知提供商+ 不使用无锚点共识或部署标记兜底。+- Composer 模型行保留完整的配置 wire ID。未匹配模型提供规范思考阶梯供手动启用,但+ 新草稿/会话在没有显式绑定默认值时从 `off` 开始。空的绑定等级数组是未知模型的通用+ 种子而不是显式禁用;非空 binding 覆盖仍然有效。目录命中的模型保留 D303 的绑定默认值+ 与最高已启用档回退行为。+- 该变化只影响元数据和 UI 投影,不改写持久化 wire ID、提供商身份或 host 能力归属。参见+ `03-runtime/13-model-catalog-and-selection.md` §11.3 与+ `04-ux/08-component-spec.md` §11。diff --git a/packages/shared/src/thinking-levels.test.ts b/packages/shared/src/thinking-levels.test.tsindex a313ba310..2ba9ee0c3 100644--- a/packages/shared/src/thinking-levels.test.ts+++ b/packages/shared/src/thinking-levels.test.ts@@ -2,6 +2,7 @@ import { describe, expect, it } from "vitest";import {highestSupportedThinkingLevel,initialThinkingLevelForBinding,+ initialThinkingLevelForUnmatchedModel,canonicalThinkingLevel,isSessionThinkingLevel,nearestSupportedThinkingLevel,@@ -54,14 +55,14 @@ describe("initialThinkingLevelForBinding", () => {).toBe("high");});- it("defaults to off when no default is stored", () => {+ it("falls back to the strongest enabled level when no default is stored", () => {expect(initialThinkingLevelForBinding({thinkingLevels: ["low", "high", "max"],defaultThinkingLevel: null,}),- ).toBe("off");- expect(initialThinkingLevelForBinding(undefined, ["low", "high"])).toBe("off");+ ).toBe("max");+ expect(initialThinkingLevelForBinding(undefined, ["low", "high"])).toBe("high");});it("honors an explicit off default and empty bindings", () => {@@ -80,6 +81,24 @@ describe("initialThinkingLevelForBinding", () => {});});+describe("initialThinkingLevelForUnmatchedModel", () => {+ it("starts unmatched models at off without overriding an explicit default", () => {+ expect(+ initialThinkingLevelForUnmatchedModel({+ thinkingLevels: ["low", "high", "max"],+ defaultThinkingLevel: null,+ }),+ ).toBe("off");+ expect(initialThinkingLevelForUnmatchedModel(undefined, ["low", "high"])).toBe("off");+ expect(+ initialThinkingLevelForUnmatchedModel({+ thinkingLevels: ["low", "high"],+ defaultThinkingLevel: "low",+ }),+ ).toBe("low");+ });+});+describe("publishedThinkingLevels", () => {it("returns the published levels in canonical order", () => {expect(publishedThinkingLevels({diff --git a/packages/shared/src/thinking-levels.ts b/packages/shared/src/thinking-levels.tsindex 7efac537b..bc521a57d 100644--- a/packages/shared/src/thinking-levels.ts+++ b/packages/shared/src/thinking-levels.ts@@ -88,23 +88,46 @@ export function nearestSupportedThinkingLevel(return "off";}-/**- * Thinking level a new draft or session starts at for a model binding.- *- * Prefer an explicitly stored default when it is still enabled, including- * `omit` on a reasoning binding. Otherwise clamp that explicit default onto- * the enabled ladder. With no stored default, start at `off`; available- * reasoning levels remain selectable but are never enabled implicitly.- */-export function initialThinkingLevelForBinding(+function initialThinkingLevelForBindingInternal(binding: ThinkingLevelBindingSource | null | undefined,fallbackLevels?: readonly ThinkingLevel[],+ defaultToOff = false,): SessionThinkingLevel {const enabled = binding?.thinkingLevels ?? fallbackLevels;const stored = binding?.defaultThinkingLevel;if (stored === "omit") return enablesReasoning(enabled) ? "omit" : "off";if (stored != null) return nearestSupportedThinkingLevel(stored, enabled);- return "off";+ return defaultToOff ? "off" : highestSupportedThinkingLevel(enabled);+}++/**+ * Thinking level a new draft or session starts at for a known model binding.+ *+ * Prefer the stored default when it is still enabled, including `omit` on a+ * reasoning binding. Otherwise clamp that default onto the enabled ladder.+ * With no stored default, fall back to the strongest enabled level so a+ * reasoning model never starts at `off` merely because Settings has not+ * picked a default yet.+ */+export function initialThinkingLevelForBinding(+ binding: ThinkingLevelBindingSource | null | undefined,+ fallbackLevels?: readonly ThinkingLevel[],+): SessionThinkingLevel {+ return initialThinkingLevelForBindingInternal(binding, fallbackLevels);+}++/**+ * Thinking level for a model absent from the catalog.+ *+ * An explicit binding default still wins, but an unknown model must not+ * enable reasoning implicitly. Its available levels remain selectable in the+ * Composer while a new draft/session starts at `off`.+ */+export function initialThinkingLevelForUnmatchedModel(+ binding: ThinkingLevelBindingSource | null | undefined,+ fallbackLevels?: readonly ThinkingLevel[],+): SessionThinkingLevel {+ return initialThinkingLevelForBindingInternal(binding, fallbackLevels, true);}/** Published record a thinking-level candidate list can be derived from. */