From 8ad25215dd32dd6a1f8fda3c8483c41276ce735a Mon Sep 17 00:00:00 2001 From: yiling Date: Sun, 5 Jul 2026 16:31:14 +0800 Subject: [PATCH] refactor(agent): prevent creating autofill and embedding tasks for audio assets --- .../src/workflows/agent-autofill.test.ts | 4 ++- packages/core/src/upload/upload.ts | 9 +++--- .../transcode/src/activities/transcode.ts | 32 ++++++++++--------- 3 files changed, 25 insertions(+), 20 deletions(-) diff --git a/packages/agent/src/workflows/agent-autofill.test.ts b/packages/agent/src/workflows/agent-autofill.test.ts index f58fe802..c4fb185f 100644 --- a/packages/agent/src/workflows/agent-autofill.test.ts +++ b/packages/agent/src/workflows/agent-autofill.test.ts @@ -300,7 +300,9 @@ describe('Agent Autofill Workflow', () => { }, }) - await expect(agentAutofillMedia(task)).rejects.toThrow('unsupported media type for autofill: audio/mp3') + await expect(agentAutofillMedia(task)).rejects.toThrow( + 'unsupported media type for autofill: audio/mp3', + ) // Verify task failed status expect(mockActivities.updateTaskStatusActivity).toHaveBeenCalledWith({ diff --git a/packages/core/src/upload/upload.ts b/packages/core/src/upload/upload.ts index 016c1405..84cd3972 100644 --- a/packages/core/src/upload/upload.ts +++ b/packages/core/src/upload/upload.ts @@ -294,7 +294,11 @@ export class UploadService { }, }) - if (autofillAgent) { + const isVideo = asset.mediaType?.startsWith('video/') + const isImage = asset.mediaType?.startsWith('image/') + const isAudio = asset.mediaType?.startsWith('audio/') + + if (autofillAgent && (isVideo || isImage)) { await tx.workflowTask.create({ data: { assetId: asset.id, @@ -310,9 +314,6 @@ export class UploadService { }) } - const isVideo = asset.mediaType?.startsWith('video/') - const isImage = asset.mediaType?.startsWith('image/') - const isAudio = asset.mediaType?.startsWith('audio/') if (!isVideo && !isImage && !isAudio) { await tx.asset.update({ where: { id: asset.id }, diff --git a/packages/transcode/src/activities/transcode.ts b/packages/transcode/src/activities/transcode.ts index 921850fd..d601fb71 100644 --- a/packages/transcode/src/activities/transcode.ts +++ b/packages/transcode/src/activities/transcode.ts @@ -582,23 +582,25 @@ export interface CreateEmbeddingTaskIfEnabledParams { export async function createEmbeddingTaskIfEnabledActivity( params: CreateEmbeddingTaskIfEnabledParams, ): Promise { - let teamId = params.teamId - let projectId = params.projectId - - // Resolve teamId and projectId from asset if missing - if (!teamId || !projectId) { - const asset = await prisma.asset.findUnique({ - where: { id: params.assetId }, - include: { - project: true, - }, - }) - if (asset) { - projectId = projectId || asset.projectId - teamId = teamId || asset.project?.teamId || null - } + const asset = await prisma.asset.findUnique({ + where: { id: params.assetId }, + include: { + project: true, + }, + }) + if (!asset) { + return } + const isVideo = asset.mediaType?.startsWith('video/') + const isImage = asset.mediaType?.startsWith('image/') + if (!isVideo && !isImage) { + return + } + + const teamId = params.teamId || asset.project?.teamId || null + const projectId = params.projectId || asset.projectId + if (!teamId) { return }