Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): 将群聊正文投影限定为 AI 改名
Dashee896a842588
diff --git a/apps/desktop/src/main/localDb/__tests__/latestMessageText.test.ts b/apps/desktop/src/main/localDb/__tests__/latestMessageText.test.tsindex 1dfb037088..ce87e46455 100644--- a/apps/desktop/src/main/localDb/__tests__/latestMessageText.test.ts+++ b/apps/desktop/src/main/localDb/__tests__/latestMessageText.test.ts@@ -219,7 +219,13 @@ describe('regenerateTitleMaterial hook user text', () => {index * 2 + 2,);}- const material = await regenerateTitleMaterial('s1', 2);+ const material = await regenerateTitleMaterial('s1', 2, false, { preferHookUserText: true });+ const predictionMaterial = await regenerateTitleMaterial('s1', 2);+ expect(predictionMaterial.opening.text).toBe(background + opening);+ expect(predictionMaterial.recent.map((m) => m.text)).toEqual([+ background + latest,+ '已整理修改',+ ]);expect(material.opening.text).toBe(opening);expect(material.recent.map((m) => m.text)).toEqual([latest, '已整理修改']);expect(material.recent[0].text.slice(0, 300)).toBe(latest);@@ -245,7 +251,7 @@ describe('regenerateTitleMaterial hook user text', () => {VALUES ('u1', 'cu1', 's1', 'user', ?, ?, 1)`,).run(JSON.stringify({ text: '原始用户正文' }), meta);- const material = await regenerateTitleMaterial('s1', 8);+ const material = await regenerateTitleMaterial('s1', 8, false, { preferHookUserText: true });expect(material.opening.text).toBe('原始用户正文');expect(material.recent.map((m) => m.text)).toEqual(['原始用户正文']);});diff --git a/apps/desktop/src/main/localDb/latestMessageText.ts b/apps/desktop/src/main/localDb/latestMessageText.tsindex 47cea33cbb..264e8037fd 100644--- a/apps/desktop/src/main/localDb/latestMessageText.ts+++ b/apps/desktop/src/main/localDb/latestMessageText.ts@@ -121,10 +121,13 @@ interface RecentTitleDbRow {rowid: number;}-function toTitleMessageCandidate(row: RecentTitleDbRow): TitleMessageCandidate | null {+function toTitleMessageCandidate(+ row: RecentTitleDbRow,+ preferHookUserText: boolean,+): TitleMessageCandidate | null {const role = row.role === 'user' ? 'user' : 'assistant';const agentMeta = parseTitleAgentMeta(row.agentMeta);- const text = extractTitleMessageText(row.content, role, agentMeta);+ const text = extractTitleMessageText(row.content, role, agentMeta, preferHookUserText);if (!text) return null;return {role,@@ -141,9 +144,16 @@ function extractTitleMessageText(content: string,role: 'user' | 'assistant',agentMeta: Record<string, unknown> | null,+ preferHookUserText: boolean,): string {const source = agentMeta?.hookSource;- if (role === 'user' && source && typeof source === 'object' && !Array.isArray(source)) {+ if (+ preferHookUserText &&+ role === 'user' &&+ source &&+ typeof source === 'object' &&+ !Array.isArray(source)+ ) {const userText = (source as Record<string, unknown>).userText;if (typeof userText === 'string' && userText.trim()) {// Match hook dispatch's empty-body fallback and preserve the existing@@ -229,6 +239,7 @@ async function recentMessagesWithClearedAt(clearedAt: number | null,snapshotUpperRowid: number | null,latestTurnIsInFlight: boolean,+ preferHookUserText: boolean,): Promise<RecentMessage[]> {if (limit <= 0 || snapshotUpperRowid == null) return [];const db = getDbClient().drizzle;@@ -280,7 +291,7 @@ async function recentMessagesWithClearedAt(};const pageCandidates = rows- .map(toTitleMessageCandidate)+ .map((row) => toTitleMessageCandidate(row, preferHookUserText)).filter((candidate): candidate is TitleMessageCandidate => candidate !== null);candidates.push(...pageCandidates);for (const candidate of pageCandidates) {@@ -332,6 +343,7 @@ async function firstUserMessageWithClearedAt(sessionId: string,clearedAt: number | null,snapshotUpperRowid: number | null,+ preferHookUserText: boolean,): Promise<OpeningMessage> {if (snapshotUpperRowid == null) return { text: '', createdAt: null, rowid: null };const db = getDbClient().drizzle;@@ -356,7 +368,7 @@ async function firstUserMessageWithClearedAt(for (const row of rows) {const agentMeta = parseTitleAgentMeta(row.agentMeta);if (!isVisibleTitleUser(agentMeta)) continue;- const text = extractTitleMessageText(row.content, 'user', agentMeta);+ const text = extractTitleMessageText(row.content, 'user', agentMeta, preferHookUserText);if (text) return { text, createdAt: row.createdAt ?? null, rowid: row.rowid };}return { text: '', createdAt: null, rowid: null };@@ -370,6 +382,8 @@ export async function regenerateTitleMaterial(sessionId: string,recentLimit: number,latestTurnIsInFlight: boolean | (() => boolean) = false,+ // Prompt prediction also consumes this material and needs injected context.+ options: { preferHookUserText?: boolean } = {},): Promise<RegenerateTitleMaterial> {const readLatestTurnIsInFlight = (): boolean =>typeof latestTurnIsInFlight === 'function'@@ -395,8 +409,14 @@ export async function regenerateTitleMaterial(clearedAt,snapshotUpperRowid,snapshotLatestTurnIsInFlight,+ options.preferHookUserText === true,+ ),+ firstUserMessageWithClearedAt(+ sessionId,+ clearedAt,+ snapshotUpperRowid,+ options.preferHookUserText === true,),- firstUserMessageWithClearedAt(sessionId, clearedAt, snapshotUpperRowid),]);return { recent, opening };}diff --git a/apps/desktop/src/main/maker-ipc/__tests__/autoTitleIpcBoundary.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/autoTitleIpcBoundary.test.tsindex d22a7a9c74..e675073362 100644--- a/apps/desktop/src/main/maker-ipc/__tests__/autoTitleIpcBoundary.test.ts+++ b/apps/desktop/src/main/maker-ipc/__tests__/autoTitleIpcBoundary.test.ts@@ -171,6 +171,7 @@ describe('maker:regenerate-title — 当前 turn 状态', () => {'s-running',expect.any(Number),expect.any(Function),+ { preferHookUserText: true },);});@@ -197,6 +198,7 @@ describe('maker:regenerate-title — 当前 turn 状态', () => {'s-completed',expect.any(Number),expect.any(Function),+ { preferHookUserText: true },);});@@ -227,6 +229,7 @@ describe('maker:regenerate-title — 当前 turn 状态', () => {'s-new-turn',expect.any(Number),expect.any(Function),+ { preferHookUserText: true },);});@@ -252,6 +255,7 @@ describe('maker:regenerate-title — 当前 turn 状态', () => {'s-snapshot-race',expect.any(Number),expect.any(Function),+ { preferHookUserText: true },);});});diff --git a/apps/desktop/src/main/maker-ipc/title.ts b/apps/desktop/src/main/maker-ipc/title.tsindex 5b6a48bf17..ed19e5b430 100644--- a/apps/desktop/src/main/maker-ipc/title.ts+++ b/apps/desktop/src/main/maker-ipc/title.ts@@ -155,7 +155,10 @@ async function readSessionAgentKindFromDb(sessionId: string): Promise<AgentKindconst defaultRegenerateDeps: RegenerateTitleDeps = {readSessionAgentKind: readSessionAgentKindFromDb,- collectMaterial: regenerateTitleMaterial,+ collectMaterial: (sessionId, recentLimit, latestTurnIsInFlight) =>+ regenerateTitleMaterial(sessionId, recentLimit, latestTurnIsInFlight, {+ preferHookUserText: true,+ }),generateTitle: (sessionId, agentKind, prompt) =>generateTitleWithAuxiliaryModelResult({ sessionId, agentKind, prompt },