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, 17:00 UTC
feat(cli): add "composio generate --toolkits [toolkits]" support, for both ts and py
jkomyno committed
Dec 11, 2025 at 20:19 UTC
3f0395eb5fcf879161c0faef8d4a34c0ee0a6139
10 files changed
+495
-35
ts/packages/cli/src/commands/generate.cmd.ts
+17
-4
@@ -18,17 +18,24 @@ export const typeTools = Options.boolean('type-tools').pipe(
18
)
19
);
20
21
+export const toolkitsOpt = Options.text('toolkits').pipe(
22
+ Options.repeated,
23
+ Options.withDescription(
24
+ 'Filter output to only include the specified toolkits. Can be specified multiple times (e.g., --toolkits gmail --toolkits slack)'
25
+ )
26
+);
27
+
28
/**
29
* @example
30
* ```bash
31
* composio generate <command>
32
* ```
33
*/
27
-export const generateCmd = Command.make('generate', { outputOpt, typeTools }).pipe(
34
+export const generateCmd = Command.make('generate', { outputOpt, typeTools, toolkitsOpt }).pipe(
35
Command.withDescription(
36
'Updates the local type stubs with the latest app data, automatically detecting the language of the project in the current working directory (TypeScript | Python).'
37
),
31
- Command.withHandler(({ outputOpt, typeTools }) =>
38
+ Command.withHandler(({ outputOpt, typeTools, toolkitsOpt }) =>
39
Effect.gen(function* () {
40
const process = yield* NodeProcess;
41
const cwd = process.cwd;
@@ -41,9 +48,15 @@ export const generateCmd = Command.make('generate', { outputOpt, typeTools }).pi
48
// Redirect to either `ts generate` or `py generate` commands
49
yield* Match.value(envLang).pipe(
50
Match.when('TypeScript', () =>
44
- generateTypescriptTypeStubs({ outputOpt, compact: false, transpiled: false, typeTools })
51
+ generateTypescriptTypeStubs({
52
+ outputOpt,
53
+ compact: false,
54
+ transpiled: false,
55
+ typeTools,
56
+ toolkitsOpt,
57
+ })
58
),
46
- Match.when('Python', () => generatePythonTypeStubs({ outputOpt })),
59
+ Match.when('Python', () => generatePythonTypeStubs({ outputOpt, toolkitsOpt })),
60
Match.exhaustive
61
);
62
})
ts/packages/cli/src/commands/py/commands/py.generate.cmd.ts
+42
-4
@@ -1,5 +1,5 @@
1
import { Command, Options } from '@effect/cli';
2
-import { pipe, Console, Effect, Option } from 'effect';
2
+import { pipe, Console, Effect, Option, Array } from 'effect';
3
import { FileSystem } from '@effect/platform';
4
import { ComposioToolkitsRepository } from 'src/services/composio-clients';
5
import type { GetCmdParams } from 'src/type-utils';
@@ -18,13 +18,23 @@ export const outputOpt = Options.optional(
18
Options.withDescription('Output directory for the generated Python type stubs')
19
);
20
21
-const _pyCmd$Generate = Command.make('generate', { outputOpt }).pipe(
21
+export const toolkitsOpt = Options.text('toolkits').pipe(
22
+ Options.repeated,
23
+ Options.withDescription(
24
+ 'Filter output to only include the specified toolkits. Can be specified multiple times (e.g., --toolkits gmail --toolkits slack)'
25
+ )
26
+);
27
+
28
+const _pyCmd$Generate = Command.make('generate', { outputOpt, toolkitsOpt }).pipe(
29
Command.withDescription('Updates the local type stubs with the latest app data.')
30
);
31
32
export const pyCmd$Generate = _pyCmd$Generate.pipe(Command.withHandler(generatePythonTypeStubs));
33
27
-export function generatePythonTypeStubs({ outputOpt }: GetCmdParams<typeof _pyCmd$Generate>) {
34
+export function generatePythonTypeStubs({
35
+ outputOpt,
36
+ toolkitsOpt,
37
+}: GetCmdParams<typeof _pyCmd$Generate>) {
38
return Effect.gen(function* () {
39
const process = yield* NodeProcess;
40
const cwd = process.cwd;
@@ -48,11 +58,28 @@ export function generatePythonTypeStubs({ outputOpt }: GetCmdParams<typeof _pyCm
58
// Fetch data from Composio API
59
yield* Console.log('Fetching latest data from Composio API. This may take a while...');
60
61
+ // Validate toolkit slugs if specified
62
+ const hasToolkitsFilter = Array.isNonEmptyArray(toolkitsOpt);
63
+ const validatedToolkitSlugs = hasToolkitsFilter
64
+ ? yield* client
65
+ .validateToolkits(toolkitsOpt)
66
+ .pipe(
67
+ Effect.catchTag('services/InvalidToolkitsError', error =>
68
+ Effect.fail(
69
+ new Error(
70
+ `Invalid toolkit(s): ${error.invalidToolkits.join(', ')}. ` +
71
+ `Available toolkits: ${error.availableToolkits.slice(0, 10).join(', ')}${error.availableToolkits.length > 10 ? '...' : ''}`
72
+ )
73
+ )
74
+ )
75
+ )
76
+ : [];
77
+
78
const triggerTypesAsEnums = yield* Effect.logDebug('Fetching trigger types...').pipe(
79
Effect.flatMap(() => client.getTriggerTypesAsEnums())
80
);
81
55
- const [toolkits, tools, triggerTypes] = yield* Effect.all(
82
+ const [allToolkits, tools, triggerTypes] = yield* Effect.all(
83
[
84
Effect.logDebug('Fetching toolkits...').pipe(Effect.flatMap(() => client.getToolkits())),
85
Effect.logDebug('Fetching tools...').pipe(Effect.flatMap(() => client.getToolsAsEnums())),
@@ -63,6 +90,17 @@ export function generatePythonTypeStubs({ outputOpt }: GetCmdParams<typeof _pyCm
90
{ concurrency: 'unbounded' }
91
);
92
93
+ // Filter toolkits if --toolkits was specified
94
+ const toolkits = hasToolkitsFilter
95
+ ? client.filterToolkitsBySlugs(allToolkits, validatedToolkitSlugs)
96
+ : allToolkits;
97
+
98
+ if (hasToolkitsFilter) {
99
+ yield* Console.log(
100
+ `Filtering to ${toolkits.length} toolkit(s): ${toolkits.map(t => t.slug).join(', ')}`
101
+ );
102
+ }
103
+
104
const typeableTools = { withTypes: false as const, tools };
105
106
const index = createToolkitIndex({ toolkits, typeableTools, triggerTypes });
ts/packages/cli/src/commands/ts/commands/ts.generate.cmd.ts
+41
-3
@@ -3,6 +3,7 @@
3
* - `--compact`: Emit a single module file
4
* - `--transpiled`: Emit not just the TypeScript files, but also the transpiled JavaScript files
5
* - `--output-dir`: Output directory for the generated TypeScript type stubs.
6
+ * - `--toolkits`: Filter output to only include the specified toolkits. Can be specified multiple times (e.g., --toolkits gmail --toolkits slack)
7
*
8
* Invariants:
9
* - The `--output-dir` cannot refer to a path inside `node_modules`
@@ -16,10 +17,10 @@
17
18
import path from 'node:path';
19
import { Command, Options } from '@effect/cli';
19
-import { Console, Effect, Option, pipe } from 'effect';
20
+import { Console, Effect, Option, pipe, Array } from 'effect';
21
import { Match } from 'effect';
22
import { FileSystem } from '@effect/platform';
22
-import { ComposioToolkitsRepository } from 'src/services/composio-clients';
23
+import { ComposioToolkitsRepository, InvalidToolkitsError } from 'src/services/composio-clients';
24
import { NodeProcess } from 'src/services/node-process';
25
import { createToolkitIndex } from 'src/generation/create-toolkit-index';
26
import type { GetCmdParams } from 'src/type-utils';
@@ -52,11 +53,19 @@ export const typeTools = Options.boolean('type-tools').pipe(
53
Options.withDescription('Whether to emit type stubs for tools')
54
);
55
56
+export const toolkitsOpt = Options.text('toolkits').pipe(
57
+ Options.repeated,
58
+ Options.withDescription(
59
+ 'Filter output to only include the specified toolkits. Can be specified multiple times (e.g., --toolkits gmail --toolkits slack)'
60
+ )
61
+);
62
+
63
const _tsCmd$Generate = Command.make('generate', {
64
outputOpt,
65
compact,
66
transpiled: transpiled,
67
typeTools,
68
+ toolkitsOpt,
69
}).pipe(Command.withDescription('Updates the local type stubs with the latest app data.'));
70
71
/**
@@ -98,6 +107,7 @@ export function generateTypescriptTypeStubs({
107
compact,
108
typeTools,
109
transpiled = false,
110
+ toolkitsOpt,
111
}: GetCmdParams<typeof _tsCmd$Generate> & { transpiled?: boolean }) {
112
return Effect.gen(function* () {
113
const fs = yield* FileSystem.FileSystem;
@@ -122,6 +132,23 @@ export function generateTypescriptTypeStubs({
132
// Fetch data from Composio API
133
yield* Console.log('Fetching latest data from Composio API. This may take a while...');
134
135
+ // Validate toolkit slugs if specified
136
+ const hasToolkitsFilter = Array.isNonEmptyArray(toolkitsOpt);
137
+ const validatedToolkitSlugs = hasToolkitsFilter
138
+ ? yield* client
139
+ .validateToolkits(toolkitsOpt)
140
+ .pipe(
141
+ Effect.catchTag('services/InvalidToolkitsError', error =>
142
+ Effect.fail(
143
+ new Error(
144
+ `Invalid toolkit(s): ${error.invalidToolkits.join(', ')}. ` +
145
+ `Available toolkits: ${error.availableToolkits.slice(0, 10).join(', ')}${error.availableToolkits.length > 10 ? '...' : ''}`
146
+ )
147
+ )
148
+ )
149
+ )
150
+ : [];
151
+
152
const [triggerTypesAsEnums, toolsAsEnums] = yield* Effect.all([
153
Effect.logDebug('Fetching trigger types...').pipe(
154
Effect.flatMap(() => client.getTriggerTypesAsEnums())
@@ -129,7 +156,7 @@ export function generateTypescriptTypeStubs({
156
Effect.logDebug('Fetching tools...').pipe(Effect.flatMap(() => client.getToolsAsEnums())),
157
]);
158
132
- const [toolkits, triggerTypes] = yield* Effect.all(
159
+ const [allToolkits, triggerTypes] = yield* Effect.all(
160
[
161
Effect.logDebug('Fetching toolkits...').pipe(Effect.flatMap(() => client.getToolkits())),
162
Effect.logDebug('Fetching trigger types payloads...').pipe(
@@ -139,6 +166,17 @@ export function generateTypescriptTypeStubs({
166
{ concurrency: 'unbounded' }
167
);
168
169
+ // Filter toolkits if --toolkits was specified
170
+ const toolkits = hasToolkitsFilter
171
+ ? client.filterToolkitsBySlugs(allToolkits, validatedToolkitSlugs)
172
+ : allToolkits;
173
+
174
+ if (hasToolkitsFilter) {
175
+ yield* Console.log(
176
+ `Filtering to ${toolkits.length} toolkit(s): ${toolkits.map(t => t.slug).join(', ')}`
177
+ );
178
+ }
179
+
180
// Only fetch tools if `--type-tools` was specified
181
const typeableTools = yield* Match.value(typeTools).pipe(
182
Match.when(true, typePredicate =>
ts/packages/cli/src/services/composio-clients-cached.ts
+6
@@ -161,6 +161,12 @@ export const ComposioToolkitsRepositoryCached = Layer.effect(
161
underlyingRepository.getTools(limit)
162
);
163
},
164
+
165
+ // These methods don't need caching as they operate on already fetched data
166
+ // or perform validation that should always be fresh
167
+ validateToolkits: toolkitSlugs => underlyingRepository.validateToolkits(toolkitSlugs),
168
+ filterToolkitsBySlugs: (toolkits, toolkitSlugs) =>
169
+ underlyingRepository.filterToolkitsBySlugs(toolkits, toolkitSlugs),
170
});
171
})
172
).pipe(
ts/packages/cli/src/services/composio-clients.ts
+71
-14
@@ -1,6 +1,6 @@
1
-import { pipe, Data, Effect, Option, Schema, Array, Order, ParseResult } from 'effect';
1
+import { pipe, Data, Effect, Option, Schema, Array, Order, ParseResult, String } from 'effect';
2
import { Composio as _RawComposioClient } from '@composio/client';
3
-import { Toolkit, Toolkits } from 'src/models/toolkits';
3
+import { Toolkit, Toolkits, ToolkitName } from 'src/models/toolkits';
4
import { ToolsAsEnums, Tools, Tool } from 'src/models/tools';
5
import { Session, RetrievedSession } from 'src/models/session';
6
import { TriggerType, TriggerTypes, TriggerTypesAsEnums } from 'src/models/trigger-types';
@@ -19,6 +19,14 @@ export class HttpServerError extends Data.TaggedError('services/HttpServerError'
19
readonly cause?: unknown;
20
}> {}
21
22
+/**
23
+ * Error thrown when one or more toolkit slugs are invalid.
24
+ */
25
+export class InvalidToolkitsError extends Data.TaggedError('services/InvalidToolkitsError')<{
26
+ readonly invalidToolkits: ReadonlyArray<string>;
27
+ readonly availableToolkits: ReadonlyArray<string>;
28
+}> {}
29
+
30
/**
31
* Error thrown when a HTTP response doesn't match the expected response schema.
32
*/
@@ -359,19 +367,21 @@ export class ComposioToolkitsRepository extends Effect.Service<ComposioToolkitsR
367
effect: Effect.gen(function* () {
368
const client = yield* ComposioClientLive;
369
370
+ const getToolkits = (limit?: number) =>
371
+ client.toolkits.list({ limit }).pipe(
372
+ Effect.map(response => response.items),
373
+ Effect.flatMap(
374
+ Effect.fn(function* (toolkits) {
375
+ // Sort apps by slug.
376
+ // TODO: make sure this happens on the server-side.
377
+ const orderBySlug = Order.mapInput(Order.string, (app: Toolkit) => app.slug);
378
+ return Array.sort(toolkits, orderBySlug) as ReadonlyArray<Toolkit>;
379
+ })
380
+ )
381
+ );
382
+
383
return {
363
- getToolkits: (limit?: number) =>
364
- client.toolkits.list({ limit }).pipe(
365
- Effect.map(response => response.items),
366
- Effect.flatMap(
367
- Effect.fn(function* (toolkits) {
368
- // Sort apps by slug.
369
- // TODO: make sure this happens on the server-side.
370
- const orderBySlug = Order.mapInput(Order.string, (app: Toolkit) => app.slug);
371
- return Array.sort(toolkits, orderBySlug) as ReadonlyArray<Toolkit>;
372
- })
373
- )
374
- ),
384
+ getToolkits,
385
getToolsAsEnums: () => client.tools.retrieveEnum(),
386
getTools: (limit: number) =>
387
client.tools.list({ limit }).pipe(
@@ -398,6 +408,53 @@ export class ComposioToolkitsRepository extends Effect.Service<ComposioToolkitsR
408
})
409
)
410
),
411
+ /**
412
+ * Validates that the given toolkit slugs are valid by comparing them against the list
413
+ * of available toolkits. Returns the list of valid toolkit slugs (normalized to lowercase).
414
+ * @param toolkitSlugs - Array of toolkit slugs to validate (case-insensitive)
415
+ */
416
+ validateToolkits: (
417
+ toolkitSlugs: ReadonlyArray<string>
418
+ ): Effect.Effect<
419
+ ReadonlyArray<string>,
420
+ InvalidToolkitsError | HttpError | NoSuchElementException
421
+ > =>
422
+ Effect.gen(function* () {
423
+ // Normalize input slugs to lowercase for comparison
424
+ const normalizedInputSlugs = toolkitSlugs.map(slug => String.toLowerCase(slug));
425
+
426
+ // Fetch all available toolkits
427
+ const allToolkits = yield* getToolkits();
428
+ const availableSlugs = allToolkits.map(toolkit => String.toLowerCase(toolkit.slug));
429
+
430
+ // Find invalid slugs
431
+ const invalidSlugs = normalizedInputSlugs.filter(
432
+ slug => !availableSlugs.includes(slug)
433
+ );
434
+
435
+ if (invalidSlugs.length > 0) {
436
+ return yield* Effect.fail(
437
+ new InvalidToolkitsError({
438
+ invalidToolkits: invalidSlugs,
439
+ availableToolkits: availableSlugs,
440
+ })
441
+ );
442
+ }
443
+
444
+ return normalizedInputSlugs;
445
+ }),
446
+ /**
447
+ * Filters the given list of toolkits to only include those with the specified slugs.
448
+ * @param toolkits - Array of toolkits to filter
449
+ * @param toolkitSlugs - Array of toolkit slugs to filter by (case-insensitive)
450
+ */
451
+ filterToolkitsBySlugs: (
452
+ toolkits: ReadonlyArray<Toolkit>,
453
+ toolkitSlugs: ReadonlyArray<string>
454
+ ): ReadonlyArray<Toolkit> => {
455
+ const normalizedSlugs = new Set(toolkitSlugs.map(slug => String.toLowerCase(slug)));
456
+ return toolkits.filter(toolkit => normalizedSlugs.has(String.toLowerCase(toolkit.slug)));
457
+ },
458
};
459
}),
460
dependencies: [ComposioClientLive.Default],
ts/packages/cli/test/__utils__/services/test-layer.ts
+24
@@ -12,6 +12,7 @@ import {
12
Logger,
13
LogLevel,
14
Schedule,
15
+ String,
16
} from 'effect';
17
import { ComposioCliConfig } from 'src/cli-config';
18
import * as MockConsole from './mock-console';
@@ -21,6 +22,7 @@ import { NodeProcess } from 'src/services/node-process';
22
import {
23
ComposioSessionRepository,
24
ComposioToolkitsRepository,
25
+ InvalidToolkitsError,
26
} from 'src/services/composio-clients';
27
import { EnvLangDetector } from 'src/services/env-lang-detector';
28
import { JsPackageManagerDetector } from 'src/services/js-package-manager-detector';
@@ -94,6 +96,28 @@ export const TestLayer = (input?: TestLiveInput) =>
96
getTriggerTypesAsEnums: () => Effect.succeed(toolkitsData.triggerTypesAsEnums),
97
getTriggerTypes: limit => Effect.succeed(toolkitsData.triggerTypes.slice(0, limit)),
98
getTools: limit => Effect.succeed(toolkitsData.tools.slice(0, limit)),
99
+ validateToolkits: (toolkitSlugs: ReadonlyArray<string>) => {
100
+ const normalizedInputSlugs = toolkitSlugs.map(slug => String.toLowerCase(slug));
101
+ const availableSlugs = toolkitsData.toolkits.map(toolkit =>
102
+ String.toLowerCase(toolkit.slug)
103
+ );
104
+ const invalidSlugs = normalizedInputSlugs.filter(slug => !availableSlugs.includes(slug));
105
+
106
+ if (invalidSlugs.length > 0) {
107
+ return Effect.fail(
108
+ new InvalidToolkitsError({
109
+ invalidToolkits: invalidSlugs,
110
+ availableToolkits: availableSlugs,
111
+ })
112
+ );
113
+ }
114
+
115
+ return Effect.succeed(normalizedInputSlugs);
116
+ },
117
+ filterToolkitsBySlugs: (toolkits, toolkitSlugs) => {
118
+ const normalizedSlugs = new Set(toolkitSlugs.map(slug => String.toLowerCase(slug)));
119
+ return toolkits.filter(toolkit => normalizedSlugs.has(String.toLowerCase(toolkit.slug)));
120
+ },
121
})
122
);
123
ts/packages/cli/test/src/commands/$default.cmd.test.ts
+10
-10
@@ -58,25 +58,25 @@ describe('CLI: composio', () => {
58
59
[0;1mCOMMANDS[0m
60
61
- - version Display your account information.
61
+ - version Display your account information.
62
63
- - upgrade Upgrade your Composio CLI to the latest available version.
63
+ - upgrade Upgrade your Composio CLI to the latest available version.
64
65
- - whoami Display your account information.
65
+ - whoami Display your account information.
66
67
- - login [--no-browser] Log in to the Composio SDK.
67
+ - login [--no-browser] Log in to the Composio SDK.
68
69
- - logout Log out from the Composio SDK.
69
+ - logout Log out from the Composio SDK.
70
71
- - generate [(-o, --output-dir directory)] [--type-tools] Updates the local type stubs with the latest app data, automatically detecting the language of the project in the current working directory (TypeScript | Python).
71
+ - generate [(-o, --output-dir directory)] [--type-tools] --toolkits text... Updates the local type stubs with the latest app data, automatically detecting the language of the project in the current working directory (TypeScript | Python).
72
73
- - py Handle Python projects.
73
+ - py Handle Python projects.
74
75
- - py generate [(-o, --output-dir directory)] Updates the local type stubs with the latest app data.
75
+ - py generate [(-o, --output-dir directory)] --toolkits text... Updates the local type stubs with the latest app data.
76
77
- - ts Handle TypeScript projects.
77
+ - ts Handle TypeScript projects.
78
79
- - ts generate [(-o, --output-dir directory)] [--compact] [--transpiled] [--type-tools] Updates the local type stubs with the latest app data.
79
+ - ts generate [(-o, --output-dir directory)] [--compact] [--transpiled] [--type-tools] --toolkits text... Updates the local type stubs with the latest app data.
80
"
81
`);
82
})
ts/packages/cli/test/src/commands/generate.cmd.test.ts
+88
@@ -1,9 +1,31 @@
1
+import path from 'node:path';
2
import { describe, expect, layer } from '@effect/vitest';
3
import { Effect } from 'effect';
4
+import { FileSystem } from '@effect/platform';
5
import { NodeProcess } from 'src/services/node-process';
6
import { cli, TestLive, MockConsole } from 'test/__utils__';
7
+import { makeTestToolkits } from 'test/__utils__/models/toolkits';
8
+import { TRIGGER_TYPES_GMAIL } from 'test/__mocks__/trigger-types-gmail';
9
+import { TOOLS_TYPES_GMAIL } from 'test/__mocks__/tools-types-gmail';
10
+import type { TestLiveInput } from 'test/__utils__/services/test-layer';
11
12
describe('CLI: composio generate', () => {
13
+ const appClientData = {
14
+ toolkits: makeTestToolkits([
15
+ {
16
+ name: 'Gmail',
17
+ slug: 'gmail',
18
+ },
19
+ {
20
+ name: 'Slack',
21
+ slug: 'slack',
22
+ },
23
+ ]),
24
+ tools: [...TOOLS_TYPES_GMAIL.slice(0, 3)],
25
+ triggerTypes: [...TRIGGER_TYPES_GMAIL.slice(0, 3)],
26
+ triggerTypesAsEnums: [...TRIGGER_TYPES_GMAIL.slice(0, 3).map(triggerType => triggerType.slug)],
27
+ } satisfies TestLiveInput['toolkitsData'];
28
+
29
layer(
30
TestLive({
31
fixture: 'python-project',
@@ -41,4 +63,70 @@ describe('CLI: composio generate', () => {
63
})
64
);
65
});
66
+
67
+ layer(
68
+ TestLive({
69
+ fixture: 'typescript-project',
70
+ toolkitsData: appClientData,
71
+ })
72
+ )(it => {
73
+ it.scoped(
74
+ '[Given] TypeScript project with --toolkits [Then] it filters output to specified toolkits',
75
+ () =>
76
+ Effect.gen(function* () {
77
+ const process = yield* NodeProcess;
78
+ const cwd = process.cwd;
79
+ const fs = yield* FileSystem.FileSystem;
80
+ const outputDir = path.join(cwd, '.generated', 'composio-filtered');
81
+
82
+ const args = ['generate', '--toolkits', 'gmail', '--output-dir', outputDir];
83
+ yield* cli(args);
84
+
85
+ const lines = yield* MockConsole.getLines();
86
+ const output = lines.join('\n');
87
+ expect(output).toContain('Project type detected: TypeScript');
88
+ expect(output).toContain('Filtering to 1 toolkit(s): gmail');
89
+
90
+ // Check generated files - only gmail.ts should exist
91
+ const files = yield* fs.readDirectory(outputDir);
92
+ const fileNames = files.map(file => path.basename(file));
93
+
94
+ expect(fileNames).toContain('gmail.ts');
95
+ expect(fileNames).not.toContain('slack.ts');
96
+ })
97
+ );
98
+ });
99
+
100
+ layer(
101
+ TestLive({
102
+ fixture: 'python-project',
103
+ toolkitsData: appClientData,
104
+ })
105
+ )(it => {
106
+ it.scoped(
107
+ '[Given] Python project with --toolkits [Then] it filters output to specified toolkits',
108
+ () =>
109
+ Effect.gen(function* () {
110
+ const process = yield* NodeProcess;
111
+ const cwd = process.cwd;
112
+ const fs = yield* FileSystem.FileSystem;
113
+ const outputDir = path.join(cwd, '.generated', 'composio-filtered');
114
+
115
+ const args = ['generate', '--toolkits', 'gmail', '--output-dir', outputDir];
116
+ yield* cli(args);
117
+
118
+ const lines = yield* MockConsole.getLines();
119
+ const output = lines.join('\n');
120
+ expect(output).toContain('Project type detected: Python');
121
+ expect(output).toContain('Filtering to 1 toolkit(s): gmail');
122
+
123
+ // Check generated files - only gmail.py should exist
124
+ const files = yield* fs.readDirectory(outputDir);
125
+ const fileNames = files.map(file => path.basename(file));
126
+
127
+ expect(fileNames).toContain('gmail.py');
128
+ expect(fileNames).not.toContain('slack.py');
129
+ })
130
+ );
131
+ });
132
});
ts/packages/cli/test/src/commands/py/py.generate.cmd.test.ts
+94
@@ -295,6 +295,100 @@ describe('CLI: composio py generate', () => {
295
});
296
})
297
);
298
+
299
+ it.scoped(
300
+ '[Given] --toolkits gmail [Then] it generates type stubs only for the gmail toolkit',
301
+ Effect.fn(function* () {
302
+ const process = yield* NodeProcess;
303
+ const cwd = process.cwd;
304
+ const fs = yield* FileSystem.FileSystem;
305
+ const outputDir = path.join(cwd, '.generated', 'composio-py-filtered');
306
+
307
+ const args = ['py', 'generate', '--toolkits', 'gmail', '--output-dir', outputDir];
308
+ yield* cli(args);
309
+
310
+ // Check generated files - only gmail.py should exist (no slack.py)
311
+ const files = yield* fs.readDirectory(outputDir);
312
+ const fileNames = files.map(file => path.basename(file));
313
+
314
+ expect(fileNames).toContain('gmail.py');
315
+ expect(fileNames).not.toContain('slack.py');
316
+
317
+ // Verify gmail.py contains GMAIL class
318
+ const gmailSourceCode = yield* fs.readFileString(path.join(outputDir, 'gmail.py'));
319
+ expect(gmailSourceCode).toContain('GMAIL');
320
+ })
321
+ );
322
+
323
+ it.scoped(
324
+ '[Given] --toolkits gmail --toolkits slack [Then] it generates type stubs for both toolkits',
325
+ Effect.fn(function* () {
326
+ const process = yield* NodeProcess;
327
+ const cwd = process.cwd;
328
+ const fs = yield* FileSystem.FileSystem;
329
+ const outputDir = path.join(cwd, '.generated', 'composio-py-multi');
330
+
331
+ const args = [
332
+ 'py',
333
+ 'generate',
334
+ '--toolkits',
335
+ 'gmail',
336
+ '--toolkits',
337
+ 'slack',
338
+ '--output-dir',
339
+ outputDir,
340
+ ];
341
+ yield* cli(args);
342
+
343
+ // Check generated files - both gmail.py and slack.py should exist
344
+ const files = yield* fs.readDirectory(outputDir);
345
+ const fileNames = files.map(file => path.basename(file));
346
+
347
+ expect(fileNames).toContain('gmail.py');
348
+ expect(fileNames).toContain('slack.py');
349
+
350
+ // Verify both files contain their respective classes
351
+ const gmailSourceCode = yield* fs.readFileString(path.join(outputDir, 'gmail.py'));
352
+ const slackSourceCode = yield* fs.readFileString(path.join(outputDir, 'slack.py'));
353
+ expect(gmailSourceCode).toContain('GMAIL');
354
+ expect(slackSourceCode).toContain('SLACK');
355
+ })
356
+ );
357
+
358
+ it.scoped(
359
+ '[Given] --toolkits with invalid toolkit [Then] it fails with an error',
360
+ Effect.fn(function* () {
361
+ const process = yield* NodeProcess;
362
+ const cwd = process.cwd;
363
+ const outputDir = path.join(cwd, '.generated', 'composio-py-invalid');
364
+
365
+ const args = ['py', 'generate', '--toolkits', 'nonexistent', '--output-dir', outputDir];
366
+ const result = yield* cli(args).pipe(Effect.catchAll(e => Effect.succeed(e)));
367
+
368
+ expect(result).toBeInstanceOf(Error);
369
+ expect((result as Error).message).toContain('Invalid toolkit(s): nonexistent');
370
+ })
371
+ );
372
+
373
+ it.scoped(
374
+ '[Given] --toolkits GMAIL (uppercase) [Then] it handles case-insensitive matching',
375
+ Effect.fn(function* () {
376
+ const process = yield* NodeProcess;
377
+ const cwd = process.cwd;
378
+ const fs = yield* FileSystem.FileSystem;
379
+ const outputDir = path.join(cwd, '.generated', 'composio-py-uppercase');
380
+
381
+ const args = ['py', 'generate', '--toolkits', 'GMAIL', '--output-dir', outputDir];
382
+ yield* cli(args);
383
+
384
+ // Check generated files - only gmail.py should exist
385
+ const files = yield* fs.readDirectory(outputDir);
386
+ const fileNames = files.map(file => path.basename(file));
387
+
388
+ expect(fileNames).toContain('gmail.py');
389
+ expect(fileNames).not.toContain('slack.py');
390
+ })
391
+ );
392
});
393
});
394
});
ts/packages/cli/test/src/commands/ts/ts.generate.cmd.test.ts
+102
@@ -847,6 +847,108 @@ describe('CLI: composio ts generate', () => {
847
assertTypeScriptIsValid({ files: { './index.ts': indexSourceCode } });
848
})
849
);
850
+
851
+ it.scoped(
852
+ '[Given] --toolkits gmail [Then] it generates type stubs only for the gmail toolkit',
853
+ () =>
854
+ Effect.gen(function* () {
855
+ const process = yield* NodeProcess;
856
+ const cwd = process.cwd;
857
+ const fs = yield* FileSystem.FileSystem;
858
+ const outputDir = path.join(cwd, 'generated-filtered');
859
+
860
+ const args = ['ts', 'generate', '--toolkits', 'gmail', '--output-dir', outputDir];
861
+ yield* cli(args);
862
+
863
+ // Check generated files - only gmail.ts and index.ts should exist
864
+ const files = yield* fs.readDirectory(outputDir);
865
+ const fileNames = files.map(file => path.basename(file));
866
+
867
+ expect(fileNames).toContain('gmail.ts');
868
+ expect(fileNames).toContain('index.ts');
869
+ expect(fileNames).not.toContain('slack.ts');
870
+
871
+ // Verify index only references gmail
872
+ const indexSourceCode = yield* fs.readFileString(path.join(outputDir, 'index.ts'));
873
+ expect(indexSourceCode).toContain('GMAIL');
874
+ expect(indexSourceCode).not.toContain('SLACK');
875
+
876
+ assertTypeScriptIsValid({ files: { './index.ts': indexSourceCode } });
877
+ })
878
+ );
879
+
880
+ it.scoped(
881
+ '[Given] --toolkits gmail --toolkits slack [Then] it generates type stubs for both toolkits',
882
+ () =>
883
+ Effect.gen(function* () {
884
+ const process = yield* NodeProcess;
885
+ const cwd = process.cwd;
886
+ const fs = yield* FileSystem.FileSystem;
887
+ const outputDir = path.join(cwd, 'generated-multi-filtered');
888
+
889
+ const args = [
890
+ 'ts',
891
+ 'generate',
892
+ '--toolkits',
893
+ 'gmail',
894
+ '--toolkits',
895
+ 'slack',
896
+ '--output-dir',
897
+ outputDir,
898
+ ];
899
+ yield* cli(args);
900
+
901
+ // Check generated files - both gmail.ts and slack.ts should exist
902
+ const files = yield* fs.readDirectory(outputDir);
903
+ const fileNames = files.map(file => path.basename(file));
904
+
905
+ expect(fileNames).toContain('gmail.ts');
906
+ expect(fileNames).toContain('slack.ts');
907
+ expect(fileNames).toContain('index.ts');
908
+
909
+ // Verify index references both
910
+ const indexSourceCode = yield* fs.readFileString(path.join(outputDir, 'index.ts'));
911
+ expect(indexSourceCode).toContain('GMAIL');
912
+ expect(indexSourceCode).toContain('SLACK');
913
+
914
+ assertTypeScriptIsValid({ files: { './index.ts': indexSourceCode } });
915
+ })
916
+ );
917
+
918
+ it.scoped('[Given] --toolkits with invalid toolkit [Then] it fails with an error', () =>
919
+ Effect.gen(function* () {
920
+ const process = yield* NodeProcess;
921
+ const cwd = process.cwd;
922
+ const outputDir = path.join(cwd, 'generated-invalid');
923
+
924
+ const args = ['ts', 'generate', '--toolkits', 'nonexistent', '--output-dir', outputDir];
925
+ const result = yield* cli(args).pipe(Effect.catchAll(e => Effect.succeed(e)));
926
+
927
+ expect(result).toBeInstanceOf(Error);
928
+ expect((result as Error).message).toContain('Invalid toolkit(s): nonexistent');
929
+ })
930
+ );
931
+
932
+ it.scoped(
933
+ '[Given] --toolkits GMAIL (uppercase) [Then] it handles case-insensitive matching',
934
+ () =>
935
+ Effect.gen(function* () {
936
+ const process = yield* NodeProcess;
937
+ const cwd = process.cwd;
938
+ const fs = yield* FileSystem.FileSystem;
939
+ const outputDir = path.join(cwd, 'generated-uppercase');
940
+
941
+ const args = ['ts', 'generate', '--toolkits', 'GMAIL', '--output-dir', outputDir];
942
+ yield* cli(args);
943
+
944
+ // Check generated files - only gmail.ts should exist
945
+ const files = yield* fs.readDirectory(outputDir);
946
+ const fileNames = files.map(file => path.basename(file));
947
+
948
+ expect(fileNames).toContain('gmail.ts');
949
+ expect(fileNames).not.toContain('slack.ts');
950
+ })
951
+ );
952
});
953
});
954