Skip to content

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

feat(rpc): add SSE event stream endpoint

Steven Enamakel68e3f47574a0
diff --git a/crates/openhuman-rpc/src/server/http/events.rs b/crates/openhuman-rpc/src/server/http/events.rs
index f705350c46..2a826a2ae1 100644
--- a/crates/openhuman-rpc/src/server/http/events.rs
+++ b/crates/openhuman-rpc/src/server/http/events.rs
@@ -1,7 +1,9 @@
//! Server-Sent Event streams: `/events`, `/events/webhooks`, `/events/domain`.
use crate::core_host::core::events::DomainEvent;
+use crate::core_host::core::runtime::DispatchCtx;
use axum::extract::Query;
+use axum::Extension;
use axum::http::{header, StatusCode};
use axum::response::sse::{Event, KeepAlive, Sse};
use axum::response::{IntoResponse, Response};
@@ -39,8 +41,12 @@ pub(super) struct EventsQuery {
/// `client_id`.
pub(super) async fn events_handler(
headers: axum::http::HeaderMap,
+ ctx: Option<Extension<DispatchCtx>>,
Query(query): Query<EventsQuery>,
) -> Response {
+ // The context the serving middleware attached; a request that carries none
+ // has no tenant, which fails closed in SaaS.
+ let ctx = ctx.map_or_else(DispatchCtx::unbound, |Extension(ctx)| ctx);
let bearer = headers
.get(header::AUTHORIZATION)
.and_then(|v| v.to_str().ok())
@@ -54,11 +60,9 @@ pub(super) async fn events_handler(
// SaaS: the stream belongs to the user the gateway scoped this request to,
// and carries only that user's events. No user scope, or a browser bind
// token instead of the gateway's bearer, is refused outright.
- // The stream keys on the tenant (profile), read from the task's own scope.
+ // The stream keys on the tenant (profile) of the request's own context.
let saas_profile = if crate::core_host::core::runtime::is_saas() {
- let profile = crate::core_host::core::runtime::current_tenant()
- .ok()
- .and_then(|tenant| tenant.profile);
+ let profile = ctx.tenant().ok().and_then(|tenant| tenant.profile);
match profile {
Some(profile) if bearer_ok => Some(profile),
_ => {