fix: preserve paired input evidence context (#204)
This commit is contained in:
@@ -2,6 +2,7 @@ import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
import {
|
||||
expandImagePromptReferences,
|
||||
extractImageTagPaths,
|
||||
imageTagCaption,
|
||||
missingImageTagCaption,
|
||||
@@ -79,7 +80,8 @@ export function buildMultimodalContent(
|
||||
text: string,
|
||||
log: LogFn,
|
||||
): StreamContent {
|
||||
const { imagePaths } = extractImageTagPaths(text);
|
||||
const expandedText = expandImagePromptReferences(text);
|
||||
const { imagePaths } = extractImageTagPaths(expandedText);
|
||||
if (imagePaths.length === 0) return text;
|
||||
|
||||
const blocks: ContentBlock[] = [];
|
||||
@@ -88,7 +90,7 @@ export function buildMultimodalContent(
|
||||
if (trimmed) blocks.push({ type: 'text', text: trimmed });
|
||||
};
|
||||
|
||||
for (const part of splitImageTagPromptParts(text)) {
|
||||
for (const part of splitImageTagPromptParts(expandedText)) {
|
||||
if (part.type === 'text') {
|
||||
pushText(part.text);
|
||||
continue;
|
||||
|
||||
@@ -94,4 +94,57 @@ describe('agent-runner multimodal prompts', () => {
|
||||
]);
|
||||
expect(logs).toContain(`Unsupported image type, skipping: ${imagePath}`);
|
||||
});
|
||||
|
||||
it('loads MEDIA image directives as Claude image blocks', () => {
|
||||
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'ejclaw-media-image-'));
|
||||
cleanupDirs.push(dir);
|
||||
const imagePath = path.join(dir, 'media-render.png');
|
||||
fs.writeFileSync(imagePath, ONE_PIXEL_PNG);
|
||||
|
||||
const content = buildMultimodalContent(`증거\nMEDIA:${imagePath}`, () => {
|
||||
// no-op
|
||||
});
|
||||
|
||||
expect(content).toEqual([
|
||||
{ type: 'text', text: '증거' },
|
||||
{ type: 'text', text: 'Image evidence: media-render.png' },
|
||||
{
|
||||
type: 'image',
|
||||
source: {
|
||||
type: 'base64',
|
||||
media_type: 'image/png',
|
||||
data: ONE_PIXEL_PNG.toString('base64'),
|
||||
},
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it('loads markdown image links as Claude image blocks', () => {
|
||||
const dir = fs.mkdtempSync(
|
||||
path.join(os.tmpdir(), 'ejclaw-markdown-image-'),
|
||||
);
|
||||
cleanupDirs.push(dir);
|
||||
const imagePath = path.join(dir, 'markdown-render.png');
|
||||
fs.writeFileSync(imagePath, ONE_PIXEL_PNG);
|
||||
|
||||
const content = buildMultimodalContent(
|
||||
`증거 `,
|
||||
() => {
|
||||
// no-op
|
||||
},
|
||||
);
|
||||
|
||||
expect(content).toEqual([
|
||||
{ type: 'text', text: '증거' },
|
||||
{ type: 'text', text: 'Image evidence: markdown-render.png' },
|
||||
{
|
||||
type: 'image',
|
||||
source: {
|
||||
type: 'base64',
|
||||
media_type: 'image/png',
|
||||
data: ONE_PIXEL_PNG.toString('base64'),
|
||||
},
|
||||
},
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user