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 122 lines 3.99 KB
Raw
1 import { telemetry, withCommandTelemetry } from 'src/analytics/command-input';
2 import { Command, Flag } from 'effect/cli';
3 import { AUTHORIZATION_TIMEOUT_SECONDS } from 'src/effects/authorization-poll';
4 import { runLogin } from './login.handler';
5
6 const noBrowser = Flag.Boolean('no-browser').pipe(
7 Flag.withDefault(false),
8 Flag.withDescription('Login without browser interaction')
9 );
10
11 const pollOpt = Flag.Boolean('poll').pipe(
12 Flag.withDefault(false),
13 Flag.withDescription('Poll the most recent pending browser login and complete it')
14 );
15
16 const timeoutOpt = Flag.String('timeout').pipe(
17 Flag.withDescription(
18 `Bound the --poll wait at N seconds (1-${AUTHORIZATION_TIMEOUT_SECONDS}); default ${AUTHORIZATION_TIMEOUT_SECONDS}`
19 ),
20 Flag.optional
21 );
22
23 const noWait = Flag.Boolean('no-wait').pipe(
24 Flag.withDefault(false),
25 Flag.withDescription(
26 'Print login URL and session info, then exit without opening browser or waiting'
27 )
28 );
29
30 const keyOpt = Flag.String('key').pipe(
31 Flag.withDescription('Poll and complete login using the session key from composio login'),
32 Flag.optional
33 );
34
35 const userApiKeyOpt = Flag.String('user-api-key').pipe(
36 Flag.withDescription('Log in directly with a Composio user API key'),
37 Flag.optional
38 );
39
40 const orgOpt = Flag.String('org').pipe(
41 Flag.withDescription('Current organization ID or name to store for CLI commands'),
42 Flag.optional
43 );
44
45 const yesOpt = Flag.Boolean('yes').pipe(
46 Flag.withAlias('y'),
47 Flag.withDefault(false),
48 Flag.withDescription('Skip org picker; use current org')
49 );
50
51 const noSkillInstall = Flag.Boolean('no-skill-install').pipe(
52 Flag.withDefault(false),
53 Flag.withDescription('Skip installing the composio-cli skill for Claude Code')
54 );
55
56 const agentOpt = Flag.Boolean('agent').pipe(
57 Flag.withDefault(false),
58 Flag.withDescription('Sign up or log in using a Composio agent identity')
59 );
60
61 /**
62 * CLI command to login using Composio's CLI session APIs.
63 *
64 * Browser-based: Opens browser for OAuth flow (default).
65 * Use --no-browser to skip auto-opening the browser and print the URL instead.
66 * Use --no-wait to print login URL and session info (JSON) then exit without opening browser or waiting.
67 * Use --key to complete login with a session key from --no-wait. Without --no-wait, polls until linked;
68 * with --no-wait, checks once and fails if not linked.
69 * Use --timeout with --poll to bound the wait, in seconds; a wait that runs out exits non-zero with
70 * the login URL and says to run --poll again.
71 * Use --user-api-key to log in directly without a browser flow, and --org to override the current org.
72 * Use --agent to sign up or log in using a Composio agent identity.
73 * Use -y to skip org picker and use current org.
74 *
75 * Non-interactive default flow: prints URL + poll instructions, or logs in
76 * unattended when a READY agent identity is already stored.
77 *
78 * @example
79 * ```bash
80 * composio login
81 * composio login --no-browser
82 * composio login --no-wait
83 * composio login --poll --timeout 120
84 * composio login --key <key>
85 * composio login --key <key> --no-wait
86 * composio login --user-api-key <uak>
87 * composio login --user-api-key <uak> --org <org>
88 * composio login --agent
89 * composio login -y
90 * ```
91 */
92 const loginCmdBase = Command.make(
93 'login',
94 {
95 noBrowser,
96 poll: pollOpt,
97 timeout: timeoutOpt,
98 noWait,
99 key: keyOpt,
100 userApiKey: userApiKeyOpt,
101 org: orgOpt,
102 yes: yesOpt,
103 noSkillInstall,
104 agent: agentOpt,
105 },
106 runLogin
107 ).pipe(Command.withDescription('Log in to the Composio SDK.'));
108
109 export const loginCmd = withCommandTelemetry(loginCmdBase, input =>
110 telemetry.fields({
111 no_browser: telemetry.flag('--no-browser', input.noBrowser),
112 no_wait: telemetry.flag('--no-wait', input.noWait),
113 has_key: {
114 value: telemetry.present(input.key) || telemetry.present(input.userApiKey),
115 flags: [
116 ...(telemetry.present(input.key) ? ['--key'] : []),
117 ...(telemetry.present(input.userApiKey) ? ['--user-api-key'] : []),
118 ],
119 },
120 skip_org_picker: telemetry.flag('--yes', input.yes),
121 })
122 );