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(composio): extract file store helpers
Steven Enamakel9f7660e55c22
diff --git a/crates/openhuman-core/src/integrations/composio/file_store.rs b/crates/openhuman-core/src/integrations/composio/file_store.rsindex d44a688daa..994765224d 100644--- a/crates/openhuman-core/src/integrations/composio/file_store.rs+++ b/crates/openhuman-core/src/integrations/composio/file_store.rs@@ -25,13 +25,14 @@ pub(crate) const USER_SCOPES_FILE: &str = "composio_user_scopes.json";/// ever read, never renamed or rewritten, so the old data stays byte-identical./// A missing file is the common case and a no-op.async fn import_legacy(+ ctx: &crate::core::runtime::DispatchCtx,config: &Config,docs: &super::file_store_documents::Docs,name: &'static str,) -> Result<(), String> {let marker_docs = docs.clone();let done =- crate::core::runtime::DispatchCtx::ambient().spawn_blocking(move || marker_docs.legacy_imported(name))+ ctx.spawn_blocking(move || marker_docs.legacy_imported(name)).await.map_err(|error| format!("[composio:store] checking legacy {name} failed: {error}"))?.map_err(|error| {@@ -54,7 +55,7 @@ async fn import_legacy(.map_err(|error| format!("[composio:store] parsing legacy {name} failed: {error}"))?;let docs = docs.clone();let wrote =- crate::core::runtime::DispatchCtx::ambient().spawn_blocking(move || docs.import_if_absent(name, value))+ ctx.spawn_blocking(move || docs.import_if_absent(name, value)).await.map_err(|error| format!("[composio:store] importing legacy {name} failed: {error}"))?.map_err(|error| {@@ -69,16 +70,19 @@ async fn import_legacy(/// # Errors////// The value cannot be read or does not parse as `T`.-pub(crate) async fn load<T>(config: &Config, name: &'static str) -> Result<T, String>+pub(crate) async fn load<T>(+ ctx: &crate::core::runtime::DispatchCtx,+ config: &Config,+ name: &'static str) -> Result<T, String>whereT: DeserializeOwned + Default + Send + 'static,{let docs = super::file_store_documents::current(&config.workspace_dir).map_err(|e| format!("[composio:store] {e:#}"))?;- import_legacy(config, &docs, name).await?;+ import_legacy(ctx, config, &docs, name).await?;// The document port is reached through a blocking bridge; keep it off the// async worker, under the caller's context.- crate::core::runtime::DispatchCtx::ambient().spawn_blocking(move || docs.load(name))+ ctx.spawn_blocking(move || docs.load(name)).await.map_err(|error| format!("[composio:store] reading {name} failed: {error}"))?.map_err(|error| format!("[composio:store] reading {name} failed: {error:#}"))@@ -92,6 +96,7 @@ where////// The value cannot be read or written.pub(crate) async fn update<T, R>(+ ctx: &crate::core::runtime::DispatchCtx,config: &Config,name: &'static str,change: impl Fn(&mut T) -> (R, bool) + Send + 'static,@@ -102,8 +107,8 @@ where{let docs = super::file_store_documents::current(&config.workspace_dir).map_err(|e| format!("[composio:store] {e:#}"))?;- import_legacy(config, &docs, name).await?;- crate::core::runtime::DispatchCtx::ambient().spawn_blocking(move || docs.update(name, change))+ import_legacy(ctx, config, &docs, name).await?;+ ctx.spawn_blocking(move || docs.update(name, change)).await.map_err(|error| format!("[composio:store] updating {name} failed: {error}"))?.map_err(|error| format!("[composio:store] updating {name} failed: {error:#}"))@@ -115,7 +120,10 @@ where////// The value cannot be serialized or written.#[cfg(test)]-pub(crate) async fn save<T>(config: &Config, name: &'static str, value: &T) -> Result<(), String>+pub(crate) async fn save<T>(+ ctx: &crate::core::runtime::DispatchCtx,+ config: &Config,+ name: &'static str, value: &T) -> Result<(), String>whereT: Serialize,{@@ -123,7 +131,7 @@ where.map_err(|e| format!("[composio:store] {e:#}"))?;let value = serde_json::to_value(value).map_err(|error| format!("[composio:store] serializing failed: {error}"))?;- crate::core::runtime::DispatchCtx::ambient().spawn_blocking(move || docs.save(name, &value))+ ctx.spawn_blocking(move || docs.save(name, &value)).await.map_err(|error| format!("[composio:store] writing {name} failed: {error}"))?.map_err(|error| format!("[composio:store] writing {name} failed: {error:#}"))