Skip to content

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

feat(inference): add tokenjuice schema definitions

Steven Enamakel07db5e788d78
diff --git a/crates/openhuman-core/src/inference/tokenjuice/schemas.rs b/crates/openhuman-core/src/inference/tokenjuice/schemas.rs
index 251c5ffcf1..e1b731f099 100644
--- a/crates/openhuman-core/src/inference/tokenjuice/schemas.rs
+++ b/crates/openhuman-core/src/inference/tokenjuice/schemas.rs
@@ -265,12 +265,10 @@ pub fn schemas(function: &str) -> ControllerSchema {
// ── Handlers ─────────────────────────────────────────────────────────
/// Refuse with the typed `COMPONENT_DISABLED:juice` error while `[components]
-/// juice` is off. Read from the ambient core context (set at boot); a call with
-/// no context is on, since the set only narrows.
-fn gate() -> Result<(), String> {
- let on = crate::core::runtime::context::CoreContext::current()
- .is_none_or(|ctx| ctx.components().juice);
- if on {
+/// juice` is off for the context the call runs under; a call with no context
+/// is on, since the set only narrows.
+fn gate(ctx: &DispatchCtx) -> Result<(), String> {
+ if ctx.components().juice {
Ok(())
} else {
log::debug!("[tokenjuice][rpc] refused, component 'juice' disabled");
@@ -282,9 +280,9 @@ fn str_param(params: &Map<String, Value>, key: &str) -> Option<String> {
params.get(key).and_then(Value::as_str).map(str::to_string)
}
-fn handle_detect(_ctx: DispatchCtx, params: Map<String, Value>) -> ControllerFuture {
+fn handle_detect(ctx: DispatchCtx, params: Map<String, Value>) -> ControllerFuture {
Box::pin(async move {
- gate()?;
+ gate(&ctx)?;
let content = str_param(&params, "content").ok_or("missing 'content'")?;
let hint = ContentHint {
source_tool: str_param(&params, "tool_name"),
@@ -331,9 +329,9 @@ fn compress_hint_from_params(params: &Map<String, Value>) -> Result<ContentHint,
})
}
-fn handle_compress(_ctx: DispatchCtx, params: Map<String, Value>) -> ControllerFuture {
+fn handle_compress(ctx: DispatchCtx, params: Map<String, Value>) -> ControllerFuture {
Box::pin(async move {
- gate()?;
+ 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?;
@@ -350,17 +348,17 @@ fn handle_compress(_ctx: DispatchCtx, params: Map<String, Value>) -> ControllerF
})
}
-fn handle_cache_stats(_ctx: DispatchCtx, _params: Map<String, Value>) -> ControllerFuture {
+fn handle_cache_stats(ctx: DispatchCtx, _params: Map<String, Value>) -> ControllerFuture {
Box::pin(async move {
- gate()?;
+ gate(&ctx)?;
let stats = super::cache_stats().await?;
Ok(serde_json::json!({ "entries": stats.entries, "bytes": stats.bytes }))
})
}
-fn handle_retrieve(_ctx: DispatchCtx, params: Map<String, Value>) -> ControllerFuture {
+fn handle_retrieve(ctx: DispatchCtx, params: Map<String, Value>) -> ControllerFuture {
Box::pin(async move {
- gate()?;
+ gate(&ctx)?;
let token = str_param(&params, "token").ok_or("missing 'token'")?;
match super::retrieve(token, None).await? {
Some(content) => Ok(serde_json::json!({ "found": true, "content": content })),
@@ -371,7 +369,7 @@ fn handle_retrieve(_ctx: DispatchCtx, params: Map<String, Value>) -> ControllerF
fn handle_settings_get(ctx: DispatchCtx, _params: Map<String, Value>) -> ControllerFuture {
Box::pin(async move {
- gate()?;
+ gate(&ctx)?;
let config = ctx
.load_config()
.await
@@ -384,7 +382,7 @@ fn handle_settings_get(ctx: DispatchCtx, _params: Map<String, Value>) -> Control
fn handle_settings_update(ctx: DispatchCtx, params: Map<String, Value>) -> ControllerFuture {
Box::pin(async move {
- gate()?;
+ gate(&ctx)?;
// Accept either {"patch": {...}} or a bare object of fields.
let patch = params
.get("patch")
@@ -414,7 +412,7 @@ fn handle_settings_update(ctx: DispatchCtx, params: Map<String, Value>) -> Contr
fn handle_savings_stats(ctx: DispatchCtx, _params: Map<String, Value>) -> ControllerFuture {
Box::pin(async move {
- gate()?;
+ gate(&ctx)?;
let cache = super::cache_stats().await?;
let config = ctx.load_config().await.map_err(|e| e.to_string())?;
super::install_from_config(&config).await?;
@@ -431,7 +429,7 @@ fn handle_savings_stats(ctx: DispatchCtx, _params: Map<String, Value>) -> Contro
fn handle_savings_reset(ctx: DispatchCtx, _params: Map<String, Value>) -> ControllerFuture {
Box::pin(async move {
- gate()?;
+ gate(&ctx)?;
let config = ctx.load_config().await.map_err(|e| e.to_string())?;
super::install_from_config(&config).await?;
super::savings::reset(&super::client(&config)).await?;
diff --git a/crates/openhuman-core/src/modules/runtime.rs b/crates/openhuman-core/src/modules/runtime.rs
index 65088cdbfb..796fcb66b8 100644
--- a/crates/openhuman-core/src/modules/runtime.rs
+++ b/crates/openhuman-core/src/modules/runtime.rs
@@ -83,9 +83,8 @@ async fn install_callbacks(runtime: &'static ModuleRuntime) -> tinybus::Result<(
// The summary callback exists for the module alone; with the component off
// the module never loads, so nothing would call it.
- let juice_on = crate::core::runtime::context::CoreContext::current()
- .is_none_or(|ctx| ctx.components().juice);
- if juice_on {
+ let host = crate::core::runtime::DispatchCtx::host_default();
+ if host.components().juice {
super::tokenjuice_host::install(connection).await?;
} else {
tracing::debug!("[modules] juice component off; MlHost not served");
@@ -94,9 +93,7 @@ async fn install_callbacks(runtime: &'static ModuleRuntime) -> tinybus::Result<(
super::storage_host::install(connection, runtime.host()).await?;
#[cfg(feature = "tinymemes")]
{
- let memes_on = crate::core::runtime::context::CoreContext::current()
- .is_none_or(|ctx| ctx.components().memes);
- if memes_on {
+ if host.components().memes {
crate::tinymemes::service::install(connection).await?;
} else {
tracing::debug!("[modules] memes component off; Host callbacks not served");