@@ -2,7 +2,9 @@ import { BoxRenderable, TextareaRenderable, MouseEvent, PasteEvent, decodePasteB
22import { createEffect , createMemo , onMount , createSignal , onCleanup , on , Show , Switch , Match } from "solid-js"
33import "opentui-spinner/solid"
44import path from "path"
5- import { fileURLToPath } from "url"
5+ import { fileURLToPath , pathToFileURL } from "url"
6+ import fs from "fs/promises"
7+ import { tmpdir } from "os"
68import { Filesystem } from "@/util/filesystem"
79import { useLocal } from "@tui/context/local"
810import { useTheme } from "@tui/context/theme"
@@ -789,14 +791,28 @@ export function Prompt(props: PromptProps) {
789791 typeId : promptPartTypeId ,
790792 } )
791793
794+ let url = `data:${ file . mime } ;base64,${ file . content } `
795+ let filepath = file . filepath
796+
797+ if ( ! filepath && file . mime . startsWith ( "image/" ) ) {
798+ const ext = file . mime . split ( "/" ) [ 1 ] ?? "png"
799+ filepath = path . join ( tmpdir ( ) , `opencode-paste-${ Date . now ( ) } .${ ext } ` )
800+ try {
801+ await fs . writeFile ( filepath , Buffer . from ( file . content , "base64" ) )
802+ url = pathToFileURL ( filepath ) . href
803+ } catch ( err ) {
804+ console . error ( "Failed to save pasted image:" , err )
805+ }
806+ }
807+
792808 const part : Omit < FilePart , "id" | "messageID" | "sessionID" > = {
793809 type : "file" as const ,
794810 mime : file . mime ,
795811 filename : file . filename ,
796- url : `data: ${ file . mime } ;base64, ${ file . content } ` ,
812+ url,
797813 source : {
798814 type : "file" ,
799- path : file . filepath ?? file . filename ?? "" ,
815+ path : filepath ?? file . filename ?? "" ,
800816 text : {
801817 start : extmarkStart ,
802818 end : extmarkEnd ,
0 commit comments