|
| 1 | +// The fake daemon's bot catalog (spec 26): the same twelve ids and |
| 2 | +// categories as the daemon's sheets, with short stand-in texts. Adding a |
| 3 | +// role goes through `bots.create`, so handles and notifications match. |
| 4 | + |
| 5 | +import type { FakeBotloft, Handlers } from "./fake"; |
| 6 | +import { botHandlers } from "./fakeBots"; |
| 7 | +import { notFound } from "./fakeRules"; |
| 8 | +import type { BotEffort, BotTemplateCategory, BotTemplateFull } from "./protocol.gen"; |
| 9 | + |
| 10 | +type CatalogMethods = Extract<keyof Handlers, `catalog.${string}`>; |
| 11 | + |
| 12 | +const ROLES: [id: string, category: BotTemplateCategory, name: string, effort?: BotEffort][] = [ |
| 13 | + ["developer", "code", "Developer"], |
| 14 | + ["code-reviewer", "code", "Code Reviewer", "high"], |
| 15 | + ["qa-tester", "code", "QA Tester"], |
| 16 | + ["designer", "design", "Designer"], |
| 17 | + ["writer", "content", "Writer"], |
| 18 | + ["social-media", "content", "Social Media"], |
| 19 | + ["translator", "content", "Translator"], |
| 20 | + ["researcher", "research", "Researcher"], |
| 21 | + ["data-analyst", "research", "Data Analyst"], |
| 22 | + ["sales-prospector", "business", "Sales Prospector"], |
| 23 | + ["customer-support", "business", "Customer Support"], |
| 24 | + ["personal-assistant", "business", "Personal Assistant"], |
| 25 | +]; |
| 26 | + |
| 27 | +/** Every role, as `catalog.get` returns it. */ |
| 28 | +export const FAKE_CATALOG: BotTemplateFull[] = ROLES.map(([id, category, name, effort]) => ({ |
| 29 | + id, |
| 30 | + category, |
| 31 | + name, |
| 32 | + role: `${name} role`, |
| 33 | + summary: `What the ${name.toLowerCase()} does`, |
| 34 | + model: "default", |
| 35 | + effort: effort ?? "default", |
| 36 | + instructions: `You are a ${name.toLowerCase()} on this crew.\n\n### What you do\nThe ${name.toLowerCase()}'s work.`, |
| 37 | +})); |
| 38 | + |
| 39 | +function find(id: string): BotTemplateFull { |
| 40 | + const found = FAKE_CATALOG.find((role) => role.id === id); |
| 41 | + if (!found) { |
| 42 | + throw notFound(`bot template ${id}`); |
| 43 | + } |
| 44 | + return found; |
| 45 | +} |
| 46 | + |
| 47 | +export function catalogHandlers(fake: FakeBotloft): Pick<Handlers, CatalogMethods> { |
| 48 | + return { |
| 49 | + "catalog.list": ({ category }) => |
| 50 | + FAKE_CATALOG.filter((role) => category === undefined || role.category === category).map( |
| 51 | + ({ id, category, name, role, summary }) => ({ id, category, name, role, summary }), |
| 52 | + ), |
| 53 | + "catalog.get": ({ id }) => find(id), |
| 54 | + "catalog.add": ({ crewId, templateId, name, role }) => { |
| 55 | + const template = find(templateId); |
| 56 | + const created = botHandlers(fake)["bots.create"]({ |
| 57 | + crewId, |
| 58 | + name, |
| 59 | + role, |
| 60 | + instructions: template.instructions, |
| 61 | + model: template.model, |
| 62 | + }); |
| 63 | + const bot = fake.bot(created.id); |
| 64 | + bot.effort = template.effort; |
| 65 | + return fake.changedBot(bot); |
| 66 | + }, |
| 67 | + }; |
| 68 | +} |
0 commit comments