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

next
ts 43 lines 1.64 KB
Raw
1 import { Effect, Match, Option } from 'effect';
2 import { ProjectEnvironmentDetector } from 'src/services/project-environment-detector';
3 import { NodeProcess } from 'src/services/node-process';
4 import { TerminalUI } from 'src/services/terminal-ui';
5 import { generateTypescriptTypeStubs, resolveTranspiled } from './ts/generate.ts.handler';
6 import { runGeneratePy } from './py/generate.py.handler';
7
8 export type GenerateParams = {
9 readonly outputDir: Option.Option<string>;
10 readonly typeTools: boolean;
11 readonly toolkits: ReadonlyArray<string>;
12 };
13
14 /**
15 * Detects the project language in the current directory and runs the matching generator.
16 */
17 export const runGenerate = ({ outputDir, typeTools, toolkits }: GenerateParams) =>
18 Effect.gen(function* () {
19 const ui = yield* TerminalUI;
20 const process = yield* NodeProcess;
21 const cwd = process.cwd;
22
23 yield* Effect.logDebug('Identifying project type...');
24 const envDetector = yield* ProjectEnvironmentDetector;
25 const env = yield* envDetector.detectProjectEnvironment(cwd);
26 const displayLang = env.kind === 'js' ? 'TypeScript' : 'Python';
27 yield* ui.log.step(`Project type detected: ${displayLang}`);
28
29 yield* Match.value(env.kind).pipe(
30 Match.when('js', () =>
31 generateTypescriptTypeStubs({
32 outputDir,
33 compact: false,
34 // `generate` has no --transpiled flag, so the `generate ts` default rule applies.
35 transpiled: resolveTranspiled({ transpiled: false, outputDir }),
36 typeTools,
37 toolkits,
38 })
39 ),
40 Match.when('python', () => runGeneratePy({ outputDir, toolkits })),
41 Match.exhaustive
42 );
43 });