The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
refactor(media): remove local download logic and inline types in favour of tinyagents-harness
Steven Enamakele4069686ac5b
diff --git a/crates/openhuman-core/Cargo.toml b/crates/openhuman-core/Cargo.tomlindex 583a22904a..9686077d7b 100644--- a/crates/openhuman-core/Cargo.toml+++ b/crates/openhuman-core/Cargo.toml@@ -999,16 +999,17 @@ runtime-node = []# and removing it from one without the other fails that lane.contacts = []# Media-generation + image domains: the `media_generate_*` agent tools-# (image/video via GMI through the backend) and the `openhuman::image` tool+# (image/video via OpenRouter through the backend's+# `/agent-integrations/openrouter` proxy) and the `openhuman::image` tool# contracts scaffold. Default-ON. Slim builds opt out via# `--no-default-features --features "<explicit list without media>"`.# Composes with the runtime `DomainSet::media` flag (#4796).-# NOTE: this gate sheds no exclusive dependencies — media generation is-# backend-proxied (reqwest, shared). It is a surface-only gate (drops the tool-# code + module from the compile), not a dependency-shedding one. There are no-# controllers / stores / subscribers tagged `Media` (agent tools only), and-# `openhuman::image` is currently unwired scaffold (added #2997).-media = []+# Enables `tinyagents-harness/media`, which pulls in `tinyinference-image` and+# `tinyinference-video` (the wire contract, job loop and generic tools); both+# are light (serde + the already-shared reqwest), so this remains mostly a+# surface gate. There are no controllers / stores / subscribers tagged `Media`+# (agent tools only), and `openhuman::image` is currently unwired scaffold.+media = ["tinyagents-harness/media"]# Flows domains: the `flows::` automation surface (saved tinyflows graphs —# create/run/schedule + the workflow_builder / flow_discovery agents), the# `tinyflows::` adapter seam, and the `rhai_workflows::` language-workflow tool.diff --git a/crates/openhuman-core/src/media/generation/download.rs b/crates/openhuman-core/src/media/generation/download.rsdeleted file mode 100644index c7ca9e1165..0000000000--- a/crates/openhuman-core/src/media/generation/download.rs+++ /dev/null@@ -1,149 +0,0 @@-//! Persist generated media to the agent's action directory.-//!-//! GMI returns expiring signed URLs; we download the bytes and write them under-//! a `generated-media/` root inside `action_dir` so final answers can reference-//! a stable local file path (per the `image_generation` contract). The action-//! directory is the agent's canonical read/write root.--use std::path::{Path, PathBuf};--use anyhow::{Context, Result};--use super::types::MediaItem;--/// Subdirectory (under `action_dir`) where generated artifacts are stored.-const GENERATED_MEDIA_DIR: &str = "generated-media";--/// A downloaded artifact and where it landed on disk.-#[derive(Debug, Clone)]-pub struct PersistedArtifact {- pub kind: String,- pub path: PathBuf,- pub source_url: String,- pub thumbnail_url: Option<String>,-}--/// Pick a file extension from the artifact kind + content type / URL.-fn extension_for(kind: &str, content_type: Option<&str>, url: &str) -> String {- if let Some(ct) = content_type {- let ct = ct.to_ascii_lowercase();- if ct.contains("png") {- return "png".to_string();- }- if ct.contains("webp") {- return "webp".to_string();- }- if ct.contains("jpeg") || ct.contains("jpg") {- return "jpg".to_string();- }- if ct.contains("mp4") {- return "mp4".to_string();- }- if ct.contains("webm") {- return "webm".to_string();- }- }- // Fall back to the URL path suffix, then a per-kind default.- let lower = url.split('?').next().unwrap_or(url).to_ascii_lowercase();- for ext in ["png", "webp", "jpg", "jpeg", "mp4", "webm"] {- if lower.ends_with(&format!(".{ext}")) {- return if ext == "jpeg" {- "jpg".to_string()- } else {- ext.to_string()- };- }- }- if kind.eq_ignore_ascii_case("video") {- "mp4".to_string()- } else {- "png".to_string()- }-}--/// Download a single media URL into `dir`, returning the written path.-async fn download_one(- http: &reqwest::Client,- dir: &Path,- item: &MediaItem,- request_id: &str,- index: usize,-) -> Result<PersistedArtifact> {- tracing::info!(- "[media_generation] downloading {} artifact {} for request={}",- item.kind,- index,- request_id- );- let resp = http- .get(&item.url)- .send()- .await- .with_context(|| format!("failed to fetch generated media from {}", item.url))?- .error_for_status()- .with_context(|| format!("generated media URL returned an error: {}", item.url))?;-- let content_type = resp- .headers()- .get(reqwest::header::CONTENT_TYPE)- .and_then(|v| v.to_str().ok())- .map(|s| s.to_string());- let ext = extension_for(&item.kind, content_type.as_deref(), &item.url);-- let bytes = resp- .bytes()- .await- .with_context(|| format!("failed to read generated media body from {}", item.url))?;-- // Sanitize the request id for use in a filename (it is a UUID from GMI, but- // be defensive against path separators).- let safe_id: String = request_id- .chars()- .map(|c| {- if c.is_ascii_alphanumeric() || c == '-' {- c- } else {- '_'- }- })- .collect();- let filename = format!("{safe_id}-{index}.{ext}");- let path = dir.join(&filename);- tokio::fs::write(&path, &bytes)- .await- .with_context(|| format!("failed to write generated media to {}", path.display()))?;-- Ok(PersistedArtifact {- kind: item.kind.clone(),- path,- source_url: item.url.clone(),- thumbnail_url: item.thumbnail_url.clone(),- })-}--/// Download + persist all media items for a request under-/// `{action_dir}/generated-media/`. Returns the written artifacts.-pub async fn persist_media(- action_dir: &Path,- request_id: &str,- items: &[MediaItem],-) -> Result<Vec<PersistedArtifact>> {- if items.is_empty() {- return Ok(Vec::new());- }- let dir = action_dir.join(GENERATED_MEDIA_DIR);- tokio::fs::create_dir_all(&dir)- .await- .with_context(|| format!("failed to create generated-media dir {}", dir.display()))?;-- let http = reqwest::Client::new();- let mut out = Vec::with_capacity(items.len());- for (i, item) in items.iter().enumerate() {- out.push(download_one(&http, &dir, item, request_id, i).await?);- }- Ok(out)-}--#[cfg(test)]-#[path = "download_tests.rs"]-mod tests;diff --git a/crates/openhuman-core/src/media/generation/download_tests.rs b/crates/openhuman-core/src/media/generation/download_tests.rsdeleted file mode 100644index b1f2539f3d..0000000000--- a/crates/openhuman-core/src/media/generation/download_tests.rs+++ /dev/null@@ -1,27 +0,0 @@-use super::*;--#[test]-fn extension_prefers_content_type() {- assert_eq!(- extension_for("image", Some("image/png"), "https://x/y"),- "png"- );- assert_eq!(- extension_for("image", Some("image/webp"), "https://x/y"),- "webp"- );- assert_eq!(- extension_for("video", Some("video/mp4"), "https://x/y"),- "mp4"- );-}--#[test]-fn extension_falls_back_to_url_then_kind() {- assert_eq!(- extension_for("image", None, "https://x/y/a.webp?sig=1"),- "webp"- );- assert_eq!(extension_for("video", None, "https://x/y/clip"), "mp4");- assert_eq!(extension_for("image", None, "https://x/y/clip"), "png");-}diff --git a/crates/openhuman-core/src/media/generation/mod.rs b/crates/openhuman-core/src/media/generation/mod.rsindex 931461f004..1e6a8f2d12 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, MediaListModelsTool, IMAGE_TOOL_NAME, LIST_MODELS_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/tools.rs b/crates/openhuman-core/src/media/generation/tools.rsindex 5dab7d5f2b..da5cd89cb8 100644--- a/crates/openhuman-core/src/media/generation/tools.rs+++ b/crates/openhuman-core/src/media/generation/tools.rs@@ -45,11 +45,22 @@ const VIDEO_DESCRIPTION: &str = "Generate a short video clip via OpenRouter (def/// Registers the media tools, or nothing when no backend is reachable.pub fn build_media_tools(root_config: &Config, action_dir: &Path) -> Vec<Box<dyn Tool>> {- let Some(MediaGenerators { image, video }) = managed_generators(root_config) else {+ let Some(generators) = managed_generators(root_config) else {return Vec::new();};+ media_tools_from(generators, action_dir, &root_config.workspace_dir)+}++/// Builds the tool set over any generators (the managed ones in production,+/// mocks in tests), writing under `action_dir`.+pub fn media_tools_from(+ generators: MediaGenerators,+ action_dir: &Path,+ workspace_dir: &Path,+) -> Vec<Box<dyn Tool>> {+ let MediaGenerators { image, video } = generators;let output = MediaOutput::new(action_dir)- .with_reference_policy(reference_policy(action_dir, &root_config.workspace_dir));+ .with_reference_policy(reference_policy(action_dir, workspace_dir));let tools: Vec<Box<dyn Tool>> = vec![Box::new(GenerateImageTool::new(Arc::clone(&image), output.clone())diff --git a/crates/openhuman-core/src/media/generation/types.rs b/crates/openhuman-core/src/media/generation/types.rsdeleted file mode 100644index be15591fbf..0000000000--- a/crates/openhuman-core/src/media/generation/types.rs+++ /dev/null@@ -1,47 +0,0 @@-//! Shared types for the `media_generation` agent tools.-//!-//! These mirror the backend's standardized `media_generation` contract-//! (`/agent-integrations/media-generation/*`) — see-//! `backend/docs/media-generation.md`. The backend normalizes GMI's per-model-//! payload/outcome shapes; the core only depends on this stable envelope.--use serde::Deserialize;--/// A single generated artifact as returned by the backend. The `url` is an-/// expiring signed URL — the core downloads + persists it locally.-#[derive(Debug, Clone, Deserialize)]-pub struct MediaItem {- #[serde(rename = "type")]- pub kind: String,- pub url: String,- #[serde(rename = "thumbnailUrl", default)]- pub thumbnail_url: Option<String>,-}--/// Standardized media-generation response envelope.-#[derive(Debug, Clone, Deserialize)]-pub struct MediaResponse {- #[serde(rename = "requestId")]- pub request_id: String,- pub status: String,- #[serde(default)]- pub model: String,- #[serde(default)]- pub media: Vec<MediaItem>,- #[serde(rename = "costUsd", default)]- pub cost_usd: f64,-}--impl MediaResponse {- pub fn is_success(&self) -> bool {- self.status.eq_ignore_ascii_case("success")- }-- pub fn is_failed(&self) -> bool {- self.status.eq_ignore_ascii_case("failed")- }-- pub fn is_terminal(&self) -> bool {- self.is_success() || self.is_failed()- }-}