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,
|
||||
@@ -22,7 +23,8 @@ export function parseAppServerInput(
|
||||
text: string,
|
||||
log: (message: string) => void = () => undefined,
|
||||
): AppServerInputItem[] {
|
||||
const { imagePaths } = extractImageTagPaths(text);
|
||||
const expandedText = expandImagePromptReferences(text);
|
||||
const { imagePaths } = extractImageTagPaths(expandedText);
|
||||
const input: AppServerInputItem[] = [];
|
||||
const pushText = (value: string) => {
|
||||
const trimmed = value.trim();
|
||||
@@ -30,7 +32,7 @@ export function parseAppServerInput(
|
||||
};
|
||||
|
||||
if (imagePaths.length > 0) {
|
||||
for (const part of splitImageTagPromptParts(text)) {
|
||||
for (const part of splitImageTagPromptParts(expandedText)) {
|
||||
if (part.type === 'text') {
|
||||
pushText(part.text);
|
||||
continue;
|
||||
|
||||
@@ -86,4 +86,36 @@ describe('codex app-server input', () => {
|
||||
]);
|
||||
expect(logs).toContain(`Unsupported image type, skipping: ${imagePath}`);
|
||||
});
|
||||
|
||||
it('loads MEDIA image directives as local image input items', () => {
|
||||
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'ejclaw-codex-media-'));
|
||||
cleanupDirs.push(dir);
|
||||
const imagePath = path.join(dir, 'media-render.png');
|
||||
fs.writeFileSync(imagePath, ONE_PIXEL_PNG);
|
||||
|
||||
const input = parseAppServerInput(`증거\nMEDIA:${imagePath}`);
|
||||
|
||||
expect(input).toEqual([
|
||||
{ type: 'text', text: '증거' },
|
||||
{ type: 'text', text: 'Image evidence: media-render.png' },
|
||||
{ type: 'localImage', path: imagePath },
|
||||
]);
|
||||
});
|
||||
|
||||
it('loads markdown image links as local image input items', () => {
|
||||
const dir = fs.mkdtempSync(
|
||||
path.join(os.tmpdir(), 'ejclaw-codex-markdown-'),
|
||||
);
|
||||
cleanupDirs.push(dir);
|
||||
const imagePath = path.join(dir, 'markdown-render.png');
|
||||
fs.writeFileSync(imagePath, ONE_PIXEL_PNG);
|
||||
|
||||
const input = parseAppServerInput(`증거 `);
|
||||
|
||||
expect(input).toEqual([
|
||||
{ type: 'text', text: '증거' },
|
||||
{ type: 'text', text: 'Image evidence: markdown-render.png' },
|
||||
{ type: 'localImage', path: imagePath },
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user