Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Shared conversations read in the place's language, not the last speaker's
milind-soni0469ff41f8a3
diff --git a/server/host/person-languages.test.ts b/server/host/person-languages.test.tsindex e192b58706..afb7a3c19a 100644--- a/server/host/person-languages.test.ts+++ b/server/host/person-languages.test.ts@@ -16,16 +16,12 @@ function fixture(configured?: string, dataDir = mkdtempSync(join(tmpdir(), "omb-}describe("the language a line for a person is written in", () => {- it("is the one their app shows, else the place's: the one set here, else the one most people's apps show", () => {+ it("is the one their app shows, else the place's: the one set here, else the one every app here shows", () => {const { languages, tick } = fixture();expect(languages.forLine()).toBeUndefined();languages.heard("ada", "de");tick();- languages.heard("ben", "en");- tick();languages.heard("cy", "de");- expect(languages.forLine("ben")).toBe("en");- expect(languages.forLine("ada")).toBe("de");expect(languages.forLine("someone-new")).toBe("de");expect(languages.forLine()).toBe("de");const set = fixture("fr");@@ -34,17 +30,34 @@ describe("the language a line for a person is written in", () => {expect(set.languages.forLine()).toBe("fr");});- it("breaks a tie with the language heard last, and follows a person who changes theirs", () => {+ it("is English for nobody in particular once two people's apps differ: no one's pick decides for the others", () => {const { languages, tick } = fixture();- languages.heard("ada", "de");+ languages.heard("ada", "pt-br");tick();- languages.heard("ben", "es");- expect(languages.forLine()).toBe("es");+ languages.heard("ben", "en");tick();- languages.heard("ada", "de");- expect(languages.forLine()).toBe("de");- languages.heard("ada", "pt-BR");+ languages.heard("cy", "pt-br");+ expect(languages.forLine("ben")).toBe("en");expect(languages.forLine("ada")).toBe("pt-br");+ expect([languages.forLine(), languages.forLine("someone-new")]).toEqual([undefined, undefined]);+ tick();+ languages.heard("ada", "pt-br");+ expect(languages.forLine(), "hearing one again does not tip it").toBeUndefined();+ languages.heard("ben", "pt-BR");+ expect(languages.forLine("ben")).toBe("pt-br");+ expect(languages.forLine(), "everyone's now").toBe("pt-br");+ });++ it("writes a conversation's lines in its one person's language, and a shared one's in the place's, whoever spoke last", () => {+ const dataDir = mkdtempSync(join(tmpdir(), "omb-person-languages-"));+ dirs.push(dataDir);+ const languages = createPersonLanguages({ dataDir, configured: () => undefined, privateTo: (threadId) => (threadId === "ada-own" ? "ada" : null) });+ languages.heard("ada", "pt-br");+ languages.heard("ben", "en");+ expect(languages.forThread("ada-own")).toBe("pt-br");+ expect(languages.forThread("team-room")).toBeUndefined();+ const configured = createPersonLanguages({ dataDir, configured: () => "de", privateTo: () => null });+ expect(configured.forThread("team-room")).toBe("de");});it("keeps what it heard across a restart, and ignores what is not a language tag", () => {diff --git a/server/host/person-languages.ts b/server/host/person-languages.tsindex fe19b20672..770e88387c 100644--- a/server/host/person-languages.ts+++ b/server/host/person-languages.ts@@ -1,8 +1,9 @@// The language each person's app shows, from its presence pings (src/hooks/use-presence.ts), so the lines the server// writes for a person read in it (server/server-lines.ts). The app keeps a person's language pick on their own computer,// so this is the only way the server learns it. Kept on disk: a routine's line at night, with no app open, still knows.-// A line for nobody in particular reads in the place's language: the one set on this server or by the team's Admin,-// else the one most people's apps here show.+// A line for nobody in particular, or in a conversation more than one person reads (a room, a team's shared chat), reads+// in the place's language: the one set on this server or by the team's Admin, else the one every app here shows, else+// English. One person's pick never decides the words everyone else reads.import { readFileSync } from "node:fs";import { join } from "node:path";import { z } from "zod";@@ -24,6 +25,8 @@ export interface PersonLanguagesDeps {dataDir: string;/** The language set on this server, else the team's default from the Admin. */configured(): string | undefined;+ /** The one person a conversation is private to (a member's own chat on a Team Cloud), else null. */+ privateTo?(threadId: string): string | null;now?: () => number;}@@ -47,17 +50,13 @@ export function createPersonLanguages(deps: PersonLanguagesDeps) {}};- /** The language most people's apps here show; on a tie, the one heard most lately. */- const usual = (): string | undefined => {- const counts = new Map<string, { people: number; at: number }>();- for (const { language, at } of people.values()) {- const count = counts.get(language);- counts.set(language, { people: (count?.people ?? 0) + 1, at: Math.max(count?.at ?? 0, at) });- }- return [...counts].sort(([, a], [, b]) => b.people - a.people || b.at - a.at)[0]?.[0];+ /** The language every app heard here shows; none (English) when they differ. */+ const everyones = (): string | undefined => {+ const heard = new Set([...people.values()].map(({ language }) => language));+ return heard.size === 1 ? [...heard][0] : undefined;};- const forLine: LineLanguage = (person) => (person ? people.get(person)?.language : undefined) ?? deps.configured() ?? usual();+ const forLine: LineLanguage = (person) => (person ? people.get(person)?.language : undefined) ?? deps.configured() ?? everyones();return {/** A presence ping from this person's app: the language it shows. Written down only when it changes. */@@ -75,6 +74,9 @@ export function createPersonLanguages(deps: PersonLanguagesDeps) {save();},forLine,+ /** A line in this conversation: its person's language when it is private to one person, else the place's, never that+ * of whoever spoke last where others read too. */+ forThread: (threadId: string): string | undefined => forLine(deps.privateTo?.(threadId) ?? undefined),};}diff --git a/server/index.ts b/server/index.tsindex 1e905c88d4..8b3834bc13 100644--- a/server/index.ts+++ b/server/index.ts@@ -698,8 +698,8 @@ const CLOUD_SECRETS = BOOT_CLOUD_SECRETS;const CLOUD_ENV: NodeJS.ProcessEnv = { ...process.env, ...CLOUD_SECRETS };const CLOUD_HOME = cloudHomeConfiguration(CLOUD_ENV);const CLOUD_TEAM = CLOUD_HOME?.team ?? null, CLOUD_PERSONAL = CLOUD_HOME !== null && CLOUD_TEAM === null, TEAM_LABEL = CLOUD_TEAM ? { label: CLOUD_TEAM.name } : {};-/** The language set on this server, else (on a Team Cloud) the team's default from the Admin. threadLanguage: the one a line in a conversation is written in, its person's, else the place's (server/server-lines.ts). */-const appLanguage = (): string | undefined => cfg.language ?? CLOUD_TEAM?.language; const personLanguages = createPersonLanguages({ dataDir: DATA_DIR, configured: appLanguage }); const threadLanguage = (threadId: string): string | undefined => personLanguages.forLine(teamConversationPerson(threadId) ?? threadPersonKey(threadId)); setConversationLanguage(threadLanguage);+/** The language set on this server, else (on a Team Cloud) the team's default from the Admin. threadLanguage: the one a line in a conversation is written in, its one person's, else the place's (server/server-lines.ts). */+const appLanguage = (): string | undefined => cfg.language ?? CLOUD_TEAM?.language; const personLanguages = createPersonLanguages({ dataDir: DATA_DIR, configured: appLanguage, privateTo: (threadId) => teamHost.privateTo(threadId) }); const threadLanguage = personLanguages.forThread; setConversationLanguage(threadLanguage);if (CLOUD_HOME) repairMovedWorkspacePaths(DATA_DIR);if (CLOUD_PERSONAL) sessions.requireAdmin(userError("serverError.cloud.personal"));const lendingEnabled = () => sharedComputersEnabled(cfg) || CLOUD_HOME !== null || ownHome.here();@@ -4118,7 +4118,7 @@ const handoffTicks = createHandoffTicks(), coordinator: Coordinator = createCoorreturn outwardActions(turnRows(node));},shareAnswer: createShareAnswer({ askedFrom: (node) => (node.parentId ? coordinator.node(node.parentId)?.threadId : undefined), audienceOf: teamHost.audienceOf, pinned: (botId, threadId) => store.taskByThread(botId, threadId)?.cwd, botFolder: (botId) => store.bot(botId)?.cwd, privateFolders: TASK_WORKSPACES_DIR }),- joined: (node) => { store.appendMessage(node.threadId, { role: "bot", kind: "activity", tool: { name: `notice: ${serverLine(personLanguages.forLine(teamConversationPerson(node.threadId) ?? threadPersonKey(node.threadId)), "server.teammates.sameRequest")}`, ok: true } }); },+ joined: (node) => { store.appendMessage(node.threadId, { role: "bot", kind: "activity", tool: { name: `notice: ${serverLine(threadLanguage(node.threadId), "server.teammates.sameRequest")}`, ok: true } }); },},});threadsAwaitingTeammates = () => coordinator.awaitingTeammateThreads();@@ -5258,7 +5258,7 @@ cacheKeepWarmStatus = (threadId) => cacheKeepWarm.status(threadId);const warmSummaries = createWarmSummaryHost({ store, instance: (id) => registry.get(id), queued: hasQueuedSteeredMessages, coordinator, waits: () => botWaits, routines: () => routines,enabled: () => cfg.context?.autoCompact !== false && process.env.OMB_WARM_SUMMARY !== "0" && spendState(cfg, DATA_DIR)?.exceeded !== true, memoryShort: () => engineMemory.headroom() < 0.3,nativeCompactAt: (id) => { const instance = registry.get(id), at = instance ? nativeCompactTokens(instance) : undefined; return at && Number.isFinite(at) ? at : undefined; },- busy: (botId, threadId) => threadBusy(botId, threadId) || botHasActiveTurn(botId), keepWarmUntil: (threadId) => cacheKeepWarm.status(threadId)?.until, book: bookForkUsage, log: (line) => console.info(line), language: (threadId) => personLanguages.forLine(threadStarters.get(threadId)),+ busy: (botId, threadId) => threadBusy(botId, threadId) || botHasActiveTurn(botId), keepWarmUntil: (threadId) => cacheKeepWarm.status(threadId)?.until, book: bookForkUsage, log: (line) => console.info(line), language: threadLanguage,fold: async ({ botId, threadId, instanceId }, idle) => { const bot = store.projectBotForTask(botId, threadId), model = store.taskByThread(botId, threadId)?.lastContextModel, instance = registry.get(instanceId), before = latestCompaction(store.activePath(threadId))?.id;if (bot && instance && model?.startsWith(`${instanceId}:`)) await compactConversation({ bot, threadId, generation: `idle:${randomUUID()}`, instance, model: model.slice(instanceId.length + 1), excludedIds: new Set(), manual: false, idle });return latestCompaction(store.activePath(threadId))?.id !== before; } });@@ -6525,7 +6525,7 @@ bus.subscribe((event: RuntimeEvent) => {: group && speaker?.botId === asker.id ? roomTurnLevels.forRequest(event.threadId, asker.id, () => ownApprovalMode(asker)): ownApprovalMode(asker);const notAsked = !permission && asker && event.requestId ? questionRouting.notAsked({ botId: asker.id, threadId: event.threadId, level: effectiveApprovalMode, question: event.summary }) : undefined;- if (notAsked !== undefined && asker && event.requestId) { void answerRequest(event.threadId, event.providerInstanceId ?? asker.modelSelection.instanceId, event.requestId, "answer", notAsked); pushMessage({ role: "bot", kind: "activity", tool: { name: serverLine(personLanguages.forLine(teamHost.privateTo(event.threadId) ?? undefined), "server.questions.notAsked", { question: event.summary.slice(0, 160) }), ok: true } }); break; }+ if (notAsked !== undefined && asker && event.requestId) { void answerRequest(event.threadId, event.providerInstanceId ?? asker.modelSelection.instanceId, event.requestId, "answer", notAsked); pushMessage({ role: "bot", kind: "activity", tool: { name: serverLine(threadLanguage(event.threadId), "server.questions.notAsked", { question: event.summary.slice(0, 160) }), ok: true } }); break; }// Shell descriptors are distinct from computer/MCP permissions: a local desktop must not disable an exact shell grant.const command = permission && asker && event.requestId && !event.requiresExplicitApproval && event.command && !guestDriven? commandAllowlistCandidate({ ...event.command, providerInstanceId: event.providerInstanceId ?? asker.modelSelection.instanceId })