mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-12-06 08:04:37 +00:00
* 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
61 lines
2.2 KiB
TypeScript
61 lines
2.2 KiB
TypeScript
import { prisma } from '@shumai/db'
|
|
import type { ShumaiMessageContext } from '@shumai/dtos'
|
|
import { degreeToSecond } from '@shumai/core/src/utils/model3d'
|
|
|
|
export async function resolveAnnotationsById(
|
|
assetId: string,
|
|
annotationId?: string | null,
|
|
): Promise<{ annotations: PrismaJson.AnnotationList | null; timestamp: number | null }> {
|
|
if (!annotationId) {
|
|
return { annotations: null, timestamp: null }
|
|
}
|
|
|
|
// 1. Check AssetComment table (Comments Mode)
|
|
const comment = await prisma.assetComment.findUnique({
|
|
where: { id: annotationId },
|
|
select: { assetId: true, annotation: true, second: true },
|
|
})
|
|
if (comment) {
|
|
if (comment.assetId !== assetId) {
|
|
throw new Error(
|
|
`Annotation "${annotationId}" belongs to asset "${comment.assetId}", not target asset "${assetId}".`,
|
|
)
|
|
}
|
|
const list = comment.annotation
|
|
const annotations =
|
|
Array.isArray(list) && list.length > 0 ? (list as PrismaJson.AnnotationList) : null
|
|
return { annotations, timestamp: comment.second }
|
|
}
|
|
|
|
// 2. Check AgentSessionEntry table (1-on-1 Chat Mode)
|
|
const entry = await prisma.agentSessionEntry.findUnique({
|
|
where: { id: annotationId },
|
|
select: { assetId: true, data: true },
|
|
})
|
|
if (entry) {
|
|
const details = (entry.data as Record<string, unknown> | null)?.details as
|
|
| ShumaiMessageContext
|
|
| undefined
|
|
const entryAssetId = entry.assetId || details?.currentAsset?.id
|
|
if (entryAssetId && entryAssetId !== assetId) {
|
|
throw new Error(
|
|
`Annotation "${annotationId}" belongs to asset "${entryAssetId}", not target asset "${assetId}".`,
|
|
)
|
|
}
|
|
const list = details?.annotations
|
|
const annotations =
|
|
Array.isArray(list) && list.length > 0 ? (list as unknown as PrismaJson.AnnotationList) : null
|
|
let timestamp: number | null = null
|
|
if (details?.position?.type === 'time') {
|
|
timestamp = details.position.seconds
|
|
} else if (details?.position?.type === 'degree') {
|
|
timestamp = degreeToSecond(details.position.degree)
|
|
} else if (details?.position?.type === 'page') {
|
|
timestamp = details.position.page
|
|
}
|
|
return { annotations, timestamp }
|
|
}
|
|
|
|
throw new Error(`Annotation with ID "${annotationId}" not found.`)
|
|
}
|