Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion apps/mobile/src/features/threads/threadAgentsPresentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
: [],
)
Expand Down
15 changes: 6 additions & 9 deletions apps/web/src/components/chat/SubagentTooltipContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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) => {
Expand Down
70 changes: 70 additions & 0 deletions packages/client-runtime/src/state/threadExecution.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ import {
deriveThreadActivityRun,
deriveThreadRuntime,
formatModelSelectionEffort,
formatSubagentEffort,
isBackgroundWorkStopPending,
presentPendingBackgroundWork,
presentProviderGoal,
presentRunStop,
readSelectedEffortValue,
threadRuntimeHasInterruptibleRun,
} from "./threadExecution.ts";

Expand Down Expand Up @@ -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", () => {
Expand Down
42 changes: 34 additions & 8 deletions packages/client-runtime/src/state/threadExecution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
type OrchestrationV2PendingBackgroundTask,
type OrchestrationV2ProviderGoal,
type OrchestrationV2ProviderSession,
type ProviderOptionDescriptor,
type ServerProvider,
type ServerProviderModel,
type OrchestrationV2ExecutionNode,
Expand Down Expand Up @@ -234,6 +235,7 @@ export const REASONING_EFFORT_OPTION_IDS: ReadonlyArray<string> = [
"variant",
"reasoning_effort",
"thinking_level",
"thought_level",
];

export function formatModelSelectionEffort(
Expand All @@ -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(
Expand Down Expand Up @@ -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<ProviderOptionDescriptor> = [],
): 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
);
}

Expand Down
Loading