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
@@ -2,7 +2,9 @@ import BunSQLite from "@moduletrace/bun-sqlite";
import { z } from "zod";
import type { BUN_SQLITE_COBBLE_BOTS, BUN_SQLITE_COBBLE_WORKSPACES } from "@/db/types/db";
import pushBotCreated from "@/src/bots-queue/push-bot-created";
import grabCrewWorkers from "@/src/functions/backend/db/bots/grab-crew-workers";
import addBotToWorkspace from "@/src/functions/backend/db/workspaces/add-bot-to-workspace";
import grabUserWorkspaces from "@/src/functions/backend/db/workspaces/grab-user-workspaces";
import type { HarnessTool } from "../../types";
type Params = {
@@ -44,16 +46,24 @@ export default function addBotToWorkspaceTool({
workspace_id: z.number().int(),
}),
run: async ({ args }) => {
const worker = workers.find((bot) => bot.id == args.bot_id);
const workspace = workspaces.find((w) => w.id == args.workspace_id);
const fresh = await grabCrewWorkers();
const live = (await grabUserWorkspaces({ user_id })).filter((w) => !w.archived);
const worker = fresh.find((bot) => bot.id == args.bot_id);
const workspace = live.find((w) => w.id == args.workspace_id);
if (!worker?.id) {
throw new Error(`No crew member has id ${args.bot_id}. Crew: ${crew || "none"}.`);
throw new Error(
`No crew member has id ${args.bot_id}. Crew: ${fresh
.map((bot) => `${bot.id}: ${bot.name}`)
.join("; ") || "none"}.`,
);
}
if (!workspace?.id) {
throw new Error(
`No workspace has id ${args.workspace_id}. Workspaces: ${list || "none"}.`,
`No workspace has id ${args.workspace_id}. Workspaces: ${
live.map((w) => `${w.id}: ${w.name}`).join("; ") || "none"
}.`,
);
}