@devries-cameron20 / composio Mirror · read-only / commits / 65bb49a67
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 22, 03:15 UTC

feat(cli): add --no-wait flag to composio link command (#2895)

## Summary Adds `--no-wait` flag to `composio link` / `composio connected-accounts link` command. ## Behavior - **Default (no flag)**: Waits until authorization is completed (opens browser, polls until ACTIVE) - **`--no-wait`**: Only prints link info and JSON to stdout (JQ-parseable), no waiting ## Output (JQ-parseable) - **With `--no-wait`**: `status: "pending"`, `connected_account_id`, `redirect_url`, `toolkit` (Tool Router flow) - **Default (wait)**: `status: "success"` when ACTIVE ## Usage ```bash # Default: wait for authorization composio link gmail # Print info only, no waiting composio link gmail --no-wait composio link gmail --no-wait | jq -r '.redirect_url' ``` Made with [Cursor](https://cursor.com)

Musthaq Ahamad committed Mar 13, 2026 at 11:02 UTC 65bb49a677baa6d2ca0deb559c2dc78162529ab0
2 files changed +86 -14
ts/packages/cli/src/commands/connected-accounts/commands/connected-accounts.link.cmd.ts
+44 -10
@@ -30,6 +30,11 @@ const noBrowser = Options.boolean('no-browser').pipe(
30 Options.withDescription('Skip auto-opening the browser')
31 );
32
33 +const noWait = Options.boolean('no-wait').pipe(
34 + Options.withDefault(false),
35 + Options.withDescription('Do not wait for authorization; only print link info')
36 +);
37 +
38 /**
39 * Open the browser and poll until the connected account becomes ACTIVE.
40 * On success, outputs valid JSON to stdout for piping (e.g. to jq).
@@ -132,8 +137,8 @@ const waitForActiveConnection = (
137 */
138 export const connectedAccountsCmd$Link = Command.make(
139 'link',
135 - { toolkit, authConfig, userId, noBrowser },
136 - ({ toolkit, authConfig, userId, noBrowser }) =>
140 + { toolkit, authConfig, userId, noBrowser, noWait },
141 + ({ toolkit, authConfig, userId, noBrowser, noWait }) =>
142 Effect.gen(function* () {
143 if (!(yield* requireAuth)) return;
144
@@ -204,13 +209,25 @@ export const connectedAccountsCmd$Link = Command.make(
209 return;
210 }
211
207 - yield* waitForActiveConnection(
208 - ui,
209 - repo,
210 - linkOpt.value.connected_account_id,
211 - linkOpt.value.redirect_url,
212 - noBrowser
213 - );
212 + const { connected_account_id: connId, redirect_url: redirectUrl } = linkOpt.value;
213 +
214 + if (noWait) {
215 + yield* ui.note(redirectUrl, 'Redirect URL');
216 + yield* ui.output(
217 + JSON.stringify(
218 + {
219 + status: 'pending',
220 + message: 'Complete authorization by opening the URL',
221 + connected_account_id: connId,
222 + redirect_url: redirectUrl,
223 + },
224 + null,
225 + 2
226 + )
227 + );
228 + } else {
229 + yield* waitForActiveConnection(ui, repo, connId, redirectUrl, noBrowser);
230 + }
231 } else {
232 // Path B: Tool Router flow — toolkit is guaranteed Some (validated above)
233 const toolkitSlug = Option.getOrThrow(toolkit);
@@ -254,7 +271,24 @@ export const connectedAccountsCmd$Link = Command.make(
271 return;
272 }
273
257 - yield* waitForActiveConnection(ui, repo, connAccountId, redirectUrl, noBrowser);
274 + if (noWait) {
275 + yield* ui.note(redirectUrl, 'Redirect URL');
276 + yield* ui.output(
277 + JSON.stringify(
278 + {
279 + status: 'pending',
280 + message: 'Complete authorization by opening the URL',
281 + connected_account_id: connAccountId,
282 + redirect_url: redirectUrl,
283 + toolkit: toolkitSlug,
284 + },
285 + null,
286 + 2
287 + )
288 + );
289 + } else {
290 + yield* waitForActiveConnection(ui, repo, connAccountId, redirectUrl, noBrowser);
291 + }
292 }
293 })
294 ).pipe(Command.withDescription('Link an external account via OAuth redirect.'));
ts/packages/cli/test/src/commands/connected-accounts/connected-accounts.link.cmd.test.ts
+42 -4
@@ -35,9 +35,9 @@ const testConfigProvider = ConfigProvider.fromMap(
35
36 describe('CLI: composio connected-accounts link', () => {
37 layer(TestLive({ baseConfigProvider: testConfigProvider, connectedAccountsData }))(
38 - '[Given] valid --auth-config and --user-id [Then] creates link and shows URL',
38 + '[Given] valid --auth-config and --user-id [Then] creates link and waits (default)',
39 it => {
40 - it.scoped('creates link and shows redirect URL', () =>
40 + it.scoped('creates link and waits for ACTIVE', () =>
41 Effect.gen(function* () {
42 yield* cli([
43 'connected-accounts',
@@ -145,10 +145,48 @@ describe('CLI: composio connected-accounts link', () => {
145 );
146
147 layer(TestLive({ baseConfigProvider: testConfigProvider, connectedAccountsData }))(
148 - '[Given] successful link [Then] outputs valid JSON with success message for jq',
148 + '[Given] --no-wait [Then] outputs valid JSON parseable by jq',
149 + it => {
150 + it.scoped('prints JSON with status pending, connected_account_id, redirect_url', () =>
151 + Effect.gen(function* () {
152 + yield* cli([
153 + 'connected-accounts',
154 + 'link',
155 + '--auth-config',
156 + 'ac_gmail_oauth',
157 + '--user-id',
158 + 'default',
159 + '--no-browser',
160 + '--no-wait',
161 + ]);
162 + const lines = yield* MockConsole.getLines({ stripAnsi: true });
163 + const output = lines.join('\n');
164 +
165 + expect(output).toContain('"status"');
166 + expect(output).toContain('"pending"');
167 + expect(output).toContain('"message"');
168 + expect(output).toContain('"connected_account_id"');
169 + expect(output).toContain('con_test_link');
170 + expect(output).toContain('"redirect_url"');
171 + expect(output).toContain('https://app.composio.dev/link');
172 + // JSON is parseable
173 + const jsonMatch = output.match(/\{[\s\S]*"status"[\s\S]*\}/);
174 + expect(jsonMatch).toBeTruthy();
175 + if (jsonMatch) {
176 + const parsed = JSON.parse(jsonMatch[0]);
177 + expect(parsed.status).toBe('pending');
178 + expect(parsed.connected_account_id).toBe('con_test_link');
179 + }
180 + })
181 + );
182 + }
183 + );
184 +
185 + layer(TestLive({ baseConfigProvider: testConfigProvider, connectedAccountsData }))(
186 + '[Given] default (wait) [Then] waits for ACTIVE and outputs success JSON for jq',
187 it => {
188 it.scoped(
151 - 'prints JSON with status, message, connected_account_id, toolkit, redirect_url',
189 + 'prints JSON with status success, message, connected_account_id, toolkit, redirect_url',
190 () =>
191 Effect.gen(function* () {
192 yield* cli([