Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Merge origin/main into train/nov15-p3
milind-soni4086d6cdc4d6
diff --cc server/host/limit-takeover.tsindex 2b3a3dc646,d71b120dc7..7b92e282a5--- a/server/host/limit-takeover.ts+++ b/server/host/limit-takeover.ts@@@ -83,17 -83,6 +83,17 @@@ interface SavedHolds { models?: Record<export function signedOutStop(stopReason: string | null | undefined, said: string | undefined): boolean {return stopReason === "auth_required" && !(said && (engineFailureKind(said) === "credits" || classifyError({ text: said }).reason === "quota"));}- export function takeoverRefusal(stopReason: string | null | undefined, said: string | undefined, limit: LimitScope | undefined): TakeoverScope | undefined {++export function takeoverRefusal(stopReason: string | null | undefined, said: string | undefined, limit: TakeoverScope | undefined): TakeoverScope | undefined {+ if (signedOutStop(stopReason, said)) return "signed-out";+ // A tool call's failure names the tool, never the engine's own limit, whatever its words.+ return limit ?? (stopReason !== "tool_error" && classifyError({ text: said ?? "" }).reason === "quota" ? "engine" : undefined);+}+export function turnRefusal(stopReason: string | null | undefined, said: string | undefined,+ flags: { limit?: LimitScope; limitResetsAt?: number } | undefined): { scope: TakeoverScope; resetsAt?: number } | undefined {+ const scope = takeoverRefusal(stopReason, said, flags?.limit);+ const resetsAt = scope === "signed-out" ? undefined : flags?.limitResetsAt;+ return scope ? { scope, ...(resetsAt ? { resetsAt } : {}) } : undefined;+}/** A row a conversation shows when its turn carried on elsewhere: `setup` marks the one signing in fixes. */export interface CarriedOnRow extends ServerToolText { name: string; ok: boolean; setup?: boolean }diff --cc server/index.tsindex d7d07a4ce0,d5d8bf8464..93026738b0--- a/server/index.ts+++ b/server/index.ts@@@ -212,9 -212,9 +212,9 @@@ import} from "./contracts.ts";import { RETRY_MAX_ATTEMPTS } from "./drivers/retry.ts";import { recoveryCapabilityError, startupBackups } from "./automatic-recovery.ts";- import { createQuotaSwitchHost } from "./host/quota-switch.ts"; import { quotaSwitchEnabled } from "./quota-switch.ts";+ import { createQuotaSwitchHost } from "./host/quota-switch.ts"; import { quotaSwitchEnabled } from "./quota-switch.ts"; import { createPeerLimitResend } from "./host/peer-limit-resend.ts";import { decodeGeneratedImage } from "./generated-image.ts";-import { createMcpServersHost } from "./host/mcp-servers-host.ts"; import { createMcpKeys } from "./vault/mcp-keys.ts"; import { createLimitTakeover, signedOutStop } from "./host/limit-takeover.ts";+import { createMcpServersHost } from "./host/mcp-servers-host.ts"; import { createMcpKeys } from "./vault/mcp-keys.ts"; import { createLimitTakeover, signedOutStop, turnRefusal } from "./host/limit-takeover.ts"; import { createHandoffLimits } from "./host/handoff-limits.ts";import {isRemoteMcpServer,parseStoredMcpServer,@@@ -5082,14 -5080,14 +5082,14 @@@ bus.subscribe((event: RuntimeEvent) =>message.role === "bot" && message.kind === "text" && message.turnId === event.turnId)?.text : undefined;const text = event.ok ? reply || event.stopReason || "The bot finished without a text reply": stoppedTurnText(event.threadId, event.turnId, undefined, event.stopReason);- const handoffPath = event.ok ? undefined : turnStops.read(event.threadId, event.turnId)?.handoffPath;+ const stop = event.ok ? undefined : turnStops.read(event.threadId, event.turnId), handoffPath = stop?.handoffPath, refusedBy = event.ok ? undefined : turnRefusal(event.stopReason, turnStops.failureCause(event), stop?.flags);const outcome: DirectTurnOutcome = { ok: event.ok, text: unansweredApprovals.annotate(event.threadId, event.turnId, text.slice(0, 12_000), event.ok), ...approvalAsk(store.botByThread(event.threadId)?.id, event.threadId, event.turnId),- ...(handoffPath ? { cap: { note: STEP_CAP_NOTE, handoffPath } } : {}) };+ ...(handoffPath ? { cap: { note: STEP_CAP_NOTE, handoffPath } } : {}), ...(refusedBy ? { refusedBy } : {}) };const owner = directFollowupTurns.complete(event.threadId, event.turnId, outcome);if (owner) {- settleDirectCoordination(owner.generation, outcome);+ peerLimitResend.ended(event, owner.generation, Boolean(handoffPath)); settleDirectCoordination(owner.generation, outcome);settleDirectFollowup(owner.generation);- }+ } else peerLimitResend.endedUnbound(event, Boolean(handoffPath));}} else if (event.type !== "session.exited") {watchdog.observe(event);diff --cc server/quota-switch.tsindex 212ff31fa8,fcb5933bed..2253d7d595--- a/server/quota-switch.ts+++ b/server/quota-switch.ts@@@ -70,6 -71,13 +70,12 @@@ export const NOT_NOW = "Not now"const ENDED: ReadonlySet<string> = new Set(["completed", "failed", "cancelled"]);+ /** Why a failed turn stopped, when it was its AI's usage limit or a sign-out. A tool call's failure names the tool,+ * never the engine's own limit, whatever its words. */+ export function turnLimitScope(event: SettledTurn, flags: { limit?: TakeoverScope } | undefined, cause: string | undefined): TakeoverScope | undefined {- return signedOutStop(event.stopReason, cause) ? "signed-out"- : flags?.limit ?? (event.stopReason !== "tool_error" && classifyError({ text: cause ?? "" }).reason === "quota" ? "engine" : undefined);++ return takeoverRefusal(event.stopReason, cause, flags?.limit);+ }+/** On unless OMB_QUOTA_SWITCH=0: a limited AI's work carries on with another AI by itself. Off, only the backups* Automatic recovery names take over, as before. */export function quotaSwitchEnabled(env: NodeJS.ProcessEnv = process.env): boolean {