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(attachments): add native staged parts to attachment scope
Steven Enamakel41cec802fad2
diff --git a/crates/openhuman-core/src/agent/attachments/mod.rs b/crates/openhuman-core/src/agent/attachments/mod.rsindex 6eb1f57b85..12bad1a428 100644--- a/crates/openhuman-core/src/agent/attachments/mod.rs+++ b/crates/openhuman-core/src/agent/attachments/mod.rs@@ -23,6 +23,8 @@ pub(crate) mod provider;pub(crate) struct AttachmentAccessScope {pub(crate) external_channel: bool,pub(crate) workspace: Option<PathBuf>,+ pub(crate) native_staged_parts: Vec<tinychannels_bus::ContentPart>,+ pub(crate) thread_id: Option<String>,}const REQUEST_SCOPE_KEY: &str = "__openhuman_attachment_access_scope";@@ -43,6 +45,8 @@ pub(crate) fn attach_request_scope(request.metadata[REQUEST_SCOPE_KEY] = serde_json::json!({"external_channel": external_channel,"workspace": workspace,+ "native_staged_parts": context.native_staged_parts,+ "thread_id": context.thread_id,});}@@ -62,6 +66,14 @@ pub(crate) fn take_request_scope(metadata: &mut serde_json::Value) -> Attachment.get("workspace").and_then(serde_json::Value::as_str).map(PathBuf::from),+ native_staged_parts: value+ .get("native_staged_parts")+ .and_then(|parts| serde_json::from_value(parts.clone()).ok())+ .unwrap_or_default(),+ thread_id: value+ .get("thread_id")+ .and_then(serde_json::Value::as_str)+ .map(str::to_owned),}}diff --git a/crates/openhuman-core/src/agent/session_host/runtime_session/post_commit.rs b/crates/openhuman-core/src/agent/session_host/runtime_session/post_commit.rsindex f7753d4f4d..e23e8ee59f 100644--- a/crates/openhuman-core/src/agent/session_host/runtime_session/post_commit.rs+++ b/crates/openhuman-core/src/agent/session_host/runtime_session/post_commit.rs@@ -135,6 +135,36 @@ pub(super) async fn finalize_committed_turn(let commit_started = std::time::Instant::now();// The turn's own context, taken before the receipt is dropped.let dispatch = receipt.options.context.dispatch_ctx();+ if !receipt.options.context.native_staged_parts.is_empty() {+ if let Some(message_id) = receipt.options.context.native_message_id.as_deref() {+ if let Some(user) = tinyagents_harness::summarization::last_user_message(+ &receipt.outcome.history,+ ) {+ let committed = crate::threads::attachments::native_parts_in_committed_message(+ &receipt.options.context.native_staged_parts,+ user,+ );+ if !committed.is_empty() {+ let thread_id = receipt+ .options+ .context+ .thread_id+ .as_deref()+ .unwrap_or_default();+ if let Err(error) = crate::threads::attachments::commit_native_channel_parts(+ &dispatch,+ thread_id,+ &committed,+ message_id,+ )+ .await+ {+ tracing::warn!("[session-runtime] native attachment claim failed after commit: {error}");+ }+ }+ }+ }+ }let output = receipt.outcome.output.clone().unwrap_or_default();// Skips compaction checkpoints (user-role, not the user's words).let input = tinyagents_harness::summarization::last_user_message(&receipt.outcome.history)diff --git a/crates/openhuman-core/src/threads/attachments.rs b/crates/openhuman-core/src/threads/attachments.rsindex 1eb443d392..8d77e61d18 100644--- a/crates/openhuman-core/src/threads/attachments.rs+++ b/crates/openhuman-core/src/threads/attachments.rs@@ -20,7 +20,8 @@ mod staged;use staged::*;pub(crate) use staged::{bind_staged_refs, commit_native_channel_parts, consume_staged_parts, discard_staged_parts,- stage_native_channel_part, stage_queued_parts, validate_opaque_parts,+ native_parts_in_committed_message, stage_native_channel_part, stage_queued_parts,+ validate_opaque_parts,};pub(crate) fn has_opaque_ref(part: &ContentPart) -> bool {diff --git a/crates/openhuman-core/src/threads/attachments/staged.rs b/crates/openhuman-core/src/threads/attachments/staged.rsindex d8b3f77346..a9ed80e9e0 100644--- a/crates/openhuman-core/src/threads/attachments/staged.rs+++ b/crates/openhuman-core/src/threads/attachments/staged.rs@@ -384,6 +384,37 @@ pub(crate) async fn commit_native_channel_parts(claim_staged_refs(ctx, thread_id, &config, committed_message_id, &entries).await}+pub(crate) fn native_parts_in_committed_message(+ staged: &[ContentPart],+ message: &tinyinference_llm::message::Message,+) -> Vec<ContentPart> {+ let tinyinference_llm::message::Message::User(user) = message else {+ return Vec::new();+ };+ let committed = user+ .content+ .iter()+ .filter_map(|block| match block {+ tinyinference_llm::message::ContentBlock::Image(image) => {+ image.url.strip_prefix("openhuman-staged://")+ }+ tinyinference_llm::message::ContentBlock::Document(+ tinyinference_llm::message::MediaRef::Path { path, .. },+ ) => path.strip_prefix("openhuman-staged://"),+ _ => None,+ })+ .collect::<std::collections::HashSet<_>>();+ staged+ .iter()+ .filter(|part| {+ opaque_media(part)+ .and_then(|media| media.opaque_id.as_deref())+ .is_some_and(|id| committed.contains(id))+ })+ .cloned()+ .collect()+}+pub(super) async fn validate_staged_files(ctx: &crate::core::runtime::DispatchCtx,thread_id: &str,