Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
// @vitest-environment happy-dom
import { createElement } from "react";
import { flushSync } from "react-dom";
import { createRoot } from "react-dom/client";
import { describe, expect, it, vi } from "vitest";
import { createAppStore } from "@/state/app-store";
import { initialState, reducer, type Action, type AppState, type Bot, type Message } from "@/state/store";
import { StoreSourceContext, type StoreSource } from "@/state/store-context";
import { DataResultChip } from "./DataResultChip";
const bot = (id: string): Bot => ({
id, threadId: `${id}-thread`, name: id, title: "", description: "", notifications: true, unread: false, color: "green",
modelSelection: { instanceId: "fake", model: "m" }, messages: [],
} as unknown as Bot);
describe("a data result's Open button follows the store", () => {
it("turns on once the result's bot arrives, without the row being drawn again from above", () => {
const store = createAppStore<AppState, Action, never>(reducer, { ...initialState, bots: [] }, (flush) => { flush(); return () => {}; });
const source: StoreSource = {
getState: store.getState, subscribe: store.subscribe, dispatch: store.dispatch,
flushBotPatches: vi.fn(), refreshInstances: vi.fn(), refreshModels: vi.fn(),
};
const message: Message = { id: "receipt", at: 1, role: "bot", kind: "activity", tool: { name: "data_show", ok: true },
dataResult: { botId: "analyst", cardId: "c_1", title: "Signups", kind: "table" } };
const container = document.createElement("div");
const root = createRoot(container);
flushSync(() => root.render(createElement(StoreSourceContext, { value: source }, createElement(DataResultChip, { message }))));
try {
const open = () => container.querySelector<HTMLButtonElement>("[data-data-result=c_1] button")!;
expect(open().disabled, "no such bot yet").toBe(true);
flushSync(() => store.dispatch({ type: "botAdded", bot: bot("analyst"), preserveSelection: true }));
expect(open().disabled, "the bot's arrival reaches the row").toBe(false);
} finally {
flushSync(() => root.unmount());
}
});
});