@devries-cameron20 / composio Mirror · read-only / commits / 78fb8ebad
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, 05:45 UTC

fix(cli): guard null auth_config, validate API responses, add "Did you mean?" suggestions

- Guard `auth_config` with optional chaining in `formatToolkitsJson` and `formatToolkitInfo` to prevent crashes when auth_config is null/undefined - Add error handling around Tool Router API calls in `toolkits info` with user-friendly messages on failure - Restore "Did you mean?" suggestions in `toolkits info` using legacy `searchToolkits` when the requested toolkit is not found - Validate `result.items` is an array in both `toolkits info` and `toolkits list` before accessing it - Validate `connected_account_id` and `redirect_url` in the Tool Router link response before passing them to `waitForActiveConnection`

jkomyno committed Feb 26, 2026 at 01:36 UTC 78fb8ebadb4526ff2eff77c3c0e60aeaeb4136f6
4 files changed +75 -29
ts/packages/cli/src/commands/connected-accounts/commands/connected-accounts.link.cmd.ts
+10 -7
@@ -205,13 +205,16 @@ export const connectedAccountsCmd$Link = Command.make(
205 return;
206 }
207
208 - yield* waitForActiveConnection(
209 - ui,
210 - repo,
211 - linkOpt.value.connected_account_id,
212 - linkOpt.value.redirect_url,
213 - noBrowser
214 - );
208 + const { connected_account_id: connAccountId, redirect_url: redirectUrl } = linkOpt.value;
209 + if (!connAccountId || !redirectUrl) {
210 + yield* ui.log.error(
211 + 'The API returned an incomplete link response (missing connected_account_id or redirect_url).'
212 + );
213 + yield* Effect.logDebug('Link response:', linkOpt.value);
214 + return;
215 + }
216 +
217 + yield* waitForActiveConnection(ui, repo, connAccountId, redirectUrl, noBrowser);
218 }
219 })
220 ).pipe(Command.withDescription('Link an external account via OAuth redirect.'));
ts/packages/cli/src/commands/toolkits/commands/toolkits.info.cmd.ts
+52 -13
@@ -1,6 +1,6 @@
1 import { Args, Command, Options } from '@effect/cli';
2 import { Effect, Option } from 'effect';
3 -import { ComposioClientSingleton } from 'src/services/composio-clients';
3 +import { ComposioClientSingleton, ComposioToolkitsRepository } from 'src/services/composio-clients';
4 import { TerminalUI } from 'src/services/terminal-ui';
5 import { requireAuth } from 'src/effects/require-auth';
6 import { createToolRouterSession } from 'src/effects/create-tool-router-session';
@@ -43,22 +43,61 @@ export const toolkitsCmd$Info = Command.make('info', { slug, userId }, ({ slug,
43 const clientSingleton = yield* ComposioClientSingleton;
44 const client = yield* clientSingleton.get();
45
46 - const result = yield* ui.withSpinner(
47 - `Fetching toolkit "${slugValue}"...`,
48 - Effect.gen(function* () {
49 - const sessionId = yield* createToolRouterSession(client, userId);
50 - return yield* Effect.tryPromise(() =>
51 - client.toolRouter.session.toolkits(sessionId, {
52 - toolkits: [slugValue],
46 + const resultOpt = yield* ui
47 + .withSpinner(
48 + `Fetching toolkit "${slugValue}"...`,
49 + Effect.gen(function* () {
50 + const sessionId = yield* createToolRouterSession(client, userId);
51 + return yield* Effect.tryPromise(() =>
52 + client.toolRouter.session.toolkits(sessionId, {
53 + toolkits: [slugValue],
54 + })
55 + );
56 + })
57 + )
58 + .pipe(
59 + Effect.asSome,
60 + Effect.catchAll(error =>
61 + Effect.gen(function* () {
62 + const message =
63 + error instanceof Error ? error.message : `Failed to fetch toolkit "${slugValue}".`;
64 + yield* ui.log.error(message);
65 + yield* ui.log.step('Browse available toolkits:\n> composio toolkits list');
66 + return Option.none();
67 })
54 - );
55 - })
56 - );
68 + )
69 + );
70 +
71 + if (Option.isNone(resultOpt)) {
72 + return;
73 + }
74 +
75 + const result = resultOpt.value;
76 + const items = Array.isArray(result.items) ? result.items : [];
77 + const toolkit = items[0];
78
58 - const toolkit = result.items[0];
79 if (!toolkit) {
80 yield* ui.log.warn(`Toolkit "${slugValue}" not found.`);
61 - yield* ui.log.step('Browse available toolkits:\n> composio toolkits list');
81 +
82 + // "Did you mean?" suggestions via legacy search
83 + const repo = yield* ComposioToolkitsRepository;
84 + const suggestions = yield* repo.searchToolkits({ search: slugValue, limit: 3 }).pipe(
85 + Effect.map(r =>
86 + r.items.map(s => ({
87 + label: `${s.slug} — ${s.meta.description}`,
88 + command: `> composio toolkits info "${s.slug}"`,
89 + }))
90 + ),
91 + Effect.catchAll(() => Effect.succeed([] as { label: string; command: string }[]))
92 + );
93 +
94 + const [first] = suggestions;
95 + if (first) {
96 + const lines = suggestions.map(s => ` ${s.label}`).join('\n');
97 + yield* ui.log.step(`Did you mean?\n${lines}\n\n${first.command}`);
98 + } else {
99 + yield* ui.log.step('Browse available toolkits:\n> composio toolkits list');
100 + }
101 return;
102 }
103
ts/packages/cli/src/commands/toolkits/commands/toolkits.list.cmd.ts
+7 -5
@@ -65,27 +65,29 @@ export const toolkitsCmd$List = Command.make(
65 })
66 );
67
68 - if (result.items.length === 0) {
68 + const items = Array.isArray(result.items) ? result.items : [];
69 +
70 + if (items.length === 0) {
71 yield* ui.log.warn('No toolkits found. Try broadening your search.');
72 yield* ui.output('[]');
73 return;
74 }
75
74 - const showing = result.items.length;
76 + const showing = items.length;
77 const total = result.total_items;
78
79 yield* ui.log.info(
78 - `Listing ${showing} of ${total} toolkits\n\n${formatToolkitsTable(result.items)}`
80 + `Listing ${showing} of ${total} toolkits\n\n${formatToolkitsTable(items)}`
81 );
82
83 // Next step hint
82 - const firstSlug = result.items[0]?.slug;
84 + const firstSlug = items[0]?.slug;
85 if (firstSlug) {
86 yield* ui.log.step(
87 `To view details of a toolkit:\n> composio toolkits info "${firstSlug}"`
88 );
89 }
90
89 - yield* ui.output(formatToolkitsJson(result.items));
91 + yield* ui.output(formatToolkitsJson(items));
92 })
93 ).pipe(Command.withDescription('List available toolkits with connection status.'));
ts/packages/cli/src/commands/toolkits/format.ts
+6 -4
@@ -55,8 +55,8 @@ export function formatToolkitsJson(toolkits: ReadonlyArray<SessionToolkitItem>):
55 ? {
56 status: t.connected_account.status,
57 id: t.connected_account.id,
58 - auth_scheme: t.connected_account.auth_config.auth_scheme,
59 - is_composio_managed: t.connected_account.auth_config.is_composio_managed,
58 + auth_scheme: t.connected_account.auth_config?.auth_scheme ?? null,
59 + is_composio_managed: t.connected_account.auth_config?.is_composio_managed ?? null,
60 }
61 : null,
62 composio_managed_auth_schemes: t.composio_managed_auth_schemes,
@@ -91,8 +91,10 @@ export function formatToolkitInfo(toolkit: SessionToolkitItem): string {
91 const statusDisplay = ca.status === 'ACTIVE' ? green(ca.status) : dim(ca.status);
92 lines.push(`${bold('Connection Status:')} ${statusDisplay}`);
93 lines.push(`${bold('Connected Account ID:')} ${ca.id}`);
94 - lines.push(`${bold('Auth Scheme:')} ${ca.auth_config.auth_scheme}`);
95 - lines.push(`${bold('Composio Managed:')} ${ca.auth_config.is_composio_managed ? 'Yes' : 'No'}`);
94 + lines.push(`${bold('Auth Scheme:')} ${ca.auth_config?.auth_scheme ?? '-'}`);
95 + lines.push(
96 + `${bold('Composio Managed:')} ${ca.auth_config?.is_composio_managed ? 'Yes' : 'No'}`
97 + );
98 } else if (!toolkit.is_no_auth) {
99 lines.push(`${bold('Connection Status:')} ${dim('Not connected')}`);
100 lines.push(