Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Merge #4290 at 3eb2b3225
milind-soni49c6e29b61f8
diff --cc server/routes/bot-messages.test.tsindex bf635c1001,2607dbf077..7956010af7--- a/server/routes/bot-messages.test.ts+++ b/server/routes/bot-messages.test.ts@@@ -40,7 -41,7 +41,7 @@@ class DirectSendRefused extends Errortype AcceptInput = Parameters<BotMessageRouteDeps["acceptDirectSend"]>[0];- async function fixture(over: Partial<Record<keyof BotMessageRouteDeps, unknown>> = {}) {-async function fixture(desktopManaged = true) {++async function fixture(over: Partial<Record<keyof BotMessageRouteDeps, unknown>> = {}, desktopManaged = true) {const store = new Store(() => sonnet);const bot = store.createBot({ name: "Scout" });const threadId = bot.threadId;@@@ -162,22 -162,35 +163,51 @@@return { store, bot, threadId, state, post, edit, cancelQueued, show, row, sent, patches: vi.spyOn(store, "patchMessage") };}+describe("editing a message with no AI", () => {+ it("says what a Send says on a team, and starts no turn", async () => {+ const line = "Olive needs to connect an AI before bots can answer. I've told them.";+ const { store, threadId, state, edit } = await fixture({ registry: { get: () => undefined }, noAiRefusal: () => Object.assign(new Error(line), { status: 409, code: "no_ai" }) });+ const sent = store.appendMessage(threadId, { role: "user", kind: "text", text: "Hello" });+ expect(await edit(sent.id, { threadId, text: "Hello again" })).toMatchObject({ status: 409, body: { error: line } });+ expect(state.started).toEqual([]);+ });++ it("keeps its own words off a team", async () => {+ const { store, threadId, edit } = await fixture({ registry: { get: () => undefined }, noAiRefusal: () => null });+ const sent = store.appendMessage(threadId, { role: "user", kind: "text", text: "Hello" });+ expect((await edit(sent.id, { threadId, text: "Hello again" })).body.error).toContain("is unavailable");+ });+});++ describe("POST /api/bots/:id/messages and who typed it", () => {+ const words = "Look at this and /standup it";++ it("takes a plain send from the desktop's own page as a person's", async () => {+ const { threadId, post } = await fixture();+ const plain = await post({ threadId, sendId: SEND, text: words });+ expect(plain.status, JSON.stringify(plain.body)).toBe(202);+ expect(typedWords(threadId, [plain.body.message])).toBe(words);+ });++ it("takes neither a press, whose words the widget wrote, nor a relay as a person's", async () => {+ const { store, bot, threadId, post, show } = await fixture();+ const pressed = await post({ threadId, sendId: SEND, text: words, widgetAction: { messageId: show("routineForm"), ref: "confirm", values: { days: "mon,tue,wed,thu,fri,sat,sun", report: "discord:releases" } } });+ expect(pressed.status, JSON.stringify(pressed.body)).toBe(202);+ expect(typedWords(threadId, [pressed.body.message])).toBe("");+ store.patchBot(bot.id, { approvalMode: "ask", autoApprove: false });+ const relayed = await post({ threadId, sendId: OTHER_SEND, text: words, expectedActiveLeafId: store.activeLeaf(threadId), expectedApprovalMode: "ask" }, "/guarded");+ expect(relayed.status, JSON.stringify(relayed.body)).toBe(202);+ expect(typedWords(threadId, [relayed.body.message])).toBe("");+ });++ it("does not take a bare loopback send as a person's on a headless server, where it may be a bot's shell", async () => {- const { threadId, post } = await fixture(false);++ const { threadId, post } = await fixture({}, false);+ const plain = await post({ threadId, sendId: SEND, text: words });+ expect(plain.status, JSON.stringify(plain.body)).toBe(202);+ expect(typedWords(threadId, [plain.body.message])).toBe("");+ });+ });+describe("POST /api/bots/:id/messages with widgetAction", () => {it("lets the server answer a press on its own card with no turn, refuses it for someone else, and reads no widget in another bot's chat", async () => {const { store, threadId, state, post, show, sent } = await fixture();