Pass onFlag and a flag control appears in the header menu.
Clicking it opens a reason field inside the panel — never a
native window.prompt, which freezes the renderer, cannot be
themed or translated, and is blocked outright in some embeds.
createAiChatWidget({
endpoint: "/chat",
onFlag: async ({ reason, threadId }) => {
await fetch(`/admin/ai/conversations/public/${threadId}/flag`, {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({ reason }),
});
},
});
Send a message first — the thread id is created on the first turn, and
the control says so rather than silently doing nothing. Then open the
⋮ menu and choose Flag this conversation.
Enter sends, Shift+Enter writes a second line, Escape cancels. A reason
starting with fail makes the stub throw, so you can see that
a failed send keeps the form and the text.
Nothing flagged yet.