diff --git a/apps/mobile/src/features/threads/threadAgentsPresentation.ts b/apps/mobile/src/features/threads/threadAgentsPresentation.ts index ae1fe531eefb2..270cc1f3d7fbe 100644 --- a/apps/mobile/src/features/threads/threadAgentsPresentation.ts +++ b/apps/mobile/src/features/threads/threadAgentsPresentation.ts @@ -219,7 +219,8 @@ export function workflowMemberMetadata( const effortChoice = provider?.models .find((candidate) => candidate.slug === slug) ?.capabilities?.optionDescriptors?.flatMap((descriptor) => - descriptor.type === "select" && REASONING_EFFORT_OPTION_IDS.includes(descriptor.id) + descriptor.type === "select" && + (descriptor.role === "reasoning" || REASONING_EFFORT_OPTION_IDS.includes(descriptor.id)) ? descriptor.options : [], ) diff --git a/apps/web/src/components/chat/SubagentTooltipContent.tsx b/apps/web/src/components/chat/SubagentTooltipContent.tsx index 229e5eda6a884..722968fb6241a 100644 --- a/apps/web/src/components/chat/SubagentTooltipContent.tsx +++ b/apps/web/src/components/chat/SubagentTooltipContent.tsx @@ -11,12 +11,8 @@ import { resolveSubagentMetadata, subagentDetailPreview, } from "@t3tools/client-runtime/state/subagent-display"; -import { REASONING_EFFORT_OPTION_IDS } from "@t3tools/client-runtime/state/thread-execution"; -import { - DEFAULT_VARIANT_CHOICE_ID, - getModelSelectionStringOptionValue, - resolveSelectableModel, -} from "@t3tools/shared/model"; +import { readSelectedEffortValue } from "@t3tools/client-runtime/state/thread-execution"; +import { resolveSelectableModel } from "@t3tools/shared/model"; import { getTraitsSpeedDisplay, TraitsSpeedIcon } from "./TraitsSpeed"; import { useGT, useMessages } from "gt-react"; import type { ReactNode } from "react"; @@ -83,9 +79,10 @@ export function SubagentTooltipContent(props: { childModel === modelSlug && childSelection?.instanceId === props.providerInstanceId ? childSelection : undefined; - const effort = REASONING_EFFORT_OPTION_IDS.map((id) => - getModelSelectionStringOptionValue(matchingSelection, id), - ).find((value) => value && value !== DEFAULT_VARIANT_CHOICE_ID); + const effort = readSelectedEffortValue( + matchingSelection, + providerModel?.capabilities?.optionDescriptors, + ); const speed = provider ? providerModel?.capabilities?.optionDescriptors ?.map((descriptor) => { diff --git a/packages/client-runtime/src/state/threadExecution.test.ts b/packages/client-runtime/src/state/threadExecution.test.ts index 2984bb97dbaeb..d932e2c0395b3 100644 --- a/packages/client-runtime/src/state/threadExecution.test.ts +++ b/packages/client-runtime/src/state/threadExecution.test.ts @@ -32,10 +32,12 @@ import { deriveThreadActivityRun, deriveThreadRuntime, formatModelSelectionEffort, + formatSubagentEffort, isBackgroundWorkStopPending, presentPendingBackgroundWork, presentProviderGoal, presentRunStop, + readSelectedEffortValue, threadRuntimeHasInterruptibleRun, } from "./threadExecution.ts"; @@ -761,6 +763,74 @@ describe("formatModelSelectionEffort", () => { expect(formatModelSelectionEffort(selection, models)).toBe("Extra High"); }); + + it("reads ACP thought_level and role: reasoning controls for cataloged and uncataloged models", () => { + const models = [ + { + slug: "gemini-4-neon", + name: "Gemini 4 Neon", + isCustom: false, + capabilities: createModelCapabilities({ + optionDescriptors: [ + { + id: "thought_level", + label: "Thinking", + type: "select", + role: "reasoning", + options: [ + { id: "medium", label: "Medium", isDefault: true }, + { id: "high", label: "High" }, + ], + }, + ], + }), + }, + { + slug: "acp-custom-agent", + name: "ACP Custom Agent", + isCustom: false, + capabilities: createModelCapabilities({ + optionDescriptors: [ + { + id: "custom_thinking_mode", + label: "Thinking", + type: "select", + role: "reasoning", + options: [{ id: "deep", label: "Deep" }], + }, + ], + }), + }, + ]; + const antigravitySelection = createModelSelection( + ProviderInstanceId.make("antigravity"), + "gemini-4-neon", + [{ id: "thought_level", value: "high" }], + ); + const customSelection = createModelSelection( + ProviderInstanceId.make("acpRegistry"), + "acp-custom-agent", + [{ id: "custom_thinking_mode", value: "deep" }], + ); + const uncatalogedSelection = createModelSelection( + ProviderInstanceId.make("antigravity"), + "gemini-4-neon-preview", + [{ id: "thought_level", value: "high" }], + ); + + expect(formatModelSelectionEffort(antigravitySelection, models)).toBe("High"); + expect(formatModelSelectionEffort(customSelection, models)).toBe("Deep"); + expect( + formatSubagentEffort({ + modelSlug: "gemini-4-neon-preview", + modelSelection: uncatalogedSelection, + provider: { driver: ProviderDriverKind.make("antigravity"), models }, + }), + ).toBe("high"); + expect( + readSelectedEffortValue(customSelection, models[1]?.capabilities?.optionDescriptors), + ).toBe("deep"); + }); }); describe("isBackgroundWorkStopPending", () => { diff --git a/packages/client-runtime/src/state/threadExecution.ts b/packages/client-runtime/src/state/threadExecution.ts index 74dc3106ca3aa..7e5ad55dc53b2 100644 --- a/packages/client-runtime/src/state/threadExecution.ts +++ b/packages/client-runtime/src/state/threadExecution.ts @@ -16,6 +16,7 @@ import { type OrchestrationV2PendingBackgroundTask, type OrchestrationV2ProviderGoal, type OrchestrationV2ProviderSession, + type ProviderOptionDescriptor, type ServerProvider, type ServerProviderModel, type OrchestrationV2ExecutionNode, @@ -234,6 +235,7 @@ export const REASONING_EFFORT_OPTION_IDS: ReadonlyArray = [ "variant", "reasoning_effort", "thinking_level", + "thought_level", ]; export function formatModelSelectionEffort( @@ -245,11 +247,21 @@ export function formatModelSelectionEffort( if (!caps) return null; const options = withLegacyUltracodeEffort(caps.optionDescriptors, selection.options); const current = options ? { ...selection, options } : selection; - for (const id of REASONING_EFFORT_OPTION_IDS) { - const descriptor = caps.optionDescriptors?.find((candidate) => candidate.id === id); - if (descriptor?.type !== "select") continue; - const value = getProviderOptionStatedValue(id, current, reportedSelection); - if (value === undefined && id !== "variant") continue; + const selectDescriptors = (caps.optionDescriptors ?? []).filter( + (candidate) => candidate.type === "select", + ); + const reasoningDescriptors = [ + ...selectDescriptors.filter((candidate) => candidate.role === "reasoning"), + ...REASONING_EFFORT_OPTION_IDS.flatMap((id) => { + const descriptor = selectDescriptors.find( + (candidate) => candidate.id === id && candidate.role !== "reasoning", + ); + return descriptor ? [descriptor] : []; + }), + ]; + for (const descriptor of reasoningDescriptors) { + const value = getProviderOptionStatedValue(descriptor.id, current, reportedSelection); + if (value === undefined && descriptor.id !== "variant") continue; if (typeof value === "boolean") continue; // Bypass picker normalization so an obsolete choice cannot become a catalog default. const label = getProviderOptionCurrentLabel( @@ -277,10 +289,24 @@ export function formatSubagentEffort(input: { if (provider.models.some((model) => model.slug === modelSlug)) { return formatModelSelectionEffort({ ...selection, model: modelSlug }, provider.models); } + return readSelectedEffortValue(selection); +} + +/** The raw saved effort, preferring the option the model marks as its reasoning control. */ +export function readSelectedEffortValue( + selection: ModelSelection | undefined, + descriptors: ReadonlyArray = [], +): string | null { + const ids = [ + ...descriptors.flatMap((descriptor) => + descriptor.type === "select" && descriptor.role === "reasoning" ? [descriptor.id] : [], + ), + ...REASONING_EFFORT_OPTION_IDS, + ]; return ( - REASONING_EFFORT_OPTION_IDS.map((id) => getModelSelectionStringOptionValue(selection, id)).find( - (value) => value && value !== DEFAULT_VARIANT_CHOICE_ID, - ) ?? null + ids + .map((id) => getModelSelectionStringOptionValue(selection, id)) + .find((value) => value && value !== DEFAULT_VARIANT_CHOICE_ID) ?? null ); }