fix: load supported document attachments (#205)

This commit is contained in:
Eyejoker
2026-05-31 22:30:49 +09:00
committed by GitHub
parent 778ed9b94a
commit b6e7e060cc
11 changed files with 398 additions and 30 deletions

View File

@@ -10,6 +10,7 @@ const ONE_PIXEL_PNG = Buffer.from(
'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+/p9sAAAAASUVORK5CYII=',
'base64',
);
const MINIMAL_PDF = Buffer.from('%PDF-1.4\n1 0 obj\n<<>>\nendobj\n%%EOF\n');
const cleanupDirs: string[] = [];
@@ -147,4 +148,62 @@ describe('agent-runner multimodal prompts', () => {
},
]);
});
it('loads PDF file tags as Claude document blocks', () => {
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'ejclaw-pdf-doc-'));
cleanupDirs.push(dir);
const pdfPath = path.join(dir, 'report.pdf');
fs.writeFileSync(pdfPath, MINIMAL_PDF);
const logs: string[] = [];
const content = buildMultimodalContent(
`검토 자료\n[File: report.pdf → ${pdfPath}]`,
(message) => logs.push(message),
);
expect(content).toEqual([
{ type: 'text', text: '검토 자료' },
{ type: 'text', text: 'Document evidence: report.pdf' },
{
type: 'document',
title: 'report.pdf',
source: {
type: 'base64',
media_type: 'application/pdf',
data: MINIMAL_PDF.toString('base64'),
},
},
]);
expect(logs).toContain(
`Added document block: ${pdfPath} (application/pdf)`,
);
});
it('loads text file tags as Claude text document blocks', () => {
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'ejclaw-text-doc-'));
cleanupDirs.push(dir);
const textPath = path.join(dir, 'notes.md');
fs.writeFileSync(textPath, '# Notes\nEvidence text');
const content = buildMultimodalContent(
`검토 자료\nMEDIA:${textPath}`,
() => {
// no-op
},
);
expect(content).toEqual([
{ type: 'text', text: '검토 자료' },
{ type: 'text', text: 'Document evidence: notes.md' },
{
type: 'document',
title: 'notes.md',
source: {
type: 'text',
media_type: 'text/plain',
data: '# Notes\nEvidence text',
},
},
]);
});
});