mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-26 03:27:19 +00:00
feat(agent): replace isAi with sessionId & implement admin logs UI
This commit is contained in:
@@ -421,7 +421,7 @@ export class AgentService {
|
||||
prompt: string,
|
||||
images: string[],
|
||||
fields: AutofillField[],
|
||||
): Promise<{ text: string; usage: Usage }> {
|
||||
): Promise<{ text: string; usage: Usage; sessionId: string }> {
|
||||
const agent = await this.prismaClient.agent.findFirst({
|
||||
where: {
|
||||
type: 'autofill',
|
||||
@@ -457,7 +457,7 @@ export class AgentService {
|
||||
|
||||
const fullPrompt = `${prompt}\n\nPlease use the "autofill_metadata" tool to provide the extracted metadata.`
|
||||
|
||||
const { usage } = await this.chatWithAgent(
|
||||
const { usage, sessionId } = await this.chatWithAgent(
|
||||
teamId,
|
||||
agent.id,
|
||||
fullPrompt,
|
||||
@@ -471,8 +471,16 @@ export class AgentService {
|
||||
return {
|
||||
text: capturedData ? JSON.stringify(capturedData) : '{}',
|
||||
usage,
|
||||
sessionId,
|
||||
}
|
||||
}
|
||||
|
||||
async getSessionEntries(params: { sessionId: string }) {
|
||||
return this.prismaClient.agentSessionEntry.findMany({
|
||||
where: { sessionId: params.sessionId },
|
||||
orderBy: { id: 'asc' },
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export const agentService = new AgentService()
|
||||
|
||||
@@ -507,12 +507,21 @@ describe('AssetService', () => {
|
||||
},
|
||||
})
|
||||
|
||||
// Create a real agent session
|
||||
const session = await prisma.agentSession.create({
|
||||
data: {
|
||||
id: 'session-id-123',
|
||||
agentId: agentUser.id,
|
||||
cwd: process.cwd(),
|
||||
},
|
||||
})
|
||||
|
||||
// Create an AI comment manually using the activity-like logic
|
||||
await prisma.assetComment.create({
|
||||
data: {
|
||||
assetId: assets.fileA1.id,
|
||||
message: 'I am an AI',
|
||||
isAi: true,
|
||||
sessionId: session.id,
|
||||
creatorId: agentUser.id,
|
||||
},
|
||||
})
|
||||
@@ -521,7 +530,7 @@ describe('AssetService', () => {
|
||||
first: 10,
|
||||
})
|
||||
|
||||
const aiComment = list.data.find((c) => c.isAi)
|
||||
const aiComment = list.data.find((c) => !!c.sessionId)
|
||||
expect(aiComment).toBeDefined()
|
||||
expect(aiComment?.creator.id).toBe(agentUser.id)
|
||||
expect(aiComment?.creator.name).toBe('Smart Agent')
|
||||
@@ -632,7 +641,7 @@ describe('AssetService', () => {
|
||||
|
||||
// Check if AI placeholder comments were NOT created here (moved to workflow)
|
||||
const comments = await prisma.assetComment.findMany({
|
||||
where: { assetId: file.id, isAi: true },
|
||||
where: { assetId: file.id, sessionId: { not: null } },
|
||||
})
|
||||
expect(comments.length).toBe(0)
|
||||
|
||||
|
||||
@@ -1058,7 +1058,7 @@ export class AssetService {
|
||||
}
|
||||
|
||||
const creator: UserInfo = { id: '', name: '' }
|
||||
if (c.isAi) {
|
||||
if (c.sessionId) {
|
||||
creator.id = c.creatorId || ''
|
||||
creator.name = c.creator?.name || 'Ai Bot'
|
||||
} else if (c.creator) {
|
||||
@@ -1077,7 +1077,7 @@ export class AssetService {
|
||||
mentions,
|
||||
createdAt: c.createdAt.toISOString(),
|
||||
updatedAt: c.updatedAt.toISOString(),
|
||||
isAi: c.isAi,
|
||||
sessionId: c.sessionId,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user