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(attachments): improve native media processing flow
Steven Enamakel13aac9dfe2fa
diff --git a/crates/openhuman-core/src/channels/runtime/dispatch/processor/native_media.rs b/crates/openhuman-core/src/channels/runtime/dispatch/processor/native_media.rsindex 5d1ce0be62..a5021cab5d 100644--- a/crates/openhuman-core/src/channels/runtime/dispatch/processor/native_media.rs+++ b/crates/openhuman-core/src/channels/runtime/dispatch/processor/native_media.rs@@ -86,7 +86,8 @@ pub(super) async fn resolve_typed_message(}let client = module_client(ctx).await;let module_dispatch = ctx.dispatch_ctx();- for part in &mut parts {+ let mut media_payloads = Vec::new();+ for (index, part) in parts.iter_mut().enumerate() {let (media, image, name) = match part {ContentPart::Image { media, .. } => (media,@@ -135,16 +136,32 @@ pub(super) async fn resolve_typed_message(.content_type.as_deref().ok_or_else(|| "native media has no content type".to_owned())?;- let staged = crate::threads::attachments::stage_native_channel_part(+ media_payloads.push((index, part.clone(), name, mime.to_owned(), bytes));+ }+ for (index, input, name, mime, bytes) in media_payloads {+ let staged = match crate::threads::attachments::stage_native_channel_part(host_dispatch,thread_id,config,- part,+ &input,&name,- mime,+ &mime,&bytes,)- .await?;+ .await+ {+ Ok(staged) => staged,+ Err(error) => {+ let _ = crate::threads::attachments::discard_native_channel_parts(+ host_dispatch,+ thread_id,+ config,+ &staged_parts,+ )+ .await;+ return Err(error);+ }+ };let opaque_id = media_opaque_id(&staged).ok_or_else(|| "staged native media has no host reference".to_owned())?;let mut model_part = staged.clone();@@ -153,7 +170,7 @@ pub(super) async fn resolve_typed_message(_ => return Err("native staged media kind changed unexpectedly".into()),};model_media.path = Some(format!("openhuman-staged://{opaque_id}"));- *part = model_part;+ parts[index] = model_part;staged_parts.push(staged);}diff --git a/crates/openhuman-core/src/channels/runtime/dispatch/processor/turn.rs b/crates/openhuman-core/src/channels/runtime/dispatch/processor/turn.rsindex 47443bf958..bb2976103f 100644--- a/crates/openhuman-core/src/channels/runtime/dispatch/processor/turn.rs+++ b/crates/openhuman-core/src/channels/runtime/dispatch/processor/turn.rs@@ -382,7 +382,7 @@ pub(crate) async fn process_channel_runtime_message(&host_dispatch,&host.config,&envelope,- &prepared_thread_id,+ &canonical_session_key,&enriched_message,).awaitdiff --git a/crates/openhuman-core/src/threads/attachments.rs b/crates/openhuman-core/src/threads/attachments.rsindex 47906a59ca..94305e9f50 100644--- a/crates/openhuman-core/src/threads/attachments.rs+++ b/crates/openhuman-core/src/threads/attachments.rs@@ -19,7 +19,8 @@ const STORAGE_KEY: &str = "__openhumanStoredAttachments";mod staged;use staged::*;pub(crate) use staged::{- bind_staged_refs, commit_native_channel_parts, consume_staged_parts, discard_staged_parts,+ bind_staged_refs, commit_native_channel_parts, consume_staged_parts, discard_native_channel_parts,+ discard_staged_parts,native_parts_in_committed_message, stage_native_channel_part, stage_queued_parts,read_authorized_native_attachment, validate_opaque_parts,};diff --git a/crates/openhuman-core/src/threads/attachments/staged.rs b/crates/openhuman-core/src/threads/attachments/staged.rsindex e23a576c61..e217c5b2d6 100644--- a/crates/openhuman-core/src/threads/attachments/staged.rs+++ b/crates/openhuman-core/src/threads/attachments/staged.rs@@ -391,6 +391,19 @@ pub(crate) async fn commit_native_channel_parts(claim_staged_refs(ctx, thread_id, &config, committed_message_id, &entries).await}+pub(crate) async fn discard_native_channel_parts(+ ctx: &crate::core::runtime::DispatchCtx,+ thread_id: &str,+ config: &crate::config::Config,+ parts: &[ContentPart],+) -> Result<(), String> {+ if parts.is_empty() {+ return Ok(());+ }+ let entries = read_staged_entries(ctx, thread_id, parts, config).await?;+ discard_staged_entries(ctx, thread_id, config, entries).await+}+pub(crate) async fn read_authorized_native_attachment(ctx: &crate::core::runtime::DispatchCtx,config: &crate::config::Config,