Let outside services and computers' browser notifications give bots work
A bot hook (bot_hooks) is a secret URL, POST /api/hooks/<token>, whose calls queue the hook's brief plus the raw body as a task, per user and bot like a routine. Only the token's hash is kept (shown once, rotatable); an optional HMAC-SHA256 signing secret is stored encrypted. Calls are rate limited per address and per hook, recorded in bot_hook_events (pruned daily), deduplicated by delivery id, and a call while the last run still waits joins its brief instead of queueing another. The payload is fenced data and HookRunNote tells the bot never to take instructions from it; failed runs retry like routines. A hook can instead watch a computer's browser notifications: the app installs a small watcher that owns org.freedesktop.Notifications on the sandbox's session bus, so Chrome hands it every notification (it only looks for that service at start-up, so Chrome is restarted once, never mid-task), and it posts each one to its hooks, optionally filtered. Computers reach the app at COMPUTER_APP_URL or the app container's name. Users make hooks in the conversation's Hooks modal and manage them all on /admin/routines; bots never create or change hooks. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
/**
|
||||
* What calls a hook: an outside service at its URL, or the watcher on a
|
||||
* computer forwarding that computer's browser notifications
|
||||
* (`syncComputerNotifyWatch`).
|
||||
*/
|
||||
export const BotHookSources = [
|
||||
{ title: "Calls to its URL", value: "url" },
|
||||
{ title: "Browser notifications on a computer", value: "browser_notifications" },
|
||||
] as const;
|
||||
|
||||
export type BotHookSource = (typeof BotHookSources)[number]["value"];
|
||||
|
||||
/**
|
||||
* How a hook's sender writes its HMAC-SHA256 signature of the raw body in
|
||||
* the signature header: plain hex, GitHub's `sha256=<hex>`, or base64
|
||||
* (Shopify and others).
|
||||
*/
|
||||
export const BotHookSignatureFormats = [
|
||||
{ title: "Hex", value: "hex" },
|
||||
{ title: "sha256=hex (GitHub)", value: "sha256=hex" },
|
||||
{ title: "Base64", value: "base64" },
|
||||
] as const;
|
||||
|
||||
export type BotHookSignatureFormat = (typeof BotHookSignatureFormats)[number]["value"];
|
||||
|
||||
/**
|
||||
* What became of one call to a hook: it queued a run, joined a run still
|
||||
* waiting, was refused (a bad signature, a paused hook), repeated a call
|
||||
* already taken, or was a notification the hook's filter left out.
|
||||
*/
|
||||
export const BotHookEventStatuses = [
|
||||
{ title: "Queued", value: "queued" },
|
||||
{ title: "Merged", value: "merged" },
|
||||
{ title: "Rejected", value: "rejected" },
|
||||
{ title: "Duplicate", value: "duplicate" },
|
||||
{ title: "Ignored", value: "ignored" },
|
||||
] as const;
|
||||
|
||||
export type BotHookEventStatus = (typeof BotHookEventStatuses)[number]["value"];
|
||||
|
||||
/**
|
||||
* Every hook token starts with this, so a leaked one is easy to spot.
|
||||
*/
|
||||
export const BotHookTokenPrefix = "cbh_";
|
||||
|
||||
/**
|
||||
* The public path a hook is called at: `<BotHookPath>/<token>`.
|
||||
*/
|
||||
export const BotHookPath = "/api/hooks";
|
||||
|
||||
/**
|
||||
* Headers a sender may use to name a delivery, so a retried call isn't
|
||||
* run twice. The first one present wins.
|
||||
*/
|
||||
export const BotHookIdempotencyHeaders = [
|
||||
"idempotency-key",
|
||||
"x-github-delivery",
|
||||
"x-request-id",
|
||||
"x-webhook-id",
|
||||
] as const;
|
||||
Reference in New Issue
Block a user