Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

Bot access: limit a bot to chosen accounts of a connected app (part 1)

AdityaUmalee09e7a5d9fdc
diff --git a/packages/phone-protocol/src/connector-scopes.ts b/packages/phone-protocol/src/connector-scopes.ts
index e7a64f3f19..3fa0176ed3 100644
--- a/packages/phone-protocol/src/connector-scopes.ts
+++ b/packages/phone-protocol/src/connector-scopes.ts
@@ -8,6 +8,8 @@ const READ_VERBS = new Set(["GET", "LIST", "FETCH", "SEARCH", "READ", "FIND", "R
interface ScopedCall {
slug: string;
+ /** The connected account the call names (its id or alias), when it names one. */
+ account?: string;
}
export type ConnectorScope = "read" | "write";
@@ -15,9 +17,12 @@ export type ConnectorScope = "read" | "write";
export interface ConnectorScopes {
/** toolkit slug (lower case, Composio's) → what this bot may do with it */
apps: Record<string, ConnectorScope>;
+ /** toolkit slug → the connected-account ids this bot may use in that app. An app with no entry: every account. */
+ accounts?: Record<string, string[]>;
}
const TOOLKIT_SLUG = /^[a-z0-9][a-z0-9_-]{0,63}$/;
+const ACCOUNT_ID = /^[A-Za-z0-9][A-Za-z0-9_.:-]{0,127}$/;
/** The toolkit a Composio slug belongs to: the part before the first
* underscore, lower-cased. A workbench API proxy belongs to no app. */
@@ -55,28 +60,61 @@ export function normalizeConnectorScopes(value: unknown): ConnectorScopes | null
if (scope !== "read" && scope !== "write") return null;
apps[slug] = scope;
}
- return { apps };
+ const rawAccounts = (value as { accounts?: unknown }).accounts;
+ if (rawAccounts === undefined) return { apps };
+ if (!rawAccounts || typeof rawAccounts !== "object" || Array.isArray(rawAccounts)) return null;
+ const accounts: Record<string, string[]> = Object.create(null);
+ for (const [key, ids] of Object.entries(rawAccounts as Record<string, unknown>)) {
+ const slug = key.trim().toLowerCase();
+ if (!TOOLKIT_SLUG.test(slug) || !Array.isArray(ids) || !ids.length) return null;
+ if (!ids.every((id): id is string => typeof id === "string" && ACCOUNT_ID.test(id))) return null;
+ // A limit for an app the bot may not use at all says nothing; dropping it keeps it from waking if the app is turned on.
+ if (Object.hasOwn(apps, slug)) accounts[slug] = [...new Set(ids)];
+ }
+ return Object.keys(accounts).length ? { apps, accounts } : { apps };
+}
+
+/** The toolkit a call belongs to: the longest known toolkit its slug starts with, else the part before the first underscore. */
+function toolkitFor(slug: string, toolkits: readonly string[]): string {
+ return toolkits.filter((candidate) => slug.startsWith(candidate.toUpperCase() + "_"))
+ .sort((a, b) => b.length - a.length)[0] ?? toolkitOf(slug);
}
export type ConnectorAccess =
| { ok: true }
- | { ok: false; slug: string; toolkit: string; reason: "app" | "write" };
+ | { ok: false; slug: string; toolkit: string; reason: "app" | "write" | "account"; allowed?: string[] };
/** May this bot run these calls? The first refusal wins, so a batch that
* mixes an allowed read with a forbidden write is refused whole rather
- * than half-run. */
+ * than half-run. In an app with an account limit each call must name an
+ * allowed connected-account id in its account field: a call naming none,
+ * an alias or another account is refused, so the backend never picks. */
export function connectorAccessDecision(scopes: ConnectorScopes | undefined, calls: ScopedCall[], toolkits: readonly string[] = []): ConnectorAccess {
if (!scopes) return { ok: true };
for (const call of calls) {
- const toolkit = toolkits.filter(candidate => call.slug.startsWith(candidate.toUpperCase() + "_"))
- .sort((a, b) => b.length - a.length)[0] ?? toolkitOf(call.slug);
+ const toolkit = toolkitFor(call.slug, toolkits);
const scope = call.slug === "COMPOSIO_PROXY_EXECUTE" || !Object.hasOwn(scopes.apps, toolkit) ? undefined : scopes.apps[toolkit];
if (!scope) return { ok: false, slug: call.slug, toolkit, reason: "app" };
if (scope === "read" && !isReadOnlyAction(call.slug, toolkit)) return { ok: false, slug: call.slug, toolkit, reason: "write" };
+ const allowed = scopes.accounts && Object.hasOwn(scopes.accounts, toolkit) ? scopes.accounts[toolkit] : undefined;
+ if (allowed && (!call.account || !allowed.includes(call.account))) return { ok: false, slug: call.slug, toolkit, reason: "account", allowed };
}
return { ok: true };
}
+/** True when `next` lets the bot do something `previous` did not: limits removed, an app turned on or raised to write, an
+ * app's account limit dropped while the app stays on, or an account added to it. No `previous` already allows everything. */
+export function widensConnectorScopes(previous: ConnectorScopes | undefined, next: ConnectorScopes | undefined): boolean {
+ if (!previous) return false;
+ if (!next) return true;
+ if (Object.entries(next.apps).some(([slug, scope]) =>
+ !Object.hasOwn(previous.apps, slug) || (scope === "write" && previous.apps[slug] === "read"))) return true;
+ return Object.entries(previous.accounts ?? {}).some(([slug, ids]) => {
+ const after = next.accounts && Object.hasOwn(next.accounts, slug) ? next.accounts[slug] : undefined;
+ return after ? after.some((id) => !ids.includes(id)) : Object.hasOwn(next.apps, slug);
+ });
+}
+
/** A bot whose scopes switch an app on gets that app's tools: every one, unless its tool list already names some. A tool
* list that leaves out an app its scopes turn on would give that app no tool on any engine. True when `bot` changed. */
export function grantScopedApps(bot: { connectorScopes?: ConnectorScopes; connectorTools?: Record<string, { tools: "*" | string[] }> }): boolean {
@@ -97,5 +135,8 @@ export function describeConnectorScopes(scopes: ConnectorScopes | undefined): st
const listed = entries
.map(([slug, scope]) => `${slug} (${scope === "read" ? "read only" : "read and write"})`)
.join(", ");
- return ` This bot may use only these connected apps: ${listed}. Do not try others, and do not write to a read-only one.`;
+ const accounts = Object.entries(scopes.accounts ?? {})
+ .map(([slug, ids]) => ` In ${slug}, use only account id ${ids.map((id) => `"${id}"`).join(" or ")}, and name it in each call's account field.`)
+ .join("");
+ return ` This bot may use only these connected apps: ${listed}. Do not try others, and do not write to a read-only one.${accounts}`;
}
diff --git a/packages/phone-protocol/src/outbound.ts b/packages/phone-protocol/src/outbound.ts
index 3aace15a2d..aa6d7b6752 100644
--- a/packages/phone-protocol/src/outbound.ts
+++ b/packages/phone-protocol/src/outbound.ts
@@ -127,6 +127,8 @@ export function trimOutboundPolicy(bot: { outbound?: OutboundPolicy }): boolean
export interface ConnectorCall {
slug: string;
arguments?: unknown;
+ /** The connected account a multi-execute item names (its id or alias). */
+ account?: string;
}
const isRecord = (value: unknown): value is Record<string, unknown> =>
@@ -147,7 +149,11 @@ export function connectorCallsIn(name: string, args: unknown): ConnectorCall[] {
if (!isRecord(item)) return [{ slug: "COMPOSIO_PROXY_EXECUTE", arguments: args }];
const slug = [item.tool_slug, item.slug, item.name, item.tool].find((value) => typeof value === "string" && value);
if (typeof slug !== "string") return [{ slug: "COMPOSIO_PROXY_EXECUTE", arguments: args }];
- calls.push({ slug, ...(item.arguments !== undefined ? { arguments: item.arguments } : {}) });
+ calls.push({
+ slug,
+ ...(item.arguments !== undefined ? { arguments: item.arguments } : {}),
+ ...(typeof item.account === "string" && item.account.trim() ? { account: item.account.trim() } : {}),
+ });
}
return calls;
}
diff --git a/server/connector-verdict.ts b/server/connector-verdict.ts
index 72d8ffeaa8..8cd3348b92 100644
--- a/server/connector-verdict.ts
+++ b/server/connector-verdict.ts
@@ -183,8 +183,12 @@ export function connectorUnrecognizedText(invoked: string, reason: string): stri
].join(" ");
}
-export function connectorScopeRefusalText(call: ConnectorCall, reason: "app" | "write", bot: string, app: string, tool: string): string {
+export function connectorScopeRefusalText(call: ConnectorCall, reason: "app" | "write" | "account", bot: string, app: string, tool: string, allowed: readonly string[] = []): string {
if (call.kind === "unrecognized") return connectorUnrecognizedText(call.invoked, call.reason);
+ if (reason === "account") {
+ return `OpenMausBot did not run this: ${bot} may use only account id ${allowed.map((id) => `"${id}"`).join(" or ")} in ${app}. `
+ + "Name one of those in the call's account field, or ask the user to allow another account under the bot's Access settings.";
+ }
return reason === "app"
? `OpenMausBot did not run this: ${bot} has not been given access to ${app}. Ask the user to allow it under the bot's Access settings, and do not retry.`
: `OpenMausBot did not run this: ${app} is read-only for ${bot}, and ${tool} would write to it. Ask the user before trying again.`;
diff --git a/server/index.ts b/server/index.ts
index 7fdedac0ea..34b57e0d8d 100644
--- a/server/index.ts
+++ b/server/index.ts
@@ -14401,7 +14401,7 @@ const handleRequest = async (req: IncomingMessage, res: ServerResponse) => {
threadId: internalCapability.threadId, botId: currentSender.id, botName: currentSender.name,
tool: access.slug, decision: "auto-denied", source: "connector-scope", rule: `scope:${access.toolkit}:${access.reason}`,
});
- return refuseOutbound(sandbox.direct ? sandbox.refusal : connectorScopeRefusalText(call, access.reason, currentSender.name, appName, described.label));
+ return refuseOutbound(sandbox.direct ? sandbox.refusal : connectorScopeRefusalText(call, access.reason, currentSender.name, appName, described.label, access.allowed));
}
const opaque = connectorCalls.some(call => call.slug === "COMPOSIO_PROXY_EXECUTE");
if (opaque && currentSender.connectorTools !== undefined && !sandbox.open(currentSender)) return refuseOutbound(sandbox.refusal);
diff --git a/server/routes/bot-patch.ts b/server/routes/bot-patch.ts
index e5d64b4511..ff20ba0abc 100644
--- a/server/routes/bot-patch.ts
+++ b/server/routes/bot-patch.ts
@@ -1,7 +1,7 @@
import { z } from "zod";
import { approvalModeFor, isApprovalMode, type ApprovalMode } from "../../shared/approval-mode.ts";
-import { normalizeConnectorScopes } from "../../shared/connector-scopes.ts";
+import { normalizeConnectorScopes, widensConnectorScopes } from "../../shared/connector-scopes.ts";
import { isBotLiveVoice } from "../../shared/live-call.ts";
import { normalizeOutboundPolicy } from "../../shared/outbound.ts";
import { normalizePhoneApps } from "../../shared/phone-apps.ts";
@@ -264,7 +264,7 @@ export function createBotPatchRoutes(deps: BotPatchRouteDeps): RouteHandler {
if (body.connectorScopes === null) patch.connectorScopes = undefined;
else {
const scopes = normalizeConnectorScopes(body.connectorScopes);
- if (!scopes) return json(res, 400, { error: "connectorScopes must be { apps: { <toolkit>: read | write } } or null" });
+ if (!scopes) return json(res, 400, { error: "connectorScopes must be { apps: { <toolkit>: read | write }, accounts?: { <toolkit>: [account ids] } } or null" });
patch.connectorScopes = scopes;
}
}
@@ -589,9 +589,7 @@ export function createBotPatchRoutes(deps: BotPatchRouteDeps): RouteHandler {
const loosened: string[] = [];
const trustPatch = patch as Pick<Partial<BotRecord>, "outbound" | "connectorScopes" | "fallback">;
if (body.outbound !== undefined && trustPatch.outbound?.policy === "allow" && existingBot?.outbound?.policy !== "allow") loosened.push("outbound");
- if (body.connectorScopes !== undefined && existingBot?.connectorScopes &&
- (!trustPatch.connectorScopes || Object.entries(trustPatch.connectorScopes.apps).some(([slug, scope]) =>
- !existingBot.connectorScopes!.apps[slug] || (scope === "write" && existingBot.connectorScopes!.apps[slug] === "read")))) loosened.push("connectorScopes");
+ if (body.connectorScopes !== undefined && widensConnectorScopes(existingBot?.connectorScopes, trustPatch.connectorScopes)) loosened.push("connectorScopes");
if (body.phoneApps !== undefined && existingBot) {
// Compare effective grants: clearing falls back to every app.
const before = phoneAppsFor(existingBot);
diff --git a/server/trust-controls.e2e.test.ts b/server/trust-controls.e2e.test.ts
index b162b98657..a0d6332248 100644
--- a/server/trust-controls.e2e.test.ts
+++ b/server/trust-controls.e2e.test.ts
@@ -401,6 +401,24 @@ it("sends 35 in a day at Full access with no sending rule, with no refusal and n
for (const thread of threads) expect((await cards(thread)).filter((row: any) => row.card?.outboundRequest), "no card waits on anyone").toEqual([]);
}, 90_000);
+it("holds a bot to the connected accounts its scopes name", async () => {
+ const b = await bot("Account limits");
+ const token = await mint(b.id, b.threadId);
+ const before = relayed.length;
+ const fetchAs = (account: string) => relay(token, "COMPOSIO_MULTI_EXECUTE_TOOL", { tools: [{ tool_slug: "GMAIL_FETCH_EMAILS", arguments: {}, account }] });
+ expect((await api("PATCH", `/api/bots/${b.id}`, { connectorScopes: { apps: { gmail: "read" }, accounts: { gmail: ["other-account"] } } })).status).toBe(200);
+ const refused = await fetchAs("fixture-account");
+ expect(refused.body.result.isError).toBe(true);
+ expect(refused.body.result.content[0].text).toContain('may use only account id "other-account" in');
+ expect((await relay(token, "GMAIL_FETCH_EMAILS")).body.result.isError, "no account named").toBe(true);
+ expect(relayed).toHaveLength(before);
+ expect((await api("PATCH", `/api/bots/${b.id}`, { connectorScopes: { apps: { gmail: "read" }, accounts: { gmail: ["fixture-account"] } } })).status).toBe(200);
+ expect((await fetchAs("fixture-account")).body.result.isError).not.toBe(true);
+ expect((await relay(token, "GMAIL_FETCH_EMAILS")).body.result.isError, "a limited app's call must name its account").toBe(true);
+ expect(relayed).toHaveLength(before + 1);
+ expect((await api("PATCH", `/api/bots/${b.id}`, { connectorScopes: { apps: { gmail: "read" }, accounts: { gmail: [] } } })).status).toBe(400);
+});
+
it("shows each outbound batch recipient and amount with explicit preview truncation before consent", async () => {
const b = await bot("Batch consent preview");
const token = await mint(b.id, b.threadId);
diff --git a/shared/connector-scopes.test.ts b/shared/connector-scopes.test.ts
index 02206039ae..b865128a20 100644
--- a/shared/connector-scopes.test.ts
+++ b/shared/connector-scopes.test.ts
@@ -7,6 +7,7 @@ import {
isReadOnlyAction,
normalizeConnectorScopes,
toolkitOf,
+ widensConnectorScopes,
} from "./connector-scopes.ts";
describe("toolkitOf", () => {
@@ -136,3 +137,64 @@ describe("grantScopedApps", () => {
expect(off.connectorTools).toEqual({});
});
});
+
+describe("per-account limits", () => {
+ const scopes = normalizeConnectorScopes({ apps: { gmail: "write", slack: "read" }, accounts: { gmail: ["ca_work"] } })!;
+
+ it("keeps an account list, and refuses an empty or malformed one", () => {
+ expect(scopes.accounts).toEqual({ gmail: ["ca_work"] });
+ expect(normalizeConnectorScopes({ apps: { gmail: "read" }, accounts: { gmail: [] } })).toBeNull();
+ expect(normalizeConnectorScopes({ apps: { gmail: "read" }, accounts: { gmail: ["bad id"] } })).toBeNull();
+ expect(normalizeConnectorScopes({ apps: { gmail: "read" }, accounts: ["ca_work"] })).toBeNull();
+ expect(normalizeConnectorScopes({ apps: { gmail: "read" }, accounts: {} })).toEqual({ apps: { gmail: "read" } });
+ });
+
+ it("drops a limit for an app the bot may not use", () => {
+ expect(normalizeConnectorScopes({ apps: { slack: "read" }, accounts: { gmail: ["ca_work"] } })).toEqual({ apps: { slack: "read" } });
+ });
+
+ it("allows a call naming an allowed account id", () => {
+ expect(connectorAccessDecision(scopes, [{ slug: "GMAIL_SEND_EMAIL", account: "ca_work" }])).toEqual({ ok: true });
+ });
+
+ it("refuses another account, an alias, or none", () => {
+ const refused = { ok: false, slug: "GMAIL_SEND_EMAIL", toolkit: "gmail", reason: "account", allowed: ["ca_work"] };
+ expect(connectorAccessDecision(scopes, [{ slug: "GMAIL_SEND_EMAIL", account: "ca_home" }])).toEqual(refused);
+ expect(connectorAccessDecision(scopes, [{ slug: "GMAIL_SEND_EMAIL", account: "work" }])).toEqual(refused);
+ expect(connectorAccessDecision(scopes, [{ slug: "GMAIL_SEND_EMAIL", account: "CA_WORK" }])).toEqual(refused);
+ expect(connectorAccessDecision(scopes, [{ slug: "GMAIL_SEND_EMAIL" }])).toEqual(refused);
+ });
+
+ it("leaves apps without a limit, and bots without limits, alone", () => {
+ expect(connectorAccessDecision(scopes, [{ slug: "SLACK_LIST_CHANNELS" }])).toEqual({ ok: true });
+ expect(connectorAccessDecision({ apps: { gmail: "write" } }, [{ slug: "GMAIL_SEND_EMAIL", account: "ca_home" }])).toEqual({ ok: true });
+ expect(connectorAccessDecision(undefined, [{ slug: "GMAIL_SEND_EMAIL" }])).toEqual({ ok: true });
+ });
+
+ it("refuses a whole batch when one call uses a forbidden account", () => {
+ const calls = [{ slug: "GMAIL_FETCH_EMAILS", account: "ca_work" }, { slug: "GMAIL_SEND_EMAIL", account: "ca_home" }];
+ expect(connectorAccessDecision(scopes, calls).ok).toBe(false);
+ });
+
+ it("tells the bot which account to name", () => {
+ expect(describeConnectorScopes(scopes)).toContain('In gmail, use only account id "ca_work", and name it in each call\'s account field.');
+ expect(describeConnectorScopes({ apps: { gmail: "read" } })).not.toContain("account");
+ });
+
+ it("counts a dropped limit or an added account as widening", () => {
+ const two = { apps: { gmail: "write" as const, slack: "read" as const }, accounts: { gmail: ["ca_work", "ca_home"] } };
+ expect(widensConnectorScopes(scopes, two)).toBe(true);
+ expect(widensConnectorScopes(scopes, { apps: { gmail: "write", slack: "read" } })).toBe(true);
+ expect(widensConnectorScopes(two, scopes)).toBe(false);
+ expect(widensConnectorScopes(scopes, { apps: { slack: "read" } })).toBe(false);
+ expect(widensConnectorScopes({ apps: { gmail: "write", slack: "read" } }, scopes)).toBe(false);
+ });
+
+ it("counts removed limits, a new app or read raised to write as widening, and nothing for an unscoped bot", () => {
+ expect(widensConnectorScopes(scopes, undefined)).toBe(true);
+ expect(widensConnectorScopes({ apps: { gmail: "read" } }, { apps: { gmail: "read", slack: "read" } })).toBe(true);
+ expect(widensConnectorScopes({ apps: { gmail: "read" } }, { apps: { gmail: "write" } })).toBe(true);
+ expect(widensConnectorScopes({ apps: { gmail: "write" } }, { apps: { gmail: "read" } })).toBe(false);
+ expect(widensConnectorScopes(undefined, scopes)).toBe(false);
+ });
+});
diff --git a/shared/outbound.test.ts b/shared/outbound.test.ts
index 775d212d40..5a17828a40 100644
--- a/shared/outbound.test.ts
+++ b/shared/outbound.test.ts
@@ -142,6 +142,13 @@ describe("trimOutboundPolicy", () => {
});
describe("connectorCallsIn", () => {
+ it("keeps the account a multi-execute item names", () => {
+ const calls = connectorCallsIn("COMPOSIO_MULTI_EXECUTE_TOOL", {
+ tools: [{ tool_slug: "GMAIL_SEND_EMAIL", arguments: {}, account: " work " }, { tool_slug: "GMAIL_FETCH_EMAILS", arguments: {} }],
+ });
+ expect(calls).toEqual([{ slug: "GMAIL_SEND_EMAIL", arguments: {}, account: "work" }, { slug: "GMAIL_FETCH_EMAILS", arguments: {} }]);
+ });
+
// Composio's session exposes a handful of meta tools; the app tools run
// inside them. The gate has to see through the wrapper or it sees nothing.
it("returns a direct app tool as itself", () => {
diff --git a/src/components/bot-settings/AccessSection.tsx b/src/components/bot-settings/AccessSection.tsx
index 242390d277..94b4508a72 100644
--- a/src/components/bot-settings/AccessSection.tsx
+++ b/src/components/bot-settings/AccessSection.tsx
@@ -35,6 +35,7 @@ import { inputCls } from "./field";
import { openKeySettings } from "../keys/key-focus";
import { KeysLink } from "../keys/KeysLink";
import type { ConnectorScope, ConnectorScopes } from "../../../shared/connector-scopes";
+import type { ConnectorAccount } from "@/lib/connector-status";
import type { useBotSettingsDerived } from "./useBotSettingsDerived";
/**
@@ -701,6 +702,7 @@ export function AccessSection({
const inventoryReady = apps.phase === "ready";
const connectedSlugs = apps.connectedSlugs;
const appLabels = Object.fromEntries(apps.apps.map((app) => [app.slug, app.label]));
+ const appAccounts = Object.fromEntries(apps.apps.map((app) => [app.slug, app.accounts ?? []]));
const webhooks = state.webhooks.filter((webhook) => webhook.botId === bot.id);
const alwaysAllow = bot.alwaysAllow ?? [];
@@ -766,7 +768,7 @@ export function AccessSection({
</div>
{connectedAppsEnabled && inventoryReady && (
<>
- {!draft && <ConnectorScopesControl connectedSlugs={connectedSlugs} labels={appLabels} scopes={bot.connectorScopes} onChange={(connectorScopes) => patch({ connectorScopes })} />}
+ {!draft && <ConnectorScopesControl connectedSlugs={connectedSlugs} labels={appLabels} accounts={appAccounts} scopes={bot.connectorScopes} onChange={(connectorScopes) => patch({ connectorScopes })} />}
<ConnectorToolsGrants bot={bot} patch={patch} slugs={connectedSlugs} />
</>
)}
@@ -893,20 +895,38 @@ export function AccessSection({
);
}
-function ConnectorScopesControl({ connectedSlugs, labels = {}, scopes, onChange }: {
+function ConnectorScopesControl({ connectedSlugs, labels = {}, accounts = {}, scopes, onChange }: {
connectedSlugs: string[];
/** display names by slug; a slug without one shows as itself */
labels?: Record<string, string>;
+ /** each app's connected accounts; an app with two or more can be limited to some of them */
+ accounts?: Record<string, ConnectorAccount[]>;
scopes: ConnectorScopes | undefined;
onChange: (scopes: ConnectorScopes | null) => void;
}) {
const limited = scopes !== undefined;
const slugs = [...new Set([...connectedSlugs, ...Object.keys(scopes?.apps ?? {})])].sort();
+ const emit = (apps: ConnectorScopes["apps"], limits: Record<string, string[]>) =>
+ onChange(Object.keys(limits).length ? { apps, accounts: limits } : { apps });
const setScope = (slug: string, scope: ConnectorScope | null) => {
const apps = { ...scopes?.apps };
+ const limits = { ...scopes?.accounts };
if (scope) apps[slug] = scope;
- else delete apps[slug];
- onChange({ apps });
+ else {
+ delete apps[slug];
+ delete limits[slug];
+ }
+ emit(apps, limits);
+ };
+ // No limit means every account; ticking the last one back drops the limit again. Ids no longer connected are dropped.
+ const connectedIds = (slug: string) => (accounts[slug] ?? []).map((account) => account.id);
+ const allowedIds = (slug: string) => scopes?.accounts?.[slug]?.filter((id) => connectedIds(slug).includes(id)) ?? connectedIds(slug);
+ const setAccount = (slug: string, id: string, on: boolean) => {
+ const ids = allowedIds(slug).filter((one) => one !== id).concat(on ? [id] : []);
+ const limits = { ...scopes?.accounts };
+ if (connectedIds(slug).every((one) => ids.includes(one))) delete limits[slug];
+ else limits[slug] = ids;
+ emit({ ...scopes?.apps }, limits);
};
return <div className="mt-3">
<div className="flex items-center justify-between gap-4">
@@ -924,6 +944,18 @@ function ConnectorScopesControl({ connectedSlugs, labels = {}, scopes, onChange
<button key={label} type="button" title={hint} aria-pressed={(scopes?.apps[slug] ?? null) === value} onClick={() => setScope(slug, value)}
className={cn("rounded px-2 py-0.5 text-[12px] font-medium", (scopes?.apps[slug] ?? null) === value ? "bg-raised text-ink" : "text-ink-secondary hover:text-ink")}>{label}</button>)}
</div>
+ {scopes?.apps[slug] && ((accounts[slug]?.length ?? 0) > 1 || scopes.accounts?.[slug]) && <fieldset className="flex w-full flex-wrap items-center gap-x-3 gap-y-1">
+ <legend className="sr-only">{t("botAccess.scopes.accountsLabel")}</legend>
+ <span aria-hidden className="text-[12px] text-ink-secondary">{t("botAccess.scopes.accountsLabel")}</span>
+ {(accounts[slug] ?? []).map((account) => {
+ const allowed = allowedIds(slug);
+ const on = allowed.includes(account.id);
+ return <label key={account.id} className="flex items-center gap-1.5 text-[12px] text-ink">
+ <input type="checkbox" checked={on} disabled={on && allowed.length === 1} onChange={(event) => setAccount(slug, account.id, event.target.checked)} />
+ {account.alias ?? account.id}
+ </label>;
+ })}
+ </fieldset>}
</div>)}
</div>}
</div>;
diff --git a/src/components/bot-settings/useBotApps.ts b/src/components/bot-settings/useBotApps.ts
index 12ac669c54..dc8e2522c6 100644
--- a/src/components/bot-settings/useBotApps.ts
+++ b/src/components/bot-settings/useBotApps.ts
@@ -6,6 +6,7 @@ import { api, type Bot } from "@/state/store";
import type { ConnectorScope } from "../../../shared/connector-scopes";
import { EMAIL_SLUG, type EmailStatus } from "../../../shared/email";
import { preloadConnectedApps, type ConnectorInventory } from "@/lib/connected-apps";
+import type { ConnectorAccount } from "@/lib/connector-status";
import type { ToolkitCard } from "../ServiceIcon";
export interface BotApp {
@@ -14,6 +15,8 @@ export interface BotApp {
blurb: string;
card: Pick<ToolkitCard, "logo" | "domain" | "label">;
scope: ConnectorScope | null;
+ /** the app's connected accounts, when the inventory lists them */
+ accounts?: ConnectorAccount[];
}
export interface BotApps {
@@ -68,6 +71,7 @@ export function botAppsFrom(
blurb: card?.blurb ?? "",
card: { logo: card?.logo ?? null, domain: card?.domain ?? null, label },
scope: botAppScope(bot, slug),
+ accounts: inventory.services[slug]?.accounts ?? [],
};
});
return { phase: "ready", apps, connectedSlugs };
diff --git a/src/locales/en.json b/src/locales/en.json
index 831498a52c..8d039ee9ae 100644
--- a/src/locales/en.json
+++ b/src/locales/en.json
@@ -7221,6 +7221,7 @@
"botAccess.scopes.empty": "No apps connected yet. Connect one, then allow it here.",
"botAccess.scopes.notConnected": "not connected",
"botAccess.scopes.accessLabel": "{app} access",
+ "botAccess.scopes.accountsLabel": "Accounts this bot may use",
"botAccess.phone.title": "Phone apps",
"botAccess.phone.subtitle": "What this bot may do on {phone}",
"botAccess.phone.notOnPhone": "Not allowed on the phone",
diff --git a/src/locales/it.json b/src/locales/it.json
index 6502491440..4f3cdde34a 100644
--- a/src/locales/it.json
+++ b/src/locales/it.json
@@ -5598,6 +5598,7 @@
"botAccess.scopes.empty": "Nessuna app ancora collegata. Collegane una, poi consentila qui.",
"botAccess.scopes.notConnected": "non collegata",
"botAccess.scopes.accessLabel": "Accesso a {app}",
+ "botAccess.scopes.accountsLabel": "Account che questo bot può usare",
"botAccess.phone.title": "App del telefono",
"botAccess.phone.subtitle": "Che cosa può fare questo bot su {phone}",
"botAccess.phone.notOnPhone": "Non consentito sul telefono",
diff --git a/src/locales/ja.json b/src/locales/ja.json
index 4ca8f4bf25..b2c3c0a2bd 100644
--- a/src/locales/ja.json
+++ b/src/locales/ja.json
@@ -6472,6 +6472,7 @@
"botAccess.scopes.empty": "接続されているアプリはまだありません。アプリを接続してから、ここで許可してください。",
"botAccess.scopes.notConnected": "未接続",
"botAccess.scopes.accessLabel": "{app}へのアクセス",
+ "botAccess.scopes.accountsLabel": "このボットが使えるアカウント",
"botAccess.phone.title": "スマートフォンのアプリ",
"botAccess.phone.subtitle": "このボットが {phone} でできること",
"botAccess.phone.notOnPhone": "スマートフォンで許可されていません",
diff --git a/src/locales/ko.json b/src/locales/ko.json
index 9636de44b8..c2275d351d 100644
--- a/src/locales/ko.json
+++ b/src/locales/ko.json
@@ -6226,6 +6226,7 @@
"botAccess.scopes.empty": "아직 연결된 앱이 없어요. 앱을 연결한 뒤 여기서 허용하세요.",
"botAccess.scopes.notConnected": "연결 안 됨",
"botAccess.scopes.accessLabel": "{app} 접근 권한",
+ "botAccess.scopes.accountsLabel": "이 봇이 사용할 수 있는 계정",
"botAccess.phone.title": "휴대폰 앱",
"botAccess.phone.subtitle": "이 봇이 {phone}에서 할 수 있는 일",
"botAccess.phone.notOnPhone": "휴대폰에서 허용 안 됨",
diff --git a/src/locales/pl.json b/src/locales/pl.json
index 3e29ddd54f..b9ab64a8c5 100644
--- a/src/locales/pl.json
+++ b/src/locales/pl.json
@@ -5754,6 +5754,7 @@
"botAccess.scopes.empty": "Brak połączonych aplikacji. Połącz aplikację, a następnie zezwól na nią tutaj.",
"botAccess.scopes.notConnected": "nie połączono",
"botAccess.scopes.accessLabel": "Dostęp: {app}",
+ "botAccess.scopes.accountsLabel": "Konta, których ten bot może używać",
"botAccess.phone.title": "Aplikacje telefonu",
"botAccess.phone.subtitle": "Co ten bot może robić na urządzeniu {phone}",
"botAccess.phone.notOnPhone": "Niedozwolone na telefonie",
diff --git a/src/locales/pt-br.json b/src/locales/pt-br.json
index 6cf7fe3e55..2812402c13 100644
--- a/src/locales/pt-br.json
+++ b/src/locales/pt-br.json
@@ -6880,6 +6880,7 @@
"botAccess.scopes.empty": "Nenhum app conectado ainda. Conecte um e permita o uso dele aqui.",
"botAccess.scopes.notConnected": "não conectado",
"botAccess.scopes.accessLabel": "Acesso a {app}",
+ "botAccess.scopes.accountsLabel": "Contas que este bot pode usar",
"botAccess.phone.title": "Apps do celular",
"botAccess.phone.subtitle": "O que este bot pode fazer em {phone}",
"botAccess.phone.notOnPhone": "Não permitido no celular",
diff --git a/src/locales/ru.json b/src/locales/ru.json
index 6199565a46..0657773c15 100644
--- a/src/locales/ru.json
+++ b/src/locales/ru.json
@@ -5803,6 +5803,7 @@
"botAccess.scopes.empty": "Приложения ещё не подключены. Подключите одно, затем разрешите его здесь.",
"botAccess.scopes.notConnected": "не подключено",
"botAccess.scopes.accessLabel": "Доступ к {app}",
+ "botAccess.scopes.accountsLabel": "Аккаунты, которые может использовать этот бот",
"botAccess.phone.title": "Приложения на телефоне",
"botAccess.phone.subtitle": "Что этому боту разрешено делать на {phone}",
"botAccess.phone.notOnPhone": "На телефоне не разрешено",
diff --git a/src/locales/source-hashes.json b/src/locales/source-hashes.json
index 8733f99277..90bbf4da3a 100644
--- a/src/locales/source-hashes.json
+++ b/src/locales/source-hashes.json
@@ -23167,6 +23167,7 @@
"botAccess.scopes.empty": "2b968e7568d0f4e9f984d3b1615c60748b5d9eddf8fa65af3edbfc36772d602e",
"botAccess.scopes.notConnected": "98b1024757dbd75df32962d5c35f2133bb698b6ebc0d096749f9267dd7b2ec3c",
"botAccess.scopes.accessLabel": "f4d2b0c12986e6d7232751e74c66d183e8027cb92569de656ffab17d1b5a0cdf",
+ "botAccess.scopes.accountsLabel": "aaffc18b6143619bfdd5a3260f20cdd498ae2fab43927441d4af09859abdb7af",
"botAccess.scopes.off": "ca7981b46ecf2c1787b6d76d81d9fd7fa0ca95842e2fcc2a452869891a9334d1",
"botAccess.scopes.offHint": "166eac5c31f802f053d30d89893a6ac442f4f1f3d09f3d07d756e3129d9f1a71",
"botAccess.scopes.read": "9b9a8d05a7ec353bda84f9c1bb3178c299de3001b5e970508ddc889c487f92ca",
@@ -32433,6 +32434,7 @@
"botAccess.scopes.empty": "2b968e7568d0f4e9f984d3b1615c60748b5d9eddf8fa65af3edbfc36772d602e",
"botAccess.scopes.notConnected": "98b1024757dbd75df32962d5c35f2133bb698b6ebc0d096749f9267dd7b2ec3c",
"botAccess.scopes.accessLabel": "f4d2b0c12986e6d7232751e74c66d183e8027cb92569de656ffab17d1b5a0cdf",
+ "botAccess.scopes.accountsLabel": "aaffc18b6143619bfdd5a3260f20cdd498ae2fab43927441d4af09859abdb7af",
"botAccess.phone.title": "8fd25f7fc85830014dbcbba6c99baa53432a2571ffdecf4f31d6b776a0acb19a",
"botAccess.phone.subtitle": "d43c00328511fba5c6ed0f2f7e9a473b0796a939742b98ccd5636960eb48d0d6",
"botAccess.phone.notOnPhone": "0d5aa6d419d0505a4677de19b49c2459e9edbf3ed00b54cbb7f534a1a08d2738",
@@ -43572,6 +43574,7 @@
"botAccess.scopes.empty": "2b968e7568d0f4e9f984d3b1615c60748b5d9eddf8fa65af3edbfc36772d602e",
"botAccess.scopes.notConnected": "98b1024757dbd75df32962d5c35f2133bb698b6ebc0d096749f9267dd7b2ec3c",
"botAccess.scopes.accessLabel": "f4d2b0c12986e6d7232751e74c66d183e8027cb92569de656ffab17d1b5a0cdf",
+ "botAccess.scopes.accountsLabel": "aaffc18b6143619bfdd5a3260f20cdd498ae2fab43927441d4af09859abdb7af",
"botAccess.scopes.off": "ca7981b46ecf2c1787b6d76d81d9fd7fa0ca95842e2fcc2a452869891a9334d1",
"botAccess.scopes.offHint": "166eac5c31f802f053d30d89893a6ac442f4f1f3d09f3d07d756e3129d9f1a71",
"botAccess.scopes.read": "9b9a8d05a7ec353bda84f9c1bb3178c299de3001b5e970508ddc889c487f92ca",
@@ -54407,6 +54410,7 @@
"botAccess.scopes.empty": "2b968e7568d0f4e9f984d3b1615c60748b5d9eddf8fa65af3edbfc36772d602e",
"botAccess.scopes.notConnected": "98b1024757dbd75df32962d5c35f2133bb698b6ebc0d096749f9267dd7b2ec3c",
"botAccess.scopes.accessLabel": "f4d2b0c12986e6d7232751e74c66d183e8027cb92569de656ffab17d1b5a0cdf",
+ "botAccess.scopes.accountsLabel": "aaffc18b6143619bfdd5a3260f20cdd498ae2fab43927441d4af09859abdb7af",
"botAccess.scopes.off": "ca7981b46ecf2c1787b6d76d81d9fd7fa0ca95842e2fcc2a452869891a9334d1",
"botAccess.scopes.offHint": "166eac5c31f802f053d30d89893a6ac442f4f1f3d09f3d07d756e3129d9f1a71",
"botAccess.scopes.read": "9b9a8d05a7ec353bda84f9c1bb3178c299de3001b5e970508ddc889c487f92ca",
@@ -78947,6 +78951,7 @@
"botAccess.scopes.empty": "2b968e7568d0f4e9f984d3b1615c60748b5d9eddf8fa65af3edbfc36772d602e",
"botAccess.scopes.notConnected": "98b1024757dbd75df32962d5c35f2133bb698b6ebc0d096749f9267dd7b2ec3c",
"botAccess.scopes.accessLabel": "f4d2b0c12986e6d7232751e74c66d183e8027cb92569de656ffab17d1b5a0cdf",
+ "botAccess.scopes.accountsLabel": "aaffc18b6143619bfdd5a3260f20cdd498ae2fab43927441d4af09859abdb7af",
"botAccess.scopes.off": "ca7981b46ecf2c1787b6d76d81d9fd7fa0ca95842e2fcc2a452869891a9334d1",
"botAccess.scopes.offHint": "166eac5c31f802f053d30d89893a6ac442f4f1f3d09f3d07d756e3129d9f1a71",
"botAccess.scopes.read": "9b9a8d05a7ec353bda84f9c1bb3178c299de3001b5e970508ddc889c487f92ca",
@@ -86318,6 +86323,7 @@
"botAccess.scopes.empty": "2b968e7568d0f4e9f984d3b1615c60748b5d9eddf8fa65af3edbfc36772d602e",
"botAccess.scopes.notConnected": "98b1024757dbd75df32962d5c35f2133bb698b6ebc0d096749f9267dd7b2ec3c",
"botAccess.scopes.accessLabel": "f4d2b0c12986e6d7232751e74c66d183e8027cb92569de656ffab17d1b5a0cdf",
+ "botAccess.scopes.accountsLabel": "aaffc18b6143619bfdd5a3260f20cdd498ae2fab43927441d4af09859abdb7af",
"botAccess.phone.title": "8fd25f7fc85830014dbcbba6c99baa53432a2571ffdecf4f31d6b776a0acb19a",
"botAccess.phone.subtitle": "d43c00328511fba5c6ed0f2f7e9a473b0796a939742b98ccd5636960eb48d0d6",
"botAccess.phone.notOnPhone": "0d5aa6d419d0505a4677de19b49c2459e9edbf3ed00b54cbb7f534a1a08d2738",
@@ -93483,6 +93489,7 @@
"botAccess.scopes.empty": "2b968e7568d0f4e9f984d3b1615c60748b5d9eddf8fa65af3edbfc36772d602e",
"botAccess.scopes.notConnected": "98b1024757dbd75df32962d5c35f2133bb698b6ebc0d096749f9267dd7b2ec3c",
"botAccess.scopes.accessLabel": "f4d2b0c12986e6d7232751e74c66d183e8027cb92569de656ffab17d1b5a0cdf",
+ "botAccess.scopes.accountsLabel": "aaffc18b6143619bfdd5a3260f20cdd498ae2fab43927441d4af09859abdb7af",
"botAccess.phone.title": "8fd25f7fc85830014dbcbba6c99baa53432a2571ffdecf4f31d6b776a0acb19a",
"botAccess.phone.subtitle": "d43c00328511fba5c6ed0f2f7e9a473b0796a939742b98ccd5636960eb48d0d6",
"botAccess.phone.notOnPhone": "0d5aa6d419d0505a4677de19b49c2459e9edbf3ed00b54cbb7f534a1a08d2738",
@@ -101426,6 +101433,7 @@
"botAccess.scopes.empty": "2b968e7568d0f4e9f984d3b1615c60748b5d9eddf8fa65af3edbfc36772d602e",
"botAccess.scopes.notConnected": "98b1024757dbd75df32962d5c35f2133bb698b6ebc0d096749f9267dd7b2ec3c",
"botAccess.scopes.accessLabel": "f4d2b0c12986e6d7232751e74c66d183e8027cb92569de656ffab17d1b5a0cdf",
+ "botAccess.scopes.accountsLabel": "aaffc18b6143619bfdd5a3260f20cdd498ae2fab43927441d4af09859abdb7af",
"botAccess.phone.title": "8fd25f7fc85830014dbcbba6c99baa53432a2571ffdecf4f31d6b776a0acb19a",
"botAccess.phone.subtitle": "d43c00328511fba5c6ed0f2f7e9a473b0796a939742b98ccd5636960eb48d0d6",
"botAccess.phone.notOnPhone": "0d5aa6d419d0505a4677de19b49c2459e9edbf3ed00b54cbb7f534a1a08d2738",
diff --git a/src/locales/zh-tw.json b/src/locales/zh-tw.json
index a92621cddc..63e26d6095 100644
--- a/src/locales/zh-tw.json
+++ b/src/locales/zh-tw.json
@@ -6689,6 +6689,7 @@
"botAccess.scopes.empty": "尚未連線任何應用程式。先連線一個,再到這裡允許它。",
"botAccess.scopes.notConnected": "未連線",
"botAccess.scopes.accessLabel": "{app} 存取權",
+ "botAccess.scopes.accountsLabel": "這個機器人可使用的帳號",
"botAccess.phone.title": "手機 App",
"botAccess.phone.subtitle": "這個機器人在 {phone} 上可以做的事",
"botAccess.phone.notOnPhone": "手機上未允許",
diff --git a/src/locales/zh.json b/src/locales/zh.json
index 3368556e8b..3bccdcb1da 100644
--- a/src/locales/zh.json
+++ b/src/locales/zh.json
@@ -6659,6 +6659,7 @@
"botAccess.scopes.empty": "还没有连接应用。先连接一个,再在这里允许它。",
"botAccess.scopes.notConnected": "未连接",
"botAccess.scopes.accessLabel": "{app} 访问权限",
+ "botAccess.scopes.accountsLabel": "这个机器人可使用的账号",
"botAccess.phone.title": "手机应用",
"botAccess.phone.subtitle": "这个机器人在 {phone} 上可以做的事",
"botAccess.phone.notOnPhone": "手机上未允许",