diff --git a/components/AppShell.auto-name.test.mjs b/components/AppShell.auto-name.test.mjs new file mode 100644 index 000000000..cfa55a2fc --- /dev/null +++ b/components/AppShell.auto-name.test.mjs @@ -0,0 +1,12 @@ +import assert from "node:assert/strict"; +import fs from "node:fs"; +import test from "node:test"; + +const source = fs.readFileSync(new URL("./AppShell.tsx", import.meta.url), "utf8"); + +test("压缩后的会话仍可根据持久化消息数生成标题", () => { + assert.match( + source, + /\(sessionStats\?\.userMessages \?\? 0\) > 0 \|\| selectedSession\.messageCount > 0/, + ); +}); diff --git a/components/AppShell.tsx b/components/AppShell.tsx index d4d827fa7..b22892e41 100644 --- a/components/AppShell.tsx +++ b/components/AppShell.tsx @@ -1023,9 +1023,10 @@ export function AppShell() { {!isMobile && {translate("history.label")}} {(() => { + // 上下文压缩后当前消息可能不再包含 user 消息,需同时参考会话文件的消息总数。 const hasMessages = Boolean( selectedSession - && (sessionStats?.userMessages ?? selectedSession.messageCount) > 0, + && ((sessionStats?.userMessages ?? 0) > 0 || selectedSession.messageCount > 0), ); const disabled = !selectedSession || !hasMessages || autoNameStatus.kind === "naming"; const isSuccess = autoNameStatus.kind === "success";