Files
cobble/src/functions/backend/db/chatrooms/chatroom-ancestry.ts
T
tbenandClaude Opus 5.5 7b762fd384 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]>
2026-10-27 18:57:34 +01:00

34 lines
1.1 KiB
TypeScript

import BunSQLite from "@moduletrace/bun-sqlite";
import type { BUN_SQLITE_COBBLE_CHATROOMS } from "@/db/types/db";
import { AppData } from "@/src/data/app-data";
type Params = {
chatroom_id?: number | string | null;
};
/**
* A room and the rooms it was asked from, nearest first: the chain a
* nested request sits in. Stops past `AppData.ChatroomMaxDepth`, which is
* as far as anything needs to look.
*/
export default async function chatroomAncestry({ chatroom_id }: Params) {
const chain: BUN_SQLITE_COBBLE_CHATROOMS[] = [];
let next = chatroom_id ? Number(chatroom_id) : null;
while (next && chain.length <= AppData.ChatroomMaxDepth) {
const room = (
await BunSQLite.sql<BUN_SQLITE_COBBLE_CHATROOMS>({
sql: `SELECT * FROM chatrooms WHERE id = ? LIMIT 1`,
values: [next],
})
).payload?.[0];
if (!room?.id || chain.some((seen) => seen.id == room.id)) break;
chain.push(room);
next = room.parent_chatroom_id ? Number(room.parent_chatroom_id) : null;
}
return chain;
}