Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
| 1 | import { Array as Arr, Effect, Option } from 'effect'; |
| 2 | import { CommandSurface, resolveSurfaceProject } from 'src/commands/surface'; |
| 3 | import { |
| 4 | CONNECTED_ACCOUNTS_SHAPE_MESSAGE, |
| 5 | decodeConnectedAccountList, |
| 6 | } from 'src/effects/decode-connected-account-list'; |
| 7 | import { failedWith } from 'src/effects/request-error'; |
| 8 | import type { KnownConnectedAccountStatus } from 'src/models/connected-accounts'; |
| 9 | import { ComposioClientSingleton } from 'src/services/composio-clients'; |
| 10 | import { idempotent } from 'src/services/composio-request'; |
| 11 | import { TerminalUI } from 'src/services/terminal-ui'; |
| 12 | import { clampLimit } from 'src/ui/clamp-limit'; |
| 13 | import { ConnectedAccountsListRequestError } from './connected-accounts.list.errors'; |
| 14 | import { |
| 15 | FETCHING_CONNECTED_ACCOUNTS_MESSAGE, |
| 16 | LIST_CONNECTED_ACCOUNTS_FAILED_MESSAGE, |
| 17 | formatConnectedAccountsJson, |
| 18 | listingMessage, |
| 19 | noConnectedAccountsMessage, |
| 20 | viewDetailsHint, |
| 21 | } from './connected-accounts.list.format'; |
| 22 | |
| 23 | /** |
| 24 | * The flags of `composio dev connected-accounts list`. The `dev` group's `--user-id` and |
| 25 | * `--project-name` come from `CommandSurface`, not from here. |
| 26 | */ |
| 27 | export type ConnectedAccountsListParams = { |
| 28 | readonly toolkits: Option.Option<string>; |
| 29 | readonly status: Option.Option<KnownConnectedAccountStatus>; |
| 30 | readonly limit: number; |
| 31 | }; |
| 32 | |
| 33 | /** Lists one page of connected accounts in the developer project, filtered by the flags. */ |
| 34 | export const runConnectedAccountsList = ({ |
| 35 | toolkits, |
| 36 | status, |
| 37 | limit, |
| 38 | }: ConnectedAccountsListParams) => |
| 39 | Effect.gen(function* () { |
| 40 | const { userId } = yield* CommandSurface; |
| 41 | const ui = yield* TerminalUI; |
| 42 | const clientSingleton = yield* ComposioClientSingleton; |
| 43 | |
| 44 | const resolvedProject = yield* resolveSurfaceProject('developer'); |
| 45 | const client = yield* clientSingleton.getFor({ |
| 46 | orgId: resolvedProject.orgId, |
| 47 | projectId: resolvedProject.projectId, |
| 48 | }); |
| 49 | |
| 50 | const rawResult = yield* ui.withSpinner( |
| 51 | FETCHING_CONNECTED_ACCOUNTS_MESSAGE, |
| 52 | client.connectedAccounts |
| 53 | .list( |
| 54 | { |
| 55 | toolkit_slugs: Option.getOrUndefined( |
| 56 | Option.map(toolkits, csv => csv.split(',').map(slug => slug.trim())) |
| 57 | ), |
| 58 | user_ids: Option.getOrUndefined(Option.map(userId, Arr.of)), |
| 59 | statuses: Option.getOrUndefined(Option.map(status, Arr.of)), |
| 60 | limit: clampLimit(limit), |
| 61 | }, |
| 62 | idempotent |
| 63 | ) |
| 64 | .pipe(failedWith(ConnectedAccountsListRequestError, LIST_CONNECTED_ACCOUNTS_FAILED_MESSAGE)) |
| 65 | ); |
| 66 | const result = yield* decodeConnectedAccountList(rawResult).pipe( |
| 67 | failedWith(ConnectedAccountsListRequestError, CONNECTED_ACCOUNTS_SHAPE_MESSAGE) |
| 68 | ); |
| 69 | |
| 70 | yield* Arr.match(result.items, { |
| 71 | onEmpty: () => ui.log.warn(noConnectedAccountsMessage({ toolkits, userId, status })), |
| 72 | onNonEmpty: nonEmptyItems => |
| 73 | Effect.gen(function* () { |
| 74 | yield* ui.log.info(listingMessage(nonEmptyItems, result.total_items)); |
| 75 | const firstId = Arr.headNonEmpty(nonEmptyItems).id; |
| 76 | if (firstId) { |
| 77 | yield* ui.log.step(viewDetailsHint(firstId)); |
| 78 | } |
| 79 | yield* ui.output(formatConnectedAccountsJson(nonEmptyItems)); |
| 80 | }), |
| 81 | }); |
| 82 | }); |