From bb789a9557c1a3fc3e6322299d907460f42c4c51 Mon Sep 17 00:00:00 2001 From: yiling Date: Wed, 29 Jul 2026 15:24:55 +0800 Subject: [PATCH] feat(agent): inject reply count alongside Thread ID tag in getPathToRoot --- packages/agent/src/activities/agent.test.ts | 2 +- .../agent/src/database-session-storage.ts | 19 +++++++++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/packages/agent/src/activities/agent.test.ts b/packages/agent/src/activities/agent.test.ts index 55ed2716..b6f3db65 100644 --- a/packages/agent/src/activities/agent.test.ts +++ b/packages/agent/src/activities/agent.test.ts @@ -665,7 +665,7 @@ describe('Agent Database Activities Integration', () => { expect(msg3Entry).toBeDefined() // eslint-disable-next-line @typescript-eslint/no-explicit-any const text = (msg3Entry as any).message.content[0].text - expect(text).toContain(`[Thread ID: ${msg3.id}]`) + expect(text).toContain(`[Thread ID: ${msg3.id}] [Replies: 1]`) }) it('should create separate thread sessions when agent is mentioned in top-level comments (msg3 & msg5) sharing DAG entries without duplication', async () => { diff --git a/packages/agent/src/database-session-storage.ts b/packages/agent/src/database-session-storage.ts index ac131168..17528cb4 100644 --- a/packages/agent/src/database-session-storage.ts +++ b/packages/agent/src/database-session-storage.ts @@ -267,23 +267,30 @@ export class DatabaseSessionStorage implements SessionStorage() + const threadReplyCountMap = new Map() for (const tc of threadCounts) { - if (tc.replyToId) commentIdsWithThreads.add(tc.replyToId) + if (tc.replyToId) { + threadReplyCountMap.set(tc.replyToId, tc._count.id) + } } - if (commentIdsWithThreads.size > 0) { + if (threadReplyCountMap.size > 0) { for (let i = 0; i < pathEntries.length; i++) { const entry = pathEntries[i] - if (commentIdsWithThreads.has(entry.id) && entry.type === 'message') { + const count = threadReplyCountMap.get(entry.id) + if (count !== undefined && count > 0 && entry.type === 'message') { const cloned = structuredClone(entry) const msg = cloned.message as unknown as { content?: Array<{ type: string; text: string }> } if (Array.isArray(msg.content) && msg.content[0] && msg.content[0].type === 'text') { - if (!msg.content[0].text.startsWith(`[Thread ID: ${entry.id}]`)) { - msg.content[0].text = `[Thread ID: ${entry.id}] ${msg.content[0].text}` + const threadTag = `[Thread ID: ${entry.id}] [Replies: ${count}]` + if (!msg.content[0].text.includes(`[Thread ID: ${entry.id}]`)) { + msg.content[0].text = `${threadTag} ${msg.content[0].text}` } } pathEntries[i] = cloned