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,61 @@
|
||||
import BunSQLite from "@moduletrace/bun-sqlite";
|
||||
import { AppData } from "@/src/data/app-data";
|
||||
import { logError } from "@/src/functions/backend/logger";
|
||||
import grabConnectedUserIds from "@/src/websocket/(functions)/grab-connected-user-ids";
|
||||
import relayChangedBots from "./relay-changed-bots";
|
||||
import relayNewBotMessages from "./relay-new-bot-messages";
|
||||
import relayNewJobUpdates from "./relay-new-job-updates";
|
||||
import type { LiveRelayCursor } from "./types";
|
||||
|
||||
/**
|
||||
* Keeps this process's sockets current with work done anywhere: every
|
||||
* `AppData.LiveRelayPollMs` it reads new bot messages, new job steps and
|
||||
* changed bots from the database and pushes them to their owners'
|
||||
* sockets here. The process that did the work pushes at once
|
||||
* (`pushBotNotice`); this catches the rest, e.g. a job run by another
|
||||
* server on the same database. Clients ignore what they already have.
|
||||
* Runs in every server process, ungated.
|
||||
*/
|
||||
export default async function liveRelay() {
|
||||
const latest = async (table: "bot_messages" | "bots_queue_updates") =>
|
||||
Number(
|
||||
(
|
||||
await BunSQLite.sql<{ id: number }>({
|
||||
sql: `SELECT MAX(id) AS id FROM ${table}`,
|
||||
})
|
||||
).payload?.[0]?.id,
|
||||
) || 0;
|
||||
|
||||
const cursor: LiveRelayCursor = {
|
||||
message_id: await latest("bot_messages"),
|
||||
update_id: await latest("bots_queue_updates"),
|
||||
bots_at: Date.now(),
|
||||
};
|
||||
|
||||
let running = false;
|
||||
|
||||
setInterval(async () => {
|
||||
if (running) return;
|
||||
|
||||
running = true;
|
||||
|
||||
try {
|
||||
const users = grabConnectedUserIds();
|
||||
const now = Date.now();
|
||||
|
||||
cursor.message_id = await relayNewBotMessages({ after_id: cursor.message_id, users });
|
||||
cursor.update_id = await relayNewJobUpdates({ after_id: cursor.update_id, users });
|
||||
|
||||
/**
|
||||
* Overlap one interval, so a change written in the same
|
||||
* millisecond as the last look isn't missed.
|
||||
*/
|
||||
await relayChangedBots({ since: cursor.bots_at - AppData.LiveRelayPollMs, users });
|
||||
cursor.bots_at = now;
|
||||
} catch (error) {
|
||||
await logError({ title: `Live relay failed`, error }).catch(() => {});
|
||||
} finally {
|
||||
running = false;
|
||||
}
|
||||
}, AppData.LiveRelayPollMs);
|
||||
}
|
||||
Reference in New Issue
Block a user