Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Grok Bot export: write Bots back as a document holding only what the importer reads
aivsomkarbb253376d3ef
diff --git a/shared/grok-import.test.ts b/shared/grok-import.test.tsindex 4deaa3001b..18068842ab 100644--- a/shared/grok-import.test.ts+++ b/shared/grok-import.test.ts@@ -1,6 +1,6 @@import { describe, expect, it } from "vitest";-import { GROK_EXPORT_FORMAT, GROK_EXPORT_PROMPT, GROK_NOTES_FILE, GrokImportError, grokMovePlan, mergeGrokBots, parseGrokExport, type GrokBot } from "./grok-import.ts";+import { GROK_EXPORT_FORMAT, GROK_EXPORT_PROMPT, GROK_NOTES_FILE, GrokImportError, grokExportDocument, grokMovePlan, mergeGrokBots, parseGrokExport, type GrokBot } from "./grok-import.ts";import { parsePackageDocument } from "./package-format.ts";const TOKEN = "sk-abcdefghijklmnopqrstuvwx";@@ -147,6 +147,12 @@ describe("what an export may never bring", () => {expect(document.package.routines!.every((routine) => routine.enabledAfterInstall === false)).toBe(true);expect(() => parsePackageDocument(document, { trust: "file" })).not.toThrow();});+ it("writes back a document that reads as the same Bots, with nothing the parser does not read", () => {+ const bots = parseGrokExport(JSON.stringify({ ...EXPORT, stray: "x", bots: [{ ...BOT, extra: { anything: 1 } }, { name: "Maus", memories: ["likes cheese"] }] }));+ const written = JSON.stringify(grokExportDocument(bots));+ expect(parseGrokExport(written)).toEqual(bots);+ expect(written).not.toMatch(/stray|anything|real-secret-value|sk-abcdefghij/);+ });});describe("what comes over", () => {diff --git a/shared/grok-import.ts b/shared/grok-import.tsindex 50230bf4ab..2b5e15ee78 100644--- a/shared/grok-import.ts+++ b/shared/grok-import.ts@@ -288,6 +288,28 @@ export function parseGrokExport(text: string): GrokBot[] {return bots;}+/** Bots as one export document holding only what parseGrokExport reads from it: what a service that carries an+ * export keeps, in place of the text it was sent. An app's header values are never read, so only the names go. */+export function grokExportDocument(bots: readonly GrokBot[]): Record<string, unknown> {+ return {+ format: GROK_EXPORT_FORMAT,+ version: 1,+ bots: bots.map((bot) => ({+ name: bot.name, title: bot.title, description: bot.description, instructions: bot.instructions,+ memories: bot.memories, user_facts: bot.userFacts, skills: bot.skills,+ routines: bot.routines.map((routine) => ({+ name: routine.name, instruction: routine.instruction, trigger: routine.trigger, schedule_cron: routine.cron,+ schedule_text: routine.when, timezone: routine.timeZone, paused: routine.paused, skills: routine.skills,+ trigger_details: routine.details,+ })),+ apps: bot.apps.map((app) => ({+ name: app.name, mcp_url: app.mcpUrl, transport: app.transport,+ ...(app.headerNames.length ? { headers: Object.fromEntries(app.headerNames.map((header) => [header, ""])) } : {}),+ })),+ })),+ };+}+const slug = (value: string, max: number) =>value.normalize("NFKD").toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, max).replace(/-+$/, "");