Files
cobble/src/utils/hook-subtitle.ts
T
tbenandClaude Opus 5.5 fb4c89fca1 Tie each hook to a session, picked in the hook form
A hook's calls used to run in whatever session was active at the time.
Now `bot_hooks.session_id` pins them to one session, open or closed
(null still follows the active one). The hook form picks where it runs
(the bot's own chat or one of its workspaces) and a session there, or a
new one of its own started beside the active one so the chat on screen
stays. A bot's proposed hook gets the session it was proposed in, and a
missing session is replaced on the next call. Changing place or session
is refused while a run is open; the computer stays only if reachable.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-25 17:08:12 +01:00

40 lines
1.5 KiB
TypeScript

import type { BotHookWithNames } from "@/src/types";
import relativeTime from "./relative-time";
type Params = {
hook: BotHookWithNames;
now?: number;
/**
* Shown by default; left out where the conversation already is the
* bot's (or the workspace's).
*/
show_bot?: boolean;
show_workspace?: boolean;
};
/**
* The line under a hook's name: whose it is, where it runs (and in which
* session, when it has one of its own), which
* computer's notifications it gets (and its filter), how many runs
* it started and when it was last called, whether calls must be signed,
* then why its last call or run failed.
*/
export default function hookSubtitle({ hook, now = Date.now(), show_bot = true, show_workspace = true }: Params) {
const runs = Number(hook.run_count || 0);
return [
show_bot ? hook.bot_name || "A bot" : "",
show_workspace ? hook.workspace_name || "" : "",
hook.session_id ? `in "${hook.session_title || `session ${hook.session_id}`}"` : "",
hook.source == "browser_notifications"
? `notifications on ${hook.watch_computer_name || "a computer"}${hook.watch_filter ? ` with "${hook.watch_filter}"` : ""}`
: "",
`${runs} ${runs == 1 ? "run" : "runs"}`,
hook.last_called_at ? `called ${relativeTime({ at: hook.last_called_at, now })}` : "never called",
hook.has_signing_secret ? "signed" : "",
hook.last_error || "",
]
.filter(Boolean)
.join(" · ");
}