From 8c00d96024e416bfce7fc45b8e47db674ab41bc8 Mon Sep 17 00:00:00 2001 From: Rohit Malhotra Date: Mon, 11 Nov 2024 13:22:17 -0500 Subject: [PATCH] Support displaying images/videos/pdfs in the workspace (#4898) --- .../_oh.app._index/code-editor-component.tsx | 38 ++++++++++++++++--- openhands/runtime/action_execution_server.py | 29 ++++++++++++++ 2 files changed, 62 insertions(+), 5 deletions(-) diff --git a/frontend/src/routes/_oh.app._index/code-editor-component.tsx b/frontend/src/routes/_oh.app._index/code-editor-component.tsx index 8182805193a0..4cc26ad213a2 100644 --- a/frontend/src/routes/_oh.app._index/code-editor-component.tsx +++ b/frontend/src/routes/_oh.app._index/code-editor-component.tsx @@ -29,6 +29,10 @@ function CodeEditorCompoonent({ if (selectedPath && value) modifyFileContent(selectedPath, value); }; + const isBase64Image = (content: string) => content.startsWith("data:image/"); + const isPDF = (content: string) => content.startsWith("data:application/pdf"); + const isVideo = (content: string) => content.startsWith("data:video/"); + React.useEffect(() => { const handleSave = async (event: KeyboardEvent) => { if (selectedPath && event.metaKey && event.key === "s") { @@ -62,16 +66,40 @@ function CodeEditorCompoonent({ ); } + const fileContent = modifiedFiles[selectedPath] || files[selectedPath]; + + if (isBase64Image(fileContent)) { + return ( +
+ {selectedPath} +
+ ); + } + + if (isPDF(fileContent)) { + return ( +