mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-21 02:55:16 +00:00
fix(ui): resolve session thinking defaults
This commit is contained in:
parent
f292cc67dc
commit
a906cb75ce
2 changed files with 70 additions and 8 deletions
|
|
@ -5,12 +5,15 @@ import { describe, expect, it, vi } from "vitest";
|
||||||
import type { SessionsListResult } from "../types.ts";
|
import type { SessionsListResult } from "../types.ts";
|
||||||
import { renderSessions, type SessionsProps } from "./sessions.ts";
|
import { renderSessions, type SessionsProps } from "./sessions.ts";
|
||||||
|
|
||||||
function buildResult(session: SessionsListResult["sessions"][number]): SessionsListResult {
|
function buildResult(
|
||||||
|
session: SessionsListResult["sessions"][number],
|
||||||
|
defaults?: Partial<SessionsListResult["defaults"]>,
|
||||||
|
): SessionsListResult {
|
||||||
return {
|
return {
|
||||||
ts: Date.now(),
|
ts: Date.now(),
|
||||||
path: "(multiple)",
|
path: "(multiple)",
|
||||||
count: 1,
|
count: 1,
|
||||||
defaults: { modelProvider: null, model: null, contextTokens: null },
|
defaults: { modelProvider: null, model: null, contextTokens: null, ...defaults },
|
||||||
sessions: [session],
|
sessions: [session],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -268,6 +271,41 @@ describe("sessions view", () => {
|
||||||
).toBe("Override: adaptive");
|
).toBe("Override: adaptive");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("labels inherited thinking from list defaults when lightweight rows omit row defaults", async () => {
|
||||||
|
const container = document.createElement("div");
|
||||||
|
render(
|
||||||
|
renderSessions(
|
||||||
|
buildProps(
|
||||||
|
buildResult(
|
||||||
|
{
|
||||||
|
key: "agent:main:main",
|
||||||
|
kind: "direct",
|
||||||
|
updatedAt: Date.now(),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
modelProvider: "openai-codex",
|
||||||
|
model: "gpt-5.5",
|
||||||
|
thinkingDefault: "high",
|
||||||
|
thinkingLevels: [
|
||||||
|
{ id: "off", label: "off" },
|
||||||
|
{ id: "high", label: "high" },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
container,
|
||||||
|
);
|
||||||
|
await Promise.resolve();
|
||||||
|
|
||||||
|
const thinking = container.querySelector("tbody select") as HTMLSelectElement | null;
|
||||||
|
expect(thinking?.value).toBe("");
|
||||||
|
expect(thinking?.options[0]?.textContent?.trim()).toBe("Inherited: high");
|
||||||
|
expect(Array.from(thinking?.options ?? []).map((option) => option.textContent?.trim())).toEqual(
|
||||||
|
["Inherited: high", "Off", "Override: high"],
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
it("keeps legacy binary thinking labels patching canonical ids", async () => {
|
it("keeps legacy binary thinking labels patching canonical ids", async () => {
|
||||||
const container = document.createElement("div");
|
const container = document.createElement("div");
|
||||||
const onPatch = vi.fn();
|
const onPatch = vi.fn();
|
||||||
|
|
|
||||||
|
|
@ -92,16 +92,37 @@ function getAgentIdentity(
|
||||||
: null;
|
: null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function rowMatchesSessionDefaults(
|
||||||
|
row: GatewaySessionRow,
|
||||||
|
defaults: SessionsListResult["defaults"] | undefined,
|
||||||
|
): boolean {
|
||||||
|
return (
|
||||||
|
(!row.modelProvider || row.modelProvider === defaults?.modelProvider) &&
|
||||||
|
(!row.model || row.model === defaults?.model)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
function resolveThinkLevelOptions(
|
function resolveThinkLevelOptions(
|
||||||
row: GatewaySessionRow,
|
row: GatewaySessionRow,
|
||||||
|
defaults?: SessionsListResult["defaults"],
|
||||||
): readonly { value: string; label: string }[] {
|
): readonly { value: string; label: string }[] {
|
||||||
const defaultLabel = formatInheritedThinkingLabel(row.thinkingDefault);
|
const sessionModelMatchesDefaults = rowMatchesSessionDefaults(row, defaults);
|
||||||
|
const defaultLabel = formatInheritedThinkingLabel(
|
||||||
|
row.thinkingDefault ?? (sessionModelMatchesDefaults ? defaults?.thinkingDefault : undefined),
|
||||||
|
);
|
||||||
const options: readonly GatewayThinkingLevelOption[] = row.thinkingLevels?.length
|
const options: readonly GatewayThinkingLevelOption[] = row.thinkingLevels?.length
|
||||||
? row.thinkingLevels
|
? row.thinkingLevels
|
||||||
: (row.thinkingOptions?.length ? row.thinkingOptions : DEFAULT_THINK_LEVELS).map((label) => ({
|
: sessionModelMatchesDefaults && defaults?.thinkingLevels?.length
|
||||||
id: normalizeThinkingOptionValue(label),
|
? defaults.thinkingLevels
|
||||||
label,
|
: (row.thinkingOptions?.length
|
||||||
}));
|
? row.thinkingOptions
|
||||||
|
: sessionModelMatchesDefaults && defaults?.thinkingOptions?.length
|
||||||
|
? defaults.thinkingOptions
|
||||||
|
: DEFAULT_THINK_LEVELS
|
||||||
|
).map((label) => ({
|
||||||
|
id: normalizeThinkingOptionValue(label),
|
||||||
|
label,
|
||||||
|
}));
|
||||||
return [
|
return [
|
||||||
{ value: "", label: defaultLabel },
|
{ value: "", label: defaultLabel },
|
||||||
...options.map((option) => ({
|
...options.map((option) => ({
|
||||||
|
|
@ -684,7 +705,10 @@ function renderRows(row: GatewaySessionRow, props: SessionsProps) {
|
||||||
const updated = row.updatedAt ? formatRelativeTimestamp(row.updatedAt) : t("common.na");
|
const updated = row.updatedAt ? formatRelativeTimestamp(row.updatedAt) : t("common.na");
|
||||||
const rawThinking = row.thinkingLevel ?? "";
|
const rawThinking = row.thinkingLevel ?? "";
|
||||||
const thinking = rawThinking ? normalizeThinkingOptionValue(rawThinking) : "";
|
const thinking = rawThinking ? normalizeThinkingOptionValue(rawThinking) : "";
|
||||||
const thinkLevels = withCurrentLabeledOption(resolveThinkLevelOptions(row), thinking);
|
const thinkLevels = withCurrentLabeledOption(
|
||||||
|
resolveThinkLevelOptions(row, props.result?.defaults),
|
||||||
|
thinking,
|
||||||
|
);
|
||||||
const fastMode = row.fastMode === true ? "on" : row.fastMode === false ? "off" : "";
|
const fastMode = row.fastMode === true ? "on" : row.fastMode === false ? "off" : "";
|
||||||
const fastLevels = withCurrentLabeledOption(buildFastLevelOptions(), fastMode);
|
const fastLevels = withCurrentLabeledOption(buildFastLevelOptions(), fastMode);
|
||||||
const verbose = row.verboseLevel ?? "";
|
const verbose = row.verboseLevel ?? "";
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue