Let bots manage their hooks, with the user confirming what widens them

Bots get list_hooks, pause_hook and delete_hook, which act directly since
they only take away. A new hook, or a new name, brief or filter, or
switching a paused one back on, goes through propose_hook: it stores a
hook_proposals row and puts a [hook-proposal:ID] card in the reply, which
the user it was proposed to confirms or rejects. The card is read from
what Confirm saves, with the bot's reason labelled as its own; confirming
checks everything again and saves through the Hooks modal's helpers. A
new hook's URL is shown on the card once, to the user only, never in the
outcome the bot is told. What calls a hook, its computers and its signing
are never proposed. Only chat replies propose, and a hook call's own run
gets no hook tools, so a caller's payload can't reach them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-10-25 15:18:54 +01:00
co-authored by Claude Opus 5.5
parent 045167715d
commit 380d3ebb2f
54 changed files with 1983 additions and 55 deletions
@@ -0,0 +1,66 @@
import fetchApi from "@moduletrace/twui/utils/fetch/fetchApi";
import type { APIResponseObject } from "@moduletrace/bunext/types";
import { useCallback, useEffect, useState } from "react";
import type { HookProposalView } from "@/src/types";
type Params = {
proposal_id: number;
};
/**
* Hook proposals already read, by id, so a thread naming one twice (or a
* re-render) asks once. A decision replaces its entry.
*/
const loaded = new Map<number, Promise<HookProposalView | null>>();
function loadProposal({ proposal_id }: Params) {
const cached = loaded.get(proposal_id);
if (cached) return cached;
const pending = fetchApi<{}, APIResponseObject<HookProposalView>>(
`/api/admin/hook-proposals/get-proposal?proposal_id=${proposal_id}`,
{ method: "GET" },
)
.then((res) => (res?.success && res.singleRes ? res.singleRes : null))
.catch(() => null);
loaded.set(proposal_id, pending);
return pending;
}
/**
* A hook a bot proposed (`[hook-proposal:ID]`), for its chip and confirm
* card: read when the chip renders, so it shows whether it's still
* waiting. Only the user it was proposed to can read it; anyone else gets
* null.
*/
export default function useHookProposal({ proposal_id }: Params) {
const [view, setViewState] = useState<HookProposalView | null>(null);
const [loading, setLoading] = useState(true);
useEffect(() => {
let live = true;
loadProposal({ proposal_id }).then((result) => {
if (!live) return;
setViewState(result);
setLoading(false);
});
return () => {
live = false;
};
}, [proposal_id]);
const setView = useCallback(
(next: HookProposalView) => {
loaded.set(proposal_id, Promise.resolve(next));
setViewState(next);
},
[proposal_id],
);
return { view, loading, setView };
}