feat(agent): implement dynamic in-memory thread tagging for session context entries

This commit is contained in:
yiling
2026-07-28 11:51:25 +08:00
parent 4e2694e2d9
commit 56421cd562
3 changed files with 84 additions and 22 deletions
@@ -247,6 +247,39 @@ export class DatabaseSessionStorage implements SessionStorage<DatabaseSessionMet
await this.reinjectSkillContentAsync(entry)
}
// Dynamically tag comments that currently have reply threads
const entryIds = pathEntries.map((e) => e.id)
if (entryIds.length > 0) {
const threadCounts = await prisma.assetComment.groupBy({
by: ['replyToId'],
where: {
replyToId: { in: entryIds },
},
})
const commentIdsWithThreads = new Set<string>()
for (const tc of threadCounts) {
if (tc.replyToId) commentIdsWithThreads.add(tc.replyToId)
}
if (commentIdsWithThreads.size > 0) {
for (let i = 0; i < pathEntries.length; i++) {
const entry = pathEntries[i]
if (commentIdsWithThreads.has(entry.id) && 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}`
}
}
pathEntries[i] = cloned
}
}
}
}
return pathEntries
}