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(artifacts): bridge versioned artifacts into legacy UI pipeline (latest-version cards)
Sanil188d07cff2ee
diff --git a/crates/openhuman-core/src/agent/artifacts/tiny_store.rs b/crates/openhuman-core/src/agent/artifacts/tiny_store.rsindex fa8799663c..db1ac498a0 100644--- a/crates/openhuman-core/src/agent/artifacts/tiny_store.rs+++ b/crates/openhuman-core/src/agent/artifacts/tiny_store.rs@@ -7,19 +7,36 @@//! one file per artifact as `<root>/versioned/<id>.json`, outside the//! legacy `meta.json` layout the one-shot producers use, so the two systems//! coexist.+//!+//! # UI bridge+//!+//! The desktop UI knows only the legacy artifact pipeline (an `ArtifactMeta`+//! row plus the `ArtifactPending` / `ArtifactReady` domain events), and it+//! only needs the *latest* revision of a deliverable — there is no version+//! stack in the UI. So every [`FsArtifactStore::upsert`] of a text-bearing+//! versioned artifact also mirrors the latest version into that legacy+//! pipeline, using the existing "regenerate in place" flow+//! ([`super::store::REGENERATE_TARGET_ID`]) so the same artifact id is+//! reused, the file it already owns is overwritten, and the UI card swaps in+//! place without flicker. Image/File kinds carry a *reference* (path), not+//! content, so they are not mirrored — their producers already file them+//! through the legacy path directly.-use std::path::{Path, PathBuf};+use std::path::Path;use std::sync::Arc;use async_trait::async_trait;-use tiny_artifacts::{ArtifactRecord, ArtifactStore};+use tiny_artifacts::{ArtifactKind, ArtifactRecord, ArtifactStore};++use super::files::FileRoots;+use super::types::ArtifactKind as LegacyArtifactKind;/// Subdirectory under the artifacts root holding versioned records.const VERSIONED_SUBDIR: &str = "versioned";/// The artifacts root, mirroring [`super::store::artifacts_root`]:/// `<workspace_dir>/artifacts/`.-async fn root(workspace_dir: &Path) -> Result<PathBuf, String> {+async fn root(workspace_dir: &Path) -> Result<std::path::PathBuf, String> {let root = workspace_dir.join("artifacts");tokio::fs::create_dir_all(&root).await@@ -44,20 +61,36 @@ fn validate_id(id: &str) -> Result<(), String> {Ok(())}+/// Mapping from the shared model's kinds to the legacy kinds the UI renders,+/// plus the file extension for the mirrored deliverable. `None` for kinds+/// whose body is a reference rather than content (image, file) — mirroring+/// those would write the reference string as the file's bytes.+fn legacy_mirror(kind: ArtifactKind) -> Option<(LegacyArtifactKind, &'static str)> {+ match kind {+ ArtifactKind::Text => Some((LegacyArtifactKind::Document, "txt")),+ ArtifactKind::Markdown => Some((LegacyArtifactKind::Document, "md")),+ ArtifactKind::Html => Some((LegacyArtifactKind::Document, "html")),+ ArtifactKind::Image | ArtifactKind::File => None,+ }+}+/// OpenHuman's storage backend for the shared versioned artifact model.////// Each record is stored whole (JSON) at `<workspace>/artifacts/versioned/<id>.json`.pub struct FsArtifactStore {- workspace_dir: PathBuf,+ workspace_dir: std::path::PathBuf,+ files: FileRoots,}impl FsArtifactStore {- /// Creates a store rooted at `workspace_dir`.- pub fn new(workspace_dir: impl Into<PathBuf>) -> Self {- Self { workspace_dir: workspace_dir.into() }+ /// Creates a store rooted at `workspace_dir`; `files` is the visible+ /// files folder mirrored deliverables land in (same as the legacy+ /// producers use, see [`FileRoots`]).+ pub fn new(workspace_dir: impl Into<std::path::PathBuf>, files: FileRoots) -> Self {+ Self { workspace_dir: workspace_dir.into(), files }}- async fn record_path(&self, id: &str) -> Result<PathBuf, String> {+ async fn record_path(&self, id: &str) -> Result<std::path::PathBuf, String> {validate_id(id)?;let root = root(&self.workspace_dir).await?;let dir = root.join(VERSIONED_SUBDIR);@@ -66,6 +99,41 @@ impl FsArtifactStore {.map_err(|e| format!("[tiny-artifacts] failed to create versioned dir {:?}: {e}", dir))?;Ok(dir.join(format!("{id}.json")))}++ /// Mirror the latest revision into the legacy UI pipeline: mint (or+ /// regenerate) the legacy meta row under the same artifact id, write the+ /// latest body to the visible files folder, and publish the ready event.+ /// Best-effort — a mirror failure must not fail the versioned write.+ async fn mirror_to_legacy(&self, record: &ArtifactRecord) -> anyhow::Result<()> {+ let Some((legacy_kind, ext)) = legacy_mirror(record.kind) else {+ return Ok(());+ };+ let Some(latest) = record.latest() else {+ return Ok(());+ };+ // Reuse the existing in-place regenerate flow so the artifact id is+ // stable and the file an older revision already owns is overwritten+ // rather than claiming a second name (#5505).+ super::store::REGENERATE_TARGET_ID+ .scope(record.id.clone(), async {+ let (meta, path) = super::store::create_artifact(+ &self.workspace_dir,+ self.files.clone(),+ legacy_kind,+ &record.title,+ ext,+ )+ .await+ .map_err(anyhow::Error::msg)?;+ tokio::fs::write(&path, latest.body.as_bytes()).await?;+ super::store::finalize_artifact(&self.workspace_dir, &meta.id, latest.body.len() as u64)+ .await+ .map_err(anyhow::Error::msg)?;+ Ok::<(), anyhow::Error>(())+ })+ .await?;+ Ok(())+ }}#[async_trait]@@ -107,23 +175,39 @@ impl ArtifactStore for FsArtifactStore {let path = self.record_path(&artifact.id).await.map_err(anyhow::Error::msg)?;let bytes = serde_json::to_vec(artifact)?;tokio::fs::write(&path, bytes).await?;+ // UI bridge: surface the latest revision through the legacy pipeline.+ if let Err(err) = self.mirror_to_legacy(artifact).await {+ tracing::warn!(+ target: "tiny-artifacts",+ err = %err,+ artifact_id = %artifact.id,+ "[tiny-artifacts] failed to mirror artifact into legacy UI pipeline"+ );+ }Ok(())}async fn delete(&self, id: &str) -> anyhow::Result<bool> {let path = self.record_path(id).await.map_err(anyhow::Error::msg)?;- match tokio::fs::remove_file(&path).await {- Ok(()) => Ok(true),- Err(e) if e.kind() == std::io::ErrorKind::NotFound => Ok(false),- Err(e) => Err(e.into()),+ let removed = match tokio::fs::remove_file(&path).await {+ Ok(()) => true,+ Err(e) if e.kind() == std::io::ErrorKind::NotFound => false,+ Err(e) => return Err(e.into()),+ };+ if removed {+ // Drop the mirrored legacy row too so the Files panel does not+ // keep listing a deleted artifact.+ let _ = super::store::delete_artifact(&self.workspace_dir, self.files.clone(), id)+ .await;}+ Ok(removed)}}/// Build the versioned artifact tools bound to this store — the four tools in/// the crate's catalogue order: `create_artifact`, `read_artifact`,/// `update_artifact`, `list_artifacts`.-pub fn registered_tools(workspace_dir: &Path) -> Vec<Box<dyn tinytools::Tool>> {- let store: Arc<dyn ArtifactStore> = Arc::new(FsArtifactStore::new(workspace_dir));+pub fn registered_tools(workspace_dir: &Path, files: FileRoots) -> Vec<Box<dyn tinytools::Tool>> {+ let store: Arc<dyn ArtifactStore> = Arc::new(FsArtifactStore::new(workspace_dir, files));tiny_artifacts::registered_tools(store)}diff --git a/crates/openhuman-core/src/media/generation/artifact_tool.rs b/crates/openhuman-core/src/media/generation/artifact_tool.rsindex cca843a236..6a1dc8b285 100644--- a/crates/openhuman-core/src/media/generation/artifact_tool.rs+++ b/crates/openhuman-core/src/media/generation/artifact_tool.rs@@ -175,7 +175,7 @@ impl<T: Tool> MediaArtifactTool<T> {// a fresh versioned record – the shared model stores// a workspace-path reference, not bytes. Best-effort:// a failure here must not fail the filed artifact.- let versioned = FsArtifactStore::new(&self.workspace_dir);+ let versioned = FsArtifactStore::new(&self.workspace_dir, self.files_dir.clone());let kind = match self.kind {ArtifactKind::Image => tiny_artifacts::ArtifactKind::Image,_ => tiny_artifacts::ArtifactKind::File,diff --git a/crates/openhuman-core/src/tools/ops.rs b/crates/openhuman-core/src/tools/ops.rsindex e20ac3d9e9..a132bc343e 100644--- a/crates/openhuman-core/src/tools/ops.rs+++ b/crates/openhuman-core/src/tools/ops.rs@@ -173,6 +173,7 @@ pub fn all_tools_with_runtime());tools.extend(crate::agent::artifacts::tiny_store::registered_tools(&config.workspace_dir,+ crate::agent::artifacts::FileRoots::from_config(&config),));tools.extend(crate::integrations::task_sources::tools::registered_tools(config.clone(),