feat: add MEDIA outbound attachment directive

This commit is contained in:
ejclaw
2026-05-26 17:26:20 +09:00
parent 89b3dd382e
commit df6ec5f2b2
11 changed files with 373 additions and 29 deletions

View File

@@ -2,6 +2,7 @@ import { describe, expect, it } from 'vitest';
import {
extractMarkdownImageAttachments,
extractMediaAttachments,
normalizeAgentOutput,
} from '../src/agent-protocol.js';
@@ -43,6 +44,69 @@ describe('normalizeAgentOutput', () => {
});
});
it('normalizes MEDIA directives into internal attachments', () => {
expect(
normalizeAgentOutput(
'TASK_DONE\n\n사운드 프리뷰입니다.\nMEDIA:/tmp/adventurer-active-sfx-preview.mp4',
),
).toEqual({
result: 'TASK_DONE\n\n사운드 프리뷰입니다.',
output: {
visibility: 'public',
text: 'TASK_DONE\n\n사운드 프리뷰입니다.',
attachments: [
{
path: '/tmp/adventurer-active-sfx-preview.mp4',
name: 'adventurer-active-sfx-preview.mp4',
mime: 'video/mp4',
},
],
},
attachmentSource: 'media-tag',
});
});
it('extracts quoted MEDIA paths with spaces', () => {
expect(
extractMediaAttachments(
'프리뷰\nMEDIA:"/tmp/Maldhalla Demo/preview.mp4"',
),
).toEqual({
cleanText: '프리뷰',
attachments: [
{
path: '/tmp/Maldhalla Demo/preview.mp4',
name: 'preview.mp4',
mime: 'video/mp4',
},
],
});
});
it('does not treat MEDIA references in code fences as attachments', () => {
const content = '```text\nMEDIA:/tmp/not-an-attachment.mp4\n```';
expect(extractMediaAttachments(content)).toEqual({
cleanText: content,
attachments: [],
});
});
it('does not treat inbound attachment placeholders as outbound directives', () => {
expect(
normalizeAgentOutput(
'TASK_DONE\n\n[Video: preview.mp4 → /tmp/preview.mp4]\n확인했습니다.',
),
).toEqual({
result:
'TASK_DONE\n\n[Video: preview.mp4 → /tmp/preview.mp4]\n확인했습니다.',
output: {
visibility: 'public',
text: 'TASK_DONE\n\n[Video: preview.mp4 → /tmp/preview.mp4]\n확인했습니다.',
},
attachmentSource: 'none',
});
});
it('normalizes legacy image tags into internal attachments', () => {
expect(
normalizeAgentOutput(