Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Routines: a routine with its own model opens its own thread
Doğukaan Kılıçarslane3da95122bcb
diff --git a/apps/docs/content/docs/features/automation.mdx b/apps/docs/content/docs/features/automation.mdxindex 40b8eb7630..25bccce665 100644--- a/apps/docs/content/docs/features/automation.mdx+++ b/apps/docs/content/docs/features/automation.mdx@@ -38,7 +38,7 @@ If your computer is often off when a routine is due, open the routine's **Advanc### A routine's own model-A routine runs on its bot's model unless it has its own. Give it one through the API with `modelSelection` (the same shape as a bot's: `instanceId`, `model`, and an optional `effort` or `variant`), for example a light hourly check on a smaller model while the bot chats on a stronger one: `PATCH /api/routines/<id>` with `{"modelSelection": {"instanceId": "claude", "model": "claude-haiku-4-5"}}`. Each run's thread then uses that model; if its AI isn't available, the thread falls back to the bot's model. Send `"modelSelection": null` to go back to the bot's model. Room goals always use their bots' own models.+A routine runs on its bot's model unless it has its own. Give it one through the API with `modelSelection` (the same shape as a bot's: `instanceId`, `model`, and an optional `effort` or `variant`), for example a light hourly check on a smaller model while the bot chats on a stronger one: `PATCH /api/routines/<id>` with `{"modelSelection": {"instanceId": "claude", "model": "claude-haiku-4-5"}}`. Each run's thread then uses that model; if its AI isn't available, the thread falls back to the bot's model. A routine with its own model always opens a new thread, so a limit-reset run doesn't continue the conversation it came from. Send `"modelSelection": null` to go back to the bot's model. Room goals always use their bots' own models.### Clear a folder's unread dotsdiff --git a/server/index.ts b/server/index.tsindex 17e564c73b..f6c3bf3b05 100644--- a/server/index.ts+++ b/server/index.ts@@ -8958,8 +8958,9 @@ routines = new RoutineManager({},joinConversation: (run) => {if (run.eventSource === "wait") return waitRunChat(run, directChatOf, Boolean(CLOUD_HOME));- const continues = routines?.listRoutines().some((routine) => routine.id === run.routineId && routine.schedule.type === "limit_reset");- if (!continues || run.target !== "bot") return null;+ const routine = routines?.listRoutines().find((each) => each.id === run.routineId);+ // A routine with its own model opens its own thread: a joined conversation keeps the conversation's model.+ if (routine?.schedule.type !== "limit_reset" || routine.modelSelection || run.target !== "bot") return null;const source = routineSourceOwner(run);if (!source || source.group || source.bot.id !== run.botId) return null;return source.threadId;diff --git a/server/limit-reset.e2e.test.ts b/server/limit-reset.e2e.test.tsindex ad21724c8e..a231966d4f 100644--- a/server/limit-reset.e2e.test.ts+++ b/server/limit-reset.e2e.test.ts@@ -150,6 +150,29 @@ it("with no other AI to carry on, the stopped turn's Continue sets up a run that});}, 120_000);+it("a limit-reset routine with its own model opens its own thread on that model, instead of continuing the conversation", async () => {+ await withLimitFixture({ codex: false }, async ({ api, control, limit, lift, evidence }) => {+ const resetsAt = Math.floor(Date.now() / 1000) + 10;+ limit(resetsAt);+ const { bot } = await control("new-bot", "--name", "Scout");+ const threadId = bot.activeTaskId;+ await control("send", "--bot", bot.id, "--task", threadId, "--text", "Write the quarterly report");+ expect((await control("wait", "--bot", bot.id, "--task", threadId, "--timeout", "30")).status).toBe("failed");+ const { routine } = await api("POST", "/api/limit-resets/continue", { botId: bot.id, threadId }, 201);+ const own = { instanceId: bot.modelSelection.instanceId, model: `${bot.modelSelection.model}-routine` };+ await api("PATCH", `/api/routines/${routine.id}`, { modelSelection: own });++ lift();+ await expect.poll(async () => (await api("GET", "/api/routines")).runs.find((run: any) => run.routineId === routine.id)?.status, { timeout: 40_000 }).toBe("completed");+ const run = (await api("GET", "/api/routines")).runs.find((candidate: any) => candidate.routineId === routine.id);+ expect(run.threadId).not.toBe(threadId);+ const { tasks } = (await api("GET", "/api/bots")).bots.find((entry: any) => entry.id === bot.id);+ expect(tasks.find((task: any) => task.threadId === run.threadId).modelSelection).toEqual(own);+ expect(tasks.find((task: any) => task.threadId === threadId).modelSelection).toEqual(bot.modelSelection);+ evidence.push({ routine, run });+ });+}, 120_000);+it("continues on the backup engine with one line, and goes back to its own engine after the reset", async () => {await withLimitFixture({ recovery: { enabled: true, backup: codex } }, async ({ api, control, limit, lift, claudePrompts, evidence }) => {const resetsAt = Math.floor(Date.now() / 1000) + 25;diff --git a/server/routine-model.e2e.test.ts b/server/routine-model.e2e.test.tsindex 867942cbaa..d1e6e5a7dd 100644--- a/server/routine-model.e2e.test.ts+++ b/server/routine-model.e2e.test.ts@@ -1,3 +1,4 @@+import { existsSync, readFileSync } from "node:fs";import { expect, it } from "vitest";import { launchVerificationServer, runControlOmb } from "../scripts/control-omb.ts";@@ -24,6 +25,9 @@ it("opens each run of a routine with its own model in the run's thread, and refuconst threadId = (await api("GET", "/api/routines")).body.runs.find((item: any) => item.id === run.id).threadId;const task = (await api("GET", "/api/bots")).body.bots.find((each: any) => each.id === bot.id).tasks.find((item: any) => item.threadId === threadId);expect(task.modelSelection).toEqual(own);+ await expect.poll(() => existsSync(fixture.fixtureDumpPath), { timeout: 30_000 }).toBe(true);+ const { argv } = JSON.parse(readFileSync(fixture.fixtureDumpPath, "utf8")) as { argv: string[] };+ expect(argv[argv.indexOf("--model") + 1]).toBe(own.model);const refused = await api("POST", "/api/routines", { name: "Inbox sweep", prompt: "Sweep the inbox", botId: bot.id,schedule: { type: "daily", time: "09:00", weekdays: [1] }, modelSelection: { instanceId: own.instanceId, model: own.model, effort: "galaxy" } });expect(refused).toMatchObject({ status: 400, body: { error: 'effort "galaxy" is not recognized' } });