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:
@@ -2,6 +2,7 @@ import BunSQLite from "@moduletrace/bun-sqlite";
|
||||
import type { BUN_SQLITE_COBBLE_BOTS_QUEUE } from "@/db/types/db";
|
||||
import { BotJobCancelledError } from "@/src/dict/bot-queue-dict";
|
||||
import AppError from "@/src/utils/app-error";
|
||||
import recordHookCallResponse from "../bot-hooks/record-hook-call-response";
|
||||
|
||||
type Params = {
|
||||
user_id: number | string;
|
||||
@@ -37,5 +38,7 @@ export default async function cancelBotJob({ user_id, job_id }: Params) {
|
||||
});
|
||||
}
|
||||
|
||||
await recordHookCallResponse({ job, status: "failed", response: BotJobCancelledError, now });
|
||||
|
||||
return job;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import setBotFace from "../bots/set-bot-face";
|
||||
import countOpenBotJobs from "./count-open-bot-jobs";
|
||||
import grabLockedBotJob from "./grab-locked-bot-job";
|
||||
import relayJobToRequester from "./relay-job-to-requester";
|
||||
import recordHookCallResponse from "../bot-hooks/record-hook-call-response";
|
||||
import noteTrackerTask from "./note-tracker-task";
|
||||
import jobSessionId from "./job-session-id";
|
||||
import grabJobUserId from "./grab-job-user-id";
|
||||
@@ -46,7 +47,8 @@ type Params = {
|
||||
* after a task and idle after a reply; with others open, it shows the one
|
||||
* still running (a reply in another session mustn't hide a task's row).
|
||||
* Nobody else's face changes. A handed-over job's result also goes to the bot that handed
|
||||
* it over (`relay`), and a handed-over task left open says so (`noteTrackerTask`). Throws if this handler no longer holds the job.
|
||||
* it over (`relay`), and a handed-over task left open says so (`noteTrackerTask`). A hook
|
||||
* run's result is kept on the calls it answered (`recordHookCallResponse`). Throws if this handler no longer holds the job.
|
||||
*/
|
||||
export default async function completeBotJob({
|
||||
job_id,
|
||||
@@ -139,6 +141,8 @@ export default async function completeBotJob({
|
||||
|
||||
await noteTrackerTask({ job });
|
||||
|
||||
await recordHookCallResponse({ job, status: "done", response: result, message_id: inserted?.id });
|
||||
|
||||
const relay = silent ? null : await relayJobToRequester({ job, text: result });
|
||||
|
||||
return { message, bot, relay };
|
||||
|
||||
@@ -4,6 +4,7 @@ import insertBotMessage from "../bots/insert-bot-message";
|
||||
import setBotFace from "../bots/set-bot-face";
|
||||
import relayJobToRequester from "./relay-job-to-requester";
|
||||
import noteTrackerTask from "./note-tracker-task";
|
||||
import recordHookCallResponse from "../bot-hooks/record-hook-call-response";
|
||||
import jobSessionId from "./job-session-id";
|
||||
import grabJobUserId from "./grab-job-user-id";
|
||||
import { BotNeedsYouStatusLine } from "@/src/dict/bot-queue-dict";
|
||||
@@ -18,7 +19,8 @@ type Params = {
|
||||
* reported once), tells the user in the bot's conversation and sets the
|
||||
* bot to needs-you for that user. Its task stays active, since the work isn't done. A
|
||||
* handed-over job's failure also goes to the bot that handed it over, and
|
||||
* blocks the handed-over task it worked on (`noteTrackerTask`).
|
||||
* blocks the handed-over task it worked on (`noteTrackerTask`). A hook run's
|
||||
* calls keep why it failed (`recordHookCallResponse`).
|
||||
*/
|
||||
export default async function notifyBotJobFailed({
|
||||
job,
|
||||
@@ -63,6 +65,13 @@ export default async function notifyBotJobFailed({
|
||||
|
||||
await noteTrackerTask({ job, failure: failure_message || job.last_error || "" });
|
||||
|
||||
await recordHookCallResponse({
|
||||
job,
|
||||
status: "failed",
|
||||
response: job.last_error || failure_message || "The run failed.",
|
||||
message_id: message?.id,
|
||||
});
|
||||
|
||||
const relay = await relayJobToRequester({
|
||||
job,
|
||||
text: failure_message || job.last_error || "",
|
||||
|
||||
@@ -5,6 +5,7 @@ import insertBotMessage from "../bots/insert-bot-message";
|
||||
import setBotFace, { type BotFaceChange } from "../bots/set-bot-face";
|
||||
import { abortRunningJob } from "@/src/bots-queue/job-abort-registry";
|
||||
import insertBotJobUpdate from "./insert-bot-job-update";
|
||||
import recordHookCallResponse from "../bot-hooks/record-hook-call-response";
|
||||
import openBotJobsSql from "./open-bot-jobs-sql";
|
||||
import stoppedJobReport, { pickReportedJobs } from "./stopped-job-report";
|
||||
|
||||
@@ -91,6 +92,8 @@ export default async function stopBotJobs({ bot_id, user_id }: Params): Promise<
|
||||
});
|
||||
}
|
||||
|
||||
await recordHookCallResponse({ job: stopped, status: "failed", response: BotJobStoppedError, now });
|
||||
|
||||
/**
|
||||
* Recorded as the job's last step, so the working row says why it
|
||||
* went quiet.
|
||||
|
||||
Reference in New Issue
Block a user