@composio/core 0.1.27 → 0.1.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -80,6 +80,7 @@ __export(index_exports, {
80
80
  GenerateURLResponseCamelCaseSchema: () => GenerateURLResponseCamelCaseSchema,
81
81
  GenerateURLResponseSchema: () => GenerateURLResponseSchema,
82
82
  IncomingTriggerPayloadSchema: () => IncomingTriggerPayloadSchema,
83
+ JSONSchemaPropertySchema: () => JSONSchemaPropertySchema,
83
84
  JsonSchemaToZodError: () => JsonSchemaToZodError,
84
85
  MCP: () => MCP,
85
86
  MCPAuthOptionsSchema: () => MCPAuthOptionsSchema,
@@ -176,19 +177,21 @@ var JSONSchemaType = import_zod.z.enum([
176
177
  "array",
177
178
  "null"
178
179
  ]);
179
- var JSONSchemaProperty = import_zod.z.object({
180
+ var JSONSchemaPropertySchema = import_zod.z.object({
180
181
  type: import_zod.z.union([JSONSchemaType, import_zod.z.array(JSONSchemaType)]).optional(),
181
182
  description: import_zod.z.string().optional(),
182
- anyOf: import_zod.z.lazy(() => import_zod.z.array(JSONSchemaProperty)).optional(),
183
- oneOf: import_zod.z.lazy(() => import_zod.z.array(JSONSchemaProperty)).optional(),
184
- allOf: import_zod.z.lazy(() => import_zod.z.array(JSONSchemaProperty)).optional(),
185
- not: import_zod.z.lazy(() => JSONSchemaProperty).optional(),
183
+ anyOf: import_zod.z.lazy(() => import_zod.z.array(JSONSchemaPropertySchema)).optional(),
184
+ oneOf: import_zod.z.lazy(() => import_zod.z.array(JSONSchemaPropertySchema)).optional(),
185
+ allOf: import_zod.z.lazy(() => import_zod.z.array(JSONSchemaPropertySchema)).optional(),
186
+ not: import_zod.z.lazy(() => JSONSchemaPropertySchema).optional(),
186
187
  title: import_zod.z.string().optional(),
187
188
  default: import_zod.z.any().optional(),
188
189
  nullable: import_zod.z.boolean().optional(),
189
- properties: import_zod.z.lazy(() => import_zod.z.record(import_zod.z.string(), JSONSchemaProperty)).optional(),
190
+ properties: import_zod.z.lazy(() => import_zod.z.record(import_zod.z.string(), JSONSchemaPropertySchema)).optional(),
190
191
  required: import_zod.z.array(import_zod.z.string()).optional(),
191
- items: import_zod.z.lazy(() => import_zod.z.union([JSONSchemaProperty, import_zod.z.array(JSONSchemaProperty)])).optional(),
192
+ file_uploadable: import_zod.z.boolean().optional(),
193
+ file_downloadable: import_zod.z.boolean().optional(),
194
+ items: import_zod.z.lazy(() => import_zod.z.union([JSONSchemaPropertySchema, import_zod.z.array(JSONSchemaPropertySchema)])).optional(),
192
195
  enum: import_zod.z.array(import_zod.z.any()).optional(),
193
196
  const: import_zod.z.any().optional(),
194
197
  minimum: import_zod.z.number().optional(),
@@ -205,31 +208,31 @@ var JSONSchemaProperty = import_zod.z.object({
205
208
  uniqueItems: import_zod.z.boolean().optional(),
206
209
  minProperties: import_zod.z.number().optional(),
207
210
  maxProperties: import_zod.z.number().optional(),
208
- patternProperties: import_zod.z.lazy(() => import_zod.z.record(import_zod.z.string(), JSONSchemaProperty)).optional(),
209
- additionalProperties: import_zod.z.union([import_zod.z.boolean(), import_zod.z.lazy(() => JSONSchemaProperty)]).optional(),
211
+ patternProperties: import_zod.z.lazy(() => import_zod.z.record(import_zod.z.string(), JSONSchemaPropertySchema)).optional(),
212
+ additionalProperties: import_zod.z.union([import_zod.z.boolean(), import_zod.z.lazy(() => JSONSchemaPropertySchema)]).optional(),
210
213
  examples: import_zod.z.array(import_zod.z.any()).optional(),
211
214
  readOnly: import_zod.z.boolean().optional(),
212
215
  writeOnly: import_zod.z.boolean().optional(),
213
- if: import_zod.z.lazy(() => JSONSchemaProperty).optional(),
214
- then: import_zod.z.lazy(() => JSONSchemaProperty).optional(),
215
- else: import_zod.z.lazy(() => JSONSchemaProperty).optional(),
216
+ if: import_zod.z.lazy(() => JSONSchemaPropertySchema).optional(),
217
+ then: import_zod.z.lazy(() => JSONSchemaPropertySchema).optional(),
218
+ else: import_zod.z.lazy(() => JSONSchemaPropertySchema).optional(),
216
219
  $ref: import_zod.z.string().optional(),
217
220
  definitions: import_zod.z.record(
218
221
  import_zod.z.string(),
219
- import_zod.z.lazy(() => JSONSchemaProperty)
222
+ import_zod.z.lazy(() => JSONSchemaPropertySchema)
220
223
  ).optional(),
221
224
  $defs: import_zod.z.record(
222
225
  import_zod.z.string(),
223
- import_zod.z.lazy(() => JSONSchemaProperty)
226
+ import_zod.z.lazy(() => JSONSchemaPropertySchema)
224
227
  ).optional()
225
228
  });
226
229
  var ParametersSchema = import_zod.z.object({
227
230
  type: import_zod.z.literal("object"),
228
- anyOf: import_zod.z.array(JSONSchemaProperty).optional(),
229
- oneOf: import_zod.z.array(JSONSchemaProperty).optional(),
230
- allOf: import_zod.z.array(JSONSchemaProperty).optional(),
231
- not: JSONSchemaProperty.optional(),
232
- properties: import_zod.z.record(import_zod.z.string(), JSONSchemaProperty),
231
+ anyOf: import_zod.z.array(JSONSchemaPropertySchema).optional(),
232
+ oneOf: import_zod.z.array(JSONSchemaPropertySchema).optional(),
233
+ allOf: import_zod.z.array(JSONSchemaPropertySchema).optional(),
234
+ not: JSONSchemaPropertySchema.optional(),
235
+ properties: import_zod.z.record(import_zod.z.string(), JSONSchemaPropertySchema),
233
236
  required: import_zod.z.array(import_zod.z.string()).optional(),
234
237
  title: import_zod.z.string().optional(),
235
238
  default: import_zod.z.any().optional(),
@@ -2049,6 +2052,286 @@ var CustomTools = class {
2049
2052
  }
2050
2053
  };
2051
2054
 
2055
+ // src/errors/FileModifierErrors.ts
2056
+ var FileModifierErrorCodes = {
2057
+ FILE_UPLOAD_FAILED: "FILE_UPLOAD_FAILED"
2058
+ };
2059
+ var ComposioFileUploadError = class extends ComposioError {
2060
+ constructor(message = "Failed to upload file", options = {}) {
2061
+ super(message, {
2062
+ ...options,
2063
+ code: FileModifierErrorCodes.FILE_UPLOAD_FAILED,
2064
+ possibleFixes: options.possibleFixes || ["Check if the file exists in the location provided"]
2065
+ });
2066
+ this.name = "ComposioFileUploadError";
2067
+ }
2068
+ };
2069
+
2070
+ // src/utils/fileUtils.ts
2071
+ var import_crypto = __toESM(require("crypto"), 1);
2072
+ var import_path = __toESM(require("path"), 1);
2073
+ var readFileContent = async (path) => {
2074
+ try {
2075
+ const content = require("fs").readFileSync(path);
2076
+ return {
2077
+ content: content.toString("base64"),
2078
+ mimeType: "application/octet-stream"
2079
+ };
2080
+ } catch (error) {
2081
+ throw new Error(`Error reading file at ${path}: ${error}`);
2082
+ }
2083
+ };
2084
+ var readFileContentFromURL = async (path) => {
2085
+ const response = await fetch(path);
2086
+ if (!response.ok) {
2087
+ throw new Error(`Failed to fetch file: ${response.statusText}`);
2088
+ }
2089
+ const arrayBuffer = await response.arrayBuffer();
2090
+ const content = Buffer.from(arrayBuffer);
2091
+ const mimeType = response.headers.get("content-type") || "application/octet-stream";
2092
+ return {
2093
+ content: content.toString("base64"),
2094
+ mimeType
2095
+ };
2096
+ };
2097
+ var uploadFileToS3 = async (fileName, content, toolSlug, toolkitSlug, mimeType, client) => {
2098
+ const response = await client.files.createPresignedURL({
2099
+ filename: fileName,
2100
+ mimetype: mimeType,
2101
+ md5: import_crypto.default.createHash("md5").update(Buffer.from(content, "base64")).digest("hex"),
2102
+ tool_slug: toolSlug,
2103
+ toolkit_slug: toolkitSlug
2104
+ });
2105
+ const { key, type } = response;
2106
+ if (type === "new" || type === "update") {
2107
+ logger_default.debug(`Uploading ${key} file to S3: ${key}`);
2108
+ const buffer = Buffer.from(content, "base64");
2109
+ const signedURL = response.type === "update" ? response.update_presigned_url : response.new_presigned_url;
2110
+ const uploadResponse = await fetch(signedURL, {
2111
+ method: "PUT",
2112
+ body: buffer,
2113
+ headers: {
2114
+ "Content-Type": mimeType,
2115
+ "Content-Length": buffer.length.toString()
2116
+ }
2117
+ });
2118
+ if (!uploadResponse.ok) {
2119
+ throw new Error(`Failed to upload file to S3: ${uploadResponse.statusText}`);
2120
+ }
2121
+ } else {
2122
+ logger_default.debug(`File already exists in S3: ${key}`);
2123
+ }
2124
+ return key;
2125
+ };
2126
+ var getFileDataAfterUploadingToS3 = async (path, toolSlug, toolkitSlug, client) => {
2127
+ const isURL = path.startsWith("http");
2128
+ const fileData = isURL ? await readFileContentFromURL(path) : await readFileContent(path);
2129
+ logger_default.debug(`Uploading file to S3: ${path}`);
2130
+ const s3key = await uploadFileToS3(
2131
+ import_path.default.basename(path) || `${toolSlug}_${Date.now()}`,
2132
+ fileData.content,
2133
+ toolSlug,
2134
+ toolkitSlug,
2135
+ fileData.mimeType,
2136
+ client
2137
+ );
2138
+ logger_default.debug(`Done! File uploaded to S3: ${s3key}`, JSON.stringify(fileData, null, 2));
2139
+ return {
2140
+ name: import_path.default.basename(path) || `${toolSlug}_${Date.now()}.${fileData.mimeType.split("/")[1]}`,
2141
+ mimetype: fileData.mimeType,
2142
+ s3key
2143
+ };
2144
+ };
2145
+ var downloadFileFromS3 = async ({
2146
+ toolSlug,
2147
+ s3Url,
2148
+ mimeType
2149
+ }) => {
2150
+ const response = await fetch(s3Url);
2151
+ if (!response.ok) {
2152
+ throw new Error(`Failed to download file: ${response.statusText}`);
2153
+ }
2154
+ const data = await response.arrayBuffer();
2155
+ const extension = mimeType.split("/")[1] || "txt";
2156
+ const fileName = `${toolSlug}_${Date.now()}.${extension}`;
2157
+ const filePath = saveFile(fileName, Buffer.from(data), true);
2158
+ return {
2159
+ name: fileName,
2160
+ mimeType,
2161
+ s3Key: s3Url,
2162
+ filePath
2163
+ };
2164
+ };
2165
+ var getComposioDir = (createDirIfNotExists = false) => {
2166
+ try {
2167
+ const os = require("os");
2168
+ const path = require("path");
2169
+ const fs = require("fs");
2170
+ const composioDir = path.join(os.homedir(), COMPOSIO_DIR);
2171
+ if (createDirIfNotExists && !fs.existsSync(composioDir)) {
2172
+ fs.mkdirSync(composioDir, { recursive: true });
2173
+ }
2174
+ return composioDir;
2175
+ } catch (_error) {
2176
+ return null;
2177
+ }
2178
+ };
2179
+ var getComposioTempFilesDir = (createDirIfNotExists = false) => {
2180
+ try {
2181
+ const os = require("os");
2182
+ const path = require("path");
2183
+ const fs = require("fs");
2184
+ const composioFilesDir = path.join(os.homedir(), COMPOSIO_DIR, TEMP_FILES_DIRECTORY_NAME);
2185
+ if (createDirIfNotExists && !fs.existsSync(composioFilesDir)) {
2186
+ fs.mkdirSync(composioFilesDir, { recursive: true });
2187
+ }
2188
+ return composioFilesDir;
2189
+ } catch (_error) {
2190
+ return null;
2191
+ }
2192
+ };
2193
+ var saveFile = (file, content, isTempFile = false) => {
2194
+ try {
2195
+ const path = require("path");
2196
+ const fs = require("fs");
2197
+ const composioFilesDir = isTempFile ? getComposioTempFilesDir(true) : getComposioDir(true);
2198
+ const filePath = path.join(composioFilesDir, path.basename(file));
2199
+ logger_default.info(`Saving file to: ${filePath}`);
2200
+ if (Buffer.isBuffer(content)) {
2201
+ fs.writeFileSync(filePath, content);
2202
+ } else {
2203
+ fs.writeFileSync(filePath, content, "utf8");
2204
+ }
2205
+ return filePath;
2206
+ } catch (_error) {
2207
+ return null;
2208
+ }
2209
+ };
2210
+
2211
+ // src/utils/modifiers/FileToolModifier.ts
2212
+ var transformProperties = (properties) => {
2213
+ const newProperties = {};
2214
+ for (const [key, property] of Object.entries(properties)) {
2215
+ if (!property.file_uploadable) {
2216
+ newProperties[key] = property;
2217
+ continue;
2218
+ }
2219
+ newProperties[key] = {
2220
+ ...property,
2221
+ format: "path"
2222
+ };
2223
+ }
2224
+ return properties;
2225
+ };
2226
+ var FileToolModifier = class {
2227
+ client;
2228
+ constructor(client) {
2229
+ this.client = client;
2230
+ }
2231
+ /**
2232
+ * Modifies the tool schema to include the file upload URL.
2233
+ *
2234
+ * @description This modifier is used to upload a file to the Composio platform and replace the file path with the file upload URL.
2235
+ *
2236
+ * @param _toolSlug - The slug of the tool that is being executed.
2237
+ * @param _toolkitSlug - The slug of the toolkit that is being executed.
2238
+ * @param schema - The schema of the tool.
2239
+ * @returns The schema with the file upload URL included.
2240
+ */
2241
+ async modifyToolSchema(toolSlug, toolkitSlug, schema) {
2242
+ if (!schema.inputParameters?.properties) {
2243
+ return schema;
2244
+ }
2245
+ const properties = transformProperties(schema.inputParameters.properties);
2246
+ return {
2247
+ ...schema,
2248
+ inputParameters: {
2249
+ ...schema.inputParameters,
2250
+ properties
2251
+ }
2252
+ };
2253
+ }
2254
+ /**
2255
+ * Modifies the input parameters to include the file upload URL.
2256
+ *
2257
+ * @description This modifier is used to upload a file to the Composio platform and replace the file path with the file upload URL.
2258
+ *
2259
+ * @param toolSlug - The slug of the tool that is being executed.
2260
+ * @param toolkitSlug - The slug of the toolkit that is being executed.
2261
+ *
2262
+ */
2263
+ async fileUploadModifier(tool, options) {
2264
+ const { arguments: args } = options.params;
2265
+ if (!args) {
2266
+ return options.params;
2267
+ }
2268
+ for (const key of Object.keys(args)) {
2269
+ const toolProperty = tool.inputParameters?.properties?.[key];
2270
+ if (toolProperty?.file_uploadable) {
2271
+ logger_default.debug(`Processing file upload for: ${key}`);
2272
+ try {
2273
+ const fileData = await getFileDataAfterUploadingToS3(
2274
+ args[key],
2275
+ options.toolSlug,
2276
+ options.toolkitSlug ?? "unknown",
2277
+ this.client
2278
+ );
2279
+ args[key] = fileData;
2280
+ } catch (error) {
2281
+ throw new ComposioFileUploadError(`Failed to upload file: ${key}`, {
2282
+ cause: error
2283
+ });
2284
+ }
2285
+ }
2286
+ }
2287
+ return options.params;
2288
+ }
2289
+ /**
2290
+ * Modifies the result to include the file download URL.
2291
+ *
2292
+ * @description This modifier is used to download a file and
2293
+ *
2294
+ * @param toolSlug - The slug of the tool that is being executed.
2295
+ * @param toolkitSlug - The slug of the toolkit that is being executed.
2296
+ * @param result - The result of the tool execution.
2297
+ * @returns The result with the file download URL included.
2298
+ */
2299
+ async fileDownloadModifier(tool, options) {
2300
+ console.log(JSON.stringify(options.result, null, 2));
2301
+ console.log(JSON.stringify(tool.outputParameters, null, 2));
2302
+ for (const [key, value] of Object.entries(options.result?.data)) {
2303
+ const fileData = value;
2304
+ if (!fileData?.s3url) continue;
2305
+ logger_default.debug(`Downloading file from S3: ${fileData.s3url}`);
2306
+ try {
2307
+ const downloadedFile = await downloadFileFromS3({
2308
+ toolSlug: options.toolSlug,
2309
+ s3Url: fileData.s3url,
2310
+ mimeType: fileData.mimetype || "application/txt"
2311
+ });
2312
+ logger_default.debug(`Downloaded file from S3: ${downloadedFile.filePath}`);
2313
+ options.result.data[key] = {
2314
+ uri: downloadedFile.filePath,
2315
+ file_downloaded: true,
2316
+ s3url: fileData.s3url,
2317
+ mimeType: downloadedFile.mimeType
2318
+ };
2319
+ } catch (error) {
2320
+ logger_default.error(`Failed to download file from S3: ${fileData.s3url}`, {
2321
+ cause: error
2322
+ });
2323
+ options.result.data[key] = {
2324
+ uri: "",
2325
+ file_downloaded: false,
2326
+ s3url: fileData.s3url,
2327
+ mimeType: fileData.mimetype || "application/txt"
2328
+ };
2329
+ }
2330
+ }
2331
+ return options.result;
2332
+ }
2333
+ };
2334
+
2052
2335
  // src/models/Tools.ts
2053
2336
  var Tools = class {
2054
2337
  client;
@@ -2181,6 +2464,85 @@ var Tools = class {
2181
2464
  }
2182
2465
  return null;
2183
2466
  }
2467
+ /**
2468
+ * Applies the default schema modifiers to the tools
2469
+ * @param tools - The tools to apply the default schema modifiers to
2470
+ * @returns The tools with the default schema modifiers applied
2471
+ */
2472
+ async applyDefaultSchemaModifiers(tools) {
2473
+ const fileToolModifier = new FileToolModifier(this.client);
2474
+ return await Promise.all(
2475
+ tools.map(
2476
+ (tool) => fileToolModifier.modifyToolSchema(tool.slug, tool.toolkit?.slug ?? "unknown", tool)
2477
+ )
2478
+ );
2479
+ }
2480
+ /**
2481
+ * Applies the before execute modifiers to the tool execution params
2482
+ * @param options.toolSlug - The slug of the tool
2483
+ * @param options.toolkitSlug - The slug of the toolkit
2484
+ * @param options.params - The params of the tool execution
2485
+ * @param modifier - The modifier to apply
2486
+ * @returns The modified params
2487
+ */
2488
+ async applyBeforeExecuteModifiers(tool, {
2489
+ toolSlug,
2490
+ toolkitSlug,
2491
+ params
2492
+ }, modifier) {
2493
+ const fileToolModifier = new FileToolModifier(this.client);
2494
+ let modifiedParams = params;
2495
+ if (modifier) {
2496
+ if (typeof modifier === "function") {
2497
+ modifiedParams = await modifier({
2498
+ toolSlug,
2499
+ toolkitSlug,
2500
+ params: modifiedParams
2501
+ });
2502
+ } else {
2503
+ throw new ComposioInvalidModifierError("Invalid beforeExecute modifier. Not a function.");
2504
+ }
2505
+ }
2506
+ modifiedParams = await fileToolModifier.fileUploadModifier(tool, {
2507
+ toolSlug,
2508
+ toolkitSlug,
2509
+ params: modifiedParams
2510
+ });
2511
+ return modifiedParams;
2512
+ }
2513
+ /**
2514
+ * Applies the after execute modifiers to the tool execution result
2515
+ * @param options.toolSlug - The slug of the tool
2516
+ * @param options.toolkitSlug - The slug of the toolkit
2517
+ * @param options.result - The result of the tool execution
2518
+ * @param modifier - The modifier to apply
2519
+ * @returns The modified result
2520
+ */
2521
+ async applyAfterExecuteModifiers(tool, {
2522
+ toolSlug,
2523
+ toolkitSlug,
2524
+ result
2525
+ }, modifier) {
2526
+ const fileToolModifier = new FileToolModifier(this.client);
2527
+ let modifiedResult = result;
2528
+ if (modifier) {
2529
+ if (typeof modifier === "function") {
2530
+ modifiedResult = await modifier({
2531
+ toolSlug,
2532
+ toolkitSlug,
2533
+ result: modifiedResult
2534
+ });
2535
+ } else {
2536
+ throw new ComposioInvalidModifierError("Invalid afterExecute modifier. Not a function.");
2537
+ }
2538
+ }
2539
+ modifiedResult = await fileToolModifier.fileDownloadModifier(tool, {
2540
+ toolSlug,
2541
+ toolkitSlug,
2542
+ result: modifiedResult
2543
+ });
2544
+ return modifiedResult;
2545
+ }
2184
2546
  /**
2185
2547
  * Lists all tools available in the Composio SDK including custom tools.
2186
2548
  *
@@ -2240,7 +2602,7 @@ var Tools = class {
2240
2602
  ..."scopes" in queryParams.data ? { scopes: queryParams.data.scopes } : {},
2241
2603
  ..."search" in queryParams.data ? { search: queryParams.data.search } : {}
2242
2604
  };
2243
- logger_default.info(`Fetching tools with filters: ${JSON.stringify(filters, null, 2)}`);
2605
+ logger_default.debug(`Fetching tools with filters: ${JSON.stringify(filters, null, 2)}`);
2244
2606
  const tools = await this.client.tools.list(filters);
2245
2607
  if (!tools) {
2246
2608
  return [];
@@ -2249,11 +2611,18 @@ var Tools = class {
2249
2611
  const customTools = await this.customTools.getCustomTools({
2250
2612
  toolSlugs: "tools" in queryParams.data ? queryParams.data.tools : void 0
2251
2613
  });
2252
- let modifiedTools = [...caseTransformedTools, ...customTools];
2614
+ let modifiedTools = await this.applyDefaultSchemaModifiers([
2615
+ ...caseTransformedTools,
2616
+ ...customTools
2617
+ ]);
2253
2618
  if (modifier) {
2254
2619
  if (typeof modifier === "function") {
2255
2620
  const modifiedPromises = modifiedTools.map(
2256
- (tool) => modifier(tool.slug, tool.toolkit?.slug ?? "unknown", tool)
2621
+ (tool) => modifier({
2622
+ toolSlug: tool.slug,
2623
+ toolkitSlug: tool.toolkit?.slug ?? "unknown",
2624
+ schema: tool
2625
+ })
2257
2626
  );
2258
2627
  modifiedTools = await Promise.all(modifiedPromises);
2259
2628
  } else {
@@ -2289,10 +2658,14 @@ var Tools = class {
2289
2658
  cause: error
2290
2659
  });
2291
2660
  }
2292
- let modifiedTool = this.transformToolCases(tool);
2661
+ let [modifiedTool] = await this.applyDefaultSchemaModifiers([this.transformToolCases(tool)]);
2293
2662
  if (modifier) {
2294
2663
  if (typeof modifier === "function") {
2295
- modifiedTool = await modifier(slug, modifiedTool.toolkit?.slug ?? "unknown", modifiedTool);
2664
+ modifiedTool = await modifier({
2665
+ toolSlug: slug,
2666
+ toolkitSlug: modifiedTool.toolkit?.slug ?? "unknown",
2667
+ schema: modifiedTool
2668
+ });
2296
2669
  } else {
2297
2670
  throw new ComposioInvalidModifierError("Invalid schema modifier. Not a function.");
2298
2671
  }
@@ -2352,7 +2725,11 @@ var Tools = class {
2352
2725
  async handleCustomToolExecution(tool, body, modifiers) {
2353
2726
  if (modifiers?.beforeExecute) {
2354
2727
  if (typeof modifiers.beforeExecute === "function") {
2355
- body = await modifiers.beforeExecute(tool.slug, "unknown", body);
2728
+ body = await modifiers.beforeExecute({
2729
+ toolSlug: tool.slug,
2730
+ toolkitSlug: tool.toolkit?.slug ?? "unknown",
2731
+ params: body
2732
+ });
2356
2733
  } else {
2357
2734
  throw new ComposioInvalidModifierError("Invalid beforeExecute modifier. Not a function.");
2358
2735
  }
@@ -2360,7 +2737,11 @@ var Tools = class {
2360
2737
  let result = await this.customTools.executeCustomTool(tool.slug, body);
2361
2738
  if (modifiers?.afterExecute) {
2362
2739
  if (typeof modifiers.afterExecute === "function") {
2363
- result = await modifiers.afterExecute(tool.slug, "unknown", result);
2740
+ result = await modifiers.afterExecute({
2741
+ toolSlug: tool.slug,
2742
+ toolkitSlug: tool.toolkit?.slug ?? "unknown",
2743
+ result
2744
+ });
2364
2745
  } else {
2365
2746
  throw new ComposioInvalidModifierError("Invalid afterExecute modifier. Not a function.");
2366
2747
  }
@@ -2376,13 +2757,15 @@ var Tools = class {
2376
2757
  * @returns The response from the tool execution
2377
2758
  */
2378
2759
  async handleComposioToolExecution(tool, body, modifiers) {
2379
- if (modifiers?.beforeExecute) {
2380
- if (typeof modifiers.beforeExecute === "function") {
2381
- body = await modifiers.beforeExecute(tool.slug, tool.toolkit?.slug ?? "unknown", body);
2382
- } else {
2383
- throw new ComposioInvalidModifierError("Invalid beforeExecute modifier. Not a function.");
2384
- }
2385
- }
2760
+ body = await this.applyBeforeExecuteModifiers(
2761
+ tool,
2762
+ {
2763
+ toolSlug: tool.slug,
2764
+ toolkitSlug: tool.toolkit?.slug ?? "unknown",
2765
+ params: body
2766
+ },
2767
+ modifiers?.beforeExecute
2768
+ );
2386
2769
  let connectedAccountId = body.connectedAccountId;
2387
2770
  if (!connectedAccountId) {
2388
2771
  connectedAccountId = await this.getConnectedAccountIdForTool(body.userId, tool.slug) || void 0;
@@ -2397,13 +2780,15 @@ var Tools = class {
2397
2780
  text: body.text
2398
2781
  });
2399
2782
  result = this.transformToolExecuteResponse(result);
2400
- if (modifiers?.afterExecute) {
2401
- if (typeof modifiers.afterExecute === "function") {
2402
- result = await modifiers.afterExecute(tool.slug, tool.toolkit?.slug ?? "unknown", result);
2403
- } else {
2404
- throw new ComposioInvalidModifierError("Invalid afterExecute modifier. Not a function.");
2405
- }
2406
- }
2783
+ result = await this.applyAfterExecuteModifiers(
2784
+ tool,
2785
+ {
2786
+ toolSlug: tool.slug,
2787
+ toolkitSlug: tool.toolkit?.slug ?? "unknown",
2788
+ result
2789
+ },
2790
+ modifiers?.afterExecute
2791
+ );
2407
2792
  return result;
2408
2793
  }
2409
2794
  /**
@@ -5082,31 +5467,37 @@ var MCP = class {
5082
5467
  return transformMcpGenerateUrlResponse(urlResponse);
5083
5468
  }
5084
5469
  /**
5085
- * Transform MCP URL response into the appropriate format.
5086
- * If the provider has a custom transform method, use it.
5087
- * Otherwise, use the default transformation.
5088
- *
5089
- * @param data - The MCP URL response data (in camelCase)
5090
- * @param serverName - Name of the MCP server
5091
- * @param connectedAccountIds - Optional array of connected account IDs
5092
- * @param userIds - Optional array of user IDs
5093
- * @param toolkits - Optional array of toolkit names
5094
- * @returns Transformed response in appropriate format
5095
- */
5470
+ * Transform MCP URL response into the appropriate format.
5471
+ * If the provider has a custom transform method, use it.
5472
+ * Otherwise, use the default transformation.
5473
+ *
5474
+ * @param data - The MCP URL response data (in camelCase)
5475
+ * @param serverName - Name of the MCP server
5476
+
5477
+ * @returns Transformed response in appropriate format
5478
+ */
5096
5479
  wrapMcpServerResponse(data, serverName, connectedAccountIds, userIds, toolkits) {
5097
5480
  if (this.provider && typeof this.provider.wrapMcpServerResponse === "function") {
5098
- const snakeCaseData = {
5099
- mcp_url: data.mcpUrl,
5100
- ...data.connectedAccountUrls && { connected_account_urls: data.connectedAccountUrls },
5101
- ...data.userIdsUrl && { user_ids_url: data.userIdsUrl }
5102
- };
5103
- const transformed = this.provider.wrapMcpServerResponse(
5104
- snakeCaseData,
5105
- serverName,
5106
- connectedAccountIds,
5107
- userIds,
5108
- toolkits
5109
- );
5481
+ let snakeCaseData;
5482
+ if (data.connectedAccountUrls?.length) {
5483
+ snakeCaseData = data.connectedAccountUrls.map((url, index) => ({
5484
+ name: serverName + "-" + connectedAccountIds?.[index],
5485
+ url
5486
+ }));
5487
+ } else if (data.userIdsUrl?.length) {
5488
+ snakeCaseData = data.userIdsUrl.map((url, index) => ({
5489
+ name: serverName + "-" + userIds?.[index],
5490
+ url
5491
+ }));
5492
+ } else {
5493
+ snakeCaseData = [
5494
+ {
5495
+ name: serverName,
5496
+ url: data.mcpUrl
5497
+ }
5498
+ ];
5499
+ }
5500
+ const transformed = this.provider.wrapMcpServerResponse(snakeCaseData);
5110
5501
  return transformed;
5111
5502
  }
5112
5503
  if (connectedAccountIds?.length && data.connectedAccountUrls) {
@@ -5261,30 +5652,13 @@ var OpenAIProvider = class extends BaseNonAgenticProvider {
5261
5652
  * OpenAI uses the standard format by default.
5262
5653
  *
5263
5654
  * @param data - The MCP URL response data
5264
- * @param serverName - Name of the MCP server
5265
- * @param connectedAccountIds - Optional array of connected account IDs
5266
- * @param userIds - Optional array of user IDs
5267
- * @param toolkits - Optional array of toolkit names
5268
5655
  * @returns Standard MCP server response format
5269
5656
  */
5270
- wrapMcpServerResponse(data, serverName, connectedAccountIds, userIds, toolkits) {
5271
- if (connectedAccountIds?.length && data.connected_account_urls) {
5272
- return data.connected_account_urls.map((url, index) => ({
5273
- url: new URL(url),
5274
- name: `${serverName}-${connectedAccountIds[index]}`,
5275
- toolkit: toolkits?.[index]
5276
- }));
5277
- } else if (userIds?.length && data.user_ids_url) {
5278
- return data.user_ids_url.map((url, index) => ({
5279
- url: new URL(url),
5280
- name: `${serverName}-${userIds[index]}`,
5281
- toolkit: toolkits?.[index]
5282
- }));
5283
- }
5284
- return {
5285
- url: new URL(data.mcp_url),
5286
- name: serverName
5287
- };
5657
+ wrapMcpServerResponse(data) {
5658
+ return data.map((item) => ({
5659
+ url: new URL(item.url),
5660
+ name: item.name
5661
+ }));
5288
5662
  }
5289
5663
  /**
5290
5664
  * Wraps a Composio tool in the OpenAI function calling format.
@@ -5675,7 +6049,7 @@ var OpenAIProvider = class extends BaseNonAgenticProvider {
5675
6049
  };
5676
6050
 
5677
6051
  // package.json
5678
- var version = "0.1.27";
6052
+ var version = "0.1.29";
5679
6053
 
5680
6054
  // src/composio.ts
5681
6055
  var Composio = class _Composio {
@@ -6081,6 +6455,7 @@ var AuthScheme = class {
6081
6455
  GenerateURLResponseCamelCaseSchema,
6082
6456
  GenerateURLResponseSchema,
6083
6457
  IncomingTriggerPayloadSchema,
6458
+ JSONSchemaPropertySchema,
6084
6459
  JsonSchemaToZodError,
6085
6460
  MCP,
6086
6461
  MCPAuthOptionsSchema,