Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Merge remote-tracking branch 'upstream/main' into fix/mail-1a1fa58c-own-window-lender
AdityaUmalef49a95324ca1
diff --cc server/index.tsindex e14f08aedf,93ccf43e26..8273574f7a--- a/server/index.ts+++ b/server/index.ts@@@ -885,10 -885,9 +885,10 @@@ function turnOrigin(capability: Pick<In/** Fail closed: only the person whose own message provably started this exact turn generation. Deliberately not the usage ledger's trigger, which defaults to the owner. */function sharedComputerPrincipal(capability: Pick<InternalCapability, "botId" | "threadId" | "generation">): string | null {if (CLOUD_HOME) { const lends = cloudLendingRefusal(capability) === null; if (lends) refusedLending.allowed(capability.threadId); return lends ? CLOUD_HOME_LENDER : null; }- return lendingPerson(provenRequestPerson(directRequestOwners.get(capability.threadId), capability.generation,- (messageId) => linePersonKey(store.messagesFor(capability.threadId).find((message) => message.id === messageId))), ownHome.ownServer(), () => sessions.list());+ const own = ownHome.ownServer(), request = directRequestOwners.get(capability.threadId);+ const person = provenRequestPerson(request, capability.generation, (messageId) => { const line = store.messagesFor(capability.threadId).find((message) => message.id === messageId); return linePersonKey(line) ?? ownWindowLender(own, ownWindowLine(capability.threadId, line)); });+ return person ? lendingPerson(person, own, () => sessions.list()) : request?.origin?.kind === "user" ? handedOwnServerLender(own, request.origin, actingPeople.requester(capability.threadId, capability.generation), () => sessions.list()) : null;- }+ } /** On a self-hosted server, the computers lent to it by the person this turn provably acts for. */ function lentToServer(agents: unknown, turn: Pick<InternalCapability, "botId" | "threadId" | "generation">) { return CLOUD_HOME || CLOUD_TEAM || DESKTOP_MANAGED || !agents || !botLending() ? undefined : sharedComputers.known(sharedComputerPrincipal(turn)).filter((computer) => computer.lent); }/** The only conversations that may feed a bot's memory, daily log, recall or brief; dropped whenever a session is revoked. */const ownerOnlyCache = new Map<string, { length: number; last?: string; owner: boolean }>();diff --cc server/routes/bot-messages.test.tsindex e0fa7c44fc,07c6f2e563..025fc7d832--- a/server/routes/bot-messages.test.ts+++ b/server/routes/bot-messages.test.ts@@@ -18,7 -18,7 +18,8 @@@ import type { RequestAuth } from "../reimport { acceptedSendMatch, sendFingerprint, SendSequencer } from "../send-idempotency.ts";import { _queuedCount, drainSteeredMessages, queuedSteeredMessage, queueSteeredMessage } from "../steer-queue.ts";import { Store, type Message } from "../store.ts";+ import { sendingSession } from "../sending-sessions.ts";+import { ownWindowLine } from "../own-window-sends.ts";import { typedWords } from "../typed-sends.ts";import { USER_ERROR } from "../user-errors.ts";import { createBotMessageRoutes, type BotMessageRouteDeps } from "./bot-messages.ts";diff --cc server/routes/bot-messages.tsindex 3710f5be6f,65d54c2145..3527c412e0--- a/server/routes/bot-messages.ts+++ b/server/routes/bot-messages.ts@@@ -35,7 -35,7 +35,8 @@@ import type { BotRecord, GroupRecord, Mimport { extractSteerImages } from "../turn-images.ts";import { followupFacts, helperFollowup, helperFollowupBody, mayFollowUp } from "../helper-followup.ts";import type { UsageTrigger } from "../usage-ledger.ts";+ import { forgetSendingSession, noteSendingSession } from "../sending-sessions.ts";+import { noteOwnWindowSend } from "../own-window-sends.ts";import { noteTypedSend } from "../typed-sends.ts";import { engineSessionOutdated, startFresh } from "../fresh-start.ts";import { parseMentionPicks } from "../../shared/room-mentions.ts";@@@ -342,8 -342,7 +343,9 @@@ export function createBotMessageRoutes(// paired session or the desktop capability proves a person and lifts the webhook block.const personPresent = auth.kind === "session" || DESKTOP_MANAGED;if (personPresent && sendId && !guarded && !press && !appSent) noteTypedSend(threadId, sendId, text);+ const notedSession = auth.kind === "session" && sendId ? noteSendingSession(threadId, sendId, auth.session.id) : false;+ // The desktop app's own window: in the desktop app a loopback change needs its private capability.+ if (DESKTOP_MANAGED && auth.kind === "loopback" && !auth.companionDevice && sendId && !guarded && !press && !appSent) noteOwnWindowSend(threadId, sendId, text);if (pressKey) pressesInFlight.set(pressKey, sendId);try {const receipt = await acceptDirectSend({