@composio/core 0.1.28 → 0.1.30

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.js CHANGED
@@ -29,19 +29,21 @@ var JSONSchemaType = z.enum([
29
29
  "array",
30
30
  "null"
31
31
  ]);
32
- var JSONSchemaProperty = z.object({
32
+ var JSONSchemaPropertySchema = z.object({
33
33
  type: z.union([JSONSchemaType, z.array(JSONSchemaType)]).optional(),
34
34
  description: z.string().optional(),
35
- anyOf: z.lazy(() => z.array(JSONSchemaProperty)).optional(),
36
- oneOf: z.lazy(() => z.array(JSONSchemaProperty)).optional(),
37
- allOf: z.lazy(() => z.array(JSONSchemaProperty)).optional(),
38
- not: z.lazy(() => JSONSchemaProperty).optional(),
35
+ anyOf: z.lazy(() => z.array(JSONSchemaPropertySchema)).optional(),
36
+ oneOf: z.lazy(() => z.array(JSONSchemaPropertySchema)).optional(),
37
+ allOf: z.lazy(() => z.array(JSONSchemaPropertySchema)).optional(),
38
+ not: z.lazy(() => JSONSchemaPropertySchema).optional(),
39
39
  title: z.string().optional(),
40
40
  default: z.any().optional(),
41
41
  nullable: z.boolean().optional(),
42
- properties: z.lazy(() => z.record(z.string(), JSONSchemaProperty)).optional(),
42
+ properties: z.lazy(() => z.record(z.string(), JSONSchemaPropertySchema)).optional(),
43
43
  required: z.array(z.string()).optional(),
44
- items: z.lazy(() => z.union([JSONSchemaProperty, z.array(JSONSchemaProperty)])).optional(),
44
+ file_uploadable: z.boolean().optional(),
45
+ file_downloadable: z.boolean().optional(),
46
+ items: z.lazy(() => z.union([JSONSchemaPropertySchema, z.array(JSONSchemaPropertySchema)])).optional(),
45
47
  enum: z.array(z.any()).optional(),
46
48
  const: z.any().optional(),
47
49
  minimum: z.number().optional(),
@@ -58,31 +60,31 @@ var JSONSchemaProperty = z.object({
58
60
  uniqueItems: z.boolean().optional(),
59
61
  minProperties: z.number().optional(),
60
62
  maxProperties: z.number().optional(),
61
- patternProperties: z.lazy(() => z.record(z.string(), JSONSchemaProperty)).optional(),
62
- additionalProperties: z.union([z.boolean(), z.lazy(() => JSONSchemaProperty)]).optional(),
63
+ patternProperties: z.lazy(() => z.record(z.string(), JSONSchemaPropertySchema)).optional(),
64
+ additionalProperties: z.union([z.boolean(), z.lazy(() => JSONSchemaPropertySchema)]).optional(),
63
65
  examples: z.array(z.any()).optional(),
64
66
  readOnly: z.boolean().optional(),
65
67
  writeOnly: z.boolean().optional(),
66
- if: z.lazy(() => JSONSchemaProperty).optional(),
67
- then: z.lazy(() => JSONSchemaProperty).optional(),
68
- else: z.lazy(() => JSONSchemaProperty).optional(),
68
+ if: z.lazy(() => JSONSchemaPropertySchema).optional(),
69
+ then: z.lazy(() => JSONSchemaPropertySchema).optional(),
70
+ else: z.lazy(() => JSONSchemaPropertySchema).optional(),
69
71
  $ref: z.string().optional(),
70
72
  definitions: z.record(
71
73
  z.string(),
72
- z.lazy(() => JSONSchemaProperty)
74
+ z.lazy(() => JSONSchemaPropertySchema)
73
75
  ).optional(),
74
76
  $defs: z.record(
75
77
  z.string(),
76
- z.lazy(() => JSONSchemaProperty)
78
+ z.lazy(() => JSONSchemaPropertySchema)
77
79
  ).optional()
78
80
  });
79
81
  var ParametersSchema = z.object({
80
82
  type: z.literal("object"),
81
- anyOf: z.array(JSONSchemaProperty).optional(),
82
- oneOf: z.array(JSONSchemaProperty).optional(),
83
- allOf: z.array(JSONSchemaProperty).optional(),
84
- not: JSONSchemaProperty.optional(),
85
- properties: z.record(z.string(), JSONSchemaProperty),
83
+ anyOf: z.array(JSONSchemaPropertySchema).optional(),
84
+ oneOf: z.array(JSONSchemaPropertySchema).optional(),
85
+ allOf: z.array(JSONSchemaPropertySchema).optional(),
86
+ not: JSONSchemaPropertySchema.optional(),
87
+ properties: z.record(z.string(), JSONSchemaPropertySchema),
86
88
  required: z.array(z.string()).optional(),
87
89
  title: z.string().optional(),
88
90
  default: z.any().optional(),
@@ -1902,12 +1904,296 @@ var CustomTools = class {
1902
1904
  }
1903
1905
  };
1904
1906
 
1907
+ // src/errors/FileModifierErrors.ts
1908
+ var FileModifierErrorCodes = {
1909
+ FILE_UPLOAD_FAILED: "FILE_UPLOAD_FAILED"
1910
+ };
1911
+ var ComposioFileUploadError = class extends ComposioError {
1912
+ constructor(message = "Failed to upload file", options = {}) {
1913
+ super(message, {
1914
+ ...options,
1915
+ code: FileModifierErrorCodes.FILE_UPLOAD_FAILED,
1916
+ possibleFixes: options.possibleFixes || ["Check if the file exists in the location provided"]
1917
+ });
1918
+ this.name = "ComposioFileUploadError";
1919
+ }
1920
+ };
1921
+
1922
+ // src/utils/fileUtils.ts
1923
+ import crypto from "crypto";
1924
+ import pathModule from "path";
1925
+ var readFileContent = async (path) => {
1926
+ try {
1927
+ const content = __require("fs").readFileSync(path);
1928
+ return {
1929
+ content: content.toString("base64"),
1930
+ mimeType: "application/octet-stream"
1931
+ };
1932
+ } catch (error) {
1933
+ throw new Error(`Error reading file at ${path}: ${error}`);
1934
+ }
1935
+ };
1936
+ var readFileContentFromURL = async (path) => {
1937
+ const response = await fetch(path);
1938
+ if (!response.ok) {
1939
+ throw new Error(`Failed to fetch file: ${response.statusText}`);
1940
+ }
1941
+ const arrayBuffer = await response.arrayBuffer();
1942
+ const content = Buffer.from(arrayBuffer);
1943
+ const mimeType = response.headers.get("content-type") || "application/octet-stream";
1944
+ return {
1945
+ content: content.toString("base64"),
1946
+ mimeType
1947
+ };
1948
+ };
1949
+ var uploadFileToS3 = async (fileName, content, toolSlug, toolkitSlug, mimeType, client) => {
1950
+ const response = await client.files.createPresignedURL({
1951
+ filename: fileName,
1952
+ mimetype: mimeType,
1953
+ md5: crypto.createHash("md5").update(Buffer.from(content, "base64")).digest("hex"),
1954
+ tool_slug: toolSlug,
1955
+ toolkit_slug: toolkitSlug
1956
+ });
1957
+ const { key, type } = response;
1958
+ if (type === "new" || type === "update") {
1959
+ logger_default.debug(`Uploading ${key} file to S3: ${key}`);
1960
+ const buffer = Buffer.from(content, "base64");
1961
+ const signedURL = response.type === "update" ? response.update_presigned_url : response.new_presigned_url;
1962
+ const uploadResponse = await fetch(signedURL, {
1963
+ method: "PUT",
1964
+ body: buffer,
1965
+ headers: {
1966
+ "Content-Type": mimeType,
1967
+ "Content-Length": buffer.length.toString()
1968
+ }
1969
+ });
1970
+ if (!uploadResponse.ok) {
1971
+ throw new Error(`Failed to upload file to S3: ${uploadResponse.statusText}`);
1972
+ }
1973
+ } else {
1974
+ logger_default.debug(`File already exists in S3: ${key}`);
1975
+ }
1976
+ return key;
1977
+ };
1978
+ var getFileDataAfterUploadingToS3 = async ({
1979
+ path,
1980
+ toolSlug,
1981
+ toolkitSlug,
1982
+ client
1983
+ }) => {
1984
+ const isURL = path.startsWith("http");
1985
+ const fileData = isURL ? await readFileContentFromURL(path) : await readFileContent(path);
1986
+ logger_default.debug(`Uploading file to S3: ${path}`);
1987
+ const s3key = await uploadFileToS3(
1988
+ pathModule.basename(path) || `${toolSlug}_${Date.now()}`,
1989
+ fileData.content,
1990
+ toolSlug,
1991
+ toolkitSlug,
1992
+ fileData.mimeType,
1993
+ client
1994
+ );
1995
+ logger_default.debug(`Done! File uploaded to S3: ${s3key}`, JSON.stringify(fileData, null, 2));
1996
+ return {
1997
+ name: pathModule.basename(path) || `${toolSlug}_${Date.now()}.${fileData.mimeType.split("/")[1]}`,
1998
+ mimetype: fileData.mimeType,
1999
+ s3key
2000
+ };
2001
+ };
2002
+ var downloadFileFromS3 = async ({
2003
+ toolSlug,
2004
+ s3Url,
2005
+ mimeType
2006
+ }) => {
2007
+ const response = await fetch(s3Url);
2008
+ if (!response.ok) {
2009
+ throw new Error(`Failed to download file: ${response.statusText}`);
2010
+ }
2011
+ const data = await response.arrayBuffer();
2012
+ const extension = mimeType.split("/")[1] || "txt";
2013
+ const fileName = `${toolSlug}_${Date.now()}.${extension}`;
2014
+ const filePath = saveFile(fileName, Buffer.from(data), true);
2015
+ return {
2016
+ name: fileName,
2017
+ mimeType,
2018
+ s3Url,
2019
+ filePath
2020
+ };
2021
+ };
2022
+ var getComposioDir = (createDirIfNotExists = false) => {
2023
+ try {
2024
+ const os = __require("os");
2025
+ const path = __require("path");
2026
+ const fs = __require("fs");
2027
+ const composioDir = path.join(os.homedir(), COMPOSIO_DIR);
2028
+ if (createDirIfNotExists && !fs.existsSync(composioDir)) {
2029
+ fs.mkdirSync(composioDir, { recursive: true });
2030
+ }
2031
+ return composioDir;
2032
+ } catch (_error) {
2033
+ return null;
2034
+ }
2035
+ };
2036
+ var getComposioTempFilesDir = (createDirIfNotExists = false) => {
2037
+ try {
2038
+ const os = __require("os");
2039
+ const path = __require("path");
2040
+ const fs = __require("fs");
2041
+ const composioFilesDir = path.join(os.homedir(), COMPOSIO_DIR, TEMP_FILES_DIRECTORY_NAME);
2042
+ if (createDirIfNotExists && !fs.existsSync(composioFilesDir)) {
2043
+ fs.mkdirSync(composioFilesDir, { recursive: true });
2044
+ }
2045
+ return composioFilesDir;
2046
+ } catch (_error) {
2047
+ return null;
2048
+ }
2049
+ };
2050
+ var saveFile = (file, content, isTempFile = false) => {
2051
+ try {
2052
+ const path = __require("path");
2053
+ const fs = __require("fs");
2054
+ const composioFilesDir = isTempFile ? getComposioTempFilesDir(true) : getComposioDir(true);
2055
+ const filePath = path.join(composioFilesDir, path.basename(file));
2056
+ logger_default.info(`Saving file to: ${filePath}`);
2057
+ if (Buffer.isBuffer(content)) {
2058
+ fs.writeFileSync(filePath, content);
2059
+ } else {
2060
+ fs.writeFileSync(filePath, content, "utf8");
2061
+ }
2062
+ return filePath;
2063
+ } catch (_error) {
2064
+ return null;
2065
+ }
2066
+ };
2067
+
2068
+ // src/utils/modifiers/FileToolModifier.ts
2069
+ var transformProperties = (properties) => {
2070
+ const newProperties = {};
2071
+ for (const [key, property] of Object.entries(properties)) {
2072
+ if (!property.file_uploadable) {
2073
+ newProperties[key] = property;
2074
+ continue;
2075
+ }
2076
+ newProperties[key] = {
2077
+ ...property,
2078
+ format: "path"
2079
+ };
2080
+ }
2081
+ return newProperties;
2082
+ };
2083
+ var FileToolModifier = class {
2084
+ client;
2085
+ constructor(client) {
2086
+ this.client = client;
2087
+ }
2088
+ /**
2089
+ * Modifies the tool schema to include the file upload URL.
2090
+ *
2091
+ * @description This modifier is used to upload a file to the Composio platform and replace the file path with the file upload URL.
2092
+ *
2093
+ * @param _toolSlug - The slug of the tool that is being executed.
2094
+ * @param _toolkitSlug - The slug of the toolkit that is being executed.
2095
+ * @param schema - The schema of the tool.
2096
+ * @returns The schema with the file upload URL included.
2097
+ */
2098
+ async modifyToolSchema(toolSlug, toolkitSlug, schema) {
2099
+ if (!schema.inputParameters?.properties) {
2100
+ return schema;
2101
+ }
2102
+ const properties = transformProperties(schema.inputParameters.properties);
2103
+ return {
2104
+ ...schema,
2105
+ inputParameters: {
2106
+ ...schema.inputParameters,
2107
+ properties
2108
+ }
2109
+ };
2110
+ }
2111
+ /**
2112
+ * Modifies the input parameters to include the file upload URL.
2113
+ *
2114
+ * @description This modifier is used to upload a file to the Composio platform and replace the file path with the file upload URL.
2115
+ *
2116
+ * @param toolSlug - The slug of the tool that is being executed.
2117
+ * @param toolkitSlug - The slug of the toolkit that is being executed.
2118
+ *
2119
+ */
2120
+ async fileUploadModifier(tool, options) {
2121
+ const { arguments: args } = options.params;
2122
+ if (!args) {
2123
+ return options.params;
2124
+ }
2125
+ for (const key of Object.keys(args)) {
2126
+ const toolProperty = tool.inputParameters?.properties?.[key];
2127
+ if (toolProperty?.file_uploadable) {
2128
+ logger_default.debug(`Processing file upload for: ${key}`);
2129
+ try {
2130
+ const fileData = await getFileDataAfterUploadingToS3({
2131
+ path: args[key],
2132
+ toolSlug: options.toolSlug,
2133
+ toolkitSlug: options.toolkitSlug ?? "unknown",
2134
+ client: this.client
2135
+ });
2136
+ args[key] = fileData;
2137
+ } catch (error) {
2138
+ throw new ComposioFileUploadError(`Failed to upload file: ${key}`, {
2139
+ cause: error
2140
+ });
2141
+ }
2142
+ }
2143
+ }
2144
+ return options.params;
2145
+ }
2146
+ /**
2147
+ * Modifies the result to include the file download URL.
2148
+ *
2149
+ * @description This modifier is used to download a file and
2150
+ *
2151
+ * @param toolSlug - The slug of the tool that is being executed.
2152
+ * @param toolkitSlug - The slug of the toolkit that is being executed.
2153
+ * @param result - The result of the tool execution.
2154
+ * @returns The result with the file download URL included.
2155
+ */
2156
+ async fileDownloadModifier(tool, options) {
2157
+ for (const [key, value] of Object.entries(options.result?.data)) {
2158
+ const fileData = value;
2159
+ if (!fileData?.s3url) continue;
2160
+ logger_default.debug(`Downloading file from S3: ${fileData.s3url}`);
2161
+ try {
2162
+ const downloadedFile = await downloadFileFromS3({
2163
+ toolSlug: options.toolSlug,
2164
+ s3Url: fileData.s3url,
2165
+ mimeType: fileData.mimetype || "application/txt"
2166
+ });
2167
+ logger_default.debug(`Downloaded file from S3: ${downloadedFile.filePath}`);
2168
+ options.result.data[key] = {
2169
+ uri: downloadedFile.filePath,
2170
+ file_downloaded: true,
2171
+ s3url: fileData.s3url,
2172
+ mimeType: downloadedFile.mimeType
2173
+ };
2174
+ } catch (error) {
2175
+ logger_default.error(`Failed to download file from S3: ${fileData.s3url}`, {
2176
+ cause: error
2177
+ });
2178
+ options.result.data[key] = {
2179
+ uri: "",
2180
+ file_downloaded: false,
2181
+ s3url: fileData.s3url,
2182
+ mimeType: fileData.mimetype || "application/txt"
2183
+ };
2184
+ }
2185
+ }
2186
+ return options.result;
2187
+ }
2188
+ };
2189
+
1905
2190
  // src/models/Tools.ts
1906
2191
  var Tools = class {
1907
2192
  client;
1908
2193
  customTools;
1909
2194
  provider;
1910
- constructor(client, provider) {
2195
+ autoUploadDownloadFiles;
2196
+ constructor(client, provider, options) {
1911
2197
  if (!client) {
1912
2198
  throw new Error("ComposioClient is required");
1913
2199
  }
@@ -1917,6 +2203,7 @@ var Tools = class {
1917
2203
  this.client = client;
1918
2204
  this.customTools = new CustomTools(client);
1919
2205
  this.provider = provider;
2206
+ this.autoUploadDownloadFiles = options?.autoUploadDownloadFiles ?? true;
1920
2207
  this.execute = this.execute.bind(this);
1921
2208
  this.provider._setExecuteToolFn(this.execute);
1922
2209
  this.getRawComposioToolBySlug = this.getRawComposioToolBySlug.bind(this);
@@ -2034,6 +2321,93 @@ var Tools = class {
2034
2321
  }
2035
2322
  return null;
2036
2323
  }
2324
+ /**
2325
+ * Applies the default schema modifiers to the tools
2326
+ * @param tools - The tools to apply the default schema modifiers to
2327
+ * @returns The tools with the default schema modifiers applied
2328
+ */
2329
+ async applyDefaultSchemaModifiers(tools) {
2330
+ if (this.autoUploadDownloadFiles) {
2331
+ const fileToolModifier = new FileToolModifier(this.client);
2332
+ return await Promise.all(
2333
+ tools.map(
2334
+ (tool) => fileToolModifier.modifyToolSchema(tool.slug, tool.toolkit?.slug ?? "unknown", tool)
2335
+ )
2336
+ );
2337
+ } else {
2338
+ return tools;
2339
+ }
2340
+ }
2341
+ /**
2342
+ * Applies the before execute modifiers to the tool execution params
2343
+ * @param options.toolSlug - The slug of the tool
2344
+ * @param options.toolkitSlug - The slug of the toolkit
2345
+ * @param options.params - The params of the tool execution
2346
+ * @param modifier - The modifier to apply
2347
+ * @returns The modified params
2348
+ */
2349
+ async applyBeforeExecuteModifiers(tool, {
2350
+ toolSlug,
2351
+ toolkitSlug,
2352
+ params
2353
+ }, modifier) {
2354
+ let modifiedParams = params;
2355
+ if (this.autoUploadDownloadFiles) {
2356
+ const fileToolModifier = new FileToolModifier(this.client);
2357
+ modifiedParams = await fileToolModifier.fileUploadModifier(tool, {
2358
+ toolSlug,
2359
+ toolkitSlug,
2360
+ params: modifiedParams
2361
+ });
2362
+ }
2363
+ if (modifier) {
2364
+ if (typeof modifier === "function") {
2365
+ modifiedParams = await modifier({
2366
+ toolSlug,
2367
+ toolkitSlug,
2368
+ params: modifiedParams
2369
+ });
2370
+ } else {
2371
+ throw new ComposioInvalidModifierError("Invalid beforeExecute modifier. Not a function.");
2372
+ }
2373
+ }
2374
+ return modifiedParams;
2375
+ }
2376
+ /**
2377
+ * Applies the after execute modifiers to the tool execution result
2378
+ * @param options.toolSlug - The slug of the tool
2379
+ * @param options.toolkitSlug - The slug of the toolkit
2380
+ * @param options.result - The result of the tool execution
2381
+ * @param modifier - The modifier to apply
2382
+ * @returns The modified result
2383
+ */
2384
+ async applyAfterExecuteModifiers(tool, {
2385
+ toolSlug,
2386
+ toolkitSlug,
2387
+ result
2388
+ }, modifier) {
2389
+ let modifiedResult = result;
2390
+ if (this.autoUploadDownloadFiles) {
2391
+ const fileToolModifier = new FileToolModifier(this.client);
2392
+ modifiedResult = await fileToolModifier.fileDownloadModifier(tool, {
2393
+ toolSlug,
2394
+ toolkitSlug,
2395
+ result: modifiedResult
2396
+ });
2397
+ }
2398
+ if (modifier) {
2399
+ if (typeof modifier === "function") {
2400
+ modifiedResult = await modifier({
2401
+ toolSlug,
2402
+ toolkitSlug,
2403
+ result: modifiedResult
2404
+ });
2405
+ } else {
2406
+ throw new ComposioInvalidModifierError("Invalid afterExecute modifier. Not a function.");
2407
+ }
2408
+ }
2409
+ return modifiedResult;
2410
+ }
2037
2411
  /**
2038
2412
  * Lists all tools available in the Composio SDK including custom tools.
2039
2413
  *
@@ -2102,11 +2476,18 @@ var Tools = class {
2102
2476
  const customTools = await this.customTools.getCustomTools({
2103
2477
  toolSlugs: "tools" in queryParams.data ? queryParams.data.tools : void 0
2104
2478
  });
2105
- let modifiedTools = [...caseTransformedTools, ...customTools];
2479
+ let modifiedTools = await this.applyDefaultSchemaModifiers([
2480
+ ...caseTransformedTools,
2481
+ ...customTools
2482
+ ]);
2106
2483
  if (modifier) {
2107
2484
  if (typeof modifier === "function") {
2108
2485
  const modifiedPromises = modifiedTools.map(
2109
- (tool) => modifier(tool.slug, tool.toolkit?.slug ?? "unknown", tool)
2486
+ (tool) => modifier({
2487
+ toolSlug: tool.slug,
2488
+ toolkitSlug: tool.toolkit?.slug ?? "unknown",
2489
+ schema: tool
2490
+ })
2110
2491
  );
2111
2492
  modifiedTools = await Promise.all(modifiedPromises);
2112
2493
  } else {
@@ -2142,10 +2523,14 @@ var Tools = class {
2142
2523
  cause: error
2143
2524
  });
2144
2525
  }
2145
- let modifiedTool = this.transformToolCases(tool);
2526
+ let [modifiedTool] = await this.applyDefaultSchemaModifiers([this.transformToolCases(tool)]);
2146
2527
  if (modifier) {
2147
2528
  if (typeof modifier === "function") {
2148
- modifiedTool = await modifier(slug, modifiedTool.toolkit?.slug ?? "unknown", modifiedTool);
2529
+ modifiedTool = await modifier({
2530
+ toolSlug: slug,
2531
+ toolkitSlug: modifiedTool.toolkit?.slug ?? "unknown",
2532
+ schema: modifiedTool
2533
+ });
2149
2534
  } else {
2150
2535
  throw new ComposioInvalidModifierError("Invalid schema modifier. Not a function.");
2151
2536
  }
@@ -2205,7 +2590,11 @@ var Tools = class {
2205
2590
  async handleCustomToolExecution(tool, body, modifiers) {
2206
2591
  if (modifiers?.beforeExecute) {
2207
2592
  if (typeof modifiers.beforeExecute === "function") {
2208
- body = await modifiers.beforeExecute(tool.slug, "unknown", body);
2593
+ body = await modifiers.beforeExecute({
2594
+ toolSlug: tool.slug,
2595
+ toolkitSlug: tool.toolkit?.slug ?? "unknown",
2596
+ params: body
2597
+ });
2209
2598
  } else {
2210
2599
  throw new ComposioInvalidModifierError("Invalid beforeExecute modifier. Not a function.");
2211
2600
  }
@@ -2213,7 +2602,11 @@ var Tools = class {
2213
2602
  let result = await this.customTools.executeCustomTool(tool.slug, body);
2214
2603
  if (modifiers?.afterExecute) {
2215
2604
  if (typeof modifiers.afterExecute === "function") {
2216
- result = await modifiers.afterExecute(tool.slug, "unknown", result);
2605
+ result = await modifiers.afterExecute({
2606
+ toolSlug: tool.slug,
2607
+ toolkitSlug: tool.toolkit?.slug ?? "unknown",
2608
+ result
2609
+ });
2217
2610
  } else {
2218
2611
  throw new ComposioInvalidModifierError("Invalid afterExecute modifier. Not a function.");
2219
2612
  }
@@ -2229,13 +2622,15 @@ var Tools = class {
2229
2622
  * @returns The response from the tool execution
2230
2623
  */
2231
2624
  async handleComposioToolExecution(tool, body, modifiers) {
2232
- if (modifiers?.beforeExecute) {
2233
- if (typeof modifiers.beforeExecute === "function") {
2234
- body = await modifiers.beforeExecute(tool.slug, tool.toolkit?.slug ?? "unknown", body);
2235
- } else {
2236
- throw new ComposioInvalidModifierError("Invalid beforeExecute modifier. Not a function.");
2237
- }
2238
- }
2625
+ body = await this.applyBeforeExecuteModifiers(
2626
+ tool,
2627
+ {
2628
+ toolSlug: tool.slug,
2629
+ toolkitSlug: tool.toolkit?.slug ?? "unknown",
2630
+ params: body
2631
+ },
2632
+ modifiers?.beforeExecute
2633
+ );
2239
2634
  let connectedAccountId = body.connectedAccountId;
2240
2635
  if (!connectedAccountId) {
2241
2636
  connectedAccountId = await this.getConnectedAccountIdForTool(body.userId, tool.slug) || void 0;
@@ -2250,13 +2645,15 @@ var Tools = class {
2250
2645
  text: body.text
2251
2646
  });
2252
2647
  result = this.transformToolExecuteResponse(result);
2253
- if (modifiers?.afterExecute) {
2254
- if (typeof modifiers.afterExecute === "function") {
2255
- result = await modifiers.afterExecute(tool.slug, tool.toolkit?.slug ?? "unknown", result);
2256
- } else {
2257
- throw new ComposioInvalidModifierError("Invalid afterExecute modifier. Not a function.");
2258
- }
2259
- }
2648
+ result = await this.applyAfterExecuteModifiers(
2649
+ tool,
2650
+ {
2651
+ toolSlug: tool.slug,
2652
+ toolkitSlug: tool.toolkit?.slug ?? "unknown",
2653
+ result
2654
+ },
2655
+ modifiers?.afterExecute
2656
+ );
2260
2657
  return result;
2261
2658
  }
2262
2659
  /**
@@ -5517,7 +5914,48 @@ var OpenAIProvider = class extends BaseNonAgenticProvider {
5517
5914
  };
5518
5915
 
5519
5916
  // package.json
5520
- var version = "0.1.28";
5917
+ var version = "0.1.30";
5918
+
5919
+ // src/models/Files.ts
5920
+ var Files = class {
5921
+ constructor(client) {
5922
+ this.client = client;
5923
+ telemetry.instrument(this);
5924
+ }
5925
+ /**
5926
+ * Upload a file to S3 and return the file data.
5927
+ * @param filePath - The path to the file to upload or a URL of the file to upload.
5928
+ * @param toolSlug - The slug of the tool that is uploading the file.
5929
+ * @param toolkitSlug - The slug of the toolkit that is uploading the file.
5930
+ * @returns The file data.
5931
+ */
5932
+ async upload({
5933
+ filePath,
5934
+ toolSlug,
5935
+ toolkitSlug
5936
+ }) {
5937
+ const fileData = await getFileDataAfterUploadingToS3({
5938
+ path: filePath,
5939
+ toolSlug,
5940
+ toolkitSlug,
5941
+ client: this.client
5942
+ });
5943
+ return fileData;
5944
+ }
5945
+ /**
5946
+ * Download a file from S3 and return the file data.
5947
+ * @param s3key - The S3 key of the file to download.
5948
+ * @returns The file data.
5949
+ */
5950
+ async download({
5951
+ toolSlug,
5952
+ s3Url,
5953
+ mimeType
5954
+ }) {
5955
+ const fileDownloadData = await downloadFileFromS3({ toolSlug, s3Url, mimeType });
5956
+ return fileDownloadData;
5957
+ }
5958
+ };
5521
5959
 
5522
5960
  // src/composio.ts
5523
5961
  var Composio = class _Composio {
@@ -5538,6 +5976,7 @@ var Composio = class _Composio {
5538
5976
  toolkits;
5539
5977
  triggers;
5540
5978
  provider;
5979
+ files;
5541
5980
  // auth configs
5542
5981
  authConfigs;
5543
5982
  // connected accounts
@@ -5553,7 +5992,6 @@ var Composio = class _Composio {
5553
5992
  * @param {string} [config.apiKey] - The API key for authenticating with the Composio API
5554
5993
  * @param {string} [config.baseURL] - The base URL for the Composio API (defaults to production URL)
5555
5994
  * @param {boolean} [config.allowTracking=true] - Whether to allow anonymous usage analytics
5556
- * @param {boolean} [config.allowTracing=true] - Whether to allow request tracing for debugging
5557
5995
  * @param {TProvider} [config.provider] - The provider to use for this Composio instance (defaults to OpenAIProvider)
5558
5996
  *
5559
5997
  * @example
@@ -5590,15 +6028,17 @@ var Composio = class _Composio {
5590
6028
  });
5591
6029
  this.config = {
5592
6030
  ...config,
5593
- allowTracking: config?.allowTracking ?? true,
5594
- allowTracing: config?.allowTracing ?? true
6031
+ allowTracking: config?.allowTracking ?? true
5595
6032
  };
5596
6033
  this.provider = config?.provider ?? new OpenAIProvider();
5597
- this.tools = new Tools(this.client, this.provider);
6034
+ this.tools = new Tools(this.client, this.provider, {
6035
+ autoUploadDownloadFiles: config?.autoUploadDownloadFiles ?? true
6036
+ });
5598
6037
  this.mcp = new MCP(this.client, this.provider);
5599
6038
  this.toolkits = new Toolkits(this.client);
5600
6039
  this.triggers = new Triggers(this.client);
5601
6040
  this.authConfigs = new AuthConfigs(this.client);
6041
+ this.files = new Files(this.client);
5602
6042
  this.connectedAccounts = new ConnectedAccounts(this.client);
5603
6043
  if (this.config.allowTracking) {
5604
6044
  telemetry.setup({
@@ -5608,11 +6048,7 @@ var Composio = class _Composio {
5608
6048
  version,
5609
6049
  isBrowser: typeof window !== "undefined",
5610
6050
  provider: this.provider?.name ?? "openai",
5611
- host: this.config.host,
5612
- // @TODO: Users might want to pass their own session id
5613
- // @TODO: We shouldn't be doing this as people might always have one session id throughout the process in server
5614
- sessionId: this.config.allowTracing ? getRandomUUID() : void 0
5615
- // @TODO: get the session id
6051
+ host: this.config.host
5616
6052
  });
5617
6053
  }
5618
6054
  telemetry.instrument(this);
@@ -5922,6 +6358,7 @@ export {
5922
6358
  GenerateURLResponseCamelCaseSchema,
5923
6359
  GenerateURLResponseSchema,
5924
6360
  IncomingTriggerPayloadSchema,
6361
+ JSONSchemaPropertySchema,
5925
6362
  JsonSchemaToZodError,
5926
6363
  MCP,
5927
6364
  MCPAuthOptionsSchema,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@composio/core",
3
- "version": "0.1.28",
3
+ "version": "0.1.30",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",
@@ -32,6 +32,7 @@
32
32
  "dependencies": {
33
33
  "@composio/client": "0.1.0-alpha.24",
34
34
  "@composio/json-schema-to-zod": "0.1.9",
35
+ "@types/json-schema": "^7.0.15",
35
36
  "chalk": "^5.4.1",
36
37
  "openai": "^4.94.0",
37
38
  "pusher-js": "^8.4.0",