Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Offer select_computer only where a person's own message can use it (#5116)
Milind Soni86ee5d01a8b3
diff --git a/server/agents-turn.test.ts b/server/agents-turn.test.tsindex 92c5558199..b76076d52b 100644--- a/server/agents-turn.test.ts+++ b/server/agents-turn.test.ts@@ -4,7 +4,7 @@ import { createHash } from "node:crypto";import { describe, expect, it } from "vitest";import { TOOL_BRIDGE_ENV } from "./drivers/agents-bridge.ts";import { agentsMcp } from "./drivers/agents-mcp.ts";-import { agentsServerEnv, COMPUTER_OFF_REFUSAL, computerPickRefusal, directTurnKind, roomSkillsRefusal, type AgentsConversation, type AgentsTurn } from "./agents-turn.ts";+import { agentsServerEnv, botDrivenConversation, COMPUTER_OFF_REFUSAL, computerPickRefusal, directTurnKind, roomSkillsRefusal, type AgentsConversation, type AgentsTurn } from "./agents-turn.ts";const HOST: AgentsConversation["host"] = { skillAuthoring: true, sharedComputers: true, cloudHome: false, team: false, escalations: true, voiceNotes: true, x: true, research: true, imageGeneration: false };const CHAT: AgentsConversation = { threadId: "thread-1", bot: { id: "bot-1", chiefOfStaff: true }, room: false, teamComputer: false, host: HOST };@@ -54,6 +54,18 @@ describe("one conversation's agents tools", () => {}}+ it("never lists select_computer in a conversation only bots or automation drive, where every pick would be refused", async () => {+ const names = async (conversation: AgentsConversation) =>+ (JSON.parse((await everyTurn(conversation))[0]!.wire) as { tools: Array<{ name: string }> }).tools.map((tool) => tool.name);+ expect(await names(CHAT)).toContain("select_computer");+ expect(await names({ ...CHAT, botDriven: true })).not.toContain("select_computer");+ expect(botDrivenConversation({ openedBy: { botId: "b" } })).toBe(true);+ expect(botDrivenConversation({ botApi: true })).toBe(true);+ expect(botDrivenConversation({ routineRunId: "r1" })).toBe(true);+ expect(botDrivenConversation({})).toBe(false);+ expect(botDrivenConversation(undefined)).toBe(false);+ });+it("lists a direct chat select_computer and the wait tools and a room none, and both the skill tools while authoring is on", async () => {const names = async (conversation: AgentsConversation) =>(JSON.parse((await everyTurn(conversation))[0]!.wire) as { tools: Array<{ name: string }> }).tools.map((tool) => tool.name);diff --git a/server/agents-turn.ts b/server/agents-turn.tsindex f663378b91..7470d6ccdc 100644--- a/server/agents-turn.ts+++ b/server/agents-turn.ts@@ -13,6 +13,8 @@ export interface AgentsConversation {room: boolean;/** The bot works on its team's cloud computer, so it has no computer of its own to pick. */teamComputer: boolean;+ /** Only bots or automation drive it (`botDrivenConversation`): no turn in it is a person's own message to pick a computer for. */+ botDriven?: boolean;/** `x`: a research credential is held (a treg key or a plan's); `research`: research works for it too. */host: { skillAuthoring: boolean; sharedComputers: boolean; cloudHome: boolean; team: boolean; escalations: boolean; voiceNotes: boolean; x: boolean; research: boolean; imageGeneration: boolean; meetings?: boolean };}@@ -49,10 +51,15 @@ export function agentsServerEnv(conversation: AgentsConversation, turn: AgentsTuOMB_ESCALATIONS: flag(host.escalations),OMB_IMAGE_GENERATION: flag(host.imageGeneration),OMB_MEETINGS: flag(host.meetings === true && !conversation.room),- OMB_COMPUTER_SELECTION: flag(!conversation.room && bot.computer !== "off" && !conversation.teamComputer),+ OMB_COMPUTER_SELECTION: flag(!conversation.room && bot.computer !== "off" && !conversation.teamComputer && !conversation.botDriven),};}+/** A conversation a bot opened, the Bot API's, or a routine's run: a fact of the conversation, so its tool list stays the same turn to turn. */+export function botDrivenConversation(task: { openedBy?: unknown; botApi?: boolean; routineRunId?: string } | undefined): boolean {+ return Boolean(task && (task.openedBy || task.botApi || task.routineRunId));+}+/** What started a direct turn, in the words a refusal uses. */export type TurnKind = "person" | "routine" | "webhook" | "api" | "handoff" | "continuation";diff --git a/server/index.ts b/server/index.tsindex deb4b22ca0..6b4e75039a 100644--- a/server/index.ts+++ b/server/index.ts@@ -485,7 +485,7 @@ import { WebhookManager } from "./webhooks.ts";import { tieAutomationsToBots } from "./bot-automations.ts"; import { WaitManager } from "./waits.ts"; import { cancelWaitFromCard, createWaitHost, waitRunChat } from "./wait-host.ts"; import { createWaitRoutes, findWaitPeer, hostWaitRefusal, waitSourceRefusal, type WaitRouteContext } from "./routes/waits.ts";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 { agentsServerEnv, COMPUTER_OFF_REFUSAL, computerPickRefusal, directTurnKind, roomSkillsRefusal, type TurnKind } from "./agents-turn.ts";+import { agentsProxyLaunch, agentsToolBridgeEnv, applyAgentsBridge, bridgedToolTitle, turnEngine } from "./agents-bridge-switch.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,@@ -1823,13 +1823,13 @@ function agentsIntegration(skillAuthoring: boolean,generation: string,roomHandoffId?: string,- hostFiles = false,+ hostFiles = false, automated = false,) {const bot = store.bot(botId), speaking = botForThread(botId, threadId) ?? bot;// Only advertises the tools; the routes behind them refuse regardless.const host = { skillAuthoring: skillAuthoringEnabled(cfg), sharedComputers: botLending(), cloudHome: Boolean(CLOUD_HOME), team: Boolean(CLOUD_TEAM), escalations: chiefEscalationsEnabled(cfg),voiceNotes: tts.voiceReady(cfg, speaking?.voice) && speaking?.voiceNotes !== false, x: Boolean(researchCredential(cfg.treg?.key)), research: researchAvailability.available(), imageGeneration: imageGenerationReady(cfg), meetings: boat.boatConfigured(cfg) };- return { ...agentsProxyLaunch(), env: agentsServerEnv({ threadId, bot: bot ?? { id: botId }, room: Boolean(store.groupByThread(threadId)), teamComputer: Boolean(bot && inheritedTeamComputer(bot)), host },+ return { ...agentsProxyLaunch(), env: agentsServerEnv({ threadId, bot: bot ?? { id: botId }, room: Boolean(store.groupByThread(threadId)), teamComputer: Boolean(bot && inheritedTeamComputer(bot)), botDriven: automated || botDrivenConversation(store.taskByThread(botId, threadId)), host },{ generation, depth, skillAuthoring, roomHandoffId, ...(hostFiles && !CLOUD_HOME && !HOSTED_WORKSPACE ? { deliversSavedFiles: true } : {}) },(turn) => mintInternalCapability({ botId, threadId, kind: "agents", createdBots: 0, openedThreads: 0, ...turn }), `http://127.0.0.1:${PORT}`) };}@@ -7764,7 +7764,7 @@ async function beginTurn(...(opts?.goalRunId ? { goalRunId: opts.goalRunId } : {}) });}if (!opts?.computerSelectionContinuation && !opts?.cardContinuation && !opts?.automationSource && !opts?.unattended &&- !opts?.commsDepth && !opts?.coordination && !inheritedTeamComputer(bot) && bot.computer !== "off" && agentsMounted) {+ !opts?.commsDepth && !opts?.coordination && !inheritedTeamComputer(bot) && bot.computer !== "off" && agentsMounted && !botDrivenConversation(task)) {const source = store.activePath(threadId).findLast(message => message.id === userMessage?.id && message.role === "user" && !message.peerAsk);if (source) computerSelectionTurns.set(threadId, { generation: dispatchClaimId, botId: bot.id, source, text, dataContext: opts?.dataContext });}@@ -8272,7 +8272,7 @@ async function beginTurn(// One reachability rule: a bot is never told about a peer that coordinate_bots would refuse.const sectionPeers = reachablePeers(store.bots, bot);if (agentsMounted) {- integrations.agents = agentsIntegration(bot.id, threadId, commsDepth, skillAuthoring, dispatchClaimId, opts?.coordination?.id, worksInWorkspace);+ integrations.agents = agentsIntegration(bot.id, threadId, commsDepth, skillAuthoring, dispatchClaimId, opts?.coordination?.id, worksInWorkspace, opts?.automationSource !== undefined);}if (instance.adapter.capabilities.hooks === true && hooksEnabled()) {integrations.hooks = hooksIntegration(bot.id, threadId, dispatchClaimId);