fix: make paired evidence loss visible (#202)

This commit is contained in:
Eyejoker
2026-05-31 16:20:09 +09:00
committed by GitHub
parent 6eca648c47
commit 239c7ff1e6
19 changed files with 644 additions and 67 deletions

View File

@@ -1,27 +1,64 @@
import fs from 'fs';
import path from 'path';
import { extractImageTagPaths } from 'ejclaw-runners-shared';
import {
extractImageTagPaths,
imageTagCaption,
missingImageTagCaption,
splitImageTagPromptParts,
} from 'ejclaw-runners-shared';
import type { AppServerInputItem } from './app-server-client.js';
const SUPPORTED_LOCAL_IMAGE_EXTENSIONS = new Set([
'.jpg',
'.jpeg',
'.png',
'.gif',
'.webp',
]);
export function parseAppServerInput(
text: string,
log: (message: string) => void = () => undefined,
): AppServerInputItem[] {
const { cleanText, imagePaths } = extractImageTagPaths(text);
const { imagePaths } = extractImageTagPaths(text);
const input: AppServerInputItem[] = [];
const pushText = (value: string) => {
const trimmed = value.trim();
if (trimmed) input.push({ type: 'text', text: trimmed });
};
if (cleanText) {
input.push({ type: 'text', text: cleanText });
}
if (imagePaths.length > 0) {
for (const part of splitImageTagPromptParts(text)) {
if (part.type === 'text') {
pushText(part.text);
continue;
}
if (!fs.existsSync(part.path)) {
log(`Image not found, skipping: ${part.path}`);
pushText(missingImageTagCaption(part, 'file not found'));
continue;
}
for (const imgPath of imagePaths) {
if (fs.existsSync(imgPath)) {
input.push({ type: 'localImage', path: imgPath });
log(`Adding image input: ${imgPath}`);
} else {
log(`Image not found, skipping: ${imgPath}`);
const ext = path.extname(part.path).toLowerCase();
if (!SUPPORTED_LOCAL_IMAGE_EXTENSIONS.has(ext)) {
log(`Unsupported image type, skipping: ${part.path}`);
pushText(
missingImageTagCaption(
part,
`unsupported image type ${ext || 'unknown'}`,
),
);
continue;
}
pushText(imageTagCaption(part));
input.push({ type: 'localImage', path: part.path });
log(`Adding image input: ${part.path}`);
}
} else if (text) {
input.push({ type: 'text', text });
}
if (input.length === 0) {