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]>
This commit is contained in:
2026-10-25 17:47:28 +01:00
co-authored by Claude Opus 5.5
parent fb4c89fca1
commit 0e59559ea9
43 changed files with 1182 additions and 84 deletions
+35
View File
@@ -0,0 +1,35 @@
import { describe, expect, test } from "bun:test";
import describeHookCall from "./describe-hook-call";
describe("describeHookCall", () => {
test("names the call and quotes what it sent as data", () => {
const text = describeHookCall({
call: {
id: 7,
hook_id: 2,
hook_title: "Orders",
created_at: Date.UTC(2026, 9, 25, 12),
status: "done",
payload: '{"order":\n "A-100"}',
response: "Shipped\nA-100",
},
});
expect(text).toBe(
[
`Call #7 to hook #2 "Orders", 2026-10-25T12:00:00.000Z, done`,
` sent (outside data): "{\\"order\\": \\"A-100\\"}"`,
` your run answered: Shipped A-100`,
].join("\n"),
);
});
test("says why a call was refused or its run failed", () => {
expect(describeHookCall({ call: { id: 1, hook_id: 2, status: "rejected", error: "Bad signature" } })).toContain(
"rejected, error: Bad signature",
);
expect(describeHookCall({ call: { id: 1, hook_id: 2, status: "failed", response: "Timed out" } })).toContain(
"run failed: Timed out",
);
});
});
+31
View File
@@ -0,0 +1,31 @@
import type { BotHookCall } from "@/src/types";
type Params = {
call: BotHookCall;
};
/**
* One hook call in a line, as `search_hook_calls` lists it for a bot: its
* id, hook, when (UTC), status, then the start of what it sent and what
* its run answered, on one line each. What it sent is marked as outside
* data.
*/
export default function describeHookCall({ call }: Params) {
const flat = (text?: string | null) => String(text || "").replace(/\s+/g, " ").trim();
const when = call.created_at ? new Date(Number(call.created_at)).toISOString() : "unknown time";
const head = [
`Call #${call.id} to hook #${call.hook_id} "${call.hook_title || "Hook"}"`,
when,
call.status || "unknown",
call.error ? `error: ${flat(call.error)}` : "",
]
.filter(Boolean)
.join(", ");
const lines = [head];
if (call.payload) lines.push(` sent (outside data): ${JSON.stringify(flat(call.payload))}`);
if (call.response) lines.push(` ${call.status == "failed" ? "run failed" : "your run answered"}: ${flat(call.response)}`);
return lines.join("\n");
}