diff --git a/AGENTS.md b/AGENTS.md index 69dfa0e6..0a238cbf 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -214,7 +214,7 @@ A user's own running browser, reached over a browser MCP server they run beside ### Connectors (`connector_connections`, `connectors`, `bot_connectors`, `workspace_connectors`, `connector_accounts`, `connector_sessions`, `connector_requests`) -A user's access to an outside app (Gmail, Slack, ...) as themselves, reached through a provider that holds the OAuth app and the connected account (Settings > Connectors). Composio is the first provider: one file under `src/harness/connectors/providers/` and the preset in `src/dict/connector-dict.ts`. **A connection is one provider account, not an app**: `connector_connections` has one row per provider account (Composio Personal, Composio Work, ...), each with its own encrypted `api_key`, added in Settings > Connectors; the form's **paradigm** (`provider`, Composio the first) decides how that connection's apps are reached, and more paradigms can be added; that form names the key a paradigm wants and links where to make it (`key_help`, `key_url`, `key_url_title` in the preset: Composio wants a project API key `ak_...` from its Project Settings > API Keys, not a `ck_...` key made for `connect.composio.dev/mcp`, whose router signs everyone in as the key's owner); `connectorProviderFor` builds the provider from that key, so no install-wide key is read from Environment. `syncConnectorConnection({ connection_id })` reads every app the connection offers into `connectors` (`connectors.connection_id`; `planConnectorSync` derives each slug and names a second connection's app after it, `gmail-work`), so nothing is added or edited app by app; a stored app follows the provider's name, description and logo only, keeping its slug, reach and accounts. A thousand apps cost nothing until one is used: its tools are read when it is first given to a bot or workspace (`syncConnector` from `set-bot-connector`/`set-connector-access` when `tools` is empty) and by the cron for assigned apps alone. **An account is a person's own** (`connector_accounts.user_id`), several per app, and its owner's runs always reach it; its owner or a super admin can also give it out (`connector_accounts.all_bots`, `connector_account_workspaces`, `connector_account_bots`, written by `setConnectorAccountAccess`), so every run in a workspace or on a bot reaches it too, whoever signed in (and giving an account out brings its app along to that bot or workspace, since `botConnectorsSql` counts a connected account given there), and the session is built as the account's owner (`openBotConnectors` passes `account.user_id`, and a shared line names whose account it is). A sign-in the provider no longer lists reads revoked, and its modal offers **Reconnect**, which starts a fresh sign-in for that row (`connector_requests.account_id`), so the finished one replaces it in place and keeps its label and namespace. A reconnect reuses that row, never a second one: a pending account no request here started (an abandoned or replaced sign-in at the provider) never becomes a row, and a reconnect the provider gave no id for lands on the one dead row with that name (`shouldAdoptConnectorAccount`). Its owner or a super admin renames it (`saveConnectorAccount`, which regenerates the slug, so a namespace follows its label); a member can only give an account to places they reach, and only a super admin sets `all_bots`. **A second account is a new sign-in, never the first one reused:** `startConnectorConnection` always makes a link (an account already connected never stands in for the new one), and a request is settled only by the account it made (`connector_requests.provider_account_id`, matched in `settleRequests` and `grabConnectorRequestView`), so a request the user has not finished cannot show the label of an account that was already there. The sign-in itself must never replace the app's earlier account: Composio's plain `connected_accounts/link` does exactly that, so the adapter first opens a multi-account tool-router session and takes its link (`/tool_router/session//link`), which keeps the other sign-ins; tool sessions stay single-account, pinning one in `connected_accounts`, since a multi-account session exposes only the router's meta tools and refuses `preload`. Credentials never reach this app or a model, and a run gets tools from an endpoint the provider builds for one account. **Where a connector reaches:** `all_bots` (every bot, every user) and `workspace_connectors` are the install's and only a super admin sets them; `bot_connectors.user_id` is NOT NULL, so a bot row is always personal to whoever made it and shows only in their runs (`botConnectorsSql`). Runs get deferred tools through `openBotConnectors` (`__`, or `-__` when the user has more than one account) and `ConnectorsNote`, opened beside `openBotExtensions`/`openBotBrowsers` in replies and task runs. Tool names and the action cap (`connectors_actions_per_run`, an `app_settings` row, 50 by default) come from the app. Transport is the MCP lane; when a provider can't pin an account at a session endpoint (`endpoint` throws), `ensure-connector-endpoint` records `session_id = "rest"` and the tools call `provider.execute({tool, args, account})` with the account, so the model's surface never changes. Composio's tool router answers with a URL and no headers and rejects a keyless call (401 "API key is required"), so the adapter sends the connection's project key as `x-api-key` on every session call; a cached session whose stored headers can't be read is rebuilt, never used keyless. **Bots never make or change a connector:** a missing account in an attended reply makes the app create `connector_requests` and show `[connect:ID]` (`ConnectRefCard`, the sign-in opened from there, then read by asking the provider's accounts), and a note line says so; a task, routine, hook call or crew request never gets the card. **The settings page lists connections only** (super admin: add, edit, delete, sync; everyone: their own sign-in); each connection's apps live at `/admin/settings/connectors/`, `ConnectorAppsPageSize` (24) a page, searched on the server over name, app and description by `grabConnectorApps`, so a connection holding 1,842 apps never renders them all; that read puts apps with a connected account the viewer can see first and filters to `all` / `connected` / `unconnected` (`ConnectorAppFilters`), returning each tab's count with the page. A row's one assignment control is who gets the app; its account cards (`ConnectorAccounts`) carry the label, one status, a refresh action (re-check a live account, reconnect a dead one) and disconnect, never where the account reaches (that lives in its modal), "New connection" opens the sign-in modal (the app's logo beside its title, Connect the only primary button), an account chip opens its own modal: the name, `all_bots` and the bots and workspaces it reaches (reach-checked lists), and Disconnect; the row's New connection line leads with how many of the app's accounts are connected (`N accounts`, in the success colour, and nothing while none is). A conversation's composer tools modal ends with a **Connectors** section (`ComposerConnectorsSection`), read by `grabBotConnectors` when the modal opens (never by the page): each app the bot reaches there (its title tagged with the connection's name, and with the account's label when an account given here is what brings it), where it comes from (every bot, this workspace, only you, or an account given here) and the accounts that reach there (this user's own, whatever their status, and connected ones given here, with their owner), or that none is connected yet, with a Manage link to Settings > Connectors, and Add/remove: Add opens a modal that walks down from the connection, to the app (searched on the server through `grabAttachableConnectors` with its `connection_id`, 20 at a time, listing only apps with a connected account of the user's and never one they already attached to this bot), to that app's own accounts (`grabConnectorOwnAccounts`, which leaves out an account already given here) or All accounts for the app alone, and gives the app to this bot for this user (`connectors/set-bot`, so every account they have of it reaches the bot, ones connected later included), plus the picked account to this bot (`connectors/set-account-access`); Remove is the row's X (shown when `entry.removable`) and calls `connectors/detach`, taking away this user's own attachment there and their own account given to that bot alone, while a workspace's, the install's or an account given to every bot shows no X. `sync-connectors` (`*/15`) refreshes every connection's apps, assigned apps' tools and the accounts a sign-in left waiting (pending requests and any account not yet `connected`, so an OAuth callback that lands after the poll is picked up); `prune-connector-requests` takes old requests. A request is only settled as connected once the provider reports an account connected, never on a sync that found none. Deleting a connection removes its apps, sessions, requests, accounts and grants explicitly. Connectors travel in no extension bundle. +A user's access to an outside app (Gmail, Slack, ...) as themselves, reached through a provider that holds the OAuth app and the connected account (Settings > Connectors). Composio is the first provider: one file under `src/harness/connectors/providers/` and the preset in `src/dict/connector-dict.ts`. **A connection is one provider account, not an app**: `connector_connections` has one row per provider account (Composio Personal, Composio Work, ...), each with its own encrypted `api_key`, added in Settings > Connectors; the form's **paradigm** (`provider`, Composio the first) decides how that connection's apps are reached, and more paradigms can be added; that form names the key a paradigm wants and links where to make it (`key_help`, `key_url`, `key_url_title` in the preset: Composio wants a project API key `ak_...` from its Project Settings > API Keys, not a `ck_...` key made for `connect.composio.dev/mcp`, whose router signs everyone in as the key's owner); `connectorProviderFor` builds the provider from that key, so no install-wide key is read from Environment. `syncConnectorConnection({ connection_id })` reads every app the connection offers into `connectors` (`connectors.connection_id`; `planConnectorSync` derives each slug and names a second connection's app after it, `gmail-work`), so nothing is added or edited app by app; a stored app follows the provider's name, description and logo only, keeping its slug, reach and accounts. A thousand apps cost nothing until one is used: its tools are read when it is first given to a bot or workspace (`syncConnector` from `set-bot-connector`/`set-connector-access` when `tools` is empty) and by the cron for assigned apps alone. **An account is a person's own** (`connector_accounts.user_id`), several per app, and its owner's runs always reach it; its owner or a super admin can also give it out (`connector_accounts.all_bots`, `connector_account_workspaces`, `connector_account_bots`, written by `setConnectorAccountAccess`), so every run in a workspace or on a bot reaches it too, whoever signed in (and giving an account out brings its app along to that bot or workspace, since `botConnectorsSql` counts a connected account given there), and the session is built as the account's owner (`openBotConnectors` passes `account.user_id`, and a shared line names whose account it is). A sign-in the provider no longer lists reads revoked, and its modal offers **Reconnect**, which starts a fresh sign-in for that row (`connector_requests.account_id`), so the finished one replaces it in place and keeps its label and namespace. A reconnect reuses that row, never a second one: a pending account no request here started (an abandoned or replaced sign-in at the provider) never becomes a row, and a reconnect the provider gave no id for lands on the one dead row with that name (`shouldAdoptConnectorAccount`). Its owner or a super admin renames it (`saveConnectorAccount`, which regenerates the slug, so a namespace follows its label); a member can only give an account to places they reach, and only a super admin sets `all_bots`. **A second account is a new sign-in, never the first one reused:** `startConnectorConnection` always makes a link (an account already connected never stands in for the new one), and a request is settled only by the account it made (`connector_requests.provider_account_id`, matched in `settleRequests` and `grabConnectorRequestView`), so a request the user has not finished cannot show the label of an account that was already there. The sign-in itself must never replace the app's earlier account: Composio's plain `connected_accounts/link` does exactly that, so the adapter first opens a multi-account tool-router session and takes its link (`/tool_router/session//link`), which keeps the other sign-ins; tool sessions stay single-account, pinning one in `connected_accounts`, since a multi-account session exposes only the router's meta tools and refuses `preload`. Credentials never reach this app or a model, and a run gets tools from an endpoint the provider builds for one account. **Where a connector reaches:** `all_bots` (every bot, every user) and `workspace_connectors` are the install's and only a super admin sets them; `bot_connectors.user_id` is NOT NULL, so a bot row is always personal to whoever made it and shows only in their runs (`botConnectorsSql`). Runs get deferred tools through `openBotConnectors` (`__`, or `-__` when the user has more than one account) and `ConnectorsNote`, opened beside `openBotExtensions`/`openBotBrowsers` in replies and task runs. Tool names and the action cap (`connectors_actions_per_run`, an `app_settings` row, 50 by default) come from the app. Transport is the MCP lane; when a provider can't pin an account at a session endpoint (`endpoint` throws), `ensure-connector-endpoint` records `session_id = "rest"` and the tools call `provider.execute({tool, args, account})` with the account, so the model's surface never changes. Composio's tool router answers with a URL and no headers and rejects a keyless call (401 "API key is required"), so the adapter sends the connection's project key as `x-api-key` on every session call; a cached session whose stored headers can't be read is rebuilt, never used keyless. **Bots never make or change a connector:** a missing account in an attended reply makes the app create `connector_requests` and show `[connect:ID]` (`ConnectRefCard`, the sign-in opened from there, then read by asking the provider's accounts), and a note line says so; a task, routine, hook call or crew request never gets the card. **The settings page lists connections only** (super admin: add, edit, delete, sync; everyone: their own sign-in); each connection's apps live at `/admin/settings/connectors/`, `ConnectorAppsPageSize` (24) a page, searched on the server over name, app and description by `grabConnectorApps`, so a connection holding 1,842 apps never renders them all; that read puts apps with a connected account the viewer can see first and filters to `all` / `connected` / `unconnected` (`ConnectorAppFilters`), returning each tab's count with the page. A row's one assignment control is who gets the app; its account cards (`ConnectorAccounts`) carry the label, one status, a refresh action (re-check a live account, reconnect a dead one) and disconnect, never where the account reaches (that lives in its modal), "New connection" opens the sign-in modal (the app's logo beside its title, Connect the only primary button), an account chip opens its own modal: the name, `all_bots` and the bots and workspaces it reaches (reach-checked lists), and Disconnect; the row's New connection line leads with how many of the app's accounts are connected (`N accounts`, in the success colour, and nothing while none is). A conversation's composer tools modal ends with a **Connectors** section (`ComposerConnectorsSection`), read by `grabBotConnectors` when the modal opens (never by the page): each app the bot reaches there (its title tagged with the connection's name, and with the account's label when an account given here is what brings it), where it comes from (every bot, this workspace, only you, or an account given here) and the accounts that reach there (this user's own, whatever their status, and connected ones given here, with their owner), or that none is connected yet, with a Manage link to Settings > Connectors, and Add/remove: Add opens a modal that walks down from the connection, to the app (searched on the server through `grabAttachableConnectors` with its `connection_id`, 20 at a time, listing only apps with a connected account of the user's and never one they already attached to this bot), to that app's own accounts (`grabConnectorOwnAccounts`, which leaves out an account already given here) or All accounts for the app alone, and gives the app to this bot for this user (`connectors/set-bot`, so every account they have of it reaches the bot, ones connected later included), plus the picked account to this bot (`connectors/set-account-access`); Remove is the row's X (shown when `entry.removable`) and calls `connectors/detach`, taking away this user's own attachment there and their own account given to that bot alone, while a workspace's, the install's or an account given to every bot shows no X. The composer's Tools button draws that bot's connected apps as up to five small circles before the spanner (one per app, `connector_apps` from `grabBotExtensionsOverview`, kept live with the count when the modal reads them), so a conversation shows what it can reach at a glance. `sync-connectors` (`*/15`) refreshes every connection's apps, assigned apps' tools and the accounts a sign-in left waiting (pending requests and any account not yet `connected`, so an OAuth callback that lands after the poll is picked up); `prune-connector-requests` takes old requests. A request is only settled as connected once the provider reports an account connected, never on a sync that found none. Deleting a connection removes its apps, sessions, requests, accounts and grants explicitly. Connectors travel in no extension bundle. ### Knowledgebases diff --git a/package.json b/package.json index 6ecbbe36..9c4f26f5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cobble", - "version": "0.27.1", + "version": "0.27.2", "module": "index.ts", "type": "module", "private": true, diff --git a/src/functions/backend/db/extensions/grab-bot-extensions-overview.ts b/src/functions/backend/db/extensions/grab-bot-extensions-overview.ts index 49595d68..8f62ad66 100644 --- a/src/functions/backend/db/extensions/grab-bot-extensions-overview.ts +++ b/src/functions/backend/db/extensions/grab-bot-extensions-overview.ts @@ -2,6 +2,7 @@ import BunSQLite from "@moduletrace/bun-sqlite"; import type { BotExtensionsPayload } from "@/src/types"; import grabCrewRole from "../access/grab-crew-role"; import countBotConnectors from "../connectors/count-bot-connectors"; +import grabBotConnectors from "../connectors/grab-bot-connectors"; import grabExtensionsOverview from "./grab-extensions-overview"; type Params = { @@ -32,14 +33,27 @@ export default async function grabBotExtensionsOverview({ BunSQLite.sql<{ kind: string }>({ sql: `SELECT kind FROM bots WHERE id = ?`, values: [bot_id] }), ]); - const [overview, connector_count] = await Promise.all([ + const [overview, connector_count, connector_entries] = await Promise.all([ grabExtensionsOverview({ can_manage: role == "super_admin" || (role == "admin" && bot.payload?.[0]?.kind != "coordinator"), bot_id, workspace_id, }), countBotConnectors({ user_id, bot_id, workspace_id }), + grabBotConnectors({ user_id, bot_id, workspace_id }), ]); - return { ...overview, connector_count }; + /** + * One icon per app, for the ones a connected account actually reaches + * here: a pending sign-in has nothing to use yet. + */ + const connector_apps = connector_entries + .filter((entry) => entry.accounts.some((account) => account.status == "connected")) + .map((entry) => ({ + id: Number(entry.connector.id), + name: entry.connector.name, + logo: entry.connector.logo, + })); + + return { ...overview, connector_count, connector_apps }; } diff --git a/src/pages/admin/bots/[bot_id]/(partials)/composer-connectors-section.tsx b/src/pages/admin/bots/[bot_id]/(partials)/composer-connectors-section.tsx index cc8b0ae1..90430e7c 100644 --- a/src/pages/admin/bots/[bot_id]/(partials)/composer-connectors-section.tsx +++ b/src/pages/admin/bots/[bot_id]/(partials)/composer-connectors-section.tsx @@ -7,7 +7,7 @@ import Stack from "@moduletrace/twui/layout/Stack"; import fetchApi from "@moduletrace/twui/utils/fetch/fetchApi"; import { Plus } from "lucide-react"; import type { APIResponseObject } from "@moduletrace/bunext/types"; -import type { BotConnectorEntry } from "@/src/types"; +import type { BotConnectorEntry, ConnectorAppIcon } from "@/src/types"; import postAdminApi from "@/src/layouts/bots/(functions)/post-admin-api"; import ComposerConnectorPicker from "./composer-connector-picker"; import ComposerConnectorRow from "./composer-connector-row"; @@ -25,6 +25,11 @@ type Props = { * count follows an add or a remove without a reload. */ onCount?: (count: number) => void; + /** + * The apps a connected account reaches here, told to the composer for the + * icons on its tools button. + */ + onApps?: (apps: ConnectorAppIcon[]) => void; }; /** @@ -38,6 +43,7 @@ export default function ComposerConnectorsSection({ workspace_id, open, onCount, + onApps, }: Props) { const [items, setItems] = useState(); const [error, setError] = useState(); @@ -93,12 +99,23 @@ export default function ComposerConnectorsSection({ setItems(entries); onCount?.(entries.length); + onApps?.( + entries + .filter((entry) => + entry.accounts.some((account) => account.status == "connected"), + ) + .map((entry) => ({ + id: Number(entry.connector.id), + name: entry.connector.name, + logo: entry.connector.logo, + })), + ); })(); return () => { live = false; }; - }, [open, bot_id, workspace_id, tick, onCount]); + }, [open, bot_id, workspace_id, tick, onCount, onApps]); return ( diff --git a/src/pages/admin/bots/[bot_id]/(partials)/composer-tools-modal.tsx b/src/pages/admin/bots/[bot_id]/(partials)/composer-tools-modal.tsx index 231e88d8..a942ba82 100644 --- a/src/pages/admin/bots/[bot_id]/(partials)/composer-tools-modal.tsx +++ b/src/pages/admin/bots/[bot_id]/(partials)/composer-tools-modal.tsx @@ -2,6 +2,8 @@ import { useState } from "react"; import Modal from "@moduletrace/twui/elements/Modal"; import Button from "@moduletrace/twui/layout/Button"; import H2 from "@moduletrace/twui/layout/H2"; +import Img from "@moduletrace/twui/layout/Img"; +import Row from "@moduletrace/twui/layout/Row"; import Span from "@moduletrace/twui/layout/Span"; import Stack from "@moduletrace/twui/layout/Stack"; import { CircleAlert, type LucideIcon } from "lucide-react"; @@ -10,6 +12,7 @@ import type { BotExtension, BotExtensionKind, BotExtensionsPayload, + ConnectorAppIcon, } from "@/src/types"; import ComposerConnectorsSection from "./composer-connectors-section"; import ComposerToolRow from "./composer-tool-row"; @@ -74,6 +77,13 @@ type Props = { * number follows an add or a remove without a reload. */ onConnectorCount?: (count: number) => void; + /** + * The apps a connector account reaches here, drawn as small circles + * before the spanner (5 at most). Read with the count, so adding or + * removing one shows without a reload. + */ + connector_apps?: ConnectorAppIcon[]; + onConnectorApps?: (apps: ConnectorAppIcon[]) => void; }; /** @@ -94,6 +104,8 @@ export default function ComposerToolsModal({ connectors, connector_count = 0, onConnectorCount, + connector_apps = [], + onConnectorApps, }: Props) { const [open, setOpen] = useState(false); const count = attached.length; @@ -102,6 +114,7 @@ export default function ComposerToolsModal({ (item) => !item.enabled || item.state == "error", ); const TriggerIcon = has_problem ? CircleAlert : copy.Icon; + const app_icons = connector_apps.filter((app) => app.logo).slice(0, 5); const label = total ? `${total} ${total == 1 ? copy.one : copy.many}` : copy.empty_label; @@ -115,7 +128,22 @@ export default function ComposerToolsModal({ variant="ghost" color="gray" size="small" - beforeIcon={} + beforeIcon={ + + {app_icons.map((app) => ( + {app.name} + ))} + + + } className="shrink-0 gap-1! px-2! py-0.5! text-[12px] leading-4 text-ink-secondary" > {label} @@ -181,6 +209,7 @@ export default function ComposerToolsModal({ workspace_id={connectors.workspace_id} open={open} onCount={onConnectorCount} + onApps={onConnectorApps} /> ) : null} diff --git a/src/pages/admin/bots/[bot_id]/(partials)/composer-tools.tsx b/src/pages/admin/bots/[bot_id]/(partials)/composer-tools.tsx index 1d6bd4d2..11a99b1d 100644 --- a/src/pages/admin/bots/[bot_id]/(partials)/composer-tools.tsx +++ b/src/pages/admin/bots/[bot_id]/(partials)/composer-tools.tsx @@ -2,7 +2,11 @@ import { useContext, useEffect, useState } from "react"; import Row from "@moduletrace/twui/layout/Row"; import Span from "@moduletrace/twui/layout/Span"; import useExtensions from "@/src/hooks/use-extensions"; -import type { BotExtensionsPayload, BotWithLastMessage } from "@/src/types"; +import type { + BotExtensionsPayload, + BotWithLastMessage, + ConnectorAppIcon, +} from "@/src/types"; import { BotComputersContext } from "../(data)/bot-computers-context"; import { composerKnowledgebasesCopy, composerToolsCopy } from "../(data)/composer-extensions-copy"; import ComposerBrowserButton from "./composer-browser-button"; @@ -66,11 +70,18 @@ export default function ComposerTools({ const [connector_count, set_connector_count] = useState( Number(initial?.connector_count || 0), ); + const [connector_apps, set_connector_apps] = useState( + initial?.connector_apps || [], + ); useEffect(() => { set_connector_count(Number(initial?.connector_count || 0)); }, [initial?.connector_count]); + useEffect(() => { + set_connector_apps(initial?.connector_apps || []); + }, [initial?.connector_apps]); + const has_tools = Boolean( tools.attached.length || connector_count || (extensions.can_manage && tools.addable.length), ); @@ -95,6 +106,8 @@ export default function ComposerTools({ connectors={{ bot_id: bot.id || 0, workspace_id }} connector_count={connector_count} onConnectorCount={set_connector_count} + connector_apps={connector_apps} + onConnectorApps={set_connector_apps} /> ) : null} diff --git a/src/types/index.ts b/src/types/index.ts index e55e0703..6713ec70 100755 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -1756,6 +1756,22 @@ export type BotExtensionsPayload = { * composer's tools count includes them without reading them all. */ connector_count?: number; + /** + * The last few apps a connector account reaches here, for the composer's + * tools button: their logo beside the spanner, so a glance says which + * apps a message can use. Never repeats an app. + */ + connector_apps?: ConnectorAppIcon[]; +}; + +/** + * One app a connector account reaches, as the composer's tools button shows + * it. + */ +export type ConnectorAppIcon = { + id: number; + name: string; + logo: string; }; export type McpServersOverviewPayload = ExtensionTargets & {