The coordinator had no tool to add a worker, so a request to create one fell back to update_workspace and wrote a bot that did not exist into the workspace context. create_bot now adds a worker with its name, role and instructions and joins it to a workspace, and add_bot_to_workspace puts an existing worker in one. Both are coordinator-only and chat-replies-only, and createBot still enforces the crew-manager check. The coordinator's prompts now say how a bot gets created, and that one which does not exist is never written into workspace context. pick-free-hue moves to utils so the tool can pick a hue without importing from layouts.
23 lines
652 B
TypeScript
23 lines
652 B
TypeScript
import { BotHues, type BotHue } from "@/src/dict/bot-dict";
|
|
|
|
type Params = {
|
|
/**
|
|
* Hues the crew already has.
|
|
*/
|
|
taken: (string | null | undefined)[];
|
|
};
|
|
|
|
/**
|
|
* The first hue nobody on the crew has yet, else the least used one, so a
|
|
* new bot is told apart at a glance.
|
|
*/
|
|
export default function pickFreeHue({ taken }: Params): BotHue {
|
|
const counts = new Map<string, number>(BotHues.map((hue) => [hue.value, 0]));
|
|
|
|
for (const hue of taken) {
|
|
if (hue && counts.has(hue)) counts.set(hue, counts.get(hue)! + 1);
|
|
}
|
|
|
|
return [...BotHues].sort((a, b) => counts.get(a.value)! - counts.get(b.value)!)[0]!.value;
|
|
}
|