Webhook Destinations
Webhook Destinations allow external systems to trigger a Mesh Intent by making a simple HTTP POST to a unique URL. They are ideal for event driven or scheduled automation scenarios where you want a Mesh to react autonomously without a human manually starting a conversation.
Quick Reference
Configuration
| Field | Purpose | Guidance |
|---|---|---|
| Name | Unique identifier | Short name uniquely identifying the webhook destination. |
| Description | Usage notes | Optional. |
| Mesh | Execution graph target | Choose the mesh this webhook will invoke. |
| Intent | Entry point within mesh | Select intent with appropriate input schema. |
| Mesh version label | Version snapshot targeting | The label of the version to invoke, for example |
Handler
| Field | Purpose | Guidance |
|---|---|---|
| Handler | Code that runs on each request | Optional. Press Add handler to add one. A handler is JavaScript. Without one, requests go to the mesh as they arrive. A handler can check each one first, reject it, or rewrite its body. See Handlers. |
| Script | JavaScript source | An ES module that exports |
| Handler Configuration Variables | Values the handler reads | Name and value pairs the handler reads with |
| Handler Secrets | Values the handler reads but no one can read back | Name and value pairs the handler reads with |
| Recent calls | What the handler did | The five newest requests the handler ran on, with the outcome, what the sender got, the handler’s output and the request. See Trying a handler. |
Overview
When you create a Webhook Destination you create a new, unique URL that can be used to invoke a mesh.
The resulting URL looks conceptually like:
https://api.partite.ai/webhooks/<unique-key>Self hosted deployments use your local base URL (for example http://localhost:8080/webhooks/<generated-key>). The caller performs a JSON POST. The body must conform to the Intent input message schema (exact field names, required fields, types, descriptions leveraged for agent context). If validation fails a 4xx error is returned and no conversation is started.
Execution Flow
- External system issues
POSTwith JSON body matching the Intent input schema. - Server creates a Conversation and a new top level Request tied to the Intent Agent Version.
- The HTTP response returns a lightweight acknowledgement.
- The Mesh processes the Request: agents may call tools, sub agents, transfer control, etc. This happens asynchronously to acknowledging receipt of the request.
Handlers
A handler is a short JavaScript program that runs on each request before the mesh sees it. Use a handler to check a signature, reject events you don’t want, or rewrite the body into the input schema of the intent. Without a handler, the request body goes to the mesh as it is.
To add one, open the destination and press Add handler under Handler. Write the script in the editor, add the values it reads under Handler Configuration Variables and Handler Secrets, and save. With Terraform, set handler on partiteai_webhook_destination, with source_path naming the script file.
Saving checks the script’s syntax and that the modules it imports exist. It runs none of the script, so a missing handle function or an error in the script’s top level shows only when a request arrives.
Writing a handler
A handler is one ES module of at most 100 KB. There is no build step: the mesh runs the script you save in a JavaScript engine (QuickJS) compiled to WebAssembly.
The module exports handle(request, config, secrets): as an export named handle, as the default export, or as a handle method of the default export. handle may be async, but the promise it returns must settle without waiting on a timer or the network, since a handler has neither.
What handle does decides what happens to the request:
handle | The sender gets | The mesh |
|---|---|---|
Returns nothing, undefined or null | 200 | Parses the body as JSON and starts a conversation. The body must be a JSON object that fits the intent’s input schema. If it isn’t, the sender gets 400 instead. |
Returns { status, message } | That status and the first 1 KB of the message. A status outside 400 to 599 becomes 400. | Starts nothing. |
| Throws, or runs out of time or memory | 500 | Starts nothing. The error is kept in Recent calls and not sent. |
A handler can import only buffer (or node:buffer). To use an npm package, bundle it into the script as one ES module, and keep the result under 100 KB. The package must not need Node modules, timers or fetch.
The request, config and secrets objects
| Call | Returns |
|---|---|
request.method() | The HTTP method. |
request.url() | The full URL the sender used. |
request.header(name) | The first value of the header, or undefined. The name is not case-sensitive. |
request.headers() | Every header, as a list of [name, value] pairs. |
request.body() | The body, as a Uint8Array. |
request.setBody(body) | Replaces the body the mesh gets. Takes bytes, or a string, which is sent as UTF-8. |
request.verifyHmac(alg, key, signedData, expected) | true when the HMAC of the signed data equals expected, compared in constant time. alg is sha1, sha256 or sha512. |
request.verifySignature(alg, publicKey, signedData, signature) | true when the signature of the signed data is good. alg is ed25519, ecdsa-p256-sha256, rsa-pkcs1-sha256 or rsa-pss-sha256. |
config.get(name) | A value from Handler Configuration Variables, or undefined. |
secrets.get(name) | A value from Handler Secrets, or undefined. |
signedData is the list of pieces that the sender signed, in order. Each piece is { tag: "bytes", val: Uint8Array } or { tag: "body" }, which stands for the request body. The check runs in the mesh, so the body isn’t copied into the handler for it.
Keys, expected values and signatures are bytes, such as a Uint8Array or a Buffer. A public key is an SPKI key as DER or PEM, a PKCS #1 RSA key, or the raw 32 bytes of an ed25519 key. An RSA key is at most 8192 bits. An ecdsa signature is ASN.1 DER, or the raw 64 bytes of r and s.
Use secrets for values such as signing keys. The configuration API returns only their names, never their values. Config values are returned, so don’t put secrets there.
These globals are available: console, TextEncoder and TextDecoder (UTF-8 only), atob, btoa, URL, URLSearchParams, crypto.getRandomValues, crypto.randomUUID and Buffer. There are no other Node modules, no timers and no fetch. A handler has no network or file access.
Each request starts from a clean state. Globals a script sets during one request are gone in the next.
Examples
This handler checks a GitHub signature, then keeps one field of the body:
export function handle(request, config, secrets) {
const header = request.header("X-Hub-Signature-256") ?? "";
const expected = Buffer.from(header.slice(7), "hex");
const key = new TextEncoder().encode(secrets.get("secret"));
if (!request.verifyHmac("sha256", key, [{ tag: "body" }], expected)) {
return { status: 401, message: "bad signature" };
}
const event = JSON.parse(new TextDecoder().decode(request.body()));
request.setBody(JSON.stringify({ action: event.action }));
}Some senders sign more than the body. Stripe signs the timestamp, a period and the body, and sends them in the Stripe-Signature header as t=...,v1=...:
export function handle(request, config, secrets) {
const fields = (request.header("Stripe-Signature") ?? "").split(",");
const t = fields.find((f) => f.startsWith("t="))?.slice(2);
const signatures = fields.filter((f) => f.startsWith("v1=")).map((f) => f.slice(3));
if (!t || signatures.length === 0) {
return { status: 400, message: "missing signature" };
}
if (Math.abs(Date.now() / 1000 - Number(t)) > 300) {
return { status: 400, message: "timestamp too old" };
}
const key = new TextEncoder().encode(secrets.get("signing_secret"));
const signed = [{ tag: "bytes", val: new TextEncoder().encode(t + ".") }, { tag: "body" }];
const good = signatures.some((s) => request.verifyHmac("sha256", key, signed, Buffer.from(s, "hex")));
if (!good) {
return { status: 401, message: "bad signature" };
}
}Trying a handler
Send a request to the destination’s URL, for example:
curl -X POST -H "Content-Type: application/json" -d '{"action": "opened"}' <webhook URL>Then open Recent calls on the destination’s page and refresh it. It shows the five newest requests the handler ran on, each with:
- The outcome: Accepted, Rejected (the handler refused it), Failed (the handler threw, ran out of time, or its script didn’t load) or Undelivered (the handler accepted it and the mesh refused the body).
- The status and message the sender got, and the error the sender didn’t see.
- What the handler wrote with
console, up to 16 KB. - The request: its headers, then as much of the body as fits in 64 KB. The values of
Authorization,Proxy-AuthorizationandCookieare hidden. - A link to the trace of the conversation, when the call was accepted.
Requests refused before the handler runs, such as a body over 1 MB, aren’t listed. A mesh with cloud config doesn’t keep calls: it writes each one to its log.
The handler interface
The JavaScript objects above are the WIT world script-webhook-handler of the package partite:webhook@0.1.0, in webhook.wit. The mesh embeds the JavaScript engine that implements it. You can’t upload a WebAssembly handler of your own.
- The handler exports
handle(request, config) -> result<_, handle-error>. The error isrejected(rejection), with astatusand amessage, orfailed(string).secretsin JavaScript reads the secrets throughconfig. - It imports one interface,
types: therequestresource, with the methods in the table above; theconfigresource, withgetandsecret;log, forconsole;unix-time-micros, for the clock; andrandom-bytes, forcrypto. It imports nothing from WASI.
Limits
| Limit | Value |
|---|---|
| Script | 100 KB |
| Request body | 1 MB, with or without a handler. The body a handler sets is also at most 1 MB. |
| Time | 1 second for each request, including loading the script. When you host Partite Mesh yourself, WEBHOOK_HANDLER_CALL_TIMEOUT sets it. |
| Memory | 8 MB of JavaScript heap, enough to parse a 1 MB JSON body |
| Stack | 256 KB. Deeper recursion, or a JSON.parse of a body nested too deeply, throws a RangeError the script can catch. |
| Data passed between the mesh and the handler | 2 MB in any one piece, such as a rejection message, a console.log line or the signed data of a check |
Signed data of an ed25519 check | 2 MB, counting the body each time it is named. The other checks take any amount, within the time limit. |
| Rejection message | The first 1 KB is sent. |
Each handler call that runs reserves the memory of one JavaScript instance from a budget that the calls share. A request that finds no room waits up to 2 seconds, then gets 503 with Retry-After: 1. When you host Partite Mesh yourself, WEBHOOK_HANDLER_MEMORY_BUDGET_MB sets the budget, 1024 MB by default.
On the hosted service, each server has a budget of 128 MB, and one organization runs at most 4 handler calls at once on each server. A request past that waits up to 2 seconds, then gets 429 with Retry-After: 1.
Use Cases
- Event bridging: Forward SaaS webhooks (GitHub issue created, PagerDuty incident, Stripe dispute) into a Mesh for analysis or enrichment.
- Scheduled automation: A cron job hits the destination daily to generate a report (Mesh agents fetch data via MCP tools and synthesize structured output).
- Data ingestion and classification: Low latency classification of incoming items before they enter a pipeline.
- Autonomous follow ups: Trigger a Mesh to draft and send responses, create tickets, or open PRs after external events (ensure separation of capabilities, see Security).
Security Considerations
Webhook Destinations intentionally trade simplicity (just a URL + JSON) for limited built in auth controls:
| Concern | Mitigation |
|---|---|
| URL Guessing | Generated key is high entropy; treat it as a secret. Do not expose in public docs or client side code. |
| Replay or flood | Optionally place an API gateway or reverse proxy in front to rate limit and log. A handler can verify an HMAC or signature before the mesh runs. |
| Untrusted input | Ensure the Intent agent is not simultaneously granted tools that can perform sensitive state changes and access sensitive data (avoid the lethal trifecta). Use a validation or sanitization sub agent via a Call Link before action agents. |
| Prompt injection | Keep the input schema minimal. Avoid allowing large free form instruction fields unless necessary. |
| Extraneous data | Reject unneeded fields early. Schema enforcement keeps the prompt small and reduces opportunity for injection. |
Operational best practices:
- Rotate (regenerate) destination keys if you suspect exposure (delete and recreate the destination).
- Maintain an allowlist of source IP addresses at your edge if feasible.
- Log request IDs and Mesh version label for trace correlation (associate external event ID with Conversation ID).
Versioning Strategy Interaction
Point Webhook Destinations at a Mesh version label (prod, staging) to decouple rollout from external integrations. Workflow:
- Create destination pointing to
staginglabel. - Send test events; validate outcomes.
- Reconfigure (or recreate) destination to point to
prodonce label updated.
Avoid pointing high volume production webhooks to the Draft Mesh unless actively testing. The Draft may change mid processing.
Summary
Webhook Destinations provide a lightweight, structured bridge from external events into your Mesh. By pairing a unique URL with a strongly typed Intent input schema and a labeled Mesh version you gain predictable invocation, safe evolution (via labels) and clear observability. Keep schemas lean, enforce grounding where accuracy matters, and partition agent capabilities to maintain security.