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]>
43 lines
1.8 KiB
TypeScript
43 lines
1.8 KiB
TypeScript
import BunSQLite from "@moduletrace/bun-sqlite";
|
|
|
|
type Params = {
|
|
/**
|
|
* A query for the ids of the rooms to delete, with its values.
|
|
*/
|
|
rooms: { sql: string; values: (string | number)[] };
|
|
};
|
|
|
|
/**
|
|
* Deletes rooms with their bots' sessions there, the messages and jobs in
|
|
* them. Explicitly, child rows first, since foreign keys are off outside
|
|
* the server process. A room's outcome already posted into the asking
|
|
* bot's own conversation stays there.
|
|
*/
|
|
export default async function deleteChatroomRows({ rooms }: Params) {
|
|
const ids = ((await BunSQLite.sql<{ id: number }>({ sql: rooms.sql, values: rooms.values })).payload || []).map(
|
|
(row) => Number(row.id),
|
|
);
|
|
|
|
if (!ids.length) return [];
|
|
|
|
const list = ids.join(", ");
|
|
const sessions = `SELECT id FROM bot_sessions WHERE chatroom_id IN (${list})`;
|
|
|
|
await BunSQLite.sql({
|
|
sql: `DELETE FROM bots_queue_updates WHERE bots_queue_id IN (SELECT id FROM bots_queue WHERE session_id IN (${sessions}))`,
|
|
});
|
|
await BunSQLite.sql({ sql: `DELETE FROM bots_queue WHERE session_id IN (${sessions})` });
|
|
await BunSQLite.sql({ sql: `DELETE FROM bot_tasks WHERE session_id IN (${sessions})` });
|
|
await BunSQLite.sql({
|
|
sql: `DELETE FROM bot_message_reactions WHERE message_id IN (SELECT id FROM bot_messages WHERE session_id IN (${sessions}))`,
|
|
});
|
|
await BunSQLite.sql({
|
|
sql: `DELETE FROM bot_message_media WHERE message_id IN (SELECT id FROM bot_messages WHERE session_id IN (${sessions}))`,
|
|
});
|
|
await BunSQLite.sql({ sql: `DELETE FROM bot_messages WHERE session_id IN (${sessions})` });
|
|
await BunSQLite.sql({ sql: `DELETE FROM bot_sessions WHERE chatroom_id IN (${list})` });
|
|
await BunSQLite.sql({ sql: `DELETE FROM chatrooms WHERE id IN (${list})` });
|
|
|
|
return ids;
|
|
}
|