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 history tracking for tiny meme operations
Steven Enamakelc91e28ac1f77
diff --git a/crates/openhuman-core/src/tinymemes/history.rs b/crates/openhuman-core/src/tinymemes/history.rsindex 1693bc6819..b448088271 100644--- a/crates/openhuman-core/src/tinymemes/history.rs+++ b/crates/openhuman-core/src/tinymemes/history.rs@@ -15,7 +15,6 @@ pub(super) fn should_remix(reply: &str, placeholder: &str) -> bool {pub(super) fn history_turns(messages: &[ConversationMessage],current_user_message: &str,- is_remixed: impl Fn(&str) -> bool,) -> Vec<WireTurn> {let mut turns: Vec<WireTurn> = messages.iter()@@ -25,11 +24,15 @@ pub(super) fn history_turns(role: WireRole::User,text: m.content.clone(),remixed: false,+ id: Some(m.id.clone()),}),"agent" | "assistant" => Some(WireTurn {role: WireRole::Assistant,text: m.content.clone(),- remixed: is_remixed(&m.id),+ // Whether it went out remixed is the module's to say: it keeps+ // the ring of remixed ids and matches them by this id.+ remixed: false,+ id: Some(m.id.clone()),}),_ => None,})@@ -43,6 +46,7 @@ pub(super) fn history_turns(role: WireRole::User,text: current.to_owned(),remixed: false,+ id: None,});}turnsdiff --git a/crates/openhuman-core/src/tinymemes/service.rs b/crates/openhuman-core/src/tinymemes/service.rsindex c0acd36f28..5f24e8cef4 100644--- a/crates/openhuman-core/src/tinymemes/service.rs+++ b/crates/openhuman-core/src/tinymemes/service.rs@@ -4,7 +4,8 @@use async_trait::async_trait;use tinybus::{CallContext, Connection, InterfaceName, MemberName, ObjectPath};use tinymemes_bus::{- RemixClient, RemixRefusal, RemixRequest, RemixResponse, HOST_INTERFACE, HOST_METHODS, HOST_PATH,+ host_methods, remix_methods, RemixRefusal, RemixRequest, RemixResponse, RemixResult,+ HOST_INTERFACE, HOST_METHODS, HOST_PATH, REMIX_INTERFACE, REMIX_PATH, STATE_INTERFACE,};use super::callbacks;@@ -60,24 +61,25 @@ impl tinybus::Interface for HostService {log::warn!("[tinymemes] refused a host callback from a peer that is not the module");return Err(tinybus::Error::failed("unknown tinymemes caller"));}- let Some(session) = callbacks::active() else {- log::debug!("[tinymemes] host callback with no remix running");- return Err(tinybus::Error::failed("no tinymemes remix is running"));+ // The module is the only caller, but it serves many remixes: the+ // correlation id says which workspace this callback answers for.+ let correlation = callbacks::correlation_of(&args).map(str::to_owned);+ if member.as_str() == host_methods::END {+ // Forgetting an unknown id is harmless, so `End` needs no session.+ if let Some(correlation) = &correlation {+ callbacks::end(correlation);+ }+ return serde_json::to_value(tinymemes_bus::HostResult::<()>::Ok(()))+ .map_err(|_| tinybus::Error::failed("invalid tinymemes host response"));+ }+ let Some(session) = correlation.as_deref().and_then(callbacks::session) else {+ log::debug!("[tinymemes] host callback with no live remix for its correlation id");+ return Err(tinybus::Error::failed("no such tinymemes remix"));};callbacks::dispatch(&session, member.as_str(), args).await}}-const COOLDOWN_ENV: &str = "OPENHUMAN_TINYMEMES_MEME_COOLDOWN";--/// The module reads its meme cooldown from the environment; hand it-/// `[memes] meme_cooldown` unless the operator already set the variable.-fn export_cooldown(config: &Config) {- if std::env::var_os(COOLDOWN_ENV).is_none() {- std::env::set_var(COOLDOWN_ENV, config.memes.meme_cooldown.to_string());- }-}-/// Serve the module's host callbacks on the module bus.pub(crate) async fn install(connection: &Connection) -> tinybus::Result<()> {connection@@ -91,20 +93,33 @@ pub(crate) async fn install(connection: &Connection) -> tinybus::Result<()> {}/// Remix one reply through the loaded module, serving its callbacks for-/// `config`'s workspace meanwhile.-pub(crate) async fn remix(config: &Config, request: RemixRequest) -> Result<RemixResponse, String> {+/// `config`'s workspace meanwhile. `request.correlation` is set here.+pub(crate) async fn remix(+ config: &Config,+ mut request: RemixRequest,+) -> Result<RemixResponse, String> {if !config.components.memes {return Err("the memes component is off".to_owned());}- export_cooldown(config);crate::modules::ensure_loaded(config, MODULE_ID).await?;let runtime = crate::modules::host::runtime().await.map_err(|error| format!("the module bus is not running: {error}"))?;- let client = RemixClient::new(runtime.connection()).map_err(|error| error.to_string())?;- let outcome = callbacks::run_with(config, client.remix(request)).await;+ let proxy = runtime+ .connection()+ .proxy(STATE_INTERFACE, REMIX_PATH, REMIX_INTERFACE)+ .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;match outcome {- Ok(Ok(response)) => Ok(response),+ Ok(Ok(response)) => {+ // Background research may still call back; the module's `End`+ // (or the age sweep) retires the entry.+ registration.keep_for_background();+ Ok(response)+ }Ok(Err(refusal)) => Err(match refusal {RemixRefusal::Closing => "the tinymemes module is closing".to_owned(),RemixRefusal::Unauthenticated => "the tinymemes module refused the caller".to_owned(),