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:
chengyongru authored and GitHub committed 2026-11-18 15:46:16 +08:00
1 parent 2b232c9133
commit 0f45d74fec
82 files changed
+2289 -113

No files matched your search

@@ -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();
});