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]>
41 lines
1.3 KiB
TypeScript
41 lines
1.3 KiB
TypeScript
import type { BUN_SQLITE_COBBLE_BOTS } from "@/db/types/db";
|
|
import grabCrewWorkers from "../bots/grab-crew-workers";
|
|
import grabUserBot from "../bots/grab-user-bot";
|
|
|
|
type Params = {
|
|
/**
|
|
* The user the room works for: only bots they reach can be asked.
|
|
*/
|
|
user_id: number | string;
|
|
/**
|
|
* The bot asking, never asked itself.
|
|
*/
|
|
requester_bot_id: number | string;
|
|
/**
|
|
* In a workspace, only its members can be asked.
|
|
*/
|
|
workspace_id?: number | string | null;
|
|
};
|
|
|
|
/**
|
|
* The workers a bot may have asked through the coordinator for a user:
|
|
* in a workspace its members, otherwise every worker the user reaches.
|
|
* Read fresh each time, so a bot that left or lost the user's grant is
|
|
* never asked.
|
|
*/
|
|
export default async function chatroomAskableBots({
|
|
user_id,
|
|
requester_bot_id,
|
|
workspace_id,
|
|
}: Params): Promise<BUN_SQLITE_COBBLE_BOTS[]> {
|
|
const workers = (await grabCrewWorkers({ workspace_id: workspace_id || null })).filter(
|
|
(bot) => bot.id != Number(requester_bot_id),
|
|
);
|
|
|
|
const reached = await Promise.all(
|
|
workers.map(async (bot) => ((await grabUserBot({ bot_id: bot.id!, user_id }))?.id ? bot : null)),
|
|
);
|
|
|
|
return reached.filter((bot): bot is BUN_SQLITE_COBBLE_BOTS => Boolean(bot));
|
|
}
|