Add computer switching, crew reporting, job steps and markdown chat
- Bots have a current computer (bots.computer_id), switched from the chat header beside the model button or by clicking a computer the bot names ([computer:ID]); tasks run on it by default - search_computers runs one read-only command on all of a bot's computers; chat replies know their computers (compose-computers-note) - The coordinator can use every computer and grants or revokes crew access with assign_computer - Delegated jobs record requested_by_bot_id; the worker's result or failure is reported back in the coordinator's conversation - bots_queue_updates records each model turn of a job, pushed live and shown in the working-on panel - Live relay: every process pushes new messages, job steps and bot changes from the database to its own sockets, so work done elsewhere shows live - Bot messages render as markdown (react-markdown + remark-gfm, no raw HTML) with twui components; rail previews are plain text - Fix header button overflow in the model and computer selects - Bump @moduletrace/twui to 0.1.2 Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
import BunSQLite from "@moduletrace/bun-sqlite";
|
||||
import type { BUN_SQLITE_COBBLE_BOTS, BUN_SQLITE_COBBLE_BOTS_QUEUE } from "@/db/types/db";
|
||||
import insertBotMessage from "../bots/insert-bot-message";
|
||||
|
||||
type Params = {
|
||||
job: BUN_SQLITE_COBBLE_BOTS_QUEUE;
|
||||
/**
|
||||
* The worker's report, or why it failed (markdown).
|
||||
*/
|
||||
text: string;
|
||||
failed?: boolean;
|
||||
};
|
||||
|
||||
/**
|
||||
* Reports a handed-over job back to the bot that handed it over
|
||||
* (`requested_by_bot_id`, the coordinator): a message in its conversation
|
||||
* with the worker's report, flagged needs-you when the job failed. Returns
|
||||
* the message for the live push, or null when nobody handed the job over.
|
||||
*/
|
||||
export default async function relayJobToRequester({ job, text, failed }: Params) {
|
||||
if (!job.requested_by_bot_id || !job.bot_id || job.requested_by_bot_id == job.bot_id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const worker = (
|
||||
await BunSQLite.sql<BUN_SQLITE_COBBLE_BOTS>({
|
||||
sql: `SELECT name FROM bots WHERE id = ? LIMIT 1`,
|
||||
values: [job.bot_id],
|
||||
})
|
||||
).payload?.[0];
|
||||
|
||||
const requester = (
|
||||
await BunSQLite.sql<BUN_SQLITE_COBBLE_BOTS>({
|
||||
sql: `SELECT id FROM bots WHERE id = ? LIMIT 1`,
|
||||
values: [job.requested_by_bot_id],
|
||||
})
|
||||
).payload?.[0];
|
||||
|
||||
if (!requester?.id) return null;
|
||||
|
||||
const name = worker?.name || "A crew member";
|
||||
const title = job.title || "the job";
|
||||
|
||||
const message = await insertBotMessage({
|
||||
bot_id: requester.id,
|
||||
text: failed
|
||||
? `${name} couldn't finish **${title}**. ${text}`.trim()
|
||||
: `${name} finished **${title}**. Their report:\n\n${text}`,
|
||||
needs_you: failed,
|
||||
});
|
||||
|
||||
return { bot_id: requester.id, message };
|
||||
}
|
||||
Reference in New Issue
Block a user