The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
feat(backend): add read_artifact_body Tauri command for content fetching
Sanil305835d364e7
diff --git a/app/src/features/conversations/aui/ArtifactPreviewPanel.tsx b/app/src/features/conversations/aui/ArtifactPreviewPanel.tsxindex e4cd5ff513..5a56a10bf8 100644--- a/app/src/features/conversations/aui/ArtifactPreviewPanel.tsx+++ b/app/src/features/conversations/aui/ArtifactPreviewPanel.tsx@@ -20,6 +20,7 @@ import { Button } from '../../../components/ui';import { useT } from '../../../lib/i18n/I18nContext';import { useAppSelector } from '../../../store/hooks';import type { ArtifactSnapshot } from '../../../store/chatRuntimeSlice';+import { invoke } from '@tauri-apps/api/core';// ─── Types ──────────────────────────────────────────────────────@@ -217,10 +218,12 @@ function ArtifactToolbar({function ArtifactContent({ artifact }: { artifact: ArtifactSnapshot }) {const [content, setContent] = useState<string | null>(null);const [loading, setLoading] = useState(true);+ const [artifactKind, setArtifactKind] = useState<string>(artifact.kind);+ const [version, setVersion] = useState(1);- // Fetch content from the file path when possible+ // Fetch artifact body from versioned store via Tauri IPCuseEffect(() => {- if (!artifact.path && !artifact.artifactId) {+ if (!artifact.artifactId) {setLoading(false);return;}@@ -228,29 +231,27 @@ function ArtifactContent({ artifact }: { artifact: ArtifactSnapshot }) {let cancelled = false;setLoading(true);- // Try to read the file content via the core's workspace file API- const fetchContent = async () => {+ const fetchBody = async () => {try {- // Use the artifact's path to fetch content- // In dev mode the core serves workspace files- const url = `http://localhost:7799/workspace/files/${encodeURIComponent(artifact.path || '')}`;- const res = await fetch(url);- if (res.ok) {- const text = await res.text();- if (!cancelled) setContent(text);- } else {- // Fallback: show the file path- if (!cancelled) setContent(`// Content from: ${artifact.path}\n// (use ai.get_artifact to read the file)`);- }- } catch {- if (!cancelled) setContent(`// Could not load: ${artifact.path}`);+ const result = await invoke<{ kind: string; title: string; version: number; body: string }>(+ 'read_artifact_body',+ { artifactId: artifact.artifactId },+ );+ if (cancelled) return;+ setContent(result.body);+ setArtifactKind(result.kind);+ setVersion(result.version);+ } catch (err) {+ // Fallback: show a placeholder+ if (cancelled) return;+ setContent(`# ${artifact.title}\n\n*Kind: ${artifact.kind}\nPath: ${artifact.path || '—'}*`);}if (!cancelled) setLoading(false);};- fetchContent();+ fetchBody();return () => { cancelled = true; };- }, [artifact.path, artifact.artifactId]);+ }, [artifact.artifactId, artifact.title, artifact.kind, artifact.path]);if (loading) {return (@@ -260,14 +261,16 @@ function ArtifactContent({ artifact }: { artifact: ArtifactSnapshot }) {);}- switch (artifact.kind) {+ const kind = artifactKind || artifact.kind;++ switch (kind) {case 'html':return <HtmlViewer content={content || ''} />;case 'markdown':case 'text':case 'document':default:- return <TextViewer content={content || `// ${artifact.title}\n// Kind: ${artifact.kind}\n// Path: ${artifact.path}`} language={artifact.kind} />;+ return <TextViewer content={content || `# ${artifact.title}\n\n*Kind: ${artifact.kind}\nPath: ${artifact.path}*`} language={kind} />;}}diff --git a/crates/openhuman-app/src/artifact_commands.rs b/crates/openhuman-app/src/artifact_commands.rsindex 80ba28622f..316a31afb6 100644--- a/crates/openhuman-app/src/artifact_commands.rs+++ b/crates/openhuman-app/src/artifact_commands.rs@@ -26,6 +26,7 @@//! written outside the Downloads directory.use std::path::{Path, PathBuf};+use serde::Serialize;/// Resolve an artifact id to the file the core's artifact store vouches for,/// in the given workspace. Isolated from config loading for unit testing.@@ -49,6 +50,41 @@ async fn copy_to_path(source: &Path, dest: &Path) -> Result<u64, String> {.map_err(|e| format!("failed to copy artifact to {:?}: {e}", dest))}+#[derive(Serialize)]+pub struct ArtifactBodyResult {+ pub kind: String,+ pub title: String,+ pub version: u32,+ pub body: String,+}++#[tauri::command]+pub async fn read_artifact_body(artifact_id: String) -> Result<ArtifactBodyResult, String> {+ let config = openhuman_rpc::embed::config::load_config_with_timeout().await?;+ let path = config.workspace_dir+ .join("artifacts/versioned")+ .join(&artifact_id)+ .with_extension("json");+ let json = tokio::fs::read_to_string(&path)+ .await+ .map_err(|e| format!("artifact {artifact_id} not found: {e}"))?;+ let record: serde_json::Value = serde_json::from_str(&json)+ .map_err(|e| format!("artifact {artifact_id} parse error: {e}"))?;+ let kind = record["kind"].as_str().unwrap_or("text").to_string();+ let title = record["title"].as_str().unwrap_or("artifact").to_string();+ let versions = record["versions"]+ .as_array()+ .map(|v| v.len() as u32)+ .unwrap_or(0);+ let 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 })+}+/// Maximum number of `(N)` suffixes we'll append when picking a/// non-colliding filename. After 1000 we give up and append a UUID/// suffix instead so the download never silently overwrites.diff --git a/crates/openhuman-app/src/lib.rs b/crates/openhuman-app/src/lib.rsindex eba0f986fc..c6fbda9525 100644--- a/crates/openhuman-app/src/lib.rs+++ b/crates/openhuman-app/src/lib.rs@@ -3303,6 +3303,7 @@ pub fn run() {// too (CodeRabbit on #4127). The Save-As dialog that used to sit in// front of this went with the shell's `rfd` dependency.artifact_commands::download_artifact_to_downloads,+ artifact_commands::read_artifact_body,// Native directory chooser for the folder memory-source (#5831).// Unlike the Save-As dialog above it, this one has no renderer-side// substitute: a `webkitdirectory` input cannot report where the