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:
@@ -13,6 +13,8 @@ import grabJobUserId from "./grab-job-user-id";
|
||||
import grabRunningBotJobFace from "./grab-running-bot-job-face";
|
||||
import withMessageUsage from "../usage/with-message-usage";
|
||||
import type { HarnessToolUse } from "@/src/harness/types";
|
||||
import grabSessionChatroomId from "../chatrooms/grab-session-chatroom-id";
|
||||
import onChatroomJobEnded from "../chatrooms/on-chatroom-job-ended";
|
||||
|
||||
type Params = {
|
||||
job_id: number | string;
|
||||
@@ -48,7 +50,8 @@ type Params = {
|
||||
* still running (a reply in another session mustn't hide a task's row).
|
||||
* Nobody else's face changes. A handed-over job's result also goes to the bot that handed
|
||||
* it over (`relay`), and a handed-over task left open says so (`noteTrackerTask`). A hook
|
||||
* run's result is kept on the calls it answered (`recordHookCallResponse`). Throws if this handler no longer holds the job.
|
||||
* run's result is kept on the calls it answered (`recordHookCallResponse`). A job in a chatroom
|
||||
* moves the room on (`onChatroomJobEnded`) and leaves the bot's face alone. Throws if this handler no longer holds the job.
|
||||
*/
|
||||
export default async function completeBotJob({
|
||||
job_id,
|
||||
@@ -130,7 +133,12 @@ export default async function completeBotJob({
|
||||
|
||||
const user_id = await grabJobUserId({ job });
|
||||
|
||||
const bot = !user_id
|
||||
/**
|
||||
* Work in a chatroom shows in the room, never on the bot's face.
|
||||
*/
|
||||
const in_room = Boolean(await grabSessionChatroomId({ session_id: job.session_id }));
|
||||
|
||||
const bot = !user_id || in_room
|
||||
? null
|
||||
: needs_you
|
||||
? await setBotFace({
|
||||
@@ -153,6 +161,8 @@ export default async function completeBotJob({
|
||||
|
||||
const relay = silent ? null : await relayJobToRequester({ job, text: result });
|
||||
|
||||
await onChatroomJobEnded({ job, text: silent ? "" : result });
|
||||
|
||||
return { message, bot, relay };
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,8 @@ import recordHookCallResponse from "../bot-hooks/record-hook-call-response";
|
||||
import jobSessionId from "./job-session-id";
|
||||
import grabJobUserId from "./grab-job-user-id";
|
||||
import { BotNeedsYouStatusLine } from "@/src/dict/bot-queue-dict";
|
||||
import grabSessionChatroomId from "../chatrooms/grab-session-chatroom-id";
|
||||
import onChatroomJobEnded from "../chatrooms/on-chatroom-job-ended";
|
||||
|
||||
type Params = {
|
||||
job: BUN_SQLITE_COBBLE_BOTS_QUEUE;
|
||||
@@ -20,7 +22,8 @@ type Params = {
|
||||
* bot to needs-you for that user. Its task stays active, since the work isn't done. A
|
||||
* handed-over job's failure also goes to the bot that handed it over, and
|
||||
* blocks the handed-over task it worked on (`noteTrackerTask`). A hook run's
|
||||
* calls keep why it failed (`recordHookCallResponse`).
|
||||
* calls keep why it failed (`recordHookCallResponse`). A job in a chatroom moves the room on
|
||||
* (`onChatroomJobEnded`) and leaves the bot's face alone.
|
||||
*/
|
||||
export default async function notifyBotJobFailed({
|
||||
job,
|
||||
@@ -53,8 +56,9 @@ export default async function notifyBotJobFailed({
|
||||
});
|
||||
|
||||
const user_id = await grabJobUserId({ job });
|
||||
const in_room = Boolean(await grabSessionChatroomId({ session_id: job.session_id }));
|
||||
|
||||
const bot = user_id
|
||||
const bot = user_id && !in_room
|
||||
? await setBotFace({
|
||||
bot_id: job.bot_id,
|
||||
user_id,
|
||||
@@ -78,5 +82,7 @@ export default async function notifyBotJobFailed({
|
||||
failed: true,
|
||||
});
|
||||
|
||||
await onChatroomJobEnded({ job, text: failure_message || job.last_error || "", failed: true });
|
||||
|
||||
return { message, bot, relay };
|
||||
}
|
||||
|
||||
@@ -8,6 +8,8 @@ import insertBotJobUpdate from "./insert-bot-job-update";
|
||||
import recordHookCallResponse from "../bot-hooks/record-hook-call-response";
|
||||
import openBotJobsSql from "./open-bot-jobs-sql";
|
||||
import stoppedJobReport, { pickReportedJobs } from "./stopped-job-report";
|
||||
import grabSessionChatroomId from "../chatrooms/grab-session-chatroom-id";
|
||||
import closeChatroom from "../chatrooms/close-chatroom";
|
||||
|
||||
type Params = {
|
||||
bot_id: number | string;
|
||||
@@ -112,6 +114,18 @@ export default async function stopBotJobs({ bot_id, user_id }: Params): Promise<
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A job it was doing in a chatroom stops the room: the bot that asked
|
||||
* is told, and the room says so.
|
||||
*/
|
||||
for (const job of jobs) {
|
||||
const chatroom_id = await grabSessionChatroomId({ session_id: job.session_id });
|
||||
|
||||
if (chatroom_id) {
|
||||
await closeChatroom({ chatroom_id, status: "stopped", outcome: "" }).catch(() => false);
|
||||
}
|
||||
}
|
||||
|
||||
const messages: BUN_SQLITE_COBBLE_BOT_MESSAGES[] = [];
|
||||
|
||||
for (const [session_id, job] of pickReportedJobs({ jobs })) {
|
||||
|
||||
Reference in New Issue
Block a user