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.

fix(cli): create './generated' folder in '@composio/core' if it doesn't exist; recursively locate '@composio/core'

jkomyno6133fa3c69ae
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 b620105e2..eb5179c5d 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
@@ -108,18 +108,16 @@ export function generateTypescriptTypeStubs({
// Determine the actual output directory
const outputDir = yield* outputOpt.pipe(
Option.match({
- // If no output directory is specified, use the default
+ // If no output directory is specified, use the default, and make sure it exists
onNone: () => jsFindComposioCoreGenerated(cwd),
// If an output directory is specified, validate and create it
- onSome: outputDir =>
- validateOutputDir(outputDir).pipe(
- Effect.tap(fs.makeDirectory(outputDir, { recursive: true }))
- ),
+ onSome: outputDir => validateOutputDir(outputDir),
})
);
yield* Effect.log(`Writing type stubs to ${outputDir}...`);
+ yield* fs.makeDirectory(outputDir, { recursive: true });
// Fetch data from Composio API
yield* Console.log('Fetching latest data from Composio API...');
@@ -197,7 +195,7 @@ export function generateTypescriptTypeStubs({
yield* Option.isNone(outputOpt)
? Console.log(
'✅ Type stubs generated successfully.\n' +
- 'You can now import generated types via `import { composio } from "@composio/core/generated"`'
+ 'You can now import generated types via `import { Toolkits } from "@composio/core/generated"`'
)
: Console.log(
`✅ Type stubs generated successfully.\n` +
diff --git a/ts/packages/cli/src/effects/find-composio-core-generated.ts b/ts/packages/cli/src/effects/find-composio-core-generated.ts
index 8e99ba7e9..ba35cb988 100644
--- a/ts/packages/cli/src/effects/find-composio-core-generated.ts
+++ b/ts/packages/cli/src/effects/find-composio-core-generated.ts
@@ -77,53 +77,96 @@ export function jsFindComposioCoreGenerated(cwd: string) {
* Returns a `ComposioCorePkgNotFound` error with the given message and cause.
* It lazily identifies the package manager used by the user to tell them how to install `@composio/core`.
*/
- const onError = (message: string) => (e: Error | string) =>
- Effect.gen(function* () {
- yield* Effect.logDebug('Identifying JS package manager...');
- const pkgManagerDetector = yield* JsPackageManagerDetector;
- const pkgManager = yield* pkgManagerDetector.detectJsPackageManager(cwd).pipe(
- Effect.andThen(pkgManager => pkgManager),
- Effect.tapError(e => Effect.logError(e)),
- Effect.catchAll(() => Effect.succeed('npm' as PackageManager))
- );
-
- yield* Effect.logDebug({ pkgManager });
-
- const installCmd = Match.value(pkgManager).pipe(
- Match.when('pnpm', () => 'pnpm add'),
- Match.when('bun', () => 'bun add'),
- Match.when('yarn', () => 'yarn add'),
- Match.when('npm', () => 'npm install -S'),
- Match.exhaustive
- );
-
- const fix = `Install @composio/core with \`${installCmd} @composio/core\`, or specify an output directory using \`--output-dir\``;
-
- return yield* Effect.fail(
- new ComposioCorePkgNotFound({
- cause: e instanceof Error ? e.message : e,
- fix,
- message,
- })
- );
- }) satisfies Effect.Effect<never, ComposioCorePkgNotFound, JsPackageManagerDetector>;
+ const onError =
+ (message: string, { pkgManager }: { pkgManager: PackageManager }) =>
+ (e: Error | string) =>
+ Effect.gen(function* () {
+ const installCmd = Match.value(pkgManager).pipe(
+ Match.when('pnpm', () => 'pnpm add'),
+ Match.when('bun', () => 'bun add'),
+ Match.when('yarn', () => 'yarn add'),
+ Match.when('npm', () => 'npm install -S'),
+ Match.exhaustive
+ );
+
+ const fix = `Install @composio/core with \`${installCmd} @composio/core\`, or specify an output directory using \`--output-dir\``;
+
+ return yield* Effect.fail(
+ new ComposioCorePkgNotFound({
+ cause: e instanceof Error ? e.message : e,
+ fix,
+ message,
+ })
+ );
+ }) satisfies Effect.Effect<never, ComposioCorePkgNotFound, JsPackageManagerDetector>;
const fs = yield* FileSystem.FileSystem;
- // First, try to find @composio/core in node_modules
- const nodeModulesPath = path.join(cwd, 'node_modules', '@composio', 'core');
- const nodeModulesExists = yield* fs
- .exists(nodeModulesPath)
- .pipe(
- Effect.catchAll(e =>
- Effect.flip(onError('@composio/core not readable in `node_modules`')(e))
- )
- );
-
- if (nodeModulesExists) {
- return path.join(nodeModulesPath, 'generated');
+ yield* Effect.logDebug('Detecting package manager...');
+ const pkgManagerDetector = yield* JsPackageManagerDetector;
+ const pkgManager = yield* pkgManagerDetector.detectJsPackageManager(cwd).pipe(
+ Effect.tapError(e => Effect.logError(e)),
+ Effect.catchAll(() => Effect.succeed('npm' as PackageManager))
+ );
+ yield* Effect.logDebug({ pkgManager });
+
+ /**
+ * Walk up the directory tree to find node_modules containing @composio/core.
+ * This handles monorepo scenarios where the package may be installed at a parent level.
+ */
+ const findInNodeModules = (
+ searchDir: string
+ ): Effect.Effect<string | null, never, FileSystem.FileSystem> =>
+ Effect.gen(function* () {
+ const nodeModulesPath = path.join(searchDir, 'node_modules', '@composio', 'core');
+
+ yield* Effect.logDebug({ searchingIn: nodeModulesPath });
+
+ const exists = yield* fs
+ .exists(nodeModulesPath)
+ .pipe(Effect.catchAll(() => Effect.succeed(false)));
+
+ if (exists) {
+ yield* Effect.logDebug({ foundComposioCoreIn: nodeModulesPath });
+ return path.join(nodeModulesPath, 'generated');
+ }
+
+ // For pnpm, also check the virtual store
+ if (pkgManager === 'pnpm') {
+ const pnpmStorePath = path.join(
+ searchDir,
+ 'node_modules',
+ '.pnpm',
+ 'node_modules',
+ '@composio',
+ 'core'
+ );
+ const pnpmExists = yield* fs
+ .exists(pnpmStorePath)
+ .pipe(Effect.catchAll(() => Effect.succeed(false)));
+
+ if (pnpmExists) {
+ yield* Effect.logDebug({ foundComposioCoreInPnpmStore: pnpmStorePath });
+ return path.join(pnpmStorePath, 'generated');
+ }
+ }
+
+ const parentDir = path.dirname(searchDir);
+ if (parentDir === searchDir) {
+ return null;
+ }
+
+ return yield* findInNodeModules(parentDir);
+ });
+
+ const foundPath = yield* findInNodeModules(cwd);
+
+ if (foundPath) {
+ return foundPath;
}
- return yield* onError('@composio/core not found')('@composio/core not installed');
+ return yield* onError('@composio/core not found', { pkgManager })(
+ '@composio/core not installed'
+ );
}) satisfies Effect.Effect<string, ComposioCorePkgNotFound, unknown>;
}