mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-27 03:14:11 +00:00
fix(embedding): resolve transcoded MIME type and validate EMBEDDING_CHUNK_DURATION positive limits
This commit is contained in:
@@ -148,6 +148,38 @@ describe('Agent Embedding Workflow', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('should run agent embedding workflow successfully for image with transcoded format', async () => {
|
||||
mockActivities.getEmbeddingContextActivity.mockResolvedValue({
|
||||
agent: { id: 'b1' },
|
||||
asset: {
|
||||
id: 'a1',
|
||||
mediaType: 'image/png',
|
||||
storageKey: { key: 'test.png' },
|
||||
media: {
|
||||
imageTranscodes: [{ key: 'test-transcoded.webp', isRaw: false, format: 'webp' }]
|
||||
}
|
||||
},
|
||||
chunkDuration: 60.0,
|
||||
})
|
||||
|
||||
const task = await prisma.workflowTask.create({
|
||||
data: {
|
||||
type: 'ai_embedding',
|
||||
status: 'pending',
|
||||
assetId: 'a1',
|
||||
teamId: 't1',
|
||||
},
|
||||
})
|
||||
|
||||
await agentEmbeddingMedia(task)
|
||||
|
||||
expect(mockActivities.generateImageEmbeddingActivity).toHaveBeenCalledWith({
|
||||
teamId: 't1',
|
||||
assetKey: 'test-transcoded.webp',
|
||||
mediaType: 'image/webp',
|
||||
})
|
||||
})
|
||||
|
||||
it('should run agent embedding workflow successfully for video in chunks', async () => {
|
||||
mockActivities.getEmbeddingContextActivity.mockResolvedValue({
|
||||
agent: { id: 'b1' },
|
||||
|
||||
@@ -69,15 +69,15 @@ export async function agentEmbeddingMedia(task: WorkflowTask): Promise<void> {
|
||||
|
||||
// Resolve the S3 key to use for embedding (preferring transcoded version)
|
||||
let embeddingKey = asset.storageKey?.key
|
||||
let embeddingMediaType = asset.mediaType
|
||||
if (asset.media) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const media = asset.media as any
|
||||
if (isVideo) {
|
||||
if (media.videoTranscodes && media.videoTranscodes.length > 0) {
|
||||
// Find first non-raw transcode or fallback to first transcode
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const transcode =
|
||||
media.videoTranscodes.find((t: any) => !t.isRaw) || media.videoTranscodes[0]
|
||||
media.videoTranscodes.find((t: PrismaJson.VideoTranscode) => !t.isRaw) || media.videoTranscodes[0]
|
||||
if (transcode?.key) {
|
||||
embeddingKey = transcode.key
|
||||
}
|
||||
@@ -85,11 +85,13 @@ export async function agentEmbeddingMedia(task: WorkflowTask): Promise<void> {
|
||||
} else if (isImage) {
|
||||
if (media.imageTranscodes && media.imageTranscodes.length > 0) {
|
||||
// Find first non-raw transcode or fallback to first transcode
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const transcode =
|
||||
media.imageTranscodes.find((t: any) => !t.isRaw) || media.imageTranscodes[0]
|
||||
media.imageTranscodes.find((t: PrismaJson.ImageTranscode) => !t.isRaw) || media.imageTranscodes[0]
|
||||
if (transcode?.key) {
|
||||
embeddingKey = transcode.key
|
||||
if (transcode.format) {
|
||||
embeddingMediaType = `image/${transcode.format}`
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -110,7 +112,7 @@ export async function agentEmbeddingMedia(task: WorkflowTask): Promise<void> {
|
||||
const result = await executeActivity(agentWorkerQueue, generateImageEmbeddingActivity, {
|
||||
teamId: task.teamId,
|
||||
assetKey: embeddingKey,
|
||||
mediaType: asset.mediaType,
|
||||
mediaType: embeddingMediaType,
|
||||
})
|
||||
results.push({ embedding: result.embedding })
|
||||
if (result.usage) {
|
||||
|
||||
Reference in New Issue
Block a user