Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(rooms): answer a repeat bot @mention once per reply, and only by name
AdityaUmale617102a4786e
diff --git a/server/index.ts b/server/index.tsindex a245e5fba5..bd90bfec97 100644--- a/server/index.ts+++ b/server/index.ts@@ -326,6 +326,7 @@ import { createLiveSession, liveAttachUrl, liveHistoryFrom, LiveSessionError, tyimport { LiveCallController, LiveCallSignedOutError, openLiveSocket } from "./live-call-controller.ts";import { liveCallSettings, liveSettingsFor, liveSettingsForClient, saveLiveSettings } from "./live-settings.ts"; import { azureLiveCallRefusal, liveScopeRefusal } from "./live-access.ts";import { recordLiveCall, spokenLineFields, titleLiveCall } from "./live-call-record.ts";+import { noteGroupTurn, turnsSince } from "./room-round-turns.ts";import { narrateTool, toUtterances } from "./tts/speech-text.ts";import { createTtsRoutes } from "./routes/tts.ts";import { turnStartLogLine } from "./turn-log.ts";@@ -9689,7 +9690,7 @@ async function runClaimedGroupMemberTurn(return true;}revokeEarlierTurnCapabilities(threadId);- spoken.add(botId);+ noteGroupTurn(spoken, botId);// The same resolver as the readiness re-check below, or a Chief's delegated level makes every such turn retry and settle busy.const preparedApprovalMode = roomTurnApprovalMode(bot, threadId, orchestration);const preparedSelection = { ...bot.modelSelection };@@ -10551,16 +10552,17 @@ async function runClaimedGroupMemberTurn(},});}- // A bot that spoke earlier answers this direct mention again; one that already answered since this reply does not.- const spokeBeforeReply = new Set(spoken);+ // 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);+ const named = new Set(mentionedBots(replyText, members).map((member) => member.id));for (const next of roomResponders(replyText, members, { kind: "mentions" })) {if (isCancelled?.()) return false;- if (spoken.has(next.id) && !spokeBeforeReply.has(next.id)) continue;+ if (spokeBeforeReply.has(next.id) ? answeredSince(next.id) > 0 || !named.has(next.id) : spoken.has(next.id)) continue;if (operation) {const verdict = await waitForChatRoomMember(operation, threadId, next);if (verdict === "stop") return false;if (verdict === "skip") {- spoken.add(next.id);+ noteGroupTurn(spoken, next.id);continue;}}diff --git a/server/room-roots.e2e.test.ts b/server/room-roots.e2e.test.tsindex 6e91f8b38d..727b4e4466 100644--- a/server/room-roots.e2e.test.ts+++ b/server/room-roots.e2e.test.ts@@ -585,6 +585,41 @@ it("R8 answers a direct bot @mention again for a bot that already spoke, up to texpect(nothingLive(f)).toEqual([]);}), hostTimeout(90_000));+it("R8 does not run a bot twice for one reply when a nested mention already woke it", () => scenario(async (f) => {+ const mira = await f.bot("Mira", "Engineering");+ const bee = await f.bot("Bee", "Engineering");+ const room = await f.room("Engineering", [f.clive.id, mira.id, bee.id], { kind: "mentions" });+ f.script(bee.id,+ { key: "B0", match: ["R8C-JOB"], reply: "R8C-B0: noted." },+ { key: "B1", match: ["R8C-M1"], reply: "R8C-B1: agreed." },+ { key: "B-EXTRA", repeat: true, match: ["R8C"], reply: "R8C-EXTRA" });+ f.script(f.clive.id,+ { key: "C0", match: ["R8C-JOB"], reply: "R8C-C0: @Mira please check, @Bee please confirm." },+ { key: "C-EXTRA", repeat: true, match: ["R8C"], reply: "R8C-EXTRA" });+ f.script(mira.id,+ { key: "M1", match: ["R8C-C0"], reply: "R8C-M1: 42. @Bee agree?" },+ { key: "M-EXTRA", repeat: true, match: ["R8C"], reply: "R8C-EXTRA" });+ await f.post(room, "R8C-JOB: @Bee note this, then @Clive ask around.");+ await f.final(room.threadId, "R8C-B1");+ await expect.poll(() => nothingLive(f), { timeout: 15_000 }).toEqual([]);+ expect(f.turns().map((record: any) => record.planKey)).toEqual(["B0", "C0", "M1", "B1"]);+}), hostTimeout(90_000));++it("R8 does not wake a bot that already spoke for an @everyone from another bot", () => scenario(async (f) => {+ const mira = await f.bot("Mira", "Engineering");+ const room = await f.room("Engineering", [f.clive.id, mira.id], { kind: "member", botId: f.clive.id });+ f.script(f.clive.id,+ { key: "C0", match: ["R8D-JOB"], reply: "R8D-C0: @Mira please check the total." },+ { key: "C-EXTRA", repeat: true, match: ["R8D"], reply: "R8D-EXTRA" });+ f.script(mira.id,+ { key: "M1", match: ["R8D-C0"], reply: "R8D-M1: 42. Thanks @everyone." },+ { key: "M-EXTRA", repeat: true, match: ["R8D"], reply: "R8D-EXTRA" });+ await f.post(room, "R8D-JOB: what is the week's total?");+ await f.final(room.threadId, "R8D-M1");+ await expect.poll(() => nothingLive(f), { timeout: 15_000 }).toEqual([]);+ expect(f.turns().map((record: any) => record.planKey)).toEqual(["C0", "M1"]);+}), hostTimeout(90_000));+const goalDone = (detail: string) => `<openmaus-goal>${JSON.stringify({ status: "completed", detail })}</openmaus-goal>`;const sendGoal = (f: any, bot: { id: string; threadId: string }, text: string) =>f.api("POST", `/api/bots/${bot.id}/messages`, { text, mode: "goal", threadId: bot.threadId });diff --git a/server/room-round-turns.ts b/server/room-round-turns.tsnew file mode 100644index 0000000000..c041442045--- /dev/null+++ b/server/room-round-turns.ts@@ -0,0 +1,15 @@+/** Turns each bot took in one room round, keyed by that round's `spoken` set, so a repeat @mention is answered once per reply. */+const roundTurns = new WeakMap<Set<string>, Map<string, number>>();++export function noteGroupTurn(spoken: Set<string>, botId: string): void {+ spoken.add(botId);+ const turns = roundTurns.get(spoken) ?? new Map<string, number>();+ turns.set(botId, (turns.get(botId) ?? 0) + 1);+ roundTurns.set(spoken, turns);+}++/** Snapshot now; the returned function counts the turns a bot has taken in this round since. */+export function turnsSince(spoken: Set<string>): (botId: string) => number {+ const before = new Map(roundTurns.get(spoken));+ return (botId) => (roundTurns.get(spoken)?.get(botId) ?? 0) - (before.get(botId) ?? 0);+}