feat(webui): switch model presets from the composer (#5077)

This commit is contained in:
chengyongru
2026-07-24 17:34:26 +08:00
committed by GitHub
parent 9aab94c766
commit 5be176a6a0
16 changed files with 991 additions and 138 deletions
+30 -1
View File
@@ -1,6 +1,10 @@
import { describe, expect, it } from "vitest";
import { normalizeLegacyLongTaskMessages } from "@/lib/thread-display-compat";
import { deriveTitle, isModelCommandText, visibleSessionPreview } from "@/lib/format";
import {
normalizeLegacyLongTaskMessages,
projectWebuiThreadMessages,
} from "@/lib/thread-display-compat";
import type { UIMessage } from "@/lib/types";
describe("normalizeLegacyLongTaskMessages", () => {
@@ -17,4 +21,29 @@ describe("normalizeLegacyLongTaskMessages", () => {
expect(out[0]!.role).toBe("tool");
expect(out[0]!.traces).toEqual(["long_task · done"]);
});
it("removes model and silent-command turns without hiding concurrent replies", () => {
const message = (
id: string,
role: UIMessage["role"],
content: string,
turnId?: string,
): UIMessage => ({ id, role, content, createdAt: 1, turnId });
const visible = projectWebuiThreadMessages([
message("model", "user", "/model fast", "model-turn"),
message("model-reply", "assistant", "Switched model preset to fast.", "model-turn"),
message("silent", "user", "/restart", "webui-system:restart"),
message("reply", "assistant", "This unrelated reply stays visible.", "other-turn"),
]);
expect(visible.map(({ content }) => content)).toEqual([
"This unrelated reply stays visible.",
]);
expect([
isModelCommandText("/MODEL@nanobot fast"),
isModelCommandText("/modelish"),
]).toEqual([true, false]);
expect(visibleSessionPreview("Switched model preset to `fast`.")).toBe("");
expect(deriveTitle("## Model\n- Current model: `gpt-5.5`", "New chat")).toBe("New chat");
});
});