Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
server/index.ts: stay at main's line count with the room takeover wired in
milind-sonic179aa7f079f
diff --git a/server/index.ts b/server/index.tsindex c953e85396..0e97d7e435 100644--- a/server/index.ts+++ b/server/index.ts@@ -488,14 +488,7 @@ import type { WebhookTrigger } from "../shared/webhooks.ts";import { AGENTS_NODE_FLAG, SPAWNED_PROXIES } from "./proxy-paths.ts";import { agentsProxyLaunch, agentsToolBridgeEnv, applyAgentsBridge, bridgedToolTitle, turnEngine } from "./agents-bridge-switch.ts"; import { serverTurnedOff } from "./drivers/agents-tool-groups.ts"; import { availableToolGroups, toolsOffPart } from "./tool-groups.ts"; import { agentsServerEnv, botDrivenConversation, COMPUTER_OFF_REFUSAL, computerPickRefusal, directTurnKind, roomSkillsRefusal, type TurnKind } from "./agents-turn.ts";import { harnessMcpTokenEnv } from "./harness-mcp-token.ts";-import {- loadBundledSkills,- loadUserSkills,- mergeSkills,- renderSkillInstructions,- selectBundledSkills,- skillsLibraryEnabled, readSkillLibraryIndex,-} from "./skill-library.ts";+import { loadBundledSkills, loadUserSkills, mergeSkills, renderSkillInstructions, selectBundledSkills, skillsLibraryEnabled, readSkillLibraryIndex } from "./skill-library.ts";import { runSkillsLibraryBootSweep } from "./skills-library-migration.ts";import { installedPlaybookInstructions } from "./installed-playbooks.ts";import type { PackageImportDeps } from "./package-import.ts";@@ -8470,8 +8463,7 @@ async function beginTurn(if (e instanceof PlaceUnavailableError) clearFailedAutoPin(bot.id, threadId, e.place);let message = e instanceof Error ? e.message : String(e);const current = store.projectBotForTask(bot.id, threadId), takeoverScope = e instanceof TurnUsageLimitRefusedError ? e.scope : e instanceof TurnAuthenticationRefusedError ? "signed-out" as const : undefined;- const weighed = takeoverScope && current && quotaSwitchEnabled() ? limitTakeover.weighBackups(bot.id, current.modelSelection, takeoverScope, approvalModeFor(current)) : null;- if (weighed && takeoverScope && current) limitTakeover.passedOver(current, current.modelSelection, takeoverScope, weighed.skipped);+ const weighed = takeoverScope && current && quotaSwitchEnabled() ? limitTakeover.weighBackups(bot.id, current.modelSelection, takeoverScope, approvalModeFor(current)) : null; if (weighed && takeoverScope && current) limitTakeover.passedOver(current, current.modelSelection, takeoverScope, weighed.skipped);const backups = weighed ? weighed.backups : current ? startupBackups(current, cfg.automaticRecovery) : [];const nextIndex = backups.findIndex((candidate, index) => index >= (opts?.automaticRecoveryIndex ?? 0) &®istry.get(candidate.instanceId)?.enabled && (e instanceof TurnUsageLimitRefusedError ? (candidate.instanceId === instanceId ? e.scope !== "engine" : limitBackupAllowed(instance, registry.get(candidate.instanceId)!, instanceConfigs(cfg)[candidate.instanceId]))@@ -9559,10 +9551,8 @@ async function runClaimedGroupMemberTurn(const preparedApprovalMode = roomTurnApprovalMode(bot, threadId, orchestration);const preparedSelection = { ...bot.modelSelection };const preparedComposio = bot.composio;- const ownInstance = registry.get(bot.modelSelection.instanceId);- const roomTakeover = roomLimits.atStart(bot, preparedApprovalMode);- const turnSelection: ModelSelection = roomTakeover?.to ?? preparedSelection;- const instance = registry.get(turnSelection.instanceId);+ const ownInstance = registry.get(bot.modelSelection.instanceId), roomTakeover = roomLimits.atStart(bot, preparedApprovalMode);+ const turnSelection: ModelSelection = roomTakeover?.to ?? preparedSelection, instance = registry.get(turnSelection.instanceId);const userName = userNameFor(threadId);if (providerInstancesChanging.has(bot.modelSelection.instanceId) || providerInstancesChanging.has(turnSelection.instanceId)) {onDispatchError?.(`${bot.name}'s provider account is being updated — try again shortly`);@@ -9730,8 +9720,7 @@ async function runClaimedGroupMemberTurn(: Boolean(readyGroup && store.groupTaskByThread(readyGroup.id, threadId));if (!readyGroup || !stillOwnsThread || !readyGroup.memberIds.includes(readyBot.id)) return false;const setupChanged =- registry.get(readyBot.modelSelection.instanceId) !== ownInstance ||- registry.get(turnSelection.instanceId) !== instance ||+ registry.get(readyBot.modelSelection.instanceId) !== ownInstance || registry.get(turnSelection.instanceId) !== instance ||roomTurnApprovalMode(readyBot, threadId, orchestration) !== preparedApprovalMode ||readyBot.modelSelection.instanceId !== preparedSelection.instanceId ||readyBot.modelSelection.model !== preparedSelection.model ||@@ -10119,8 +10108,7 @@ async function runClaimedGroupMemberTurn(}const turnTexts: string[] = [];let turnCompletedOk = false;- let turnCompleted: Extract<RuntimeEvent, { type: "turn.completed" }> | undefined;- let oneTimeInputTaken = false;+ let turnCompleted: Extract<RuntimeEvent, { type: "turn.completed" }> | undefined, oneTimeInputTaken = false;let providerTurnId: string | undefined;let abandoned = false;const retirementOwner = `room-abandoned:${randomUUID()}`;@@ -10171,8 +10159,7 @@ async function runClaimedGroupMemberTurn(deadline.observe(e);if (e.type === "item.completed" && e.itemType === "assistant_text") turnTexts.push(e.text);else if (e.type === "turn.completed") {- turnCompletedOk = e.ok;- turnCompleted = e;+ turnCompletedOk = e.ok; turnCompleted = e;const end = roomTurnEnd(e, Boolean(orchestration), roomClaimFailure);if (orchestration && end.stopReason !== undefined) {orchestration.result.stopReason = roomClaimFailure ? end.stopReason : stoppedTurnText(threadId, e.turnId, undefined, end.stopReason);@@ -10204,9 +10191,7 @@ async function runClaimedGroupMemberTurn(const turnApprovalMode = roomTurnApprovalMode(readyBot, threadId, orchestration);if (!done) releaseTurnLevel = roomTurnLevels.dispatched(threadId, readyBot.id, turnApprovalMode);const { reset: roomReset, displaced } = roomMemberContexts.dispatch(threadId, readyBot.id, instance.instanceId, cfg.context);- for (const tool of roomTakeover ? limitTakeover.carryOnRows(readyBot, preparedSelection, roomTakeover.to, roomTakeover) : []) {- store.appendMessage(threadId, { role: "bot", kind: "activity", from: { botId: readyBot.id, name: readyBot.name, color: readyBot.color }, tool });- }+ for (const tool of roomTakeover ? limitTakeover.carryOnRows(readyBot, preparedSelection, roomTakeover.to, roomTakeover) : []) store.appendMessage(threadId, { role: "bot", kind: "activity", from: { botId: readyBot.id, name: readyBot.name, color: readyBot.color }, tool });if (roomReset) {store.appendMessage(threadId, {role: "bot", kind: "activity", from: { botId: readyBot.id, name: readyBot.name, color: readyBot.color },@@ -10359,8 +10344,7 @@ async function runClaimedGroupMemberTurn(return false;}const resent = orchestration || cardContinuation || oneTimeInputTaken || outcome !== "settled" || isCancelled?.() ? undefined : await roomLimits.resendOnce(threadId, bot, preparedApprovalMode, turnCompleted, roomSpeaker?.since ?? 0,- () => runGroupMemberTurn(groupId, threadId, bot.id, hop, spoken, undefined, onDispatchError, isCancelled, onProviderHandshakeStarted, onProviderHandshakeSettled, skillAuthoringClaim, undefined, operation));- if (resent !== undefined) return resent;+ () => runGroupMemberTurn(groupId, threadId, bot.id, hop, spoken, undefined, onDispatchError, isCancelled, onProviderHandshakeStarted, onProviderHandshakeSettled, skillAuthoringClaim, undefined, operation)); if (resent !== undefined) return resent;if (!orchestration &&