Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(chief): recheck the copy source before writing; copied unusable model falls back
AdityaUmalec73d531b92e1
diff --git a/server/create-bot-model.e2e.test.ts b/server/create-bot-model.e2e.test.tsindex 0b34b4f41e..6d54b1c02c 100644--- a/server/create-bot-model.e2e.test.ts+++ b/server/create-bot-model.e2e.test.ts@@ -42,6 +42,9 @@ it("Chief creation uses the workspace default or a validated explicit model withexpect(result).toMatchObject({ state: "applied", applied: true });return { id: result.id as string, modelSelection: result.modelSelection };};+ // A bot whose model the installed CLI can no longer run; a copy of it falls back to the workspace default.+ const staleModel = { instanceId: "claude", model: claude.models.options.find((item: any) => item.needsCliUpdate).id };+ const stale = (await api("POST", "/api/bots", { name: "Stale specialist", section: "Design", modelSelection: staleModel }, 201)).bot;const before = (await api("GET", "/api/bots")).bots.length;const first = applied(await create("Default specialist"));// The installed CLI is too old for the newest model: a proposal may not name it, and the explicit pick is one it can run.@@ -55,11 +58,12 @@ it("Chief creation uses the workspace default or a validated explicit model with{ ...explicit, variant: "a-variant" }, { instanceId: "claude", model: tooNew.id }]) {await create("Invalid specialist", invalid, 400);}- await create("Third specialist");// A replacement copies a managed bot's soul, role and model; extra instructions come after.- const copyOf = (copyFromBotId: string, expected = 201) => api("POST", "/api/internal/create-bot", {- fromBotId: chief.id, fromThreadId: chief.threadId, name: "Fourth specialist", copyFromBotId, instructions: "Pick up the open work.",+ const copyOf = (copyFromBotId: string, expected = 201, extra = {}) => api("POST", "/api/internal/create-bot", {+ fromBotId: chief.id, fromThreadId: chief.threadId, name: "Fourth specialist", copyFromBotId, instructions: "Pick up the open work.", ...extra,}, expected, token);+ const staleCopy = applied(await copyOf(stale.id, 201, { name: "Third specialist", role: "Specialist" }));+ expect(staleCopy.modelSelection).toEqual(defaultModel);await copyOf("missing-bot", 404);const copy = applied(await copyOf(second.id));await create("Fifth specialist", undefined, 429);diff --git a/server/index.ts b/server/index.tsindex 0c0f33f997..b2a9394963 100644--- a/server/index.ts+++ b/server/index.ts@@ -14169,7 +14169,7 @@ const handleRequest = async (req: IncomingMessage, res: ServerResponse) => {}let selection: ModelSelection;if (body.modelSelection === undefined) {- const copied = fields.modelSelection && checkedModelSelection(fields.modelSelection, undefined, true); selection = copied && copied.ok ? copied.selection : await defaultSelection();+ const copied = fields.modelSelection && checkedModelSelection(fields.modelSelection, undefined, true); selection = copied && copied.ok && !validateModelProposal(copied.selection) ? copied.selection : await defaultSelection();} else {const checked = checkedModelSelection(body.modelSelection, undefined, true);if (!checked.ok) return json(res, checked.status, refusalBody(checked));@@ -14190,7 +14190,7 @@ const handleRequest = async (req: IncomingMessage, res: ServerResponse) => {return json(res, 429, { error: `You can create at most ${MAX_CREATED_BOTS_PER_TURN} bots in one turn. Use the team you have before adding more.` });}if (store.bots.length >= MAX_WORKSPACE_BOTS) return json(res, 409, { error: `this workspace is limited to ${MAX_WORKSPACE_BOTS} bots` });- const duplicate = store.bots.find(+ const recheck = body.copyFromBotId === undefined ? fields : createBotFields(body, chief, store.bots); if ("error" in recheck) return json(res, recheck.status, { error: recheck.error }); const duplicate = store.bots.find((candidate) =>!candidate.hidden &§ionKey(candidate.section) === sectionKey(chief.section) &&