Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(artifacts): read text file content for file-kind artifacts, render in panel

Sanilada2a4aa8a03
diff --git a/app/src/features/conversations/aui/ArtifactPreviewPanel.tsx b/app/src/features/conversations/aui/ArtifactPreviewPanel.tsx
index 5ae3fe6654..67c9bea0bc 100644
--- a/app/src/features/conversations/aui/ArtifactPreviewPanel.tsx
+++ b/app/src/features/conversations/aui/ArtifactPreviewPanel.tsx
@@ -38,6 +38,7 @@ interface ArtifactBodyResponse {
title: string;
version: number;
body: string;
+ is_text: boolean;
}
// ─── Constants ──────────────────────────────────────────────────
@@ -167,6 +168,12 @@ export function ArtifactPreviewPanel({ artifactId, onClose }: ArtifactPreviewPan
function ArtifactContentPanel({ artifact }: { artifact: ArtifactSnapshot }) {
const [bodyResult, setBodyResult] = useState<ArtifactBodyResponse | null>(null);
+ useEffect(() => {
+ // Clear when switching artifacts
+ setBodyResult(null);
+ setLoading(true);
+ setError(null);
+ }, [artifact.artifactId]);
const [loading, setLoading] = useState(true);
const [error, setError] = useState<string | null>(null);
@@ -206,9 +213,22 @@ function ArtifactContentPanel({ artifact }: { artifact: ArtifactSnapshot }) {
const kind = bodyResult?.kind || artifact.kind;
const body = bodyResult?.body || '';
const version = bodyResult?.version || 1;
+ const isText = bodyResult?.is_text ?? false;
- // Binary / file-reference kinds → FileViewer (metadata + download)
+ // File kind whose body is actual readable text → editable viewer.
+ // Truly binary files (body stays a path) → FileViewer (metadata + download).
if (kind === 'file' || kind === 'image') {
+ if (isText) {
+ return (
+ <EditableTextViewer
+ artifact={artifact}
+ body={body}
+ version={version}
+ kind={kind}
+ error={error}
+ />
+ );
+ }
return <FileViewer artifact={artifact} body={body} version={version} error={error} />;
}
diff --git a/crates/openhuman-app/src/artifact_commands.rs b/crates/openhuman-app/src/artifact_commands.rs
index fff2c0cd84..1ba2cb2658 100644
--- a/crates/openhuman-app/src/artifact_commands.rs
+++ b/crates/openhuman-app/src/artifact_commands.rs
@@ -56,6 +56,7 @@ pub struct ArtifactBodyResult {
pub title: String,
pub version: u32,
pub body: String,
+ pub is_text: bool,
}
#[tauri::command]
@@ -76,13 +77,37 @@ pub async fn read_artifact_body(artifact_id: String) -> Result<ArtifactBodyResul
.as_array()
.map(|v| v.len() as u32)
.unwrap_or(0);
- let body = record["versions"]
+ let mut body = record["versions"]
.as_array()
.and_then(|v| v.last())
.and_then(|v| v["body"].as_str())
.unwrap_or("")
.to_string();
- Ok(ArtifactBodyResult { kind, title, version: versions, body })
+ let mut is_text = kind != "file" && kind != "image";
+
+ // For file-kind artifacts the body is a path to a real file. Try to read
+ // its text content so the panel can render it (md/txt/html/etc).
+ // Truly binary files stay as paths — the panel shows metadata + download.
+ if kind == "file" && !body.is_empty() {
+ let file_path = PathBuf::from(&body);
+ match tokio::fs::read(&file_path).await {
+ Ok(bytes) => {
+ // Heuristic: treat as text if it decodes as UTF-8 and has no
+ // NUL bytes in the first 8 KiB (binary signatures).
+ let probe = &bytes[..bytes.len().min(8192)];
+ let looks_text = !probe.contains(&0)
+ && std::str::from_utf8(probe).is_ok();
+ if looks_text {
+ if let Ok(text) = String::from_utf8(bytes) {
+ body = text;
+ is_text = true;
+ }
+ }
+ }
+ Err(_) => { /* leave the path as the body */ }
+ }
+ }
+ Ok(ArtifactBodyResult { kind, title, version: versions, body, is_text })
}
#[derive(Deserialize)]