Let workers ask each other through the coordinator in chatrooms
A worker asks for another bot's help with ask_crew. The coordinator reads the request, asks the right bot (in a workspace, only its members), and sends the answer back into the asking bot's conversation, waking it. Each exchange is kept as a read-only chatroom: listed in the main rail after the workspaces, or in the workspace's rail for requests made there, with live status rows for each bot while it's open and a Stop button. Room sessions are hidden from every conversation list, other bots' words reach the model fenced as data, and turns, nesting and open rooms are capped. Closed rooms are pruned after a retention period and past a cap per place (Settings > General). Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -43,7 +43,7 @@ export default async function grabBotSessions({
|
||||
sql += ` (SELECT COUNT(*) FROM bot_messages m WHERE m.session_id = s.id) AS message_count,\n`;
|
||||
sql += ` (SELECT m.text FROM bot_messages m WHERE m.session_id = s.id ORDER BY m.created_at DESC, m.id DESC LIMIT 1) AS last_message_text\n`;
|
||||
sql += `FROM bot_sessions s\n`;
|
||||
sql += `WHERE s.user_id = ? AND s.bot_id = ? AND s.workspace_id IS ?\n`;
|
||||
sql += `WHERE s.user_id = ? AND s.bot_id = ? AND s.workspace_id IS ? AND s.chatroom_id IS NULL\n`;
|
||||
sql += `AND (s.status = 'active' OR EXISTS (SELECT 1 FROM bot_messages m WHERE m.session_id = s.id))\n`;
|
||||
|
||||
if (like) {
|
||||
|
||||
@@ -56,6 +56,7 @@ export default async function grabConversationHistory({
|
||||
|
||||
const in_conversation =
|
||||
asked?.id &&
|
||||
!asked.chatroom_id &&
|
||||
Number(asked.bot_id) == Number(open_bot_id) &&
|
||||
(asked.workspace_id ? Number(asked.workspace_id) : null) ==
|
||||
(conversation_workspace_id ? Number(conversation_workspace_id) : null);
|
||||
|
||||
@@ -72,7 +72,7 @@ export default async function grabPastSessionMessages({
|
||||
const session = (
|
||||
await BunSQLite.sql<BUN_SQLITE_COBBLE_BOT_SESSIONS>({
|
||||
sql: `SELECT id, title, previous_session_id FROM bot_sessions
|
||||
WHERE id = ? AND user_id = ? AND bot_id = ? AND workspace_id IS ? AND id != ? LIMIT 1`,
|
||||
WHERE id = ? AND user_id = ? AND bot_id = ? AND workspace_id IS ? AND id != ? AND chatroom_id IS NULL LIMIT 1`,
|
||||
values: [
|
||||
target_session_id,
|
||||
user_id,
|
||||
|
||||
@@ -5,7 +5,7 @@ import searchPastSessionsSql, { type SearchPastSessionsParams } from "./past-ses
|
||||
/**
|
||||
* A bot's search of its earlier sessions reads only that user's
|
||||
* conversation with it (in the same place), never the session it's
|
||||
* answering. Run against real SQLite.
|
||||
* answering, nor its part of a chatroom. Run against real SQLite.
|
||||
*/
|
||||
const db = new Database(":memory:");
|
||||
|
||||
@@ -26,6 +26,12 @@ db.run(`INSERT INTO bot_messages (id, session_id, author, text) VALUES
|
||||
(6, 5, 'user', 'Acme invoice in the workspace'),
|
||||
(7, 1, 'user', 'Discount of 100% off'),
|
||||
(8, 1, 'user', 'Discount of 10 off')`);
|
||||
/**
|
||||
* The bot's part of a chatroom: never one of its past sessions.
|
||||
*/
|
||||
db.run(`ALTER TABLE bot_sessions ADD COLUMN chatroom_id INTEGER`);
|
||||
db.run(`INSERT INTO bot_sessions (id, user_id, bot_id, workspace_id, title, chatroom_id) VALUES (6, 1, 10, NULL, 'A chatroom', 3)`);
|
||||
db.run(`INSERT INTO bot_messages (id, session_id, author, text) VALUES (9, 6, 'bot', 'Acme invoice asked in a chatroom')`);
|
||||
|
||||
function ids(params: Partial<SearchPastSessionsParams>) {
|
||||
const { sql, values } = searchPastSessionsSql({
|
||||
|
||||
@@ -62,6 +62,7 @@ export default function searchPastSessionsSql({
|
||||
`s.bot_id = ?`,
|
||||
`s.workspace_id IS ?`,
|
||||
`s.id != ?`,
|
||||
`s.chatroom_id IS NULL`,
|
||||
];
|
||||
|
||||
for (const word of words) {
|
||||
|
||||
@@ -26,6 +26,13 @@ export default async function reopenBotSession({
|
||||
|
||||
if (session.status == "active") return session;
|
||||
|
||||
/**
|
||||
* A bot's part of a chatroom is only ever read in the room.
|
||||
*/
|
||||
if (session.chatroom_id) {
|
||||
throw new AppError(`Session not found.`);
|
||||
}
|
||||
|
||||
/**
|
||||
* The bot moved the conversation on from it (`continue_in_new_session`):
|
||||
* reopened, the conversation would go on without what was said since,
|
||||
|
||||
Reference in New Issue
Block a user