Skip to content

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

refactor(flows): thread dispatch context through create and update ops

Steven Enamakel00d04a9e604c
diff --git a/crates/openhuman-core/src/flows/ops/definitions.rs b/crates/openhuman-core/src/flows/ops/definitions.rs
index 8d9fa44009..b7c36aa580 100644
--- a/crates/openhuman-core/src/flows/ops/definitions.rs
+++ b/crates/openhuman-core/src/flows/ops/definitions.rs
@@ -57,7 +57,24 @@ pub async fn flows_create(
graph_json: Value,
require_approval: bool,
) -> Result<Outcome<Flow>, String> {
- let graph = validate_and_migrate_graph(&crate::core::runtime::DispatchCtx::ambient(), config, graph_json).await?;
+ flows_create_with_context(
+ &crate::core::runtime::DispatchCtx::ambient(),
+ config,
+ name,
+ graph_json,
+ require_approval,
+ )
+ .await
+}
+
+pub(crate) async fn flows_create_with_context(
+ ctx: &crate::core::runtime::DispatchCtx,
+ config: &Config,
+ name: String,
+ graph_json: Value,
+ require_approval: bool,
+) -> Result<Outcome<Flow>, String> {
+ let graph = validate_and_migrate_graph(ctx, config, graph_json).await?;
// Rule 1: automatic triggers create DISABLED — the user must arm them
// explicitly.
diff --git a/crates/openhuman-core/src/flows/ops/updates.rs b/crates/openhuman-core/src/flows/ops/updates.rs
index 7968fbba36..f87a886db6 100644
--- a/crates/openhuman-core/src/flows/ops/updates.rs
+++ b/crates/openhuman-core/src/flows/ops/updates.rs
@@ -72,8 +72,32 @@ pub async fn flows_update(
graph_json: Option<Value>,
require_approval: Option<bool>,
expected_version: Option<String>,
+) -> Result<Outcome<Flow>, String> {
+ flows_update_with_context(
+ &crate::core::runtime::DispatchCtx::ambient(),
+ config,
+ id,
+ name,
+ graph_json,
+ require_approval,
+ expected_version,
+ disarm_automatic,
+ )
+ .await
+}
+
+pub(crate) async fn flows_update_with_context(
+ ctx: &crate::core::runtime::DispatchCtx,
+ config: &Config,
+ id: &str,
+ name: Option<String>,
+ graph_json: Option<Value>,
+ require_approval: Option<bool>,
+ expected_version: Option<String>,
+ disarm_automatic: bool,
) -> Result<Outcome<Flow>, String> {
flows_update_inner(
+ ctx,
config,
id,
name,
@@ -86,6 +110,7 @@ pub async fn flows_update(
}
async fn flows_update_inner(
+ ctx: &crate::core::runtime::DispatchCtx,
config: &Config,
id: &str,
name: Option<String>,
@@ -103,12 +128,12 @@ async fn flows_update_inner(
let graph_changed = graph_json.is_some();
let graph = match graph_json {
Some(raw) => {
- let graph = validate_and_migrate_graph(&crate::core::runtime::DispatchCtx::ambient(), config, raw).await?;
+ let graph = validate_and_migrate_graph(ctx, config, raw).await?;
graph
}
None => {
validate_and_migrate_graph(
- &crate::core::runtime::DispatchCtx::ambient(),
+ ctx,
config,
serde_json::to_value(&existing.graph).map_err(|error| error.to_string())?,
)