Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
feat(ts/cli): optimize client requests; bandwidth usage of "composio ts generate--type-tools --toolkits entelligence" went from 112MB to 6.21 KB
jkomyno committed
Jan 14, 2026 at 16:01 UTC
0a56414beb6a984f09c282864a72878bf480aa1e
7 files changed
+438
-121
ts/packages/cli/package.json
+1
@@ -26,6 +26,7 @@
26
"cli": "bun run src/bin.ts",
27
"build:bin": "bun run ./scripts/build-binary.ts",
28
"install:bin": "bun run ./scripts/install-binary.ts ./dist/composio",
29
+ "table:metrics": "bun run ./scripts/optimize-metrics-table.ts",
30
"mock": "bun run ./scripts/copy-mocks-from-cache.ts",
31
"prebuild": "pnpm run typecheck",
32
"build": "tsdown",
ts/packages/cli/scripts/optimize-metrics-table.ts
new
+86
@@ -0,0 +1,86 @@
1
+#!/usr/bin/env bun
2
+
3
+/**
4
+ * Generate a Markdown table comparing API metrics before and after an optimization PR.
5
+ *
6
+ * Usage:
7
+ * pnpm run metrics
8
+ */
9
+
10
+interface Metric {
11
+ requests: number;
12
+ megabytes: number;
13
+}
14
+
15
+interface MetricRow {
16
+ name: string;
17
+ before: Metric;
18
+ after: Metric;
19
+}
20
+
21
+const data: MetricRow[] = [
22
+ {
23
+ name: 'Default',
24
+ before: { requests: 4, megabytes: 1.71 },
25
+ after: { requests: 3, megabytes: 1.7 },
26
+ },
27
+ {
28
+ name: '`--type-tools`',
29
+ before: { requests: 26, megabytes: 111.3 },
30
+ after: { requests: 24, megabytes: 110.62 },
31
+ },
32
+ {
33
+ name: '`--toolkits entelligence`',
34
+ before: { requests: 5, megabytes: 2.35 },
35
+ after: { requests: 3, megabytes: 718.68 / 1024 }, // Convert KB to MB
36
+ },
37
+ {
38
+ name: '`--type-tools` + `--toolkits entelligence`',
39
+ before: { requests: 27, megabytes: 111.94 },
40
+ after: { requests: 3, megabytes: 6.21 / 1024 }, // Convert KB to MB
41
+ },
42
+];
43
+
44
+function percentChange(before: number, after: number): string {
45
+ let change = ((after - before) / before) * 100;
46
+ // Cap at -99.9% unless it's truly 0
47
+ if (after > 0 && change < -99.9) {
48
+ change = -99.9;
49
+ }
50
+ const sign = change > 0 ? '+' : '';
51
+ return `${sign}${change.toFixed(1)}%`;
52
+}
53
+
54
+function formatMB(mb: number): string {
55
+ if (mb < 1) {
56
+ return `${(mb * 1024).toFixed(2)} KB`;
57
+ }
58
+ return `${mb.toFixed(2)} MB`;
59
+}
60
+
61
+function generateMarkdownTable(rows: MetricRow[]): string {
62
+ const lines: string[] = [];
63
+
64
+ lines.push('# Metrics Comparison: Before vs After Optimization');
65
+ lines.push('');
66
+ lines.push(
67
+ '| Case | Requests (Before) | Requests (After) | Requests Δ | Downloaded (Before) | Downloaded (After) | Downloaded Δ |'
68
+ );
69
+ lines.push(
70
+ '|------|-------------------|------------------|------------|---------------------|--------------------|--------------| '
71
+ );
72
+
73
+ for (const row of rows) {
74
+ const reqChange = percentChange(row.before.requests, row.after.requests);
75
+ const mbChange = percentChange(row.before.megabytes, row.after.megabytes);
76
+
77
+ lines.push(
78
+ `| ${row.name} | ${row.before.requests} | ${row.after.requests} | ${reqChange} | ${formatMB(row.before.megabytes)} | ${formatMB(row.after.megabytes)} | ${mbChange} |`
79
+ );
80
+ }
81
+
82
+ return lines.join('\n');
83
+}
84
+
85
+const table = generateMarkdownTable(data);
86
+console.log(table);
ts/packages/cli/src/commands/py/commands/py.generate.cmd.ts
+2
-6
@@ -78,16 +78,12 @@ export function generatePythonTypeStubs({
78
)
79
: [];
80
81
- const triggerTypesAsEnums = yield* Effect.logDebug('Fetching trigger types...').pipe(
82
- Effect.flatMap(() => client.getTriggerTypesAsEnums())
83
- );
84
-
81
const [allToolkits, tools, triggerTypes] = yield* Effect.all(
82
[
83
Effect.logDebug('Fetching toolkits...').pipe(Effect.flatMap(() => client.getToolkits())),
84
Effect.logDebug('Fetching tools...').pipe(Effect.flatMap(() => client.getToolsAsEnums())),
89
- Effect.logDebug('Fetching trigger types payloads...').pipe(
90
- Effect.flatMap(() => client.getTriggerTypes(triggerTypesAsEnums.length))
85
+ Effect.logDebug('Fetching trigger types...').pipe(
86
+ Effect.flatMap(() => client.getTriggerTypes())
87
),
88
],
89
{ concurrency: 'unbounded' }
ts/packages/cli/src/commands/ts/commands/ts.generate.cmd.ts
+145
-66
@@ -29,6 +29,9 @@ import { generateTypeScriptSources } from 'src/generation/typescript/generate';
29
import { jsFindComposioCoreGenerated } from 'src/effects/find-composio-core-generated';
30
import { transpileTypeScriptSources } from 'src/generation/typescript/transpile';
31
import { BANNER } from 'src/generation/constants';
32
+import type { Toolkit } from 'src/models/toolkits';
33
+import type { TriggerType } from 'src/models/trigger-types';
34
+import type { Tool, ToolsAsEnums } from 'src/models/tools';
35
36
export const outputOpt = Options.optional(
37
Options.directory('output-dir', {
@@ -75,6 +78,140 @@ const _tsCmd$Generate = Command.make('generate', {
78
)
79
);
80
81
+/**
82
+ * Result type for fetching toolkit data
83
+ */
84
+type FetchResult = {
85
+ toolkits: ReadonlyArray<Toolkit>;
86
+ triggerTypes: ReadonlyArray<TriggerType>;
87
+ typeableTools:
88
+ | { withTypes: true; tools: ReadonlyArray<Tool> }
89
+ | { withTypes: false; tools: ToolsAsEnums };
90
+};
91
+
92
+/**
93
+ * Fetches data for specific toolkits when --toolkits filter is provided.
94
+ * Makes targeted API calls for only the requested toolkits.
95
+ */
96
+function fetchFilteredData(
97
+ client: ComposioToolkitsRepository,
98
+ slugs: ReadonlyArray<string>,
99
+ typeTools: boolean
100
+): Effect.Effect<FetchResult, Error, never> {
101
+ return Effect.gen(function* () {
102
+ yield* Console.log(`Fetching data for ${slugs.length} toolkit(s): ${slugs.join(', ')}...`);
103
+
104
+ const [filteredToolkits, filteredTriggerTypes, filteredTypeableTools] = yield* Effect.all(
105
+ [
106
+ // Fetch only the specified toolkits by slug
107
+ Effect.logDebug(`Fetching ${slugs.length} toolkit(s) by slug...`).pipe(
108
+ Effect.flatMap(() =>
109
+ client
110
+ .getToolkitsBySlugs(slugs)
111
+ .pipe(
112
+ Effect.catchTag('services/InvalidToolkitsError', error =>
113
+ Effect.fail(
114
+ new Error(
115
+ `Invalid toolkit(s): ${error.invalidToolkits.join(', ')}. Toolkit not found.`
116
+ )
117
+ )
118
+ )
119
+ )
120
+ )
121
+ ),
122
+ // Fetch only trigger types for the specified toolkits
123
+ Effect.logDebug(`Fetching trigger types for ${slugs.length} toolkit(s)...`).pipe(
124
+ Effect.flatMap(() => client.getTriggerTypes(slugs))
125
+ ),
126
+ // Fetch tools for the specified toolkits
127
+ Match.value(typeTools).pipe(
128
+ Match.when(true, withTypes =>
129
+ Effect.logDebug(`Fetching tools with schemas for ${slugs.length} toolkit(s)...`).pipe(
130
+ Effect.flatMap(() => client.getTools(slugs)),
131
+ Effect.map(tools => ({ withTypes, tools }))
132
+ )
133
+ ),
134
+ Match.when(false, withTypes =>
135
+ Effect.logDebug(`Fetching tool names for ${slugs.length} toolkit(s)...`).pipe(
136
+ Effect.flatMap(() => client.getToolsAsEnums()),
137
+ Effect.map(allTools => ({
138
+ withTypes,
139
+ // Filter tool enums by toolkit prefix
140
+ tools: allTools.filter(tool => {
141
+ const prefix = tool.split('_')[0]?.toLowerCase();
142
+ return slugs.some(s => s.toLowerCase() === prefix);
143
+ }),
144
+ }))
145
+ )
146
+ ),
147
+ Match.exhaustive
148
+ ),
149
+ ],
150
+ { concurrency: 'unbounded' }
151
+ );
152
+
153
+ yield* Console.log(
154
+ `Filtering to ${filteredToolkits.length} toolkit(s): ${filteredToolkits.map(t => t.slug).join(', ')}`
155
+ );
156
+
157
+ return {
158
+ toolkits: filteredToolkits,
159
+ triggerTypes: filteredTriggerTypes,
160
+ typeableTools: filteredTypeableTools,
161
+ };
162
+ });
163
+}
164
+
165
+/**
166
+ * Fetches all toolkit data when no --toolkits filter is provided.
167
+ * Fetches everything from the API.
168
+ */
169
+function fetchAllData(
170
+ client: ComposioToolkitsRepository,
171
+ typeTools: boolean
172
+): Effect.Effect<FetchResult, Error, never> {
173
+ return Effect.gen(function* () {
174
+ yield* Console.log('Fetching all toolkits, tools, and triggers from Composio API...');
175
+
176
+ // Fetch all data in parallel
177
+ // Note: getToolsAsEnums is only called when typeTools === false
178
+ const [allToolkits, allTriggerTypes, allTypeableTools] = yield* Effect.all(
179
+ [
180
+ Effect.logDebug('Fetching all toolkits...').pipe(
181
+ Effect.flatMap(() => client.getToolkits())
182
+ ),
183
+ Effect.logDebug('Fetching all trigger types...').pipe(
184
+ Effect.flatMap(() => client.getTriggerTypes())
185
+ ),
186
+ Match.value(typeTools).pipe(
187
+ Match.when(true, withTypes =>
188
+ Effect.logDebug('Fetching all tools with schemas...').pipe(
189
+ Effect.flatMap(() => client.getTools()),
190
+ Effect.map(tools => ({ withTypes, tools }))
191
+ )
192
+ ),
193
+ Match.when(false, withTypes =>
194
+ Effect.logDebug('Fetching all tool names...').pipe(
195
+ Effect.flatMap(() => client.getToolsAsEnums()),
196
+ Effect.map(tools => ({ withTypes, tools }))
197
+ )
198
+ ),
199
+ Match.exhaustive
200
+ ),
201
+ ],
202
+ { concurrency: 'unbounded' }
203
+ );
204
+
205
+ yield* Console.log(`Found ${allToolkits.length} toolkit(s)`);
206
+
207
+ return {
208
+ toolkits: allToolkits,
209
+ triggerTypes: allTriggerTypes,
210
+ typeableTools: allTypeableTools,
211
+ };
212
+ });
213
+}
214
+
215
/**
216
* Validates that the output directory is not inside node_modules
217
*/
@@ -136,73 +273,15 @@ export function generateTypescriptTypeStubs({
273
yield* Effect.log(`Writing type stubs to ${outputDir}...`);
274
yield* fs.makeDirectory(outputDir, { recursive: true });
275
139
- // Fetch data from Composio API
140
- yield* Console.log('Fetching latest data from Composio API. This may take a while...');
141
-
142
- // Validate toolkit slugs if specified
143
- const hasToolkitsFilter = Array.isNonEmptyArray(toolkitsOpt);
144
- const validatedToolkitSlugs = hasToolkitsFilter
145
- ? yield* client
146
- .validateToolkits(toolkitsOpt)
147
- .pipe(
148
- Effect.catchTag('services/InvalidToolkitsError', error =>
149
- Effect.fail(
150
- new Error(
151
- `Invalid toolkit(s): ${error.invalidToolkits.join(', ')}. ` +
152
- `Available toolkits: ${error.availableToolkits.slice(0, 10).join(', ')}${error.availableToolkits.length > 10 ? '...' : ''}`
153
- )
154
- )
155
- )
156
- )
157
- : [];
276
+ // Normalize toolkit slugs if specified (lowercase for API filtering)
277
+ const toolkitSlugsFilter = Array.isNonEmptyArray(toolkitsOpt)
278
+ ? toolkitsOpt.map(s => s.toLowerCase())
279
+ : null;
280
159
- const [triggerTypesAsEnums, toolsAsEnums] = yield* Effect.all([
160
- Effect.logDebug('Fetching trigger types...').pipe(
161
- Effect.flatMap(() => client.getTriggerTypesAsEnums())
162
- ),
163
- Effect.logDebug('Fetching tools...').pipe(Effect.flatMap(() => client.getToolsAsEnums())),
164
- ]);
165
-
166
- const [allToolkits, triggerTypes] = yield* Effect.all(
167
- [
168
- Effect.logDebug('Fetching toolkits...').pipe(Effect.flatMap(() => client.getToolkits())),
169
- Effect.logDebug('Fetching trigger types payloads...').pipe(
170
- Effect.flatMap(() => client.getTriggerTypes(triggerTypesAsEnums.length))
171
- ),
172
- ],
173
- { concurrency: 'unbounded' }
174
- );
175
-
176
- // Filter toolkits if --toolkits was specified
177
- const toolkits = hasToolkitsFilter
178
- ? client.filterToolkitsBySlugs(allToolkits, validatedToolkitSlugs)
179
- : allToolkits;
180
-
181
- if (hasToolkitsFilter) {
182
- yield* Console.log(
183
- `Filtering to ${toolkits.length} toolkit(s): ${toolkits.map(t => t.slug).join(', ')}`
184
- );
185
- }
186
-
187
- // Only fetch tools if `--type-tools` was specified
188
- const typeableTools = yield* Match.value(typeTools).pipe(
189
- Match.when(true, typePredicate =>
190
- Effect.logDebug('Fetching tools...').pipe(
191
- Effect.flatMap(() => client.getTools(toolsAsEnums.length)),
192
- Effect.map(tools => ({
193
- withTypes: typePredicate,
194
- tools,
195
- }))
196
- )
197
- ),
198
- Match.when(false, typePredicate =>
199
- Effect.succeed({
200
- withTypes: typePredicate,
201
- tools: toolsAsEnums,
202
- })
203
- ),
204
- Match.exhaustive
205
- );
281
+ // Fetch data using two distinct strategies based on whether --toolkits filter is provided
282
+ const { toolkits, triggerTypes, typeableTools } = yield* toolkitSlugsFilter !== null
283
+ ? fetchFilteredData(client, toolkitSlugsFilter, typeTools)
284
+ : fetchAllData(client, typeTools);
285
286
yield* Console.log('Writing TypeScript type stubs to disk...');
287
const index = createToolkitIndex({ toolkits, typeableTools, triggerTypes });
ts/packages/cli/src/services/composio-clients-cached.ts
+40
-9
@@ -6,18 +6,20 @@ import { setupCacheDir } from 'src/effects/setup-cache-dir';
6
import { FORCE_CONFIG } from 'src/effects/force-config';
7
import { ComposioToolkitsRepository } from './composio-clients';
8
import { NodeOs } from './node-os';
9
-import { toolkitsFromJSON, toolkitsToJSON } from 'src/models/toolkits';
9
+import { toolkitsFromJSON, toolkitsToJSON, type Toolkits } from 'src/models/toolkits';
10
import {
11
toolsAsEnumsFromJSON,
12
toolsAsEnumsToJSON,
13
ToolsFromJSON,
14
ToolsToJSON,
15
+ type Tools,
16
} from 'src/models/tools';
17
import {
18
TriggerTypesAsEnumsFromJSON,
19
TriggerTypesAsEnumsToJSON,
20
TriggerTypesFromJSON,
21
TriggerTypesToJSON,
22
+ type TriggerTypes,
23
} from 'src/models/trigger-types';
24
import { ConfigLive } from './config';
25
@@ -39,7 +41,8 @@ function createCachedEffect<T, E, R>(
41
cacheFileName: string,
42
decoder: (input: string) => Effect.Effect<T, ParseResult.ParseError>,
43
encoder: (input: T) => Effect.Effect<string, ParseResult.ParseError>,
42
- computation: Effect.Effect<T, E, R>
44
+ computation: Effect.Effect<T, E, R>,
45
+ cacheFilter?: (data: T) => T
46
): Effect.Effect<T, E, R> {
47
// First define the cache-handling function that will run with all required services
48
const cacheEffect = Effect.gen(function* () {
@@ -68,7 +71,7 @@ function createCachedEffect<T, E, R>(
71
);
72
73
if (Option.isSome(cachedResult)) {
71
- return cachedResult.value;
74
+ return cacheFilter ? cacheFilter(cachedResult.value) : cachedResult.value;
75
}
76
}
77
@@ -124,6 +127,20 @@ export const ComposioToolkitsRepositoryCached = Layer.effect(
127
);
128
},
129
130
+ getToolkitsBySlugs: slugs => {
131
+ const cacheFilter = (data: Toolkits): Toolkits => {
132
+ const slugSet = new Set(slugs.map(s => s.toUpperCase()));
133
+ return data.filter(t => slugSet.has(t.slug.toUpperCase()));
134
+ };
135
+ return createCachedEffect(
136
+ CACHE_FILES.toolkits,
137
+ toolkitsFromJSON,
138
+ toolkitsToJSON,
139
+ underlyingRepository.getToolkitsBySlugs(slugs),
140
+ cacheFilter
141
+ );
142
+ },
143
+
144
getToolsAsEnums: () => {
145
return createCachedEffect(
146
CACHE_FILES.toolsAsEnums,
@@ -142,23 +159,37 @@ export const ComposioToolkitsRepositoryCached = Layer.effect(
159
);
160
},
161
145
- getTriggerTypes: (limit: number) => {
162
+ getTriggerTypes: (toolkitSlugs?: ReadonlyArray<string>) => {
163
+ const cacheFilter =
164
+ toolkitSlugs && toolkitSlugs.length > 0
165
+ ? (data: TriggerTypes): TriggerTypes => {
166
+ const prefixes = toolkitSlugs.map(s => `${s.toUpperCase()}_`);
167
+ return data.filter(t => prefixes.some(p => t.slug.toUpperCase().startsWith(p)));
168
+ }
169
+ : undefined;
170
return createCachedEffect(
147
- // We don't care about the limit in the cache file name
171
CACHE_FILES.triggerTypes,
172
TriggerTypesFromJSON,
173
TriggerTypesToJSON,
151
- underlyingRepository.getTriggerTypes(limit)
174
+ underlyingRepository.getTriggerTypes(toolkitSlugs),
175
+ cacheFilter
176
);
177
},
178
155
- getTools: (limit: number) => {
179
+ getTools: (toolkitSlugs?: ReadonlyArray<string>) => {
180
+ const cacheFilter =
181
+ toolkitSlugs && toolkitSlugs.length > 0
182
+ ? (data: Tools): Tools => {
183
+ const prefixes = toolkitSlugs.map(s => `${s.toUpperCase()}_`);
184
+ return data.filter(t => prefixes.some(p => t.slug.toUpperCase().startsWith(p)));
185
+ }
186
+ : undefined;
187
return createCachedEffect(
157
- // We don't care about the limit in the cache file name
188
CACHE_FILES.tools,
189
ToolsFromJSON,
190
ToolsToJSON,
161
- underlyingRepository.getTools(limit)
191
+ underlyingRepository.getTools(toolkitSlugs),
192
+ cacheFilter
193
);
194
},
195
ts/packages/cli/src/services/composio-clients.ts
+131
-38
@@ -66,6 +66,24 @@ export const ToolkitsResponse = Schema.Struct({
66
}).annotations({ identifier: 'ToolkitsResponse' });
67
export type ToolkitsResponse = Schema.Schema.Type<typeof ToolkitsResponse>;
68
69
+// Similar to Toolkits, without auth_schemes, with auth_config_details instead
70
+export const ToolkitRetrieveResponse = Schema.Struct({
71
+ name: Schema.String,
72
+ slug: Schema.Trim.pipe(Schema.nonEmptyString()),
73
+ is_local_toolkit: Schema.Boolean,
74
+ composio_managed_auth_schemes: Schema.optionalWith(Schema.Array(Schema.String), {
75
+ default: () => [],
76
+ }),
77
+ no_auth: Schema.optionalWith(Schema.Boolean, { default: () => false }),
78
+ meta: Schema.Struct({
79
+ description: Schema.optionalWith(Schema.String, { default: () => '' }),
80
+ categories: Schema.optionalWith(Schema.Array(Schema.Unknown), { default: () => [] }),
81
+ created_at: Schema.DateTimeUtc,
82
+ updated_at: Schema.DateTimeUtc,
83
+ }),
84
+}).annotations({ identifier: 'ToolkitRetrieveResponse' });
85
+export type ToolkitRetrieveResponse = Schema.Schema.Type<typeof ToolkitRetrieveResponse>;
86
+
87
export const ToolsAsEnumsResponse = ToolsAsEnums;
88
export type ToolsAsEnumsResponse = Schema.Schema.Type<typeof ToolsAsEnumsResponse>;
89
@@ -246,13 +264,18 @@ type PaginatedSchema = Schema.Schema<
264
any
265
>;
266
267
+// Maximum items per page allowed by the server
268
+const MAX_PAGE_SIZE = 1000;
269
+
270
+// Maximum concurrent requests per each endpoint
271
+const MAX_CONCURRENT_REQUESTS_PER_ENDPOINT = 4;
272
+
273
// Utility function for calling paginated Composio API endpoints.
250
-// Automatically fetches all pages until the specified limit is reached.
274
+// Automatically fetches all pages, using MAX_PAGE_SIZE per request.
275
const callClientWithPagination = <T, S extends PaginatedSchema>(
276
clientSingleton: ComposioClientSingleton,
253
- apiCall: (client: _RawComposioClient, cursor?: string) => APIPromise<T>,
254
- responseSchema: S,
255
- limit: number
277
+ apiCall: (client: _RawComposioClient, cursor?: string, limit?: number) => APIPromise<T>,
278
+ responseSchema: S
279
): Effect.Effect<
280
{ data: Schema.Schema.Type<S>; metrics: Metrics },
281
HttpError | NoSuchElementException
@@ -265,7 +288,7 @@ const callClientWithPagination = <T, S extends PaginatedSchema>(
288
const fetchPage = (cursor?: string): Effect.Effect<StreamedResponse, HttpServerError> =>
289
Effect.gen(function* () {
290
const response = yield* Effect.tryPromise({
268
- try: () => apiCall(client, cursor).asResponse(),
291
+ try: () => apiCall(client, cursor, MAX_PAGE_SIZE).asResponse(),
292
catch: e => {
293
const decodedOpt = Schema.decodeUnknownOption(HttpErrorResponse)(e);
294
@@ -313,7 +336,8 @@ const callClientWithPagination = <T, S extends PaginatedSchema>(
336
let currentCursor: string | null = null;
337
let totalPages = 0;
338
316
- while (allItems.length < limit) {
339
+ // Fetch all pages using MAX_PAGE_SIZE per request
340
+ while (true) {
341
const { json, byteSize } = yield* fetchPage(currentCursor ?? undefined);
342
totalByteSize += byteSize;
343
totalRequests += 1;
@@ -334,7 +358,7 @@ const callClientWithPagination = <T, S extends PaginatedSchema>(
358
359
return {
360
data: {
337
- items: allItems.slice(0, limit),
361
+ items: allItems,
362
total_pages: totalPages,
363
next_cursor: currentCursor,
364
} as DecodedPage,
@@ -411,21 +435,42 @@ export class ComposioClientLive extends Effect.Service<ComposioClientLive>()(
435
toolkits: {
436
/**
437
* Retrieves a comprehensive list of toolkits that are available to the authenticated project.
414
- * If limit is provided, automatically handles pagination to fetch up to that many items.
438
+ * Automatically handles pagination to fetch all items.
439
*/
416
- list: (params?: { limit?: number }) =>
417
- params?.limit
418
- ? withMetrics(
419
- callClientWithPagination(
420
- clientSingleton,
421
- (client, cursor) => client.toolkits.list({ cursor }),
422
- ToolkitsResponse,
423
- params.limit
424
- )
425
- )
426
- : withMetrics(
427
- callClient(clientSingleton, client => client.toolkits.list(), ToolkitsResponse)
428
- ),
440
+ list: () =>
441
+ withMetrics(
442
+ callClientWithPagination(
443
+ clientSingleton,
444
+ (client, cursor, limit) => client.toolkits.list({ cursor, limit }),
445
+ ToolkitsResponse
446
+ )
447
+ ),
448
+ /**
449
+ * Retrieves a single toolkit by its slug.
450
+ * Transforms the response to match the Toolkit schema.
451
+ */
452
+ retrieve: (slug: string) =>
453
+ withMetrics(
454
+ callClient(
455
+ clientSingleton,
456
+ client => client.toolkits.retrieve(slug),
457
+ ToolkitRetrieveResponse
458
+ )
459
+ ).pipe(
460
+ // Transform to Toolkit format by adding missing fields
461
+ Effect.map(
462
+ retrieved =>
463
+ ({
464
+ name: retrieved.name,
465
+ slug: retrieved.slug,
466
+ auth_schemes: [], // retrieve endpoint doesn't return auth_schemes
467
+ composio_managed_auth_schemes: retrieved.composio_managed_auth_schemes,
468
+ is_local_toolkit: retrieved.is_local_toolkit,
469
+ no_auth: retrieved.no_auth,
470
+ meta: retrieved.meta,
471
+ }) satisfies Toolkit
472
+ )
473
+ ),
474
},
475
tools: {
476
/**
@@ -440,16 +485,17 @@ export class ComposioClientLive extends Effect.Service<ComposioClientLive>()(
485
)
486
),
487
/**
443
- * Retrieve a list of tools, automatically handling pagination to fetch up to $limit items.
488
+ * Retrieve a list of tools, automatically handling pagination.
489
+ * @param toolkitSlugs - Optional array of toolkit slugs to filter by
490
*/
445
- list: (params: { limit: number }) =>
491
+ list: (toolkitSlugs?: ReadonlyArray<string>) =>
492
withMetrics(
493
callClientWithPagination(
494
clientSingleton,
449
- (client, cursor) =>
450
- client.tools.list({ cursor, limit: params.limit, toolkit_versions: 'latest' }),
451
- ToolsResponse,
452
- params.limit
495
+ (client, cursor, limit) =>
496
+ client.tools.list({
497
+ cursor, toolkit_slug: toolkitSlugs?.join(',') ?? '', toolkit_versions: 'latest', limit, }),
498
+ ToolsResponse
499
)
500
),
501
},
@@ -466,15 +512,20 @@ export class ComposioClientLive extends Effect.Service<ComposioClientLive>()(
512
)
513
),
514
/**
469
- * Retrieve a list of trigger types, automatically handling pagination to fetch up to $limit items.
515
+ * Retrieve a list of trigger types, automatically handling pagination.
516
+ * @param toolkitSlugs - Optional array of toolkit slugs to filter by
517
*/
471
- list: (params: { limit: number }) =>
518
+ list: (toolkitSlugs?: ReadonlyArray<string>) =>
519
withMetrics(
520
callClientWithPagination(
521
clientSingleton,
475
- (client, cursor) => client.triggersTypes.list({ cursor, limit: params.limit }),
476
- TriggerTypesResponse,
477
- params.limit
522
+ (client, cursor, limit) =>
523
+ client.triggersTypes.list({
524
+ cursor,
525
+ limit,
526
+ toolkit_slugs: toolkitSlugs ? [...toolkitSlugs] : undefined,
527
+ }),
528
+ TriggerTypesResponse
529
)
530
),
531
},
@@ -515,8 +566,8 @@ export class ComposioToolkitsRepository extends Effect.Service<ComposioToolkitsR
566
effect: Effect.gen(function* () {
567
const client = yield* ComposioClientLive;
568
518
- const getToolkits = (limit?: number) =>
519
- client.toolkits.list({ limit }).pipe(
569
+ const getToolkits = () =>
570
+ client.toolkits.list().pipe(
571
Effect.map(response => response.items),
572
Effect.flatMap(
573
Effect.fn(function* (toolkits) {
@@ -528,12 +579,49 @@ export class ComposioToolkitsRepository extends Effect.Service<ComposioToolkitsR
579
)
580
);
581
582
+ /**
583
+ * Fetches specific toolkits by their slugs.
584
+ * Makes parallel API calls to retrieve each toolkit.
585
+ * @param slugs - Array of toolkit slugs to fetch
586
+ */
587
+ const getToolkitsBySlugs = (slugs: ReadonlyArray<string>) =>
588
+ Effect.all(
589
+ slugs.map(slug =>
590
+ client.toolkits.retrieve(slug).pipe(
591
+ Effect.catchTag('services/HttpServerError', () =>
592
+ Effect.fail(
593
+ new InvalidToolkitsError({
594
+ invalidToolkits: [slug],
595
+ availableToolkits: [],
596
+ })
597
+ )
598
+ )
599
+ )
600
+ ),
601
+ { concurrency: MAX_CONCURRENT_REQUESTS_PER_ENDPOINT }
602
+ ).pipe(
603
+ Effect.flatMap(
604
+ Effect.fn(function* (toolkits) {
605
+ // Sort apps by slug.
606
+ // TODO: make sure this happens on the server-side.
607
+ const orderBySlug = Order.mapInput(Order.string, (app: Toolkit) => app.slug);
608
+ return Array.sort(toolkits, orderBySlug) as ReadonlyArray<Toolkit>;
609
+ })
610
+ )
611
+ );
612
+
613
return {
614
getToolkits,
615
+ getToolkitsBySlugs,
616
getMetrics: () => client.getMetrics(),
617
getToolsAsEnums: () => client.tools.retrieveEnum(),
535
- getTools: (limit: number) =>
536
- client.tools.list({ limit }).pipe(
618
+ /**
619
+ * Fetches tools with optional toolkit filtering.
620
+ * When toolkitSlugs is provided, fetches all matching tools.
621
+ * @param toolkitSlugs - Optional array of toolkit slugs to filter by
622
+ */
623
+ getTools: (toolkitSlugs?: ReadonlyArray<string>) =>
624
+ client.tools.list(toolkitSlugs).pipe(
625
Effect.map(response => response.items),
626
Effect.flatMap(
627
Effect.fn(function* (tools) {
@@ -545,8 +633,13 @@ export class ComposioToolkitsRepository extends Effect.Service<ComposioToolkitsR
633
)
634
),
635
getTriggerTypesAsEnums: () => client.triggersTypes.retrieveEnum(),
548
- getTriggerTypes: (limit: number) =>
549
- client.triggersTypes.list({ limit }).pipe(
636
+ /**
637
+ * Fetches trigger types with optional toolkit filtering.
638
+ * When toolkitSlugs is provided, fetches all matching trigger types.
639
+ * @param toolkitSlugs - Optional array of toolkit slugs to filter by
640
+ */
641
+ getTriggerTypes: (toolkitSlugs?: ReadonlyArray<string>) =>
642
+ client.triggersTypes.list(toolkitSlugs).pipe(
643
Effect.map(response => response.items),
644
Effect.flatMap(
645
Effect.fn(function* (triggerTypes) {
ts/packages/cli/test/__utils__/services/test-layer.ts
+33
-2
@@ -92,11 +92,42 @@ export const TestLayer = (input?: TestLiveInput) =>
92
ComposioToolkitsRepository,
93
new ComposioToolkitsRepository({
94
getToolkits: () => Effect.succeed(toolkitsData.toolkits),
95
+ getToolkitsBySlugs: (slugs: ReadonlyArray<string>) => {
96
+ const normalizedSlugs = new Set(slugs.map(s => String.toLowerCase(s)));
97
+ const found = toolkitsData.toolkits.filter(t =>
98
+ normalizedSlugs.has(String.toLowerCase(t.slug))
99
+ );
100
+ if (found.length !== slugs.length) {
101
+ const foundSlugs = new Set(found.map(t => String.toLowerCase(t.slug)));
102
+ const notFound = slugs.filter(s => !foundSlugs.has(String.toLowerCase(s)));
103
+ return Effect.fail(
104
+ new InvalidToolkitsError({
105
+ invalidToolkits: [...notFound],
106
+ availableToolkits: toolkitsData.toolkits.map(t => t.slug),
107
+ })
108
+ );
109
+ }
110
+ return Effect.succeed(found);
111
+ },
112
getMetrics: () => Effect.succeed({ byteSize: 0, requests: 0 }),
113
getToolsAsEnums: () => Effect.succeed(toolkitsData.tools.map(tool => tool.slug)),
114
getTriggerTypesAsEnums: () => Effect.succeed(toolkitsData.triggerTypesAsEnums),
98
- getTriggerTypes: limit => Effect.succeed(toolkitsData.triggerTypes.slice(0, limit)),
99
- getTools: limit => Effect.succeed(toolkitsData.tools.slice(0, limit)),
115
+ getTriggerTypes: (toolkitSlugs?: ReadonlyArray<string>) => {
116
+ let triggers = toolkitsData.triggerTypes;
117
+ if (toolkitSlugs && toolkitSlugs.length > 0) {
118
+ const prefixes = toolkitSlugs.map(s => `${s.toUpperCase()}_`);
119
+ triggers = triggers.filter(t => prefixes.some(p => t.slug.startsWith(p)));
120
+ }
121
+ return Effect.succeed(triggers);
122
+ },
123
+ getTools: (toolkitSlugs?: ReadonlyArray<string>) => {
124
+ let tools = toolkitsData.tools;
125
+ if (toolkitSlugs && toolkitSlugs.length > 0) {
126
+ const prefixes = toolkitSlugs.map(s => `${s.toUpperCase()}_`);
127
+ tools = tools.filter(t => prefixes.some(p => t.slug.startsWith(p)));
128
+ }
129
+ return Effect.succeed(tools);
130
+ },
131
validateToolkits: (toolkitSlugs: ReadonlyArray<string>) => {
132
const normalizedInputSlugs = toolkitSlugs.map(slug => String.toLowerCase(slug));
133
const availableSlugs = toolkitsData.toolkits.map(toolkit =>