Skip to content

An open-source, faster Devin alternative

TypeScript

Agent webhooks: the URL carries the credential; provider bodies and delivery ids pass through

Igor Zalutski3e480a718fd9
diff --git a/cli/src/commands.ts b/cli/src/commands.ts
index d7753add..5390b97f 100644
--- a/cli/src/commands.ts
+++ b/cli/src/commands.ts
@@ -1408,8 +1408,9 @@ export async function runCommand(
`${existing ? "Reused" : "Created"} ${webhook.name} (${webhook.id}) for ${agentId}@${environment}.\n` +
`URL: ${webhook.invocationUrl}\n` +
(existing
- ? "The existing token remains unchanged.\n"
- : `Token: ${webhook.token ?? "unavailable"}\nSave this token now. It will not be shown again.\n`),
+ ? "The existing token remains unchanged; this URL omits it.\n"
+ : `Token: ${webhook.token ?? "unavailable"}\n` +
+ "Save this URL now. It carries the token and will not be shown again.\n"),
);
}
return;
@@ -1442,8 +1443,9 @@ export async function runCommand(
else {
process.stdout.write(
`Rotated the token for ${webhook.name}.\n` +
+ `URL: ${webhook.invocationUrl}\n` +
`Token: ${webhook.token ?? "unavailable"}\n` +
- "Save this token now. The previous token no longer works.\n",
+ "Save this URL now. The previous token and URL no longer work.\n",
);
}
return;
diff --git a/cloudflare-workers/api-edge/src/managed_agents.test.ts b/cloudflare-workers/api-edge/src/managed_agents.test.ts
index d52d6614..78f3378a 100644
--- a/cloudflare-workers/api-edge/src/managed_agents.test.ts
+++ b/cloudflare-workers/api-edge/src/managed_agents.test.ts
@@ -365,6 +365,78 @@ describe("managed agents proxy", () => {
expect(JSON.stringify(body)).not.toContain("internal");
});
+ it("forwards a URL-credential delivery with the provider's delivery id and no bearer header", async () => {
+ const sentryBody = {
+ action: "triggered",
+ data: { event: { event_id: "a".repeat(32) } },
+ installation: { uuid: "inst" },
+ };
+ const fetchSpy = vi.fn(
+ async (target: URL | RequestInfo, init?: RequestInit) => {
+ expect(String(target)).toBe(
+ "https://managedagents.test/v1/agent-webhooks/wh_0123456789abcdef0123456789abcdef/ocwh_token-segment_0123456789",
+ );
+ const headers = new Headers(init?.headers);
+ expect(headers.get("authorization")).toBeNull();
+ expect(headers.get("request-id")).toBe("sentry-delivery-1");
+ expect(headers.get("sentry-hook-resource")).toBeNull();
+ expect(await new Response(init?.body).json()).toEqual(sentryBody);
+ return Response.json({
+ request: {
+ id: "whr_request",
+ webhookId: "wh_0123456789abcdef0123456789abcdef",
+ projectId: "prj_test",
+ environment: "development",
+ agentId: "oncall",
+ sessionId: "session_pending",
+ outcome: "pending",
+ attempt: 0,
+ createdAt: "2026-09-08T00:00:00.000Z",
+ updatedAt: "2026-09-08T00:00:00.000Z",
+ },
+ }, { status: 202 });
+ },
+ );
+ vi.stubGlobal("fetch", fetchSpy);
+
+ const response = await handleAgentWebhookInvocation(
+ new Request(
+ "https://app.opencomputer.dev/api/agent-webhooks/wh_0123456789abcdef0123456789abcdef/ocwh_token-segment_0123456789",
+ {
+ method: "POST",
+ headers: {
+ "content-type": "application/json",
+ "request-id": "sentry-delivery-1",
+ "sentry-hook-resource": "event_alert",
+ },
+ body: JSON.stringify(sentryBody),
+ },
+ ),
+ { MANAGED_AGENTS_API_URL: "https://managedagents.test" },
+ );
+
+ expect(response.status).toBe(202);
+ await expect(response.json()).resolves.toMatchObject({
+ request: { sessionId: "session_pending", outcome: "pending" },
+ sessionUrl:
+ "https://app.opencomputer.dev/projects/prj_test/sessions/session_pending?agent=oncall&environment=development",
+ });
+ });
+
+ it("rejects a malformed path token before reaching the backend", async () => {
+ const fetchSpy = vi.fn();
+ vi.stubGlobal("fetch", fetchSpy);
+ const response = await handleAgentWebhookInvocation(
+ new Request(
+ "https://app.opencomputer.dev/api/agent-webhooks/wh_0123456789abcdef0123456789abcdef/bad%20token",
+ { method: "POST", headers: { "content-type": "application/json" }, body: "{}" },
+ ),
+ {},
+ );
+ expect(response.status).toBe(404);
+ expect(fetchSpy).not.toHaveBeenCalled();
+ });
+
it("rejects webhook calls without bearer credentials", async () => {
const fetchSpy = vi.fn();
vi.stubGlobal("fetch", fetchSpy);
diff --git a/cloudflare-workers/api-edge/src/managed_agents.ts b/cloudflare-workers/api-edge/src/managed_agents.ts
index 5d1f868f..678b5da0 100644
--- a/cloudflare-workers/api-edge/src/managed_agents.ts
+++ b/cloudflare-workers/api-edge/src/managed_agents.ts
@@ -476,9 +476,15 @@ function publicWebhook(
agentId: webhook.agentId,
name: webhook.name,
enabled: webhook.enabled,
+ // The token is the credential; when this response carries it (create,
+ // rotate), the URL carries it too and is shown once. Listings never do.
...(publicOrigin && id
? {
- invocationUrl: `${publicOrigin}/api/agent-webhooks/${encodeURIComponent(id)}`,
+ invocationUrl:
+ `${publicOrigin}/api/agent-webhooks/${encodeURIComponent(id)}` +
+ (typeof webhook.token === "string"
+ ? `/${encodeURIComponent(webhook.token)}`
+ : ""),
}
: {}),
...(typeof webhook.token === "string" ? { token: webhook.token } : {}),
@@ -1340,12 +1346,21 @@ export async function handleManagedAgentChannelConnection(
});
}
+const WEBHOOK_DELIVERY_ID_HEADERS = [
+ "idempotency-key",
+ "request-id",
+ "x-github-delivery",
+ "svix-id",
+] as const;
+
export async function handleAgentWebhookInvocation(
request: Request,
env: ManagedAgentsEnv,
): Promise<Response> {
const url = new URL(request.url);
- const match = url.pathname.match(/^\/api\/agent-webhooks\/([^/]+)$/);
+ const match = url.pathname.match(
+ /^\/api\/agent-webhooks\/([^/]+)(?:\/([^/]+))?$/,
+ );
if (!match?.[1] || request.method !== "POST") {
return Response.json(
{ error: { code: "not_found", message: "Webhook not found." } },
@@ -1353,14 +1368,20 @@ export async function handleAgentWebhookInvocation(
);
}
const webhookId = match[1];
- if (!/^wh_[a-f0-9]{32}$/.test(webhookId)) {
+ const pathToken = match[2];
+ if (
+ !/^wh_[a-f0-9]{32}$/.test(webhookId) ||
+ (pathToken !== undefined && !/^[A-Za-z0-9_-]{16,128}$/.test(pathToken))
+ ) {
return Response.json(
{ error: { code: "not_found", message: "Webhook not found." } },
{ status: 404 },
);
}
+ // The credential is the token: in the path, or as a bearer header for
+ // senders that can set one. Providers that can do neither use the URL.
const authorization = request.headers.get("authorization");
- if (!authorization?.startsWith("Bearer ")) {
+ if (!pathToken && !authorization?.startsWith("Bearer ")) {
return Response.json(
{
error: {
@@ -1375,7 +1396,8 @@ export async function handleAgentWebhookInvocation(
env.MANAGED_AGENTS_API_URL ?? DEFAULT_MANAGED_AGENTS_API_URL
).replace(/\/+$/, "");
const target = new URL(
- `${base}/v1/agent-webhooks/${encodeURIComponent(webhookId)}`,
+ `${base}/v1/agent-webhooks/${encodeURIComponent(webhookId)}` +
+ (pathToken ? `/${encodeURIComponent(pathToken)}` : ""),
);
if (target.protocol !== "https:" && target.hostname !== "localhost") {
return Response.json(
@@ -1389,12 +1411,16 @@ export async function handleAgentWebhookInvocation(
);
}
const headers = new Headers({
- authorization,
"content-type": request.headers.get("content-type") ?? "application/json",
"x-request-id": crypto.randomUUID(),
});
- const idempotencyKey = request.headers.get("idempotency-key");
- if (idempotencyKey) headers.set("idempotency-key", idempotencyKey);
+ if (authorization) headers.set("authorization", authorization);
+ // Delivery identity, in the backend's order of precedence: the caller's
+ // key, else the delivery id a provider sends.
+ for (const header of WEBHOOK_DELIVERY_ID_HEADERS) {
+ const value = request.headers.get(header);
+ if (value) headers.set(header, value);
+ }
try {
const upstream = await fetch(target, {
method: "POST",
diff --git a/docs/agents/webhooks.mdx b/docs/agents/webhooks.mdx
index 6f969402..7b6f6127 100644
--- a/docs/agents/webhooks.mdx
+++ b/docs/agents/webhooks.mdx
@@ -14,8 +14,9 @@ webhook URL.
## Create a webhook
Open an agent's **Webhooks** tab, select Development or Production, and choose
-**Create webhook**. The dashboard shows the bearer token once. Store it in the
-calling service's secret store.
+**Create webhook**. The dashboard shows the webhook URL once. The URL carries
+the credential: store it in the calling service's secret store, and treat it
+as you would a token.
The CLI supports the same lifecycle:
@@ -31,16 +32,15 @@ opencomputer webhooks rotate-token <webhook-id>
opencomputer webhooks remove <webhook-id>
```
-Rotation invalidates the previous token immediately. List output never
-contains a token.
+`create` and `rotate-token` print the URL with its token once. Rotation
+invalidates the previous URL immediately. `list` prints URLs without tokens.
## Invoke it
-Send `POST` with `application/json` and the token as a bearer credential:
+Send `POST` with `application/json` to the URL:
```bash
-curl -X POST 'https://app.opencomputer.dev/api/agent-webhooks/wh_...' \
- -H 'Authorization: Bearer <token>' \
+curl -X POST 'https://app.opencomputer.dev/api/agent-webhooks/wh_.../ocwh_...' \
-H 'Content-Type: application/json' \
-H 'Idempotency-Key: delivery-123' \
-d '{
@@ -52,14 +52,29 @@ curl -X POST 'https://app.opencomputer.dev/api/agent-webhooks/wh_...' \
}'
```
-At least one of `text` or `payload` is required. `text` becomes the initial
-turn prompt. `payload` remains structured JSON available to the agent. The
-response is HTTP 202 with the request, session ID, and dashboard session URL;
-the agent continues asynchronously.
-
-Use a unique `Idempotency-Key` for each upstream delivery. Retrying the same
-body with the same key returns the original request and session instead of
-starting another one.
+`text` becomes the initial turn prompt. `payload` remains structured JSON
+available to the agent. A body with neither key is delivered whole as
+`payload`, so a provider such as Sentry, GitHub, or Stripe can point its
+webhook at the URL directly; the prompt is then `Webhook <name> invoked`.
+Bodies are limited to 256 KiB.
+
+A sender that sets headers may omit the last path segment and send the token
+as `Authorization: Bearer <token>` instead. Both forms verify the same
+credential.
+
+The response is HTTP 202 with the request, session ID, and dashboard session
+URL. It is sent as soon as the delivery is stored; the session starts
+afterwards, so the response arrives within Sentry's and GitHub's timeouts.
+The request's `outcome` is `pending` in the response and becomes `accepted`
+once the session is running, or `failed` after the platform has retried the
+start for about forty minutes. The dashboard's Webhooks tab lists requests
+with their outcomes.
+
+Each delivery needs an identity so that a retry does not start a second
+session. OpenComputer uses the first present of `Idempotency-Key`,
+`Request-ID` (Sentry), `X-GitHub-Delivery`, and `Svix-Id`. Retrying the same
+body with the same identity returns the original request and session; if
+that request had failed to start, the retry starts it again.
## Read webhook input
@@ -89,5 +104,21 @@ Use payload fields such as `mode` for business behavior. `input.source` is
`"webhook"` and `input.webhook` contains the webhook ID, request ID, and receive
time for provenance and correlation.
+## Provider deliveries
+
+A provider body arrives unchanged as `input.payload`. Narrow it to what the
+agent needs; for a Sentry issue alert that is the event under `data.event`:
+
+```tsx
+const payload = (input.payload ?? {}) as {
+ data?: { event?: { event_id?: string; release?: string } };
+};
+const event = payload.data?.event;
+```
+
+Configure the provider with the full webhook URL. Sentry's internal
+integrations and GitHub repository webhooks accept it as is; both send a
+delivery id header that OpenComputer uses as the request identity.
+
Development and Production webhooks have separate URLs, tokens, and sessions.
Disable or remove a webhook when its caller should no longer start sessions.
diff --git a/web/src/managed-agents/Webhooks.tsx b/web/src/managed-agents/Webhooks.tsx
index d60c79dd..c0b5e8ef 100644
--- a/web/src/managed-agents/Webhooks.tsx
+++ b/web/src/managed-agents/Webhooks.tsx
@@ -38,10 +38,12 @@ function formatDate(value?: string) {
return value ? new Date(value).toLocaleString() : 'Never'
}
+// The URL carries the token, so a request needs no credential header. Any
+// JSON object is accepted; one without `text` or `payload` is delivered whole
+// as the agent's payload.
function curlCommand(webhook: ManagedAgentWebhook) {
return [
`curl -X POST '${webhook.invocationUrl}' \\`,
- ` -H 'Authorization: Bearer ${webhook.token ?? '<token>'}' \\`,
" -H 'Content-Type: application/json' \\",
" -H 'Idempotency-Key: <unique-request-id>' \\",
` -d '{"text":"Run this workflow","payload":{"mode":"default"}}'`,
@@ -249,7 +251,8 @@ export function ManagedAgentWebhooks({
<DialogTitle>Create webhook</DialogTitle>
<DialogDescription>
This webhook will trigger {agentName} in {environment}. Give the
- ingress point a name; its bearer token is shown once.
+ ingress point a name; its URL, which carries the credential, is
+ shown once.
</DialogDescription>
</DialogHeader>
<div className="space-y-2">
@@ -283,14 +286,20 @@ export function ManagedAgentWebhooks({
>
<DialogContent className="max-w-2xl">
<DialogHeader>
- <DialogTitle>Save this webhook token</DialogTitle>
+ <DialogTitle>Save this webhook URL</DialogTitle>
<DialogDescription>
- OpenComputer stores only its hash, so this token cannot be shown
- again. Rotating it invalidates the previous token.
+ The URL carries the credential and OpenComputer stores only its
+ hash, so it cannot be shown again. Rotating the token invalidates
+ this URL. Senders that set headers may instead call the URL
+ without its last segment with the token as a bearer credential.
</DialogDescription>
</DialogHeader>
{credentials?.token ? (
<div className="space-y-4">
+ <div className="space-y-2">
+ <Label>Webhook URL</Label>
+ <CopyRow value={credentials.invocationUrl} maskable />
+ </div>
<div className="space-y-2">
<Label>Token</Label>
<CopyRow value={credentials.token} maskable />