@devries-cameron20 / composio Mirror · read-only
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.

Mirrored from https://github.com/Camo67/composio.git

Synced Nov 21, 06:00 UTC

next
ts 65 lines 2.48 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 connectedAccountWhoamiTitle,
16 formatConnectedAccountWhoami,
17 formatConnectedAccountWhoamiJson,
18 inactiveStatusMessage,
19 } from './connected-accounts.whoami.format';
20
21 /** The arguments of `composio dev connected-accounts whoami`. */
22 export type ConnectedAccountsWhoamiParams = {
23 readonly id: Option.Option<string>;
24 };
25
26 const invalidInput = commandInputError('dev connected-accounts whoami');
27
28 const showConnectedAccountProfile = (id: string) =>
29 Effect.gen(function* () {
30 const ui = yield* TerminalUI;
31 const repo = yield* ComposioToolkitsRepository;
32 const project = yield* resolveDeveloperResourceProject;
33
34 const account = yield* ui
35 .withSpinner(fetchingConnectedAccountMessage(id), repo.getConnectedAccount(project, id))
36 .pipe(
37 Effect.catchTag(
38 CLIENT_API_ERROR_TAGS,
39 handleClientApiError(ui, {
40 fallbackMessage: `Failed to fetch connected account "${id}".`,
41 hint: BROWSE_CONNECTED_ACCOUNTS_HINT,
42 })
43 )
44 );
45
46 if (account.status !== 'ACTIVE') {
47 yield* ui.log.warn(inactiveStatusMessage(account.status));
48 }
49 yield* ui.note(formatConnectedAccountWhoami(account), connectedAccountWhoamiTitle(account));
50 yield* ui.output(formatConnectedAccountWhoamiJson(account));
51 });
52
53 /**
54 * Shows who a connected account of the developer project is connected as (toolkit, user,
55 * status), warning when the connection is not ACTIVE. A missing `<id>` fails with a
56 * `CommandInputError` before any request, and a developer project that cannot be found with
57 * `ProjectResolutionError`; an API failure is reported with a hint and exits 1.
58 */
59 export const runConnectedAccountsWhoami = ({ id }: ConnectedAccountsWhoamiParams) =>
60 Effect.gen(function* () {
61 if (Option.isNone(id)) {
62 return yield* invalidInput(`${MISSING_ID_MESSAGE}\n${missingIdHint('whoami')}`, '<id>');
63 }
64 yield* showConnectedAccountProfile(id.value);
65 });