From bc2df982d1e6dd5e339e4cd80d85713e5259eb55 Mon Sep 17 00:00:00 2001 From: R44VC0RP Date: Wed, 2 Sep 2026 15:49:30 +0000 Subject: [PATCH] fix(core): expose inline media source paths --- .../core/src/session/runner/to-llm-message.ts | 6 ++++- .../core/test/session-runner-message.test.ts | 23 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/packages/core/src/session/runner/to-llm-message.ts b/packages/core/src/session/runner/to-llm-message.ts index 8b5d767f7f..9cc4a99ce7 100644 --- a/packages/core/src/session/runner/to-llm-message.ts +++ b/packages/core/src/session/runner/to-llm-message.ts @@ -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 { diff --git a/packages/core/test/session-runner-message.test.ts b/packages/core/test/session-runner-message.test.ts index 5f37a4d19a..4e4fb78742 100644 --- a/packages/core/test/session-runner-message.test.ts +++ b/packages/core/test/session-runner-message.test.ts @@ -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(