Skip to content

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

feat(tools): add presentation tool and harden shell and update apply

Steven Enamakel110992d8e6c4
diff --git a/crates/openhuman-core/src/tools/impl/presentation/mod.rs b/crates/openhuman-core/src/tools/impl/presentation/mod.rs
index c946ebdd5d..cc301ee3ec 100644
--- a/crates/openhuman-core/src/tools/impl/presentation/mod.rs
+++ b/crates/openhuman-core/src/tools/impl/presentation/mod.rs
@@ -74,6 +74,7 @@ trait ImageInspector: Sync {
struct ModuleImageInspector<'a> {
config: Option<&'a crate::config::Config>,
+ ctx: &'a DispatchCtx,
}
#[async_trait]
@@ -83,7 +84,8 @@ impl ImageInspector for ModuleImageInspector<'_> {
let config = match self.config {
Some(config) => config,
None => {
- loaded = DispatchCtx::ambient()
+ loaded = self
+ .ctx
.load_config()
.await
.map_err(|error| format!("config unavailable: {error}"))?;
@@ -291,7 +293,7 @@ impl Tool for PresentationTool {
}
async fn execute(&self, args: Value) -> anyhow::Result<ToolResult> {
- self.run(args, None).await
+ self.run(args, None, &dispatch_ctx_for_tool(None)).await
}
async fn execute_with_context(
@@ -301,7 +303,8 @@ impl Tool for PresentationTool {
context: Option<&dyn tinytools::ToolRunContext>,
) -> anyhow::Result<ToolResult> {
let approval = crate::agent::tinyagents::host::run_context::approval_for_tool(context);
- self.run(args, approval.chat.as_ref()).await
+ self.run(args, approval.chat.as_ref(), &dispatch_ctx_for_tool(context))
+ .await
}
}
@@ -312,6 +315,7 @@ impl PresentationTool {
&self,
args: Value,
chat: Option<&crate::security::approval::ApprovalChatContext>,
+ ctx: &DispatchCtx,
) -> anyhow::Result<ToolResult> {
let input: GeneratePresentationInput = match serde_json::from_value(args.clone()) {
Ok(v) => v,
@@ -338,7 +342,7 @@ impl PresentationTool {
// Resolve + validate per-slide images at the async boundary. A
// bad image is skipped with a warning (partial success) rather
// than failing the whole deck — mirrors the #3076 ethos.
- let (resolved_images, image_warnings) = self.resolve_images(&input).await;
+ let (resolved_images, image_warnings) = self.resolve_images(&input, ctx).await;
if !image_warnings.is_empty() {
tracing::info!(
target: "presentation",
@@ -498,11 +502,13 @@ impl PresentationTool {
async fn resolve_images(
&self,
input: &GeneratePresentationInput,
+ ctx: &DispatchCtx,
) -> (Vec<Vec<SlideImage>>, Vec<String>) {
self.resolve_images_with_inspector(
input,
&ModuleImageInspector {
config: self.config.as_ref(),
+ ctx,
},
)
.await
diff --git a/crates/openhuman-core/src/tools/impl/presentation/presentation_tests.rs b/crates/openhuman-core/src/tools/impl/presentation/presentation_tests.rs
index edb7721ea7..b0cc052280 100644
--- a/crates/openhuman-core/src/tools/impl/presentation/presentation_tests.rs
+++ b/crates/openhuman-core/src/tools/impl/presentation/presentation_tests.rs
@@ -356,7 +356,7 @@ async fn image_inspection_does_not_fall_back_when_modules_are_disabled() {
.expect("parse presentation input");
validate_input(&input).expect("valid presentation input");
- let (resolved, warnings) = tool.resolve_images(&input).await;
+ let (resolved, warnings) = tool.resolve_images(&input, &DispatchCtx::ambient()).await;
assert!(resolved.iter().all(Vec::is_empty));
assert_eq!(warnings.len(), 1);
assert!(warnings[0].contains("disabled"), "{warnings:?}");
@@ -380,7 +380,7 @@ async fn execute_skips_oversize_image_with_warning() {
}]
});
let input: GeneratePresentationInput = serde_json::from_value(args).expect("args parse");
- let (resolved, warnings) = tool.resolve_images(&input).await;
+ let (resolved, warnings) = tool.resolve_images(&input, &DispatchCtx::ambient()).await;
assert!(
resolved.iter().all(Vec::is_empty),
"a rejected image must not reach the deck"
@@ -406,7 +406,7 @@ async fn execute_skips_missing_artifact_with_warning() {
}]
});
let input: GeneratePresentationInput = serde_json::from_value(args).expect("args parse");
- let (resolved, warnings) = tool.resolve_images(&input).await;
+ let (resolved, warnings) = tool.resolve_images(&input, &DispatchCtx::ambient()).await;
assert!(
resolved.iter().all(Vec::is_empty),
"a rejected image must not reach the deck"
diff --git a/crates/openhuman-core/src/tools/impl/system/shell.rs b/crates/openhuman-core/src/tools/impl/system/shell.rs
index d4090d3fdd..a20826e399 100644
--- a/crates/openhuman-core/src/tools/impl/system/shell.rs
+++ b/crates/openhuman-core/src/tools/impl/system/shell.rs
@@ -264,7 +264,7 @@ impl Tool for ShellTool {
}
async fn execute(&self, args: serde_json::Value) -> anyhow::Result<ToolResult> {
- self.execute_in_context(&DispatchCtx::ambient(), args, None)
+ self.execute_in_context(&dispatch_ctx_for_tool(None), args, None)
.await
}
@@ -274,7 +274,7 @@ impl Tool for ShellTool {
_options: ToolCallOptions,
context: Option<&dyn ToolRunContext>,
) -> anyhow::Result<ToolResult> {
- self.execute_in_context(&DispatchCtx::ambient(), args, context)
+ self.execute_in_context(&dispatch_ctx_for_tool(context), args, context)
.await
}
}
diff --git a/crates/openhuman-core/src/tools/impl/system/update_apply.rs b/crates/openhuman-core/src/tools/impl/system/update_apply.rs
index 69a1ef0af1..ad0e8a40e9 100644
--- a/crates/openhuman-core/src/tools/impl/system/update_apply.rs
+++ b/crates/openhuman-core/src/tools/impl/system/update_apply.rs
@@ -19,6 +19,7 @@
//! high impact (replaces a binary on disk, optionally restarts the core
//! process) and must not happen silently.
+use crate::agent::tinyagents::host::run_context::dispatch_ctx_for_tool;
use crate::core::runtime::DispatchCtx;
use std::sync::Arc;
@@ -106,6 +107,21 @@ impl Tool for UpdateApplyTool {
}
async fn execute(&self, args: Value) -> anyhow::Result<ToolResult> {
+ self.run(args, &dispatch_ctx_for_tool(None)).await
+ }
+
+ async fn execute_with_context(
+ &self,
+ args: Value,
+ _options: tinytools::ToolCallOptions,
+ context: Option<&dyn tinytools::ToolRunContext>,
+ ) -> anyhow::Result<ToolResult> {
+ self.run(args, &dispatch_ctx_for_tool(context)).await
+ }
+}
+
+impl UpdateApplyTool {
+ async fn run(&self, args: Value, ctx: &DispatchCtx) -> anyhow::Result<ToolResult> {
tracing::debug!(args = %args, "[update_apply] execute start");
if let Some(blocked) = Self::require_consent(&args) {
@@ -117,7 +133,7 @@ impl Tool for UpdateApplyTool {
return Ok(blocked);
}
- let outcome = update::rpc::update_run(&DispatchCtx::ambient()).await;
+ let outcome = update::rpc::update_run(ctx).await;
for log in &outcome.logs {
tracing::debug!(target: "update_apply", "{log}");
}