Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

refactor(tokenjuice): pass config by value to client and install helpers

Steven Enamakel81bc485fed21
diff --git a/crates/openhuman-core/src/inference/tokenjuice/mod.rs b/crates/openhuman-core/src/inference/tokenjuice/mod.rs
index c908c90c7f..cd50d41141 100644
--- a/crates/openhuman-core/src/inference/tokenjuice/mod.rs
+++ b/crates/openhuman-core/src/inference/tokenjuice/mod.rs
@@ -387,7 +387,7 @@ async fn detect_with_config(
content: String,
hint: tinyjuice_bus::types::ContentHint,
) -> Result<String, String> {
- client(&config)
+ client(config)
.call("tinyjuice", methods::DETECT, (content, hint))
.await
.map_err(|error| error.to_string())
@@ -408,13 +408,13 @@ async fn compress_with_config(
content: String,
hint: tinyjuice_bus::types::ContentHint,
) -> Result<tinyjuice_bus::types::CompressedOutput, String> {
- install_from_config(&config).await?;
- let response: tinyjuice_bus::types::CompressedOutput = client(&config)
+ install_from_config(config).await?;
+ let response: tinyjuice_bus::types::CompressedOutput = client(config)
.call("tinyjuice", methods::COMPRESS, (content, hint))
.await
.map_err(|error| error.to_string())?;
savings::record(
- &client(&config),
+ &client(config),
response.compressor,
(response.original_bytes as u64).div_ceil(4),
(response.compacted_bytes as u64).div_ceil(4),
@@ -438,8 +438,8 @@ async fn retrieve_with_config(
token: String,
range: Option<tinyjuice_bus::wire::RetrieveRange>,
) -> Result<Option<String>, String> {
- install_from_config(&config).await?;
- client(&config)
+ install_from_config(config).await?;
+ client(config)
.call("tinyjuice", methods::RETRIEVE, (token, range))
.await
.map_err(|error| error.to_string())
@@ -455,8 +455,8 @@ pub async fn cache_stats() -> Result<tinyjuice_bus::wire::CacheStats, String> {
async fn cache_stats_with_config(
config: &crate::config::Config,
) -> Result<tinyjuice_bus::wire::CacheStats, String> {
- install_from_config(&config).await?;
- client(&config)
+ install_from_config(config).await?;
+ client(config)
.call("tinyjuice", methods::CACHE_STATS, ())
.await
.map_err(|error| error.to_string())
diff --git a/crates/openhuman-core/src/inference/tokenjuice/rpc_scope_tests.rs b/crates/openhuman-core/src/inference/tokenjuice/rpc_scope_tests.rs
index adeeb6874a..e05792d7f8 100644
--- a/crates/openhuman-core/src/inference/tokenjuice/rpc_scope_tests.rs
+++ b/crates/openhuman-core/src/inference/tokenjuice/rpc_scope_tests.rs
@@ -59,6 +59,11 @@ impl JuiceFixture {
bytes: 12,
})
}
+
+ async fn savings_stats(&self) -> tinybus::Result<tinyjuice_bus::savings::SavingsAggregate> {
+ self.0.methods.lock().unwrap().push("SavingsStats".into());
+ Ok(tinyjuice_bus::savings::SavingsAggregate::default())
+ }
}
async fn fixture() -> (tinybus::Proxy, Connection, Arc<Calls>) {
@@ -207,12 +212,20 @@ async fn tokenjuice_rpcs_use_their_derived_config_for_module_calls_and_install()
&seen_configs,
)
.await;
+ invoke_for_config(
+ contexts[index].clone(),
+ "savings_stats",
+ serde_json::json!({}),
+ &configs[index],
+ &seen_configs,
+ )
+ .await;
}
})
.await;
let methods = calls.methods.lock().unwrap();
- for method in ["Detect", "Compress", "CacheStats", "Retrieve"] {
+ for method in ["Detect", "Compress", "Retrieve", "SavingsStats"] {
assert_eq!(
methods
.iter()
@@ -222,6 +235,14 @@ async fn tokenjuice_rpcs_use_their_derived_config_for_module_calls_and_install()
"{method} reached the TinyBus client once per derived context"
);
}
+ assert_eq!(
+ methods
+ .iter()
+ .filter(|actual| actual.as_str() == "CacheStats")
+ .count(),
+ 4,
+ "cache statistics and savings statistics each query TinyJuice per caller"
+ );
drop(methods);
let installs = calls.installs.lock().unwrap();
for (index, config) in configs.iter().enumerate() {