mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-24 17:19:02 +00:00
refactor(agent): optimize ULID id sorting and exclude __CHAT__ placeholder comments
This commit is contained in:
@@ -597,7 +597,7 @@ describe('Agent Database Activities Integration', () => {
|
||||
// Retrieve main session entries (contains top-level comments mainComment1 and mainComment2)
|
||||
const mainEntries = await prisma.agentSessionEntry.findMany({
|
||||
where: { sessionId: mainSession!.id },
|
||||
orderBy: { createdAt: 'asc' },
|
||||
orderBy: { id: 'asc' },
|
||||
})
|
||||
|
||||
// Main session contains mainComment1 and mainComment2, but NOT threadReply1
|
||||
@@ -878,6 +878,37 @@ describe('Agent Database Activities Integration', () => {
|
||||
).resolves.not.toThrow()
|
||||
})
|
||||
|
||||
it('should not tag Thread ID when only __CHAT__ placeholder comment exists under root comment', async () => {
|
||||
const rootComment = await prisma.assetComment.create({
|
||||
data: { assetId: asset.id, message: 'Root comment asking agent', creatorId: user.id },
|
||||
})
|
||||
// Create placeholder comment under rootComment
|
||||
await prisma.assetComment.create({
|
||||
data: {
|
||||
assetId: asset.id,
|
||||
message: '__CHAT__',
|
||||
creatorId: user.id,
|
||||
replyToId: rootComment.id,
|
||||
},
|
||||
})
|
||||
|
||||
const sessionId = await initializeAgentSessionActivity({
|
||||
teamId: team.id,
|
||||
agentId: 'test-agent-id',
|
||||
userCommentId: rootComment.id,
|
||||
userId: user.id,
|
||||
})
|
||||
|
||||
const storage = new DatabaseSessionStorage(sessionId)
|
||||
const pathEntries = await storage.getPathToRoot(rootComment.id)
|
||||
const rootEntry = pathEntries.find((e) => e.id === rootComment.id)
|
||||
|
||||
expect(rootEntry).toBeDefined()
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- entry data structure parsing
|
||||
const content = (rootEntry as any)?.message?.content?.[0]?.text || ''
|
||||
expect(content).not.toContain(`[Thread ID: ${rootComment.id}]`)
|
||||
})
|
||||
|
||||
it('should return user name and role for team member', async () => {
|
||||
const info = await getUserTeamInfoActivity({
|
||||
userId: user.id,
|
||||
|
||||
@@ -547,14 +547,14 @@ export async function initializeAgentSessionActivity(params: {
|
||||
})
|
||||
}
|
||||
|
||||
// 1. Fetch top-level comments up to rootComment.createdAt
|
||||
// 1. Fetch top-level comments up to rootComment.createdAt sorted by id
|
||||
const topLevelComments = await prisma.assetComment.findMany({
|
||||
where: {
|
||||
assetId: userComment.assetId,
|
||||
replyToId: null,
|
||||
createdAt: { lte: rootComment.createdAt },
|
||||
},
|
||||
orderBy: { createdAt: 'asc' },
|
||||
orderBy: { id: 'asc' },
|
||||
include: { creator: true },
|
||||
})
|
||||
|
||||
@@ -566,7 +566,7 @@ export async function initializeAgentSessionActivity(params: {
|
||||
createdAt: { lte: userComment.createdAt },
|
||||
id: { not: userComment.id },
|
||||
},
|
||||
orderBy: { createdAt: 'asc' },
|
||||
orderBy: { id: 'asc' },
|
||||
include: { creator: true },
|
||||
})
|
||||
: []
|
||||
|
||||
@@ -265,6 +265,7 @@ export class DatabaseSessionStorage implements SessionStorage<DatabaseSessionMet
|
||||
by: ['replyToId'],
|
||||
where: {
|
||||
replyToId: { in: entryIds },
|
||||
message: { not: '__CHAT__' },
|
||||
},
|
||||
})
|
||||
const commentIdsWithThreads = new Set<string>()
|
||||
|
||||
@@ -28,8 +28,11 @@ export const createReadThreadTool = (): AgentTool<
|
||||
}
|
||||
|
||||
const replies = await prisma.assetComment.findMany({
|
||||
where: { replyToId: rootComment.id },
|
||||
orderBy: { createdAt: 'asc' },
|
||||
where: {
|
||||
replyToId: rootComment.id,
|
||||
message: { not: '__CHAT__' },
|
||||
},
|
||||
orderBy: { id: 'asc' },
|
||||
include: { creator: true },
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user