mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-27 03:14:11 +00:00
feat(agent): support 3D degree comments, markup annotations, and config3d in read_asset (#473)
* feat(agent): support AI embedding, autofill, and read_asset for 3D assets * feat(agent): support 3D degree comments, markup annotations, and config3d in read_asset * fix(agent): resolve 3D session annotations to turntable degree frame time
This commit is contained in:
@@ -806,4 +806,89 @@ describe('Agent Chat Workflow', () => {
|
||||
}),
|
||||
)
|
||||
})
|
||||
|
||||
it('should format mediaPosition as degree for 3D assets in 1-on-1 chat', async () => {
|
||||
mockActivities.getAssetActivity.mockResolvedValue({
|
||||
id: 'a-3d',
|
||||
project: { teamId: 't1' },
|
||||
type: 'file',
|
||||
name: 'model.glb',
|
||||
mediaType: 'model/gltf-binary',
|
||||
media: { proxyType: '3d' },
|
||||
parentId: null,
|
||||
})
|
||||
|
||||
const task = await prisma.workflowTask.create({
|
||||
data: {
|
||||
type: 'chat',
|
||||
status: 'pending',
|
||||
assetId: 'a-3d',
|
||||
payload: {
|
||||
projectId: 'p1',
|
||||
agent: {
|
||||
agentId: 'b1',
|
||||
prompt: 'Look at this angle',
|
||||
sessionId: 'session-3d-1',
|
||||
second: 0.5, // 0.5s turntable time = 45°
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
await agentChat(task)
|
||||
|
||||
expect(mockActivities.agentChatActivity).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
messageContext: expect.objectContaining({
|
||||
position: { type: 'degree', degree: 45 },
|
||||
}),
|
||||
}),
|
||||
)
|
||||
})
|
||||
|
||||
it('should format mediaPosition as degree for 3D assets in comment mode', async () => {
|
||||
mockActivities.getAssetActivity.mockResolvedValue({
|
||||
id: 'a-3d',
|
||||
project: { teamId: 't1' },
|
||||
type: 'file',
|
||||
name: 'model.glb',
|
||||
mediaType: 'model/gltf-binary',
|
||||
media: { proxyType: '3d' },
|
||||
parentId: null,
|
||||
})
|
||||
|
||||
mockActivities.getCommentActivity.mockResolvedValue({
|
||||
id: 'comment-3d-1',
|
||||
creatorId: 'user-c1',
|
||||
message: 'Look at the back',
|
||||
replyToId: null,
|
||||
second: 2.0, // 2.0s = 180°
|
||||
attachments: [],
|
||||
})
|
||||
|
||||
const task = await prisma.workflowTask.create({
|
||||
data: {
|
||||
type: 'chat',
|
||||
status: 'pending',
|
||||
assetId: 'a-3d',
|
||||
payload: {
|
||||
projectId: 'p1',
|
||||
agent: {
|
||||
agentId: 'b1',
|
||||
userCommentId: 'comment-3d-1',
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
await agentChat(task)
|
||||
|
||||
expect(mockActivities.agentChatActivity).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
messageContext: expect.objectContaining({
|
||||
position: { type: 'degree', degree: 180 },
|
||||
}),
|
||||
}),
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -8,6 +8,7 @@ import type {
|
||||
ShumaiMediaPosition,
|
||||
} from '@shumai/dtos'
|
||||
import { getProxyType } from '@shumai/core/src/utils/mime'
|
||||
import { secondToDegree } from '@shumai/core/src/utils/model3d'
|
||||
|
||||
export async function agentChat(task: WorkflowTask): Promise<void> {
|
||||
const {
|
||||
@@ -273,7 +274,9 @@ export async function agentChat(task: WorkflowTask): Promise<void> {
|
||||
// Build position
|
||||
let mediaPosition: ShumaiMediaPosition | undefined
|
||||
if (commentTimestamp !== undefined && commentTimestamp !== null) {
|
||||
if (proxyType === 'pdf') {
|
||||
if (proxyType === '3d') {
|
||||
mediaPosition = { type: 'degree', degree: secondToDegree(commentTimestamp) }
|
||||
} else if (proxyType === 'pdf') {
|
||||
mediaPosition = { type: 'page', page: Math.round(commentTimestamp) }
|
||||
} else {
|
||||
mediaPosition = { type: 'time', seconds: commentTimestamp }
|
||||
|
||||
@@ -211,6 +211,68 @@ describe('Agent Embedding Workflow', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('should run agent embedding workflow successfully for 3D asset using 4-views image', async () => {
|
||||
mockActivities.getEmbeddingContextActivity.mockResolvedValue({
|
||||
agent: { id: 'b1' },
|
||||
asset: {
|
||||
id: 'model-1',
|
||||
mediaType: 'model/gltf-binary',
|
||||
storageKey: { key: 'raw/model.glb' },
|
||||
media: {
|
||||
proxyType: '3d',
|
||||
imageTranscodes: [{ key: 'files/views.webp', format: 'webp' }],
|
||||
},
|
||||
},
|
||||
chunkDuration: 60.0,
|
||||
chunkOverlap: 5.0,
|
||||
})
|
||||
|
||||
const task = await prisma.workflowTask.create({
|
||||
data: {
|
||||
type: 'ai_embedding',
|
||||
status: 'pending',
|
||||
assetId: 'model-1',
|
||||
teamId: 't1',
|
||||
},
|
||||
})
|
||||
|
||||
await agentEmbeddingMedia(task)
|
||||
|
||||
expect(mockActivities.generateImageEmbeddingActivity).toHaveBeenCalledWith({
|
||||
teamId: 't1',
|
||||
assetKey: 'files/views.webp',
|
||||
mediaType: 'image/webp',
|
||||
})
|
||||
})
|
||||
|
||||
it('should reject 3D asset for embeddings if imageTranscodes is missing', async () => {
|
||||
mockActivities.getEmbeddingContextActivity.mockResolvedValue({
|
||||
agent: { id: 'b1' },
|
||||
asset: {
|
||||
id: 'model-1',
|
||||
mediaType: 'model/gltf-binary',
|
||||
storageKey: { key: 'raw/model.glb' },
|
||||
media: {
|
||||
proxyType: '3d',
|
||||
imageTranscodes: [],
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
const task = await prisma.workflowTask.create({
|
||||
data: {
|
||||
type: 'ai_embedding',
|
||||
status: 'pending',
|
||||
assetId: 'model-1',
|
||||
teamId: 't1',
|
||||
},
|
||||
})
|
||||
|
||||
await expect(agentEmbeddingMedia(task)).rejects.toThrow(
|
||||
'unsupported media type for embeddings: model/gltf-binary',
|
||||
)
|
||||
})
|
||||
|
||||
it('should run agent embedding workflow successfully for video in chunks', async () => {
|
||||
mockActivities.getEmbeddingContextActivity.mockResolvedValue({
|
||||
agent: { id: 'b1' },
|
||||
|
||||
@@ -70,7 +70,10 @@ export async function agentEmbeddingMedia(task: WorkflowTask): Promise<void> {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const { asset, chunkDuration, chunkOverlap } = context as any
|
||||
|
||||
const isImage = asset.mediaType?.startsWith('image/')
|
||||
const mediaInfo = asset.media as PrismaJson.MediaInfo | null
|
||||
const is3dWithViews =
|
||||
mediaInfo?.proxyType === '3d' && (mediaInfo.imageTranscodes?.length ?? 0) > 0
|
||||
const isImage = asset.mediaType?.startsWith('image/') || is3dWithViews
|
||||
const isVideo = asset.mediaType?.startsWith('video/')
|
||||
|
||||
if (!isImage && !isVideo) {
|
||||
|
||||
Reference in New Issue
Block a user