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]>
This commit is contained in:
2026-10-25 17:08:12 +01:00
co-authored by Claude Opus 5.5
parent 69988e08fc
commit fb4c89fca1
26 changed files with 630 additions and 19 deletions
@@ -15,17 +15,25 @@ type Params = {
* The session this one carries on from.
*/
previous_session_id?: number | null;
/**
* `closed` starts it in the background (a hook's own session), leaving
* the conversation's active one as it is. Active by default.
*/
status?: "active" | "closed";
title?: string | null;
};
/**
* Starts an active session in a user's conversation. Callers close the old one
* first (`startBotSession`).
* Starts a session in a user's conversation: an active one (callers close
* the old one first, `startBotSession`) or, `closed`, one beside it.
*/
export default async function createBotSession({
user_id,
bot_id,
workspace_id,
previous_session_id,
status = "active",
title,
}: Params): Promise<BUN_SQLITE_COBBLE_BOT_SESSIONS> {
const now = Date.now();
@@ -34,7 +42,8 @@ export default async function createBotSession({
bot_id: Number(bot_id),
workspace_id: workspace_id ? Number(workspace_id) : undefined,
previous_session_id: previous_session_id || undefined,
status: "active",
status,
title: title || undefined,
unread: 0,
last_activity_at: now,
};