Skip to content

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

feat(channels): add hosted progressive reply and typed relay publishing

Steven Enamakel37dcffe2d916
diff --git a/crates/openhuman-core/src/channels/bus/delivery.rs b/crates/openhuman-core/src/channels/bus/delivery.rs
index 3ffd7d6da0..da1798d008 100644
--- a/crates/openhuman-core/src/channels/bus/delivery.rs
+++ b/crates/openhuman-core/src/channels/bus/delivery.rs
@@ -159,6 +159,9 @@ pub(super) struct ModuleProgressiveReply {
pub(crate) struct NativeProgressiveReply {
object: tinybus::module::ModuleObjectClient,
handle: String,
+ // Hosted relay handles own their callback runtime. Keep that lease alive
+ // until Close is acknowledged or the final reply owner is dropped.
+ runtime: Option<ChannelRuntimeLease>,
}
impl NativeProgressiveReply {
@@ -182,7 +185,45 @@ impl NativeProgressiveReply {
.await?;
match result {
ProgressiveResult::Opened { handle } if !handle.is_empty() && handle.len() <= 128 => {
- Ok(Self { object, handle })
+ Ok(Self {
+ object,
+ handle,
+ runtime: None,
+ })
+ }
+ _ => {
+ crate::modules::report::malformed_reply("tinychannels");
+ Err(ModuleCallError::ModuleFault.into())
+ }
+ }
+ }
+
+ pub(crate) async fn open_hosted(
+ runtime: ChannelRuntimeLease,
+ channel: tinychannels_bus::channel::ChannelRef,
+ conversation: tinychannels_bus::channel::ConversationRef,
+ turn_id: String,
+ lifetime: std::time::Duration,
+ ) -> anyhow::Result<Self> {
+ let object = runtime.object().clone();
+ let result: ProgressiveResult = object
+ .call_confidential(
+ methods::EXECUTE_PROGRESSIVE,
+ (ProgressiveCommand::OpenHostedOutput {
+ channel,
+ conversation,
+ turn_id,
+ lifetime_ms: lifetime.as_millis().min(u64::MAX as u128) as u64,
+ },),
+ )
+ .await?;
+ match result {
+ ProgressiveResult::Opened { handle } if !handle.is_empty() && handle.len() <= 128 => {
+ Ok(Self {
+ object,
+ handle,
+ runtime: Some(runtime),
+ })
}
_ => {
crate::modules::report::malformed_reply("tinychannels");
@@ -265,6 +306,9 @@ impl NativeProgressiveReply {
crate::modules::report::malformed_reply("tinychannels");
return Err(ModuleCallError::ModuleFault);
}
+ if let Some(runtime) = &self.runtime {
+ runtime.close().await?;
+ }
Ok(())
}
}
diff --git a/crates/openhuman-core/src/channels/providers/relay/channel.rs b/crates/openhuman-core/src/channels/providers/relay/channel.rs
index 7ccc2cf392..73edf17495 100644
--- a/crates/openhuman-core/src/channels/providers/relay/channel.rs
+++ b/crates/openhuman-core/src/channels/providers/relay/channel.rs
@@ -78,6 +78,60 @@ impl RelayChannel {
})),
}
}
+
+ /// Publish lossless typed output to the gateway that owns provider delivery.
+ /// The receipt acknowledges acceptance by this host event path; provider
+ /// receipt IDs arrive separately from the gateway and are never fabricated.
+ pub(crate) fn publish_typed_reply(
+ &self,
+ channel: &tinychannels_bus::ChannelRef,
+ conversation: &tinychannels_bus::ConversationRef,
+ turn_id: &str,
+ sequence: u64,
+ segment_index: u32,
+ idempotency_key: &str,
+ parts: &[tinychannels_bus::OutboundContentPart],
+ text: &str,
+ ) -> tinychannels_bus::channel::ChannelSendOutcome {
+ self.sent
+ .lock()
+ .unwrap_or_else(|e| e.into_inner())
+ .push(text.to_owned());
+ publish_web_channel_event(WebChannelEvent::ChannelOutbound {
+ context: crate::web_chat::event_context(
+ self.client_id.clone(),
+ self.thread_id.clone(),
+ self.request_id.clone(),
+ ),
+ full_response: Some(text.to_owned()),
+ structured: Some(json!({
+ "kind": CHANNEL_OUTBOUND_EVENT,
+ "channel": self.channel,
+ "chat_id": conversation.id,
+ "thread_ts": conversation.thread_id,
+ "reply_to_message_id": self.reply_to,
+ "turn_id": turn_id,
+ "sequence": sequence,
+ "segment_index": segment_index,
+ "idempotency_key": idempotency_key,
+ "channel_ref": channel,
+ "conversation_ref": conversation,
+ "parts": parts,
+ })),
+ });
+
+ tinychannels_bus::channel::ChannelSendOutcome {
+ receipt: tinychannels_bus::channel::MessageReceipt {
+ idempotency_key: Some(idempotency_key.to_owned()),
+ channel: Some(channel.clone()),
+ conversation: Some(conversation.clone()),
+ thread_id: conversation.thread_id.clone(),
+ reply_to_id: Some(self.reply_to.clone()),
+ ..Default::default()
+ },
+ error: None,
+ }
+ }
}
#[async_trait]