Skip to content

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

FieldPurposeGuidance
NameUnique identifier

Short name uniquely identifying the webhook destination.

DescriptionUsage notes

Optional.

MeshExecution graph target

Choose the mesh this webhook will invoke.

IntentEntry point within mesh

Select intent with appropriate input schema.

Mesh version labelVersion snapshot targeting

The label of the version to invoke, for example latest or production. Point production webhooks at a label, not the draft.

Handler

FieldPurposeGuidance
HandlerCode 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.

ScriptJavaScript source

An ES module that exports handle(request, config, secrets), up to 100 KB. It runs with no network access, timers or Node modules.

Handler Configuration VariablesValues the handler reads

Name and value pairs the handler reads with config.get(name). The configuration API returns them, so put signing keys in Handler Secrets.

Handler SecretsValues the handler reads but no one can read back

Name and value pairs the handler reads with secrets.get(name), such as a signing key. Saved values are never shown. Type a new value to replace one.

Recent callsWhat 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

  1. External system issues POST with JSON body matching the Intent input schema.
  2. Server creates a Conversation and a new top level Request tied to the Intent Agent Version.
  3. The HTTP response returns a lightweight acknowledgement.
  4. 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:

handleThe sender getsThe mesh
Returns nothing, undefined or null200Parses 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 memory500Starts 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

CallReturns
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-Authorization and Cookie are 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 is rejected(rejection), with a status and a message, or failed(string). secrets in JavaScript reads the secrets through config.
  • It imports one interface, types: the request resource, with the methods in the table above; the config resource, with get and secret; log, for console; unix-time-micros, for the clock; and random-bytes, for crypto. It imports nothing from WASI.

Limits

LimitValue
Script100 KB
Request body1 MB, with or without a handler. The body a handler sets is also at most 1 MB.
Time1 second for each request, including loading the script. When you host Partite Mesh yourself, WEBHOOK_HANDLER_CALL_TIMEOUT sets it.
Memory8 MB of JavaScript heap, enough to parse a 1 MB JSON body
Stack256 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 handler2 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 check2 MB, counting the body each time it is named. The other checks take any amount, within the time limit.
Rejection messageThe 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:

ConcernMitigation
URL GuessingGenerated key is high entropy; treat it as a secret. Do not expose in public docs or client side code.
Replay or floodOptionally 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 inputEnsure 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 injectionKeep the input schema minimal. Avoid allowing large free form instruction fields unless necessary.
Extraneous dataReject 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:

  1. Create destination pointing to staging label.
  2. Send test events; validate outcomes.
  3. Reconfigure (or recreate) destination to point to prod once 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.