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]>
81 lines
2.0 KiB
TypeScript
81 lines
2.0 KiB
TypeScript
import bunext from "@moduletrace/bunext";
|
|
import cronHeartbeat from "./heartbeat";
|
|
import pruneBotsQueue from "./prune-bots-queue";
|
|
import pruneBotHookEvents from "./prune-bot-hook-events";
|
|
import syncNotifyWatchers from "./sync-notify-watchers";
|
|
import cronSyncHarnessModels from "./sync-harness-models";
|
|
import syncComputers from "./sync-computers";
|
|
import syncMcpServers from "./sync-mcp-servers";
|
|
import runCronJobs from "./run-cron-jobs";
|
|
import ingestPendingFiles from "./ingest-pending-files";
|
|
import registerCronJob from "./register-cron-job";
|
|
|
|
export default function cron() {
|
|
if (process.env.NODE_ENV == "production" && !process.env.MAIN_SERVER) {
|
|
return;
|
|
}
|
|
|
|
bunext.bunextLog.watch(`Running Cron Services ...`);
|
|
|
|
registerCronJob({
|
|
title: "heartbeat",
|
|
schedule: "@hourly",
|
|
task: cronHeartbeat,
|
|
run_on_start: true,
|
|
});
|
|
|
|
registerCronJob({
|
|
title: "prune-bots-queue",
|
|
schedule: "@daily",
|
|
task: pruneBotsQueue,
|
|
});
|
|
|
|
registerCronJob({
|
|
title: "prune-bot-hook-events",
|
|
schedule: "@daily",
|
|
task: pruneBotHookEvents,
|
|
});
|
|
|
|
registerCronJob({
|
|
title: "sync-notify-watchers",
|
|
schedule: "*/5 * * * *",
|
|
task: syncNotifyWatchers,
|
|
quiet: true,
|
|
});
|
|
|
|
registerCronJob({
|
|
title: "sync-harness-models",
|
|
schedule: "@hourly",
|
|
task: cronSyncHarnessModels,
|
|
run_on_start: true,
|
|
});
|
|
|
|
registerCronJob({
|
|
title: "sync-computers",
|
|
schedule: "*/5 * * * *",
|
|
task: syncComputers,
|
|
run_on_start: true,
|
|
});
|
|
|
|
registerCronJob({
|
|
title: "sync-mcp-servers",
|
|
schedule: "@hourly",
|
|
task: syncMcpServers,
|
|
});
|
|
|
|
registerCronJob({
|
|
title: "run-cron-jobs",
|
|
schedule: "* * * * *",
|
|
task: runCronJobs,
|
|
run_on_start: true,
|
|
quiet: true,
|
|
});
|
|
|
|
registerCronJob({
|
|
title: "ingest-pending-files",
|
|
schedule: "*/10 * * * *",
|
|
task: ingestPendingFiles,
|
|
quiet: true,
|
|
});
|
|
}
|