Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(connectors): tell the bot when an app it asked to connect already has an account
AdityaUmale8cea60517ddf
diff --git a/server/connector-proxy.test.ts b/server/connector-proxy.test.tsindex 58db28c131..f2f4ca53ff 100644--- a/server/connector-proxy.test.ts+++ b/server/connector-proxy.test.ts@@ -187,6 +187,24 @@ describe("connector MCP bridge", () => {);});+ it("tells the bot when an app it asked to connect already has an account, so it can ask again with an alias", async () => {+ const note = "Gmail already has a connected account, so its card shows it connected and no new account was added. "+ + "To add another Gmail account, call COMPOSIO_MANAGE_CONNECTIONS again with toolkits: [{\"name\": \"gmail\", \"alias\": \"<a short name for the new account>\"}].";+ const harness = await listen((request, response) => {+ request.resume();+ request.on("end", () => {+ response.writeHead(200, { "content-type": "application/json" });+ response.end(JSON.stringify({ messageIds: ["m1"], connectedNote: note }));+ });+ });+ const lines = start({ OMB_HARNESS_URL: harness, OMB_CONNECTOR_TOKEN: "bridge-secret", OMB_BOT_ID: "bot-1", OMB_THREAD_ID: "thread-1" });+ child!.stdin.write(`${JSON.stringify({ jsonrpc: "2.0", id: 4, method: "tools/call", params: { name: "COMPOSIO_MANAGE_CONNECTIONS", arguments: { toolkits: ["gmail"] } } })}\n`);+ expect((await nextJson(lines)).result.content[0].text).toBe(+ `OpenMausBot showed the user a secure connection card for gmail. ${note} End this turn now. The app will continue the task `+ + "automatically after the connection finishes.",+ );+ });+it("offers auth_config_id on COMPOSIO_MANAGE_CONNECTIONS, whose Composio schema has none", async () => {const manage = {name: "COMPOSIO_MANAGE_CONNECTIONS",diff --git a/server/connector-proxy.ts b/server/connector-proxy.tsindex e1246617c9..6fc96eeac4 100644--- a/server/connector-proxy.ts+++ b/server/connector-proxy.ts@@ -204,7 +204,7 @@ function connectorAdds(args: unknown): { requests: ConnectorRequest[]; badAuthCoreturn { requests: checked, badAuthConfig };}-/** Resolves to the harness's line on which auth config each toolkit connects with, when it names one. */+/** Resolves to the harness's lines on which auth config each toolkit connects with, and on apps already connected, when it has any. */async function showConnectorCards(items: ConnectorRequest[]): Promise<string> {const response = await fetch(`${HARNESS}/api/internal/connectors/request`, {method: "POST",@@ -212,9 +212,9 @@ async function showConnectorCards(items: ConnectorRequest[]): Promise<string> {body: JSON.stringify({ botId: BOT_ID, threadId: THREAD_ID, items, resumeKey: randomUUID() }),signal: AbortSignal.timeout(30_000),});- const body = (await response.json().catch(() => ({}))) as { error?: unknown; authConfigNote?: unknown };+ const body = (await response.json().catch(() => ({}))) as { error?: unknown; authConfigNote?: unknown; connectedNote?: unknown };if (!response.ok) throw new Error(String(body.error ?? `could not show connection card (HTTP ${response.status})`));- return typeof body.authConfigNote === "string" && body.authConfigNote ? ` ${body.authConfigNote}` : "";+ return [body.authConfigNote, body.connectedNote].map((note) => (typeof note === "string" && note ? ` ${note}` : "")).join("");}/** The harness's answer to a bot's search of the catalog. */@@ -307,11 +307,11 @@ async function handle(received: Json): Promise<void> {return;}if (requests.length) {- const authConfigNote = await showConnectorCards(requests);+ const notes = await showConnectorCards(requests);const labels = requests.map((r) => (r.alias ? `${r.slug} (${r.alias})` : r.slug)).join(", ");send(textResult(id,- `OpenMausBot showed the user a secure connection card for ${labels}.${authConfigNote} End this turn now. The app will continue the task automatically after the connection finishes.`,+ `OpenMausBot showed the user a secure connection card for ${labels}.${notes} End this turn now. The app will continue the task automatically after the connection finishes.`,));return;}diff --git a/server/host/connector-cards.ts b/server/host/connector-cards.tsindex ac50aabc54..cd1eb9c10a 100644--- a/server/host/connector-cards.ts+++ b/server/host/connector-cards.ts@@ -21,7 +21,7 @@ export interface ConnectorCardsDeps {maybeResume(threadId: string, resumeKey: string): void;}-export type ConnectorCardAnswer = { status: 200; body: { messageIds: string[]; authConfigNote?: string } } | { status: 400 | 403 | 409; body: { error: string } };+export type ConnectorCardAnswer = { status: 200; body: { messageIds: string[]; authConfigNote?: string; connectedNote?: string } } | { status: 400 | 403 | 409; body: { error: string } };export function createConnectorCards(deps: ConnectorCardsDeps) {async function request(capability: Capability, input: { botId?: unknown; threadId?: unknown; resumeKey?: unknown; items?: unknown; slugs?: unknown }, requireActive: () => void): Promise<ConnectorCardAnswer> {@@ -49,6 +49,8 @@ export function createConnectorCards(deps: ConnectorCardsDeps) {const connectionState: Record<string, { connected?: boolean }> = await deps.composio.connectionStatus(cfg, slugs).catch(() => ({}));requireActive();const messageIds: string[] = [];+ // A card without an alias for an app that already has an account shows it connected; the bot must ask again with an alias to add another.+ const connectedNotes: string[] = [];for (const item of items) {const existing = deps.store.messagesFor(threadId).find((message) => message.connector?.resumeKey === resumeKey && message.connector.slug === item.slug@@ -62,6 +64,10 @@ export function createConnectorCards(deps: ConnectorCardsDeps) {requireActive();const connected = connectionState[item.slug]?.connected === true;const status = item.alias ? "required" : connected ? "connected" : "required";+ if (status === "connected") {+ connectedNotes.push(`${toolkit.label} already has a connected account, so its card shows it connected and no new account was added. `+ + `To add another ${toolkit.label} account, call COMPOSIO_MANAGE_CONNECTIONS again with toolkits: [{"name": "${item.slug}", "alias": "<a short name for the new account>"}].`);+ }const language = deps.language(threadId);// The app catalog's own words, when it has some, are English; ours are in the person's language.const description = item.alias ? connectorCardDescription(toolkit.label, item.alias, language) : toolkit.blurb || connectorCardDescription(toolkit.label, undefined, language);@@ -75,7 +81,8 @@ export function createConnectorCards(deps: ConnectorCardsDeps) {messageIds.push(message.id);}deps.maybeResume(threadId, resumeKey);- return { status: 200, body: { messageIds, ...(authConfigNote ? { authConfigNote } : {}) } };+ const connectedNote = connectedNotes.join(" ");+ return { status: 200, body: { messageIds, ...(authConfigNote ? { authConfigNote } : {}), ...(connectedNote ? { connectedNote } : {}) } };}return { request };}diff --git a/server/index.test.ts b/server/index.test.tsindex 33b4bb1a91..6dcd9a6736 100644--- a/server/index.test.ts+++ b/server/index.test.ts@@ -12302,6 +12302,41 @@ describe("harness HTTP API", () => {}});+ it("tells the bot an app it asked to connect without an alias already has an account, and how to add another", async () => {+ expect((await api("PUT", "/api/config", { composio: { apiKey: "ak_good" } })).status).toBe(200);+ const bot = (await api("POST", "/api/bots")).body.bot;+ connectorAccounts = [{ id: "ca_personal", alias: "personal", status: "ACTIVE", toolkit: { slug: "gmail" } }];+ try {+ const token = await mintTestCapability(BASE, bot.id, bot.threadId, { kind: "connectors" });+ const request = async (items: unknown[], resumeKey: string) => {+ const response = await fetch(`${BASE}/api/internal/connectors/request`, {+ method: "POST",+ headers: { "content-type": "application/json", authorization: `Bearer ${token}` },+ body: JSON.stringify({ botId: bot.id, threadId: bot.threadId, resumeKey, items }),+ });+ return { status: response.status, body: await response.json() as any };+ };+ const plain = await request([{ slug: "gmail" }, { slug: "slack" }], "connected-note-plain");+ expect(plain.status).toBe(200);+ const stored = (await api("GET", `/api/threads/${bot.threadId}/messages`)).body.messages as any[];+ const gmailCard = stored.find((message) => message.id === plain.body.messageIds[0]);+ expect(gmailCard.connector.status).toBe("connected");+ expect(plain.body.connectedNote).toBe(+ `${gmailCard.connector.label} already has a connected account, so its card shows it connected and no new account was added. `+ + `To add another ${gmailCard.connector.label} account, call COMPOSIO_MANAGE_CONNECTIONS again with toolkits: [{"name": "gmail", "alias": "<a short name for the new account>"}].`,+ );+ const withAlias = await request([{ slug: "gmail", alias: "work" }], "connected-note-alias");+ expect(withAlias.status).toBe(200);+ expect(withAlias.body.connectedNote).toBeUndefined();+ const fresh = await request([{ slug: "notion" }], "connected-note-fresh");+ expect(fresh.status).toBe(200);+ expect(fresh.body.connectedNote).toBeUndefined();+ } finally {+ connectorAccounts = [];+ await api("DELETE", `/api/bots/${bot.id}`);+ }+ });+it("checks a bot's auth_config_id in the person's Composio project before its card shows, and connects with it", async () => {expect((await api("PUT", "/api/config", { composio: { apiKey: "ak_good" } })).status).toBe(200);const bot = (await api("POST", "/api/bots")).body.bot;