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

@@ -1,3 +1,5 @@
import { isModelDocumentPath } from 'ejclaw-runners-shared';
import { buildArbiterContextPrompt } from './arbiter-context.js';
import { TASK_USER_CONTEXT_START_SKEW_MS } from './message-runtime-task-context.js';
import { formatMessages } from './router.js';
@@ -21,6 +23,12 @@ function isImageAttachment(attachment: OutboundAttachment): boolean {
return /\.(?:png|jpe?g|gif|webp|bmp)$/i.test(attachment.path);
}
function isDocumentAttachment(attachment: OutboundAttachment): boolean {
const mime = attachment.mime?.toLowerCase();
if (mime === 'application/pdf' || mime?.startsWith('text/')) return true;
return isModelDocumentPath(attachment.path);
}
function attachmentLabel(attachment: OutboundAttachment): string {
return attachment.name?.trim() || attachment.path.split('/').at(-1) || 'file';
}
@@ -39,11 +47,15 @@ function formatTurnOutputAttachmentContext(
if (!attachments?.length) return '';
const lines = attachments.map((attachment) => {
const label = attachmentLabel(attachment);
return isImageAttachment(attachment)
? `[Image: ${label}${attachment.path}]`
: `[Attachment unavailable: ${label}${attachment.path}${nonImageAttachmentReason(
attachment,
)}]`;
if (isImageAttachment(attachment)) {
return `[Image: ${label}${attachment.path}]`;
}
if (isDocumentAttachment(attachment)) {
return `[File: ${label}${attachment.path}]`;
}
return `[Attachment unavailable: ${label}${attachment.path}${nonImageAttachmentReason(
attachment,
)}]`;
});
return `\n\nAttached evidence from this turn:\n${lines.join('\n')}`;
}