Skip to content

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

feat(dispatch): add notification dispatch support

Steven Enamakel2e42d2067a7d
diff --git a/crates/openhuman-core/src/core/dispatch.rs b/crates/openhuman-core/src/core/dispatch.rs
index 031a67f1f0..b0ae3e5d9c 100644
--- a/crates/openhuman-core/src/core/dispatch.rs
+++ b/crates/openhuman-core/src/core/dispatch.rs
@@ -27,6 +27,7 @@ use serde_json::{json, Map, Value};
/// A `Result` containing the JSON-formatted response or an error message if
/// the method is unknown or invocation fails.
pub async fn dispatch(
+ ctx: crate::core::runtime::DispatchCtx,
state: AppState,
method: &str,
params: serde_json::Value,
@@ -247,7 +248,7 @@ async fn try_registry_dispatch(
if let Err(err) = crate::core::all::validate_params(&schema, &params_obj) {
return Some(Err(err));
}
- crate::core::all::try_invoke_registered_rpc(method, params_obj).await
+ crate::core::all::try_invoke_registered_rpc(ctx, method, params_obj).await
}
fn params_to_object(params: Value) -> Result<Map<String, Value>, String> {
diff --git a/crates/openhuman-core/src/core/runtime/dispatch_ctx.rs b/crates/openhuman-core/src/core/runtime/dispatch_ctx.rs
index 7867c234b3..9559a04619 100644
--- a/crates/openhuman-core/src/core/runtime/dispatch_ctx.rs
+++ b/crates/openhuman-core/src/core/runtime/dispatch_ctx.rs
@@ -48,6 +48,17 @@ impl DispatchCtx {
}
}
+ /// The ambient context of the calling task, or unbound.
+ ///
+ /// Transitional (#7801): for a caller that has no context of its own to
+ /// hand over yet. Every use is a reader still to be moved onto an explicit
+ /// carrier, and the function goes away with the ambient context.
+ pub fn ambient() -> Self {
+ Self {
+ core: CoreContext::current(),
+ }
+ }
+
/// The context this call runs under, if any.
pub fn core(&self) -> Option<&Arc<CoreContext>> {
self.core.as_ref()
diff --git a/crates/openhuman-core/src/desktop/notifications/schemas.rs b/crates/openhuman-core/src/desktop/notifications/schemas.rs
index 660298c70a..e569188c2b 100644
--- a/crates/openhuman-core/src/desktop/notifications/schemas.rs
+++ b/crates/openhuman-core/src/desktop/notifications/schemas.rs
@@ -9,7 +9,7 @@ use crate::core::all::{ControllerFuture, RegisteredController};
use crate::core::{ControllerSchema, FieldSchema, TypeSchema};
type SchemaBuilder = fn() -> ControllerSchema;
-type ControllerHandler = fn(Map<String, Value>) -> ControllerFuture;
+type ControllerHandler = fn(DispatchCtx, Map<String, Value>) -> ControllerFuture;
struct NotificationControllerDef {
function: &'static str,