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:
2026-10-25 14:06:59 +01:00
co-authored by Claude Opus 5.5
parent a596722e59
commit bd9744043e
69 changed files with 3777 additions and 18 deletions
@@ -4,6 +4,10 @@ import dockerRequest from "./docker-request";
export type AppContainer = {
id: string;
/**
* Its name, which other containers on its networks resolve.
*/
name: string;
mounts: { Source: string; Destination: string }[];
networks: string[];
};
@@ -25,6 +29,7 @@ async function inspectSelf(): Promise<AppContainer | null> {
const res = await dockerRequest<{
Id: string;
Name?: string;
Mounts?: AppContainer["mounts"];
NetworkSettings?: { Networks?: Record<string, unknown> };
}>({ path: `/containers/${encodeURIComponent(os.hostname())}/json` });
@@ -35,6 +40,7 @@ async function inspectSelf(): Promise<AppContainer | null> {
return {
id: res.data.Id,
name: (res.data.Name || "").replace(/^\//, ""),
mounts: res.data.Mounts || [],
networks: Object.keys(res.data.NetworkSettings?.Networks || {}),
};
@@ -0,0 +1,29 @@
import { AppData } from "@/src/data/app-data";
import grabEnv from "@/src/functions/backend/db/envs/grab-env";
import dockerRequest from "./docker-request";
import grabAppContainer from "./grab-app-container";
/**
* Where a computer reaches this app (no trailing slash), for the hooks it
* calls: the `COMPUTER_APP_URL` app setting when set, else the app's
* container by name on the docker network, else (a dev server on the
* host) the computers' network gateway, which is the host. Null when
* none can be worked out.
*/
export default async function grabComputerAppUrl(): Promise<string | null> {
const setting = (await grabEnv({ key: "COMPUTER_APP_URL" }))?.trim().replace(/\/+$/, "");
if (setting) return setting;
const port = process.env.PORT || 7227;
const container = await grabAppContainer().catch(() => null);
if (container?.name) return `http://${container.name}:${port}`;
const network = await dockerRequest<{ IPAM?: { Config?: { Gateway?: string }[] } }>({
path: `/networks/${encodeURIComponent(AppData.DockerNetworkName)}`,
}).catch(() => null);
const gateway = network?.ok ? network.data?.IPAM?.Config?.find((c) => c.Gateway)?.Gateway : undefined;
return gateway ? `http://${gateway}:${port}` : null;
}