fix(agent): only include duration_seconds for time-based media (video/audio)

This commit is contained in:
yiling
2026-08-30 15:51:23 +08:00
parent 07cb648183
commit 810e0c4cf5
2 changed files with 23 additions and 6 deletions
@@ -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,
}),
}),
}),
+21 -5
View File
@@ -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<void> {
const {
@@ -145,8 +146,14 @@ export async function agentChat(task: WorkflowTask): Promise<void> {
// 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<void> {
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<void> {
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<void> {
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,