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.
This commit is contained in:
1 parent
6d4add200b
commit
3c022ada6a
3 files changed
+92
-2
No files matched your search
@@ -3003,6 +3003,7 @@ function Shell({
|
||||
<ThreadShell
|
||||
session={activeSession}
|
||||
sessions={sessions}
|
||||
titleOverrides={sidebarState.title_overrides}
|
||||
title={headerTitle}
|
||||
temporary={temporaryChatRequested}
|
||||
temporaryChatIds={temporaryChatIds}
|
||||
@@ -3053,6 +3054,7 @@ function Shell({
|
||||
<ThreadShell
|
||||
session={paneSession}
|
||||
sessions={sessions}
|
||||
titleOverrides={sidebarState.title_overrides}
|
||||
title={pane.title}
|
||||
temporaryChatIds={temporaryChatIds}
|
||||
messageCache={threadMessageCache}
|
||||
|
||||
@@ -212,9 +212,12 @@ function maxFilePreviewWidth(containerWidth: number): number {
|
||||
);
|
||||
}
|
||||
|
||||
const EMPTY_TITLE_OVERRIDES: Record<string, string> = {};
|
||||
|
||||
interface ThreadShellProps {
|
||||
session: ChatSummary | null;
|
||||
sessions?: ChatSummary[];
|
||||
titleOverrides?: Record<string, string>;
|
||||
title: string;
|
||||
temporary?: boolean;
|
||||
temporaryChatIds?: readonly string[];
|
||||
@@ -440,6 +443,7 @@ function useInstalledSettingItems<Payload, Item>({
|
||||
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(
|
||||
|
||||
@@ -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<SidebarStatePayload>;
|
||||
mockFetchRoutes({ "/api/webui/sidebar-state": () => persisted });
|
||||
setSidebarStateSpy.mockImplementation(async (state: SidebarStatePayload) => {
|
||||
persisted = state;
|
||||
return state;
|
||||
});
|
||||
const firstRender = render(<App />);
|
||||
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(<App />);
|
||||
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(<App />);
|
||||
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 = [
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user