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,4 +1,6 @@
import userAuth from "@/src/functions/backend/auth/user-auth";
import pushWorkspaceRemoved from "@/src/bots-queue/push-workspace-removed";
import grabWorkspaceAudience from "@/src/functions/backend/db/access/grab-workspace-audience";
import deleteWorkspace from "@/src/functions/backend/db/workspaces/delete-workspace";
import logEvent, { grabRequestIP } from "@/src/functions/backend/logger";
import { WorkspaceIdRequestSchema } from "@/src/schemas/workspace-schema";
@@ -33,8 +35,16 @@ export const handler: BunextAPIRouteHandler<APIResponseObject> = async ({ req, b
const { workspace_id } = parseWithSchema({ schema: WorkspaceIdRequestSchema, data: body });
/**
* Read before the delete: its links go with it, so who saw it
* can't be worked out afterwards.
*/
const audience = await grabWorkspaceAudience({ workspace_id });
const workspace = await deleteWorkspace({ user_id: user.id, workspace_id });
pushWorkspaceRemoved({ workspace_id, user_ids: audience });
await logEvent({
title: "Workspace deleted",
category: "system",