fix(core): forward PDF prompt attachments (#43799)

This commit is contained in:
Aiden Cline 2026-08-21 01:16:05 -05:00 committed by GitHub
parent d158f2cd39
commit b0ab1e2992
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 7 additions and 4 deletions

View file

@ -67,7 +67,7 @@ const directoryAttachment = (file: FileAttachment): ContentPart => ({
const attachmentContent = (file: FileAttachment): ContentPart[] => {
if (file.mime === "text/plain") return [textAttachment(file)]
if (file.mime === "application/x-directory") return [directoryAttachment(file)]
if (imageMimes.has(file.mime)) {
if (imageMimes.has(file.mime) || file.mime === "application/pdf") {
const location = attachmentLocation(file)
return [...(location === undefined ? [] : [Message.text(`Attached file: ${location}`)]), media(file)]
}

View file

@ -9,16 +9,18 @@ describe("SessionModelRequest.unsupportedParts", () => {
const messages = unsupportedParts(
[
Message.user([
Message.text("Describe this image"),
Message.text("Describe these files"),
{ type: "media", mediaType: "image/png", data: "aGVsbG8=", filename: "logo.png" },
{ type: "media", mediaType: "application/pdf", data: "JVBERg==", filename: "document.pdf" },
]),
],
capabilities(["text"]),
)
expect(messages[0]?.content).toEqual([
Message.text("Describe this image"),
Message.text("Describe these files"),
Message.text('ERROR: Cannot read "logo.png" (this model does not support image input). Inform the user.'),
Message.text('ERROR: Cannot read "document.pdf" (this model does not support pdf input). Inform the user.'),
])
})

View file

@ -361,7 +361,7 @@ Recent work
])
})
test("uses materialized image data as provider media and drops unsupported attachments", () => {
test("uses materialized image and PDF data as provider media", () => {
const data = Base64.make("AAECAw==")
const messages = toLLMMessages(
[
@ -387,6 +387,7 @@ Recent work
expect(messages[0]?.content).toEqual([
{ type: "text", text: "Inspect this image" },
{ type: "media", mediaType: "image/png", data, filename: "image.png" },
{ type: "media", mediaType: "application/pdf", data: "JVBERg==", filename: "document.pdf" },
])
})