Skip to content

Commit 0e6f381

Browse files
authored
refactor(ui): simplify model effort profile flow (#122412)
* refactor(ui): simplify model effort profile flow consolidate the Gateway profile shape, remove New Session's synthetic row, and retain boundary regression coverage. * fix(gateway): preserve thinking projection order Keep deterministic response bytes while consuming the canonical thinking profile.
1 parent 630aac9 commit 0e6f381

9 files changed

Lines changed: 62 additions & 171 deletions

File tree

‎src/gateway/server-methods/models-list-result.ts‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -453,10 +453,7 @@ async function buildPublicModelsListEntries(params: {
453453
return {
454454
...buildPublicModelProjection(entry),
455455
...(agentRuntime ? { agentRuntime } : {}),
456-
...(thinkingProfile && {
457-
thinkingLevels: thinkingProfile.levels,
458-
thinkingDefault: thinkingProfile.defaultLevel,
459-
}),
456+
...thinkingProfile,
460457
...(capabilityProvider && params.apiKeyCapabilities?.providers.has(capabilityProvider)
461458
? {
462459
apiKeySupported: params.apiKeyCapabilities.providers.get(capabilityProvider) === true,

‎src/gateway/session-utils-contracts.ts‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ import type { resolveSessionModelRef } from "../agents/session-model-ref.js";
66
import type { SubagentRunReadIndex } from "../agents/subagents/registry/subagent-registry-read.js";
77
import type { SubagentRunReadRecord } from "../agents/subagents/registry/subagent-registry.types.js";
88
import type { ThinkLevel, listThinkingLevelOptions } from "../auto-reply/thinking.js";
9+
10+
export type GatewayModelThinkingProfile = {
11+
thinkingLevels: ReturnType<typeof listThinkingLevelOptions>;
12+
thinkingDefault: ThinkLevel;
13+
};
914
import type { SessionAcpMeta, SessionEntry } from "../config/sessions.js";
1015
import type { ModelCostConfig } from "../utils/usage-format.js";
1116

@@ -18,13 +23,7 @@ export type SessionListRowContext = {
1823
subagentRuns: SubagentRunReadIndex<SubagentRunReadRecord>;
1924
storeChildSessionsByKey: Map<string, string[]>;
2025
selectedModelByOverrideRef: Map<string, ReturnType<typeof resolveSessionModelRef>>;
21-
thinkingMetadataByModelRef: Map<
22-
string,
23-
{
24-
levels: ReturnType<typeof listThinkingLevelOptions>;
25-
defaultLevel: ThinkLevel;
26-
}
27-
>;
26+
thinkingMetadataByModelRef: Map<string, GatewayModelThinkingProfile>;
2827
displayModelIdentityByKey: Map<string, { provider?: string; model?: string }>;
2928
modelCostConfigByModelRef: Map<string, ModelCostConfig | undefined>;
3029
userProfileIdentityById: Map<string, SessionActorProfileIdentity | undefined>;

‎src/gateway/session-utils-model.ts‎

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import { normalizeAgentId } from "../routing/session-key.js";
4444
import type { GatewayModelCatalogSnapshot } from "./server-model-catalog.types.js";
4545
import {
4646
createSessionRowModelCacheKey,
47+
type GatewayModelThinkingProfile,
4748
type SessionListRowContext,
4849
} from "./session-utils-contracts.js";
4950
import type { GatewaySessionsDefaults, SessionsPatchResult } from "./session-utils.types.js";
@@ -114,10 +115,7 @@ export function resolveGatewayModelThinkingProfile(params: {
114115
modelCatalog?: ModelCatalogEntry[];
115116
rowContext?: SessionListRowContext;
116117
sessionKey?: string;
117-
}): {
118-
levels: ReturnType<typeof listThinkingLevelOptions>;
119-
defaultLevel: ReturnType<typeof resolveGatewaySessionThinkingDefault>;
120-
} {
118+
}): GatewayModelThinkingProfile {
121119
const catalogEntry = params.modelCatalog
122120
? findModelCatalogEntry(params.modelCatalog, {
123121
provider: params.provider,
@@ -137,13 +135,13 @@ export function resolveGatewayModelThinkingProfile(params: {
137135
});
138136
if (!params.rowContext) {
139137
return {
140-
levels: listThinkingLevelOptions(
138+
thinkingLevels: listThinkingLevelOptions(
141139
params.provider,
142140
params.model,
143141
params.modelCatalog,
144142
agentRuntime,
145143
),
146-
defaultLevel: resolveGatewaySessionThinkingDefault({
144+
thinkingDefault: resolveGatewaySessionThinkingDefault({
147145
cfg: params.cfg,
148146
provider: params.provider,
149147
model: params.model,
@@ -162,13 +160,13 @@ export function resolveGatewayModelThinkingProfile(params: {
162160
return cached;
163161
}
164162
const metadata = {
165-
levels: listThinkingLevelOptions(
163+
thinkingLevels: listThinkingLevelOptions(
166164
params.provider,
167165
params.model,
168166
params.modelCatalog,
169167
agentRuntime,
170168
),
171-
defaultLevel: resolveGatewaySessionThinkingDefault({
169+
thinkingDefault: resolveGatewaySessionThinkingDefault({
172170
cfg: params.cfg,
173171
provider: params.provider,
174172
model: params.model,
@@ -264,10 +262,11 @@ export function resolveGatewaySessionThinkingProjectionInternal(
264262
return {
265263
agentRuntime,
266264
thinkingLevel,
267-
effectiveThinkingLevel: thinkingLevel ?? metadata.defaultLevel,
268-
thinkingLevels: metadata.levels,
269-
thinkingOptions: metadata.levels.map((level) => level.label),
270-
thinkingDefault: metadata.defaultLevel,
265+
effectiveThinkingLevel: thinkingLevel ?? metadata.thinkingDefault,
266+
// Preserve the established serialized projection order for byte-stable responses.
267+
thinkingLevels: metadata.thinkingLevels,
268+
thinkingOptions: metadata.thinkingLevels.map((level) => level.label),
269+
thinkingDefault: metadata.thinkingDefault,
271270
};
272271
}
273272

@@ -309,9 +308,10 @@ export function getSessionDefaults(
309308
model: resolved.model ?? null,
310309
contextTokens: contextTokens ?? null,
311310
agentRuntime,
312-
thinkingLevels: thinkingProfile.levels,
313-
thinkingOptions: thinkingProfile.levels.map((level) => level.label),
314-
thinkingDefault: thinkingProfile.defaultLevel,
311+
// Preserve the established serialized projection order for byte-stable responses.
312+
thinkingLevels: thinkingProfile.thinkingLevels,
313+
thinkingOptions: thinkingProfile.thinkingLevels.map((level) => level.label),
314+
thinkingDefault: thinkingProfile.thinkingDefault,
315315
};
316316
}
317317

‎src/gateway/session-utils-store.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -364,9 +364,10 @@ export function listAgentsForGateway(
364364
workspace,
365365
workspaceGit,
366366
agentRuntime,
367-
thinkingLevels: thinkingProfile.levels,
368-
thinkingOptions: thinkingProfile.levels.map((level) => level.label),
369-
thinkingDefault: thinkingProfile.defaultLevel,
367+
// Preserve the established serialized projection order for byte-stable responses.
368+
thinkingLevels: thinkingProfile.thinkingLevels,
369+
thinkingOptions: thinkingProfile.thinkingLevels.map((level) => level.label),
370+
thinkingDefault: thinkingProfile.thinkingDefault,
370371
},
371372
model ? { model } : {},
372373
);

‎ui/src/lib/chat/thinking.test.ts‎

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ describe("chat thinking helpers", () => {
2020
resolveThinkingLevelInput(
2121
"ultra",
2222
{
23-
key: "agent:main:main",
24-
kind: "direct",
25-
updatedAt: 1,
2623
thinkingLevels: [{ id: "ultra", label: "Ultra" }],
2724
},
2825
undefined,
@@ -93,40 +90,4 @@ describe("chat thinking helpers", () => {
9390

9491
expect(state.options.map((option) => option.value)).not.toContain("ultra");
9592
});
96-
97-
it("uses identical reasoning options for a canonical default and explicit selection", () => {
98-
const thinkingLevels = ["off", "minimal", "low", "medium", "high", "xhigh", "max", "ultra"].map(
99-
(id) => ({ id, label: id }),
100-
);
101-
const defaults = {
102-
modelProvider: "openai",
103-
model: "gpt-5.6-sol",
104-
contextTokens: null,
105-
thinkingLevels,
106-
thinkingOptions: thinkingLevels.map((level) => level.label),
107-
thinkingDefault: "medium",
108-
};
109-
const inherited = resolveChatThinkingSelectState({
110-
catalog: [{ provider: "openai", id: "gpt-5.6-sol", name: "GPT-5.6 Sol", reasoning: true }],
111-
defaults,
112-
sessionKey: "new-session:main",
113-
session: { key: "new-session:main", kind: "direct", updatedAt: null },
114-
sessionsResult: null,
115-
});
116-
const explicit = resolveChatThinkingSelectState({
117-
catalog: [{ provider: "openai", id: "gpt-5.6-sol", name: "GPT-5.6 Sol", reasoning: true }],
118-
defaults,
119-
sessionKey: "new-session:main",
120-
session: {
121-
key: "new-session:main",
122-
kind: "direct",
123-
updatedAt: null,
124-
modelProvider: "openai",
125-
model: "gpt-5.6-sol",
126-
},
127-
sessionsResult: null,
128-
});
129-
130-
expect(explicit).toEqual(inherited);
131-
});
13293
});

‎ui/src/lib/chat/thinking.ts‎

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,22 @@ import { normalizeLowercaseStringOrEmpty } from "../string-coerce.ts";
1616

1717
type ThinkingSessionDefaults = SessionsListResult["defaults"] | undefined;
1818

19-
type ChatThinkingSelection =
20-
| {
21-
kind: "anchored";
22-
source: "override" | "default";
23-
value: string;
24-
displayLabel: string;
25-
index: number;
26-
}
27-
| {
28-
kind: "unanchored";
29-
source: "override" | "default";
30-
value: string;
31-
displayLabel: string;
32-
};
19+
type ChatThinkingSelection = {
20+
source: "override" | "default";
21+
value: string;
22+
displayLabel: string;
23+
} & ({ kind: "anchored"; index: number } | { kind: "unanchored" });
24+
25+
export type ChatThinkingTarget = Pick<
26+
GatewaySessionRow,
27+
| "agentRuntime"
28+
| "model"
29+
| "modelProvider"
30+
| "thinkingDefault"
31+
| "thinkingLevel"
32+
| "thinkingLevels"
33+
| "thinkingOptions"
34+
>;
3335

3436
export type ChatThinkingSelectState = {
3537
selection: ChatThinkingSelection;
@@ -38,15 +40,15 @@ export type ChatThinkingSelectState = {
3840
};
3941

4042
function resolveThinkingLevelOptionsForSession(
41-
session: GatewaySessionRow | undefined,
43+
session: ChatThinkingTarget | undefined,
4244
defaults: ThinkingSessionDefaults,
4345
): GatewayThinkingLevelOption[] {
4446
const { provider, model } = resolveThinkingTargetModel({ defaults, session });
4547
return resolveThinkingLevelOptions({ catalog: [], defaults, model, provider, session });
4648
}
4749

4850
export function formatThinkingCommandOptionsForSession(
49-
session: GatewaySessionRow | undefined,
51+
session: ChatThinkingTarget | undefined,
5052
defaults?: SessionsListResult["defaults"],
5153
): string {
5254
const options = resolveThinkingLevelOptionsForSession(session, defaults)
@@ -57,7 +59,7 @@ export function formatThinkingCommandOptionsForSession(
5759

5860
export function resolveThinkingLevelInput(
5961
rawLevel: string,
60-
session: GatewaySessionRow | undefined,
62+
session: ChatThinkingTarget | undefined,
6163
defaults: ThinkingSessionDefaults,
6264
): string | undefined {
6365
const normalized = normalizeThinkLevel(rawLevel);
@@ -74,7 +76,7 @@ export function resolveThinkingLevelInput(
7476
}
7577

7678
export function isThinkingLevelOptionForSession(
77-
session: GatewaySessionRow | undefined,
79+
session: ChatThinkingTarget | undefined,
7880
defaults: ThinkingSessionDefaults,
7981
level: string,
8082
): boolean {
@@ -85,7 +87,7 @@ export function isThinkingLevelOptionForSession(
8587
}
8688

8789
export function resolveCurrentThinkingLevel(
88-
session: GatewaySessionRow | undefined,
90+
session: ChatThinkingTarget | undefined,
8991
defaults: ThinkingSessionDefaults,
9092
models: ModelCatalogEntry[],
9193
): string {
@@ -143,7 +145,7 @@ function isOffOnlyThinkingLevels(levels: readonly GatewayThinkingLevelOption[]):
143145

144146
function resolveThinkingTargetModel(params: {
145147
defaults: ThinkingSessionDefaults;
146-
session: GatewaySessionRow | undefined;
148+
session: ChatThinkingTarget | undefined;
147149
}): { provider: string | null; model: string | null } {
148150
return {
149151
provider: params.session?.modelProvider ?? params.defaults?.modelProvider ?? null,
@@ -167,7 +169,7 @@ function resolveThinkingLevelOptions(params: {
167169
hideUnsupportedOffOnly?: boolean;
168170
model: string | null;
169171
provider: string | null;
170-
session: GatewaySessionRow | undefined;
172+
session: ChatThinkingTarget | undefined;
171173
}): GatewayThinkingLevelOption[] {
172174
const modelMatchesDefaults = sessionModelMatchesDefaults(params.session, params.defaults);
173175
const catalogEntry = resolveThinkingCatalogEntry(params.catalog, params.provider, params.model);
@@ -209,7 +211,7 @@ function resolveThinkingLevelOptions(params: {
209211
export function resolveChatThinkingSelectState(params: {
210212
catalog: readonly ModelCatalogEntry[];
211213
defaults?: SessionsListResult["defaults"];
212-
session?: GatewaySessionRow;
214+
session?: ChatThinkingTarget;
213215
sessionKey: string;
214216
sessionsResult: SessionsListResult | null;
215217
}): ChatThinkingSelectState {

‎ui/src/pages/chat/components/chat-model-controls.ts‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
// Chat-owned model, reasoning, and fast-mode picker orchestration.
22
import { html } from "lit";
3-
import type {
4-
GatewaySessionRow,
5-
ModelCatalogEntry,
6-
SessionsListResult,
7-
} from "../../../api/types.ts";
3+
import type { ModelCatalogEntry, SessionsListResult } from "../../../api/types.ts";
84
import { t } from "../../../i18n/index.ts";
95
import { normalizeChatModelProviderId } from "../../../lib/chat/model-ref.ts";
106
import {
117
resolveChatFastModeSelectState,
128
resolveChatModelSelectState,
139
type ChatFastModeSelectValue,
1410
} from "../../../lib/chat/model-select-state.ts";
15-
import { resolveChatThinkingSelectState } from "../../../lib/chat/thinking.ts";
11+
import {
12+
resolveChatThinkingSelectState,
13+
type ChatThinkingTarget,
14+
} from "../../../lib/chat/thinking.ts";
1615
import { areUiSessionKeysEquivalent } from "../../../lib/sessions/session-key.ts";
1716
import { renderChatEffortPicker } from "./chat-effort-picker.ts";
1817
import {
@@ -46,7 +45,7 @@ type ChatModelControlsProps = {
4645
sessionsResult: SessionsListResult | null;
4746
stream: string | null;
4847
thinkingDefaults?: SessionsListResult["defaults"];
49-
thinkingSession?: GatewaySessionRow;
48+
thinkingSession?: ChatThinkingTarget;
5049
onFastModeSelect?: (value: ChatFastModeSelectValue, sessionKey: string) => unknown;
5150
onModelSelect?: (value: string, sessionKey: string) => unknown;
5251
onModelPickerTargetSelect?: (groupId: string, value: string) => unknown;

‎ui/src/pages/new-session/model-control.test.ts‎

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -664,70 +664,6 @@ describe("new-session model runtime", () => {
664664
});
665665
});
666666

667-
it("keeps xhigh anchored to the selected model profile across an interactive model switch", async () => {
668-
const levels = (ids: string[]) => ids.map((id) => ({ id, label: id }));
669-
const { context, request } = contextWith([
670-
{
671-
id: "k3",
672-
name: "Kimi K3",
673-
provider: "kimi",
674-
reasoning: true,
675-
thinkingLevels: levels([
676-
"off",
677-
"minimal",
678-
"low",
679-
"medium",
680-
"high",
681-
"xhigh",
682-
"max",
683-
"ultra",
684-
]),
685-
thinkingDefault: "high",
686-
},
687-
{
688-
id: "gpt-5.6-sol",
689-
name: "GPT-5.6 Sol",
690-
provider: "openai",
691-
reasoning: true,
692-
thinkingLevels: levels(["off", "minimal", "low", "medium", "high", "xhigh", "max"]),
693-
thinkingDefault: "medium",
694-
},
695-
]);
696-
const onSelectionChange = vi.fn();
697-
const control = new NewSessionModelControl(() => undefined, onSelectionChange);
698-
control.load(context, "main", true);
699-
await vi.waitFor(() => {
700-
expect(request).toHaveBeenCalledOnce();
701-
expect(
702-
renderControl(control, context).querySelector(
703-
'[data-chat-model-option="openai/gpt-5.6-sol"]',
704-
),
705-
).not.toBeNull();
706-
});
707-
control.selected = "kimi/k3";
708-
control.thinkingLevel = "xhigh";
709-
710-
renderControl(control, context)
711-
.querySelector<HTMLButtonElement>('[data-chat-model-option="openai/gpt-5.6-sol"]')
712-
?.click();
713-
714-
expect(control.selected).toBe("openai/gpt-5.6-sol");
715-
expect(control.thinkingLevel).toBe("xhigh");
716-
expect(onSelectionChange).toHaveBeenLastCalledWith({
717-
model: "openai/gpt-5.6-sol",
718-
thinkingLevel: "xhigh",
719-
});
720-
const container = renderControl(control, context);
721-
const slider = container.querySelector<HTMLInputElement>('[data-chat-thinking-slider="true"]');
722-
expect(slider?.dataset.chatThinkingValues).toBe("off,minimal,low,medium,high,xhigh,max");
723-
expect(slider?.value).toBe("5");
724-
expect(slider?.max).toBe("6");
725-
expect(slider?.getAttribute("aria-valuetext")).toBe("Extra high");
726-
expect(
727-
Number.parseFloat(slider?.style.getPropertyValue("--reasoning-fill") ?? "0"),
728-
).toBeCloseTo(83.33, 1);
729-
});
730-
731667
it("clears xhigh when an interactive model switch targets a profile ending at high", async () => {
732668
const levels = (ids: string[]) => ids.map((id) => ({ id, label: id }));
733669
const { context, request } = contextWith([

0 commit comments

Comments
 (0)