diff --git a/packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx b/packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx index 747c61fd0bf9..982735a53fee 100644 --- a/packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx +++ b/packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx @@ -2,7 +2,8 @@ import { BoxRenderable, TextareaRenderable, MouseEvent, PasteEvent, decodePasteB import { createEffect, createMemo, onMount, createSignal, onCleanup, on, Show, Switch, Match } from "solid-js" import "opentui-spinner/solid" import path from "path" -import { fileURLToPath } from "url" +import { fileURLToPath, pathToFileURL } from "url" +import { tmpdir } from "os" import { Filesystem } from "@/util/filesystem" import { useLocal } from "@tui/context/local" import { useTheme } from "@tui/context/theme" @@ -789,14 +790,28 @@ export function Prompt(props: PromptProps) { typeId: promptPartTypeId, }) + let url = `data:${file.mime};base64,${file.content}` + let filepath = file.filepath + + if (!filepath && file.mime.startsWith("image/")) { + const ext = file.mime.split("/")[1] ?? "png" + filepath = path.join(tmpdir(), `opencode-paste-${Date.now()}.${ext}`) + try { + await Bun.write(filepath, Buffer.from(file.content, "base64")) + url = pathToFileURL(filepath).href + } catch { + // fall back to data URL + } + } + const part: Omit = { type: "file" as const, mime: file.mime, filename: file.filename, - url: `data:${file.mime};base64,${file.content}`, + url, source: { type: "file", - path: file.filepath ?? file.filename ?? "", + path: filepath ?? file.filename ?? "", text: { start: extmarkStart, end: extmarkEnd,