Files
cobble/src/harness/tools/bot/find-workspace-tool.ts
T
tben 139b3e443d 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.
2026-10-19 20:34:51 +01:00

59 lines
2.1 KiB
TypeScript

import { z } from "zod";
import grabUserWorkspaces from "@/src/functions/backend/db/workspaces/grab-user-workspaces";
import type { HarnessTool } from "../../types";
type Params = {
user_id: number | string;
};
type Args = {
query?: string;
limit?: number;
};
/**
* Lets the coordinator look up the user's live workspaces: by id, name,
* description or shared context, so it can find the one to change or
* delete. Read fresh every call, so a workspace another reply just
* created is already there.
*/
export default function findWorkspaceTool({ user_id }: Params): HarnessTool<Args> {
return {
name: "find_workspace",
description: `Find a live workspace: by id, name, description, or words in its shared context. Returns each match's id, name and description. With no query it lists them, up to limit.`,
schema: z.object({
query: z.string().trim().max(200).optional(),
limit: z.number().int().min(1).max(50).optional(),
}),
run: async ({ args }) => {
const live = (await grabUserWorkspaces({ user_id })).filter((w) => !w.archived);
const query = (args.query || "").trim().toLowerCase();
const matches = (
query
? live.filter((workspace) =>
[
workspace.id ? String(workspace.id) : "",
workspace.name,
workspace.description,
workspace.system_prompt,
].some((field) => (field || "").toLowerCase().includes(query)),
)
: live
).slice(0, args.limit ?? 20);
if (!matches.length) {
return `No workspace matches "${args.query || ""}".`;
}
return matches
.map(
(workspace) =>
`#${workspace.id} ${workspace.name}${workspace.description ? ` - ${workspace.description}` : ""}`,
)
.join("\n");
},
};
}