Files
ARTEX/db/migrations/0016_chat_bridge_access.sql
shivandkrad e84648f99d feat(chatbridge): task commands, main-agent chat and per-user access
Part 2 of #5, on top of the bridge core.

Access: chat_bridges.allowed_users (migration 0016). A private chat is
served when its chat ID is allowed, as before. In a group the sender must
also be an allowed user, and a group with no allowed users serves nobody,
so joining an allowed group grants nothing by itself. A refused member
gets one refusal naming their user ID.

Commands: /tasks, /task [id], /pause [id], /resume [id], /findings [id].
Each chat selects its task with /task; the selection is stored in
chat_bridge_chats and cleared when the task is deleted. /pause and /resume
go through applyTaskControl, the same path as the web UI.

Plain text goes to the selected task's main agent through startTaskChat,
which the web chat handler now also uses, so the bot and the web chat
share one conversation. The answer is relayed when the turn ends, through
chatbridge.SafeText: code blocks dropped, the task's stored credentials
and common secret shapes masked, cut to 1500 characters, with a link
back. An answer is dropped if its chat is no longer allowed.

Co-authored-by: krad <222954346+dar1k0@users.noreply.github.com>
2026-11-27 11:30:06 +05:30

21 lines
1.1 KiB
SQL

-- Chat bridge, part 2 (issue #5): per-user access in groups, and the task each
-- chat works on.
--
-- allowed_users lists the user ids that may use the bot inside an allowed
-- group chat, a JSON array of strings. A group is a shared space: without
-- this list everyone added to an allowed group, now or later, would get the
-- control the bot gives over tasks. A private chat needs no entry, because
-- its chat id is the user. An empty list refuses every group message.
ALTER TABLE chat_bridges ADD COLUMN IF NOT EXISTS allowed_users JSONB NOT NULL DEFAULT '[]'::jsonb;
-- chat_bridge_chats keeps the task a chat selected with /task, so the
-- selection survives a restart. Deleting the task or the bridge removes it.
CREATE TABLE IF NOT EXISTS chat_bridge_chats (
kind TEXT NOT NULL REFERENCES chat_bridges(kind) ON DELETE CASCADE,
chat_id TEXT NOT NULL,
task_id BIGINT NOT NULL REFERENCES tasks(id) ON DELETE CASCADE,
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
PRIMARY KEY (kind, chat_id)
);
CREATE INDEX IF NOT EXISTS chat_bridge_chats_task_idx ON chat_bridge_chats(task_id);