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
feat(agent): add multimodal attachment handling tests
Steven Enamakelbfbc5faee4e3
diff --git a/crates/openhuman-core/src/agent/multimodal.rs b/crates/openhuman-core/src/agent/multimodal.rsindex 5e5b6061d9..b4dcce42d8 100644--- a/crates/openhuman-core/src/agent/multimodal.rs+++ b/crates/openhuman-core/src/agent/multimodal.rs@@ -100,10 +100,14 @@ fn remote_client() -> Client {////// Claims `application/pdf` and nothing else. The native module runs in the/// core process; a wait deadline does not cancel its blocking parser work.-pub struct DocumentsTextExtractor;+pub struct DocumentsTextExtractor<'a> {+ /// The context the extraction reads its config under.+ #[cfg_attr(not(feature = "documents"), allow(dead_code))]+ pub ctx: &'a DispatchCtx,+}#[async_trait]-impl TextExtractor for DocumentsTextExtractor {+impl TextExtractor for DocumentsTextExtractor<'_> {fn handles(&self, mime: &str) -> bool {mime == "application/pdf"}@@ -126,7 +130,7 @@ impl TextExtractor for DocumentsTextExtractor {use crate::modules::documents;match tokio::time::timeout(PDF_EXTRACTION_TIMEOUT, async {- let config = crate::config::ops::load_current_or_init(&DispatchCtx::ambient())+ let config = crate::config::ops::load_current_or_init(self.ctx).await.map_err(|error| format!("config unavailable for pdf extraction: {error}"))?;documents::extract_text(&config, bytes)@@ -197,6 +201,7 @@ fn latest_user_message(messages: &[TranscriptMessage]) -> Option<&TranscriptMess/// Counts are checked against the raw markers before any read happens: a cap/// enforced after the fetch is not a cap.pub async fn prepare_messages_for_provider(+ ctx: &DispatchCtx,messages: &[TranscriptMessage],image_config: &MultimodalConfig,file_config: &MultimodalFileConfig,@@ -295,7 +300,7 @@ pub async fn prepare_messages_for_provider(max_file_bytes,max_extracted_text_chars,&client,- &DocumentsTextExtractor,+ &DocumentsTextExtractor { ctx },).await?,);@@ -347,7 +352,11 @@ fn data_uri_uses_base64(reference: &str) -> bool {/// scanned for prompt injection — so the multi-MB base64 data URI never/// survives past the front door. Idempotent: a message with no `[FILE:` marker/// (already-rewritten `[FILE-EXTRACTED]` text included) is returned unchanged.-pub async fn inline_file_attachments(message: &str, file_config: &MultimodalFileConfig) -> String {+pub async fn inline_file_attachments(+ ctx: &DispatchCtx,+ message: &str,+ file_config: &MultimodalFileConfig,+) -> String {if !message.contains(markers::FILE_MARKER_PREFIX) {return message.to_string();}@@ -381,7 +390,7 @@ pub async fn inline_file_attachments(message: &str, file_config: &MultimodalFilemax_file_bytes,max_extracted_text_chars,&client,- &DocumentsTextExtractor,+ &DocumentsTextExtractor { ctx },).await{diff --git a/crates/openhuman-core/src/agent/multimodal_attachment_handling_tests.rs b/crates/openhuman-core/src/agent/multimodal_attachment_handling_tests.rsindex cfb16aa463..fd8417bce8 100644--- a/crates/openhuman-core/src/agent/multimodal_attachment_handling_tests.rs+++ b/crates/openhuman-core/src/agent/multimodal_attachment_handling_tests.rs@@ -19,8 +19,7 @@ async fn prepare_messages_handles_mixed_image_and_file_markers() {txt_path.display()))];- let prepared = prepare_messages_for_provider(- &messages,+ let prepared = prepare_messages_for_provider(&DispatchCtx::ambient(), &messages,&MultimodalConfig::default(),&MultimodalFileConfig::default(),)@@ -94,7 +93,7 @@ async fn prepare_messages_rejects_absolute_file_marker_under_untrusted_channel_clet messages = vec![TranscriptMessage::user("please summarise [FILE:/etc/passwd]".to_string(),)];- let err = prepare_messages_for_provider(&messages, &MultimodalConfig::default(), &cfg)+ let err = prepare_messages_for_provider(&DispatchCtx::ambient(), &messages, &MultimodalConfig::default(), &cfg).await.expect_err("absolute file marker on a channel turn must be rejected");assert!(@@ -112,7 +111,7 @@ async fn prepare_messages_rejects_relative_file_marker_under_untrusted_channel_clet messages = vec![TranscriptMessage::user("what does [FILE:./relative.txt] say?".to_string(),)];- let err = prepare_messages_for_provider(&messages, &MultimodalConfig::default(), &cfg)+ let err = prepare_messages_for_provider(&DispatchCtx::ambient(), &messages, &MultimodalConfig::default(), &cfg).await.expect_err("relative file marker on a channel turn must be rejected");assert!(@@ -128,7 +127,7 @@ async fn prepare_messages_under_untrusted_channel_config_passes_plain_text_throu// ordinary channel chatter.let cfg = MultimodalFileConfig::for_untrusted_channel_input();let messages = vec![TranscriptMessage::user("hello, how are you?".to_string())];- let prepared = prepare_messages_for_provider(&messages, &MultimodalConfig::default(), &cfg)+ let prepared = prepare_messages_for_provider(&DispatchCtx::ambient(), &messages, &MultimodalConfig::default(), &cfg).await.expect("plain channel text must pass through the hardened config");assert!(!prepared.contains_files);@@ -142,7 +141,7 @@ async fn prepare_messages_under_untrusted_channel_config_passes_plain_text_throuasync fn inline_file_attachments_replaces_marker_with_extracted_text() {// base64("hello world") = aGVsbG8gd29ybGQ=let msg = "summarize [FILE:data:text/plain;base64,aGVsbG8gd29ybGQ=]";- let out = inline_file_attachments(msg, &MultimodalFileConfig::default()).await;+ let out = inline_file_attachments(&DispatchCtx::ambient(), msg, &MultimodalFileConfig::default()).await;assert!(out.contains("[FILE-EXTRACTED"),"extracted block present: {out}"@@ -158,7 +157,7 @@ async fn inline_file_attachments_replaces_marker_with_extracted_text() {#[tokio::test]async fn inline_file_attachments_noop_without_marker() {let msg = "just a normal message";- let out = inline_file_attachments(msg, &MultimodalFileConfig::default()).await;+ let out = inline_file_attachments(&DispatchCtx::ambient(), msg, &MultimodalFileConfig::default()).await;assert_eq!(out, msg);}@@ -210,8 +209,7 @@ async fn image_placeholder_rehydrates_to_inline_data_uri_for_provider() {// Round-trip: the provider prep step re-reads the file back into a data URI,// so the model still receives inline image bytes.- let prepared = prepare_messages_for_provider(- &rehydrated,+ let prepared = prepare_messages_for_provider(&DispatchCtx::ambient(), &rehydrated,&MultimodalConfig::default(),&MultimodalFileConfig::default(),)@@ -248,7 +246,7 @@ async fn inline_file_attachments_caps_at_max_files() {max_files: 1,..MultimodalFileConfig::default()};- let out = inline_file_attachments(msg, &cfg).await;+ let out = inline_file_attachments(&DispatchCtx::ambient(), msg, &cfg).await;// First file is extracted; the second is over the cap → placeholder, unread.assert!(out.contains("[FILE-EXTRACTED"),