Files
cobble/src/harness/tools/bot/hooks/grab-bot-hook-tools.ts
T
tbenandClaude Opus 5.5 0e59559ea9 Keep every hook call's response, searchable by the user and the bot
A hook call used to record only how it was taken; its run's answer went
to the chat alone and was lost to the call once the job was pruned. Now
`bot_hook_events` keeps `response`, `response_message_id` and
`responded_at`, written on every call a run took in when that run ends
(completed, failed, lost, stopped or cancelled) by
`recordHookCallResponse` in the job helpers, and calls turn done or
failed. The Calls view searches what calls sent and what runs answered,
filters by status and pages; Show all loads one call whole. Bots get
`search_hook_calls` and `read_hook_call` for their own hooks (never in a
hook call's own run), with payloads always marked as outside data.
Calls are kept for the app setting `hook_events_keep_days` (Settings >
General, default now 30 days). The caller still only gets 202 Queued.

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

58 lines
1.9 KiB
TypeScript

import type { BUN_SQLITE_COBBLE_COMPUTERS } from "@/db/types/db";
import type { HarnessTool } from "../../../types";
import deleteHookTool from "./delete-hook-tool";
import listHooksTool from "./list-hooks-tool";
import pauseHookTool from "./pause-hook-tool";
import proposeHookTool from "./propose-hook-tool";
import readHookCallTool from "./read-hook-call-tool";
import searchHookCallsTool from "./search-hook-calls-tool";
type Params = {
user_id: number | string;
bot_id: number | string;
session_id?: number | string;
workspace_id?: number | string | null;
computers: BUN_SQLITE_COBBLE_COMPUTERS[];
/**
* The run is a hook call: what started it came from outside, so it
* gets no hook tools at all.
*/
hooked?: boolean;
/**
* Called with each proposal's ref, so the reply carries its card. Only
* a chat reply proposes: someone is there to confirm.
*/
onPropose?: (params: { ref: string }) => void;
};
/**
* A bot's tools for the user's hooks it runs: read them and search their
* calls (what each sent and what its run answered), pause or delete
* one (that only takes away), and in a chat reply propose a new one or a
* change (the user confirms it from a card; a new one's URL goes to them
* alone). A hook call's own run gets none, so a caller's payload can never
* reach them.
*/
export default function grabBotHookTools({
user_id,
bot_id,
session_id,
workspace_id,
computers,
hooked,
onPropose,
}: Params): HarnessTool[] {
if (hooked) return [];
return [
listHooksTool({ user_id, bot_id }),
searchHookCallsTool({ user_id, bot_id }),
readHookCallTool({ user_id, bot_id }),
pauseHookTool({ user_id, bot_id }),
deleteHookTool({ user_id, bot_id }),
...(session_id && onPropose
? [proposeHookTool({ user_id, bot_id, session_id, workspace_id, computers, onPropose })]
: []),
];
}