fix(opencode): fill blank reasoning labels (#14978)
This commit is contained in:
1 parent
ca4f84e702
commit
63f74e209d
16 files changed
+397
-21
No files matched your search
@@ -150,6 +150,7 @@ export interface ThreadComposerProps {
|
||||
*/
|
||||
readonly threadSyncPhase?: "loading" | "syncing" | null;
|
||||
readonly selectedThread: EnvironmentThreadShell;
|
||||
readonly reportedModelSelection?: ModelSelection | null;
|
||||
readonly hasCompactableConversation: boolean;
|
||||
readonly serverConfig: T3ServerConfig | null;
|
||||
readonly queueCount: number;
|
||||
@@ -667,6 +668,7 @@ export const ThreadComposer = memo(function ThreadComposer(props: ThreadComposer
|
||||
providerInstanceId: currentModelSelection.instanceId,
|
||||
providerGroups: threadProviderGroups,
|
||||
selectedModel: currentModelSelection,
|
||||
reportedModelSelection: props.reportedModelSelection,
|
||||
onSelectModel: (option) =>
|
||||
props.onUpdateModelSelection(withRememberedModelOptions(option.selection)),
|
||||
optionDescriptors: providerOptionDescriptors,
|
||||
@@ -683,6 +685,7 @@ export const ThreadComposer = memo(function ThreadComposer(props: ThreadComposer
|
||||
}),
|
||||
[
|
||||
currentModelSelection,
|
||||
props.reportedModelSelection,
|
||||
currentRuntimeMode,
|
||||
props.onUpdateModelSelection,
|
||||
props.onUpdateRuntimeMode,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { useThreadReportedModelSelection } from "../../state/entities";
|
||||
import { UsageLimitRecoveryCard } from "./UsageLimitRecoveryCard";
|
||||
import { useNavigation } from "@react-navigation/native";
|
||||
import type { WorktreeSetupCardProps } from "./worktree-setup-card";
|
||||
@@ -303,6 +304,10 @@ const USER_INPUT_TOGGLE_TIMING = {
|
||||
|
||||
export const ThreadDetailScreen = memo(function ThreadDetailScreen(props: ThreadDetailScreenProps) {
|
||||
const navigation = useNavigation();
|
||||
const reportedModelSelection = useThreadReportedModelSelection({
|
||||
environmentId: props.environmentId,
|
||||
threadId: props.selectedThread.id,
|
||||
});
|
||||
const deviceState = useEnvironmentQuery(
|
||||
deviceEnvironment.state({ environmentId: props.environmentId, input: {} }),
|
||||
);
|
||||
@@ -1277,6 +1282,7 @@ export const ThreadDetailScreen = memo(function ThreadDetailScreen(props: Thread
|
||||
effortLabel={formatModelSelectionEffort(
|
||||
props.selectedThread.modelSelection,
|
||||
providerSubagentProvider?.models,
|
||||
reportedModelSelection,
|
||||
)}
|
||||
status={props.providerSubagentStatus ?? null}
|
||||
onOpenParent={
|
||||
@@ -1293,6 +1299,7 @@ export const ThreadDetailScreen = memo(function ThreadDetailScreen(props: Thread
|
||||
) : (
|
||||
<>
|
||||
<ThreadComposer
|
||||
reportedModelSelection={reportedModelSelection}
|
||||
editorRef={composerEditorRef}
|
||||
draftMessage={props.draftMessage}
|
||||
draftAttachments={props.draftAttachments}
|
||||
|
||||
@@ -245,6 +245,7 @@ type ThreadSettingsSessionProps = {
|
||||
readonly providerInstanceId?: ProviderInstanceId;
|
||||
readonly providerGroups: ReadonlyArray<ProviderGroup>;
|
||||
readonly selectedModel: ModelSelection | null;
|
||||
readonly reportedModelSelection?: ModelSelection | null;
|
||||
readonly onSelectModel: (option: ModelOption) => void;
|
||||
readonly optionDescriptors: ReadonlyArray<ProviderOptionDescriptor>;
|
||||
readonly onUpdateOptionSelections: (selections: ReadonlyArray<ProviderOptionSelection>) => void;
|
||||
@@ -304,6 +305,8 @@ type ThreadSettingsSessionValue = {
|
||||
readonly runtimeModeChoices: ReturnType<typeof runtimeModeChoicesForSupportedModes>;
|
||||
readonly onUpdateRuntimeMode: (mode: RuntimeMode) => void;
|
||||
readonly displayedDescriptors: ReadonlyArray<ProviderOptionDescriptor>;
|
||||
readonly displayedModelSelection: ModelSelection | null;
|
||||
readonly reportedModelSelection: ModelSelection | null;
|
||||
readonly providerExpansionOverrides: ReadonlySet<string>;
|
||||
readonly hasLegacyModels: boolean;
|
||||
readonly pendingModel: ModelOption | null;
|
||||
@@ -476,6 +479,8 @@ function ThreadSettingsSessionProvider(
|
||||
runtimeModeChoices,
|
||||
onUpdateRuntimeMode: props.onUpdateRuntimeMode,
|
||||
displayedDescriptors,
|
||||
displayedModelSelection: pendingModel?.selection ?? props.selectedModel,
|
||||
reportedModelSelection: pendingModel ? null : (props.reportedModelSelection ?? null),
|
||||
favoriteKeys,
|
||||
favoritesLoaded,
|
||||
providerExpansionOverrides,
|
||||
@@ -507,6 +512,8 @@ function ThreadSettingsSessionProvider(
|
||||
isApplied,
|
||||
isDisplayed,
|
||||
props.environmentId,
|
||||
props.selectedModel,
|
||||
props.reportedModelSelection,
|
||||
props.providerInstanceId,
|
||||
pendingModel,
|
||||
pressModel,
|
||||
@@ -743,7 +750,11 @@ function ThreadSettingsOptionsItem(props: {
|
||||
>
|
||||
<DisclosureRow
|
||||
label={descriptor.label}
|
||||
value={getProviderOptionCurrentLabel(descriptor)}
|
||||
value={getProviderOptionCurrentLabel(
|
||||
descriptor,
|
||||
session.displayedModelSelection,
|
||||
session.reportedModelSelection,
|
||||
)}
|
||||
onPress={() => props.onOpenSubmenu({ kind: "descriptor", id: descriptor.id })}
|
||||
/>
|
||||
</Animated.View>
|
||||
@@ -997,7 +1008,13 @@ function ThreadSettingsChoiceContent(props: {
|
||||
id: choice.id,
|
||||
label: choice.label,
|
||||
description: undefined,
|
||||
selected: choice.id === getProviderOptionCurrentValue(activeDescriptor),
|
||||
selected:
|
||||
choice.id ===
|
||||
getProviderOptionCurrentValue(
|
||||
activeDescriptor,
|
||||
session.displayedModelSelection,
|
||||
session.reportedModelSelection,
|
||||
),
|
||||
onPress: () => {
|
||||
void Haptics.selectionAsync();
|
||||
session.applyOptionChange(activeDescriptor.id, choice.id);
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
import { useAtomValue } from "@effect/atom-react";
|
||||
import { deriveReportedModelSelection } from "@t3tools/client-runtime/state/thread-execution";
|
||||
|
||||
import { appAtomRegistry } from "./atom-registry";
|
||||
import type {
|
||||
EnvironmentProject,
|
||||
EnvironmentThread,
|
||||
EnvironmentThreadShell,
|
||||
} from "@t3tools/client-runtime/state/shell";
|
||||
import type {
|
||||
@@ -15,7 +17,7 @@ import { Atom } from "effect/unstable/reactivity";
|
||||
|
||||
import { environmentProjects } from "./projects";
|
||||
import { environmentServerConfigsAtom, serverEnvironment } from "./server";
|
||||
import { environmentThreadShells } from "./threads";
|
||||
import { environmentThreadDetails, environmentThreadShells } from "./threads";
|
||||
|
||||
const EMPTY_PROJECT_ATOM = Atom.make<EnvironmentProject | null>(null).pipe(
|
||||
Atom.withLabel("mobile-project:empty"),
|
||||
@@ -87,3 +89,10 @@ export function useEnvironmentServerConfig(
|
||||
export function useServerConfigs(): ReadonlyMap<EnvironmentId, ServerConfig> {
|
||||
return useAtomValue(environmentServerConfigsAtom);
|
||||
}
|
||||
|
||||
const selectReportedModelSelection = (thread: EnvironmentThread | null) =>
|
||||
thread === null ? null : deriveReportedModelSelection(thread.projection);
|
||||
|
||||
export function useThreadReportedModelSelection(ref: ScopedThreadRef) {
|
||||
return useAtomValue(environmentThreadDetails.threadAtom(ref), selectReportedModelSelection);
|
||||
}
|
||||
@@ -410,6 +410,11 @@ describe("OpenCode2 adapter", () => {
|
||||
promptAccepted,
|
||||
event("session.execution.succeeded", { sessionID: SESSION }),
|
||||
]);
|
||||
assert.deepEqual(thread.nativeMetadata?.modelSelection, {
|
||||
...bigPickle,
|
||||
options: [{ id: "variant", value: "default" }],
|
||||
});
|
||||
assert.equal(bigPickle.options, undefined);
|
||||
const terminal = yield* terminalOf(runtime).pipe(Effect.forkScoped);
|
||||
yield* runtime.startTurn(
|
||||
turnInput(thread, {
|
||||
@@ -2833,6 +2838,10 @@ describe("OpenCode2 adapter", () => {
|
||||
modelSelection: bigPickle,
|
||||
runtimePolicy: customPolicy,
|
||||
});
|
||||
assert.deepEqual(thread.nativeMetadata?.modelSelection, {
|
||||
...bigPickle,
|
||||
options: [{ id: "variant", value: "default" }],
|
||||
});
|
||||
// Each directory keeps its own limit, whichever was read last.
|
||||
assert.equal(runtime.getModelContextWindow?.(bigPickle, WORK), 160000);
|
||||
assert.equal(runtime.getModelContextWindow?.(bigPickle, custom), 48000);
|
||||
@@ -3869,3 +3878,44 @@ const providerTurnId = Effect.gen(function* () {
|
||||
nativeTurnId: `${SESSION}:attempt:attempt:opencode2-adapter`,
|
||||
});
|
||||
}).pipe(Effect.provide(IdAllocator.layer));
|
||||
|
||||
describe("OpenCode reported model variants", () => {
|
||||
it.effect(
|
||||
"updates reported variants from selected-model and step events without duplicate updates",
|
||||
() =>
|
||||
Effect.gen(function* () {
|
||||
const model = { providerID: "opencode", id: "big-pickle", variant: "thinking" };
|
||||
const step = {
|
||||
sessionID: SESSION,
|
||||
assistantMessageID: "msg_0eb735d5b001oAFVeY5jz3WD4Z",
|
||||
agent: "build",
|
||||
model,
|
||||
started: 1,
|
||||
};
|
||||
const { runtime, thread } = yield* resumed([
|
||||
out("session.prompt", { sessionID: SESSION, text: "<any>" }),
|
||||
promptAccepted,
|
||||
event("session.execution.started", { sessionID: SESSION }),
|
||||
event("session.model.selected", { sessionID: SESSION, model }),
|
||||
event("session.step.started", step),
|
||||
event("session.step.started", { ...step, model: { ...model, variant: "none" } }),
|
||||
event("session.execution.succeeded", { sessionID: SESSION }),
|
||||
]);
|
||||
const collected = yield* runtime.events.pipe(
|
||||
Stream.takeUntil((event) => event.type === "turn.terminal"),
|
||||
Stream.runCollect,
|
||||
Effect.forkScoped,
|
||||
);
|
||||
yield* runtime.startTurn(turnInput(thread));
|
||||
const updates = (yield* Fiber.join(collected)).filter(
|
||||
(event) => event.type === "provider_thread.updated",
|
||||
);
|
||||
assert.deepEqual(
|
||||
updates.map(
|
||||
(event) => event.providerThread.nativeMetadata?.modelSelection?.options?.[0]?.value,
|
||||
),
|
||||
["default", "thinking", "none", "none"],
|
||||
);
|
||||
}).pipe(Effect.scoped),
|
||||
);
|
||||
});
|
||||
@@ -78,7 +78,7 @@ import * as McpProviderSession from "../../mcp/McpProviderSession.ts";
|
||||
import { buildRuntimeInstructions } from "../../provider/RuntimeInstructions.ts";
|
||||
import { t3OrchestrationSystemPrompt } from "../../provider/T3OrchestrationInstructions.ts";
|
||||
import { SKILL_MENTION_PATTERN } from "@t3tools/shared/composerInlineTokens";
|
||||
import { getModelSelectionStringOptionValue } from "@t3tools/shared/model";
|
||||
import { getModelSelectionStringOptionValue, modelSelectionsEqual } from "@t3tools/shared/model";
|
||||
import { causeErrorTag } from "@t3tools/shared/observability";
|
||||
|
||||
import { providerMessageTextWithAttachmentPaths } from "../AttachmentPrompt.ts";
|
||||
@@ -1385,6 +1385,27 @@ export const make = Effect.fn("OpenCode2Adapter.make")(function* (instanceId: Pr
|
||||
});
|
||||
});
|
||||
|
||||
const withReportedModel = (
|
||||
providerThread: OrchestrationV2ProviderThread,
|
||||
model: ModelRef | undefined,
|
||||
): OrchestrationV2ProviderThread => {
|
||||
if (model === undefined) return providerThread;
|
||||
const modelSelection: ModelSelection = {
|
||||
instanceId,
|
||||
model: `${model.providerID}/${model.id}`,
|
||||
options: model.variant === undefined ? [] : [{ id: "variant", value: model.variant }],
|
||||
};
|
||||
if (
|
||||
providerThread.nativeMetadata?.modelSelection !== undefined &&
|
||||
modelSelectionsEqual(providerThread.nativeMetadata.modelSelection, modelSelection)
|
||||
)
|
||||
return providerThread;
|
||||
return {
|
||||
...providerThread,
|
||||
nativeMetadata: { ...providerThread.nativeMetadata, modelSelection },
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Gives a subagent call its session once both are known: OpenCode names
|
||||
* the session on the call's progress, and announces it just before. The
|
||||
@@ -1463,7 +1484,8 @@ export const make = Effect.fn("OpenCode2Adapter.make")(function* (instanceId: Pr
|
||||
const child =
|
||||
previous ?? newThreadState(childId, providerThread, call.state.directory, subagent);
|
||||
child.subagent = subagent;
|
||||
child.providerThread = providerThread;
|
||||
child.model = info?.model ?? child.model;
|
||||
child.providerThread = withReportedModel(providerThread, child.model);
|
||||
child.directory = call.state.directory;
|
||||
child.agent = info?.agent ?? call.agent ?? child.agent;
|
||||
// OpenCode gives a new session its parent's rules, which are the thread's.
|
||||
@@ -1472,7 +1494,11 @@ export const make = Effect.fn("OpenCode2Adapter.make")(function* (instanceId: Pr
|
||||
childOwners.set(childId, rootOf(call.state));
|
||||
call.child = child;
|
||||
yield* emit({ type: "app_thread.created", driver, appThread });
|
||||
yield* emit({ type: "provider_thread.updated", driver, providerThread });
|
||||
yield* emit({
|
||||
type: "provider_thread.updated",
|
||||
driver,
|
||||
providerThread: child.providerThread,
|
||||
});
|
||||
yield* emitSubagent(call);
|
||||
// A session called again was not made now, so it may hold the rules of
|
||||
// a mode the thread has left. OpenCode applies a rules change to the
|
||||
@@ -2520,6 +2546,18 @@ export const make = Effect.fn("OpenCode2Adapter.make")(function* (instanceId: Pr
|
||||
if (sessionId === undefined) return;
|
||||
const state = threads.get(sessionId);
|
||||
if (state === undefined) return;
|
||||
if (event.type === "session.model.selected" || event.type === "session.step.started") {
|
||||
if (event.type === "session.model.selected") state.model = event.data.model;
|
||||
const providerThread = withReportedModel(state.providerThread, event.data.model);
|
||||
if (providerThread !== state.providerThread) {
|
||||
state.providerThread = { ...providerThread, updatedAt: yield* DateTime.now };
|
||||
yield* emit({
|
||||
type: "provider_thread.updated",
|
||||
driver,
|
||||
providerThread: state.providerThread,
|
||||
});
|
||||
}
|
||||
}
|
||||
if (
|
||||
event.type === "session.inbox.enqueued" &&
|
||||
state.subagent !== undefined &&
|
||||
@@ -2962,6 +3000,7 @@ export const make = Effect.fn("OpenCode2Adapter.make")(function* (instanceId: Pr
|
||||
},
|
||||
directory: string,
|
||||
) => {
|
||||
providerThread = withReportedModel(providerThread, native.model);
|
||||
const existing = threads.get(native.id);
|
||||
if (existing !== undefined) {
|
||||
existing.providerThread = providerThread;
|
||||
@@ -3582,7 +3621,7 @@ export const make = Effect.fn("OpenCode2Adapter.make")(function* (instanceId: Pr
|
||||
directory,
|
||||
);
|
||||
state.policy = policy;
|
||||
return providerThread;
|
||||
return state.providerThread;
|
||||
}).pipe(
|
||||
Effect.mapError((cause) =>
|
||||
isProviderAdapterError(cause)
|
||||
@@ -3625,7 +3664,7 @@ export const make = Effect.fn("OpenCode2Adapter.make")(function* (instanceId: Pr
|
||||
directory: AbsolutePath.make(cwd),
|
||||
});
|
||||
}
|
||||
return providerThread;
|
||||
return state.providerThread;
|
||||
}).pipe(
|
||||
Effect.mapError((cause) =>
|
||||
isProviderAdapterError(cause)
|
||||
@@ -4183,7 +4222,7 @@ export const make = Effect.fn("OpenCode2Adapter.make")(function* (instanceId: Pr
|
||||
directory: AbsolutePath.make(cwd),
|
||||
});
|
||||
}
|
||||
return providerThread;
|
||||
return state.providerThread;
|
||||
}).pipe(
|
||||
exclusive(forkInput.sourceProviderThread),
|
||||
Effect.mapError((cause) =>
|
||||
|
||||
@@ -88,6 +88,7 @@ import { effectiveSnoozed, threadWokeAt } from "@t3tools/client-runtime/state/th
|
||||
import { useThreadActions } from "../hooks/useThreadActions";
|
||||
import {
|
||||
deriveProviderSubagentStatus,
|
||||
deriveReportedModelSelection,
|
||||
formatModelSelectionEffort,
|
||||
deriveRunlessWorkStartedAt,
|
||||
deriveThreadActivityRun,
|
||||
@@ -1626,6 +1627,9 @@ export default function ChatView(props: ChatViewProps) {
|
||||
});
|
||||
const serverThreadProjection = useThreadProjection(routeThreadDetailRef);
|
||||
const serverProjection = serverThreadProjection?.projection ?? null;
|
||||
const reportedModelSelection = serverProjection
|
||||
? deriveReportedModelSelection(serverProjection)
|
||||
: null;
|
||||
const threadStatus = useThreadStatus(routeThreadDetailRef);
|
||||
const threadSyncPhase = resolveThreadSyncPhase({
|
||||
detailExists: serverProjection !== null,
|
||||
@@ -4073,7 +4077,11 @@ export default function ChatView(props: ChatViewProps) {
|
||||
const providerSubagentEffortLabel =
|
||||
activeThread === undefined
|
||||
? null
|
||||
: formatModelSelectionEffort(activeThread.modelSelection, providerSubagentModels);
|
||||
: formatModelSelectionEffort(
|
||||
activeThread.modelSelection,
|
||||
providerSubagentModels,
|
||||
reportedModelSelection,
|
||||
);
|
||||
const mountComposerContextStrip = shouldShowComposerContextStrip({
|
||||
isDraftHeroState,
|
||||
persistInActiveThreads: settings.persistComposerContextStrip,
|
||||
@@ -10818,6 +10826,7 @@ export default function ChatView(props: ChatViewProps) {
|
||||
) : null}
|
||||
{!composerMounted ? null : (
|
||||
<ChatComposer
|
||||
reportedModelSelection={reportedModelSelection}
|
||||
multipleModelSelections={multipleModelSelections}
|
||||
supportsMultipleModels={
|
||||
serverConfig?.environment.capabilities.requiredWorktreeBootstrap ===
|
||||
|
||||
@@ -1581,6 +1581,7 @@ export interface ChatComposerProps {
|
||||
providerCatalogKnown: boolean;
|
||||
activeProjectDefaultModelSelection: ModelSelection | null | undefined;
|
||||
activeThreadModelSelection: ModelSelection | null | undefined;
|
||||
reportedModelSelection?: ModelSelection | null;
|
||||
|
||||
// Context window
|
||||
activeContextWindow: ContextWindowSnapshot | null;
|
||||
@@ -1728,6 +1729,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
|
||||
providerCatalogKnown,
|
||||
activeProjectDefaultModelSelection,
|
||||
activeThreadModelSelection,
|
||||
reportedModelSelection,
|
||||
activeContextWindow,
|
||||
compactThreadUnavailable,
|
||||
compactDisabled,
|
||||
@@ -2877,6 +2879,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
|
||||
model: selectedModel,
|
||||
models: selectedProviderModels,
|
||||
modelOptions: composerModelOptions?.[selectedInstanceId],
|
||||
reportedModelSelection,
|
||||
prompt,
|
||||
onPromptChange: setPromptFromTraits,
|
||||
planModeEnabled: settings.planModeEnabled,
|
||||
@@ -2889,6 +2892,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
|
||||
model: selectedModel,
|
||||
models: selectedProviderModels,
|
||||
modelOptions: composerModelOptions?.[selectedInstanceId],
|
||||
reportedModelSelection,
|
||||
prompt,
|
||||
onPromptChange: setPromptFromTraits,
|
||||
planModeEnabled: settings.planModeEnabled,
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
import { describe, expect, it } from "vite-plus/test";
|
||||
import { ProviderDriverKind, type ProviderOptionDescriptor } from "@t3tools/contracts";
|
||||
import {
|
||||
ProviderInstanceId,
|
||||
ProviderDriverKind,
|
||||
type ProviderOptionDescriptor,
|
||||
} from "@t3tools/contracts";
|
||||
import { buildTraitsTriggerDisplay, buildUnavailableModelOptionDescriptors } from "./TraitsPicker";
|
||||
|
||||
function selectDescriptor(
|
||||
@@ -232,3 +236,34 @@ describe("buildUnavailableModelOptionDescriptors", () => {
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
it("shows Unknown until a matching provider report provides Default", () => {
|
||||
const selection = {
|
||||
instanceId: ProviderInstanceId.make("opencode"),
|
||||
model: "ling",
|
||||
options: [],
|
||||
};
|
||||
const input = {
|
||||
provider: ProviderDriverKind.make("opencode"),
|
||||
descriptors: [
|
||||
selectDescriptor(
|
||||
"variant",
|
||||
[
|
||||
{ id: "none", label: "None" },
|
||||
{ id: "thinking", label: "Thinking" },
|
||||
],
|
||||
"",
|
||||
),
|
||||
],
|
||||
primarySelectDescriptorId: "variant",
|
||||
ultrathinkPromptControlled: false,
|
||||
modelSelection: selection,
|
||||
};
|
||||
expect(buildTraitsTriggerDisplay(input).label).toBe("Unknown");
|
||||
expect(
|
||||
buildTraitsTriggerDisplay({
|
||||
...input,
|
||||
reportedModelSelection: { ...selection, options: [{ id: "variant", value: "default" }] },
|
||||
}).label,
|
||||
).toBe("Default");
|
||||
});
|
||||
@@ -1,4 +1,5 @@
|
||||
import {
|
||||
type ModelSelection,
|
||||
type ProviderDriverKind,
|
||||
type ProviderInstanceId,
|
||||
type ProviderOptionDescriptor,
|
||||
@@ -122,11 +123,13 @@ function replaceDescriptorCurrentValue(
|
||||
|
||||
function getDescriptorStringValue(
|
||||
descriptor: Extract<ProviderOptionDescriptor, { type: "select" }> | null,
|
||||
selection?: ModelSelection | null,
|
||||
reportedSelection?: ModelSelection | null,
|
||||
): string | null {
|
||||
if (!descriptor) {
|
||||
return null;
|
||||
}
|
||||
const value = getProviderOptionCurrentValue(descriptor);
|
||||
const value = getProviderOptionCurrentValue(descriptor, selection, reportedSelection);
|
||||
return typeof value === "string" ? value : null;
|
||||
}
|
||||
|
||||
@@ -274,6 +277,7 @@ export interface TraitsMenuContentProps {
|
||||
prompt: string;
|
||||
onPromptChange: (prompt: string) => void;
|
||||
modelOptions?: ProviderOptions | null | undefined;
|
||||
reportedModelSelection?: ModelSelection | null | undefined;
|
||||
allowPromptInjectedEffort?: boolean;
|
||||
planModeEnabled: boolean;
|
||||
triggerClassName?: string;
|
||||
@@ -288,10 +292,13 @@ export const TraitsMenuContent = memo(function TraitsMenuContentImpl({
|
||||
prompt,
|
||||
onPromptChange,
|
||||
modelOptions,
|
||||
reportedModelSelection,
|
||||
allowPromptInjectedEffort = true,
|
||||
planModeEnabled,
|
||||
...persistence
|
||||
}: TraitsMenuContentProps & TraitsPersistence) {
|
||||
const modelSelection =
|
||||
instanceId && model ? { instanceId, model, options: modelOptions ?? [] } : null;
|
||||
const setProviderModelOptions = useComposerDraftStore((store) => store.setProviderModelOptions);
|
||||
const updateModelOptions = useCallback(
|
||||
(nextOptions: ProviderOptions | undefined) => {
|
||||
@@ -362,7 +369,11 @@ export const TraitsMenuContent = memo(function TraitsMenuContentImpl({
|
||||
return (
|
||||
<>
|
||||
{descriptors.map((descriptor, index) => {
|
||||
const value = getProviderOptionCurrentLabel(descriptor);
|
||||
const value = getProviderOptionCurrentLabel(
|
||||
descriptor,
|
||||
modelSelection,
|
||||
reportedModelSelection,
|
||||
);
|
||||
if (!value) return null;
|
||||
return (
|
||||
<div key={descriptor.id}>
|
||||
@@ -386,7 +397,7 @@ export const TraitsMenuContent = memo(function TraitsMenuContentImpl({
|
||||
const selectedValue =
|
||||
ultrathinkPromptControlled && descriptor.id === primarySelectDescriptor?.id
|
||||
? "ultrathink"
|
||||
: (getDescriptorStringValue(descriptor) ?? "");
|
||||
: (getDescriptorStringValue(descriptor, modelSelection, reportedModelSelection) ?? "");
|
||||
|
||||
return (
|
||||
<div key={descriptor.id}>
|
||||
@@ -483,6 +494,8 @@ export function buildTraitsTriggerDisplay(input: {
|
||||
descriptors: ReadonlyArray<ProviderOptionDescriptor>;
|
||||
primarySelectDescriptorId: string | null;
|
||||
ultrathinkPromptControlled: boolean;
|
||||
modelSelection?: ModelSelection | null;
|
||||
reportedModelSelection?: ModelSelection | null | undefined;
|
||||
}): { label: string; speedIcon: "fast" | "ultrafast" | null } {
|
||||
let fastModeFallbackLabel: string | null = null;
|
||||
let speedIcon: "fast" | "ultrafast" | null = null;
|
||||
@@ -522,7 +535,11 @@ export function buildTraitsTriggerDisplay(input: {
|
||||
? "Ultrathink"
|
||||
: descriptor.type === "boolean"
|
||||
? `${descriptor.label} ${descriptor.currentValue === true ? "On" : "Off"}`
|
||||
: getProviderOptionCurrentLabel(descriptor);
|
||||
: getProviderOptionCurrentLabel(
|
||||
descriptor,
|
||||
input.modelSelection,
|
||||
input.reportedModelSelection,
|
||||
);
|
||||
if (typeof label === "string" && label.length > 0) {
|
||||
labels.push(label);
|
||||
}
|
||||
@@ -545,6 +562,7 @@ export const TraitsPicker = memo(function TraitsPicker({
|
||||
prompt,
|
||||
onPromptChange,
|
||||
modelOptions,
|
||||
reportedModelSelection,
|
||||
allowPromptInjectedEffort = true,
|
||||
planModeEnabled,
|
||||
triggerClassName,
|
||||
@@ -588,6 +606,8 @@ export const TraitsPicker = memo(function TraitsPicker({
|
||||
descriptors,
|
||||
primarySelectDescriptorId: primarySelectDescriptor?.id ?? null,
|
||||
ultrathinkPromptControlled,
|
||||
modelSelection: instanceId && model ? { instanceId, model, options: modelOptions ?? [] } : null,
|
||||
reportedModelSelection,
|
||||
});
|
||||
const speedLabel = speedIcon === "ultrafast" ? "Ultrafast mode on" : "Fast mode on";
|
||||
const accessibleLabel = speedIcon ? `${triggerLabel}, ${speedLabel}` : triggerLabel;
|
||||
@@ -686,6 +706,7 @@ export const TraitsPicker = memo(function TraitsPicker({
|
||||
prompt={prompt}
|
||||
onPromptChange={onPromptChange}
|
||||
modelOptions={modelOptions}
|
||||
reportedModelSelection={reportedModelSelection}
|
||||
allowPromptInjectedEffort={allowPromptInjectedEffort}
|
||||
planModeEnabled={planModeEnabled}
|
||||
{...persistence}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import {
|
||||
type ModelCapabilities,
|
||||
type ModelSelection,
|
||||
type ProviderDriverKind,
|
||||
type ProviderInstanceId,
|
||||
type ProviderOptionSelection,
|
||||
@@ -48,6 +49,7 @@ type TraitsRenderInput = {
|
||||
model: string;
|
||||
models: ReadonlyArray<ServerProviderModel>;
|
||||
modelOptions: ReadonlyArray<ProviderOptionSelection> | undefined;
|
||||
reportedModelSelection?: ModelSelection | null | undefined;
|
||||
prompt: string;
|
||||
onPromptChange: (prompt: string) => void;
|
||||
planModeEnabled: boolean;
|
||||
@@ -170,6 +172,7 @@ function renderTraitsControl(
|
||||
model,
|
||||
models,
|
||||
modelOptions,
|
||||
reportedModelSelection,
|
||||
prompt,
|
||||
onPromptChange,
|
||||
planModeEnabled,
|
||||
@@ -208,6 +211,7 @@ function renderTraitsControl(
|
||||
{...(draftId ? { draftId } : {})}
|
||||
model={model}
|
||||
modelOptions={resolvedModelOptions}
|
||||
reportedModelSelection={reportedModelSelection}
|
||||
prompt={prompt}
|
||||
onPromptChange={onPromptChange}
|
||||
planModeEnabled={planModeEnabled}
|
||||
|
||||
@@ -3,6 +3,9 @@ import {
|
||||
NodeId,
|
||||
MessageId,
|
||||
ProviderInstanceId,
|
||||
ProviderThreadId,
|
||||
ProviderSessionId,
|
||||
ProviderDriverKind,
|
||||
RunId,
|
||||
ThreadId,
|
||||
type OrchestrationV2ExecutionNode,
|
||||
@@ -15,6 +18,7 @@ import { describe, expect, it } from "vite-plus/test";
|
||||
import { v2Projection } from "./orchestrationV2TestFixtures.ts";
|
||||
import {
|
||||
presentPendingBackgroundWork,
|
||||
deriveReportedModelSelection,
|
||||
deriveLatestThreadRun,
|
||||
deriveProviderSubagentStatus,
|
||||
formatModelSelectionEffort,
|
||||
@@ -578,3 +582,72 @@ describe("presentPendingBackgroundWork", () => {
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("provider-reported model selection", () => {
|
||||
const selected = v2Projection.thread.modelSelection;
|
||||
const reported = { ...selected, options: [{ id: "reasoningEffort", value: "default" }] };
|
||||
const providerThread = {
|
||||
id: ProviderThreadId.make("active"),
|
||||
driver: ProviderDriverKind.make("codex"),
|
||||
providerInstanceId: selected.instanceId,
|
||||
providerSessionId: ProviderSessionId.make("session"),
|
||||
appThreadId: v2Projection.thread.id,
|
||||
ownerNodeId: null,
|
||||
nativeThreadRef: null,
|
||||
nativeConversationHeadRef: null,
|
||||
status: "idle" as const,
|
||||
firstRunOrdinal: null,
|
||||
lastRunOrdinal: null,
|
||||
handoffIds: [],
|
||||
forkedFrom: null,
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
nativeMetadata: { modelSelection: reported },
|
||||
};
|
||||
const projection = {
|
||||
...v2Projection,
|
||||
thread: { ...v2Projection.thread, activeProviderThreadId: providerThread.id },
|
||||
providerThreads: [providerThread],
|
||||
};
|
||||
|
||||
it("reads only the active provider thread's reported selection", () => {
|
||||
expect(deriveReportedModelSelection(projection)).toBe(reported);
|
||||
expect(
|
||||
deriveReportedModelSelection({
|
||||
...projection,
|
||||
thread: { ...projection.thread, activeProviderThreadId: null },
|
||||
}),
|
||||
).toBeNull();
|
||||
expect(
|
||||
deriveReportedModelSelection({
|
||||
...projection,
|
||||
providerThreads: [
|
||||
{ ...providerThread, providerInstanceId: ProviderInstanceId.make("other") },
|
||||
],
|
||||
}),
|
||||
).toBeNull();
|
||||
});
|
||||
|
||||
it("shows the reported default in a subagent's effort label", () => {
|
||||
const models = [
|
||||
{
|
||||
slug: selected.model,
|
||||
name: selected.model,
|
||||
isCustom: false,
|
||||
capabilities: {
|
||||
optionDescriptors: [
|
||||
{
|
||||
id: "variant",
|
||||
label: "Reasoning",
|
||||
type: "select" as const,
|
||||
options: [{ id: "high", label: "High" }],
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
];
|
||||
const variantReport = { ...selected, options: [{ id: "variant", value: "default" }] };
|
||||
expect(formatModelSelectionEffort(selected, models, variantReport)).toBe("Default");
|
||||
expect(formatModelSelectionEffort(selected, models)).toBe("Unknown");
|
||||
});
|
||||
});
|
||||
@@ -142,6 +142,18 @@ export function deriveProviderSubagentStatus(
|
||||
};
|
||||
}
|
||||
|
||||
/** The observed selection belongs to the active provider thread, never a previous handoff. */
|
||||
export function deriveReportedModelSelection(
|
||||
projection: OrchestrationV2ThreadProjection,
|
||||
): ModelSelection | null {
|
||||
const providerThread = projection.providerThreads.find(
|
||||
(candidate) =>
|
||||
candidate.id === projection.thread.activeProviderThreadId &&
|
||||
candidate.providerInstanceId === projection.thread.modelSelection.instanceId,
|
||||
);
|
||||
return providerThread?.nativeMetadata?.modelSelection ?? null;
|
||||
}
|
||||
|
||||
// Option ids providers use for reasoning effort (Codex, Claude, Grok/ACP, OpenCode).
|
||||
const REASONING_EFFORT_OPTION_IDS = ["reasoningEffort", "effort", "reasoning", "variant"] as const;
|
||||
|
||||
@@ -155,6 +167,7 @@ const REASONING_EFFORT_OPTION_IDS = ["reasoningEffort", "effort", "reasoning", "
|
||||
export function formatModelSelectionEffort(
|
||||
selection: ModelSelection,
|
||||
models: ReadonlyArray<ServerProviderModel> = [],
|
||||
reportedSelection?: ModelSelection | null,
|
||||
): string | null {
|
||||
const caps = models.find((model) => model.slug === selection.model)?.capabilities;
|
||||
if (!caps) return null;
|
||||
@@ -162,7 +175,7 @@ export function formatModelSelectionEffort(
|
||||
for (const id of REASONING_EFFORT_OPTION_IDS) {
|
||||
const descriptor = descriptors.find((candidate) => candidate.id === id);
|
||||
if (descriptor?.type !== "select") continue;
|
||||
const label = getProviderOptionCurrentLabel(descriptor);
|
||||
const label = getProviderOptionCurrentLabel(descriptor, selection, reportedSelection);
|
||||
if (label) return label;
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -796,6 +796,8 @@ export type OrchestrationV2PendingBackgroundTask = typeof OrchestrationV2Pending
|
||||
|
||||
/** Provider and adapter metadata that should not overwrite the app thread's title. */
|
||||
export const OrchestrationV2ProviderThreadNativeMetadata = Schema.Struct({
|
||||
/** Provider-reported selection for display, separate from the app's saved preferences. */
|
||||
modelSelection: Schema.optional(ModelSelection),
|
||||
title: Schema.optional(Schema.NullOr(TrimmedNonEmptyString)),
|
||||
updatedAt: Schema.optional(Schema.NullOr(TrimmedNonEmptyString)),
|
||||
/** Version 2 scopes provider-derived item ids by provider instance. */
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
createModelSelection,
|
||||
formatCodexModelName,
|
||||
formatModelSlugName,
|
||||
getProviderOptionCurrentLabel,
|
||||
getModelSelectionBooleanOptionValue,
|
||||
getModelSelectionStringOptionValue,
|
||||
getProviderOptionDescriptors,
|
||||
@@ -302,3 +303,63 @@ describe("readCustomModelEntries", () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("provider-reported option display", () => {
|
||||
const selection = createModelSelection(ProviderInstanceId.make("opencode"), "ling");
|
||||
const reported = { ...selection, options: [{ id: "variant", value: "default" }] };
|
||||
const descriptor = {
|
||||
id: "variant",
|
||||
label: "Reasoning",
|
||||
type: "select" as const,
|
||||
options: [
|
||||
{ id: "none", label: "None" },
|
||||
{ id: "thinking", label: "Thinking" },
|
||||
],
|
||||
};
|
||||
|
||||
it("shows explicit reports without adding a choice or a dispatch option", () => {
|
||||
expect(getProviderOptionCurrentLabel(descriptor, selection, reported)).toBe("Default");
|
||||
expect(
|
||||
getProviderOptionCurrentLabel(descriptor, selection, {
|
||||
...reported,
|
||||
options: [{ id: "variant", value: "thinking" }],
|
||||
}),
|
||||
).toBe("Thinking");
|
||||
expect(
|
||||
getProviderOptionCurrentLabel(
|
||||
{ ...descriptor, currentValue: "none" },
|
||||
{ ...selection, options: [{ id: "variant", value: "none" }] },
|
||||
reported,
|
||||
),
|
||||
).toBe("None");
|
||||
expect(descriptor.options.map((option) => option.id)).toEqual(["none", "thinking"]);
|
||||
expect(buildProviderOptionSelectionsFromDescriptors([descriptor])).toBeUndefined();
|
||||
expect(getProviderOptionCurrentLabel(descriptor, selection)).toBe("Unknown");
|
||||
const effortDescriptor = { ...descriptor, id: "effort", currentValue: "default" };
|
||||
expect(getProviderOptionCurrentLabel(effortDescriptor, selection)).toBeUndefined();
|
||||
expect(
|
||||
getProviderOptionCurrentLabel(effortDescriptor, selection, {
|
||||
...reported,
|
||||
model: "other",
|
||||
options: [{ id: "effort", value: "default" }],
|
||||
}),
|
||||
).toBeUndefined();
|
||||
expect(
|
||||
getProviderOptionCurrentLabel(effortDescriptor, selection, {
|
||||
...reported,
|
||||
options: [{ id: "effort", value: "default" }],
|
||||
}),
|
||||
).toBe("Default");
|
||||
expect(
|
||||
getProviderOptionCurrentLabel({ ...descriptor, currentValue: "thinking" }, selection),
|
||||
).toBe("Unknown");
|
||||
});
|
||||
|
||||
it.each([
|
||||
{ ...selection, model: "other" },
|
||||
{ ...selection, instanceId: ProviderInstanceId.make("other") },
|
||||
{ ...selection, options: [{ id: "variant", value: "none" }] },
|
||||
])("ignores reports after changing the model, instance, or option: %j", (selected) => {
|
||||
expect(getProviderOptionCurrentLabel(descriptor, selected, reported)).toBe("Unknown");
|
||||
});
|
||||
});
|
||||
@@ -202,12 +202,35 @@ export function getProviderOptionDescriptors(input: {
|
||||
);
|
||||
}
|
||||
|
||||
function getReportedOptionValue(
|
||||
id: string,
|
||||
selection?: ModelSelection | null,
|
||||
reportedSelection?: ModelSelection | null,
|
||||
) {
|
||||
if (
|
||||
!selection ||
|
||||
!reportedSelection ||
|
||||
selection.instanceId !== reportedSelection.instanceId ||
|
||||
selection.model !== reportedSelection.model ||
|
||||
selection.options?.some((option) => option.id === id)
|
||||
)
|
||||
return undefined;
|
||||
return getRawSelectionValueById(reportedSelection.options, id);
|
||||
}
|
||||
|
||||
export function getProviderOptionCurrentValue(
|
||||
descriptor: ProviderOptionDescriptor | null | undefined,
|
||||
selection?: ModelSelection | null,
|
||||
reportedSelection?: ModelSelection | null,
|
||||
): string | boolean | undefined {
|
||||
if (!descriptor) {
|
||||
return undefined;
|
||||
}
|
||||
const hasExplicitOption = selection?.options?.some((option) => option.id === descriptor.id);
|
||||
// Reported values are display-only; callers that build dispatch options omit this context.
|
||||
const reportedValue = getReportedOptionValue(descriptor.id, selection, reportedSelection);
|
||||
if (reportedValue !== undefined) return reportedValue;
|
||||
if (descriptor.id === "variant" && selection && !hasExplicitOption) return undefined;
|
||||
if (descriptor.type === "boolean") {
|
||||
return descriptor.currentValue;
|
||||
}
|
||||
@@ -219,6 +242,8 @@ export function getProviderOptionCurrentValue(
|
||||
|
||||
export function getProviderOptionCurrentLabel(
|
||||
descriptor: ProviderOptionDescriptor | null | undefined,
|
||||
selection?: ModelSelection | null,
|
||||
reportedSelection?: ModelSelection | null,
|
||||
): string | undefined {
|
||||
if (!descriptor) {
|
||||
return undefined;
|
||||
@@ -230,11 +255,15 @@ export function getProviderOptionCurrentLabel(
|
||||
: "Off"
|
||||
: undefined;
|
||||
}
|
||||
const currentValue = getProviderOptionCurrentValue(descriptor);
|
||||
if (typeof currentValue !== "string") {
|
||||
return undefined;
|
||||
}
|
||||
return descriptor.options.find((option) => option.id === currentValue)?.label;
|
||||
const currentValue = getProviderOptionCurrentValue(descriptor, selection, reportedSelection);
|
||||
return (
|
||||
descriptor.options.find((option) => option.id === currentValue)?.label ??
|
||||
(getReportedOptionValue(descriptor.id, selection, reportedSelection) === "default"
|
||||
? "Default"
|
||||
: descriptor.id === "variant"
|
||||
? "Unknown"
|
||||
: undefined)
|
||||
);
|
||||
}
|
||||
|
||||
export function buildProviderOptionSelectionsFromDescriptors(
|
||||
|
||||
Reference in new issue
Block a user