feat(webui): add session-scoped reasoning effort (#6441)
* feat(webui): add session-scoped model options Extend the composer preset menu with inherited reasoning effort and Codex Fast mode overrides. Persist choices with ordinary inputs, isolate captured runtimes, and restore browser preferences without changing shared presets. Add regression coverage for pending preset ordering, settings initialization, session and host isolation, queue edits, Codex request mapping, and narrow-screen controls. * feat(webui): refine session model options and add Codex Ultrafast Fit the composer options into a compact single row and preview reasoning effort only during a drag. Add Fast/Ultrafast controls for eligible Codex models, preserve explicit session choices across reloads, and document the speed tiers. * fix(webui): add Codex speed control to the component gallery * fix(webui): preserve saved model options after preset rename Use the session options for display when a browser preference no longer matches the preset. Omit model options from the next message unless the browser has a matching choice, so stale preferences cannot overwrite options the gateway already saved.
This commit is contained in:
1 parent
2b232c9133
commit
0f45d74fec
82 files changed
+2289
-113
No files matched your search
@@ -1351,6 +1351,7 @@ describe("webui API helpers", () => {
|
||||
title: "优化 WebUI 标题",
|
||||
project_locked: projectLocked,
|
||||
model_preset: "fast",
|
||||
model_options: projectLocked ? { reasoning_effort: "high", codex_fast_mode: false } : undefined,
|
||||
run_started_at: 1_700_000_000,
|
||||
handle: {
|
||||
id: "handle_0123456789abcdef0123456789abcdef",
|
||||
@@ -1368,6 +1369,8 @@ describe("webui API helpers", () => {
|
||||
projectLocked: true,
|
||||
preview: "",
|
||||
modelPreset: "fast",
|
||||
modelOptions: projectLocked ? { reasoning_effort: "high", codex_fast_mode: false }
|
||||
: { reasoning_effort: null, codex_fast_mode: null },
|
||||
runStartedAt: 1_700_000_000,
|
||||
handle: {
|
||||
id: "handle_0123456789abcdef0123456789abcdef",
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
import { fireEvent, render, screen } from "@testing-library/react";
|
||||
import { useState } from "react";
|
||||
import { expect, it, vi } from "vitest";
|
||||
|
||||
import { ModelOptionsControl } from "@/components/thread/ModelOptionsControl";
|
||||
import type { SessionModelOptions } from "@/lib/types";
|
||||
|
||||
function Control({ fast = true, defaultEffort = "medium", onChange }: {
|
||||
fast?: boolean;
|
||||
defaultEffort?: string | null;
|
||||
onChange?: (value: SessionModelOptions) => void;
|
||||
}) {
|
||||
const [value, setValue] = useState<SessionModelOptions>({ reasoning_effort: null, codex_fast_mode: null });
|
||||
const efforts = ["low", "medium", "high"];
|
||||
return <ModelOptionsControl data={{ value, efforts, capability: {
|
||||
reasoning_effort: { default: defaultEffort, values: efforts },
|
||||
...(fast ? { codex_fast_mode: { default: true } } : {}),
|
||||
} }} onChange={(next) => { setValue(next); onChange?.(next); }} />;
|
||||
}
|
||||
|
||||
it("preselects the actual preset values without writing them and saves a reselected value explicitly", () => {
|
||||
const onChange = vi.fn();
|
||||
render(<Control onChange={onChange} />);
|
||||
const effort = screen.getByRole("slider", { name: "Reasoning effort" });
|
||||
const fast = screen.getByRole("button", { name: "Fast" });
|
||||
expect(effort).toHaveAttribute("aria-valuetext", "medium");
|
||||
expect(fast).toHaveAttribute("aria-pressed", "true");
|
||||
expect(onChange).not.toHaveBeenCalled();
|
||||
fireEvent.change(effort, { target: { value: "0" } });
|
||||
expect(effort).toHaveAttribute("aria-valuetext", "low");
|
||||
fireEvent.click(fast);
|
||||
expect(fast).toHaveAttribute("aria-pressed", "false");
|
||||
fireEvent.change(effort, { target: { value: "1" } });
|
||||
expect(onChange).toHaveBeenLastCalledWith({ reasoning_effort: "medium", codex_fast_mode: false });
|
||||
});
|
||||
|
||||
it("lets the model choose the effort when no concrete preset value is known", () => {
|
||||
const onChange = vi.fn();
|
||||
render(<Control defaultEffort={null} onChange={onChange} />);
|
||||
const effort = screen.getByRole("slider", { name: "Reasoning effort" });
|
||||
expect(effort).toHaveAttribute("aria-valuetext", "Auto");
|
||||
fireEvent.change(effort, { target: { value: "3" } });
|
||||
expect(effort).toHaveAttribute("aria-valuetext", "high");
|
||||
fireEvent.change(effort, { target: { value: "0" } });
|
||||
expect(onChange).toHaveBeenLastCalledWith({ reasoning_effort: null, codex_fast_mode: null });
|
||||
});
|
||||
|
||||
it("keeps a custom preset effort selectable without giving it a position on the scale", () => {
|
||||
const onChange = vi.fn();
|
||||
render(<Control defaultEffort="extended" onChange={onChange} />);
|
||||
const effort = screen.getByRole("combobox", { name: "Reasoning effort" });
|
||||
expect(effort).toHaveDisplayValue("extended");
|
||||
fireEvent.change(effort, { target: { value: "1" } });
|
||||
expect(effort).toHaveDisplayValue("medium");
|
||||
fireEvent.change(effort, { target: { value: "3" } });
|
||||
expect(onChange).toHaveBeenLastCalledWith({ reasoning_effort: "extended", codex_fast_mode: null });
|
||||
});
|
||||
|
||||
it("uses the capability description rather than the provider name to expose Fast mode", () => {
|
||||
render(<Control fast={false} />);
|
||||
expect(screen.getByRole("slider", { name: "Reasoning effort" })).toBeVisible();
|
||||
expect(screen.queryByRole("button", { name: "Fast" })).not.toBeInTheDocument();
|
||||
});
|
||||
@@ -70,6 +70,50 @@ afterEach(() => {
|
||||
});
|
||||
|
||||
describe("NanobotClient", () => {
|
||||
it.each([
|
||||
{ reasoning_effort: "high", codex_fast_mode: true },
|
||||
{ reasoning_effort: null, codex_fast_mode: false },
|
||||
{ reasoning_effort: null, codex_fast_mode: null },
|
||||
])("transmits the whole model option selection without dropping false or null: %j", (modelOptions) => {
|
||||
const client = new NanobotClient({ url: "ws://test", reconnect: false,
|
||||
socketFactory: (url) => new FakeSocket(url) as unknown as WebSocket });
|
||||
client.connect();
|
||||
const socket = lastSocket();
|
||||
socket.fakeOpen();
|
||||
client.sendMessage("chat", "normal message", undefined, { modelOptions });
|
||||
expect(JSON.parse(socket.sent.at(-1)!)).toMatchObject({ type: "message", model_options: modelOptions });
|
||||
client.sendMessage("chat", "keep saved options");
|
||||
expect(JSON.parse(socket.sent.at(-1)!)).not.toHaveProperty("model_options");
|
||||
client.close();
|
||||
});
|
||||
|
||||
it("omits model options for Temporary Chats and shell commands", async () => {
|
||||
const client = new NanobotClient({ url: "ws://test", reconnect: false,
|
||||
socketFactory: (url) => new FakeSocket(url) as unknown as WebSocket });
|
||||
client.connect();
|
||||
const socket = lastSocket();
|
||||
socket.fakeOpen();
|
||||
const created = client.newTemporaryChat();
|
||||
socket.fakeMessage({ event: "attached", chat_id: "temporary-options", temporary: true, request_id: lastRequestId(socket) });
|
||||
await created;
|
||||
const modelOptions = { reasoning_effort: "high", codex_fast_mode: true };
|
||||
client.sendMessage("temporary-options", "temporary message", undefined, { modelOptions });
|
||||
expect(JSON.parse(socket.sent.at(-1)!)).not.toHaveProperty("model_options");
|
||||
client.sendMessage("regular", "pwd", undefined, { modelOptions, userShell: true });
|
||||
expect(JSON.parse(socket.sent.at(-1)!)).toMatchObject({ user_shell: true });
|
||||
expect(JSON.parse(socket.sent.at(-1)!)).not.toHaveProperty("model_options");
|
||||
client.close();
|
||||
});
|
||||
|
||||
it("uses a stable host/path preference scope across token refresh, including custom host transports", () => {
|
||||
const client = new NanobotClient({ url: "ws://host/ws?token=secret", reconnect: false });
|
||||
expect(client.preferenceScope).toBe("ws://host/ws");
|
||||
client.updateUrl("ws://host/ws?token=refreshed");
|
||||
expect(client.preferenceScope).toBe("ws://host/ws");
|
||||
client.updateUrl("nanobot-host://other-host/events?token=secret");
|
||||
expect(client.preferenceScope).toBe("nanobot-host://other-host/events");
|
||||
});
|
||||
|
||||
const chatRequests = [
|
||||
{ type: "new_chat", start: (client: NanobotClient, timeout: number) => client.newChat(timeout) },
|
||||
{ type: "new_temporary_chat", start: (client: NanobotClient, timeout: number) => client.newTemporaryChat(timeout) },
|
||||
|
||||
@@ -304,6 +304,31 @@ describe("Settings models", () => {
|
||||
));
|
||||
});
|
||||
|
||||
it.each([
|
||||
{ model: "gpt-5.6-sol", label: "Off", modeValue: false },
|
||||
{ model: "openai-codex/gpt-6.2-sol", label: "Ultrafast", modeValue: "ultrafast" },
|
||||
])("saves $label for the Codex preset without editing its connection", async ({ model, label, modeValue }) => {
|
||||
const payload = settingsPayload();
|
||||
payload.providers = [{ name: "openai_codex", label: "Codex", configured: true, codex_fast_mode_supported: true,
|
||||
codex_ultrafast_models: ["gpt-6.2-sol"], extra_body: { service_tier: "priority" } }];
|
||||
Object.assign(payload.model_presets[0], {
|
||||
provider: "openai_codex", resolved_provider: "openai_codex", model, codex_fast_mode: null,
|
||||
});
|
||||
requestMutationMock.mockResolvedValue(payload);
|
||||
renderSettingsView({ initialSection: "models", initialSettings: payload });
|
||||
fireEvent.click(await screen.findByRole("button", { name: /primary/i }));
|
||||
const mode = within(screen.getByRole("group", { name: "Fast" }));
|
||||
const fast = mode.getByRole("button", { name: /^Fast$/ });
|
||||
expect(fast).toHaveAttribute("aria-pressed", "true");
|
||||
expect(requestMutationMock).not.toHaveBeenCalled();
|
||||
if (modeValue === false) expect(mode.queryByRole("button", { name: "Ultrafast" })).not.toBeInTheDocument();
|
||||
fireEvent.click(modeValue === false ? fast : mode.getByRole("button", { name: label }));
|
||||
fireEvent.click(presetSaveButton());
|
||||
await waitFor(() => expect(requestMutationMock).toHaveBeenCalledWith(
|
||||
"settings.model_configuration.update", { include_usage: false, name: "primary", codex_fast_mode: modeValue }, 20_000,
|
||||
));
|
||||
});
|
||||
|
||||
it("shows the host's automatic API and discards an older reasoning resolution", async () => {
|
||||
const payload = settingsPayload();
|
||||
payload.model_api_resolution_supported = true;
|
||||
|
||||
@@ -945,7 +945,7 @@ describe("Settings providers", () => {
|
||||
await waitFor(() => expect(screen.getByRole("dialog", { name: "Manage providers" })).toBeVisible());
|
||||
|
||||
fireEvent.click(screen.getByRole("button", { name: "OpenAI Codex" }));
|
||||
fireEvent.click(screen.getByRole("switch", { name: "Fast mode" }));
|
||||
fireEvent.click(screen.getByRole("switch", { name: "Fast" }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Save provider" }));
|
||||
await waitFor(() => expect(requestMutationMock).toHaveBeenCalledWith(
|
||||
"settings.provider.update",
|
||||
|
||||
@@ -66,6 +66,7 @@ function makeClient() {
|
||||
return status;
|
||||
},
|
||||
defaultChatId: null as string | null,
|
||||
preferenceScope: lifecycle.preferenceScope,
|
||||
onStatus: (handler: (nextStatus: ConnectionStatus) => void) => {
|
||||
statusHandlers.add(handler);
|
||||
handler(status);
|
||||
@@ -466,6 +467,87 @@ function settingsWithFastPreset(): SettingsPayload {
|
||||
}
|
||||
|
||||
describe("ThreadShell", () => {
|
||||
function optionsSettings() {
|
||||
const settings = settingsWithFastPreset();
|
||||
for (const preset of settings.model_presets) preset.model_options = {
|
||||
reasoning_effort: { default: "low", values: ["low", "high"] }, codex_fast_mode: { default: true },
|
||||
};
|
||||
settings.providers = settings.providers.map((provider) => ({ ...provider, model_catalog: "unsupported" }));
|
||||
return settings;
|
||||
}
|
||||
|
||||
async function changeOptions() {
|
||||
fireEvent.click(await screen.findByRole("button", { name: "Default" }));
|
||||
fireEvent.change(screen.getByRole("slider", { name: "Reasoning effort" }), { target: { value: "1" } });
|
||||
fireEvent.click(screen.getByRole("button", { name: "Fast" }));
|
||||
fireEvent.keyDown(screen.getByRole("dialog", { name: "Switch model" }), { key: "Escape" });
|
||||
}
|
||||
|
||||
it("keeps model option choices local until sending, includes explicit false, and clears them on preset switch", async () => {
|
||||
localStorage.clear();
|
||||
const client = makeClient();
|
||||
render(wrap(client, <ThreadShell session={session("model-options")} title="Options" onToggleSidebar={() => {}}
|
||||
settingsSnapshot={optionsSettings()} />, null, "tok", ["webui.model-options.v1"]));
|
||||
await changeOptions();
|
||||
expect(client.sendMessage).not.toHaveBeenCalled();
|
||||
expect(client.sendSystemCommand).not.toHaveBeenCalled();
|
||||
fireEvent.change(screen.getByLabelText("Message input"), { target: { value: "selected options" } });
|
||||
fireEvent.click(screen.getByRole("button", { name: "Send message" }));
|
||||
await waitFor(() => expect(client.sendMessage).toHaveBeenCalledWith("model-options", "selected options", undefined,
|
||||
expect.objectContaining({ modelOptions: { reasoning_effort: "high", codex_fast_mode: false } })));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Default" }));
|
||||
fireEvent.click(await screen.findByRole("option", { name: "fast" }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "fast" }));
|
||||
expect(screen.getByRole("slider", { name: "Reasoning effort" })).toHaveAttribute("aria-valuetext", "low");
|
||||
expect(screen.getByRole("button", { name: "Fast" })).toHaveAttribute("aria-pressed", "true");
|
||||
expect(client.sendSystemCommand).toHaveBeenCalledWith("model-options", "/model fast");
|
||||
expect(client.sendMessage).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it("sends and migrates the landing selection with the first ordinary message", async () => {
|
||||
localStorage.clear();
|
||||
const client = makeClient();
|
||||
const settings = optionsSettings();
|
||||
const view = (currentSession: ReturnType<typeof session> | null) => wrap(client, <ThreadShell session={currentSession}
|
||||
title="Options" onToggleSidebar={() => {}} settingsSnapshot={settings} onCreateChat={async () => "options-created"} />,
|
||||
null, "tok", ["webui.model-options.v1"]);
|
||||
const rendered = render(view(null));
|
||||
await changeOptions();
|
||||
fireEvent.change(screen.getByLabelText("Message input"), { target: { value: "first selection" } });
|
||||
fireEvent.click(screen.getByRole("button", { name: "Send message" }));
|
||||
await act(async () => {});
|
||||
rendered.rerender(view(session("options-created")));
|
||||
await waitFor(() => expect(client.sendMessage).toHaveBeenCalledWith("options-created", "first selection", undefined,
|
||||
expect.objectContaining({ modelOptions: { reasoning_effort: "high", codex_fast_mode: false } })));
|
||||
fireEvent.click(await screen.findByRole("button", { name: "Default" }));
|
||||
expect(screen.getByRole("slider", { name: "Reasoning effort" })).toHaveAttribute("aria-valuetext", "high");
|
||||
expect(screen.getByRole("button", { name: "Fast" })).toHaveAttribute("aria-pressed", "false");
|
||||
});
|
||||
|
||||
it("sends edited queued prompts using current options, while cancelling the queue sends nothing", async () => {
|
||||
localStorage.clear();
|
||||
const client = makeClient();
|
||||
const chatId = "options-queue";
|
||||
render(wrap(client, <ThreadShell session={session(chatId)} title="Options" onToggleSidebar={() => {}}
|
||||
settingsSnapshot={optionsSettings()} />, null, "tok", ["webui.model-options.v1"]));
|
||||
await screen.findByLabelText("Message input");
|
||||
act(() => client._emitChat(chatId, { event: "goal_status", chat_id: chatId, turn_id: "owner", status: "running", started_at: 1_000 }));
|
||||
const input = screen.getByLabelText("Message input");
|
||||
fireEvent.change(input, { target: { value: "queued options" } });
|
||||
fireEvent.keyDown(input, { key: "Enter" });
|
||||
fireEvent.click(screen.getByRole("button", { name: "Delete message" }));
|
||||
expect(client.sendMessage).not.toHaveBeenCalled();
|
||||
fireEvent.change(input, { target: { value: "queued options again" } });
|
||||
fireEvent.keyDown(input, { key: "Enter" });
|
||||
await changeOptions();
|
||||
fireEvent.click(screen.getByRole("button", { name: "Edit message" }));
|
||||
fireEvent.change(input, { target: { value: "edited options" } });
|
||||
fireEvent.keyDown(input, { key: "Enter" });
|
||||
fireEvent.click(screen.getByRole("button", { name: "Send now" }));
|
||||
await waitFor(() => expect(client.sendMessage).toHaveBeenCalledWith(chatId, "edited options", undefined,
|
||||
expect.objectContaining({ modelOptions: { reasoning_effort: "high", codex_fast_mode: false } })));
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
webuiThreadCache.clear();
|
||||
clearStoredComposerDrafts();
|
||||
|
||||
@@ -0,0 +1,180 @@
|
||||
import { act, renderHook, waitFor } from "@testing-library/react";
|
||||
import type { ReactNode } from "react";
|
||||
import { afterEach, beforeEach, expect, it, vi } from "vitest";
|
||||
|
||||
import { useSessionModelOptions } from "@/hooks/useSessionModelOptions";
|
||||
import * as api from "@/lib/api";
|
||||
import { NanobotClient } from "@/lib/nanobot-client";
|
||||
import { reasoningEffortValues } from "@/lib/provider-model-catalog";
|
||||
import type { ProviderModelsPayload, SessionModelOptions, SettingsPayload } from "@/lib/types";
|
||||
import { ClientProvider } from "@/providers/ClientProvider";
|
||||
import { settingsPayload } from "./settings-test-utils";
|
||||
|
||||
vi.mock("@/lib/api", () => ({ fetchProviderModels: vi.fn() }));
|
||||
const inherit: SessionModelOptions = { reasoning_effort: null, codex_fast_mode: null };
|
||||
const chosen: SessionModelOptions = { reasoning_effort: "max", codex_fast_mode: false };
|
||||
const payload: ProviderModelsPayload = {
|
||||
provider: "custom", label: "Custom", status: "available", catalog_kind: "official", model_count: 1, source: "remote",
|
||||
models: [{ id: "openai/gpt-4o", reasoning_efforts: ["none", "low", "max"] }],
|
||||
};
|
||||
function props() {
|
||||
const settings = settingsPayload();
|
||||
settings.providers = [{ name: "custom", label: "Custom", configured: true }];
|
||||
settings.model_presets[0].resolved_provider = "custom";
|
||||
settings.model_presets[0].model_options = {
|
||||
reasoning_effort: { default: "low", values: ["low", "high"] }, codex_fast_mode: { default: true },
|
||||
};
|
||||
return { sessionKey: "websocket:a" as string | null, preset: "primary", settings, open: false, disabled: false,
|
||||
storedValue: undefined as SessionModelOptions | undefined };
|
||||
}
|
||||
function wrapper(connection = { client: new NanobotClient({ url: "ws://host-a/ws?token=old", reconnect: false }), token: "old" }, enabled = true) {
|
||||
return ({ children }: { children: ReactNode }) => <ClientProvider client={connection.client} token={connection.token}
|
||||
webuiCapabilities={enabled ? ["webui.model-options.v1"] : []}>{children}</ClientProvider>;
|
||||
}
|
||||
beforeEach(() => {
|
||||
localStorage.clear();
|
||||
vi.mocked(api.fetchProviderModels).mockReset().mockResolvedValue(payload);
|
||||
});
|
||||
afterEach(() => vi.useRealTimers());
|
||||
|
||||
it("shares lazy settings recommendations and uses backend capability descriptions for custom providers", async () => {
|
||||
const initial = props();
|
||||
const view = renderHook(useSessionModelOptions, { wrapper: wrapper(), initialProps: initial });
|
||||
expect(api.fetchProviderModels).not.toHaveBeenCalled();
|
||||
expect(view.result.current.data?.efforts).toEqual(["low", "high"]);
|
||||
expect(view.result.current.data?.capability.codex_fast_mode?.default).toBe(true);
|
||||
view.rerender({ ...initial, open: true });
|
||||
await waitFor(() => expect(view.result.current.data?.efforts).toEqual(reasoningEffortValues(payload, initial.settings.agent.model)));
|
||||
expect(view.result.current.data?.value).toEqual(inherit);
|
||||
expect(view.result.current.sendValue()).toBeUndefined();
|
||||
});
|
||||
|
||||
it("coalesces browser writes, immediately transmits false/null, and flushes pagehide without gateway mutations", () => {
|
||||
const view = renderHook(useSessionModelOptions, { wrapper: wrapper(), initialProps: props() });
|
||||
const mutation = vi.spyOn(NanobotClient.prototype, "requestMutation");
|
||||
const storage = vi.spyOn(localStorage, "setItem");
|
||||
vi.useFakeTimers();
|
||||
act(() => { view.result.current.select(chosen); view.result.current.select({ ...chosen, reasoning_effort: null }); });
|
||||
expect(view.result.current.sendValue()).toEqual({ reasoning_effort: null, codex_fast_mode: false });
|
||||
expect(storage).not.toHaveBeenCalled();
|
||||
act(() => vi.advanceTimersByTime(250));
|
||||
expect(storage).toHaveBeenCalledTimes(1);
|
||||
expect(JSON.parse(storage.mock.calls[0][1])).toEqual({ preset: "primary", options: { reasoning_effort: null, codex_fast_mode: false } });
|
||||
act(() => view.result.current.select(inherit));
|
||||
act(() => window.dispatchEvent(new Event("pagehide")));
|
||||
expect(storage).toHaveBeenCalledTimes(2);
|
||||
expect(mutation).not.toHaveBeenCalled();
|
||||
storage.mockRestore(); mutation.mockRestore();
|
||||
});
|
||||
|
||||
it("reloads unsent preferences across token renewal and isolates hosts and sessions including rapid switches", () => {
|
||||
const connection = { client: new NanobotClient({ url: "ws://host-a/ws?token=old", reconnect: false }), token: "old" };
|
||||
const initial = props();
|
||||
const view = renderHook(useSessionModelOptions, { wrapper: wrapper(connection), initialProps: initial });
|
||||
act(() => view.result.current.select(chosen));
|
||||
connection.token = "renewed";
|
||||
connection.client.updateUrl("ws://host-a/ws?token=renewed");
|
||||
view.rerender({ ...initial });
|
||||
expect(view.result.current.sendValue()).toEqual(chosen);
|
||||
view.rerender({ ...initial, sessionKey: "websocket:b", storedValue: { reasoning_effort: "low", codex_fast_mode: true } });
|
||||
expect(view.result.current.data?.value).toEqual({ reasoning_effort: "low", codex_fast_mode: true });
|
||||
expect(view.result.current.sendValue()).toBeUndefined();
|
||||
act(() => view.result.current.select(inherit));
|
||||
view.rerender(initial);
|
||||
expect(view.result.current.sendValue()).toEqual(chosen);
|
||||
connection.client.updateUrl("ws://host-b/ws");
|
||||
view.rerender({ ...initial });
|
||||
expect(view.result.current.data?.value).toEqual(inherit);
|
||||
expect(view.result.current.sendValue()).toBeUndefined();
|
||||
connection.client.updateUrl("ws://host-a/ws?token=again");
|
||||
view.unmount();
|
||||
const reloaded = renderHook(useSessionModelOptions, { wrapper: wrapper(connection), initialProps: initial });
|
||||
expect(reloaded.result.current.sendValue()).toEqual(chosen);
|
||||
reloaded.rerender({ ...initial, sessionKey: "websocket:b" });
|
||||
expect(reloaded.result.current.sendValue()).toEqual(inherit);
|
||||
});
|
||||
|
||||
it("waits for settings before reconciling a reloaded browser preference with the active preset", () => {
|
||||
const initial = props();
|
||||
const key = 'nanobot.model-options.v1.["ws://host-a/ws","websocket:a"]';
|
||||
const saved = JSON.stringify({ preset: initial.preset, options: chosen });
|
||||
localStorage.setItem(key, saved);
|
||||
const view = renderHook(useSessionModelOptions, { wrapper: wrapper(), initialProps: {
|
||||
...initial, preset: "default", settings: null as SettingsPayload | null,
|
||||
} });
|
||||
expect(view.result.current.sendValue()).toBeUndefined();
|
||||
act(() => window.dispatchEvent(new Event("pagehide")));
|
||||
expect(localStorage.getItem(key)).toBe(saved);
|
||||
view.rerender(initial);
|
||||
expect(view.result.current.sendValue()).toEqual(chosen);
|
||||
expect(view.result.current.data?.value).toEqual(chosen);
|
||||
view.unmount();
|
||||
expect(localStorage.getItem(key)).toBe(saved);
|
||||
});
|
||||
|
||||
it("shows the Gateway's last-used options after a preset rename without sending a replacement", () => {
|
||||
const initial = props();
|
||||
const wrap = wrapper();
|
||||
const storedValue: SessionModelOptions = { reasoning_effort: "high", codex_fast_mode: "ultrafast" };
|
||||
const previous = renderHook(useSessionModelOptions, { wrapper: wrap, initialProps: initial });
|
||||
act(() => previous.result.current.select(storedValue));
|
||||
previous.unmount();
|
||||
|
||||
initial.settings.model_presets[0].name = "renamed";
|
||||
const renamed = { ...initial, preset: "renamed", storedValue };
|
||||
const reopened = renderHook(useSessionModelOptions, { wrapper: wrap, initialProps: renamed });
|
||||
expect(reopened.result.current.data?.value).toEqual(storedValue);
|
||||
expect(reopened.result.current.sendValue()).toBeUndefined();
|
||||
reopened.unmount();
|
||||
|
||||
const reloaded = renderHook(useSessionModelOptions, { wrapper: wrap, initialProps: renamed });
|
||||
expect(reloaded.result.current.data?.value).toEqual(storedValue);
|
||||
expect(reloaded.result.current.sendValue()).toBeUndefined();
|
||||
});
|
||||
|
||||
it("migrates a draft snapshot to the first session, clears both choices on preset switch, and clears the draft", () => {
|
||||
const initial = { ...props(), sessionKey: null as string | null };
|
||||
const wrap = wrapper();
|
||||
const view = renderHook(useSessionModelOptions, { wrapper: wrap, initialProps: initial });
|
||||
act(() => view.result.current.select(chosen));
|
||||
act(() => view.result.current.moveToSession("websocket:created", chosen));
|
||||
view.rerender({ ...initial, sessionKey: "websocket:created" });
|
||||
expect(view.result.current.sendValue()).toEqual(chosen);
|
||||
// ThreadShell resets options and selects the preset in the same action.
|
||||
act(() => {
|
||||
view.result.current.reset("other");
|
||||
view.rerender({ ...initial, sessionKey: "websocket:created", preset: "other" });
|
||||
});
|
||||
expect(view.result.current.sendValue()).toEqual(inherit);
|
||||
act(() => {
|
||||
view.result.current.reset("primary");
|
||||
view.rerender({ ...initial, sessionKey: "websocket:created" });
|
||||
});
|
||||
expect(view.result.current.sendValue()).toEqual(inherit);
|
||||
view.unmount();
|
||||
const landing = renderHook(useSessionModelOptions, { wrapper: wrap, initialProps: initial });
|
||||
expect(landing.result.current.data?.value).toEqual(inherit);
|
||||
expect(landing.result.current.sendValue()).toBeUndefined();
|
||||
});
|
||||
|
||||
it("preserves newer target choices made while draft creation was pending", () => {
|
||||
const initial = { ...props(), sessionKey: null as string | null };
|
||||
const view = renderHook(useSessionModelOptions, { wrapper: wrapper(), initialProps: initial });
|
||||
act(() => view.result.current.select(chosen));
|
||||
const transfer = view.result.current.moveToSession;
|
||||
view.rerender({ ...initial, sessionKey: "websocket:created" });
|
||||
const newer = { reasoning_effort: "low", codex_fast_mode: true };
|
||||
act(() => view.result.current.select(newer));
|
||||
act(() => transfer("websocket:created", chosen));
|
||||
expect(view.result.current.sendValue()).toEqual(newer);
|
||||
});
|
||||
|
||||
it.each(["temporary", "unsupported"])("hides and omits options for %s chats", (mode) => {
|
||||
const view = renderHook(useSessionModelOptions, { wrapper: wrapper(undefined, mode !== "unsupported"),
|
||||
initialProps: { ...props(), disabled: mode === "temporary" } });
|
||||
act(() => view.result.current.select(chosen));
|
||||
expect(view.result.current.data).toBeNull();
|
||||
expect(view.result.current.sendValue()).toBeUndefined();
|
||||
expect(localStorage.length).toBe(0);
|
||||
expect(api.fetchProviderModels).not.toHaveBeenCalled();
|
||||
});
|
||||
Reference in new issue
Block a user