Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(connectors): no 'end this turn' or 'securely connected' update when every requested app was already connected
AdityaUmaledeb5dcda9de7
diff --git a/server/connector-proxy.test.ts b/server/connector-proxy.test.tsindex f2f4ca53ff..5feac57ba6 100644--- a/server/connector-proxy.test.ts+++ b/server/connector-proxy.test.ts@@ -188,20 +188,19 @@ 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. "+ const note = "Gmail is already connected (it has an account, or needs no sign-in), 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 }));+ response.end(JSON.stringify({ messageIds: ["m1"], connectedNote: note, nothingToSignIn: true }));});});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.",+ `OpenMausBot showed the user a card that gmail is already connected; no sign-in started. ${note} Do not end this turn: carry on now.`,);});diff --git a/server/connector-proxy.ts b/server/connector-proxy.tsindex 6fc96eeac4..496d9fe2ed 100644--- a/server/connector-proxy.ts+++ b/server/connector-proxy.ts@@ -205,16 +205,17 @@ function connectorAdds(args: unknown): { requests: ConnectorRequest[]; badAuthCo}/** 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> {+async function showConnectorCards(items: ConnectorRequest[]): Promise<{ notes: string; nothingToSignIn: boolean }> {const response = await fetch(`${HARNESS}/api/internal/connectors/request`, {method: "POST",headers: { "content-type": "application/json", authorization: `Bearer ${TOKEN}` },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; connectedNote?: unknown };+ const body = (await response.json().catch(() => ({}))) as { error?: unknown; authConfigNote?: unknown; connectedNote?: unknown; nothingToSignIn?: unknown };if (!response.ok) throw new Error(String(body.error ?? `could not show connection card (HTTP ${response.status})`));- return [body.authConfigNote, body.connectedNote].map((note) => (typeof note === "string" && note ? ` ${note}` : "")).join("");+ const notes = [body.authConfigNote, body.connectedNote].map((note) => (typeof note === "string" && note ? ` ${note}` : "")).join("");+ return { notes, nothingToSignIn: body.nothingToSignIn === true };}/** The harness's answer to a bot's search of the catalog. */@@ -307,11 +308,13 @@ async function handle(received: Json): Promise<void> {return;}if (requests.length) {- const notes = await showConnectorCards(requests);+ const { notes, nothingToSignIn } = 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}.${notes} End this turn now. The app will continue the task automatically after the connection finishes.`,+ nothingToSignIn+ ? `OpenMausBot showed the user a card that ${labels} is already connected; no sign-in started.${notes} Do not end this turn: carry on now.`+ : `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 cd1eb9c10a..6d718b9866 100644--- a/server/host/connector-cards.ts+++ b/server/host/connector-cards.ts@@ -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[] = [];+ // Every requested app is already connected: no sign-in starts, so nothing waits on these cards and no "connected" update follows.+ const nothingToSignIn = items.every((item) => !item.alias && connectionState[item.slug]?.connected === true);// 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) {@@ -65,7 +67,7 @@ export function createConnectorCards(deps: ConnectorCardsDeps) {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. `+ connectedNotes.push(`${toolkit.label} is already connected (it has an account, or needs no sign-in), 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);@@ -76,13 +78,13 @@ export function createConnectorCards(deps: ConnectorCardsDeps) {kind: "connector",text: connectorCardText(toolkit.label, item.alias, language),...(owner.group ? { from: { botId: owner.bot.id, name: owner.bot.name, color: owner.bot.color } } : {}),- connector: { slug: item.slug, label: toolkit.label, description, status, resumeKey, ...(item.alias ? { alias: item.alias } : {}) },+ connector: { slug: item.slug, label: toolkit.label, description, status, resumeKey, ...(item.alias ? { alias: item.alias } : {}), ...(nothingToSignIn ? { resumed: true } : {}) },});messageIds.push(message.id);}- deps.maybeResume(threadId, resumeKey);+ if (!nothingToSignIn) deps.maybeResume(threadId, resumeKey);const connectedNote = connectedNotes.join(" ");- return { status: 200, body: { messageIds, ...(authConfigNote ? { authConfigNote } : {}), ...(connectedNote ? { connectedNote } : {}) } };+ return { status: 200, body: { messageIds, ...(authConfigNote ? { authConfigNote } : {}), ...(connectedNote ? { connectedNote } : {}), ...(nothingToSignIn ? { nothingToSignIn } : {}) } };}return { request };}diff --git a/server/index.test.ts b/server/index.test.tsindex 6dcd9a6736..5c679862a7 100644--- a/server/index.test.ts+++ b/server/index.test.ts@@ -12322,12 +12322,20 @@ describe("harness HTTP API", () => {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. `+ `${gmailCard.connector.label} is already connected (it has an account, or needs no sign-in), 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>"}].`,);+ expect(plain.body.nothingToSignIn).toBeUndefined();+ expect(gmailCard.connector.resumed).toBeUndefined();+ const only = await request([{ slug: "gmail" }], "connected-note-only");+ expect(only.status).toBe(200);+ expect(only.body.nothingToSignIn).toBe(true);+ const onlyCard = ((await api("GET", `/api/threads/${bot.threadId}/messages`)).body.messages as any[]).find((message) => message.id === only.body.messageIds[0]);+ expect(onlyCard.connector).toMatchObject({ status: "connected", resumed: true });const withAlias = await request([{ slug: "gmail", alias: "work" }], "connected-note-alias");expect(withAlias.status).toBe(200);expect(withAlias.body.connectedNote).toBeUndefined();+ expect(withAlias.body.nothingToSignIn).toBeUndefined();const fresh = await request([{ slug: "notion" }], "connected-note-fresh");expect(fresh.status).toBe(200);expect(fresh.body.connectedNote).toBeUndefined();