Skip to content

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

feat(flows): add draft promotion host for workflow saves

Steven Enamakel56eb88727ff3
diff --git a/crates/openhuman-core/src/flows/authoring_host.rs b/crates/openhuman-core/src/flows/authoring_host.rs
index c8b67edbb9..456ecc2b43 100644
--- a/crates/openhuman-core/src/flows/authoring_host.rs
+++ b/crates/openhuman-core/src/flows/authoring_host.rs
@@ -177,11 +177,86 @@ impl ApprovalCallbacks {
#[derive(Clone)]
struct ApprovalCallbacks(Callbacks);
+#[derive(Clone)]
+struct DraftPromotionCallbacks(Callbacks);
+
+#[tinybus::interface(name = "ai.tinyhumans.tinyflows.DraftPromotionHost")]
+impl DraftPromotionCallbacks {
+ async fn save_promoted_draft(
+ &self,
+ request: catalog::SavePromotedDraftRequest,
+ ) -> BusResult<catalog::SavePromotedDraftResponse> {
+ let config = Arc::clone(&self.0.config);
+ let context = self.0.context.clone();
+ let response = self
+ .0
+ .in_context(async move {
+ use catalog::{DraftPromotionOperation, SavePromotedDraftResponse};
+
+ let outcome = match request.operation {
+ DraftPromotionOperation::Create {
+ name,
+ graph,
+ require_approval,
+ } => {
+ ops::flows_create_with_context(
+ &context,
+ &config,
+ name,
+ graph,
+ require_approval,
+ )
+ .await?
+ }
+ DraftPromotionOperation::Update {
+ id,
+ name,
+ graph,
+ require_approval,
+ expected_version,
+ } => {
+ ops::flows_update_with_context(
+ &context,
+ &config,
+ &id,
+ Some(name),
+ Some(graph),
+ require_approval,
+ expected_version,
+ )
+ .await?
+ }
+ };
+ let workflow: catalog::Workflow = crate::flows::store::roundtrip(outcome.value)
+ .map_err(|error| error.to_string())?;
+ Ok(SavePromotedDraftResponse::Ok(
+ catalog::SavePromotedDraftResult {
+ workflow,
+ metadata: serde_json::json!({"logs": outcome.logs}),
+ },
+ ))
+ })
+ .await;
+ Ok(match response {
+ Ok(response) => response,
+ Err(message) => catalog::SavePromotedDraftResponse::Error(
+ catalog::DraftPromotionFailure {
+ code: "workflow_save_failed".into(),
+ message,
+ details: None,
+ },
+ ),
+ })
+ }
+}
+
/// A callback registration whose lifetime is bounded by one authoring call.
pub(crate) struct Registration {
_registration: module::ServedObjectRegistration,
+ _draft_promotion_registration: module::ServedObjectRegistration,
pub(crate) authoring: AuthoringHost,
pub(crate) catalog: catalog::CallbackAddress,
+ pub(crate) draft_promotion: catalog::CallbackAddress,
}
pub(crate) async fn register(
@@ -200,11 +275,21 @@ pub(crate) async fn register(
let registration = module::serve_pair(
path.clone(),
callbacks.clone(),
- ApprovalCallbacks(callbacks),
+ ApprovalCallbacks(callbacks.clone()),
+ )
+ .await?;
+ let draft_promotion_path = format!(
+ "/ai/tinyhumans/openhuman/DraftPromotionHost/h{}",
+ uuid::Uuid::new_v4().simple()
+ );
+ let draft_promotion_registration = module::serve_registered(
+ draft_promotion_path.clone(),
+ DraftPromotionCallbacks(callbacks),
)
.await?;
Ok(Registration {
_registration: registration,
+ _draft_promotion_registration: draft_promotion_registration,
authoring: AuthoringHost {
bus_name: module::HOST_BUS_NAME.to_string(),
object_path: path.clone(),
@@ -213,6 +298,10 @@ pub(crate) async fn register(
destination: module::HOST_BUS_NAME.to_string(),
object_path: path,
},
+ draft_promotion: catalog::CallbackAddress {
+ destination: module::HOST_BUS_NAME.to_string(),
+ object_path: draft_promotion_path,
+ },
})
}
diff --git a/crates/openhuman-core/src/flows/caps_host/code.rs b/crates/openhuman-core/src/flows/caps_host/code.rs
index 83b179c481..62afabbf2b 100644
--- a/crates/openhuman-core/src/flows/caps_host/code.rs
+++ b/crates/openhuman-core/src/flows/caps_host/code.rs
@@ -8,10 +8,7 @@
use crate::core::runtime::DispatchCtx;
use std::sync::Arc;
-use async_trait::async_trait;
use serde_json::{json, Value};
-use tinyflows::caps::*;
-use tinyflows::error::{EngineError, Result};
use super::*;
use crate::config::Config;
@@ -55,9 +52,13 @@ pub struct OpenHumanCode {
pub(crate) const CODE_RUN_TIMEOUT_SECS: u64 = 60;
-#[async_trait]
-impl CodeRunner for OpenHumanCode {
- async fn run(&self, language: CodeLanguage, source: &str, input: Value) -> Result<Value> {
+impl OpenHumanCode {
+ pub(crate) async fn run(
+ &self,
+ language: tinyflows_bus::runs::CodeLanguage,
+ source: &str,
+ input: Value,
+ ) -> Result<Value> {
// Autonomy-tier gate (Phase 2): sandboxed arbitrary-code execution is
// Write-class. A read-only run `Block`s here and never spawns anything;
// Supervised/Full fall through to the ApprovalGate below.
@@ -122,8 +123,12 @@ impl CodeRunner for OpenHumanCode {
// sandbox failures.
let exec_result = async {
let (script_name, interpreter, script_body) = match language {
- CodeLanguage::JavaScript => ("script.js", "node", js_harness(source)),
- CodeLanguage::Python => ("script.py", "python3", python_harness(source)),
+ tinyflows_bus::runs::CodeLanguage::JavaScript => {
+ ("script.js", "node", js_harness(source))
+ }
+ tinyflows_bus::runs::CodeLanguage::Python => {
+ ("script.py", "python3", python_harness(source))
+ }
};
let script_path = work_dir.join(script_name);
let input_path = work_dir.join("input.json");