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
@@ -0,0 +1,29 @@
import BunSQLite from "@moduletrace/bun-sqlite";
import type { BUN_SQLITE_COBBLE_BOTS } from "@/db/types/db";
type Params = {
/**
* The workspace to scope them to: only its members. Left out for the
* whole crew (the coordinator's own chat).
*/
workspace_id?: number | string | null;
};
/**
* Every worker bot the coordinator can hand work to, by id. Read fresh on
* each call rather than carried from the start of the run, so a bot
* `create_bot` made earlier in the same reply is already there.
*/
export default async function grabCrewWorkers({
workspace_id,
}: Params = {}): Promise<BUN_SQLITE_COBBLE_BOTS[]> {
const res = await BunSQLite.sql<BUN_SQLITE_COBBLE_BOTS>({
sql: workspace_id
? `SELECT b.* FROM bots b JOIN workspace_bots wb ON wb.bot_id = b.id AND wb.workspace_id = ?
WHERE b.kind = 'worker' ORDER BY b.id ASC`
: `SELECT * FROM bots WHERE kind = 'worker' ORDER BY id ASC`,
values: workspace_id ? [workspace_id] : [],
});
return res.payload || [];
}