Skip to content

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

refactor(tokenjuice): accept config in tokenjuice operations

Steven Enamakel287f8c42b6eb
diff --git a/crates/openhuman-core/src/inference/tokenjuice/mod.rs b/crates/openhuman-core/src/inference/tokenjuice/mod.rs
index 819635d2b9..c908c90c7f 100644
--- a/crates/openhuman-core/src/inference/tokenjuice/mod.rs
+++ b/crates/openhuman-core/src/inference/tokenjuice/mod.rs
@@ -379,6 +379,14 @@ pub async fn detect(
let config = crate::config::Config::load_or_init()
.await
.map_err(|error| error.to_string())?;
+ detect_with_config(&config, content, hint).await
+}
+
+async fn detect_with_config(
+ config: &crate::config::Config,
+ content: String,
+ hint: tinyjuice_bus::types::ContentHint,
+) -> Result<String, String> {
client(&config)
.call("tinyjuice", methods::DETECT, (content, hint))
.await
@@ -392,6 +400,14 @@ pub async fn compress(
let config = crate::config::Config::load_or_init()
.await
.map_err(|error| error.to_string())?;
+ compress_with_config(&config, content, hint).await
+}
+
+async fn compress_with_config(
+ config: &crate::config::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)
.call("tinyjuice", methods::COMPRESS, (content, hint))
@@ -414,6 +430,14 @@ pub async fn retrieve(
let config = crate::config::Config::load_or_init()
.await
.map_err(|error| error.to_string())?;
+ retrieve_with_config(&config, token, range).await
+}
+
+async fn retrieve_with_config(
+ config: &crate::config::Config,
+ token: String,
+ range: Option<tinyjuice_bus::wire::RetrieveRange>,
+) -> Result<Option<String>, String> {
install_from_config(&config).await?;
client(&config)
.call("tinyjuice", methods::RETRIEVE, (token, range))
@@ -425,6 +449,12 @@ pub async fn cache_stats() -> Result<tinyjuice_bus::wire::CacheStats, String> {
let config = crate::config::Config::load_or_init()
.await
.map_err(|error| error.to_string())?;
+ cache_stats_with_config(&config).await
+}
+
+async fn cache_stats_with_config(
+ config: &crate::config::Config,
+) -> Result<tinyjuice_bus::wire::CacheStats, String> {
install_from_config(&config).await?;
client(&config)
.call("tinyjuice", methods::CACHE_STATS, ())
diff --git a/crates/openhuman-core/src/inference/tokenjuice/schemas.rs b/crates/openhuman-core/src/inference/tokenjuice/schemas.rs
index 187579a915..3d69437adc 100644
--- a/crates/openhuman-core/src/inference/tokenjuice/schemas.rs
+++ b/crates/openhuman-core/src/inference/tokenjuice/schemas.rs
@@ -288,7 +288,8 @@ fn handle_detect(ctx: DispatchCtx, params: Map<String, Value>) -> ControllerFutu
extension: str_param(&params, "extension"),
..Default::default()
};
- let kind = super::detect(content, hint).await?;
+ let config = ctx.load_config().await?;
+ let kind = super::detect_with_config(&config, content, hint).await?;
Ok(serde_json::json!({ "kind": kind }))
})
}
@@ -333,7 +334,8 @@ fn handle_compress(ctx: DispatchCtx, params: Map<String, Value>) -> ControllerFu
gate(&ctx)?;
let content = str_param(&params, "content").ok_or("missing 'content'")?;
let hint = compress_hint_from_params(&params)?;
- let res = super::compress(content, hint).await?;
+ let config = ctx.load_config().await?;
+ let res = super::compress_with_config(&config, content, hint).await?;
Ok(serde_json::json!({
"applied": res.applied,
"kind": res.content_kind.as_str(),
@@ -350,7 +352,8 @@ fn handle_compress(ctx: DispatchCtx, params: Map<String, Value>) -> ControllerFu
fn handle_cache_stats(ctx: DispatchCtx, _params: Map<String, Value>) -> ControllerFuture {
Box::pin(async move {
gate(&ctx)?;
- let stats = super::cache_stats().await?;
+ let config = ctx.load_config().await?;
+ let stats = super::cache_stats_with_config(&config).await?;
Ok(serde_json::json!({ "entries": stats.entries, "bytes": stats.bytes }))
})
}
@@ -359,7 +362,8 @@ fn handle_retrieve(ctx: DispatchCtx, params: Map<String, Value>) -> ControllerFu
Box::pin(async move {
gate(&ctx)?;
let token = str_param(&params, "token").ok_or("missing 'token'")?;
- match super::retrieve(token, None).await? {
+ let config = ctx.load_config().await?;
+ match super::retrieve_with_config(&config, token, None).await? {
Some(content) => Ok(serde_json::json!({ "found": true, "content": content })),
None => Ok(serde_json::json!({ "found": false, "content": Value::Null })),
}