Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
Mirrored from https://github.com/Camo67/composio.git
Synced Nov 21, 04:45 UTC
| 1 | import type { ComposioClientShape, ComposioError } from '@composio/client/effect'; |
| 2 | import type { |
| 3 | ConnectedAccountListParams, |
| 4 | ConnectedAccountListResponse, |
| 5 | } from '@composio/client/resources/connected-accounts'; |
| 6 | import { Effect, Stream } from 'effect'; |
| 7 | import { ConnectedAccountListShapeError } from 'src/effects/decode-connected-account-list'; |
| 8 | import { idempotent } from 'src/services/composio-request'; |
| 9 | |
| 10 | /** |
| 11 | * The largest page `GET /connected_accounts` serves. The server clamps a |
| 12 | * larger `limit` to this without an error, so a single request for more |
| 13 | * returns 50 items and a `next_cursor`. |
| 14 | */ |
| 15 | export const CONNECTED_ACCOUNTS_MAX_PAGE_SIZE = 50; |
| 16 | |
| 17 | /** |
| 18 | * Lists every connected account matching `query`, following `next_cursor` |
| 19 | * page by page until the server reports no next page. A single |
| 20 | * `connectedAccounts.list` call returns at most |
| 21 | * {@link CONNECTED_ACCOUNTS_MAX_PAGE_SIZE} accounts, so a caller that needs |
| 22 | * the whole list (e.g. "is this toolkit connected?") must come through here. |
| 23 | * The client's stream owns cursor traversal and pagination guards. Callers |
| 24 | * decode the collected accounts; pagination failures keep the CLI's redacted |
| 25 | * shape-error contract. |
| 26 | */ |
| 27 | export const listAllConnectedAccounts = ( |
| 28 | client: ComposioClientShape, |
| 29 | query: Omit<ConnectedAccountListParams, 'cursor' | 'limit'> |
| 30 | ): Effect.Effect< |
| 31 | ConnectedAccountListResponse['items'], |
| 32 | ComposioError | ConnectedAccountListShapeError |
| 33 | > => |
| 34 | client.connectedAccounts |
| 35 | .listStream({ ...query, limit: CONNECTED_ACCOUNTS_MAX_PAGE_SIZE }, idempotent) |
| 36 | .pipe( |
| 37 | Stream.runCollect, |
| 38 | Effect.catchTag( |
| 39 | '@composio/client/ConfigurationError', |
| 40 | (error): Effect.Effect<never, ComposioError | ConnectedAccountListShapeError> => |
| 41 | error.message.startsWith('Pagination ') |
| 42 | ? Effect.fail( |
| 43 | new ConnectedAccountListShapeError({ |
| 44 | message: 'Invalid connected-account pagination response.', |
| 45 | }) |
| 46 | ) |
| 47 | : Effect.fail(error) |
| 48 | ) |
| 49 | ); |