From 3c022ada6ac60f3a378aec583056b24e11188134 Mon Sep 17 00:00:00 2001 From: chengyongru <61816729+chengyongru@users.noreply.github.com> Date: Sat, 24 Oct 2026 03:00:22 +0800 Subject: [PATCH] fix(webui): show renamed topic titles in @ mentions (#6413) * fix(webui): use renamed titles for session mentions Pass persisted title overrides to each thread and resolve mention display titles through the same helper as the sidebar. Keep canonical session identities unchanged. Fixes NAN-342 * fix(webui): refresh bound session mention titles without truncating previews * fix(webui): persist topic renames as session titles with legacy import * fix(webui): keep session rename broadcast typed and identity-owned * fix(webui): limit topic-title fix to composer mentions Withdraw backend title storage, rename protocol/capability, import migration and global-title changes. Keep the existing sidebar title overrides and only project those names into the composer mention catalog. Retain focused single/split-pane rename, bound-label, send/reload and full-preview filtering coverage. * fix(webui): preserve bound mention and draft behavior Keep the fix limited to candidate titles. Leave existing bound references untouched and exercise rename, candidate filtering, selection, send and reload in the regression test. --- webui/src/App.tsx | 2 + webui/src/components/thread/ThreadShell.tsx | 11 ++- webui/src/tests/app-layout.test.tsx | 81 +++++++++++++++++++++ 3 files changed, 92 insertions(+), 2 deletions(-) diff --git a/webui/src/App.tsx b/webui/src/App.tsx index d43562f86..280dbd82c 100644 --- a/webui/src/App.tsx +++ b/webui/src/App.tsx @@ -3003,6 +3003,7 @@ function Shell({ = {}; + interface ThreadShellProps { session: ChatSummary | null; sessions?: ChatSummary[]; + titleOverrides?: Record; title: string; temporary?: boolean; temporaryChatIds?: readonly string[]; @@ -440,6 +443,7 @@ function useInstalledSettingItems({ export function ThreadShell({ session, sessions = [], + titleOverrides = EMPTY_TITLE_OVERRIDES, title, temporary = false, temporaryChatIds = [], @@ -486,8 +490,11 @@ export function ThreadShell({ const historyKey = temporary ? null : session?.key ?? null; const previewSessionKey = session?.key ?? null; const mentionSessions = useMemo( - () => sessions.filter((candidate) => candidate.key !== historyKey), - [historyKey, sessions], + () => sessions.filter((candidate) => candidate.key !== historyKey).map((candidate) => { + const renamedTitle = titleOverrides[candidate.key]?.trim(); + return renamedTitle ? { ...candidate, title: renamedTitle } : candidate; + }), + [historyKey, sessions, titleOverrides], ); const { client, getToken, ingressLimits, modelName, token, webuiCapabilities } = useClient(); const favoriteWorkspaceProject = useCallback( diff --git a/webui/src/tests/app-layout.test.tsx b/webui/src/tests/app-layout.test.tsx index e77acca32..3a2e3481c 100644 --- a/webui/src/tests/app-layout.test.tsx +++ b/webui/src/tests/app-layout.test.tsx @@ -2635,6 +2635,87 @@ describe("App layout", () => { expect(await screen.findByRole("button", { name: "Renamed topic" })).toBeInTheDocument(); }); + it.each([false, true])("uses renamed topic titles in mention candidates and sends across reloads (split=%s)", async (split) => { + restoreBrowserFocus = mockBrowserFocus(); + const user = userEvent.setup(); + const target: ChatSummary = { + key: "websocket:target", channel: "websocket", chatId: "target", + createdAt: null, updatedAt: null, title: "Generated title", preview: "Original question", + handle: { id: "handle_0123456789abcdef0123456789abcdef", name: "gane" }, + }; + mockSessions = [ + { ...target, key: "websocket:source", chatId: "source", title: "Source", handle: undefined }, + { ...target, key: "websocket:second", chatId: "second", title: "Second", handle: undefined }, + target, + ]; + window.history.replaceState(null, "", split ? "/#/chat/websocket%3Asource" : "/#/new"); + let persisted = { + workbench: { version: 1, tabs: split ? { + "tab:websocket:source": { + explicit: true, title: "Workspace", paneKeys: ["websocket:source", "websocket:second"], + layout: "columns", + }, + } : {} }, + } as Partial; + mockFetchRoutes({ "/api/webui/sidebar-state": () => persisted }); + setSidebarStateSpy.mockImplementation(async (state: SidebarStatePayload) => { + persisted = state; + return state; + }); + const firstRender = render(); + await act(async () => { await import("@/components/thread/ThreadShell"); }); + await waitFor(() => expect(connectSpy).toHaveBeenCalled()); + act(() => statusHandlers.forEach((handler) => handler("open"))); + const sidebar = screen.getByRole("navigation", { name: "Sidebar navigation" }); + await user.click(await within(sidebar).findByRole("button", { name: "Topic actions for Generated title" })); + await user.click(await screen.findByRole("menuitem", { name: "Rename" })); + const name = screen.getByRole("textbox", { name: "Topic name" }); + await user.clear(name); + await user.type(name, "会话编辑{Enter}"); + await within(sidebar).findByText("会话编辑"); + expect(persisted.title_overrides?.[target.key]).toBe("会话编辑"); + + const input = screen.getByRole("textbox", { name: /^Message / }); + fireEvent.change(input, { target: { value: "@", selectionStart: 1 } }); + expect(screen.getByRole("option", { name: /@gane/ })).toHaveTextContent("会话编辑"); + fireEvent.change(input, { target: { value: "@会话", selectionStart: 3 } }); + expect(screen.getByRole("option", { name: /@gane/ })).toHaveTextContent("会话编辑"); + fireEvent.keyDown(input, { key: "Tab" }); + fireEvent.keyDown(input, { key: "Escape" }); + expect(input).toHaveValue("@gane "); + expect(screen.getByTestId("composer-session-mention-gane")).toHaveAttribute("title", "Session: 会话编辑"); + fireEvent.keyDown(input, { key: "Enter" }); + await waitFor(() => expect(sendMessageSpy).toHaveBeenCalled()); + expect(sendMessageSpy.mock.calls.at(-1)?.[3]?.sessionMentions).toEqual([{ + id: target.handle?.id, name: "gane", session_key: target.key, title: "会话编辑", + }]); + + firstRender.unmount(); + render(); + await screen.findByText("会话编辑"); + const restoredInput = await screen.findByRole("textbox", { name: /^Message / }); + fireEvent.change(restoredInput, { target: { value: "@gane", selectionStart: 5 } }); + expect(screen.getByRole("option", { name: /@gane/ })).toHaveTextContent("会话编辑"); + }); + + it("searches the full preview of a session without a custom title", async () => { + restoreBrowserFocus = mockBrowserFocus(); + const preview = `Review notes ${"alpha ".repeat(10)}orangeunique`; + mockSessions = [{ + key: "websocket:target", channel: "websocket", chatId: "target", + createdAt: null, updatedAt: null, title: "", preview, + handle: { id: "handle_0123456789abcdef0123456789abcdef", name: "gane" }, + }]; + window.history.replaceState(null, "", "/#/new"); + render(); + await act(async () => { await import("@/components/thread/ThreadShell"); }); + await waitFor(() => expect(connectSpy).toHaveBeenCalled()); + act(() => statusHandlers.forEach((handler) => handler("open"))); + const input = screen.getByRole("textbox", { name: /^Message / }); + fireEvent.change(input, { target: { value: "@orangeunique", selectionStart: 13 } }); + expect(screen.getByRole("option", { name: /@gane/ })).toHaveTextContent("orangeunique"); + }); + it("retries a failed sidebar read before enabling edits without losing saved state", async () => { mockSessions = [ {