Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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<FilePart, "id" | "messageID" | "sessionID"> = {
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,
Expand Down
Loading