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

next
ts 60 lines 2.22 KB
Raw
1 import { Effect, Option } from 'effect';
2 import { commandInputError } from 'src/commands/errors';
3 import { resolveDeveloperResourceProject } from 'src/commands/surface';
4 import { handleClientApiError } from 'src/effects/handle-http-error';
5 import { ComposioToolkitsRepository } from 'src/services/composio-clients';
6 import { CLIENT_API_ERROR_TAGS } from 'src/services/composio-errors';
7 import { TerminalUI } from 'src/services/terminal-ui';
8 import {
9 BROWSE_CONNECTED_ACCOUNTS_HINT,
10 MISSING_ID_MESSAGE,
11 fetchingConnectedAccountMessage,
12 missingIdHint,
13 } from '../format';
14 import {
15 connectedAccountInfoTitle,
16 formatConnectedAccountInfo,
17 formatConnectedAccountInfoJson,
18 } from './connected-accounts.info.format';
19
20 /** The arguments of `composio dev connected-accounts info`. */
21 export type ConnectedAccountsInfoParams = {
22 readonly id: Option.Option<string>;
23 };
24
25 const invalidInput = commandInputError('dev connected-accounts info');
26
27 const showConnectedAccount = (id: string) =>
28 Effect.gen(function* () {
29 const ui = yield* TerminalUI;
30 const repo = yield* ComposioToolkitsRepository;
31 const project = yield* resolveDeveloperResourceProject;
32
33 const account = yield* ui
34 .withSpinner(fetchingConnectedAccountMessage(id), repo.getConnectedAccount(project, id))
35 .pipe(
36 Effect.catchTag(
37 CLIENT_API_ERROR_TAGS,
38 handleClientApiError(ui, {
39 fallbackMessage: `Failed to fetch connected account "${id}".`,
40 hint: BROWSE_CONNECTED_ACCOUNTS_HINT,
41 })
42 )
43 );
44
45 yield* ui.note(formatConnectedAccountInfo(account), connectedAccountInfoTitle(account));
46 yield* ui.output(formatConnectedAccountInfoJson(account));
47 });
48
49 /**
50 * Shows one connected account of the developer project. A missing `<id>` fails with a
51 * `CommandInputError` before any request, and a developer project that cannot be found with
52 * `ProjectResolutionError`; an API failure is reported with a hint and exits 1.
53 */
54 export const runConnectedAccountsInfo = ({ id }: ConnectedAccountsInfoParams) =>
55 Effect.gen(function* () {
56 if (Option.isNone(id)) {
57 return yield* invalidInput(`${MISSING_ID_MESSAGE}\n${missingIdHint('info')}`, '<id>');
58 }
59 yield* showConnectedAccount(id.value);
60 });