Skip to content

Commit 2e2c824

Browse files
committed
fix(media): forward scanned PDF page images as inline data URIs on chat channels
When extractFileBlocks receives a scanned/image-only PDF (no extractable text but page images present), it previously set a dead-end placeholder and dropped the images. The /v1/responses API path already forwarded the same images correctly. Fix: embed the extracted page images as base64 data URIs in the file context block, so vision-capable models can read scanned documents on all chat channels. Closes #96541
1 parent f65aca6 commit 2e2c824

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

src/media-understanding/apply.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,18 @@ async function extractFileBlocks(params: {
497497
let blockText = text ? wrapUntrustedAttachmentContent(text) : "";
498498
if (!blockText) {
499499
if (extracted?.images && extracted.images.length > 0) {
500-
blockText = "[PDF content rendered to images; images not forwarded to model]";
500+
// Forward extracted PDF page images as inline base64 data URIs so
501+
// vision-capable models can read scanned documents. Mirrors the
502+
// /v1/responses path behavior (openresponses-http.ts:629-630) where
503+
// the same extractor output is forwarded as separate image content.
504+
//
505+
// Base64 data URIs are used because the chat path has no image-carrying
506+
// field on ApplyMediaUnderstandingResult; embedding them in the text block
507+
// ensures they reach the model without structural type changes.
508+
const imageContext = extracted.images
509+
.map((img, i) => `![Page ${i + 1}](data:${img.mimeType ?? "image/png"};base64,${img.base64})`)
510+
.join("\n\n");
511+
blockText = `[PDF content rendered to images]\n\n${imageContext}`;
501512
} else {
502513
blockText = "[No extractable text]";
503514
}

0 commit comments

Comments
 (0)