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, 19:30 UTC
fix(cli): create './generated' folder in '@composio/core' if it doesn't exist; recursively locate '@composio/core'
jkomyno committed
Oct 27, 2025 at 22:57 UTC
6133fa3c69ae725f5b10dabfaa0b6c1bc362d653
2 files changed
+90
-49
ts/packages/cli/src/commands/ts/commands/ts.generate.cmd.ts
+4
-6
@@ -108,18 +108,16 @@ export function generateTypescriptTypeStubs({
108
// Determine the actual output directory
109
const outputDir = yield* outputOpt.pipe(
110
Option.match({
111
- // If no output directory is specified, use the default
111
+ // If no output directory is specified, use the default, and make sure it exists
112
onNone: () => jsFindComposioCoreGenerated(cwd),
113
114
// If an output directory is specified, validate and create it
115
- onSome: outputDir =>
116
- validateOutputDir(outputDir).pipe(
117
- Effect.tap(fs.makeDirectory(outputDir, { recursive: true }))
118
- ),
115
+ onSome: outputDir => validateOutputDir(outputDir),
116
})
117
);
118
119
yield* Effect.log(`Writing type stubs to ${outputDir}...`);
120
+ yield* fs.makeDirectory(outputDir, { recursive: true });
121
122
// Fetch data from Composio API
123
yield* Console.log('Fetching latest data from Composio API...');
@@ -197,7 +195,7 @@ export function generateTypescriptTypeStubs({
195
yield* Option.isNone(outputOpt)
196
? Console.log(
197
'✅ Type stubs generated successfully.\n' +
200
- 'You can now import generated types via `import { composio } from "@composio/core/generated"`'
198
+ 'You can now import generated types via `import { Toolkits } from "@composio/core/generated"`'
199
)
200
: Console.log(
201
`✅ Type stubs generated successfully.\n` +
ts/packages/cli/src/effects/find-composio-core-generated.ts
+86
-43
@@ -77,53 +77,96 @@ export function jsFindComposioCoreGenerated(cwd: string) {
77
* Returns a `ComposioCorePkgNotFound` error with the given message and cause.
78
* It lazily identifies the package manager used by the user to tell them how to install `@composio/core`.
79
*/
80
- const onError = (message: string) => (e: Error | string) =>
81
- Effect.gen(function* () {
82
- yield* Effect.logDebug('Identifying JS package manager...');
83
- const pkgManagerDetector = yield* JsPackageManagerDetector;
84
- const pkgManager = yield* pkgManagerDetector.detectJsPackageManager(cwd).pipe(
85
- Effect.andThen(pkgManager => pkgManager),
86
- Effect.tapError(e => Effect.logError(e)),
87
- Effect.catchAll(() => Effect.succeed('npm' as PackageManager))
88
- );
89
-
90
- yield* Effect.logDebug({ pkgManager });
91
-
92
- const installCmd = Match.value(pkgManager).pipe(
93
- Match.when('pnpm', () => 'pnpm add'),
94
- Match.when('bun', () => 'bun add'),
95
- Match.when('yarn', () => 'yarn add'),
96
- Match.when('npm', () => 'npm install -S'),
97
- Match.exhaustive
98
- );
99
-
100
- const fix = `Install @composio/core with \`${installCmd} @composio/core\`, or specify an output directory using \`--output-dir\``;
101
-
102
- return yield* Effect.fail(
103
- new ComposioCorePkgNotFound({
104
- cause: e instanceof Error ? e.message : e,
105
- fix,
106
- message,
107
- })
108
- );
109
- }) satisfies Effect.Effect<never, ComposioCorePkgNotFound, JsPackageManagerDetector>;
80
+ const onError =
81
+ (message: string, { pkgManager }: { pkgManager: PackageManager }) =>
82
+ (e: Error | string) =>
83
+ Effect.gen(function* () {
84
+ const installCmd = Match.value(pkgManager).pipe(
85
+ Match.when('pnpm', () => 'pnpm add'),
86
+ Match.when('bun', () => 'bun add'),
87
+ Match.when('yarn', () => 'yarn add'),
88
+ Match.when('npm', () => 'npm install -S'),
89
+ Match.exhaustive
90
+ );
91
+
92
+ const fix = `Install @composio/core with \`${installCmd} @composio/core\`, or specify an output directory using \`--output-dir\``;
93
+
94
+ return yield* Effect.fail(
95
+ new ComposioCorePkgNotFound({
96
+ cause: e instanceof Error ? e.message : e,
97
+ fix,
98
+ message,
99
+ })
100
+ );
101
+ }) satisfies Effect.Effect<never, ComposioCorePkgNotFound, JsPackageManagerDetector>;
102
103
const fs = yield* FileSystem.FileSystem;
104
113
- // First, try to find @composio/core in node_modules
114
- const nodeModulesPath = path.join(cwd, 'node_modules', '@composio', 'core');
115
- const nodeModulesExists = yield* fs
116
- .exists(nodeModulesPath)
117
- .pipe(
118
- Effect.catchAll(e =>
119
- Effect.flip(onError('@composio/core not readable in `node_modules`')(e))
120
- )
121
- );
122
-
123
- if (nodeModulesExists) {
124
- return path.join(nodeModulesPath, 'generated');
105
+ yield* Effect.logDebug('Detecting package manager...');
106
+ const pkgManagerDetector = yield* JsPackageManagerDetector;
107
+ const pkgManager = yield* pkgManagerDetector.detectJsPackageManager(cwd).pipe(
108
+ Effect.tapError(e => Effect.logError(e)),
109
+ Effect.catchAll(() => Effect.succeed('npm' as PackageManager))
110
+ );
111
+ yield* Effect.logDebug({ pkgManager });
112
+
113
+ /**
114
+ * Walk up the directory tree to find node_modules containing @composio/core.
115
+ * This handles monorepo scenarios where the package may be installed at a parent level.
116
+ */
117
+ const findInNodeModules = (
118
+ searchDir: string
119
+ ): Effect.Effect<string | null, never, FileSystem.FileSystem> =>
120
+ Effect.gen(function* () {
121
+ const nodeModulesPath = path.join(searchDir, 'node_modules', '@composio', 'core');
122
+
123
+ yield* Effect.logDebug({ searchingIn: nodeModulesPath });
124
+
125
+ const exists = yield* fs
126
+ .exists(nodeModulesPath)
127
+ .pipe(Effect.catchAll(() => Effect.succeed(false)));
128
+
129
+ if (exists) {
130
+ yield* Effect.logDebug({ foundComposioCoreIn: nodeModulesPath });
131
+ return path.join(nodeModulesPath, 'generated');
132
+ }
133
+
134
+ // For pnpm, also check the virtual store
135
+ if (pkgManager === 'pnpm') {
136
+ const pnpmStorePath = path.join(
137
+ searchDir,
138
+ 'node_modules',
139
+ '.pnpm',
140
+ 'node_modules',
141
+ '@composio',
142
+ 'core'
143
+ );
144
+ const pnpmExists = yield* fs
145
+ .exists(pnpmStorePath)
146
+ .pipe(Effect.catchAll(() => Effect.succeed(false)));
147
+
148
+ if (pnpmExists) {
149
+ yield* Effect.logDebug({ foundComposioCoreInPnpmStore: pnpmStorePath });
150
+ return path.join(pnpmStorePath, 'generated');
151
+ }
152
+ }
153
+
154
+ const parentDir = path.dirname(searchDir);
155
+ if (parentDir === searchDir) {
156
+ return null;
157
+ }
158
+
159
+ return yield* findInNodeModules(parentDir);
160
+ });
161
+
162
+ const foundPath = yield* findInNodeModules(cwd);
163
+
164
+ if (foundPath) {
165
+ return foundPath;
166
}
167
127
- return yield* onError('@composio/core not found')('@composio/core not installed');
168
+ return yield* onError('@composio/core not found', { pkgManager })(
169
+ '@composio/core not installed'
170
+ );
171
}) satisfies Effect.Effect<string, ComposioCorePkgNotFound, unknown>;
172
}