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:
2026-10-19 04:44:35 +01:00
co-authored by Claude Opus 5.5
parent 6a2665dae9
commit 7b580d782e
64 changed files with 1792 additions and 86 deletions
+80
View File
@@ -0,0 +1,80 @@
import type { BUN_SQLITE_COBBLE_COMPUTERS } from "@/db/types/db";
import userAuth from "@/src/functions/backend/auth/user-auth";
import pushBotNotice from "@/src/bots-queue/push-bot-notice";
import setBotComputer from "@/src/functions/backend/db/computers/set-bot-computer";
import logEvent, { grabRequestIP } from "@/src/functions/backend/logger";
import { SetBotComputerRequestSchema } from "@/src/schemas/bot-schema";
import AppError from "@/src/utils/app-error";
import parseWithSchema from "@/src/utils/parse-with-schema";
import isReadOnlyUser from "@/src/utils/rbac/is-read-only-user";
import safeErrorMessage from "@/src/utils/safe-error-message";
import type {
APIResponseObject,
BunextAPIRouteHandler,
} from "@moduletrace/bunext/types";
/**
* Switches the computer one of the session user's bots works on, and
* tells the user's other tabs. Returns the bot's computers, the new one
* first.
*/
export const handler: BunextAPIRouteHandler<
APIResponseObject<BUN_SQLITE_COBBLE_COMPUTERS>
> = async ({ req, body }) => {
try {
if (req.method != "POST") {
throw new AppError(`Method not allowed`);
}
const { user, user_types } = await userAuth({ req });
if (!user?.logged_in_status || !user.id) {
return { success: false, msg: `Unauthorized`, logoutUser: true };
}
if (isReadOnlyUser({ user_types: user_types || [] })) {
throw new AppError(`This user can only read records.`);
}
const { bot_id, computer_id } = parseWithSchema({
schema: SetBotComputerRequestSchema,
data: body,
});
const { bot, computer, computers } = await setBotComputer({
bot_id,
computer_id,
user_id: user.id,
});
await pushBotNotice({
bot_id: bot.id || 0,
bot: {
id: bot.id,
face: bot.face,
status_line: bot.status_line,
computer_id: computer.id,
},
});
await logEvent({
title: "Bot computer switched",
category: "system",
user_id: user.id,
plain_text: `User #${user.id} switched ${bot.name} to ${computer.name || `computer #${computer.id}`}.`,
metadata: { bot_id: bot.id, computer_id: computer.id },
ip_address: grabRequestIP(req),
});
return {
success: true,
msg: `${bot.name} is on ${computer.name || "that computer"} now.`,
payload: computers,
};
} catch (error: unknown) {
return {
success: false,
msg: safeErrorMessage({ error }),
};
}
};