Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Merge pull request #3885 from Absterrg0/fix/bot-opened-thread-notifications
milind-soni20238f2f11c9
diff --cc server/index.tsindex ee4bf87987,752ca39aac..5bca391d12--- a/server/index.ts+++ b/server/index.ts@@@ -4040,8 -4100,8 +4040,8 @@@ const handoffTicks = createHandoffTicks});const quiet = turnAnswers(node.threadId, { cardContinuation: true, coordination: node }).quiet;const routineRoot = !node.parentId && activeRoutineRunForThread(node.threadId) !== null;- if (node.restart !== "rerun" && !quiet && !routineRoot && !node.parentId && asking.length === 0 && !doneNotice.owes(node.threadId)) {- if (node.restart !== "rerun" && !quiet && !routineRoot && asking.length === 0 && !unaskedBotThread(store.taskByThread(bot.id, node.threadId), store.activePath(node.threadId), node.parentId ? node.createdAt : undefined)) {- notify(buildNotification("delegation-settled", bot, node.threadId, `Results in from ${who}`, { avatarUrl: bot.avatarUrl }));++ if (node.restart !== "rerun" && !quiet && !routineRoot && !node.parentId && asking.length === 0 && !doneNotice.owes(node.threadId) && !unaskedBotThread(store.taskByThread(bot.id, node.threadId), store.activePath(node.threadId))) {+ notify(buildNotification("delegation-settled", bot, node.threadId, serverLine(language, "server.notify.resultsFrom", { who }), { avatarUrl: bot.avatarUrl }));}if (!node.parentId && !quiet) reviewAnswerThreads.add(node.threadId);} else if (node.restart === "rerun" && !group) {@@@ -6831,7 -6949,7 +6831,7 @@@ bus.subscribe((event: RuntimeEvent) =>const routineReportThread = routineRun ? routineSourceThread(routineRun) : null;if (!routineReportThread && (!internal || reviewAnswer)) store.patchTask(bot.id, event.threadId, { unread: true });if (routineRun && routineReportThread !== event.threadId) automationReports.runSettled(routineRun, completedTurnId);- else if ((!routineRun || routineRun.status === "completed") && (!internal || reviewAnswer) && !computerSelectionTurns.get(event.threadId)?.selected && doneNotice.atTurnEnd({ botId: bot.id, threadId: event.threadId, review: reviewAnswer, ok: event.ok, routine: Boolean(routineRun) }) === "notify" && !personWaits.atTurnEnd(event.threadId, reply)) {- else if ((!routineRun || routineRun.status === "completed") && !internal && !unaskedBotThread(settledTask, store.activePath(event.threadId)) && !computerSelectionTurns.get(event.threadId)?.selected) {++ else if ((!routineRun || routineRun.status === "completed") && (!internal || reviewAnswer) && !computerSelectionTurns.get(event.threadId)?.selected && doneNotice.atTurnEnd({ botId: bot.id, threadId: event.threadId, review: reviewAnswer, ok: event.ok, routine: Boolean(routineRun) }) === "notify" && !personWaits.atTurnEnd(event.threadId, reply) && !unaskedBotThread(settledTask, store.activePath(event.threadId))) {notify(buildNotification("done", bot, event.threadId, routineRun ? reply || routineRun.output || routineRun.routineName : reply, { avatarUrl: bot.avatarUrl }), routineRun ? { routine: true } : undefined);}if (screenPollers.has(event.threadId)) {diff --cc server/notify.test.tsindex b125ab0f74,b5a19cb3db..8befdfbc9a--- a/server/notify.test.ts+++ b/server/notify.test.ts@@@ -1,8 -1,6 +1,8 @@@-import { describe, expect, it } from "vitest";+import { afterEach, describe, expect, it } from "vitest";- import { buildNotification, buildSpendNotification, summarize } from "./notify.ts";+ import { buildNotification, buildSpendNotification, summarize, unaskedBotThread } from "./notify.ts";+import { conversationLanguage, setConversationLanguage } from "./server-lines.ts";+import "./server-line-packs.ts";const bot = { id: "bot-1", name: "Scout", threadId: "thread-1" };@@@ -140,28 -121,25 +140,51 @@@ describe("buildSpendNotification", () =});});+describe("a notification's title", () => {+ afterEach(() => setConversationLanguage(() => undefined));++ it("uses Brazilian Portuguese once on the server and leaves other conversations in English", () => {+ setConversationLanguage((threadId) => threadId === "thread-1" ? "pt-BR" : undefined);+ expect(buildNotification("question", bot, "thread-1", "Which file?", { group: { id: "g1", name: "Launch" } })?.title)+ .toBe("Scout em Launch tem uma pergunta");+ expect(buildNotification("routine-failed", bot, "thread-1", "Signed out.")?.title).toBe("A rotina de Scout falhou");+ expect(buildNotification("sign-in", bot, "thread-1", "", { site: "github.com" })?.title).toBe("Scout precisa que você faça login em github.com");+ expect(buildNotification("done", bot, "thread-1", "Done.")?.title).toBe("Scout terminou");+ expect(buildNotification("question", bot, "other", "Which file?")?.title).toBe("Scout has a question");+ });++ it("is in the language of the conversation's person", () => {+ setConversationLanguage((threadId) => (threadId === "beaver-main" ? "de" : undefined));+ const bot = { id: "beaver", name: "Biber", threadId: "beaver-main" };+ expect(conversationLanguage("beaver-main")).toBe("de");+ expect(buildNotification("routine-failed", bot, "beaver-main", "Nightly report: signed out")?.title).toBe("Routine von Biber ist fehlgeschlagen");+ expect(buildNotification("question", bot, "beaver-main", "Send it?", { group: { id: "launch", name: "Launch" } })?.title).toBe("Biber in Launch hat eine Frage");+ expect(buildNotification("sign-in", bot, "beaver-main", "", { site: "github.com" })?.title).toBe("Biber braucht deine Anmeldung bei github.com");+ expect(buildNotification("sign-in", bot, "beaver-main", "")?.title).toBe("Biber braucht deine Anmeldung bei einer Website");+ expect(buildNotification("done", bot, "beaver-main", "Done.")?.title).toBe("Biber ist fertig");+ expect(buildNotification("routine-failed", bot, "other", "x")?.title).toBe("Biber's routine failed");+ });+});+++ describe("unaskedBotThread", () => {+ const opened = { openedBy: { botId: "chief" } };+ const person = (at: number) => ({ role: "user", kind: "text", at });+ const peer = (at: number) => ({ role: "user", kind: "text", at, peerAsk: {} });+ const reply = (at: number) => ({ role: "bot", kind: "text", at });++ it("is quiet while the newest request in a bot-opened thread is a bot's", () => {+ expect(unaskedBotThread(opened, [])).toBe(true);+ expect(unaskedBotThread(opened, [peer(1), reply(2)])).toBe(true);+ expect(unaskedBotThread(opened, [peer(1), reply(2), person(3), reply(4), peer(5)])).toBe(true);+ expect(unaskedBotThread(opened, [person(1), reply(2)], 3)).toBe(true);+ });++ it("speaks for the person's own request, a failure report, and any thread a person opened", () => {+ expect(unaskedBotThread(opened, [peer(1), reply(2), person(3), reply(4)])).toBe(false);+ expect(unaskedBotThread(opened, [reply(2), person(3)], 1)).toBe(false);+ expect(unaskedBotThread(opened, [{ ...peer(1), peerAsk: { incident: {} } }])).toBe(false);+ expect(unaskedBotThread({}, [peer(1)])).toBe(false);+ expect(unaskedBotThread({}, [person(1)], 2)).toBe(false);+ expect(unaskedBotThread(undefined, [])).toBe(false);+ });+ });