feat(agent): refactor media tools to static injection with mandatory assetId and authz

This commit is contained in:
yiling
2026-07-21 16:09:39 +08:00
parent 1ac0d1452e
commit 93e957fa4f
8 changed files with 181 additions and 59 deletions
+24 -2
View File
@@ -4,15 +4,19 @@ import { type ImageContent } from '@earendil-works/pi-ai'
import { prisma, WorkflowTaskType, WorkflowTaskStatus } from '@shumai/db'
import { s3Service } from '@shumai/core/src/s3/s3'
import { workflowService } from '@shumai/workflow-core'
import { authzService, Permission, ResourceType } from '@shumai/core/src/authz/authz'
const screenshotSchema = Type.Object({
assetId: Type.String({
description: 'The asset ID of the video asset. This parameter is required.',
}),
start: Type.Number({ description: 'Start time in seconds' }),
end: Type.Number({ description: 'End time in seconds' }),
count: Type.Number({ description: 'Number of screenshots to take' }),
})
export function createScreenshotTool(
assetId: string,
userId?: string,
userCommentId?: string | null,
): AgentTool<typeof screenshotSchema> {
return {
@@ -23,6 +27,24 @@ export function createScreenshotTool(
parameters: screenshotSchema,
execute: async (_toolCallId, params) => {
try {
const assetId = params.assetId
if (userId) {
const user = await prisma.user.findUnique({ where: { id: userId } })
if (!user) {
return {
content: [{ type: 'text', text: `User not found: ${userId}` }],
details: {},
}
}
await authzService.hasPermission({
user,
permission: Permission.Read,
type: ResourceType.Asset,
id: assetId,
})
}
const asset = await prisma.asset.findUnique({
where: { id: assetId },
})
@@ -41,7 +63,7 @@ export function createScreenshotTool(
const comment = await prisma.assetComment.findUnique({
where: { id: userCommentId },
})
if (comment) {
if (comment && comment.assetId === assetId) {
commentTimestamp = comment.second !== null ? comment.second : null
if (comment.annotation) {
const list = comment.annotation