import test from 'node:test'; import assert from 'node:assert/strict'; import { buildAttachmentPayload, extractFileAttachmentsFromMessage, } from './tkmind-proxy.mjs'; test('extractFileAttachmentsFromMessage reads metadata.fileAttachments', () => { const attachments = extractFileAttachmentsFromMessage({ metadata: { fileAttachments: [ { assetId: 'asset-1', filename: 'report.xlsx', downloadUrl: '/api/mindspace/v1/assets/asset-1/download', mimeType: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', }, ], }, content: [], }); assert.equal(attachments.length, 1); assert.equal(attachments[0].filename, 'report.xlsx'); }); test('buildAttachmentPayload injects extracted attachment text for agent execution', async () => { const xlsxBuffer = Buffer.from('PK\x03\x04'); const payload = await buildAttachmentPayload({ userId: 'user-1', userMessage: { metadata: { displayText: '请分析这份表格', fileAttachments: [ { assetId: 'asset-9', filename: 'note.txt', downloadUrl: '/api/mindspace/v1/assets/asset-9/download', mimeType: 'text/plain', }, ], }, content: [{ type: 'text', text: '请分析这份表格\n\n[文件1: note.txt]: /api/mindspace/v1/assets/asset-9/download' }], }, localFetchAsset: async () => ({ buffer: Buffer.from('hello attachment'), mimeType: 'text/plain', }), }); assert.ok(payload?.userMessage); const text = payload.userMessage.content[0].text; assert.match(text, /【TKMind 附件分析结果/); assert.match(text, /hello attachment/); assert.match(text, /oa\/note\.txt/); assert.equal(payload.userMessage.metadata.displayText, '请分析这份表格'); });