Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

Keep the kept-computer refusal out of the size-capped routines file

AdityaUmaleeaa24611b371
diff --git a/server/routine-computer.ts b/server/routine-computer.ts
index 97f7da2eaa..c42531e6ef 100644
--- a/server/routine-computer.ts
+++ b/server/routine-computer.ts
@@ -12,9 +12,9 @@ export function routineComputer(value: unknown, routine: { target?: Routine["tar
/** A bot on its team's computer works there on every turn, so its routines may keep only the cloud computer. */
export const TEAM_COMPUTER_REFUSAL = "This bot works on its team's cloud computer, so its routines can't keep another computer. Clear the computer, or take the bot off the team computer first.";
-/** Why a routine of this bot can't keep `computer`, or null when it can. */
-export function keptComputerRefusal(computer: RoutineComputer | undefined, onTeamComputer: boolean): string | null {
- return computer && computer !== "cloud" && onTeamComputer ? TEAM_COMPUTER_REFUSAL : null;
+/** Throws when a routine keeps a computer other than the cloud one for a bot on its team's computer. */
+export function refuseKeptComputer(routine: { botId: string; computer?: RoutineComputer }, onTeamComputer?: (botId: string) => boolean): void {
+ if (routine.computer && routine.computer !== "cloud" && onTeamComputer?.(routine.botId)) throw new Error(TEAM_COMPUTER_REFUSAL);
}
/** The computer the person chose for a chat; a place a turn picked on its own (Auto) is not kept, nor any by a bot on its team's computer. */
diff --git a/server/routines.ts b/server/routines.ts
index 559477231e..e87ca0446d 100644
--- a/server/routines.ts
+++ b/server/routines.ts
@@ -36,7 +36,7 @@ import { EVENT_RETRY_WINDOW_MS, MAX_EVENT_RECEIPTS, type EventRunReceipt } from
import { attachmentPathsOf, cloneAttachments } from "./routine-attachments.ts";
import { loadInstalledPackage, matchingRequestReceipt, rememberRequest } from "./routine-load.ts";
import { applyHolds, holdCauses, type AppliedHolds } from "./routine-holds.ts";
-import { cancelUnfinishedRuns, interruptRunTurns } from "./routine-stops.ts"; import { keptComputerRefusal } from "./routine-computer.ts";
+import { cancelUnfinishedRuns, interruptRunTurns } from "./routine-stops.ts"; import { refuseKeptComputer } from "./routine-computer.ts";
import { sanitizeInput } from "./routine-input.ts";
import { applyCheckResult, codedLine, keptRunOutput, routineLine, runLineFields, type RoutineLine, type RoutineLineCodes, type RoutineTroubleCode } from "./routine-lines.ts";
import { checkHold, CHECK_BOOT_HOLD_MS, type CheckHold } from "./routine-check-pacing.ts";
@@ -565,8 +565,7 @@ export class RoutineManager {
const at = this.now();
const clean = sanitizeInput(input, at);
clean.schedule = this.timedSchedule(clean.schedule);
- if (this.targetState(clean) === "missing") throw new Error(this.missingTargetMessage(clean.target));
- this.refuseKeptComputer(clean);
+ if (this.targetState(clean) === "missing") throw new Error(this.missingTargetMessage(clean.target)); refuseKeptComputer(clean, this.options.teamComputer);
const nextRunAt = clean.enabled ? this.initialOccurrence(clean.schedule, at) : null;
if (clean.schedule.type === "interval" && clean.enabled && nextRunAt === null) {
throw new Error("This interval has no future runs. Choose a later end date or turn it off.");
@@ -629,8 +628,7 @@ export class RoutineManager {
deliver: Object.hasOwn(patch, "deliver") ? patch.deliver : routine.deliver, computer: Object.hasOwn(patch, "computer") ? patch.computer : routine.computer,
}, now);
clean.schedule = this.timedSchedule(clean.schedule, routine.id);
- if (this.targetState(clean) === "missing") throw new Error(this.missingTargetMessage(clean.target));
- if (patch.computer) this.refuseKeptComputer(clean);
+ if (this.targetState(clean) === "missing") throw new Error(this.missingTargetMessage(clean.target)); if (patch.computer) refuseKeptComputer(clean, this.options.teamComputer);
const scheduleChanged = JSON.stringify(clean.schedule) !== JSON.stringify(routine.schedule);
const enabledChanged = clean.enabled !== routine.enabled;
if (enabledChanged && clean.enabled && clean.schedule.type === "once" && clean.schedule.at <= now) throw new RoutineScheduleError("Its time has passed. Edit it to pick a new time.");
@@ -1411,11 +1409,6 @@ export class RoutineManager {
return this.options.botState(target.botId);
}
- private refuseKeptComputer(routine: { botId: string; computer?: RoutineComputer }): void {
- const refusal = keptComputerRefusal(routine.computer, this.options.teamComputer?.(routine.botId) === true);
- if (refusal) throw new Error(refusal);
- }
-
private missingTargetMessage(target: RoutineTarget): string {
return target === "room-goal"
? "The assigned room or coordinator no longer exists"