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): each file version keeps its own copy
Sanile74bbe6fbdd3
diff --git a/crates/openhuman-core/src/agent/artifacts/preview.rs b/crates/openhuman-core/src/agent/artifacts/preview.rsindex 528cd4342e..28e1f986c7 100644--- a/crates/openhuman-core/src/agent/artifacts/preview.rs+++ b/crates/openhuman-core/src/agent/artifacts/preview.rs@@ -48,7 +48,12 @@ pub struct ArtifactBody {/// read.pub async fn read_body(config: &Config, id: &str) -> Result<ArtifactBody, String> {let files = super::files::FileRoots::from_config(config);- let mut roots: Vec<PathBuf> = vec![config.action_dir.clone()];+ // Where a file version may live: its own kept copy, the agent's working+ // folder, or the files folders.+ let mut roots: Vec<PathBuf> = vec![+ super::tiny_store::version_files_dir(&config.workspace_dir),+ config.action_dir.clone(),+ ];roots.extend(files.trusted().iter().cloned());let record = super::tiny_store::artifacts_service(&config.workspace_dir,diff --git a/crates/openhuman-core/src/agent/artifacts/production_tests.rs b/crates/openhuman-core/src/agent/artifacts/production_tests.rsindex b0d1934bc0..9adca7f2bd 100644--- a/crates/openhuman-core/src/agent/artifacts/production_tests.rs+++ b/crates/openhuman-core/src/agent/artifacts/production_tests.rs@@ -87,8 +87,12 @@ async fn a_new_artifact_shares_one_id_and_one_file_between_card_and_record() {record.latest().unwrap().author_id,crate::agent::artifacts::tiny_store::AGENT_AUTHOR_ID);+ // The version holds its own copy; the files folder shows the newest.let file = record.latest().unwrap().file.clone().unwrap();- assert!(file.path.ends_with("quarterly-deck.pptx"), "{}", file.path);+ let kept = crate::agent::artifacts::tiny_store::version_files_dir(&workspace)+ .join(&id)+ .join("v1.pptx");+ assert_eq!(std::path::Path::new(&file.path), kept.as_path());assert_eq!(files_in(&files),vec!["quarterly-deck.pptx"],@@ -115,6 +119,10 @@ async fn a_revision_reuses_the_id_and_file_and_keeps_the_history() {std::fs::read(files.join("quarterly-deck.pptx")).unwrap(),b"deck-v2!");+ // Each version still holds what it was.+ let bytes_of = |n: u32| std::fs::read(&record.version(n).unwrap().file.clone().unwrap().path);+ assert_eq!(bytes_of(1).unwrap(), b"deck-v1");+ assert_eq!(bytes_of(2).unwrap(), b"deck-v2!");}#[tokio::test]diff --git a/crates/openhuman-core/src/agent/artifacts/tiny_store.rs b/crates/openhuman-core/src/agent/artifacts/tiny_store.rsindex 10122a3d4a..58329d80c4 100644--- a/crates/openhuman-core/src/agent/artifacts/tiny_store.rs+++ b/crates/openhuman-core/src/agent/artifacts/tiny_store.rs@@ -122,14 +122,25 @@ impl LegacyUiBridge {else {return Ok(());};- // A producer writes its file straight into the row it reserved: the- // row only needs marking ready (re-reserving would flash its card- // back to "generating").+ // A file version lands in the file its card already owns: copy it there+ // (a producer has usually written that file itself) and mark the card+ // ready. Re-reserving would flash the card back to "generating".if let Some(file) = latest.file.as_ref() {if let Ok(meta) = super::store::get_artifact(&self.workspace_dir, &record.id).await {- let owned = meta.file.as_deref().map(Path::new);- if owned.is_some_and(|owned| same_file(owned, Path::new(&file.path))) {- let size = tokio::fs::metadata(&file.path).await?.len();+ let owned = meta.file.as_deref().map(Path::new).filter(|owned| {+ owned+ .extension()+ .and_then(|e| e.to_str())+ .map(str::to_ascii_lowercase)+ == Some(ext.clone())+ });+ if let Some(owned) = owned {+ let source = Path::new(&file.path);+ let size = if same_file(owned, source) {+ tokio::fs::metadata(source).await?.len()+ } else {+ tokio::fs::copy(source, owned).await?+ };super::store::finalize_artifact(&self.workspace_dir,&record.id,@@ -235,6 +246,17 @@ pub fn artifacts_service(Artifacts::new(Arc::new(versioned_store(workspace_dir))).with_observer(Arc::new(LegacyUiBridge::new(workspace_dir, files, chat))).with_file_roots(tiny_artifacts::FileRoots::new(roots))+ .with_version_files(version_files_dir(workspace_dir))+}++/// Where each file version keeps its own copy:+/// `<workspace>/artifacts/versioned/files/<id>/v<N>.<ext>`. The visible file+/// in the files folder shows the newest version.+pub fn version_files_dir(workspace_dir: &Path) -> PathBuf {+ workspace_dir+ .join("artifacts")+ .join(VERSIONED_SUBDIR)+ .join("files")}/// Build the artifact tools bound to this workspace's service: the crate'sdiff --git a/crates/openhuman-core/src/integrations/file_storage/artifact_publisher.rs b/crates/openhuman-core/src/integrations/file_storage/artifact_publisher.rsindex e7eec34275..7f8c60376c 100644--- a/crates/openhuman-core/src/integrations/file_storage/artifact_publisher.rs+++ b/crates/openhuman-core/src/integrations/file_storage/artifact_publisher.rs@@ -79,11 +79,12 @@ async fn upload_body(let bytes = tokio::fs::read(path).await.map_err(|e| anyhow::anyhow!("cannot read the artifact's file: {e}"))?;- let name = path- .file_name()- .and_then(|n| n.to_str())- .unwrap_or("artifact")- .to_string();+ // Named after the artifact: the file read may be a kept version copy+ // (`v2.pptx`), whose name means nothing to whoever opens the link.+ let name = match path.extension().and_then(|e| e.to_str()) {+ Some(ext) => format!("{}.{ext}", file_stem(&record.title)),+ None => file_stem(&record.title),+ };let mime = mime_for_path(path);return Ok((bytes, name, mime));}diff --git a/crates/openhuman-core/src/integrations/file_storage/artifact_publisher_tests.rs b/crates/openhuman-core/src/integrations/file_storage/artifact_publisher_tests.rsindex 3e8e7fbeb4..baa19620af 100644--- a/crates/openhuman-core/src/integrations/file_storage/artifact_publisher_tests.rs+++ b/crates/openhuman-core/src/integrations/file_storage/artifact_publisher_tests.rs@@ -104,7 +104,7 @@ async fn a_public_file_share_uses_the_public_url_and_makes_no_link() {Mock::given(method("POST")).and(path("/agent-integrations/file-storage/files")).and(body_string_contains("PNG-BYTES"))- .and(body_string_contains("filename=\"chart.png\""))+ .and(body_string_contains("filename=\"Chart.png\"")).and(body_string_contains("public")).respond_with(uploaded(Some("https://api.example/public/file-1"))).expect(1)diff --git a/vendor/tiny-artifacts b/vendor/tiny-artifactsindex d84cecbff8..899c606474 160000--- a/vendor/tiny-artifacts+++ b/vendor/tiny-artifacts@@ -1 +1 @@-Subproject commit d84cecbff85a350658edc4fcfe47e061b59c1b47+Subproject commit 899c6064744944bbc053ca70c83faff8d617d4dd