Compare commits

...
Author SHA1 Message Date
R44VC0RP 37ef7dd136 fix(core): expose inline media source paths 2026-09-02 15:54:41 +00:00
2 changed files with 28 additions and 1 deletions
@@ -2,6 +2,7 @@ import { Message, ToolCallPart, ToolResultPart, type ContentPart, type ProviderM
import type { Model } from "@opencode-ai/schema/model"
import { Option, Schema } from "effect"
import { fileURLToPath } from "url"
import path from "path"
import { SessionMessage } from "../message.js"
import type { FileAttachment } from "@opencode-ai/schema/prompt"
@@ -16,7 +17,10 @@ const media = (file: FileAttachment): ContentPart => ({
})
const attachmentLocation = (file: FileAttachment) => {
if (file.source.type !== "uri") return undefined
if (file.source.type === "inline") {
if (!file.name) return undefined
return path.posix.isAbsolute(file.name) || path.win32.isAbsolute(file.name) ? file.name : undefined
}
const url = URL.parse(file.source.uri)
if (url?.protocol !== "file:") return undefined
try {
@@ -491,6 +491,29 @@ Recent work
])
})
test("exposes desktop media source paths retained on inline attachments", () => {
const data = Base64.make("AAECAw==")
const location = "/Users/vogel/Downloads/preview.gif"
const messages = toLLMMessages(
[
SessionMessage.User.make({
id: id("user-inline-image-path"),
type: "user",
text: "Add this GIF to the page",
files: [FileAttachment.make({ data, mime: "image/gif", source: { type: "inline" }, name: location })],
time: { created },
}),
],
model,
)
expect(messages[0]?.content).toEqual([
{ type: "text", text: "Add this GIF to the page" },
{ type: "text", text: `Attached file: ${location}` },
{ type: "media", mediaType: "image/gif", data, filename: location },
])
})
test("falls back to attachment names for invalid local source paths", () => {
const data = Base64.make("AAECAw==")
const messages = toLLMMessages(