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.

refactor(cli): extract shared handleTsGenerate to eliminate handler duplication

jkomynoc3a5605644aa
diff --git a/ts/packages/cli/src/commands/generate/generate-ts.cmd.ts b/ts/packages/cli/src/commands/generate/generate-ts.cmd.ts
index a77eed7f2..f66d5d168 100644
--- a/ts/packages/cli/src/commands/generate/generate-ts.cmd.ts
+++ b/ts/packages/cli/src/commands/generate/generate-ts.cmd.ts
@@ -1,12 +1,11 @@
import { Command } from '@effect/cli';
-import { Option } from 'effect';
import {
- generateTypescriptTypeStubs,
outputOpt,
compact,
transpiled,
typeTools,
toolkitsOpt,
+ handleTsGenerate,
} from '../ts/commands/ts.generate.cmd';
/**
@@ -20,12 +19,5 @@ export const generateCmd$Ts = Command.make('ts', {
toolkitsOpt,
}).pipe(
Command.withDescription('Generate TypeScript type stubs for toolkits, tools, and triggers.'),
- Command.withHandler(params => {
- const shouldCompile = params.transpiled || !Option.isSome(params.outputOpt);
- return generateTypescriptTypeStubs({
- ...params,
- compact: params.compact,
- transpiled: shouldCompile,
- });
- })
+ Command.withHandler(handleTsGenerate)
);
diff --git a/ts/packages/cli/src/commands/ts/commands/ts.generate.cmd.ts b/ts/packages/cli/src/commands/ts/commands/ts.generate.cmd.ts
index 2a98c6c52..535e8c0c4 100644
--- a/ts/packages/cli/src/commands/ts/commands/ts.generate.cmd.ts
+++ b/ts/packages/cli/src/commands/ts/commands/ts.generate.cmd.ts
@@ -332,20 +332,21 @@ function validateOutputDir(outputDir: string): Effect.Effect<string, Error, File
});
}
-export const tsCmd$Generate = _tsCmd$Generate.pipe(
- Command.withHandler(params => {
- // Determine if we should compile based on the rules:
- // - If --output-dir is specified, default transpiled to false unless overridden
- // - If no --output-dir, default transpiled to true unless overridden
- const shouldCompile = params.transpiled || !Option.isSome(params.outputOpt);
-
- return generateTypescriptTypeStubs({
- ...params,
- compact: params.compact,
- transpiled: shouldCompile,
- });
- })
-);
+/**
+ * Shared handler for TypeScript generation commands.
+ * Resolves the `transpiled` default based on whether `--output-dir` was provided.
+ */
+export const handleTsGenerate = (params: GetCmdParams<typeof _tsCmd$Generate>) => {
+ // Determine if we should compile based on the rules:
+ // - If --output-dir is specified, default transpiled to false unless overridden
+ // - If no --output-dir, default transpiled to true unless overridden
+ const shouldCompile = params.transpiled || !Option.isSome(params.outputOpt);
+
+ return generateTypescriptTypeStubs({
+ ...params,
+ transpiled: shouldCompile,
+ });
+};
export function generateTypescriptTypeStubs({
outputOpt,