Skip to content

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

refactor(media): tidy artifact tool wiring and imports

Steven Enamakel370f3efd1707
diff --git a/crates/openhuman-core/src/media/generation/artifact_tool.rs b/crates/openhuman-core/src/media/generation/artifact_tool.rs
index 7da9c48f4e..dd63462a1c 100644
--- a/crates/openhuman-core/src/media/generation/artifact_tool.rs
+++ b/crates/openhuman-core/src/media/generation/artifact_tool.rs
@@ -11,7 +11,7 @@ use async_trait::async_trait;
use serde_json::{json, Value};
use tinyagents_harness_tools::media::{
ArtifactFiling, FiledArtifact, GeneratedArtifact, MediaArtifactKind,
- MediaInnerFactory, MediaJobProgress, MediaProgressFn,
+ MediaInnerFactory,
};
use tinytools::{
PermissionLevel, Tool, ToolCallOptions, ToolCategory, ToolPolicy, ToolResult, ToolRunContext,
@@ -21,7 +21,6 @@ use tokio::io::AsyncWriteExt;
use crate::artifacts::production::Production;
use crate::artifacts::ArtifactKind;
-use crate::security::approval::ApprovalChatContext;
/// A host adapter that retains OpenHuman artifact behavior while delegating
/// generic media result handling to TinyAgents' harness-tools crate.
@@ -102,7 +101,6 @@ impl<T: Tool> MediaArtifactTool<T> {
ReferenceRefreshTool::new(build(progress, context), Arc::clone(&policy))
}));
Self { inner, policy }
- self
}
}
@@ -300,14 +298,12 @@ impl OpenHumanArtifactFiling {
source: &Path,
) -> Result<u64, String> {
let size = production.complete().await?;
- self.delete_blob_after_finalize(
- &self
- .0
- .read()
- .unwrap_or_else(std::sync::PoisonError::into_inner),
- source,
- )
- .await;
+ let policy = self
+ .0
+ .read()
+ .unwrap_or_else(std::sync::PoisonError::into_inner)
+ .clone();
+ self.delete_blob_after_finalize(&policy, source).await;
Ok(size)
}
@@ -340,10 +336,7 @@ struct ReferenceRefreshTool<T: Tool> {
}
impl<T: Tool> ReferenceRefreshTool<T> {
- fn new(
- inner: T,
- policy: Arc<RwLock<MediaArtifactPolicy>>,
- ) -> Self {
+ fn new(inner: T, policy: Arc<RwLock<MediaArtifactPolicy>>) -> Self {
Self { inner, policy }
}
@@ -411,19 +404,45 @@ impl<T: Tool> ReferenceRefreshTool<T> {
#[async_trait]
impl<T: Tool> Tool for ReferenceRefreshTool<T> {
- fn name(&self) -> &str { self.inner.name() }
- fn description(&self) -> &str { self.inner.description() }
- fn parameters_schema(&self) -> Value { self.inner.parameters_schema() }
- fn policy(&self) -> ToolPolicy { self.inner.policy() }
- fn permission_level(&self) -> PermissionLevel { self.inner.permission_level() }
- fn permission_level_with_args(&self, args: &Value) -> PermissionLevel { self.inner.permission_level_with_args(args) }
- fn scope(&self) -> ToolScope { self.inner.scope() }
- fn category(&self) -> ToolCategory { self.inner.category() }
- fn external_effect(&self) -> bool { self.inner.external_effect() }
- fn external_effect_with_args(&self, args: &Value) -> bool { self.inner.external_effect_with_args(args) }
- fn timeout_policy(&self, args: &Value) -> ToolTimeout { self.inner.timeout_policy(args) }
- fn supports_markdown(&self) -> bool { self.inner.supports_markdown() }
- fn max_result_size_chars(&self) -> Option<usize> { self.inner.max_result_size_chars() }
+ fn name(&self) -> &str {
+ self.inner.name()
+ }
+ fn description(&self) -> &str {
+ self.inner.description()
+ }
+ fn parameters_schema(&self) -> Value {
+ self.inner.parameters_schema()
+ }
+ fn policy(&self) -> ToolPolicy {
+ self.inner.policy()
+ }
+ fn permission_level(&self) -> PermissionLevel {
+ self.inner.permission_level()
+ }
+ fn permission_level_with_args(&self, args: &Value) -> PermissionLevel {
+ self.inner.permission_level_with_args(args)
+ }
+ fn scope(&self) -> ToolScope {
+ self.inner.scope()
+ }
+ fn category(&self) -> ToolCategory {
+ self.inner.category()
+ }
+ fn external_effect(&self) -> bool {
+ self.inner.external_effect()
+ }
+ fn external_effect_with_args(&self, args: &Value) -> bool {
+ self.inner.external_effect_with_args(args)
+ }
+ fn timeout_policy(&self, args: &Value) -> ToolTimeout {
+ self.inner.timeout_policy(args)
+ }
+ fn supports_markdown(&self) -> bool {
+ self.inner.supports_markdown()
+ }
+ fn max_result_size_chars(&self) -> Option<usize> {
+ self.inner.max_result_size_chars()
+ }
async fn execute(&self, args: Value) -> anyhow::Result<ToolResult> {
self.execute_with_context(args, ToolCallOptions::default(), None).await
diff --git a/crates/openhuman-core/src/media/generation/tools.rs b/crates/openhuman-core/src/media/generation/tools.rs
index fc5397782a..807b1fa25e 100644
--- a/crates/openhuman-core/src/media/generation/tools.rs
+++ b/crates/openhuman-core/src/media/generation/tools.rs
@@ -16,6 +16,7 @@ use serde_json::{json, Value};
use tinyagents_harness::media::{GenerateImageTool, GenerateVideoTool, MediaOutput};
use tinyagents_harness::tinyinference_image::ImageGenerator;
use tinyagents_harness::tinyinference_video::{VideoGenerator, WaitPolicy};
+use tinyagents_harness_tools::media::MediaJobProgress;
use tinytools::{PermissionLevel, Tool, ToolCategory, ToolResult};
use super::artifact_tool::MediaArtifactTool;
@@ -132,8 +133,10 @@ fn media_tools_from_with_allowlist(
.with_per_call_inner({
let generators = Arc::clone(&generators);
let output = output.clone();
- move |_observer, chat| {
- let routed = generators.routed(chat);
+ move |_observer, context| {
+ let approval =
+ crate::agent::tinyagents::host::run_context::approval_for_tool(context);
+ let routed = generators.routed(approval.chat.as_ref());
GenerateImageTool::new(routed.image, output.clone())
.with_name(IMAGE_TOOL_NAME)
.with_description(IMAGE_DESCRIPTION)
@@ -154,8 +157,20 @@ fn media_tools_from_with_allowlist(
.with_per_call_inner({
let generators = Arc::clone(&generators);
let output = output.clone();
- move |observer, chat| {
- let routed = generators.routed(chat);
+ move |progress, context| {
+ let approval =
+ crate::agent::tinyagents::host::run_context::approval_for_tool(context);
+ let routed = generators.routed(approval.chat.as_ref());
+ let observer = Arc::new(move |status: &tinyagents_harness::tinyinference_video::VideoJobStatus| {
+ progress(&MediaJobProgress {
+ id: status.id.clone(),
+ state: status.state.to_string(),
+ outputs: status.outputs,
+ output_indices: status.output_indices.clone(),
+ cost_usd: status.cost_usd,
+ error: status.error.clone(),
+ });
+ });
video_tool(
&routed.video,
&output,