diff --git a/packages/ui/src/components/prompt-input.tsx b/packages/ui/src/components/prompt-input.tsx index bffd3404..4ed7d407 100644 --- a/packages/ui/src/components/prompt-input.tsx +++ b/packages/ui/src/components/prompt-input.tsx @@ -720,8 +720,24 @@ export default function PromptInput(props: PromptInputProps) { const filename = file.name const mime = file.type || "text/plain" - const attachment = createFileAttachment(path, filename, mime, undefined, props.instanceFolder) - addAttachment(props.instanceId, props.sessionId, attachment) + const createAndStoreAttachment = (previewUrl?: string) => { + const attachment = createFileAttachment(path, filename, mime, undefined, props.instanceFolder) + if (previewUrl && mime.startsWith("image/")) { + attachment.url = previewUrl + } + addAttachment(props.instanceId, props.sessionId, attachment) + } + + if (mime.startsWith("image/") && typeof FileReader !== "undefined") { + const reader = new FileReader() + reader.onload = () => { + const result = typeof reader.result === "string" ? reader.result : undefined + createAndStoreAttachment(result) + } + reader.readAsDataURL(file) + } else { + createAndStoreAttachment() + } } textareaRef?.focus() @@ -772,7 +788,7 @@ export default function PromptInput(props: PromptInputProps) { {(attachment) => { const isImage = attachment.mediaType.startsWith("image/") return ( -