Bots get list_hooks, pause_hook and delete_hook, which act directly since they only take away. A new hook, or a new name, brief or filter, or switching a paused one back on, goes through propose_hook: it stores a hook_proposals row and puts a [hook-proposal:ID] card in the reply, which the user it was proposed to confirms or rejects. The card is read from what Confirm saves, with the bot's reason labelled as its own; confirming checks everything again and saves through the Hooks modal's helpers. A new hook's URL is shown on the card once, to the user only, never in the outcome the bot is told. What calls a hook, its computers and its signing are never proposed. Only chat replies propose, and a hook call's own run gets no hook tools, so a caller's payload can't reach them. Co-Authored-By: Claude Opus 5.5 <[email protected]>
32 lines
1.4 KiB
TypeScript
32 lines
1.4 KiB
TypeScript
import type { BotHookWithNames } from "@/src/types";
|
|
|
|
type Params = {
|
|
hook: BotHookWithNames;
|
|
};
|
|
|
|
/**
|
|
* One hook as a bot reads it: id, name, what calls it, where it runs, its
|
|
* state, runs and last call (ISO, UTC), and the last error if any. Never
|
|
* its URL or any part of its token: a bot doesn't hold those.
|
|
*/
|
|
export default function describeBotHook({ hook }: Params) {
|
|
const runs = Number(hook.run_count || 0);
|
|
const watching = hook.source == "browser_notifications";
|
|
const parts = [
|
|
`#${hook.id} "${hook.title}"`,
|
|
watching
|
|
? `called by browser notifications on computer ${hook.watch_computer_id}${hook.watch_computer_name ? ` (${hook.watch_computer_name})` : ""}${
|
|
hook.watch_filter ? `, only those containing "${hook.watch_filter}"` : ""
|
|
}`
|
|
: `called at its URL${hook.has_signing_secret ? " (signed calls only)" : ""}`,
|
|
hook.workspace_name ? `in the workspace ${hook.workspace_name}` : `in your own chat`,
|
|
hook.computer_id ? `on computer ${hook.computer_id}` : "",
|
|
hook.enabled ? "on" : "paused",
|
|
`${runs} run${runs == 1 ? "" : "s"} so far`,
|
|
hook.last_called_at ? `last called ${new Date(Number(hook.last_called_at)).toISOString()}` : "never called",
|
|
hook.last_error ? `last error: ${hook.last_error}` : "",
|
|
];
|
|
|
|
return parts.filter(Boolean).join(", ");
|
|
}
|