From e821144c7eb491de9508eda576ab8c331523cea9 Mon Sep 17 00:00:00 2001 From: chengyongru <2755839590@qq.com> Date: Sun, 25 Oct 2026 20:22:20 +0800 Subject: [PATCH] feat(webui): search loaded message text in Ctrl+K --- webui/browser/fixture.tsx | 5 +- .../browser/loaded-session-search-fixture.tsx | 42 +++++++++++ webui/browser/loaded-session-search.spec.ts | 37 ++++++++++ webui/src/App.tsx | 1 + webui/src/components/SessionSearchDialog.tsx | 49 ++++++++++--- webui/src/components/thread/ThreadShell.tsx | 9 +++ webui/src/i18n/locales/en/common.json | 2 +- webui/src/i18n/locales/es/common.json | 2 +- webui/src/i18n/locales/fr/common.json | 2 +- webui/src/i18n/locales/id/common.json | 2 +- webui/src/i18n/locales/ja/common.json | 2 +- webui/src/i18n/locales/ko/common.json | 2 +- webui/src/i18n/locales/pt-BR/common.json | 2 +- webui/src/i18n/locales/vi/common.json | 2 +- webui/src/i18n/locales/zh-CN/common.json | 2 +- webui/src/i18n/locales/zh-TW/common.json | 2 +- webui/src/lib/loaded-message-search.ts | 47 ++++++++++++ webui/src/lib/memory-lru-cache.ts | 5 ++ webui/src/lib/thread-message-cache.ts | 57 +++++++++++++++ webui/src/tests/loaded-message-search.test.ts | 71 +++++++++++++++++++ .../src/tests/session-search-dialog.test.tsx | 50 ++++++++++++- webui/src/tests/thread-shell.test.tsx | 26 +++++++ 22 files changed, 396 insertions(+), 23 deletions(-) create mode 100644 webui/browser/loaded-session-search-fixture.tsx create mode 100644 webui/browser/loaded-session-search.spec.ts create mode 100644 webui/src/lib/loaded-message-search.ts create mode 100644 webui/src/tests/loaded-message-search.test.ts diff --git a/webui/browser/fixture.tsx b/webui/browser/fixture.tsx index e9908dd1d..caf6b33aa 100644 --- a/webui/browser/fixture.tsx +++ b/webui/browser/fixture.tsx @@ -40,6 +40,7 @@ import { MobileChatLayoutFixture } from "./mobile-chat-layout-fixture"; import { ThemeToggleFixture } from "./theme-toggle-fixture"; import { DisplayMathFixture } from "./display-math-fixture"; import { AttachmentLayoutFixture } from "./attachment-layout-fixture"; +import { LoadedSessionSearchFixture } from "./loaded-session-search-fixture"; const history: UIMessage[] = [ { id: "question", role: "user", content: "Earlier question", createdAt: 1_700_000_000_000 }, @@ -213,7 +214,9 @@ if (parameters.get("case") === "skeleton-additions") installSkeletonPreviewApi() if (parameters.get("case") === "idle-compaction") installIdleCompactionApi(); await initializeI18n(); createRoot(document.getElementById("root")!).render( - {parameters.get("case") === "attachments" + {parameters.get("case") === "loaded-session-search" + ? + : parameters.get("case") === "attachments" ? : parameters.get("case") === "theme-toggle" ? diff --git a/webui/browser/loaded-session-search-fixture.tsx b/webui/browser/loaded-session-search-fixture.tsx new file mode 100644 index 000000000..d104fe8f1 --- /dev/null +++ b/webui/browser/loaded-session-search-fixture.tsx @@ -0,0 +1,42 @@ +import { useEffect, useState } from "react"; +import { SessionSearchDialog } from "@/components/SessionSearchDialog"; +import { useAppViewport } from "@/hooks/useAppViewport"; +import { ThreadMessageCache } from "@/lib/thread-message-cache"; +import { ThreadTranscript } from "@/lib/thread-transcript"; +import type { ChatSummary } from "@/lib/types"; + +const sessions: ChatSummary[] = Array.from({ length: 1000 }, (_, index) => ({ + key: `websocket:topic-${index}`, chatId: `topic-${index}`, channel: "websocket", + title: `Topic ${index}`, preview: `Preview ${index}`, createdAt: null, updatedAt: null, +})); + +export function LoadedSessionSearchFixture() { + useAppViewport(); + const [open, setOpen] = useState(false); + const [selected, setSelected] = useState(null); + const [cache] = useState(() => { + const value = new ThreadMessageCache(() => false); + value.set("topic-1", new ThreadTranscript([ + { id: "user", role: "user", content: "我们讨论权限与配对", createdAt: 1 }, + { id: "answer", role: "assistant", content: `${"Earlier notes. ".repeat(500)}Use Full Access at 25% in session_history.py`, createdAt: 2 }, + ]).save()); + return value; + }); + useEffect(() => { + const shortcut = (event: KeyboardEvent) => { + if ((event.ctrlKey || event.metaKey) && event.key.toLowerCase() === "k") { + event.preventDefault(); + setOpen(true); + } + }; + window.addEventListener("keydown", shortcut); + return () => window.removeEventListener("keydown", shortcut); + }, []); + return
+ +