feat(api): add missing audit log calls to API endpoints

This commit is contained in:
yiling
2026-08-01 11:03:50 +08:00
parent 7dfb2c7f2f
commit 0324b95c7e
18 changed files with 695 additions and 2 deletions
+30
View File
@@ -12,6 +12,8 @@ import {
} from '@shumai/dtos'
import type { Prisma } from '@shumai/db'
import { prisma, AuditAction } from '@shumai/db'
import { auditLogService } from '@shumai/core/src/auditLog/auditLog'
type User = Prisma.UserGetPayload<Record<string, never>>
@@ -94,6 +96,13 @@ const route = new Hono<{ Variables: { user: User } }>()
deniedTools: config.deniedTools || [],
}
await auditLogService.logAction({
action: AuditAction.agent_create,
teamId,
userId: userReq?.id,
itemId: agent.id,
})
return c.json(info, 200)
})
.put('/agents/:agentId', zValidator('json', updateAgentRequestSchema), async (c) => {
@@ -113,6 +122,13 @@ const route = new Hono<{ Variables: { user: User } }>()
...req,
})
await auditLogService.logAction({
action: AuditAction.agent_update,
teamId: agent.teamId,
userId: userReq?.id,
itemId: agent.id,
})
const config = agent.config as unknown as PrismaJson.AgentConfig
const info: AgentInfo = {
id: agent.id,
@@ -146,10 +162,24 @@ const route = new Hono<{ Variables: { user: User } }>()
id: agentId,
})
const existingAgent = await prisma.agent.findUnique({
where: { id: agentId },
select: { teamId: true },
})
await agentService.deleteAgent({
agentId,
})
if (existingAgent) {
await auditLogService.logAction({
action: AuditAction.agent_delete,
teamId: existingAgent.teamId,
userId: userReq?.id,
itemId: agentId,
})
}
return new Response(null, { status: 204 })
})
.get('/agent-sessions/:sessionId/entries', async (c) => {