Skip to content

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

fix(webhooks): handle missing event type in webhook payload

Steven Enamakel2de3bd4aab28
diff --git a/crates/openhuman-tinyhumans/src/hosted/webhooks/mod.rs b/crates/openhuman-tinyhumans/src/hosted/webhooks/mod.rs
new file mode 100644
index 0000000000..8527ccdeb1
--- /dev/null
+++ b/crates/openhuman-tinyhumans/src/hosted/webhooks/mod.rs
@@ -0,0 +1,16 @@
+//! Backend-managed webhook tunnels (`/webhooks/core*`): tunnel CRUD and the
+//! remaining bandwidth budget, on the SDK's typed `webhooks()` client.
+//!
+//! The RPC names (`openhuman.webhooks_{list,create,get,update,delete}_tunnel`,
+//! `openhuman.webhooks_get_bandwidth`) are unchanged wire contracts. They share
+//! the `webhooks` namespace with the core's local webhook router controllers
+//! (`list_registrations`, `register_echo`, `trigger_agent`, …), which stay in
+//! the core because they route inbound deliveries to skills and agents.
+
+mod ops;
+mod schemas;
+
+pub use ops::*;
+pub use schemas::{
+ all_webhooks_controller_schemas, all_webhooks_registered_controllers, webhooks_schemas,
+};
diff --git a/crates/openhuman-tinyhumans/src/hosted/webhooks/ops.rs b/crates/openhuman-tinyhumans/src/hosted/webhooks/ops.rs
new file mode 100644
index 0000000000..e0f9868dab
--- /dev/null
+++ b/crates/openhuman-tinyhumans/src/hosted/webhooks/ops.rs
@@ -0,0 +1,107 @@
+//! Webhook tunnel RPC ops — thin adapters over the SDK's `webhooks()` client.
+//!
+//! Every call authenticates with the core's resolved backend credential
+//! ([`HostedClient`]); the backend owns tunnel ownership and quotas. Input
+//! validation runs before the credential is resolved.
+
+use serde_json::Value;
+use tinyhumans_sdk::api::webhooks::{CreateWebhookTunnelRequest, UpdateWebhookTunnelRequest};
+
+use openhuman_core::config::Config;
+use openhuman_core::rpc::RpcOutcome;
+
+use crate::hosted::client::HostedClient;
+
+fn require_id(id: &str) -> Result<&str, String> {
+ let id = id.trim();
+ if id.is_empty() {
+ return Err("id is required".to_string());
+ }
+ Ok(id)
+}
+
+/// `GET /webhooks/core` — the user's tunnels.
+pub async fn list_tunnels(config: &Config) -> Result<RpcOutcome<Value>, String> {
+ let client = HostedClient::from_config(config)?;
+ let data = client.finish_value(
+ "GET /webhooks/core",
+ client.sdk().webhooks().list_tunnels().await,
+ )?;
+ Ok(RpcOutcome::single_log(data, "webhook tunnels fetched"))
+}
+
+/// `POST /webhooks/core`. `name` is trimmed and required; a blank
+/// `description` is dropped rather than sent.
+pub async fn create_tunnel(
+ config: &Config,
+ name: &str,
+ description: Option<String>,
+) -> Result<RpcOutcome<Value>, String> {
+ let name = name.trim();
+ if name.is_empty() {
+ return Err("name is required".to_string());
+ }
+ let request = CreateWebhookTunnelRequest {
+ name: name.to_string(),
+ description: description
+ .map(|d| d.trim().to_string())
+ .filter(|d| !d.is_empty()),
+ };
+ let client = HostedClient::from_config(config)?;
+ let data = client.finish_value(
+ "POST /webhooks/core",
+ client.sdk().webhooks().create_tunnel(&request).await,
+ )?;
+ Ok(RpcOutcome::single_log(data, "webhook tunnel created"))
+}
+
+/// `GET /webhooks/core/{id}`.
+pub async fn get_tunnel(config: &Config, id: &str) -> Result<RpcOutcome<Value>, String> {
+ let id = require_id(id)?;
+ let client = HostedClient::from_config(config)?;
+ let data = client.finish_value(
+ "GET /webhooks/core/{id}",
+ client.sdk().webhooks().get_tunnel(id).await,
+ )?;
+ Ok(RpcOutcome::single_log(data, "webhook tunnel fetched"))
+}
+
+/// `PATCH /webhooks/core/{id}`; omitted fields are left unchanged.
+pub async fn update_tunnel(
+ config: &Config,
+ id: &str,
+ request: UpdateWebhookTunnelRequest,
+) -> Result<RpcOutcome<Value>, String> {
+ let id = require_id(id)?;
+ let client = HostedClient::from_config(config)?;
+ let data = client.finish_value(
+ "PATCH /webhooks/core/{id}",
+ client.sdk().webhooks().update_tunnel(id, &request).await,
+ )?;
+ Ok(RpcOutcome::single_log(data, "webhook tunnel updated"))
+}
+
+/// `DELETE /webhooks/core/{id}`.
+pub async fn delete_tunnel(config: &Config, id: &str) -> Result<RpcOutcome<Value>, String> {
+ let id = require_id(id)?;
+ let client = HostedClient::from_config(config)?;
+ let data = client.finish_value(
+ "DELETE /webhooks/core/{id}",
+ client.sdk().webhooks().delete_tunnel(id).await,
+ )?;
+ Ok(RpcOutcome::single_log(data, "webhook tunnel deleted"))
+}
+
+/// `GET /webhooks/core/bandwidth` — the remaining bandwidth budget.
+pub async fn get_bandwidth(config: &Config) -> Result<RpcOutcome<Value>, String> {
+ let client = HostedClient::from_config(config)?;
+ let data = client.finish_value(
+ "GET /webhooks/core/bandwidth",
+ client.sdk().webhooks().get_bandwidth().await,
+ )?;
+ Ok(RpcOutcome::single_log(data, "webhook bandwidth fetched"))
+}
+
+#[cfg(test)]
+#[path = "ops_tests.rs"]
+mod tests;
diff --git a/crates/openhuman-tinyhumans/src/hosted/webhooks/schemas.rs b/crates/openhuman-tinyhumans/src/hosted/webhooks/schemas.rs
new file mode 100644
index 0000000000..adee182d44
--- /dev/null
+++ b/crates/openhuman-tinyhumans/src/hosted/webhooks/schemas.rs
@@ -0,0 +1,254 @@
+use serde::de::DeserializeOwned;
+use serde::Deserialize;
+use serde_json::{Map, Value};
+use tinyhumans_sdk::api::webhooks::UpdateWebhookTunnelRequest;
+
+use openhuman_core::config::rpc as config_rpc;
+use openhuman_core::core::all::{ControllerFuture, RegisteredController};
+use openhuman_core::core::{ControllerSchema, FieldSchema, TypeSchema};
+use openhuman_core::rpc::RpcOutcome;
+
+#[derive(Debug, Deserialize)]
+struct WebhookCreateTunnelParams {
+ name: String,
+ description: Option<String>,
+}
+
+#[derive(Debug, Deserialize)]
+struct WebhookTunnelIdParams {
+ id: String,
+}
+
+#[derive(Debug, Deserialize)]
+#[serde(rename_all = "camelCase")]
+struct WebhookUpdateTunnelParams {
+ id: String,
+ name: Option<String>,
+ description: Option<String>,
+ is_active: Option<bool>,
+}
+
+const FUNCTIONS: &[&str] = &[
+ "list_tunnels",
+ "create_tunnel",
+ "get_tunnel",
+ "update_tunnel",
+ "delete_tunnel",
+ "get_bandwidth",
+];
+
+pub fn all_webhooks_controller_schemas() -> Vec<ControllerSchema> {
+ FUNCTIONS.iter().map(|f| webhooks_schemas(f)).collect()
+}
+
+pub fn all_webhooks_registered_controllers() -> Vec<RegisteredController> {
+ vec![
+ RegisteredController {
+ schema: webhooks_schemas("list_tunnels"),
+ handler: handle_list_tunnels,
+ },
+ RegisteredController {
+ schema: webhooks_schemas("create_tunnel"),
+ handler: handle_create_tunnel,
+ },
+ RegisteredController {
+ schema: webhooks_schemas("get_tunnel"),
+ handler: handle_get_tunnel,
+ },
+ RegisteredController {
+ schema: webhooks_schemas("update_tunnel"),
+ handler: handle_update_tunnel,
+ },
+ RegisteredController {
+ schema: webhooks_schemas("delete_tunnel"),
+ handler: handle_delete_tunnel,
+ },
+ RegisteredController {
+ schema: webhooks_schemas("get_bandwidth"),
+ handler: handle_get_bandwidth,
+ },
+ ]
+}
+
+/// Schema for one hosted `webhooks.*` function (unchanged wire contract).
+pub fn webhooks_schemas(function: &str) -> ControllerSchema {
+ match function {
+ "list_tunnels" => ControllerSchema {
+ namespace: "webhooks",
+ function: "list_tunnels",
+ description: "List backend-managed webhook tunnels for the current user.",
+ inputs: vec![],
+ outputs: vec![json_output("result", "Webhook tunnel list.")],
+ },
+ "create_tunnel" => ControllerSchema {
+ namespace: "webhooks",
+ function: "create_tunnel",
+ description: "Create a backend-managed webhook tunnel.",
+ inputs: vec![
+ FieldSchema {
+ name: "name",
+ ty: TypeSchema::String,
+ comment: "Tunnel name.",
+ required: true,
+ },
+ FieldSchema {
+ name: "description",
+ ty: TypeSchema::Option(Box::new(TypeSchema::String)),
+ comment: "Optional tunnel description.",
+ required: false,
+ },
+ ],
+ outputs: vec![json_output("result", "Created webhook tunnel.")],
+ },
+ "get_tunnel" => ControllerSchema {
+ namespace: "webhooks",
+ function: "get_tunnel",
+ description: "Fetch a backend-managed webhook tunnel by id.",
+ inputs: vec![FieldSchema {
+ name: "id",
+ ty: TypeSchema::String,
+ comment: "Backend tunnel id.",
+ required: true,
+ }],
+ outputs: vec![json_output("result", "Webhook tunnel payload.")],
+ },
+ "update_tunnel" => ControllerSchema {
+ namespace: "webhooks",
+ function: "update_tunnel",
+ description: "Update a backend-managed webhook tunnel.",
+ inputs: vec![
+ FieldSchema {
+ name: "id",
+ ty: TypeSchema::String,
+ comment: "Backend tunnel id.",
+ required: true,
+ },
+ FieldSchema {
+ name: "name",
+ ty: TypeSchema::Option(Box::new(TypeSchema::String)),
+ comment: "Optional tunnel name.",
+ required: false,
+ },
+ FieldSchema {
+ name: "description",
+ ty: TypeSchema::Option(Box::new(TypeSchema::String)),
+ comment: "Optional tunnel description.",
+ required: false,
+ },
+ FieldSchema {
+ name: "isActive",
+ ty: TypeSchema::Option(Box::new(TypeSchema::Bool)),
+ comment: "Optional active flag.",
+ required: false,
+ },
+ ],
+ outputs: vec![json_output("result", "Updated webhook tunnel payload.")],
+ },
+ "delete_tunnel" => ControllerSchema {
+ namespace: "webhooks",
+ function: "delete_tunnel",
+ description: "Delete a backend-managed webhook tunnel.",
+ inputs: vec![FieldSchema {
+ name: "id",
+ ty: TypeSchema::String,
+ comment: "Backend tunnel id.",
+ required: true,
+ }],
+ outputs: vec![json_output("result", "Delete webhook tunnel result.")],
+ },
+ "get_bandwidth" => ControllerSchema {
+ namespace: "webhooks",
+ function: "get_bandwidth",
+ description: "Fetch the remaining webhook bandwidth budget.",
+ inputs: vec![],
+ outputs: vec![json_output("result", "Webhook bandwidth payload.")],
+ },
+ _ => ControllerSchema {
+ namespace: "webhooks",
+ function: "unknown",
+ description: "Unknown webhooks controller function.",
+ inputs: vec![],
+ outputs: vec![FieldSchema {
+ name: "error",
+ ty: TypeSchema::String,
+ comment: "Lookup error details.",
+ required: true,
+ }],
+ },
+ }
+}
+
+fn handle_list_tunnels(_params: Map<String, Value>) -> ControllerFuture {
+ Box::pin(async move {
+ let config = config_rpc::load_config_with_timeout().await?;
+ to_json(crate::hosted::webhooks::list_tunnels(&config).await?)
+ })
+}
+
+fn handle_create_tunnel(params: Map<String, Value>) -> ControllerFuture {
+ Box::pin(async move {
+ let config = config_rpc::load_config_with_timeout().await?;
+ let payload = deserialize_params::<WebhookCreateTunnelParams>(params)?;
+ to_json(
+ crate::hosted::webhooks::create_tunnel(&config, payload.name.trim(), payload.description)
+ .await?,
+ )
+ })
+}
+
+fn handle_delete_tunnel(params: Map<String, Value>) -> ControllerFuture {
+ Box::pin(async move {
+ let config = config_rpc::load_config_with_timeout().await?;
+ let payload = deserialize_params::<WebhookTunnelIdParams>(params)?;
+ to_json(crate::hosted::webhooks::delete_tunnel(&config, &payload.id).await?)
+ })
+}
+
+fn handle_get_tunnel(params: Map<String, Value>) -> ControllerFuture {
+ Box::pin(async move {
+ let config = config_rpc::load_config_with_timeout().await?;
+ let payload = deserialize_params::<WebhookTunnelIdParams>(params)?;
+ to_json(crate::hosted::webhooks::get_tunnel(&config, &payload.id).await?)
+ })
+}
+
+fn handle_update_tunnel(params: Map<String, Value>) -> ControllerFuture {
+ Box::pin(async move {
+ let config = config_rpc::load_config_with_timeout().await?;
+ let payload = deserialize_params::<WebhookUpdateTunnelParams>(params)?;
+ let request = UpdateWebhookTunnelRequest {
+ name: payload.name,
+ description: payload.description,
+ is_active: payload.is_active,
+ };
+ to_json(crate::hosted::webhooks::update_tunnel(&config, &payload.id, request).await?)
+ })
+}
+
+fn handle_get_bandwidth(_params: Map<String, Value>) -> ControllerFuture {
+ Box::pin(async move {
+ let config = config_rpc::load_config_with_timeout().await?;
+ to_json(crate::hosted::webhooks::get_bandwidth(&config).await?)
+ })
+}
+
+fn deserialize_params<T: DeserializeOwned>(params: Map<String, Value>) -> Result<T, String> {
+ serde_json::from_value(Value::Object(params)).map_err(|e| format!("invalid params: {e}"))
+}
+
+fn to_json<T: serde::Serialize>(outcome: RpcOutcome<T>) -> Result<Value, String> {
+ outcome.into_cli_compatible_json()
+}
+
+fn json_output(name: &'static str, comment: &'static str) -> FieldSchema {
+ FieldSchema {
+ name,
+ ty: TypeSchema::Json,
+ comment,
+ required: true,
+ }
+}
+
+#[cfg(test)]
+#[path = "schemas_tests.rs"]
+mod tests;