Give the coordinator working crew management tools

- Resolve the crew and workspaces fresh inside each tool run, so a bot or
  workspace created earlier in the same reply is usable: create_bot,
  assign_computer, add_bot_to_workspace, delegate_task and
  set_bot_workspace_instructions.
- Add coordinator-only update_bot, find_bot, find_workspace, delete_bot,
  delete_workspace and remove_bot_from_workspace tools.
- Push server:workspace-removed when a workspace is deleted, and
  workspace_ids on server:bot-updated so a workspace's crew drops a bot
  that was taken out of it.
This commit is contained in:
2026-10-19 20:34:51 +01:00
parent b79cebf397
commit 139b3e443d
20 changed files with 648 additions and 39 deletions
@@ -1,5 +1,6 @@
import { z } from "zod";
import type { BUN_SQLITE_COBBLE_BOTS, BUN_SQLITE_COBBLE_COMPUTERS } from "@/db/types/db";
import grabCrewWorkers from "@/src/functions/backend/db/bots/grab-crew-workers";
import addBotToComputer from "@/src/functions/backend/db/computers/add-bot-to-computer";
import removeBotFromComputer from "@/src/functions/backend/db/computers/remove-bot-from-computer";
import computerRef from "@/src/utils/computer-ref";
@@ -57,11 +58,16 @@ export default function assignComputerTool({
access: z.enum(["grant", "revoke"]),
}),
run: async ({ args }) => {
const worker = workers.find((bot) => bot.id == args.bot_id);
const fresh = await grabCrewWorkers();
const worker = fresh.find((bot) => bot.id == args.bot_id);
const computer = computers.find((c) => c.id == args.computer_id);
if (!worker?.id) {
throw new Error(`No crew member has id ${args.bot_id}.`);
throw new Error(
`No crew member has id ${args.bot_id}. Crew: ${fresh
.map((bot) => `${bot.id}: ${bot.name}`)
.join("; ") || "none"}.`,
);
}
if (!computer?.id) {