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
refactor(artifacts): move document store helpers into store_documents
Steven Enamakelf15d749a8875
diff --git a/crates/openhuman-core/src/agent/artifacts/store.rs b/crates/openhuman-core/src/agent/artifacts/store.rsindex 2d4f7e6cae..7548c67fd8 100644--- a/crates/openhuman-core/src/agent/artifacts/store.rs+++ b/crates/openhuman-core/src/agent/artifacts/store.rs@@ -1,7 +1,7 @@use std::path::{Path, PathBuf};use super::files::{self, FileRoots};-use super::store_documents::{self, Docs};+use super::store_documents::{self, documents, on_docs, page_of};use super::types::{ArtifactMeta, ArtifactStatus};const ARTIFACTS_SUBDIR: &str = "artifacts";@@ -24,52 +24,6 @@ tokio::task_local! {pub static REGENERATE_TARGET_ID: String;}-/// Runs a document-store call off the async worker (the port is reached-/// through a blocking bridge).-async fn on_docs<T: Send + 'static>(- docs: Docs,- f: impl FnOnce(Docs) -> anyhow::Result<T> + Send + 'static,-) -> Result<T, String> {- tokio::task::spawn_blocking(move || f(docs))- .await- .map_err(|e| format!("[artifacts] storage task failed: {e}"))?- .map_err(|e| format!("[artifacts] storage: {e:#}"))-}--/// The document store for this call, when a storage backend is configured.-/// The first call that finds it empty imports the workspace's legacy-/// `meta.json` / `args.json` files.-async fn documents(workspace_dir: &Path) -> Result<Option<Docs>, String> {- let Some(docs) =- store_documents::current().map_err(|e| format!("[artifacts] storage: {e:#}"))?- else {- return Ok(None);- };- // Once per scope and workspace: the import only matters the first time.- static IMPORTED: std::sync::Mutex<Vec<String>> = std::sync::Mutex::new(Vec::new());- let scope = crate::storage::current_scope().map_err(|e| format!("[artifacts] storage: {e}"))?;- let key = format!("{scope}|{}", workspace_dir.display());- let first = {- let mut seen = IMPORTED- .lock()- .unwrap_or_else(std::sync::PoisonError::into_inner);- if seen.contains(&key) {- false- } else {- seen.push(key);- true- }- };- if first {- let legacy = workspace_dir.join(ARTIFACTS_SUBDIR);- on_docs(docs.clone(), move |docs| {- docs.import_legacy(&legacy).map(|_| ())- })- .await?;- }- Ok(Some(docs))-}-/// Returns the artifacts root directory, creating it if it doesn't exist.////// The root lives at `<workspace_dir>/artifacts/`.@@ -279,33 +233,6 @@ pub(crate) async fn list_artifacts(Ok(page_of(all, offset, limit, thread_id))}-/// Sorts newest first, applies the thread filter and then the page.-fn page_of(- mut all: Vec<ArtifactMeta>,- offset: usize,- limit: usize,- thread_id: Option<&str>,-) -> (Vec<ArtifactMeta>, usize) {- // Sort descending by created_at (newest first)- all.sort_by_key(|item| std::cmp::Reverse(item.created_at));-- // Apply thread filter BEFORE pagination so `total` reflects the- // per-thread count the UI surfaces, and so a small page doesn't get- // silently emptied by filtering after the slice (#3226).- if let Some(tid) = thread_id {- all.retain(|m| m.thread_id.as_deref() == Some(tid));- }-- let total = all.len();- let page = all.into_iter().skip(offset).take(limit).collect::<Vec<_>>();-- log::debug!(- "[artifacts] list_artifacts: total={total} returning {} items",- page.len()- );- (page, total)-}-/// Retrieve a single artifact by ID.pub(crate) async fn get_artifact(workspace_dir: &Path,diff --git a/crates/openhuman-core/src/agent/artifacts/store_documents.rs b/crates/openhuman-core/src/agent/artifacts/store_documents.rsindex 4ac519fe3c..4b6b021bd0 100644--- a/crates/openhuman-core/src/agent/artifacts/store_documents.rs+++ b/crates/openhuman-core/src/agent/artifacts/store_documents.rs@@ -187,6 +187,77 @@ impl Docs {}}+/// Runs a document-store call off the async worker (the port is reached+/// through a blocking bridge).+pub(super) async fn on_docs<T: Send + 'static>(+ docs: Docs,+ f: impl FnOnce(Docs) -> anyhow::Result<T> + Send + 'static,+) -> Result<T, String> {+ crate::core::runtime::spawn_blocking_scoped(move || f(docs))+ .await+ .map_err(|e| format!("[artifacts] storage task failed: {e}"))?+ .map_err(|e| format!("[artifacts] storage: {e:#}"))+}++/// The document store for this call, when a storage backend is configured.+/// The first call that finds it empty imports the workspace's legacy+/// `meta.json` / `args.json` files.+pub(super) async fn documents(workspace_dir: &Path) -> Result<Option<Docs>, String> {+ let Some(docs) = current().map_err(|e| format!("[artifacts] storage: {e:#}"))? else {+ return Ok(None);+ };+ // Once per scope and workspace: the import only matters the first time.+ static IMPORTED: std::sync::Mutex<Vec<String>> = std::sync::Mutex::new(Vec::new());+ let scope = crate::storage::current_scope().map_err(|e| format!("[artifacts] storage: {e}"))?;+ let key = format!("{scope}|{}", workspace_dir.display());+ let first = {+ let mut seen = IMPORTED+ .lock()+ .unwrap_or_else(std::sync::PoisonError::into_inner);+ if seen.contains(&key) {+ false+ } else {+ seen.push(key);+ true+ }+ };+ if first {+ let legacy = workspace_dir.join("artifacts");+ on_docs(docs.clone(), move |docs| {+ docs.import_legacy(&legacy).map(|_| ())+ })+ .await?;+ }+ Ok(Some(docs))+}++/// Sorts newest first, applies the thread filter and then the page.+pub(super) fn page_of(+ mut all: Vec<ArtifactMeta>,+ offset: usize,+ limit: usize,+ thread_id: Option<&str>,+) -> (Vec<ArtifactMeta>, usize) {+ // Sort descending by created_at (newest first)+ all.sort_by_key(|item| std::cmp::Reverse(item.created_at));++ // Apply thread filter BEFORE pagination so `total` reflects the+ // per-thread count the UI surfaces, and so a small page doesn't get+ // silently emptied by filtering after the slice (#3226).+ if let Some(tid) = thread_id {+ all.retain(|m| m.thread_id.as_deref() == Some(tid));+ }++ let total = all.len();+ let page = all.into_iter().skip(offset).take(limit).collect::<Vec<_>>();++ log::debug!(+ "[artifacts] list_artifacts: total={total} returning {} items",+ page.len()+ );+ (page, total)+}+#[cfg(test)]#[path = "store_documents_tests.rs"]mod tests;diff --git a/crates/openhuman-core/src/integrations/composio/file_store.rs b/crates/openhuman-core/src/integrations/composio/file_store.rsindex 807f717180..27421cac04 100644--- a/crates/openhuman-core/src/integrations/composio/file_store.rs+++ b/crates/openhuman-core/src/integrations/composio/file_store.rs@@ -52,8 +52,18 @@ wherelet owned = path.to_path_buf();return crate::core::runtime::spawn_blocking_scoped(move || docs.load(&owned)).await- .map_err(|error| format!("[composio:store] reading {} failed: {error}", path.display()))?- .map_err(|error| format!("[composio:store] reading {} failed: {error:#}", path.display()));+ .map_err(|error| {+ format!(+ "[composio:store] reading {} failed: {error}",+ path.display()+ )+ })?+ .map_err(|error| {+ format!(+ "[composio:store] reading {} failed: {error:#}",+ path.display()+ )+ });}let bytes = match tokio::fs::read(path).await {Ok(bytes) => bytes,@@ -137,8 +147,18 @@ where.map_err(|error| format!("[composio:store] serializing failed: {error}"))?;return crate::core::runtime::spawn_blocking_scoped(move || docs.save(&owned, &value)).await- .map_err(|error| format!("[composio:store] writing {} failed: {error}", path.display()))?- .map_err(|error| format!("[composio:store] writing {} failed: {error:#}", path.display()));+ .map_err(|error| {+ format!(+ "[composio:store] writing {} failed: {error}",+ path.display()+ )+ })?+ .map_err(|error| {+ format!(+ "[composio:store] writing {} failed: {error:#}",+ path.display()+ )+ });}let bytes = serde_json::to_vec_pretty(value).map_err(|error| format!("[composio:store] serializing failed: {error}"))?;