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(provider): support Claude Opus 5.5 adaptive thinking
zszz3c4fd6b289fad
diff --git a/apps/desktop/electron/main/models-dev-catalog.ts b/apps/desktop/electron/main/models-dev-catalog.tsindex 8788b9fe9..eb830dca4 100644--- a/apps/desktop/electron/main/models-dev-catalog.ts+++ b/apps/desktop/electron/main/models-dev-catalog.ts@@ -18,6 +18,7 @@ import type {ModelProviderMetadata,ModelReasoningOption,ThinkingLevel,+ ThinkingProtocol,} from "@pi-desktop/shared";import { genericModelConfig, type ModelConfig } from "@pi-desktop/agent-runtime";@@ -76,6 +77,7 @@ export type ModelsDevModel = {reasoning: boolean;reasoningPublished: boolean;reasoningOptions?: ModelReasoningOption[];+ thinkingProtocol?: ThinkingProtocol;thinkingLevels: ThinkingLevel[];modalities: ModelModalities;modalitiesPublished: boolean;@@ -416,6 +418,10 @@ function modelFromRaw(const reasoningPublished = typeof raw.reasoning === "boolean";const reasoning = raw.reasoning === true;const reasoningOptions = parseReasoningOptions(raw.reasoning_options);+ const thinkingProtocol: ThinkingProtocol | undefined =+ providerKey === "anthropic" && reasoningOptions?.some((option) => option.type === "effort")+ ? "adaptive"+ : undefined;const limit = parseLimit(raw.limit);const experimental = publishedExperimental(raw.experimental);const providerMetadata = publishedMetadata(raw.provider);@@ -442,6 +448,7 @@ function modelFromRaw(reasoning,reasoningPublished,...(reasoningOptions ? { reasoningOptions } : {}),+ ...(thinkingProtocol ? { thinkingProtocol } : {}),thinkingLevels: thinkingLevelsFromModelsDev(reasoning, raw.reasoning_options),modalities: modalityResult.modalities,modalitiesPublished: modalityResult.published,@@ -717,6 +724,7 @@ export function modelInfoFromModelsDev(...(model.attachment !== undefined ? { attachment: model.attachment } : {}),reasoning: model.reasoning,...(model.reasoningOptions !== undefined ? { reasoningOptions: model.reasoningOptions } : {}),+ ...(model.thinkingProtocol !== undefined ? { thinkingProtocol: model.thinkingProtocol } : {}),...(thinkingLevelMap !== undefined ? { thinkingLevelMap } : {}),...(model.toolCall !== undefined ? { toolCall: model.toolCall } : {}),...(model.structuredOutput !== undefined ? { structuredOutput: model.structuredOutput } : {}),@@ -783,6 +791,7 @@ export function modelConfigFromModelsDev(if (model.family !== undefined) config.family = model.family;if (model.attachment !== undefined) config.attachment = model.attachment;if (model.reasoningOptions !== undefined) config.reasoningOptions = model.reasoningOptions;+ if (model.thinkingProtocol !== undefined) config.thinkingProtocol = model.thinkingProtocol;const thinkingLevelMap = thinkingLevelMapFromModelsDev(model.reasoningOptions, thinkingLevels);if (thinkingLevelMap) config.thinkingLevelMap = thinkingLevelMap;if (model.toolCall !== undefined) config.toolCall = model.toolCall;diff --git a/apps/desktop/src/components/settings/ModelSelectionPanes.tsx b/apps/desktop/src/components/settings/ModelSelectionPanes.tsxindex 3ce419e54..640eec376 100644--- a/apps/desktop/src/components/settings/ModelSelectionPanes.tsx+++ b/apps/desktop/src/components/settings/ModelSelectionPanes.tsx@@ -26,6 +26,7 @@ import {type ModelInfo,type SessionThinkingLevel,type ThinkingLevel,+ type ThinkingProtocol,} from "@pi-desktop/shared";import {CONTEXT_WINDOW_PRESETS,@@ -809,34 +810,63 @@ export function ModelSelectionPanes({<HelpIcon label={t("settings.thinkingManualOverrideHint")} />) : null}</span>- {bindingDefaultThinkingMenuLevels(enabledLevels).length > 1 ? (- <div className="provider-chosen-thinking-default">+ <div className="provider-chosen-thinking-controls">+ <div className="provider-chosen-thinking-protocol"><span className="provider-chosen-thinking-label">- {t("settings.defaultThinkingLevel")}+ {t("settings.thinkingProtocol")}</span><SettingsMenuSelectclassName="provider-chosen-thinking-select"- label={t("settings.defaultThinkingLevel")}+ label={t("settings.thinkingProtocol")}value={- resolveBindingDefaultThinkingLevel(- binding.defaultThinkingLevel,- enabledLevels,- ) ?? ""+ binding.thinkingProtocol ?? info?.thinkingProtocol ?? "legacy"}onChange={(id) =>updateBinding(binding.id, {- defaultThinkingLevel: id as SessionThinkingLevel,+ thinkingProtocol: id as ThinkingProtocol,})}- options={bindingDefaultThinkingMenuLevels(enabledLevels).map(- (level) => ({- id: level,- label: level,- }),- )}+ options={[+ {+ id: "legacy",+ label: t("settings.thinkingProtocolLegacy"),+ },+ {+ id: "adaptive",+ label: t("settings.thinkingProtocolAdaptive"),+ },+ ]}/></div>- ) : null}+ {bindingDefaultThinkingMenuLevels(enabledLevels).length > 1 ? (+ <div className="provider-chosen-thinking-default">+ <span className="provider-chosen-thinking-label">+ {t("settings.defaultThinkingLevel")}+ </span>+ <SettingsMenuSelect+ className="provider-chosen-thinking-select"+ label={t("settings.defaultThinkingLevel")}+ value={+ resolveBindingDefaultThinkingLevel(+ binding.defaultThinkingLevel,+ enabledLevels,+ ) ?? ""+ }+ onChange={(id) =>+ updateBinding(binding.id, {+ defaultThinkingLevel: id as SessionThinkingLevel,+ })+ }+ options={bindingDefaultThinkingMenuLevels(enabledLevels).map(+ (level) => ({+ id: level,+ label: level,+ }),+ )}+ />+ </div>+ ) : null}+ </div></div><divclassName="provider-chosen-thinking-chips"diff --git a/apps/desktop/src/components/settings/provider-copy.ts b/apps/desktop/src/components/settings/provider-copy.tsindex ae66b704c..54b06748b 100644--- a/apps/desktop/src/components/settings/provider-copy.ts+++ b/apps/desktop/src/components/settings/provider-copy.ts@@ -40,6 +40,9 @@ export function copyProviderConfiguration(provider: ProviderPublic, name: string: {}),thinkingLevels: [...model.thinkingLevels],defaultThinkingLevel: model.defaultThinkingLevel,+ ...(model.thinkingProtocol !== undefined+ ? { thinkingProtocol: model.thinkingProtocol }+ : {}),...(model.supportsImages !== undefined ? { supportsImages: model.supportsImages } : {}),...(model.supportsDocuments !== undefined ? { supportsDocuments: model.supportsDocuments } : {}),...(model.availableForSubagents !== undefined ? { availableForSubagents: model.availableForSubagents } : {}),diff --git a/apps/desktop/src/styles/model-config.css b/apps/desktop/src/styles/model-config.cssindex e5c51e9fb..0818a2762 100644--- a/apps/desktop/src/styles/model-config.css+++ b/apps/desktop/src/styles/model-config.css@@ -1189,10 +1189,14 @@}.provider-chosen-thinking-head {- display: flex;+ display: grid;+ grid-template-columns: minmax(0, 1fr) auto;align-items: center;- flex-wrap: wrap;- gap: 4px 8px;+ gap: 4px 12px;+ min-width: 0;+}++.provider-chosen-thinking-head > .provider-chosen-thinking-label {min-width: 0;}@@ -1216,11 +1220,18 @@line-height: var(--leading-normal);}-.provider-chosen-thinking-default {+.provider-chosen-thinking-controls {+ display: flex;+ align-items: center;+ justify-self: end;+ gap: 12px;+}++.provider-chosen-thinking-default,+.provider-chosen-thinking-protocol {display: flex;align-items: center;gap: 6px;- margin-left: auto;}/* The row body keeps its own compact field metric (28px inputs and selects), so@@ -1902,6 +1913,19 @@grid-template-columns: repeat(4, minmax(0, 1fr));}+ .provider-chosen-thinking-head {+ grid-template-columns: minmax(0, 1fr) auto;+ }++ .provider-chosen-thinking-head > .provider-chosen-thinking-label {+ grid-column: 1 / -1;+ }++ .provider-chosen-thinking-controls {+ grid-column: 1 / -1;+ justify-self: end;+ }+}@media (prefers-reduced-motion: reduce) {diff --git a/apps/desktop/test/model-advanced-capabilities.test.mjs b/apps/desktop/test/model-advanced-capabilities.test.mjsindex ac58b731e..dca4e022b 100644--- a/apps/desktop/test/model-advanced-capabilities.test.mjs+++ b/apps/desktop/test/model-advanced-capabilities.test.mjs@@ -47,6 +47,17 @@ test("advanced settings choose the default thinking level among omit and the enaassert.match(pickerSource, /bindingDefaultThinkingMenuLevels\(enabledLevels\)\.length > 1 \?/);});+test("advanced settings expose the model thinking protocol", () => {+ assert.match(pickerSource, /settings\.thinkingProtocol/);+ assert.match(pickerSource, /settings\.thinkingProtocolLegacy/);+ assert.match(pickerSource, /settings\.thinkingProtocolAdaptive/);+ assert.match(+ pickerSource,+ /binding\.thinkingProtocol\s*\?\?\s*info\?\.thinkingProtocol\s*\?\?\s*"legacy"/,+ );+ assert.match(pickerSource, /thinkingProtocol: id as ThinkingProtocol/);+});+test("the capability checkboxes show and follow the published value", () => {assert.match(pickerSource, /settings\.imageInput/);assert.match(pickerSource, /settings\.documentInput/);diff --git a/apps/desktop/test/models-dev-catalog.test.mjs b/apps/desktop/test/models-dev-catalog.test.mjsindex 69ed8a846..247639fe7 100644--- a/apps/desktop/test/models-dev-catalog.test.mjs+++ b/apps/desktop/test/models-dev-catalog.test.mjs@@ -891,6 +891,7 @@ test("models.dev records retain all published model parameters and modalities",assert.deepEqual(config.input, ["text", "image"]);assert.deepEqual(config.modalities, info.modalities);assert.deepEqual(config.supportedThinkingLevels, ["low", "medium", "high", "xhigh", "max"]);+ assert.equal(config.thinkingProtocol, "adaptive");assert.deepEqual(config.thinkingLevelMap, {low: "low",medium: "medium",diff --git a/crates/host-core/src/plugins/providers.rs b/crates/host-core/src/plugins/providers.rsindex 88e1e5a61..9b6f9a207 100644--- a/crates/host-core/src/plugins/providers.rs+++ b/crates/host-core/src/plugins/providers.rs@@ -182,6 +182,10 @@ pub(crate) fn declared_providers(manifest: &PluginManifest) -> Vec<DeclaredPlugi.unwrap_or(0),thinking_levels: declared_thinking_levels(model),default_thinking_level: declared_default_thinking_level(model),+ thinking_protocol: model+ .get("thinkingProtocol")+ .and_then(Value::as_str)+ .map(str::to_string),supports_images: model.get("supportsImages").and_then(Value::as_bool),diff --git a/crates/host-core/src/providers/catalog.rs b/crates/host-core/src/providers/catalog.rsindex 5d6d13c57..ab1567189 100644--- a/crates/host-core/src/providers/catalog.rs+++ b/crates/host-core/src/providers/catalog.rs@@ -7,6 +7,7 @@ pub(crate) const PROVIDER_SELECT: &str =pub(crate) const CANONICAL_THINKING_LEVELS: &[&str] =&["off", "minimal", "low", "medium", "high", "xhigh", "max"];+const THINKING_PROTOCOLS: &[&str] = &["legacy", "adaptive"];/// Recognised per-limit provenance markers. Anything else is dropped so a/// row always falls back to the documented rule instead of a third state no/// reader understands.@@ -37,6 +38,11 @@ pub(crate) fn normalize_model_bindings(bindings: &[ModelBinding]) -> Vec<ModelBireturn None;}let thinking_levels = normalize_thinking_levels(&binding.thinking_levels);+ let thinking_protocol = binding+ .thinking_protocol+ .as_deref()+ .filter(|protocol| THINKING_PROTOCOLS.contains(protocol))+ .map(str::to_string);let default_thinking_level = binding.default_thinking_level.as_deref()@@ -70,6 +76,7 @@ pub(crate) fn normalize_model_bindings(bindings: &[ModelBinding]) -> Vec<ModelBi},thinking_levels,default_thinking_level,+ thinking_protocol,supports_images: binding.supports_images,supports_documents: binding.supports_documents,available_for_subagents: binding.available_for_subagents,@@ -92,6 +99,7 @@ fn legacy_model_binding(model_id: Option<String>) -> Vec<ModelBinding> {max_tokens: DEFAULT_MAX_TOKENS,thinking_levels: Vec::new(),default_thinking_level: None,+ thinking_protocol: None,supports_images: None,supports_documents: None,available_for_subagents: None,@@ -376,6 +384,7 @@ mod tests {max_tokens: DEFAULT_MAX_TOKENS,thinking_levels: Vec::new(),default_thinking_level: None,+ thinking_protocol: None,supports_images: None,supports_documents: None,available_for_subagents: None,diff --git a/crates/host-core/src/providers/model.rs b/crates/host-core/src/providers/model.rsindex a3c4f7e09..40f590012 100644--- a/crates/host-core/src/providers/model.rs+++ b/crates/host-core/src/providers/model.rs@@ -152,6 +152,9 @@ pub struct ModelBinding {#[serde(default)]pub thinking_levels: Vec<String>,pub default_thinking_level: Option<String>,+ /// Provider request protocol used when thinking is enabled.+ #[serde(default, skip_serializing_if = "Option::is_none")]+ pub thinking_protocol: Option<String>,/// Attachment capability overrides. `None` follows the published catalog/// capability, so a models.dev correction still reaches a saved binding.#[serde(default, skip_serializing_if = "Option::is_none")]diff --git a/crates/host-core/src/providers/tests.rs b/crates/host-core/src/providers/tests.rsindex b2bc349b0..3a6e9ec0f 100644--- a/crates/host-core/src/providers/tests.rs+++ b/crates/host-core/src/providers/tests.rs@@ -168,6 +168,7 @@ fn model_bindings_roundtrip_and_legacy_model_migrates_on_read() {max_tokens: 16_000,thinking_levels: vec!["high".into(), "medium".into()],default_thinking_level: Some("medium".into()),+ thinking_protocol: Some("adaptive".into()),supports_images: Some(true),supports_documents: None,available_for_subagents: Some(true),@@ -182,6 +183,7 @@ fn model_bindings_roundtrip_and_legacy_model_migrates_on_read() {max_tokens: 8_192,thinking_levels: vec![],default_thinking_level: None,+ thinking_protocol: None,supports_images: None,supports_documents: Some(false),available_for_subagents: None,@@ -290,6 +292,7 @@ fn binding_with_alias(id: &str, alias: Option<&str>) -> ModelBinding {max_tokens: DEFAULT_MAX_TOKENS,thinking_levels: Vec::new(),default_thinking_level: None,+ thinking_protocol: None,supports_images: None,supports_documents: None,available_for_subagents: None,@@ -311,6 +314,22 @@ fn normalize_model_bindings_trims_aliases_and_drops_blank_ones() {assert_eq!(normalized[3].alias, None);}+#[test]+fn normalize_model_bindings_preserves_known_thinking_protocols_only() {+ let normalized = normalize_model_bindings(&[+ ModelBinding {+ thinking_protocol: Some("adaptive".into()),+ ..binding_with_alias("adaptive-model", None)+ },+ ModelBinding {+ thinking_protocol: Some("unsupported".into()),+ ..binding_with_alias("legacy-model", None)+ },+ ]);+ assert_eq!(normalized[0].thinking_protocol.as_deref(), Some("adaptive"));+ assert_eq!(normalized[1].thinking_protocol, None);+}+#[test]fn alias_survives_the_provider_config_round_trip() {let bindings = vec![@@ -1187,6 +1206,7 @@ fn binding_with_limits(id: &str, context_window: u32, max_tokens: u32) -> ModelBmax_tokens,thinking_levels: Vec::new(),default_thinking_level: None,+ thinking_protocol: None,supports_images: None,supports_documents: None,available_for_subagents: None,diff --git a/docs/spec/03-runtime/11-provider-model-system.md b/docs/spec/03-runtime/11-provider-model-system.mdindex 433ef74cd..44387b834 100644--- a/docs/spec/03-runtime/11-provider-model-system.md+++ b/docs/spec/03-runtime/11-provider-model-system.md@@ -384,6 +384,7 @@ type ModelBinding = {maxTokens: numberthinkingLevels: ThinkingLevel[]defaultThinkingLevel: SessionThinkingLevel | null+ thinkingProtocol?: "legacy" | "adaptive"availableForSubagents?: boolean // opt-in for AI-driven delegation}diff --git a/docs/spec/03-runtime/12-provider-config-schema.md b/docs/spec/03-runtime/12-provider-config-schema.mdindex a2b580f4a..62f5e8f16 100644--- a/docs/spec/03-runtime/12-provider-config-schema.md+++ b/docs/spec/03-runtime/12-provider-config-schema.md@@ -102,6 +102,10 @@ Tables (canonical DDL in [04-data-storage](04-data-storage.md) §4.3–4.4, §4."type": ["string", "null"],"enum": ["off", "minimal", "low", "medium", "high", "xhigh", "max", "omit", null]},+ "thinkingProtocol": {+ "enum": ["legacy", "adaptive"],+ "description": "Provider request protocol used when thinking is enabled; absent preserves legacy behavior."+ },"supportsImages": { "type": ["boolean", "null"] },"supportsDocuments": { "type": ["boolean", "null"] },"availableForSubagents": { "type": "boolean", "default": false }diff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.mdindex c4200cbf0..f889abd0a 100644--- a/docs/spec/06-delivery/04-e2e-test-plan.md+++ b/docs/spec/06-delivery/04-e2e-test-plan.md@@ -183,6 +183,26 @@- Keep validation evidence tied to the commit the gate ran on, plus any latercommit that changes the landed executable content.+### E2E-PROVIDER-adaptive-thinking-protocol++- **Preconditions:** Isolated provider settings fixture with an Anthropic+ Messages provider and models `claude-opus-5-5` and a legacy Claude model;+ no live credentials.+- **Steps:** Open a configured model's Advanced settings, inspect the+ thinking-protocol row, save an adaptive model with `medium`, then submit a+ request through the local Anthropic transport fixture. Repeat with the+ legacy model.+- **Expected:** The adaptive model sends `thinking.type=adaptive` and+ `output_config.effort=medium`; the legacy model sends the existing+ budget-based thinking shape. Omitting the new field on an old binding keeps+ legacy behavior after reload.+- **Specs:** 03-runtime/11-provider-model-system; 03-runtime/12-provider-config-schema.+- **Acceptance:** Provider/model protocol selection and wire compatibility.+- **Milestone:** Maintenance.+- **Status:** Protocol coverage is automated in the agent-runtime provider+ binding tests; desktop settings coverage remains part of the provider model+ configuration E2E fixture.+## 2. Non-goals- Full UI-driven automated coverage; protocol and source-contract automation isdiff --git a/packages/agent-runtime/src/model-capabilities.ts b/packages/agent-runtime/src/model-capabilities.tsindex 3cb939cfb..c31ddbbe4 100644--- a/packages/agent-runtime/src/model-capabilities.ts+++ b/packages/agent-runtime/src/model-capabilities.ts@@ -76,6 +76,7 @@ export function modelConfigWithBinding(| "contextWindowSource"| "maxTokens"| "thinkingLevels"+ | "thinkingProtocol"| "supportsImages"| "supportsDocuments"| "nativeWebSearch"@@ -87,6 +88,12 @@ export function modelConfigWithBinding(binding.thinkingLevels.includes(level),);const thinkingLevelMap = { ...(model.thinkingLevelMap ?? {}) };+ const compat = binding.thinkingProtocol+ ? {+ ...(model.compat ?? {}),+ forceAdaptiveThinking: binding.thinkingProtocol === "adaptive",+ }+ : model.compat;// pi-ai treats xhigh/max as unsupported when their adapter-facing mapping// is absent or null. The explicit binding is authoritative, so an enabled// extended level without a catalog translation must pass through as-is.@@ -123,6 +130,10 @@ export function modelConfigWithBinding(maxTokens: binding.maxTokens,reasoning: enabledThinkingLevels.some((level) => level !== "off"),supportedThinkingLevels: enabledThinkingLevels,+ ...(binding.thinkingProtocol+ ? { thinkingProtocol: binding.thinkingProtocol }+ : {}),+ ...(compat ? { compat } : {}),...(Object.keys(thinkingLevelMap).length > 0 ? { thinkingLevelMap } : {}),...modalityOverride(model, binding),...(binding.nativeWebSearch === true ? { webSearch: true } : {}),diff --git a/packages/agent-runtime/src/provider-binding.test.ts b/packages/agent-runtime/src/provider-binding.test.tsindex bfef94b6a..1290c0d83 100644--- a/packages/agent-runtime/src/provider-binding.test.ts+++ b/packages/agent-runtime/src/provider-binding.test.ts@@ -116,6 +116,94 @@ describe("Anthropic runtime endpoint", () => {expect(result.stopReason).toBe("error");expect(urls).toEqual(["https://gw.example/anthropic/v1/messages?beta=true"]);});++ it("uses adaptive thinking for models explicitly marked adaptive", async () => {+ const provider: RuntimeProviderConfig = {+ ...keyedProvider,+ id: "anthropic-adaptive",+ name: "Anthropic adaptive",+ baseUrl: "https://api.anthropic.com",+ modelId: "claude-opus-5-5",+ apiStyle: "anthropic_messages",+ supportsReasoning: true,+ supportedThinkingLevels: ["off", "medium"],+ modelConfig: {+ source: "models.dev",+ name: "Claude Opus 5.5",+ baseUrl: "https://api.anthropic.com",+ reasoning: true,+ thinkingProtocol: "adaptive",+ thinkingLevelMap: { medium: "medium" },+ input: ["text"],+ contextWindow: 200_000,+ maxTokens: 16_000,+ },+ };+ const model = buildProviderModel(provider);+ const requests: Record<string, unknown>[] = [];+ const fetch = vi.fn(async (_input: RequestInfo | URL, init?: RequestInit) => {+ requests.push(JSON.parse(String(init?.body)) as Record<string, unknown>);+ return new Response("bad request", { status: 400 });+ });++ await createProviderModels(provider, model)+ .streamSimple(+ model,+ { systemPrompt: "system", messages: [{ role: "user", content: "hello", timestamp: Date.now() }], tools: [] },+ { reasoning: "medium", fetch },+ )+ .result();++ expect(model.compat).toMatchObject({ forceAdaptiveThinking: true });+ expect(requests[0]).toMatchObject({+ thinking: { type: "adaptive" },+ output_config: { effort: "medium" },+ });+ });++ it("keeps the legacy budget request for legacy models", async () => {+ const provider: RuntimeProviderConfig = {+ ...keyedProvider,+ id: "anthropic-legacy",+ name: "Anthropic legacy",+ baseUrl: "https://api.anthropic.com",+ modelId: "claude-opus-4-5",+ apiStyle: "anthropic_messages",+ supportsReasoning: true,+ supportedThinkingLevels: ["off", "medium"],+ modelConfig: {+ source: "models.dev",+ name: "Claude Opus 4.5",+ baseUrl: "https://api.anthropic.com",+ reasoning: true,+ reasoningOptions: [{ type: "effort", values: ["low", "medium", "high"] }],+ thinkingProtocol: "legacy",+ input: ["text"],+ contextWindow: 200_000,+ maxTokens: 16_000,+ },+ };+ const model = buildProviderModel(provider);+ const requests: Record<string, unknown>[] = [];+ const fetch = vi.fn(async (_input: RequestInfo | URL, init?: RequestInit) => {+ requests.push(JSON.parse(String(init?.body)) as Record<string, unknown>);+ return new Response("bad request", { status: 400 });+ });++ await createProviderModels(provider, model)+ .streamSimple(+ model,+ { systemPrompt: "system", messages: [{ role: "user", content: "hello", timestamp: Date.now() }], tools: [] },+ { reasoning: "medium", fetch },+ )+ .result();++ expect(model.compat).toMatchObject({ forceAdaptiveThinking: false });+ expect(requests[0]).toMatchObject({+ thinking: { type: "enabled" },+ });+ expect((requests[0].thinking as Record<string, unknown>).budget_tokens).toEqual(expect.any(Number));+ });});describe("Anthropic adaptive thinking from models.dev reasoning options", () => {diff --git a/packages/agent-runtime/src/provider-binding.ts b/packages/agent-runtime/src/provider-binding.tsindex 64fd7cb8a..592a09560 100644--- a/packages/agent-runtime/src/provider-binding.ts+++ b/packages/agent-runtime/src/provider-binding.ts@@ -280,6 +280,11 @@ export function buildProviderModel(...(copilotDefaults ?? {}),...(catalogModel.headers ?? {}),};+ const thinkingProtocolCompat = catalogModel.thinkingProtocol+ ? { forceAdaptiveThinking: catalogModel.thinkingProtocol === "adaptive" }+ : undefined;+ const autoAdaptiveThinking =+ catalogModel.thinkingProtocol === undefined && requiresAdaptiveThinking(catalogModel);// OpenAI-compatible gateways are not guaranteed to implement the newer// `developer` role, even when the selected model supports reasoning. Keep// the broadest Chat Completions wire shape as the default; a catalog/model@@ -290,13 +295,21 @@ export function buildProviderModel(binding.api === "openai-completions"? {...(catalogModel.compat ?? {}),+ ...(thinkingProtocolCompat ?? {}),...(zhipuCompat ?? {}),...(deepseekCompat ?? {}),supportsDeveloperRole: catalogModel.compat?.supportsDeveloperRole === true,}- : binding.api === "anthropic-messages" && requiresAdaptiveThinking(catalogModel)- ? { ...(catalogModel.compat ?? {}), forceAdaptiveThinking: true }- : catalogModel.compat;+ : binding.api === "anthropic-messages" &&+ (catalogModel.thinkingProtocol === "adaptive" || autoAdaptiveThinking)+ ? {+ ...(catalogModel.compat ?? {}),+ ...(thinkingProtocolCompat ?? {}),+ forceAdaptiveThinking: true,+ }+ : thinkingProtocolCompat+ ? { ...(catalogModel.compat ?? {}), ...thinkingProtocolCompat }+ : catalogModel.compat;return {...catalogModel,id: provider.modelId,diff --git a/packages/agent-runtime/src/thinking-level.ts b/packages/agent-runtime/src/thinking-level.tsindex 32cb0625e..791ddb05a 100644--- a/packages/agent-runtime/src/thinking-level.ts+++ b/packages/agent-runtime/src/thinking-level.ts@@ -7,6 +7,7 @@ import type {ModelProviderMetadata,ModelReasoningOption,SessionThinkingLevel,+ ThinkingProtocol,ThinkingLevel,} from "@pi-desktop/shared";@@ -29,6 +30,7 @@ export type ModelConfig = {attachment?: boolean;reasoning: boolean;reasoningOptions?: ModelReasoningOption[];+ thinkingProtocol?: ThinkingProtocol;supportedThinkingLevels?: readonly ThinkingLevel[];thinkingLevelMap?: Partial<Record<ThinkingLevel, string | null>>;toolCall?: boolean;diff --git a/packages/i18n/src/locales/de/index.ts b/packages/i18n/src/locales/de/index.tsindex 1904836e1..00a39b8c3 100644--- a/packages/i18n/src/locales/de/index.ts+++ b/packages/i18n/src/locales/de/index.ts@@ -1449,6 +1449,9 @@ sklm: {"maxOutput": "Maximale Ausgabe","supportedThinkingLevels": "Denkebenen","defaultThinkingLevel": "Standard-Denkebene",+ "thinkingProtocol": "Denkprotokoll",+ "thinkingProtocolLegacy": "Standard",+ "thinkingProtocolAdaptive": "Adaptiv","modelCapabilities": "Fähigkeiten","imageInput": "Bilder","documentInput": "PDF",diff --git a/packages/i18n/src/locales/en/index.ts b/packages/i18n/src/locales/en/index.tsindex dfefe1616..c11cfdf46 100644--- a/packages/i18n/src/locales/en/index.ts+++ b/packages/i18n/src/locales/en/index.ts@@ -1467,6 +1467,9 @@ sklm: {maxOutput: "Max output",supportedThinkingLevels: "Thinking levels",defaultThinkingLevel: "Default thinking level",+ thinkingProtocol: "Thinking protocol",+ thinkingProtocolLegacy: "Standard",+ thinkingProtocolAdaptive: "Adaptive",modelCapabilities: "Capabilities",imageInput: "Images",documentInput: "PDF",diff --git a/packages/i18n/src/locales/es/index.ts b/packages/i18n/src/locales/es/index.tsindex 63cb48ed5..c63e7b3f7 100644--- a/packages/i18n/src/locales/es/index.ts+++ b/packages/i18n/src/locales/es/index.ts@@ -1449,6 +1449,9 @@ sklm: {"maxOutput": "Salida máxima","supportedThinkingLevels": "Niveles de pensamiento","defaultThinkingLevel": "Nivel de pensamiento predeterminado",+ "thinkingProtocol": "Protocolo de pensamiento",+ "thinkingProtocolLegacy": "Estándar",+ "thinkingProtocolAdaptive": "Adaptativo","modelCapabilities": "Capacidades","imageInput": "Imágenes","documentInput": "PDF",diff --git a/packages/i18n/src/locales/fr/index.ts b/packages/i18n/src/locales/fr/index.tsindex 75e40f991..b445386ea 100644--- a/packages/i18n/src/locales/fr/index.ts+++ b/packages/i18n/src/locales/fr/index.ts@@ -1449,6 +1449,9 @@ sklm: {"maxOutput": "Sortie maximale","supportedThinkingLevels": "Niveaux de réflexion","defaultThinkingLevel": "Niveau de réflexion par défaut",+ "thinkingProtocol": "Protocole de réflexion",+ "thinkingProtocolLegacy": "Standard",+ "thinkingProtocolAdaptive": "Adaptatif","modelCapabilities": "Capacités","imageInput": "Images","documentInput": "PDF",diff --git a/packages/i18n/src/locales/ko/index.ts b/packages/i18n/src/locales/ko/index.tsindex 55067dc56..827fd49a4 100644--- a/packages/i18n/src/locales/ko/index.ts+++ b/packages/i18n/src/locales/ko/index.ts@@ -1465,6 +1465,9 @@ sklm: {maxOutput: "최대 출력",supportedThinkingLevels: "생각 수준",defaultThinkingLevel: "기본 생각 수준",+ thinkingProtocol: "사고 프로토콜",+ thinkingProtocolLegacy: "표준",+ thinkingProtocolAdaptive: "적응형",modelCapabilities: "기능",imageInput: "이미지",documentInput: "PDF",diff --git a/packages/i18n/src/locales/pt-BR/index.ts b/packages/i18n/src/locales/pt-BR/index.tsindex d713aa54b..91103e0fc 100644--- a/packages/i18n/src/locales/pt-BR/index.ts+++ b/packages/i18n/src/locales/pt-BR/index.ts@@ -1411,6 +1411,9 @@ export const ptBR = {maxOutput: "Saída máxima",supportedThinkingLevels: "Níveis de raciocínio",defaultThinkingLevel: "Nível de raciocínio padrão",+ thinkingProtocol: "Protocolo de pensamento",+ thinkingProtocolLegacy: "Padrão",+ thinkingProtocolAdaptive: "Adaptativo",modelCapabilities: "Recursos",imageInput: "Imagens",documentInput: "PDF",diff --git a/packages/i18n/src/locales/tr/index.ts b/packages/i18n/src/locales/tr/index.tsindex f422935fe..214acfb62 100644--- a/packages/i18n/src/locales/tr/index.ts+++ b/packages/i18n/src/locales/tr/index.ts@@ -1455,6 +1455,9 @@ sklm: {maxOutput: "En fazla çıktı",supportedThinkingLevels: "Düşünme düzeyleri",defaultThinkingLevel: "Varsayılan düşünme düzeyi",+ thinkingProtocol: "Düşünme protokolü",+ thinkingProtocolLegacy: "Standart",+ thinkingProtocolAdaptive: "Uyarlanabilir",modelCapabilities: "Yetenekler",imageInput: "Görüntüler",documentInput: "PDF",diff --git a/packages/i18n/src/locales/zh-CN/index.ts b/packages/i18n/src/locales/zh-CN/index.tsindex f20603b53..105c91fdf 100644--- a/packages/i18n/src/locales/zh-CN/index.ts+++ b/packages/i18n/src/locales/zh-CN/index.ts@@ -1436,6 +1436,9 @@ sklm: {maxOutput: "最大输出",supportedThinkingLevels: "思考等级",defaultThinkingLevel: "默认思考等级",+ thinkingProtocol: "思考协议",+ thinkingProtocolLegacy: "标准",+ thinkingProtocolAdaptive: "自适应",modelCapabilities: "能力",imageInput: "图片",documentInput: "PDF",diff --git a/packages/i18n/src/locales/zh-TW/index.ts b/packages/i18n/src/locales/zh-TW/index.tsindex 097e46c2a..2cffad9e1 100644--- a/packages/i18n/src/locales/zh-TW/index.ts+++ b/packages/i18n/src/locales/zh-TW/index.ts@@ -1436,6 +1436,9 @@ sklm: {maxOutput: "最大輸出",supportedThinkingLevels: "思考等級",defaultThinkingLevel: "預設思考等級",+ thinkingProtocol: "思考協定",+ thinkingProtocolLegacy: "標準",+ thinkingProtocolAdaptive: "自適應",modelCapabilities: "能力",imageInput: "圖片",documentInput: "PDF",diff --git a/packages/shared/src/model-catalog.ts b/packages/shared/src/model-catalog.tsindex 7fb051c57..f104a9539 100644--- a/packages/shared/src/model-catalog.ts+++ b/packages/shared/src/model-catalog.ts@@ -309,6 +309,7 @@ export function bindingFromModelInfo(model: ModelInfo): ModelBinding {defaultThinkingLevel: thinkingLevels.includes("medium")? "medium": (thinkingLevels[0] ?? null),+ ...(model.thinkingProtocol ? { thinkingProtocol: model.thinkingProtocol } : {}),// Absent overrides keep following models.dev, so a catalog correction still// reaches an already saved binding.supportsImages: null,diff --git a/packages/shared/src/types/models.ts b/packages/shared/src/types/models.tsindex 035da97c8..5b21c5b9c 100644--- a/packages/shared/src/types/models.ts+++ b/packages/shared/src/types/models.ts@@ -9,6 +9,8 @@ export const THINKING_LEVELS = ["max",] as const;export type ThinkingLevel = (typeof THINKING_LEVELS)[number];+export const THINKING_PROTOCOLS = ["legacy", "adaptive"] as const;+export type ThinkingProtocol = (typeof THINKING_PROTOCOLS)[number];/*** Session and subagent selector values. `omit` leaves the provider default* untouched and is not a catalog/binding capability.@@ -224,6 +226,8 @@ export type ModelBinding = {thinkingLevels: ThinkingLevel[];/** Canonical enabled level, or `omit` when new sessions should send no override. */defaultThinkingLevel: SessionThinkingLevel | null;+ /** Provider request protocol used when thinking is enabled. */+ thinkingProtocol?: ThinkingProtocol;/*** User override for image input. `null` or absent follows the published* models.dev capability. Once explicitly selected, either boolean is pinned@@ -309,6 +313,7 @@ export type ModelInfo = {attachment?: boolean;reasoning?: boolean;reasoningOptions?: ModelReasoningOption[];+ thinkingProtocol?: ThinkingProtocol;thinkingLevelMap?: Partial<Record<ThinkingLevel, string | null>>;toolCall?: boolean;structuredOutput?: boolean;