From 810e0c4cf57cf86ef5ae8c541a6551253994984b Mon Sep 17 00:00:00 2001 From: yiling Date: Sun, 30 Aug 2026 15:51:23 +0800 Subject: [PATCH] fix(agent): only include duration_seconds for time-based media (video/audio) --- .../agent/src/workflows/agent-chat.test.ts | 3 ++- packages/agent/src/workflows/agent-chat.ts | 26 +++++++++++++++---- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/packages/agent/src/workflows/agent-chat.test.ts b/packages/agent/src/workflows/agent-chat.test.ts index 74f00699..0316f523 100644 --- a/packages/agent/src/workflows/agent-chat.test.ts +++ b/packages/agent/src/workflows/agent-chat.test.ts @@ -672,7 +672,7 @@ describe('Agent Chat Workflow', () => { type: 'file', name: 'doc.pdf', mediaType: 'application/pdf', - media: { proxyType: 'pdf', frames: 15 }, + media: { proxyType: 'pdf', frames: 15, duration: 0 }, parentId: 'f1', } } @@ -729,6 +729,7 @@ describe('Agent Chat Workflow', () => { mediaType: 'pdf', totalPages: 15, totalFrames: undefined, + durationSeconds: undefined, }), }), }), diff --git a/packages/agent/src/workflows/agent-chat.ts b/packages/agent/src/workflows/agent-chat.ts index 117512fd..d58c09f9 100644 --- a/packages/agent/src/workflows/agent-chat.ts +++ b/packages/agent/src/workflows/agent-chat.ts @@ -7,6 +7,7 @@ import type { ShumaiAttachedFileContext, ShumaiMediaPosition, } from '@shumai/dtos' +import { getProxyType } from '@shumai/core/src/utils/mime' export async function agentChat(task: WorkflowTask): Promise { const { @@ -145,8 +146,14 @@ export async function agentChat(task: WorkflowTask): Promise { // eslint-disable-next-line @typescript-eslint/no-explicit-any const mediaInfo = asset.media as any - const duration = mediaInfo?.duration - const proxyType = (asset.media as PrismaJson.MediaInfo | null)?.proxyType + const proxyType = + (asset.media as PrismaJson.MediaInfo | null)?.proxyType || + getProxyType(asset.mediaType, asset.name) || + undefined + const duration = + (proxyType === 'video' || proxyType === 'audio') && typeof mediaInfo?.duration === 'number' + ? mediaInfo.duration + : undefined const totalPages = proxyType === 'pdf' ? mediaInfo?.frames || mediaInfo?.metadata?.totalFrames : undefined const totalFrames = @@ -163,7 +170,10 @@ export async function agentChat(task: WorkflowTask): Promise { getAssetPathContextActivity, att.asset.id, ) - const attProxyType = (att.asset.media as PrismaJson.MediaInfo | null)?.proxyType + const attProxyType = + (att.asset.media as PrismaJson.MediaInfo | null)?.proxyType || + getProxyType(att.asset.mediaType, att.asset.name) || + undefined attachedFiles.push({ id: att.asset.id, name: att.asset.name, @@ -184,7 +194,10 @@ export async function agentChat(task: WorkflowTask): Promise { getAssetPathContextActivity, fileId, ) - const fileProxyType = (file.media as PrismaJson.MediaInfo | null)?.proxyType + const fileProxyType = + (file.media as PrismaJson.MediaInfo | null)?.proxyType || + getProxyType(file.mediaType, file.name) || + undefined attachedFiles.push({ id: file.id, name: file.name, @@ -209,7 +222,10 @@ export async function agentChat(task: WorkflowTask): Promise { getAssetPathContextActivity, assetId, ) - const refProxyType = (referencedAsset.media as PrismaJson.MediaInfo | null)?.proxyType + const refProxyType = + (referencedAsset.media as PrismaJson.MediaInfo | null)?.proxyType || + getProxyType(referencedAsset.mediaType, referencedAsset.name) || + undefined referencedAssets.push({ id: referencedAsset.id, name: referencedAsset.name,