mirror of
https://github.com/Heretek-AI/opencode.git
synced 2026-11-23 07:59:33 -10:00
fix(core): expose inline media source paths
This commit is contained in:
1 parent
3f437faba7
commit
bc2df982d1
2 files changed
+28
-1
No files matched your search
@@ -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(
|
||||
|
||||
Reference in new issue
Block a user