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(tinymemes): add callback support to the service
Steven Enamakel3ead88781421
diff --git a/crates/openhuman-core/src/tinymemes/callbacks.rs b/crates/openhuman-core/src/tinymemes/callbacks.rsindex 180f113aae..948c41d2e9 100644--- a/crates/openhuman-core/src/tinymemes/callbacks.rs+++ b/crates/openhuman-core/src/tinymemes/callbacks.rs@@ -101,7 +101,9 @@ pub(super) fn register(config: &Config) -> Registration {/// The session a callback answers for, if its remix is still registered.pub(super) fn session(correlation: &str) -> Option<Arc<Session>> {- registry().get(correlation).map(|entry| entry.session.clone())+ registry()+ .get(correlation)+ .map(|entry| entry.session.clone())}/// The module finished this remix: forget it.diff --git a/crates/openhuman-core/src/tinymemes/callbacks_tests.rs b/crates/openhuman-core/src/tinymemes/callbacks_tests.rsindex 5323651141..ebe04e985c 100644--- a/crates/openhuman-core/src/tinymemes/callbacks_tests.rs+++ b/crates/openhuman-core/src/tinymemes/callbacks_tests.rs@@ -46,9 +46,13 @@ async fn an_index_saved_through_the_host_loads_back_per_kind() {("memes", "{\"memes\":2}"),("remixed", "[\"m1\"]"),] {- let loaded = dispatch(&session, host_methods::LOAD_INDEX, json!([{ "kind": kind }]))- .await- .unwrap();+ let loaded = dispatch(+ &session,+ host_methods::LOAD_INDEX,+ json!([{ "kind": kind }]),+ )+ .await+ .unwrap();assert_eq!(decode::<Option<String>>(loaded), Ok(Some(body.into())));}}@@ -114,7 +118,10 @@ fn registrations_are_independent_and_forgotten_on_drop() {assert!(session(a.correlation()).is_some() && session(b.correlation()).is_some());let a_id = a.correlation().to_owned();drop(a);- assert!(session(&a_id).is_none(), "a failed call leaves nothing behind");+ assert!(+ session(&a_id).is_none(),+ "a failed call leaves nothing behind"+ );assert!(session(b.correlation()).is_some());assert!(session("").is_none() && session("unknown").is_none());}@@ -125,7 +132,10 @@ fn a_kept_registration_lives_until_the_module_reports_the_end() {let registration = register(&config_in(dir.path()));let id = registration.correlation().to_owned();registration.keep_for_background();- assert!(session(&id).is_some(), "background research may still call back");+ assert!(+ session(&id).is_some(),+ "background research may still call back"+ );end(&id);assert!(session(&id).is_none());end(&id);diff --git a/crates/openhuman-core/src/tinymemes/docs.rs b/crates/openhuman-core/src/tinymemes/docs.rsindex 3cf7a6c9e8..40da050cb1 100644--- a/crates/openhuman-core/src/tinymemes/docs.rs+++ b/crates/openhuman-core/src/tinymemes/docs.rs@@ -14,8 +14,8 @@ use std::path::{Path, PathBuf};use anyhow::{anyhow, Result};use serde_json::{json, Value};-use tinystoragedrivers::{CollectionSpec, Precondition};use tinymemes_bus::IndexKind;+use tinystoragedrivers::{CollectionSpec, Precondition};use crate::config::Config;use crate::storage::documents::{text, Repo};@@ -69,9 +69,14 @@ pub(super) fn load(config: &Config, kind: IndexKind) -> Result<Option<String>> {// `Absent`: a concurrent save wins over the old file's content.let adopted = legacy.clone();let written = repo.run(move |docs| async move {- docs.put(COLLECTION, id, json!({ FIELD: adopted }), Precondition::Absent)- .await- .map(|_| ())+ docs.put(+ COLLECTION,+ id,+ json!({ FIELD: adopted }),+ Precondition::Absent,+ )+ .await+ .map(|_| ())});match written {Ok(()) => {diff --git a/crates/openhuman-core/src/tinymemes/e2e_tests.rs b/crates/openhuman-core/src/tinymemes/e2e_tests.rsindex fd819db1ca..41005e0b59 100644--- a/crates/openhuman-core/src/tinymemes/e2e_tests.rs+++ b/crates/openhuman-core/src/tinymemes/e2e_tests.rs@@ -74,7 +74,10 @@ async fn the_real_module_fails_open_and_reads_its_documents_through_the_host() {assert_eq!(response.reply, "That's done.");let legacy = config.workspace_dir.join("tinymemes/remixed.json");- assert!(!legacy.exists(), "the module's LoadIndex adopted the old file");+ assert!(+ !legacy.exists(),+ "the module's LoadIndex adopted the old file"+ );assert_eq!(docs::load(&config, IndexKind::Remixed).unwrap().as_deref(),Some("[\"old-1\"]")diff --git a/crates/openhuman-core/src/tinymemes/mod_tests.rs b/crates/openhuman-core/src/tinymemes/mod_tests.rsindex bc6088f4c6..dc6c749f07 100644--- a/crates/openhuman-core/src/tinymemes/mod_tests.rs+++ b/crates/openhuman-core/src/tinymemes/mod_tests.rs@@ -1,7 +1,6 @@use super::*;use std::sync::atomic::{AtomicUsize, Ordering};-use std::sync::Arc;use crate::threads::store::ConversationMessage;@@ -80,11 +79,7 @@ fn thread() -> Vec<ConversationMessage> {]}-async fn run(- remixer: &ScriptedRemixer,- request_id: &str,- budget: Duration,-) -> Option<String> {+async fn run(remixer: &ScriptedRemixer, request_id: &str, budget: Duration) -> Option<String> {remix_with(remixer,options_with(None, 3, true),@@ -213,10 +208,7 @@ async fn a_remix_that_returns_the_same_text_is_not_a_change() {#[tokio::test]async fn a_module_error_sends_the_original() {let remixer = ScriptedRemixer::new(Err("module unavailable".into()));- assert_eq!(- run(&remixer, "req-err", Duration::from_secs(5)).await,- None- );+ assert_eq!(run(&remixer, "req-err", Duration::from_secs(5)).await, None);}#[tokio::test]@@ -308,7 +300,10 @@ fn the_cooldown_env_beats_config_and_bad_values_fall_back() {options_with(Some("5"), 3, true).meme_cooldown_turns,Some(5));- assert_eq!(options_with(Some("0"), 3, true).meme_cooldown_turns, Some(0));+ assert_eq!(+ options_with(Some("0"), 3, true).meme_cooldown_turns,+ Some(0)+ );assert_eq!(options_with(Some("often"), 3, true).meme_cooldown_turns,Some(3)diff --git a/crates/openhuman-core/src/tinymemes/service.rs b/crates/openhuman-core/src/tinymemes/service.rsindex 918819286e..6ee81297f6 100644--- a/crates/openhuman-core/src/tinymemes/service.rs+++ b/crates/openhuman-core/src/tinymemes/service.rs@@ -111,8 +111,7 @@ pub(crate) async fn remix(.map_err(|error| error.to_string())?;let registration = callbacks::register(config);request.correlation = registration.correlation().to_owned();- let outcome: tinybus::Result<RemixResult> =- proxy.call(remix_methods::REMIX, (request,)).await;+ let outcome: tinybus::Result<RemixResult> = proxy.call(remix_methods::REMIX, (request,)).await;match outcome {Ok(Ok(response)) => {// Background research may still call back; the module's `End`diff --git a/crates/openhuman-core/src/tinymemes/service_tests.rs b/crates/openhuman-core/src/tinymemes/service_tests.rsindex 6ba3b1844f..56242a4791 100644--- a/crates/openhuman-core/src/tinymemes/service_tests.rs+++ b/crates/openhuman-core/src/tinymemes/service_tests.rs@@ -22,7 +22,11 @@ struct Bus {async fn bus() -> Bus {let bus = MemoryBus::new();Broker::new().spawn(bus.clone());- let connect = || async { Connection::connect(bus.connect().await.unwrap()).await.unwrap() };+ let connect = || async {+ Connection::connect(bus.connect().await.unwrap())+ .await+ .unwrap()+ };let (host, module, intruder) = (connect().await, connect().await, connect().await);install(&host).await.unwrap();module.request_name(STATE_INTERFACE).await.unwrap();@@ -34,7 +38,12 @@ async fn bus() -> Bus {}impl Bus {- async fn call(&self, from: &Connection, member: &str, payload: Value) -> tinybus::Result<Value> {+ async fn call(+ &self,+ from: &Connection,+ member: &str,+ payload: Value,+ ) -> tinybus::Result<Value> {let host = self.host.unique_name().unwrap();from.proxy(host.as_str(), HOST_PATH, HOST_INTERFACE).unwrap()@@ -105,7 +114,8 @@ async fn remixes_for_different_workspaces_are_served_at_once_each_for_its_own()// Both are live together: neither waits for the other.let save = |registration: &callbacks::Registration, json: &str| {- let payload = json!({ "correlation": registration.correlation(), "kind": "slang", "json": json });+ let payload =+ json!({ "correlation": registration.correlation(), "kind": "slang", "json": json });bus.call(&bus.module, host_methods::SAVE_INDEX, payload)};let (saved_a, saved_b) = tokio::join!(save(&a, "{\"a\":1}"), save(&b, "{\"b\":1}"));