mirror of
https://github.com/anomalyco/opencode.git
synced 2026-08-21 23:53:26 +00:00
fix(core): forward PDF prompt attachments (#43799)
This commit is contained in:
parent
d158f2cd39
commit
b0ab1e2992
3 changed files with 7 additions and 4 deletions
|
|
@ -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)]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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.'),
|
||||
])
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -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" },
|
||||
])
|
||||
})
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue