Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Rooms: the first answer hands skill shares to the bots it @mentions even when its own engine can't write skills
AdityaUmale70fb6fa6dd40
diff --git a/server/agents-turn.test.ts b/server/agents-turn.test.tsindex 5b1a87ed9d..0dfdcec085 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, botDrivenConversation, COMPUTER_OFF_REFUSAL, computerPickRefusal, directTurnKind, handRoomSkills, roomSkillsRefusal, roomTurnMayWriteSkills, takeRoomSkills, type AgentsConversation, type AgentsTurn, type RoomSkillsClaim } from "./agents-turn.ts";+import { agentsServerEnv, botDrivenConversation, COMPUTER_OFF_REFUSAL, computerPickRefusal, directTurnKind, handRoomSkills, roomSkillsRefusal, roomSkillsTurn, roomTurnMayWriteSkills, takeRoomSkills, type AgentsConversation, type AgentsTurn, type RoomSkillsClaim } from "./agents-turn.ts";const HOST: AgentsConversation["host"] = { skillAuthoring: true, sharedComputers: true, cloudHome: false, team: false, voiceNotes: true, x: true, research: true, imageGeneration: false, localVm: true };const CHAT: AgentsConversation = { threadId: "thread-1", bot: { id: "bot-1", chiefOfStaff: true }, room: false, teamComputer: false, host: HOST };@@ -185,6 +185,17 @@ describe("what a turn that may not use a listed tool is told", () => {expect(roomTurnMayWriteSkills(claim, 1, "video")).toBe(false);});+ it("lets the first answer hand shares to the bots it @mentions even when its own engine can't write skills", () => {+ const claim: RoomSkillsClaim = { claimed: false };+ expect(roomSkillsTurn(claim, 0, "writer", { allowed: true, canWrite: false })).toEqual({ writes: false, hands: true });+ expect(roomSkillsTurn(claim, 0, "writer", { allowed: true, canWrite: true })).toEqual({ writes: true, hands: true });+ expect(roomSkillsTurn(claim, 0, "writer", { allowed: false, canWrite: true })).toEqual({ writes: false, hands: false });+ handRoomSkills(claim, ["video"]);+ expect(roomSkillsTurn(claim, 1, "video", { allowed: true, canWrite: true })).toEqual({ writes: true, hands: false });+ takeRoomSkills(claim, 0, "editor", true);+ expect(roomSkillsTurn(claim, 0, "other", { allowed: true, canWrite: true })).toEqual({ writes: false, hands: false });+ });+it("gives the share back to a turn that never ran", () => {const claim: RoomSkillsClaim = { claimed: false };takeRoomSkills(claim, 0, "writer", true);diff --git a/server/agents-turn.ts b/server/agents-turn.tsindex c7460aa470..49509db6f2 100644--- a/server/agents-turn.ts+++ b/server/agents-turn.ts@@ -111,6 +111,13 @@ export function roomTurnMayWriteSkills(claim: RoomSkillsClaim, hop: number, botIreturn hop === 0 ? !claim.claimed : claim.mentioned?.has(botId) === true;}+/** What one room turn may do with skills: `writes` its own (it may, and its engine can), and `hands` a share to each bot it+ * @mentions (the first answer, even when its own engine can't write skills). */+export function roomSkillsTurn(claim: RoomSkillsClaim, hop: number, botId: string, { allowed, canWrite }: { allowed: boolean; canWrite: boolean }): { writes: boolean; hands: boolean } {+ const may = allowed && roomTurnMayWriteSkills(claim, hop, botId);+ return { writes: may && canWrite, hands: may && hop === 0 };+}+/** The first answer, holding the claim, @mentions `botIds`: each may change its own skills once on this message. Returns what* withdraws the shares still unused, for when that answer's mentions are done, so no later answer's mention can use them. */export function handRoomSkills(claim: RoomSkillsClaim, botIds: readonly string[]): () => void {diff --git a/server/index.ts b/server/index.tsindex 73ce32ad4e..4eeb8bb62f 100644--- a/server/index.ts+++ b/server/index.ts@@ -487,7 +487,7 @@ import { WebhookManager } from "./webhooks.ts";import { tieAutomationsToBots } from "./bot-automations.ts"; import { WaitManager } from "./waits.ts"; import { cancelWaitFromCard, createWaitHost, waitContinuationCheck, waitLineFields, waitRunChat, waitTurnRunId } from "./wait-host.ts"; import { continuedConversation } from "./routine-same-conversation.ts"; import { createWaitRoutes, findWaitPeer, handedAssignment, 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 { serverTurnedOff } from "./drivers/agents-tool-groups.ts"; import { availableToolGroups, toolsOffPart } from "./tool-groups.ts"; import { agentsServerEnv, botDrivenConversation, COMPUTER_OFF_REFUSAL, computerPickRefusal, directTurnKind, handRoomSkills, roomSkillsRefusal, roomTurnMayWriteSkills, takeRoomSkills, type RoomSkillsClaim, type TurnKind } from "./agents-turn.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, handRoomSkills, roomSkillsRefusal, roomSkillsTurn, takeRoomSkills, type RoomSkillsClaim, 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 { runSkillsLibraryBootSweep } from "./skills-library-migration.ts";@@ -9591,11 +9591,8 @@ async function runClaimedGroupMemberTurn(assertWithinBudget(cfg, DATA_DIR); if (!operation?.continuesRun) usageCapGate.assertTurn(bot.id, personWaitingInRoom(operation, routineTriggerOf(threadId)), threadLanguage(threadId));assertModelVariantSupported(turnSelection, instance.adapter.capabilities);const integrations: NonNullable<Parameters<typeof instance.adapter.sendTurn>[0]["integrations"]> = {};- const skillAuthoring =- skillAuthoringEnabled(cfg) &&- roomTurnMayWriteSkills(skillAuthoringClaim, hop, bot.id) &&- !cardContinuation &&- instance.adapter.capabilities.agentsMcp === true;+ const roomSkills = roomSkillsTurn(skillAuthoringClaim, hop, bot.id, { allowed: skillAuthoringEnabled(cfg) && !cardContinuation, canWrite: instance.adapter.capabilities.agentsMcp === true });+ const skillAuthoring = roomSkills.writes;if (instance.adapter.capabilities.agentsMcp === true) {integrations.agents = agentsIntegration(bot.id, threadId, hop, skillAuthoring, internalGeneration, orchestration?.roomHandoffId, supportsWorkspaceFiles(instance.driverKind));}@@ -10375,7 +10372,7 @@ async function runClaimedGroupMemberTurn(}// A bot that spoke earlier answers a mention by its own name (not @everyone) again, unless it took a turn since this reply.const spokeBeforeReply = new Set(spoken), answeredSince = turnsSince(spoken), named = new Set(mentionedBots(replyText, members).map((member) => member.id));- const responders = roomResponders(replyText, members, { kind: "mentions" }), withdrawSkills = skillAuthoring && hop === 0 ? handRoomSkills(skillAuthoringClaim, responders.map((next) => next.id)) : undefined;+ const responders = roomResponders(replyText, members, { kind: "mentions" }), withdrawSkills = roomSkills.hands ? handRoomSkills(skillAuthoringClaim, responders.map((next) => next.id)) : undefined;try { for (const next of responders) {if (isCancelled?.()) return false;if (spokeBeforeReply.has(next.id) ? answeredSince(next.id) > 0 || !named.has(next.id) : spoken.has(next.id)) continue;