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 (
+
+
+
+ );
+ }
+
+ if (isPDF(fileContent)) {
+ return (
+
+ );
+ }
+
+ if (isVideo(fileContent)) {
+ return (
+
+ );
+ }
return (
Observation:
working_dir = self.bash_session.workdir
filepath = self._resolve_path(action.path, working_dir)
try:
+ if filepath.lower().endswith(('.png', '.jpg', '.jpeg', '.bmp', '.gif')):
+ with open(filepath, 'rb') as file:
+ image_data = file.read()
+ encoded_image = base64.b64encode(image_data).decode('utf-8')
+ mime_type, _ = mimetypes.guess_type(filepath)
+ if mime_type is None:
+ mime_type = 'image/png' # default to PNG if mime type cannot be determined
+ encoded_image = f'data:{mime_type};base64,{encoded_image}'
+
+ return FileReadObservation(path=filepath, content=encoded_image)
+ elif filepath.lower().endswith('.pdf'):
+ with open(filepath, 'rb') as file:
+ pdf_data = file.read()
+ encoded_pdf = base64.b64encode(pdf_data).decode('utf-8')
+ encoded_pdf = f'data:application/pdf;base64,{encoded_pdf}'
+ return FileReadObservation(path=filepath, content=encoded_pdf)
+ elif filepath.lower().endswith(('.mp4', '.webm', '.ogg')):
+ with open(filepath, 'rb') as file:
+ video_data = file.read()
+ encoded_video = base64.b64encode(video_data).decode('utf-8')
+ mime_type, _ = mimetypes.guess_type(filepath)
+ if mime_type is None:
+ mime_type = 'video/mp4' # default to MP4 if MIME type cannot be determined
+ encoded_video = f'data:{mime_type};base64,{encoded_video}'
+
+ return FileReadObservation(path=filepath, content=encoded_video)
+
with open(filepath, 'r', encoding='utf-8') as file:
lines = read_lines(file.readlines(), action.start, action.end)
except FileNotFoundError: