Files
cobble/src/utils/chatroom-bot-statuses.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

77 lines
2.4 KiB
TypeScript

import type { ChatroomBot, ChatroomSummary } from "@/src/types";
type Params = {
room: Pick<ChatroomSummary, "status" | "requester_bot_id" | "bots" | "jobs">;
/**
* The latest step pushed for each room session, newer than the step the
* room was read with.
*/
steps?: Record<number, string>;
};
export type ChatroomBotStatus = {
bot: ChatroomBot;
label: string;
/**
* Its latest step, while it works.
*/
detail: string | null;
/**
* Working now (a job of its runs or waits to run).
*/
active: boolean;
};
/**
* Where each bot of an open room stands, for the rows under the thread:
* the asking bot waits for the answer, the coordinator thinks or waits on
* whoever it asked, an asked bot works (with its latest step) or is done.
* A closed room has none.
*/
export default function chatroomBotStatuses({ room, steps = {} }: Params): ChatroomBotStatus[] {
if (room.status != "open") return [];
const jobs = room.jobs || [];
return room.bots.map((bot) => {
const name = bot.name || "A bot";
const job = jobs.find((item) => item.bot_id == bot.id);
const step = job ? steps[job.session_id] || job.progress || null : null;
const is_coordinator = bot.kind == "coordinator";
if (job) {
const started = job.status == "processing" || Boolean(step);
return {
bot,
label: !started
? `${name} is getting to it…`
: is_coordinator
? `${name} is thinking…`
: `${name} is working…`,
detail: started ? step : null,
active: true,
};
}
if (bot.id == room.requester_bot_id) {
return { bot, label: `${name} is waiting for the answer`, detail: null, active: false };
}
if (is_coordinator) {
const waiting_on = room.bots
.filter((other) => other.id != bot.id && jobs.some((item) => item.bot_id == other.id))
.map((other) => other.name || "a bot");
return {
bot,
label: waiting_on.length ? `${name} is waiting on ${waiting_on.join(", ")}` : `${name} is passing it on`,
detail: null,
active: false,
};
}
return { bot, label: `${name} is done`, detail: null, active: false };
});
}