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 81 lines 2.99 KB
Raw
1 import { telemetry, withCommandTelemetry } from 'src/analytics/command-input';
2 import { Argument, Command, Flag } from 'effect/cli';
3 import { withCommandMeta } from 'src/invocation/command-identity';
4 import { runConnectedAccountsLink } from './connected-accounts.link.handler';
5
6 const toolkit = Argument.String('toolkit').pipe(
7 Argument.withDescription('Toolkit slug to link (e.g. "github", "gmail")'),
8 Argument.optional
9 );
10
11 const authConfig = Flag.String('auth-config').pipe(
12 Flag.withDescription('Auth config ID (e.g. "ac_..."). Uses legacy flow (no Tool Router).'),
13 Flag.optional
14 );
15
16 const noWait = Flag.Boolean('no-wait').pipe(
17 Flag.withDefault(false),
18 Flag.withDescription('Do not wait for authorization; only print link info')
19 );
20
21 const noBrowser = Flag.Boolean('no-browser').pipe(
22 Flag.withDefault(false),
23 Flag.withDescription('Do not open the browser automatically; print the URL to open manually')
24 );
25
26 const alias = Flag.String('alias').pipe(
27 Flag.withDescription(
28 'Alias to assign to the connected account. Required when creating an additional account for the same toolkit/auth config.'
29 ),
30 Flag.optional
31 );
32
33 const list = Flag.Boolean('list').pipe(
34 Flag.withDefault(false),
35 Flag.withDescription(
36 'List existing connected accounts for the toolkit instead of creating a new link'
37 )
38 );
39
40 /**
41 * Built from the path the help page shows, because this one definition is registered on both
42 * trees: as `composio link` (the consumer user) and as `composio dev connected-accounts link`
43 * (a developer project's user). A fixed `composio link …` would teach the root command on the
44 * dev page.
45 */
46 const linkExamples = ({ commandPath }: { readonly commandPath: ReadonlyArray<string> }) => {
47 const command = commandPath.join(' ');
48 return [
49 { command: `${command} github` },
50 { command: `${command} gmail --alias work` },
51 { command: `${command} github --list` },
52 ];
53 };
54
55 const connectedAccountsCmd$LinkBase = Command.make(
56 'link',
57 { toolkit, authConfig, noWait, noBrowser, alias, list },
58 runConnectedAccountsLink
59 ).pipe(
60 Command.withDescription(
61 'Connect an external account (GitHub, Gmail, Slack, etc.) for the user this command acts as.\nOpens a browser for OAuth authorization and waits for confirmation.\n`composio link` acts as you; `composio dev connected-accounts link` acts as a user of a developer project, its test user unless another is named.'
62 ),
63 Command.withShortDescription(
64 'Connect an external account (GitHub, Gmail, Slack, etc.) for the user this command acts as.'
65 ),
66 Command.withExamples(linkExamples),
67 withCommandMeta({ requiresLogin: true })
68 );
69
70 export const connectedAccountsCmd$Link = withCommandTelemetry(
71 connectedAccountsCmd$LinkBase,
72 input =>
73 telemetry.fields(
74 {
75 no_browser: telemetry.flag('--no-browser', input.noBrowser),
76 no_wait: telemetry.flag('--no-wait', input.noWait),
77 has_auth_config: telemetry.flag('--auth-config', telemetry.present(input.authConfig)),
78 },
79 telemetry.optional(input.toolkit)
80 )
81 );