Skip to content

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

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

jkomyno78fb8ebadb45
diff --git a/ts/packages/cli/src/commands/connected-accounts/commands/connected-accounts.link.cmd.ts b/ts/packages/cli/src/commands/connected-accounts/commands/connected-accounts.link.cmd.ts
index 73652c9b4..324701d72 100644
--- a/ts/packages/cli/src/commands/connected-accounts/commands/connected-accounts.link.cmd.ts
+++ b/ts/packages/cli/src/commands/connected-accounts/commands/connected-accounts.link.cmd.ts
@@ -205,13 +205,16 @@ export const connectedAccountsCmd$Link = Command.make(
return;
}
- yield* waitForActiveConnection(
- ui,
- repo,
- linkOpt.value.connected_account_id,
- linkOpt.value.redirect_url,
- noBrowser
- );
+ const { connected_account_id: connAccountId, redirect_url: redirectUrl } = linkOpt.value;
+ if (!connAccountId || !redirectUrl) {
+ yield* ui.log.error(
+ 'The API returned an incomplete link response (missing connected_account_id or redirect_url).'
+ );
+ yield* Effect.logDebug('Link response:', linkOpt.value);
+ return;
+ }
+
+ yield* waitForActiveConnection(ui, repo, connAccountId, redirectUrl, noBrowser);
}
})
).pipe(Command.withDescription('Link an external account via OAuth redirect.'));
diff --git a/ts/packages/cli/src/commands/toolkits/commands/toolkits.info.cmd.ts b/ts/packages/cli/src/commands/toolkits/commands/toolkits.info.cmd.ts
index 47476b1a8..1671d50d1 100644
--- a/ts/packages/cli/src/commands/toolkits/commands/toolkits.info.cmd.ts
+++ b/ts/packages/cli/src/commands/toolkits/commands/toolkits.info.cmd.ts
@@ -1,6 +1,6 @@
import { Args, Command, Options } from '@effect/cli';
import { Effect, Option } from 'effect';
-import { ComposioClientSingleton } from 'src/services/composio-clients';
+import { ComposioClientSingleton, ComposioToolkitsRepository } from 'src/services/composio-clients';
import { TerminalUI } from 'src/services/terminal-ui';
import { requireAuth } from 'src/effects/require-auth';
import { createToolRouterSession } from 'src/effects/create-tool-router-session';
@@ -43,22 +43,61 @@ export const toolkitsCmd$Info = Command.make('info', { slug, userId }, ({ slug,
const clientSingleton = yield* ComposioClientSingleton;
const client = yield* clientSingleton.get();
- const result = yield* ui.withSpinner(
- `Fetching toolkit "${slugValue}"...`,
- Effect.gen(function* () {
- const sessionId = yield* createToolRouterSession(client, userId);
- return yield* Effect.tryPromise(() =>
- client.toolRouter.session.toolkits(sessionId, {
- toolkits: [slugValue],
+ const resultOpt = yield* ui
+ .withSpinner(
+ `Fetching toolkit "${slugValue}"...`,
+ Effect.gen(function* () {
+ const sessionId = yield* createToolRouterSession(client, userId);
+ return yield* Effect.tryPromise(() =>
+ client.toolRouter.session.toolkits(sessionId, {
+ toolkits: [slugValue],
+ })
+ );
+ })
+ )
+ .pipe(
+ Effect.asSome,
+ Effect.catchAll(error =>
+ Effect.gen(function* () {
+ const message =
+ error instanceof Error ? error.message : `Failed to fetch toolkit "${slugValue}".`;
+ yield* ui.log.error(message);
+ yield* ui.log.step('Browse available toolkits:\n> composio toolkits list');
+ return Option.none();
})
- );
- })
- );
+ )
+ );
+
+ if (Option.isNone(resultOpt)) {
+ return;
+ }
+
+ const result = resultOpt.value;
+ const items = Array.isArray(result.items) ? result.items : [];
+ const toolkit = items[0];
- const toolkit = result.items[0];
if (!toolkit) {
yield* ui.log.warn(`Toolkit "${slugValue}" not found.`);
- yield* ui.log.step('Browse available toolkits:\n> composio toolkits list');
+
+ // "Did you mean?" suggestions via legacy search
+ const repo = yield* ComposioToolkitsRepository;
+ const suggestions = yield* repo.searchToolkits({ search: slugValue, limit: 3 }).pipe(
+ Effect.map(r =>
+ r.items.map(s => ({
+ label: `${s.slug} — ${s.meta.description}`,
+ command: `> composio toolkits info "${s.slug}"`,
+ }))
+ ),
+ Effect.catchAll(() => Effect.succeed([] as { label: string; command: string }[]))
+ );
+
+ const [first] = suggestions;
+ if (first) {
+ const lines = suggestions.map(s => ` ${s.label}`).join('\n');
+ yield* ui.log.step(`Did you mean?\n${lines}\n\n${first.command}`);
+ } else {
+ yield* ui.log.step('Browse available toolkits:\n> composio toolkits list');
+ }
return;
}
diff --git a/ts/packages/cli/src/commands/toolkits/commands/toolkits.list.cmd.ts b/ts/packages/cli/src/commands/toolkits/commands/toolkits.list.cmd.ts
index a829e6a3e..3faa29145 100644
--- a/ts/packages/cli/src/commands/toolkits/commands/toolkits.list.cmd.ts
+++ b/ts/packages/cli/src/commands/toolkits/commands/toolkits.list.cmd.ts
@@ -65,27 +65,29 @@ export const toolkitsCmd$List = Command.make(
})
);
- if (result.items.length === 0) {
+ const items = Array.isArray(result.items) ? result.items : [];
+
+ if (items.length === 0) {
yield* ui.log.warn('No toolkits found. Try broadening your search.');
yield* ui.output('[]');
return;
}
- const showing = result.items.length;
+ const showing = items.length;
const total = result.total_items;
yield* ui.log.info(
- `Listing ${showing} of ${total} toolkits\n\n${formatToolkitsTable(result.items)}`
+ `Listing ${showing} of ${total} toolkits\n\n${formatToolkitsTable(items)}`
);
// Next step hint
- const firstSlug = result.items[0]?.slug;
+ const firstSlug = items[0]?.slug;
if (firstSlug) {
yield* ui.log.step(
`To view details of a toolkit:\n> composio toolkits info "${firstSlug}"`
);
}
- yield* ui.output(formatToolkitsJson(result.items));
+ yield* ui.output(formatToolkitsJson(items));
})
).pipe(Command.withDescription('List available toolkits with connection status.'));
diff --git a/ts/packages/cli/src/commands/toolkits/format.ts b/ts/packages/cli/src/commands/toolkits/format.ts
index 0325adf8d..af1e6582c 100644
--- a/ts/packages/cli/src/commands/toolkits/format.ts
+++ b/ts/packages/cli/src/commands/toolkits/format.ts
@@ -55,8 +55,8 @@ export function formatToolkitsJson(toolkits: ReadonlyArray<SessionToolkitItem>):
? {
status: t.connected_account.status,
id: t.connected_account.id,
- auth_scheme: t.connected_account.auth_config.auth_scheme,
- is_composio_managed: t.connected_account.auth_config.is_composio_managed,
+ auth_scheme: t.connected_account.auth_config?.auth_scheme ?? null,
+ is_composio_managed: t.connected_account.auth_config?.is_composio_managed ?? null,
}
: null,
composio_managed_auth_schemes: t.composio_managed_auth_schemes,
@@ -91,8 +91,10 @@ export function formatToolkitInfo(toolkit: SessionToolkitItem): string {
const statusDisplay = ca.status === 'ACTIVE' ? green(ca.status) : dim(ca.status);
lines.push(`${bold('Connection Status:')} ${statusDisplay}`);
lines.push(`${bold('Connected Account ID:')} ${ca.id}`);
- lines.push(`${bold('Auth Scheme:')} ${ca.auth_config.auth_scheme}`);
- lines.push(`${bold('Composio Managed:')} ${ca.auth_config.is_composio_managed ? 'Yes' : 'No'}`);
+ lines.push(`${bold('Auth Scheme:')} ${ca.auth_config?.auth_scheme ?? '-'}`);
+ lines.push(
+ `${bold('Composio Managed:')} ${ca.auth_config?.is_composio_managed ? 'Yes' : 'No'}`
+ );
} else if (!toolkit.is_no_auth) {
lines.push(`${bold('Connection Status:')} ${dim('Not connected')}`);
lines.push(