feat(chat): support markups, attachments, and timestamps in agent 1-to-1 chat (#368)

* feat(chat): support markups, attachments, and timestamps in agent 1-to-1 chat

* feat(chat): improve message card layout with inline badges and integrated assets

* fix(chat): enable image attachment thumbnails in 1-to-1 chat cards

* fix(chat): address code review feedback on input state, mentions, i18n, and session deletion

* fix(chat): replace ring with border color on selected message card
This commit is contained in:
Yiling-J
2026-08-31 20:11:27 +08:00
committed by GitHub
parent 6e9cf8dfb6
commit e06478df88
36 changed files with 1908 additions and 353 deletions
+57 -5
View File
@@ -811,7 +811,12 @@ export async function initializeAgentSessionActivity(params: {
const commentDetails: ShumaiMessageContext = {
...(userObj ? { user: userObj } : {}),
...(position ? { position } : {}),
...(annotation ? { annotation: true } : {}),
...(annotation
? {
annotation: true,
annotations: c.annotation as unknown as ShumaiMessageContext['annotations'],
}
: {}),
...(attachedFiles.length > 0 ? { attachedFiles } : {}),
}
@@ -1190,6 +1195,7 @@ export async function getAssetActivity(assetId: string) {
},
})
let resolvedAsset = asset
if (asset && asset.type === AssetType.version_stack) {
const latestVersion = await prisma.asset.findFirst({
where: { parentId: asset.id, isDeleted: false },
@@ -1205,18 +1211,36 @@ export async function getAssetActivity(assetId: string) {
})
if (latestVersion) {
return {
resolvedAsset = {
...latestVersion,
project: latestVersion.project ?? asset.project,
}
} as typeof asset
}
}
return asset
if (!resolvedAsset) return null
let url: string | undefined
if (resolvedAsset.storageKey?.key) {
try {
url = await s3Service.presign(
process.env.S3_BUCKET || 'shumai',
resolvedAsset.storageKey.key,
'GET',
)
} catch {
// Ignore presign errors
}
}
return {
...resolvedAsset,
url,
}
}
export async function getCommentActivity(commentId: string) {
return prisma.assetComment.findUnique({
const comment = await prisma.assetComment.findUnique({
where: { id: commentId },
include: {
attachments: {
@@ -1224,6 +1248,34 @@ export async function getCommentActivity(commentId: string) {
},
},
})
if (!comment) return null
const attachmentsWithUrl = await Promise.all(
comment.attachments.map(async (att) => {
let url: string | undefined
if (att.asset?.storageKey?.key) {
try {
url = await s3Service.presign(
process.env.S3_BUCKET || 'shumai',
att.asset.storageKey.key,
'GET',
)
} catch {
// Ignore
}
}
return {
...att,
asset: att.asset ? { ...att.asset, url } : null,
}
}),
)
return {
...comment,
attachments: attachmentsWithUrl,
}
}
export async function getProjectAutofillFieldsActivity(projectId: string) {
@@ -735,4 +735,35 @@ describe('Agent Chat Workflow', () => {
}),
)
})
it('should include annotations and second in direct chat messageContext', async () => {
const task = await prisma.workflowTask.create({
data: {
type: 'chat',
status: 'pending',
assetId: 'a1',
payload: {
projectId: 'p1',
agent: {
prompt: 'Look at the highlighted zone',
agentId: 'b1',
sessionId: 'session-markup-1',
second: 14.2,
annotations: [{ type: 'rectangle', x: 20, y: 30, width: 40, height: 50 }],
},
},
},
})
await agentChat(task)
expect(mockActivities.agentChatActivity).toHaveBeenCalledWith(
expect.objectContaining({
messageContext: expect.objectContaining({
position: { type: 'time', seconds: 14.2 },
annotations: [{ type: 'rectangle', x: 20, y: 30, width: 40, height: 50 }],
}),
}),
)
})
})
+23 -1
View File
@@ -61,6 +61,8 @@ export async function agentChat(task: WorkflowTask): Promise<void> {
let commentAnnotation = false
let commentCreatorId: string | undefined
let commentAnnotations: unknown[] | undefined
if (userCommentId) {
userComment = await executeActivity(agentWorkerQueue, getCommentActivity, userCommentId)
if (!userComment) {
@@ -77,6 +79,7 @@ export async function agentChat(task: WorkflowTask): Promise<void> {
userComment.annotation.length > 0
) {
commentAnnotation = true
commentAnnotations = userComment.annotation
}
// 2. Create Placeholder Comment
@@ -101,6 +104,17 @@ export async function agentChat(task: WorkflowTask): Promise<void> {
} else {
prompt = payload.agent?.prompt || ''
attachmentImageUrls = payload.agent?.imageUrls || []
if (payload.agent?.second !== null && payload.agent?.second !== undefined) {
commentTimestamp = payload.agent.second
}
if (
payload.agent?.annotations &&
Array.isArray(payload.agent.annotations) &&
payload.agent.annotations.length > 0
) {
commentAnnotation = true
commentAnnotations = payload.agent.annotations
}
}
// 3. Get Asset
@@ -181,6 +195,7 @@ export async function agentChat(task: WorkflowTask): Promise<void> {
mediaType: attProxyType as ShumaiAttachedFileContext['mediaType'],
mimeType: att.asset.mediaType || undefined,
path: filePath || undefined,
url: (att.asset as { url?: string }).url || undefined,
})
attachedAssets.push({ id: att.asset.id, name: att.asset.name, type: att.asset.type })
}
@@ -205,6 +220,7 @@ export async function agentChat(task: WorkflowTask): Promise<void> {
mediaType: fileProxyType as ShumaiAttachedFileContext['mediaType'],
mimeType: file.mediaType || undefined,
path: filePath || undefined,
url: (file as { url?: string }).url || undefined,
})
attachedAssets.push({ id: file.id, name: file.name, type: file.type })
}
@@ -233,6 +249,7 @@ export async function agentChat(task: WorkflowTask): Promise<void> {
mediaType: refProxyType as ShumaiAttachedFileContext['mediaType'],
mimeType: referencedAsset.mediaType || undefined,
path: filePath || undefined,
url: (referencedAsset as { url?: string }).url || undefined,
})
attachedAssets.push({
id: referencedAsset.id,
@@ -286,7 +303,12 @@ export async function agentChat(task: WorkflowTask): Promise<void> {
: {}),
currentAsset: currentAssetContext,
...(mediaPosition ? { position: mediaPosition } : {}),
...(commentAnnotation ? { annotation: true } : {}),
...(commentAnnotation
? {
annotation: true,
annotations: commentAnnotations as ShumaiMessageContext['annotations'],
}
: {}),
...(attachedFiles.length > 0 ? { attachedFiles } : {}),
...(referencedAssets.length > 0 ? { referencedAssets } : {}),
}