@devries-cameron20 / composio Mirror · read-only / commits / 9d2f3fe5a
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, 04:30 UTC

fix(cli): unify toolkits list/search output into a single stable schema

The `toolkits list` command had two separate code paths producing different JSON schemas depending on whether a user_id was resolved (session format vs legacy format). This caused e2e test failures when the test environment had a test_user_id configured, silently switching to the session format which lacked catalog fields like latest_version. Consolidate into a single path: always fetch from the catalog API (which provides tools_count, triggers_count, latest_version), then optionally enrich with session connection data when a user_id is available. The output schema is now stable regardless of context.

jkomyno committed Mar 9, 2026 at 15:34 UTC 9d2f3fe5a203d2099e177144a252feaf686ed717
4 files changed +132 -135
ts/e2e-tests/cli/toolkits/list/e2e.test.ts
+3 -1
@@ -58,10 +58,12 @@ e2e(import.meta.url, {
58 expect(item).toHaveProperty('name');
59 expect(item).toHaveProperty('slug');
60 expect(item).toHaveProperty('description');
61 - // `toolkits list` without user-id uses legacy listing output.
61 expect(item).toHaveProperty('latest_version');
62 expect(item).toHaveProperty('tools_count');
63 expect(item).toHaveProperty('triggers_count');
64 + expect(item).toHaveProperty('is_no_auth');
65 + expect(item).toHaveProperty('enabled');
66 + expect(item).toHaveProperty('connected');
67 });
68 });
69
ts/packages/cli/src/commands/toolkits/commands/toolkits.list.cmd.ts
+48 -55
@@ -8,12 +8,7 @@ import { ProjectContext } from 'src/services/project-context';
8 import { ComposioUserContext } from 'src/services/user-context';
9 import { clampLimit } from 'src/ui/clamp-limit';
10 import { extractMessage } from 'src/utils/api-error-extraction';
11 -import {
12 - formatLegacyToolkitsJson,
13 - formatLegacyToolkitsTable,
14 - formatToolkitsJson,
15 - formatToolkitsTable,
16 -} from '../format';
11 +import { mergeToolkitData, formatToolkitsJson, formatToolkitsTable } from '../format';
12
13 const query = Options.text('query').pipe(
14 Options.withDescription('Text search by name, slug, or description'),
@@ -40,6 +35,10 @@ const userId = Options.text('user-id').pipe(
35 /**
36 * List available toolkits with connection status.
37 *
38 + * Always fetches catalog data (tools_count, triggers_count, latest_version).
39 + * When a user ID is available (explicit --user-id, project, or global config),
40 + * also fetches session data to enrich with connection status.
41 + *
42 * @example
43 * ```bash
44 * composio toolkits list
@@ -80,78 +79,72 @@ export const toolkitsCmd$List = Command.make(
79 yield* ui.log.message('To show status for a specific user, use `--user-id`.');
80 }
81
83 - if (Option.isSome(resolvedUserId)) {
84 - const result = yield* ui.withSpinner(
85 - 'Fetching toolkits...',
86 - Effect.gen(function* () {
87 - const { client, sessionId } = yield* resolveToolRouterSession(resolvedUserId.value);
88 - return yield* Effect.tryPromise(() =>
89 - client.toolRouter.session.toolkits(sessionId, {
90 - search: Option.getOrUndefined(query),
91 - limit: clampedLimit,
92 - is_connected: Option.getOrUndefined(connected),
93 - })
94 - );
95 - })
96 - );
97 -
98 - const { items } = result;
99 - if (items.length === 0) {
100 - yield* ui.log.warn('No toolkits found. Try broadening your search.');
101 - yield* ui.output('[]');
102 - return;
103 - }
104 -
105 - const showing = items.length;
106 - const total = result.total_items;
107 - yield* ui.log.info(
108 - `Listing ${showing} of ${total} toolkits\n\n${formatToolkitsTable(items)}`
109 - );
110 -
111 - const firstSlug = items[0]?.slug;
112 - if (firstSlug) {
113 - yield* ui.log.step(
114 - `To view details of a toolkit:\n> composio toolkits info "${firstSlug}"`
115 - );
116 - }
117 - yield* ui.output(formatToolkitsJson(items));
118 - return;
119 - }
120 -
121 - if (Option.isSome(connected)) {
82 + if (Option.isSome(connected) && Option.isNone(resolvedUserId)) {
83 yield* ui.log.warn(
84 '`--connected` requires a user id. Use `--user-id` or run `composio init`.'
85 );
86 }
87
127 - const result = yield* ui.withSpinner(
88 + // Always fetch catalog data (has tools_count, triggers_count, versions).
89 + const catalogResult = yield* ui.withSpinner(
90 'Fetching toolkits...',
91 repo.searchToolkits({
92 search: Option.getOrUndefined(query),
93 limit: clampedLimit,
94 })
95 );
134 - const items = result.items;
135 - if (items.length === 0) {
96 +
97 + if (catalogResult.items.length === 0) {
98 yield* ui.log.warn('No toolkits found. Try broadening your search.');
99 yield* ui.output('[]');
100 return;
101 }
140 - const showing = items.length;
141 - const total = result.total_items;
102 +
103 + // When a user ID is available, also fetch session data for connection status.
104 + let sessionItems:
105 + | ReadonlyArray<
106 + import('@composio/client/resources/tool-router').SessionToolkitsResponse.Item
107 + >
108 + | undefined;
109 + if (Option.isSome(resolvedUserId)) {
110 + sessionItems = yield* resolveToolRouterSession(resolvedUserId.value).pipe(
111 + Effect.flatMap(({ client, sessionId }) =>
112 + Effect.tryPromise(() =>
113 + client.toolRouter.session.toolkits(sessionId, {
114 + search: Option.getOrUndefined(query),
115 + limit: clampedLimit,
116 + is_connected: Option.getOrUndefined(connected),
117 + })
118 + )
119 + ),
120 + Effect.map(r => r.items),
121 + Effect.catchAll(error =>
122 + Effect.gen(function* () {
123 + yield* Effect.logDebug('Failed to fetch session data for connection status:', error);
124 + return [] as ReadonlyArray<
125 + import('@composio/client/resources/tool-router').SessionToolkitsResponse.Item
126 + >;
127 + })
128 + )
129 + );
130 + if (sessionItems.length === 0) sessionItems = undefined;
131 + }
132 +
133 + const unified = mergeToolkitData(catalogResult.items, sessionItems);
134 +
135 + const showing = unified.length;
136 + const total = catalogResult.total_items;
137 yield* ui.log.info(
143 - `Listing ${showing} of ${total} toolkits\n\n${formatLegacyToolkitsTable(items)}`
138 + `Listing ${showing} of ${total} toolkits\n\n${formatToolkitsTable(unified)}`
139 );
140
146 - // Next step hint
147 - const firstSlug = items[0]?.slug;
141 + const firstSlug = unified[0]?.slug;
142 if (firstSlug) {
143 yield* ui.log.step(
144 `To view details of a toolkit:\n> composio toolkits info "${firstSlug}"`
145 );
146 }
153 -
154 - yield* ui.output(formatLegacyToolkitsJson(items));
147 + yield* ui.output(formatToolkitsJson(unified));
148 }).pipe(
149 Effect.catchAll(error =>
150 Effect.gen(function* () {
ts/packages/cli/src/commands/toolkits/commands/toolkits.search.cmd.ts
+6 -6
@@ -5,7 +5,7 @@ import { TerminalUI } from 'src/services/terminal-ui';
5 import { requireAuth } from 'src/effects/require-auth';
6 import { clampLimit } from 'src/ui/clamp-limit';
7 import { extractMessage } from 'src/utils/api-error-extraction';
8 -import { formatLegacyToolkitsTable, formatLegacyToolkitsJson } from '../format';
8 +import { mergeToolkitData, formatToolkitsTable, formatToolkitsJson } from '../format';
9
10 const query = Args.text({ name: 'query' }).pipe(
11 Args.withDescription('Search query (e.g. "send emails")')
@@ -50,17 +50,17 @@ export const toolkitsCmd$Search = Command.make('search', { query, limit }, ({ qu
50 const showing = result.items.length;
51 const total = result.total_items;
52
53 - yield* ui.log.info(
54 - `Found ${showing} of ${total} toolkits\n\n${formatLegacyToolkitsTable(result.items)}`
55 - );
53 + const unified = mergeToolkitData(result.items);
54 +
55 + yield* ui.log.info(`Found ${showing} of ${total} toolkits\n\n${formatToolkitsTable(unified)}`);
56
57 // Next step hint
58 - const firstSlug = result.items[0]?.slug;
58 + const firstSlug = unified[0]?.slug;
59 if (firstSlug) {
60 yield* ui.log.step(`To view details:\n> composio toolkits info "${firstSlug}"`);
61 }
62
63 - yield* ui.output(formatLegacyToolkitsJson(result.items));
63 + yield* ui.output(formatToolkitsJson(unified));
64 }).pipe(
65 Effect.catchAll(error =>
66 Effect.gen(function* () {
ts/packages/cli/src/commands/toolkits/format.ts
+75 -73
@@ -21,65 +21,106 @@ const formatAuthConfigField = (field: {
21 ` description: ${field.description || '-'}`,
22 ].join('\n');
23
24 -// ---------- Tool Router format functions ----------
24 +// ---------- Unified toolkit list format ----------
25
26 /**
27 - * Derive connection status text and color from a session toolkit item.
28 - * Returns plain text + color function so callers can pad before coloring.
27 + * Unified representation of a toolkit for list/search output.
28 + * Catalog data is always present; connection data is optional (requires a user session).
29 */
30 -function connectionStatusParts(item: SessionToolkitItem): {
30 +export interface UnifiedToolkit {
31 + name: string;
32 + slug: string;
33 + description: string;
34 + latest_version: string | null;
35 + tools_count: number;
36 + triggers_count: number;
37 + is_no_auth: boolean;
38 + enabled: boolean | null;
39 + connected: {
40 + status: string;
41 + id: string;
42 + auth_scheme: string | null;
43 + is_composio_managed: boolean | null;
44 + } | null;
45 +}
46 +
47 +/**
48 + * Build unified toolkit items from catalog data, optionally enriched with
49 + * session connection data (keyed by slug).
50 + */
51 +export function mergeToolkitData(
52 + catalogItems: ReadonlyArray<Toolkit>,
53 + sessionItems?: ReadonlyArray<SessionToolkitItem>
54 +): UnifiedToolkit[] {
55 + const sessionBySlug = new Map<string, SessionToolkitItem>();
56 + if (sessionItems) {
57 + for (const s of sessionItems) {
58 + sessionBySlug.set(s.slug, s);
59 + }
60 + }
61 +
62 + return catalogItems.map(t => {
63 + const session = sessionBySlug.get(t.slug);
64 + return {
65 + name: t.name,
66 + slug: t.slug,
67 + description: t.meta.description,
68 + latest_version: t.meta.available_versions.at(-1) ?? null,
69 + tools_count: t.meta.tools_count,
70 + triggers_count: t.meta.triggers_count,
71 + is_no_auth: t.no_auth,
72 + enabled: session?.enabled ?? null,
73 + connected: session?.connected_account
74 + ? {
75 + status: session.connected_account.status,
76 + id: session.connected_account.id,
77 + auth_scheme: session.connected_account.auth_config?.auth_scheme ?? null,
78 + is_composio_managed: session.connected_account.auth_config?.is_composio_managed ?? null,
79 + }
80 + : null,
81 + };
82 + });
83 +}
84 +
85 +/**
86 + * Derive connection status text and color from a unified toolkit.
87 + */
88 +function connectionStatusParts(item: UnifiedToolkit): {
89 text: string;
90 color: (s: string) => string;
91 } {
92 if (item.is_no_auth) return { text: 'no auth', color: dim };
35 - if (item.connected_account?.status === 'ACTIVE') return { text: 'active', color: green };
93 + if (item.connected?.status === 'ACTIVE') return { text: 'active', color: green };
94 + if (item.connected === null && item.enabled === null) return { text: '-', color: dim };
95 return { text: 'not connected', color: dim };
96 }
97
98 /**
40 - * Format a list of session toolkits as a human-readable table.
99 + * Format a list of unified toolkits as a human-readable table.
100 */
42 -export function formatToolkitsTable(toolkits: ReadonlyArray<SessionToolkitItem>): string {
43 - const header = `${bold('Name'.padEnd(20))} ${bold('Slug'.padEnd(20))} ${bold('Connected'.padEnd(16))} ${bold('Auth Scheme'.padEnd(14))} ${bold('Description')}`;
101 +export function formatToolkitsTable(toolkits: ReadonlyArray<UnifiedToolkit>): string {
102 + const header = `${bold('Name'.padEnd(20))} ${bold('Slug'.padEnd(20))} ${bold('Version'.padEnd(12))} ${bold('Tools'.padEnd(7))} ${bold('Triggers'.padEnd(10))} ${bold('Connected'.padEnd(16))} ${bold('Description')}`;
103
104 const rows = toolkits.map(t => {
105 const name = t.name.padEnd(20);
106 const slug = t.slug.padEnd(20);
48 - // Pad plain text first, then apply color — ANSI escapes break padEnd.
107 + const version = (t.latest_version ?? '-').padEnd(12);
108 + const tools = String(t.tools_count).padEnd(7);
109 + const triggers = String(t.triggers_count).padEnd(10);
110 const { text: statusText, color: statusColor } = connectionStatusParts(t);
111 const status = statusColor(statusText.padEnd(16));
51 - const authScheme = (t.connected_account?.auth_config?.auth_scheme ?? '-').padEnd(14);
52 - const desc = gray(truncate(t.meta.description, 50));
53 - return `${name} ${slug} ${status} ${authScheme} ${desc}`;
112 + const desc = gray(truncate(t.description, 50));
113 + return `${name} ${slug} ${version} ${tools} ${triggers} ${status} ${desc}`;
114 });
115
116 return [header, ...rows].join('\n');
117 }
118
119 /**
60 - * Format session toolkits as JSON for piped output.
120 + * Format unified toolkits as JSON for piped output.
121 */
62 -export function formatToolkitsJson(toolkits: ReadonlyArray<SessionToolkitItem>): string {
63 - return JSON.stringify(
64 - toolkits.map(t => ({
65 - name: t.name,
66 - slug: t.slug,
67 - description: t.meta.description,
68 - is_no_auth: t.is_no_auth,
69 - enabled: t.enabled,
70 - connected: t.connected_account
71 - ? {
72 - status: t.connected_account.status,
73 - id: t.connected_account.id,
74 - auth_scheme: t.connected_account.auth_config?.auth_scheme ?? null,
75 - is_composio_managed: t.connected_account.auth_config?.is_composio_managed ?? null,
76 - }
77 - : null,
78 - composio_managed_auth_schemes: t.composio_managed_auth_schemes,
79 - })),
80 - null,
81 - 2
82 - );
122 +export function formatToolkitsJson(toolkits: ReadonlyArray<UnifiedToolkit>): string {
123 + return JSON.stringify(toolkits, null, 2);
124 }
125
126 /**
@@ -238,42 +279,3 @@ export function formatToolkitInfoJson(
279 2
280 );
281 }
241 -
242 -// ---------- Legacy format functions (used by non-migrated commands) ----------
243 -
244 -/**
245 - * Format a list of toolkits as a human-readable table (legacy format).
246 - */
247 -export function formatLegacyToolkitsTable(toolkits: ReadonlyArray<Toolkit>): string {
248 - const header = `${bold('Name'.padEnd(20))} ${bold('Slug'.padEnd(20))} ${bold('Version'.padEnd(12))} ${bold('Tools'.padEnd(7))} ${bold('Triggers'.padEnd(10))} ${bold('Description')}`;
249 -
250 - const rows = toolkits.map(t => {
251 - const name = t.name.padEnd(20);
252 - const slug = t.slug.padEnd(20);
253 - const version = (t.meta.available_versions.at(-1) ?? '-').padEnd(12);
254 - const tools = String(t.meta.tools_count).padEnd(7);
255 - const triggers = String(t.meta.triggers_count).padEnd(10);
256 - const desc = gray(truncate(t.meta.description, 50));
257 - return `${name} ${slug} ${version} ${tools} ${triggers} ${desc}`;
258 - });
259 -
260 - return [header, ...rows].join('\n');
261 -}
262 -
263 -/**
264 - * Format toolkits as JSON for piped output (legacy format).
265 - */
266 -export function formatLegacyToolkitsJson(toolkits: ReadonlyArray<Toolkit>): string {
267 - return JSON.stringify(
268 - toolkits.map(t => ({
269 - name: t.name,
270 - slug: t.slug,
271 - latest_version: t.meta.available_versions.at(-1) ?? null,
272 - tools_count: t.meta.tools_count,
273 - triggers_count: t.meta.triggers_count,
274 - description: t.meta.description,
275 - })),
276 - null,
277 - 2
278 - );
279 -}