mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-28 03:44:27 +00:00
feat(asset): record and display agent provenance on assets and audit logs (#380)
* feat(asset): record and display agent provenance on assets and audit logs * style(webui): apply 30% translucent frosted glass background to bot badges * style(webui): match bot icon badge style to thumbnail media overlay (bg-black/60 text-white) * style(webui): use "AI" text badge with pdf overlay style instead of bot icon
This commit is contained in:
@@ -116,4 +116,57 @@ describe('AuditLogService', () => {
|
||||
expect(result.nodes.map((n) => n.action)).toContain(AuditAction.kanban_task_create)
|
||||
expect(result.nodes.map((n) => n.action)).toContain(AuditAction.kanban_goal_create)
|
||||
})
|
||||
|
||||
it('records and filters agent provenance in audit logs', async () => {
|
||||
const user = await prisma.user.create({
|
||||
data: { name: 'Audit Human User', email: 'audit_human@example.com', password: 'password' },
|
||||
})
|
||||
const team = await prisma.team.create({
|
||||
data: { name: 'Agent Audit Team' },
|
||||
})
|
||||
const agentUser = await prisma.user.create({
|
||||
data: {
|
||||
name: 'Creation Bot',
|
||||
email: 'creation_bot@example.com',
|
||||
type: 'agent',
|
||||
},
|
||||
})
|
||||
const agent = await prisma.agent.create({
|
||||
data: {
|
||||
id: agentUser.id,
|
||||
teamId: team.id,
|
||||
type: 'chat',
|
||||
config: { provider: 'test', model: 'test' },
|
||||
},
|
||||
})
|
||||
|
||||
const log = await auditLogService.logAction({
|
||||
action: AuditAction.file_create,
|
||||
teamId: team.id,
|
||||
userId: user.id,
|
||||
agentId: agent.id,
|
||||
itemId: 'file-xyz',
|
||||
})
|
||||
|
||||
expect(log).toBeDefined()
|
||||
expect(log?.agentId).toBe(agent.id)
|
||||
|
||||
const resultWithAgent = await auditLogService.listAuditLogs({
|
||||
teamId: team.id,
|
||||
agentIds: [agent.id],
|
||||
})
|
||||
|
||||
expect(resultWithAgent.total).toBe(1)
|
||||
expect(resultWithAgent.nodes[0].agentId).toBe(agent.id)
|
||||
expect(resultWithAgent.nodes[0].agent).toEqual({
|
||||
id: agent.id,
|
||||
name: 'Creation Bot',
|
||||
})
|
||||
|
||||
const resultOtherAgent = await auditLogService.listAuditLogs({
|
||||
teamId: team.id,
|
||||
agentIds: ['non-existent-agent'],
|
||||
})
|
||||
expect(resultOtherAgent.total).toBe(0)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -8,6 +8,7 @@ export interface LogActionParams {
|
||||
action: AuditAction
|
||||
teamId: string
|
||||
userId?: string
|
||||
agentId?: string
|
||||
projectId?: string
|
||||
itemId?: string
|
||||
}
|
||||
@@ -16,6 +17,7 @@ export interface ListAuditLogsParams {
|
||||
teamId: string
|
||||
actions?: AuditAction[]
|
||||
userIds?: string[]
|
||||
agentIds?: string[]
|
||||
itemId?: string
|
||||
first?: number
|
||||
after?: string
|
||||
@@ -29,6 +31,7 @@ export class AuditLogService {
|
||||
action: params.action,
|
||||
teamId: params.teamId,
|
||||
userId: params.userId,
|
||||
agentId: params.agentId,
|
||||
projectId: params.projectId,
|
||||
itemId: params.itemId,
|
||||
},
|
||||
@@ -52,6 +55,10 @@ export class AuditLogService {
|
||||
where.userId = { in: params.userIds }
|
||||
}
|
||||
|
||||
if (params.agentIds && params.agentIds.length > 0) {
|
||||
where.agentId = { in: params.agentIds }
|
||||
}
|
||||
|
||||
if (params.itemId && params.itemId.trim() !== '') {
|
||||
where.itemId = { contains: params.itemId.trim(), mode: 'insensitive' }
|
||||
}
|
||||
@@ -60,6 +67,7 @@ export class AuditLogService {
|
||||
(skip, take) =>
|
||||
prisma.auditLog.findMany({
|
||||
where,
|
||||
include: { agent: { include: { user: true } } },
|
||||
orderBy: { id: 'desc' },
|
||||
skip,
|
||||
take,
|
||||
@@ -74,6 +82,8 @@ export class AuditLogService {
|
||||
action: item.action,
|
||||
teamId: item.teamId,
|
||||
userId: item.userId,
|
||||
agentId: item.agentId,
|
||||
agent: item.agent ? { id: item.agent.id, name: item.agent.user.name } : null,
|
||||
projectId: item.projectId,
|
||||
itemId: item.itemId,
|
||||
createdAt: item.createdAt.toISOString(),
|
||||
|
||||
Reference in New Issue
Block a user