Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Full access sends freely unless someone set this bot a sending rule
milind-sonic8ed74c9dce6
diff --git a/server/index.ts b/server/index.tsindex 60e595e600..f01af72454 100644--- a/server/index.ts+++ b/server/index.ts@@ -14659,9 +14659,13 @@ const handleRequest = async (req: IncomingMessage, res: ServerResponse) => {}const opaque = connectorCalls.some(call => call.slug === "COMPOSIO_PROXY_EXECUTE");if (opaque && currentSender.connectorTools !== undefined) return refuseOutbound("OpenMausBot cannot verify this code against this bot's tool grants. Use a direct app tool.");- const held: OutboundHoldAnswer = outboundTool+ // Full access sends freely unless someone set this bot a sending rule. A room turn can run at a Chief's delegated level, which only the room handoff carries.+ const sendsFreely = () => store.bot(internalCapability.botId)?.outbound === undefined && roomTurnLevels.forRequest(internalCapability.threadId, internalCapability.botId,+ () => sourceApprovalMode(internalCapability.botId, internalCapability.threadId)) === "full";+ const fullAccess = outboundTool !== null && sendsFreely();+ const held: OutboundHoldAnswer = outboundTool && !fullAccess? await outboundHold.hold({- bot: currentSender, threadId: internalCapability.threadId, tool: outboundTool, calls: outboundCalls, opaque,+ bot: currentSender, threadId: internalCapability.threadId, tool: outboundTool, calls: outboundCalls, opaque, fullAccess,active: () => internalCapabilityIsActive(internalCapability),}): { ok: true, approved: false };@@ -14698,7 +14702,7 @@ const handleRequest = async (req: IncomingMessage, res: ServerResponse) => {try {outboundHold.reserve({bot: fresh, threadId: internalCapability.threadId, tool: outboundTool, calls: outboundCalls, opaque,- approved: outboundApproved,+ fullAccess: fullAccess && sendsFreely(), approved: outboundApproved,});} catch (error) {refuseDispatch(error instanceof Error ? error.message : String(error));diff --git a/server/outbound-hold.test.ts b/server/outbound-hold.test.tsindex ea46b6ae3c..1346fca2cb 100644--- a/server/outbound-hold.test.ts+++ b/server/outbound-hold.test.ts@@ -61,7 +61,7 @@ function setup(bot: HoldBot) {activeGroupTurnForBot: () => null,notify: (notification) => notified.push(notification),};- const input = { bot, threadId: "t1", tool: "GMAIL_SEND_EMAIL", calls, opaque: false };+ const input = { bot, threadId: "t1", tool: "GMAIL_SEND_EMAIL", calls, opaque: false, fullAccess: false };return { hold: createOutboundHold(deps), dataDir, appended, patches, activity, notified, outboundRequests, input };}@@ -147,8 +147,12 @@ describe("createOutboundHold", () => {});it("reserve refuses when the hold was not approved and the policy is ask", async () => {- const { hold, input } = setup(bot({ policy: "ask", dailyCap: 10 }));- expect(() => hold.reserve({ ...input, approved: false })).toThrow(/outbound policy changed/);- expect(() => hold.reserve({ ...input, approved: true })).not.toThrow();+ const { hold, dataDir, input } = setup(bot({ policy: "ask", dailyCap: 10 }));+ expect(() => hold.reserve({ ...input, fullAccess: false, approved: false })).toThrow(/outbound policy changed/);++ // Full access sends freely and logs it.+ expect(() => hold.reserve({ ...input, fullAccess: true, approved: false })).not.toThrow();+ await flushDecisionLog(dataDir);+ expect(readDecisions(dataDir, 10)).toMatchObject([{ decision: "auto-approved", source: "outbound", rule: "full-access" }]);});});diff --git a/server/outbound-hold.ts b/server/outbound-hold.tsindex e0d24d9c7b..29ee4d9df1 100644--- a/server/outbound-hold.ts+++ b/server/outbound-hold.ts@@ -30,8 +30,10 @@ export interface OutboundHoldDeps {export type OutboundHoldAnswer = { ok: true; approved: boolean } | { ok: false; text: string };export interface OutboundHold {- hold(input: { bot: OutboundHoldBot; threadId: string; tool: string; calls: ConnectorCall[]; opaque: boolean; active: () => boolean }): Promise<OutboundHoldAnswer>;- reserve(input: { bot: OutboundHoldBot; threadId: string; tool: string; calls: ConnectorCall[]; opaque: boolean; approved: boolean }): void;+ /** Below Full access, a send waits on the "Send on your behalf?" card or spends the daily allowance. */+ hold(input: { bot: OutboundHoldBot; threadId: string; tool: string; calls: ConnectorCall[]; opaque: boolean; fullAccess: boolean; active: () => boolean }): Promise<OutboundHoldAnswer>;+ /** At dispatch time: Full access logs auto-approved; "allow" reserves against the cap; otherwise the hold must have been approved. Throws the refusal text. */+ reserve(input: { bot: OutboundHoldBot; threadId: string; tool: string; calls: ConnectorCall[]; opaque: boolean; fullAccess: boolean; approved: boolean }): void;}export function createOutboundHold(deps: OutboundHoldDeps): OutboundHold {@@ -40,8 +42,9 @@ export function createOutboundHold(deps: OutboundHoldDeps): OutboundHold {const { holdMs } = deps;return {- async hold({ bot: currentSender, threadId, tool: outboundTool, calls: outboundCalls, opaque, active }) {+ async hold({ bot: currentSender, threadId, tool: outboundTool, calls: outboundCalls, opaque, fullAccess, active }) {const refuseOutbound = (text: string): OutboundHoldAnswer => ({ ok: false, text });+ if (fullAccess) return { ok: true, approved: false };const policy = currentSender.outbound ?? DEFAULT_OUTBOUND_POLICY;const { app, calls, summary } = outboundCard(outboundCalls);const capNote = (count: number) =>@@ -110,20 +113,25 @@ export function createOutboundHold(deps: OutboundHoldDeps): OutboundHold {}return { ok: true, approved: false };},- reserve({ bot: fresh, threadId, tool: outboundTool, calls: outboundCalls, opaque, approved: outboundApproved }) {+ reserve({ bot: fresh, threadId, tool: outboundTool, calls: outboundCalls, opaque, fullAccess, approved: outboundApproved }) {const refuseDispatch: (text: string) => never = (text) => {throw new Error(text);};- const policy = fresh.outbound ?? DEFAULT_OUTBOUND_POLICY;- if (policy.policy === "allow" && !opaque) {- let reserved: number | null;- try { reserved = outboundCounts.reserve(fresh.id, outboundCalls.length, policy.dailyCap); }- catch { refuseDispatch("The daily allowance could not be saved. Nothing was sent."); }- if (reserved === null) refuseDispatch("This bot has reached its daily outbound limit. Nothing was sent.");+ if (fullAccess) {appendDecision(DATA_DIR, { threadId, botId: fresh.id, botName: fresh.name,- tool: outboundTool, decision: "auto-approved", source: "outbound", rule: `daily-allowance:${reserved}/${policy.dailyCap}` });- } else if (!outboundApproved) {- refuseDispatch("The outbound policy changed. Ask for approval again before sending.");+ tool: outboundTool, decision: "auto-approved", source: "outbound", rule: "full-access" });+ } else {+ const policy = fresh.outbound ?? DEFAULT_OUTBOUND_POLICY;+ if (policy.policy === "allow" && !opaque) {+ let reserved: number | null;+ try { reserved = outboundCounts.reserve(fresh.id, outboundCalls.length, policy.dailyCap); }+ catch { refuseDispatch("The daily allowance could not be saved. Nothing was sent."); }+ if (reserved === null) refuseDispatch("This bot has reached its daily outbound limit. Nothing was sent.");+ appendDecision(DATA_DIR, { threadId, botId: fresh.id, botName: fresh.name,+ tool: outboundTool, decision: "auto-approved", source: "outbound", rule: `daily-allowance:${reserved}/${policy.dailyCap}` });+ } else if (!outboundApproved) {+ refuseDispatch("The outbound policy changed. Ask for approval again before sending.");+ }}},};diff --git a/server/system-prompt.test.ts b/server/system-prompt.test.tsindex 319535a125..86a33fb913 100644--- a/server/system-prompt.test.ts+++ b/server/system-prompt.test.ts@@ -313,7 +313,7 @@ describe("shared sentences", () => {describe("composioSystemPrompt", () => {it("keeps the generic all-tools sentence for legacy bots, with the app tools every engine offers by name", () => {- expect(composioSystemPrompt(undefined)).toBe(`${COMPOSIO_PROMPT} Gmail and Google Calendar, when connected, have tools of their own: call gmail.search_emails, gmail.read_email, gmail.read_email_thread, gmail.create_draft, gmail.list_drafts, gmail.read_draft and gmail.update_draft. Draft requests never authorize sending. Revisions update the existing draft ID; creation always makes another draft. If an action fails or accidentally sends, report that fact accurately; a later draft does not undo a send, and googlecalendar.list_events and googlecalendar.list_calendars directly (your engine may show them behind its own prefix, with _ for the dot), and use the composio tools for everything else.`);+ expect(composioSystemPrompt(undefined)).toBe(`${COMPOSIO_PROMPT} Gmail and Google Calendar, when connected, have tools of their own: call gmail.search_emails, gmail.read_email, gmail.read_email_thread, gmail.create_draft, gmail.list_drafts, gmail.read_draft and gmail.update_draft, and googlecalendar.list_events and googlecalendar.list_calendars directly (your engine may show them behind its own prefix, with _ for the dot), and use the composio tools for everything else. Draft requests never authorize sending. Revisions update the existing draft ID; creation always makes another draft. If an action fails or accidentally sends, report that fact accurately; a later draft does not undo a send`);});it("names the app tools of only the apps a bot was granted", () => {diff --git a/server/system-prompt.ts b/server/system-prompt.tsindex 050b09b5e3..7ed2cb8a14 100644--- a/server/system-prompt.ts+++ b/server/system-prompt.ts@@ -176,8 +176,8 @@ export const COMPOSIO_PROMPT =" The user's connected apps (Gmail, Calendar, Slack, Notion, and the rest) are reachable through the composio tools — find the right one with COMPOSIO_SEARCH_TOOLS, read its arguments with COMPOSIO_GET_TOOL_SCHEMAS, then run it with COMPOSIO_MULTI_EXECUTE_TOOL. Reach for them before telling the user you have no access to a service.";/** The app tools a bot with these apps can call by name, on every engine. */-const APP_TOOLS_PROMPT: Record<string, { label: string; tools: string }> = {- gmail: { label: "Gmail", tools: "gmail.search_emails, gmail.read_email, gmail.read_email_thread, gmail.create_draft, gmail.list_drafts, gmail.read_draft and gmail.update_draft. Draft requests never authorize sending. Revisions update the existing draft ID; creation always makes another draft. If an action fails or accidentally sends, report that fact accurately; a later draft does not undo a send" },+const APP_TOOLS_PROMPT: Record<string, { label: string; tools: string; note?: string }> = {+ gmail: { label: "Gmail", tools: "gmail.search_emails, gmail.read_email, gmail.read_email_thread, gmail.create_draft, gmail.list_drafts, gmail.read_draft and gmail.update_draft", note: "Draft requests never authorize sending. Revisions update the existing draft ID; creation always makes another draft. If an action fails or accidentally sends, report that fact accurately; a later draft does not undo a send" },googlecalendar: { label: "Google Calendar", tools: "googlecalendar.list_events and googlecalendar.list_calendars" },};@@ -185,7 +185,7 @@ function appToolsPrompt(apps: readonly string[]): string {const named = apps.filter((app) => Object.hasOwn(APP_TOOLS_PROMPT, app)).map((app) => APP_TOOLS_PROMPT[app]!);if (!named.length) return "";const one = named.length === 1;- return ` ${named.map((app) => app.label).join(" and ")}, when connected, ${one ? "has tools of its" : "have tools of their"} own: call ${named.map((app) => app.tools).join(", and ")} directly (your engine may show them behind its own prefix, with _ for the dot), and use the composio tools for everything else.`;+ return ` ${named.map((app) => app.label).join(" and ")}, when connected, ${one ? "has tools of its" : "have tools of their"} own: call ${named.map((app) => app.tools).join(", and ")} directly (your engine may show them behind its own prefix, with _ for the dot), and use the composio tools for everything else.${named.map((app) => (app.note ? ` ${app.note}` : "")).join("")}`;}export function composioSystemPrompt(grants: Record<string, ConnectorToolGrant> | undefined): string {diff --git a/shared/outbound.ts b/shared/outbound.tsindex 66140dde30..d9fec95a53 100644--- a/shared/outbound.ts+++ b/shared/outbound.ts@@ -1,3 +1,8 @@+// Outbound actions: calls that reach a person outside the app or move money.+// Below Full access they get their own confirmation, or spend an optional daily+// allowance per bot; at Full access they run. A read-and-draft routine run never+// reaches them: the relay refuses every send there. Shared by the harness (which+// enforces it) and the app.import { isConnectedAppsServer } from "./own-apps.ts";export type OutboundPolicy = {diff --git a/src/locales/en.json b/src/locales/en.jsonindex 6e070cb6b3..6454005cd9 100644--- a/src/locales/en.json+++ b/src/locales/en.json@@ -3093,7 +3093,7 @@"permissions.approval.helpHanded": "Default for new threads, routines and work handed to it. Full access also applies at once to every existing thread. Use Refresh permissions on a thread to apply the current level to that conversation.","permissions.approval.applyFull": "Apply Full access to all threads","permissions.outbound.title": "Sending on your behalf",- "permissions.outbound.help": "Emails, messages, posts, invites, and payments through connected apps. Reading and drafting never count. These sending rules also apply at Full access.",+ "permissions.outbound.help": "Emails, messages, posts, invites, and payments through connected apps. Reading and drafting never count. Full access sends without asking unless you set a rule here.","permissions.outbound.ask": "Ask every time","permissions.outbound.askHint": "Every send waits for your tap.","permissions.outbound.allow": "Allow a daily amount",