@devries-cameron20 / composio-1 / commits / 5948e8302
Fork 0

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

refactor(cli): move `connections list` into the directory shape (#5137)

This PR: - builds on top of https://github.com/ComposioHQ/composio/pull/5130 - splits `connections list` out of the legacy `connections/commands/` file into the directory shape; `connections/commands/` no longer exists - pure move: same flag, description, examples, request, output, `ConnectionsListRequestError` tag and message, and the `MissingActingUserError` for an empty consumer user id from #5130 - open PR #4817 edits the old `connections.list.cmd.test.ts` and will need to follow the move | Old | New | | --- | --- | | `src/commands/connections/commands/connections.list.cmd.ts` (flag + `Command.make`) | `src/commands/connections/list/connections.list.cmd.ts` | | same file (handler) | `src/commands/connections/list/connections.list.handler.ts` (`runConnectionsList`, `ConnectionsListParams`) | | same file (`formatConnectionsJson`) | `src/commands/connections/list/connections.list.format.ts` | | same file (`ConnectionsListRequestError`) | `src/commands/connections/list/connections.list.errors.ts` | | `test/src/commands/connections/connections.list.cmd.test.ts` | `test/src/commands/connections/list/connections.list.cmd.test.ts` (unchanged) | ## Context Verified: root `pnpm typecheck`, `pnpm --filter @composio/cli run lint:effect` (0 diagnostics), `pnpm --filter @composio/cli test` (validate:boundaries and validate:command-tests pass; 210 files, 2514 passed, 1 skipped, the same counts as the base branch), oxlint (no findings in touched files). No user-visible change, so no CHANGELOG entry.

Alberto Schiabel committed Oct 28, 2026 at 12:36 UTC 5948e8302f3e626081413fbd09f5d83b7eb6c376
7 files changed +145 -125
ts/packages/cli/src/commands/connections/commands/connections.list.cmd.ts deleted
-124
@@ -1,124 +0,0 @@
1 -import { Effect, Option } from 'effect';
2 -import { Command, Flag } from 'effect/cli';
3 -import {
4 - CONNECTED_ACCOUNTS_SHAPE_MESSAGE,
5 - decodeConnectedAccountList,
6 -} from 'src/effects/decode-connected-account-list';
7 -import { failedWith, requestError } from 'src/effects/request-error';
8 -import type { ConnectedAccountItem } from 'src/models/connected-accounts';
9 -import { ComposioClientSingleton } from 'src/services/composio-clients';
10 -import { actingUser } from 'src/commands/surface';
11 -import { TerminalUI } from 'src/services/terminal-ui';
12 -import {
13 - getConnectedAccountPermissionGroup,
14 - getConsumerPermissionSnapshot,
15 -} from 'src/services/tool-permissions';
16 -import { idempotent } from 'src/services/composio-request';
17 -
18 -class ConnectionsListRequestError extends requestError('commands/ConnectionsListRequestError') {}
19 -
20 -const toolkit = Flag.String('toolkit').pipe(
21 - Flag.withDescription('Filter by toolkit slug (e.g. "gmail")'),
22 - Flag.optional
23 -);
24 -
25 -const formatConnectionsJson = (
26 - items: ReadonlyArray<ConnectedAccountItem>,
27 - permissionGroups: ReadonlyMap<string, string | undefined> = new Map()
28 -): string => {
29 - const toolkitCounts = items.reduce<Map<string, number>>((acc, item) => {
30 - acc.set(item.toolkit.slug, (acc.get(item.toolkit.slug) ?? 0) + 1);
31 - return acc;
32 - }, new Map());
33 -
34 - const grouped = items.reduce<
35 - Record<
36 - string,
37 - Array<{
38 - id: string;
39 - status: string;
40 - alias?: string | null;
41 - word_id?: string | null;
42 - display_name?: string;
43 - permission_group: string | null;
44 - }>
45 - >
46 - >((acc, item) => {
47 - const toolkit = item.toolkit.slug;
48 - // Several accounts for one toolkit keep `alias` on every entry (null when
49 - // unset); a lone account prints it only when it actually has one.
50 - const includeAlias = item.alias != null || (toolkitCounts.get(toolkit) ?? 0) > 1;
51 - const entry = {
52 - id: item.id,
53 - status: item.status,
54 - ...(includeAlias ? { alias: item.alias ?? null } : {}),
55 - ...(item.word_id != null ? { word_id: item.word_id } : {}),
56 - ...(item.display_name !== undefined ? { display_name: item.display_name } : {}),
57 - permission_group: permissionGroups.get(item.id) ?? null,
58 - };
59 -
60 - if (!acc[toolkit]) {
61 - acc[toolkit] = [];
62 - }
63 - acc[toolkit].push(entry);
64 - return acc;
65 - }, {});
66 -
67 - return JSON.stringify(grouped, null, 2);
68 -};
69 -
70 -export const connectionsCmd$List = Command.make('list', { toolkit }, ({ toolkit }) =>
71 - Effect.gen(function* () {
72 - const ui = yield* TerminalUI;
73 - const clientSingleton = yield* ComposioClientSingleton;
74 - const toolkitSlug = Option.getOrUndefined(toolkit);
75 - const { userId: consumerUserId, project: resolvedProject } = yield* actingUser();
76 -
77 - const client = yield* clientSingleton.getFor({
78 - orgId: resolvedProject.orgId,
79 - projectId: resolvedProject.projectId,
80 - });
81 - const rawResult = yield* client.connectedAccounts
82 - .list(
83 - {
84 - toolkit_slugs: toolkitSlug ? [toolkitSlug] : undefined,
85 - user_ids: [consumerUserId],
86 - limit: 1000,
87 - },
88 - idempotent
89 - )
90 - .pipe(failedWith(ConnectionsListRequestError, 'Failed to list connections.'));
91 - const result = yield* decodeConnectedAccountList(rawResult).pipe(
92 - failedWith(ConnectionsListRequestError, CONNECTED_ACCOUNTS_SHAPE_MESSAGE)
93 - );
94 - const permissionSnapshot = yield* getConsumerPermissionSnapshot({
95 - orgId: resolvedProject.orgId,
96 - projectId: resolvedProject.projectId,
97 - consumerUserId,
98 - connectedAccountIds: result.items.map(item => item.id),
99 - });
100 - const permissionGroups = new Map(
101 - result.items.map(item => [
102 - item.id,
103 - getConnectedAccountPermissionGroup({
104 - snapshot: permissionSnapshot,
105 - connectedAccountId: item.id,
106 - }),
107 - ])
108 - );
109 -
110 - yield* ui.output(formatConnectionsJson(result.items, permissionGroups), { force: true });
111 - })
112 -).pipe(
113 - Command.withDescription(
114 - 'List connections as JSON with each account id and status, plus its alias, word_id, and provider display name when available.'
115 - ),
116 - Command.withExamples([
117 - {
118 - command: 'composio connections list',
119 - },
120 - {
121 - command: 'composio connections list --toolkit gmail',
122 - },
123 - ])
124 -);
ts/packages/cli/src/commands/connections/connections.cmd.ts
+1 -1
@@ -1,6 +1,6 @@
1 import { requireLogin } from 'src/effects/require-auth';
2 import { Command } from 'effect/cli';
3 -import { connectionsCmd$List } from './commands/connections.list.cmd';
3 +import { connectionsCmd$List } from './list/connections.list.cmd';
4 import { connectionsCmd$Remove } from './remove/connections.remove.cmd';
5
6 export const rootConnectionsCmd = Command.make('connections').pipe(
ts/packages/cli/src/commands/connections/list/connections.list.cmd.ts new
+21
@@ -0,0 +1,21 @@
1 +import { Command, Flag } from 'effect/cli';
2 +import { runConnectionsList } from './connections.list.handler';
3 +
4 +const toolkit = Flag.String('toolkit').pipe(
5 + Flag.withDescription('Filter by toolkit slug (e.g. "gmail")'),
6 + Flag.optional
7 +);
8 +
9 +export const connectionsCmd$List = Command.make('list', { toolkit }, runConnectionsList).pipe(
10 + Command.withDescription(
11 + 'List connections as JSON with each account id and status, plus its alias, word_id, and provider display name when available.'
12 + ),
13 + Command.withExamples([
14 + {
15 + command: 'composio connections list',
16 + },
17 + {
18 + command: 'composio connections list --toolkit gmail',
19 + },
20 + ])
21 +);
ts/packages/cli/src/commands/connections/list/connections.list.errors.ts new
+5
@@ -0,0 +1,5 @@
1 +import { requestError } from 'src/effects/request-error';
2 +
3 +export class ConnectionsListRequestError extends requestError(
4 + 'commands/ConnectionsListRequestError'
5 +) {}
ts/packages/cli/src/commands/connections/list/connections.list.format.ts new
+50
@@ -0,0 +1,50 @@
1 +import type { ConnectedAccountItem } from 'src/models/connected-accounts';
2 +
3 +/**
4 + * The connections grouped by toolkit slug, as JSON for stdout, each with its permission group
5 + * (null when none).
6 + */
7 +export const formatConnectionsJson = (
8 + items: ReadonlyArray<ConnectedAccountItem>,
9 + permissionGroups: ReadonlyMap<string, string | undefined> = new Map()
10 +): string => {
11 + const toolkitCounts = items.reduce<Map<string, number>>((acc, item) => {
12 + acc.set(item.toolkit.slug, (acc.get(item.toolkit.slug) ?? 0) + 1);
13 + return acc;
14 + }, new Map());
15 +
16 + const grouped = items.reduce<
17 + Record<
18 + string,
19 + Array<{
20 + id: string;
21 + status: string;
22 + alias?: string | null;
23 + word_id?: string | null;
24 + display_name?: string;
25 + permission_group: string | null;
26 + }>
27 + >
28 + >((acc, item) => {
29 + const toolkit = item.toolkit.slug;
30 + // Several accounts for one toolkit keep `alias` on every entry (null when
31 + // unset); a lone account prints it only when it actually has one.
32 + const includeAlias = item.alias != null || (toolkitCounts.get(toolkit) ?? 0) > 1;
33 + const entry = {
34 + id: item.id,
35 + status: item.status,
36 + ...(includeAlias ? { alias: item.alias ?? null } : {}),
37 + ...(item.word_id != null ? { word_id: item.word_id } : {}),
38 + ...(item.display_name !== undefined ? { display_name: item.display_name } : {}),
39 + permission_group: permissionGroups.get(item.id) ?? null,
40 + };
41 +
42 + if (!acc[toolkit]) {
43 + acc[toolkit] = [];
44 + }
45 + acc[toolkit].push(entry);
46 + return acc;
47 + }, {});
48 +
49 + return JSON.stringify(grouped, null, 2);
50 +};
ts/packages/cli/src/commands/connections/list/connections.list.handler.ts new
+68
@@ -0,0 +1,68 @@
1 +import { Effect, Option } from 'effect';
2 +import {
3 + CONNECTED_ACCOUNTS_SHAPE_MESSAGE,
4 + decodeConnectedAccountList,
5 +} from 'src/effects/decode-connected-account-list';
6 +import { failedWith } from 'src/effects/request-error';
7 +import { ComposioClientSingleton } from 'src/services/composio-clients';
8 +import { actingUser } from 'src/commands/surface';
9 +import { TerminalUI } from 'src/services/terminal-ui';
10 +import {
11 + getConnectedAccountPermissionGroup,
12 + getConsumerPermissionSnapshot,
13 +} from 'src/services/tool-permissions';
14 +import { idempotent } from 'src/services/composio-request';
15 +import { ConnectionsListRequestError } from './connections.list.errors';
16 +import { formatConnectionsJson } from './connections.list.format';
17 +
18 +/** The flags of `composio connections list`. */
19 +export type ConnectionsListParams = {
20 + readonly toolkit: Option.Option<string>;
21 +};
22 +
23 +/**
24 + * Prints the acting user's connections, optionally for one toolkit, as JSON grouped by toolkit
25 + * slug with each account's permission group.
26 + */
27 +export const runConnectionsList = ({ toolkit }: ConnectionsListParams) =>
28 + Effect.gen(function* () {
29 + const ui = yield* TerminalUI;
30 + const clientSingleton = yield* ComposioClientSingleton;
31 + const toolkitSlug = Option.getOrUndefined(toolkit);
32 + const { userId: consumerUserId, project: resolvedProject } = yield* actingUser();
33 +
34 + const client = yield* clientSingleton.getFor({
35 + orgId: resolvedProject.orgId,
36 + projectId: resolvedProject.projectId,
37 + });
38 + const rawResult = yield* client.connectedAccounts
39 + .list(
40 + {
41 + toolkit_slugs: toolkitSlug ? [toolkitSlug] : undefined,
42 + user_ids: [consumerUserId],
43 + limit: 1000,
44 + },
45 + idempotent
46 + )
47 + .pipe(failedWith(ConnectionsListRequestError, 'Failed to list connections.'));
48 + const result = yield* decodeConnectedAccountList(rawResult).pipe(
49 + failedWith(ConnectionsListRequestError, CONNECTED_ACCOUNTS_SHAPE_MESSAGE)
50 + );
51 + const permissionSnapshot = yield* getConsumerPermissionSnapshot({
52 + orgId: resolvedProject.orgId,
53 + projectId: resolvedProject.projectId,
54 + consumerUserId,
55 + connectedAccountIds: result.items.map(item => item.id),
56 + });
57 + const permissionGroups = new Map(
58 + result.items.map(item => [
59 + item.id,
60 + getConnectedAccountPermissionGroup({
61 + snapshot: permissionSnapshot,
62 + connectedAccountId: item.id,
63 + }),
64 + ])
65 + );
66 +
67 + yield* ui.output(formatConnectionsJson(result.items, permissionGroups), { force: true });
68 + });
ts/packages/cli/test/src/commands/connections/list/connections.list.cmd.test.ts renamed