Skip to content

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

chore: reformat long lines and improve error handling in media generation tools

Steven Enamakelad41667be8b0
diff --git a/crates/openhuman-core/src/media/generation/mod.rs b/crates/openhuman-core/src/media/generation/mod.rs
index 1e6a8f2d12..d771ce074c 100644
--- a/crates/openhuman-core/src/media/generation/mod.rs
+++ b/crates/openhuman-core/src/media/generation/mod.rs
@@ -19,6 +19,6 @@ pub mod tools;
pub use provider::{managed_generators, MediaGenerators, OPENROUTER_PROXY_PATH};
pub use tools::{
- build_media_tools, media_tools_from, MediaListModelsTool, IMAGE_TOOL_NAME, LIST_MODELS_TOOL_NAME,
- VIDEO_TOOL_NAME,
+ build_media_tools, media_tools_from, MediaListModelsTool, IMAGE_TOOL_NAME,
+ LIST_MODELS_TOOL_NAME, VIDEO_TOOL_NAME,
};
diff --git a/crates/openhuman-core/src/media/generation/provider.rs b/crates/openhuman-core/src/media/generation/provider.rs
index fc0aba7919..4a254e765d 100644
--- a/crates/openhuman-core/src/media/generation/provider.rs
+++ b/crates/openhuman-core/src/media/generation/provider.rs
@@ -31,7 +31,9 @@ use tinyagents_harness::tinyinference_video::{
use crate::api::config::effective_backend_api_url;
use crate::api::BackendOAuthClient;
use crate::config::Config;
-use crate::security::credentials::session_support::{resolve_backend_credential, BackendCredential};
+use crate::security::credentials::session_support::{
+ resolve_backend_credential, BackendCredential,
+};
/// Backend route prefix that proxies OpenRouter's media API.
pub const OPENROUTER_PROXY_PATH: &str = "/agent-integrations/openrouter";
@@ -118,7 +120,8 @@ impl Guard {
/// Refuses a billed submit when managed credits are exhausted.
async fn budget(&self) -> ti_image::Result<()> {
- if crate::integrations::client::budget_gate::managed_tool_budget_exhausted(&self.config).await
+ if crate::integrations::client::budget_gate::managed_tool_budget_exhausted(&self.config)
+ .await
{
tracing::info!("[media_generation] managed credits exhausted; submit refused");
return Err(ti_image::Error::Validation(
diff --git a/crates/openhuman-core/src/media/generation/tools.rs b/crates/openhuman-core/src/media/generation/tools.rs
index ae7b8f98bb..33eaa6da5e 100644
--- a/crates/openhuman-core/src/media/generation/tools.rs
+++ b/crates/openhuman-core/src/media/generation/tools.rs
@@ -100,10 +100,16 @@ pub(crate) fn reference_policy(
let roots: Vec<PathBuf> = vec![action_dir.to_path_buf(), workspace_dir.to_path_buf()];
Arc::new(move |path: &Path| {
if path.components().any(|c| matches!(c, Component::ParentDir)) {
- return Err(format!("reference path {} may not contain '..'", path.display()));
+ return Err(format!(
+ "reference path {} may not contain '..'",
+ path.display()
+ ));
}
if crate::security::SecurityPolicy::is_always_forbidden(path) {
- return Err(format!("reference path {} is in a protected location", path.display()));
+ return Err(format!(
+ "reference path {} is in a protected location",
+ path.display()
+ ));
}
if !roots.iter().any(|root| path.starts_with(root)) {
return Err(format!(
@@ -172,9 +178,16 @@ impl Tool for MediaListModelsTool {
.filter(|m| keep(&m.id, m.name.as_deref()))
.map(|m| json!({ "id": m.id, "name": m.name }))
.collect();
- out.insert("image".into(), json!({ "default": self.image.default_model(), "models": list }));
+ out.insert(
+ "image".into(),
+ json!({ "default": self.image.default_model(), "models": list }),
+ );
+ }
+ Err(error) => {
+ return Ok(ToolResult::error(format!(
+ "Listing image models failed: {error}"
+ )))
}
- Err(error) => return Ok(ToolResult::error(format!("Listing image models failed: {error}"))),
}
}
if kind != "image" {
@@ -185,9 +198,16 @@ impl Tool for MediaListModelsTool {
.filter(|m| keep(&m.id, m.name.as_deref()))
.map(|m| json!({ "id": m.id, "name": m.name }))
.collect();
- out.insert("video".into(), json!({ "default": self.video.default_model(), "models": list }));
+ out.insert(
+ "video".into(),
+ json!({ "default": self.video.default_model(), "models": list }),
+ );
+ }
+ Err(error) => {
+ return Ok(ToolResult::error(format!(
+ "Listing video models failed: {error}"
+ )))
}
- Err(error) => return Ok(ToolResult::error(format!("Listing video models failed: {error}"))),
}
}
Ok(ToolResult::json(Value::Object(out)))
diff --git a/crates/openhuman-core/src/media/generation/tools_tests.rs b/crates/openhuman-core/src/media/generation/tools_tests.rs
index f4bfe4fe62..b0a5355c72 100644
--- a/crates/openhuman-core/src/media/generation/tools_tests.rs
+++ b/crates/openhuman-core/src/media/generation/tools_tests.rs
@@ -6,7 +6,9 @@ use tinyagents_harness::tinyinference_image::MockImageGenerator;
use tinyagents_harness::tinyinference_video::{MockVideoGenerator, MockVideoScript};
use tinytools::{PermissionLevel, Tool, ToolCategory};
-use super::{media_tools_from, reference_policy, IMAGE_TOOL_NAME, LIST_MODELS_TOOL_NAME, VIDEO_TOOL_NAME};
+use super::{
+ media_tools_from, reference_policy, IMAGE_TOOL_NAME, LIST_MODELS_TOOL_NAME, VIDEO_TOOL_NAME,
+};
use crate::media::generation::MediaGenerators;
fn tools(action_dir: &Path) -> Vec<Box<dyn Tool>> {
@@ -39,10 +41,17 @@ fn tool_names_match_the_media_pack() {
let dir = tempfile::tempdir().unwrap();
let tools = tools(dir.path());
let names: Vec<&str> = tools.iter().map(|tool| tool.name()).collect();
- assert_eq!(names, vec![IMAGE_TOOL_NAME, VIDEO_TOOL_NAME, LIST_MODELS_TOOL_NAME]);
assert_eq!(
names,
- vec!["media_generate_image", "media_generate_video", "media_list_models"]
+ vec![IMAGE_TOOL_NAME, VIDEO_TOOL_NAME, LIST_MODELS_TOOL_NAME]
+ );
+ assert_eq!(
+ names,
+ vec![
+ "media_generate_image",
+ "media_generate_video",
+ "media_list_models"
+ ]
);
}
@@ -67,12 +76,36 @@ fn schemas_expose_the_reference_standards() {
let tools = tools(dir.path());
let image = by_name(&tools, IMAGE_TOOL_NAME).parameters_schema();
assert_eq!(image["required"], json!(["prompt"]));
- for key in ["prompt", "model", "n", "aspect_ratio", "resolution", "size", "seed", "references"] {
- assert!(image["properties"].get(key).is_some(), "image schema missing {key}");
+ for key in [
+ "prompt",
+ "model",
+ "n",
+ "aspect_ratio",
+ "resolution",
+ "size",
+ "seed",
+ "references",
+ ] {
+ assert!(
+ image["properties"].get(key).is_some(),
+ "image schema missing {key}"
+ );
}
let video = by_name(&tools, VIDEO_TOOL_NAME).parameters_schema();
- for key in ["prompt", "duration", "resolution", "aspect_ratio", "first_frame", "last_frame", "references", "resume_job_id"] {
- assert!(video["properties"].get(key).is_some(), "video schema missing {key}");
+ for key in [
+ "prompt",
+ "duration",
+ "resolution",
+ "aspect_ratio",
+ "first_frame",
+ "last_frame",
+ "references",
+ "resume_job_id",
+ ] {
+ assert!(
+ video["properties"].get(key).is_some(),
+ "video schema missing {key}"
+ );
}
}
@@ -85,7 +118,9 @@ async fn image_tool_saves_under_generated_media_in_the_action_dir() {
.await
.unwrap();
assert!(!result.is_error, "{result:?}");
- let saved = std::fs::read_dir(dir.path().join("generated-media")).unwrap().count();
+ let saved = std::fs::read_dir(dir.path().join("generated-media"))
+ .unwrap()
+ .count();
assert_eq!(saved, 1);
}
@@ -98,7 +133,10 @@ async fn list_models_reports_both_catalogs_and_defaults() {
.await
.unwrap();
let text = serde_json::to_string(&result).unwrap();
- assert!(text.contains("mock/image") && text.contains("mock/video"), "{text}");
+ assert!(
+ text.contains("mock/image") && text.contains("mock/video"),
+ "{text}"
+ );
}
#[test]
@@ -112,5 +150,8 @@ fn reference_policy_admits_workspace_files_only() {
assert!(policy(&action.join("../secret.png")).is_err());
assert!(policy(Path::new("/etc/passwd")).is_err());
assert!(policy(Path::new("/home/user/Documents/private.png")).is_err());
- assert!(policy(&action.join(".ssh/id_rsa")).is_err(), "credential stores stay forbidden");
+ assert!(
+ policy(&action.join(".ssh/id_rsa")).is_err(),
+ "credential stores stay forbidden"
+ );
}
diff --git a/tests/media_generation_e2e.rs b/tests/media_generation_e2e.rs
index b29698edf5..6d8fddf64e 100644
--- a/tests/media_generation_e2e.rs
+++ b/tests/media_generation_e2e.rs
@@ -252,6 +252,12 @@ async fn media_tools_deliver_images_and_videos_through_the_backend_proxy() {
assert_eq!(auth, &format!("Bearer {API_KEY}"), "{route} credential");
assert!(*sdk_name, "{route} is missing x-sdk-name");
}
- let submits = requests.iter().filter(|(r, _, _)| r.starts_with("POST")).count();
- assert_eq!(submits, 2, "exactly one billed submit per tool call: {requests:?}");
+ let submits = requests
+ .iter()
+ .filter(|(r, _, _)| r.starts_with("POST"))
+ .count();
+ assert_eq!(
+ submits, 2,
+ "exactly one billed submit per tool call: {requests:?}"
+ );
}