Skip to content

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

feat(channels): project durable voice media refs for configured accounts

Steven Enamakel1859673f6631
diff --git a/crates/openhuman-core/src/channels/runtime/startup/callback.rs b/crates/openhuman-core/src/channels/runtime/startup/callback.rs
index b1eb525735..38750fb16e 100644
--- a/crates/openhuman-core/src/channels/runtime/startup/callback.rs
+++ b/crates/openhuman-core/src/channels/runtime/startup/callback.rs
@@ -241,6 +241,46 @@ impl ChannelHostCallbacks {
.map_err(|_| Error::failed("channel speech synthesis failed"))
}
+ async fn store_voice_media(
+ &self,
+ request: tinychannels_bus::HostStoreVoiceMediaRequest,
+ ) -> Result<tinychannels_bus::HostStoreVoiceMediaResult> {
+ Self::validate_callback_size(&request)?;
+ let scope = &request.scope;
+ let Some(channel) = self
+ .context()?
+ .channels_by_name
+ .get(&scope.configured_instance)
+ else {
+ return Err(Error::failed("voice media account is not configured"));
+ };
+ if scope.configured_instance.trim().is_empty()
+ || scope.channel.id != tinychannels_bus::provider_id(&scope.configured_instance)
+ || scope.channel.account_id.as_deref() != Some(scope.configured_instance.as_str())
+ || tinychannels_bus::provider_id(channel.name()) != scope.channel.id
+ || scope.conversation.id.trim().is_empty()
+ || scope.turn_id.trim().is_empty()
+ {
+ return Err(Error::failed(
+ "voice media scope does not match configured account",
+ ));
+ }
+ let media = request
+ .media_reference
+ .filter(|media| {
+ media
+ .opaque_id
+ .as_deref()
+ .is_some_and(|id| id.starts_with("tinychannels_media_v1_"))
+ })
+ .ok_or_else(|| Error::failed("voice media has no durable scoped reference"))?;
+ Ok(tinychannels_bus::HostStoreVoiceMediaResult {
+ media,
+ // A local durable reference does not grant public-link access.
+ accessible_url: None,
+ })
+ }
+
async fn get_voice_reply_policy(
&self,
request: HostVoiceReplyPolicyRequest,
diff --git a/crates/openhuman-core/src/channels/runtime/startup/callback_tests.rs b/crates/openhuman-core/src/channels/runtime/startup/callback_tests.rs
index 2613426d6f..0e66c18d0f 100644
--- a/crates/openhuman-core/src/channels/runtime/startup/callback_tests.rs
+++ b/crates/openhuman-core/src/channels/runtime/startup/callback_tests.rs
@@ -197,6 +197,62 @@ fn callback_for_channels(
(callback, context)
}
+#[tokio::test]
+async fn voice_media_projection_accepts_only_durable_refs_for_the_configured_account() {
+ let channel = Arc::new(RecordingChannel::new("telegram:bot-a"));
+ let channels: HashMap<String, Arc<dyn Channel>> = HashMap::from([(
+ channel.name().to_owned(),
+ channel.clone() as Arc<dyn Channel>,
+ )]);
+ let (callback, _context) = callback_for_channels(channels, HashMap::new(), None);
+ let request = || tinychannels_bus::HostStoreVoiceMediaRequest {
+ scope: tinychannels_bus::HostVoiceScope {
+ configured_instance: "telegram:bot-a".into(),
+ channel: tinychannels_bus::ChannelRef {
+ id: "telegram".into(),
+ account_id: Some("telegram:bot-a".into()),
+ },
+ conversation: tinychannels_bus::ConversationRef {
+ kind: tinychannels_bus::ConversationKind::Dm,
+ id: "chat-42".into(),
+ ..Default::default()
+ },
+ turn_id: "telegram_42_7".into(),
+ },
+ direction: tinychannels_bus::HostVoiceMediaDirection::Inbound,
+ audio_base64: "fixture bytes are already stored by the module".into(),
+ mime_type: "audio/ogg".into(),
+ codec: Some("ogg_opus".into()),
+ duration_ms: Some(1000),
+ file_name: Some("voice.ogg".into()),
+ media_reference: Some(tinychannels_bus::MediaReference {
+ opaque_id: Some("tinychannels_media_v1_fixture".into()),
+ kind: tinychannels_bus::MediaKind::Audio,
+ content_type: Some("audio/ogg".into()),
+ ..Default::default()
+ }),
+ };
+
+ let stored = callback
+ .store_voice_media(request())
+ .await
+ .expect("configured module's durable scoped ref is projected");
+ assert_eq!(
+ stored.media.opaque_id.as_deref(),
+ Some("tinychannels_media_v1_fixture")
+ );
+ assert!(stored.accessible_url.is_none());
+
+ let mut forged = request();
+ forged.scope.configured_instance = "telegram:bot-b".into();
+ forged.scope.channel.account_id = Some("telegram:bot-b".into());
+ assert!(callback.store_voice_media(forged).await.is_err());
+
+ let mut unscoped = request();
+ unscoped.media_reference.as_mut().unwrap().opaque_id = Some("external-id".into());
+ assert!(callback.store_voice_media(unscoped).await.is_err());
+}
+
#[tokio::test]
async fn native_progressive_transport_dispatches_typed_content_through_configured_channel() {
let other_account = Arc::new(RecordingChannel::new("telegram:bot-a"));