@composio/core 0.1.29 → 0.1.31

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
@@ -2123,7 +2123,12 @@ var uploadFileToS3 = async (fileName, content, toolSlug, toolkitSlug, mimeType,
2123
2123
  }
2124
2124
  return key;
2125
2125
  };
2126
- var getFileDataAfterUploadingToS3 = async (path, toolSlug, toolkitSlug, client) => {
2126
+ var getFileDataAfterUploadingToS3 = async ({
2127
+ path,
2128
+ toolSlug,
2129
+ toolkitSlug,
2130
+ client
2131
+ }) => {
2127
2132
  const isURL = path.startsWith("http");
2128
2133
  const fileData = isURL ? await readFileContentFromURL(path) : await readFileContent(path);
2129
2134
  logger_default.debug(`Uploading file to S3: ${path}`);
@@ -2158,7 +2163,7 @@ var downloadFileFromS3 = async ({
2158
2163
  return {
2159
2164
  name: fileName,
2160
2165
  mimeType,
2161
- s3Key: s3Url,
2166
+ s3Url,
2162
2167
  filePath
2163
2168
  };
2164
2169
  };
@@ -2212,17 +2217,92 @@ var saveFile = (file, content, isTempFile = false) => {
2212
2217
  var transformProperties = (properties) => {
2213
2218
  const newProperties = {};
2214
2219
  for (const [key, property] of Object.entries(properties)) {
2215
- if (!property.file_uploadable) {
2220
+ if (property.file_uploadable) {
2221
+ newProperties[key] = {
2222
+ title: property.title,
2223
+ description: property.description,
2224
+ format: "path",
2225
+ type: "string",
2226
+ file_uploadable: true
2227
+ };
2228
+ } else if (property.type === "object" && property.properties) {
2229
+ newProperties[key] = {
2230
+ ...property,
2231
+ properties: transformProperties(property.properties)
2232
+ };
2233
+ } else {
2216
2234
  newProperties[key] = property;
2217
- continue;
2218
2235
  }
2219
- newProperties[key] = {
2220
- ...property,
2221
- format: "path"
2222
- };
2223
2236
  }
2224
- return properties;
2237
+ return newProperties;
2238
+ };
2239
+ var hydrateFiles = async (value, schema, ctx) => {
2240
+ if (schema?.file_uploadable) {
2241
+ if (typeof value !== "string") return value;
2242
+ logger_default.debug(`Uploading file "${value}"`);
2243
+ return getFileDataAfterUploadingToS3({
2244
+ path: value,
2245
+ toolSlug: ctx.toolSlug,
2246
+ toolkitSlug: ctx.toolkitSlug,
2247
+ client: ctx.client
2248
+ });
2249
+ }
2250
+ if (schema?.type === "object" && schema.properties && isPlainObject(value)) {
2251
+ const transformed = {};
2252
+ for (const [k, v] of Object.entries(value)) {
2253
+ transformed[k] = await hydrateFiles(v, schema.properties[k], ctx);
2254
+ }
2255
+ return transformed;
2256
+ }
2257
+ if (schema?.type === "array" && schema.items && Array.isArray(value)) {
2258
+ const itemSchema = Array.isArray(schema.items) ? schema.items[0] : schema.items;
2259
+ return Promise.all(
2260
+ value.map((item) => hydrateFiles(item, itemSchema, ctx))
2261
+ );
2262
+ }
2263
+ return value;
2225
2264
  };
2265
+ var hydrateDownloads = async (value, ctx) => {
2266
+ if (isPlainObject(value) && typeof value.s3url === "string") {
2267
+ const { s3url, mimetype } = value;
2268
+ try {
2269
+ logger_default.debug(`Downloading from S3: ${s3url}`);
2270
+ const dl = await downloadFileFromS3({
2271
+ toolSlug: ctx.toolSlug,
2272
+ s3Url: s3url,
2273
+ mimeType: mimetype ?? "application/octet-stream"
2274
+ });
2275
+ logger_default.debug(`Downloaded \u2192 ${dl.filePath}`);
2276
+ return {
2277
+ uri: dl.filePath,
2278
+ file_downloaded: true,
2279
+ s3url,
2280
+ mimeType: dl.mimeType
2281
+ };
2282
+ } catch (err) {
2283
+ logger_default.error(`Download failed: ${s3url}`, { cause: err });
2284
+ return {
2285
+ uri: "",
2286
+ file_downloaded: false,
2287
+ s3url,
2288
+ mimeType: mimetype ?? "application/octet-stream"
2289
+ };
2290
+ }
2291
+ }
2292
+ if (isPlainObject(value)) {
2293
+ const pairs = await Promise.all(
2294
+ Object.entries(value).map(async ([k, v]) => [k, await hydrateDownloads(v, ctx)])
2295
+ );
2296
+ return Object.fromEntries(pairs);
2297
+ }
2298
+ if (Array.isArray(value)) {
2299
+ return Promise.all(value.map((item) => hydrateDownloads(item, ctx)));
2300
+ }
2301
+ return value;
2302
+ };
2303
+ function isPlainObject(val) {
2304
+ return typeof val === "object" && val !== null && !Array.isArray(val);
2305
+ }
2226
2306
  var FileToolModifier = class {
2227
2307
  client;
2228
2308
  constructor(client) {
@@ -2261,30 +2341,21 @@ var FileToolModifier = class {
2261
2341
  *
2262
2342
  */
2263
2343
  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
- }
2344
+ const { params, toolSlug, toolkitSlug = "unknown" } = options;
2345
+ const { arguments: args } = params;
2346
+ if (!args || typeof args !== "object") return params;
2347
+ try {
2348
+ const newArgs = await hydrateFiles(args, tool.inputParameters, {
2349
+ toolSlug,
2350
+ toolkitSlug,
2351
+ client: this.client
2352
+ });
2353
+ return { ...params, arguments: newArgs };
2354
+ } catch (error) {
2355
+ throw new ComposioFileUploadError("Failed to upload file", {
2356
+ cause: error
2357
+ });
2286
2358
  }
2287
- return options.params;
2288
2359
  }
2289
2360
  /**
2290
2361
  * Modifies the result to include the file download URL.
@@ -2296,39 +2367,10 @@ var FileToolModifier = class {
2296
2367
  * @param result - The result of the tool execution.
2297
2368
  * @returns The result with the file download URL included.
2298
2369
  */
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;
2370
+ async fileDownloadModifier(_tool, options) {
2371
+ const { result, toolSlug } = options;
2372
+ const dataWithDownloads = await hydrateDownloads(result.data, { toolSlug });
2373
+ return { ...result, data: dataWithDownloads };
2332
2374
  }
2333
2375
  };
2334
2376
 
@@ -2337,7 +2379,8 @@ var Tools = class {
2337
2379
  client;
2338
2380
  customTools;
2339
2381
  provider;
2340
- constructor(client, provider) {
2382
+ autoUploadDownloadFiles;
2383
+ constructor(client, provider, options) {
2341
2384
  if (!client) {
2342
2385
  throw new Error("ComposioClient is required");
2343
2386
  }
@@ -2347,6 +2390,7 @@ var Tools = class {
2347
2390
  this.client = client;
2348
2391
  this.customTools = new CustomTools(client);
2349
2392
  this.provider = provider;
2393
+ this.autoUploadDownloadFiles = options?.autoUploadDownloadFiles ?? true;
2350
2394
  this.execute = this.execute.bind(this);
2351
2395
  this.provider._setExecuteToolFn(this.execute);
2352
2396
  this.getRawComposioToolBySlug = this.getRawComposioToolBySlug.bind(this);
@@ -2470,12 +2514,16 @@ var Tools = class {
2470
2514
  * @returns The tools with the default schema modifiers applied
2471
2515
  */
2472
2516
  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
- );
2517
+ if (this.autoUploadDownloadFiles) {
2518
+ const fileToolModifier = new FileToolModifier(this.client);
2519
+ return await Promise.all(
2520
+ tools.map(
2521
+ (tool) => fileToolModifier.modifyToolSchema(tool.slug, tool.toolkit?.slug ?? "unknown", tool)
2522
+ )
2523
+ );
2524
+ } else {
2525
+ return tools;
2526
+ }
2479
2527
  }
2480
2528
  /**
2481
2529
  * Applies the before execute modifiers to the tool execution params
@@ -2490,8 +2538,15 @@ var Tools = class {
2490
2538
  toolkitSlug,
2491
2539
  params
2492
2540
  }, modifier) {
2493
- const fileToolModifier = new FileToolModifier(this.client);
2494
2541
  let modifiedParams = params;
2542
+ if (this.autoUploadDownloadFiles) {
2543
+ const fileToolModifier = new FileToolModifier(this.client);
2544
+ modifiedParams = await fileToolModifier.fileUploadModifier(tool, {
2545
+ toolSlug,
2546
+ toolkitSlug,
2547
+ params: modifiedParams
2548
+ });
2549
+ }
2495
2550
  if (modifier) {
2496
2551
  if (typeof modifier === "function") {
2497
2552
  modifiedParams = await modifier({
@@ -2503,11 +2558,6 @@ var Tools = class {
2503
2558
  throw new ComposioInvalidModifierError("Invalid beforeExecute modifier. Not a function.");
2504
2559
  }
2505
2560
  }
2506
- modifiedParams = await fileToolModifier.fileUploadModifier(tool, {
2507
- toolSlug,
2508
- toolkitSlug,
2509
- params: modifiedParams
2510
- });
2511
2561
  return modifiedParams;
2512
2562
  }
2513
2563
  /**
@@ -2523,8 +2573,15 @@ var Tools = class {
2523
2573
  toolkitSlug,
2524
2574
  result
2525
2575
  }, modifier) {
2526
- const fileToolModifier = new FileToolModifier(this.client);
2527
2576
  let modifiedResult = result;
2577
+ if (this.autoUploadDownloadFiles) {
2578
+ const fileToolModifier = new FileToolModifier(this.client);
2579
+ modifiedResult = await fileToolModifier.fileDownloadModifier(tool, {
2580
+ toolSlug,
2581
+ toolkitSlug,
2582
+ result: modifiedResult
2583
+ });
2584
+ }
2528
2585
  if (modifier) {
2529
2586
  if (typeof modifier === "function") {
2530
2587
  modifiedResult = await modifier({
@@ -2536,11 +2593,6 @@ var Tools = class {
2536
2593
  throw new ComposioInvalidModifierError("Invalid afterExecute modifier. Not a function.");
2537
2594
  }
2538
2595
  }
2539
- modifiedResult = await fileToolModifier.fileDownloadModifier(tool, {
2540
- toolSlug,
2541
- toolkitSlug,
2542
- result: modifiedResult
2543
- });
2544
2596
  return modifiedResult;
2545
2597
  }
2546
2598
  /**
@@ -4078,17 +4130,38 @@ var Toolkits = class {
4078
4130
  authConfigIdToUse = authConfig.items[0]?.id;
4079
4131
  if (!authConfigIdToUse) {
4080
4132
  if (toolkit.authConfigDetails && toolkit.authConfigDetails.length > 0) {
4081
- const authConfig2 = await composioAuthConfig.create(toolkitSlug, {
4082
- type: "use_composio_managed_auth",
4083
- name: `${toolkit.name} Auth Config`
4084
- });
4085
- authConfigIdToUse = authConfig2.id;
4133
+ try {
4134
+ const authConfig2 = await composioAuthConfig.create(toolkitSlug, {
4135
+ type: "use_composio_managed_auth",
4136
+ name: `${toolkit.name} Auth Config`
4137
+ });
4138
+ authConfigIdToUse = authConfig2.id;
4139
+ } catch (error) {
4140
+ if (error instanceof import_client4.default.APIError && error.status === 400) {
4141
+ throw new ComposioAuthConfigNotFoundError(
4142
+ `No Default auth config found for toolkit ${toolkitSlug}`,
4143
+ {
4144
+ meta: {
4145
+ toolkitSlug
4146
+ },
4147
+ cause: error,
4148
+ possibleFixes: [
4149
+ `Please Create an auth config for the toolkit ${toolkitSlug} via the dashboard`
4150
+ ]
4151
+ }
4152
+ );
4153
+ }
4154
+ throw error;
4155
+ }
4086
4156
  } else {
4087
- throw new ComposioAuthConfigNotFoundError("No auth config found for toolkit", {
4088
- meta: {
4089
- toolkitSlug
4157
+ throw new ComposioAuthConfigNotFoundError(
4158
+ `No auth configs found for toolkit ${toolkitSlug}`,
4159
+ {
4160
+ meta: {
4161
+ toolkitSlug
4162
+ }
4090
4163
  }
4091
- });
4164
+ );
4092
4165
  }
4093
4166
  }
4094
4167
  const composioConnectedAccount = new ConnectedAccounts(this.client);
@@ -6049,7 +6122,48 @@ var OpenAIProvider = class extends BaseNonAgenticProvider {
6049
6122
  };
6050
6123
 
6051
6124
  // package.json
6052
- var version = "0.1.29";
6125
+ var version = "0.1.31";
6126
+
6127
+ // src/models/Files.ts
6128
+ var Files = class {
6129
+ constructor(client) {
6130
+ this.client = client;
6131
+ telemetry.instrument(this);
6132
+ }
6133
+ /**
6134
+ * Upload a file to S3 and return the file data.
6135
+ * @param filePath - The path to the file to upload or a URL of the file to upload.
6136
+ * @param toolSlug - The slug of the tool that is uploading the file.
6137
+ * @param toolkitSlug - The slug of the toolkit that is uploading the file.
6138
+ * @returns The file data.
6139
+ */
6140
+ async upload({
6141
+ filePath,
6142
+ toolSlug,
6143
+ toolkitSlug
6144
+ }) {
6145
+ const fileData = await getFileDataAfterUploadingToS3({
6146
+ path: filePath,
6147
+ toolSlug,
6148
+ toolkitSlug,
6149
+ client: this.client
6150
+ });
6151
+ return fileData;
6152
+ }
6153
+ /**
6154
+ * Download a file from S3 and return the file data.
6155
+ * @param s3key - The S3 key of the file to download.
6156
+ * @returns The file data.
6157
+ */
6158
+ async download({
6159
+ toolSlug,
6160
+ s3Url,
6161
+ mimeType
6162
+ }) {
6163
+ const fileDownloadData = await downloadFileFromS3({ toolSlug, s3Url, mimeType });
6164
+ return fileDownloadData;
6165
+ }
6166
+ };
6053
6167
 
6054
6168
  // src/composio.ts
6055
6169
  var Composio = class _Composio {
@@ -6070,6 +6184,7 @@ var Composio = class _Composio {
6070
6184
  toolkits;
6071
6185
  triggers;
6072
6186
  provider;
6187
+ files;
6073
6188
  // auth configs
6074
6189
  authConfigs;
6075
6190
  // connected accounts
@@ -6085,7 +6200,6 @@ var Composio = class _Composio {
6085
6200
  * @param {string} [config.apiKey] - The API key for authenticating with the Composio API
6086
6201
  * @param {string} [config.baseURL] - The base URL for the Composio API (defaults to production URL)
6087
6202
  * @param {boolean} [config.allowTracking=true] - Whether to allow anonymous usage analytics
6088
- * @param {boolean} [config.allowTracing=true] - Whether to allow request tracing for debugging
6089
6203
  * @param {TProvider} [config.provider] - The provider to use for this Composio instance (defaults to OpenAIProvider)
6090
6204
  *
6091
6205
  * @example
@@ -6122,15 +6236,17 @@ var Composio = class _Composio {
6122
6236
  });
6123
6237
  this.config = {
6124
6238
  ...config,
6125
- allowTracking: config?.allowTracking ?? true,
6126
- allowTracing: config?.allowTracing ?? true
6239
+ allowTracking: config?.allowTracking ?? true
6127
6240
  };
6128
6241
  this.provider = config?.provider ?? new OpenAIProvider();
6129
- this.tools = new Tools(this.client, this.provider);
6242
+ this.tools = new Tools(this.client, this.provider, {
6243
+ autoUploadDownloadFiles: config?.autoUploadDownloadFiles ?? true
6244
+ });
6130
6245
  this.mcp = new MCP(this.client, this.provider);
6131
6246
  this.toolkits = new Toolkits(this.client);
6132
6247
  this.triggers = new Triggers(this.client);
6133
6248
  this.authConfigs = new AuthConfigs(this.client);
6249
+ this.files = new Files(this.client);
6134
6250
  this.connectedAccounts = new ConnectedAccounts(this.client);
6135
6251
  if (this.config.allowTracking) {
6136
6252
  telemetry.setup({
@@ -6140,11 +6256,7 @@ var Composio = class _Composio {
6140
6256
  version,
6141
6257
  isBrowser: typeof window !== "undefined",
6142
6258
  provider: this.provider?.name ?? "openai",
6143
- host: this.config.host,
6144
- // @TODO: Users might want to pass their own session id
6145
- // @TODO: We shouldn't be doing this as people might always have one session id throughout the process in server
6146
- sessionId: this.config.allowTracing ? getRandomUUID() : void 0
6147
- // @TODO: get the session id
6259
+ host: this.config.host
6148
6260
  });
6149
6261
  }
6150
6262
  telemetry.instrument(this);
package/dist/index.d.cts CHANGED
@@ -10646,7 +10646,10 @@ declare class Tools<TToolCollection, TTool, TProvider extends BaseComposioProvid
10646
10646
  private client;
10647
10647
  private readonly customTools;
10648
10648
  private provider;
10649
- constructor(client: ComposioClient, provider: TProvider);
10649
+ private autoUploadDownloadFiles;
10650
+ constructor(client: ComposioClient, provider: TProvider, options?: {
10651
+ autoUploadDownloadFiles: boolean;
10652
+ });
10650
10653
  /**
10651
10654
  * Transforms tool data from snake_case API format to camelCase for internal SDK use.
10652
10655
  *
@@ -40443,6 +40446,45 @@ declare class OpenAIProvider extends BaseNonAgenticProvider<OpenAiToolCollection
40443
40446
 
40444
40447
  type ComposioRequestHeaders = Record<string, string>;
40445
40448
 
40449
+ type FileUploadData = {
40450
+ name: string;
40451
+ mimetype: string;
40452
+ s3key: string;
40453
+ };
40454
+ type FileDownloadData = {
40455
+ name: string;
40456
+ mimeType: string;
40457
+ s3Url: string;
40458
+ filePath: string;
40459
+ };
40460
+
40461
+ declare class Files {
40462
+ private readonly client;
40463
+ constructor(client: ComposioClient);
40464
+ /**
40465
+ * Upload a file to S3 and return the file data.
40466
+ * @param filePath - The path to the file to upload or a URL of the file to upload.
40467
+ * @param toolSlug - The slug of the tool that is uploading the file.
40468
+ * @param toolkitSlug - The slug of the toolkit that is uploading the file.
40469
+ * @returns The file data.
40470
+ */
40471
+ upload({ filePath, toolSlug, toolkitSlug, }: {
40472
+ filePath: string;
40473
+ toolSlug: string;
40474
+ toolkitSlug: string;
40475
+ }): Promise<FileUploadData>;
40476
+ /**
40477
+ * Download a file from S3 and return the file data.
40478
+ * @param s3key - The S3 key of the file to download.
40479
+ * @returns The file data.
40480
+ */
40481
+ download({ toolSlug, s3Url, mimeType, }: {
40482
+ s3Url: string;
40483
+ toolSlug: string;
40484
+ mimeType: string;
40485
+ }): Promise<FileDownloadData>;
40486
+ }
40487
+
40446
40488
  type ComposioConfig<TProvider extends BaseComposioProvider<unknown, unknown, unknown> = OpenAIProvider> = {
40447
40489
  /**
40448
40490
  * The API key for the Composio API.
@@ -40461,11 +40503,11 @@ type ComposioConfig<TProvider extends BaseComposioProvider<unknown, unknown, unk
40461
40503
  */
40462
40504
  allowTracking?: boolean;
40463
40505
  /**
40464
- * Whether to allow tracing for the Composio instance.
40506
+ * Whether to automatically upload and download files during tool execution.
40465
40507
  * @example true, false
40466
40508
  * @default true
40467
40509
  */
40468
- allowTracing?: boolean;
40510
+ autoUploadDownloadFiles?: boolean;
40469
40511
  /**
40470
40512
  * The tool provider to use for this Composio instance.
40471
40513
  * @example new OpenAIProvider()
@@ -40517,6 +40559,7 @@ declare class Composio<TProvider extends BaseComposioProvider<unknown, unknown,
40517
40559
  toolkits: Toolkits;
40518
40560
  triggers: Triggers;
40519
40561
  provider: TProvider;
40562
+ files: Files;
40520
40563
  authConfigs: AuthConfigs;
40521
40564
  connectedAccounts: ConnectedAccounts;
40522
40565
  mcp: MCP<ExtractMcpResponseType<TProvider>>;
@@ -40530,7 +40573,6 @@ declare class Composio<TProvider extends BaseComposioProvider<unknown, unknown,
40530
40573
  * @param {string} [config.apiKey] - The API key for authenticating with the Composio API
40531
40574
  * @param {string} [config.baseURL] - The base URL for the Composio API (defaults to production URL)
40532
40575
  * @param {boolean} [config.allowTracking=true] - Whether to allow anonymous usage analytics
40533
- * @param {boolean} [config.allowTracing=true] - Whether to allow request tracing for debugging
40534
40576
  * @param {TProvider} [config.provider] - The provider to use for this Composio instance (defaults to OpenAIProvider)
40535
40577
  *
40536
40578
  * @example
package/dist/index.d.ts CHANGED
@@ -10646,7 +10646,10 @@ declare class Tools<TToolCollection, TTool, TProvider extends BaseComposioProvid
10646
10646
  private client;
10647
10647
  private readonly customTools;
10648
10648
  private provider;
10649
- constructor(client: ComposioClient, provider: TProvider);
10649
+ private autoUploadDownloadFiles;
10650
+ constructor(client: ComposioClient, provider: TProvider, options?: {
10651
+ autoUploadDownloadFiles: boolean;
10652
+ });
10650
10653
  /**
10651
10654
  * Transforms tool data from snake_case API format to camelCase for internal SDK use.
10652
10655
  *
@@ -40443,6 +40446,45 @@ declare class OpenAIProvider extends BaseNonAgenticProvider<OpenAiToolCollection
40443
40446
 
40444
40447
  type ComposioRequestHeaders = Record<string, string>;
40445
40448
 
40449
+ type FileUploadData = {
40450
+ name: string;
40451
+ mimetype: string;
40452
+ s3key: string;
40453
+ };
40454
+ type FileDownloadData = {
40455
+ name: string;
40456
+ mimeType: string;
40457
+ s3Url: string;
40458
+ filePath: string;
40459
+ };
40460
+
40461
+ declare class Files {
40462
+ private readonly client;
40463
+ constructor(client: ComposioClient);
40464
+ /**
40465
+ * Upload a file to S3 and return the file data.
40466
+ * @param filePath - The path to the file to upload or a URL of the file to upload.
40467
+ * @param toolSlug - The slug of the tool that is uploading the file.
40468
+ * @param toolkitSlug - The slug of the toolkit that is uploading the file.
40469
+ * @returns The file data.
40470
+ */
40471
+ upload({ filePath, toolSlug, toolkitSlug, }: {
40472
+ filePath: string;
40473
+ toolSlug: string;
40474
+ toolkitSlug: string;
40475
+ }): Promise<FileUploadData>;
40476
+ /**
40477
+ * Download a file from S3 and return the file data.
40478
+ * @param s3key - The S3 key of the file to download.
40479
+ * @returns The file data.
40480
+ */
40481
+ download({ toolSlug, s3Url, mimeType, }: {
40482
+ s3Url: string;
40483
+ toolSlug: string;
40484
+ mimeType: string;
40485
+ }): Promise<FileDownloadData>;
40486
+ }
40487
+
40446
40488
  type ComposioConfig<TProvider extends BaseComposioProvider<unknown, unknown, unknown> = OpenAIProvider> = {
40447
40489
  /**
40448
40490
  * The API key for the Composio API.
@@ -40461,11 +40503,11 @@ type ComposioConfig<TProvider extends BaseComposioProvider<unknown, unknown, unk
40461
40503
  */
40462
40504
  allowTracking?: boolean;
40463
40505
  /**
40464
- * Whether to allow tracing for the Composio instance.
40506
+ * Whether to automatically upload and download files during tool execution.
40465
40507
  * @example true, false
40466
40508
  * @default true
40467
40509
  */
40468
- allowTracing?: boolean;
40510
+ autoUploadDownloadFiles?: boolean;
40469
40511
  /**
40470
40512
  * The tool provider to use for this Composio instance.
40471
40513
  * @example new OpenAIProvider()
@@ -40517,6 +40559,7 @@ declare class Composio<TProvider extends BaseComposioProvider<unknown, unknown,
40517
40559
  toolkits: Toolkits;
40518
40560
  triggers: Triggers;
40519
40561
  provider: TProvider;
40562
+ files: Files;
40520
40563
  authConfigs: AuthConfigs;
40521
40564
  connectedAccounts: ConnectedAccounts;
40522
40565
  mcp: MCP<ExtractMcpResponseType<TProvider>>;
@@ -40530,7 +40573,6 @@ declare class Composio<TProvider extends BaseComposioProvider<unknown, unknown,
40530
40573
  * @param {string} [config.apiKey] - The API key for authenticating with the Composio API
40531
40574
  * @param {string} [config.baseURL] - The base URL for the Composio API (defaults to production URL)
40532
40575
  * @param {boolean} [config.allowTracking=true] - Whether to allow anonymous usage analytics
40533
- * @param {boolean} [config.allowTracing=true] - Whether to allow request tracing for debugging
40534
40576
  * @param {TProvider} [config.provider] - The provider to use for this Composio instance (defaults to OpenAIProvider)
40535
40577
  *
40536
40578
  * @example
package/dist/index.js CHANGED
@@ -1975,7 +1975,12 @@ var uploadFileToS3 = async (fileName, content, toolSlug, toolkitSlug, mimeType,
1975
1975
  }
1976
1976
  return key;
1977
1977
  };
1978
- var getFileDataAfterUploadingToS3 = async (path, toolSlug, toolkitSlug, client) => {
1978
+ var getFileDataAfterUploadingToS3 = async ({
1979
+ path,
1980
+ toolSlug,
1981
+ toolkitSlug,
1982
+ client
1983
+ }) => {
1979
1984
  const isURL = path.startsWith("http");
1980
1985
  const fileData = isURL ? await readFileContentFromURL(path) : await readFileContent(path);
1981
1986
  logger_default.debug(`Uploading file to S3: ${path}`);
@@ -2010,7 +2015,7 @@ var downloadFileFromS3 = async ({
2010
2015
  return {
2011
2016
  name: fileName,
2012
2017
  mimeType,
2013
- s3Key: s3Url,
2018
+ s3Url,
2014
2019
  filePath
2015
2020
  };
2016
2021
  };
@@ -2064,17 +2069,92 @@ var saveFile = (file, content, isTempFile = false) => {
2064
2069
  var transformProperties = (properties) => {
2065
2070
  const newProperties = {};
2066
2071
  for (const [key, property] of Object.entries(properties)) {
2067
- if (!property.file_uploadable) {
2072
+ if (property.file_uploadable) {
2073
+ newProperties[key] = {
2074
+ title: property.title,
2075
+ description: property.description,
2076
+ format: "path",
2077
+ type: "string",
2078
+ file_uploadable: true
2079
+ };
2080
+ } else if (property.type === "object" && property.properties) {
2081
+ newProperties[key] = {
2082
+ ...property,
2083
+ properties: transformProperties(property.properties)
2084
+ };
2085
+ } else {
2068
2086
  newProperties[key] = property;
2069
- continue;
2070
2087
  }
2071
- newProperties[key] = {
2072
- ...property,
2073
- format: "path"
2074
- };
2075
2088
  }
2076
- return properties;
2089
+ return newProperties;
2090
+ };
2091
+ var hydrateFiles = async (value, schema, ctx) => {
2092
+ if (schema?.file_uploadable) {
2093
+ if (typeof value !== "string") return value;
2094
+ logger_default.debug(`Uploading file "${value}"`);
2095
+ return getFileDataAfterUploadingToS3({
2096
+ path: value,
2097
+ toolSlug: ctx.toolSlug,
2098
+ toolkitSlug: ctx.toolkitSlug,
2099
+ client: ctx.client
2100
+ });
2101
+ }
2102
+ if (schema?.type === "object" && schema.properties && isPlainObject(value)) {
2103
+ const transformed = {};
2104
+ for (const [k, v] of Object.entries(value)) {
2105
+ transformed[k] = await hydrateFiles(v, schema.properties[k], ctx);
2106
+ }
2107
+ return transformed;
2108
+ }
2109
+ if (schema?.type === "array" && schema.items && Array.isArray(value)) {
2110
+ const itemSchema = Array.isArray(schema.items) ? schema.items[0] : schema.items;
2111
+ return Promise.all(
2112
+ value.map((item) => hydrateFiles(item, itemSchema, ctx))
2113
+ );
2114
+ }
2115
+ return value;
2077
2116
  };
2117
+ var hydrateDownloads = async (value, ctx) => {
2118
+ if (isPlainObject(value) && typeof value.s3url === "string") {
2119
+ const { s3url, mimetype } = value;
2120
+ try {
2121
+ logger_default.debug(`Downloading from S3: ${s3url}`);
2122
+ const dl = await downloadFileFromS3({
2123
+ toolSlug: ctx.toolSlug,
2124
+ s3Url: s3url,
2125
+ mimeType: mimetype ?? "application/octet-stream"
2126
+ });
2127
+ logger_default.debug(`Downloaded \u2192 ${dl.filePath}`);
2128
+ return {
2129
+ uri: dl.filePath,
2130
+ file_downloaded: true,
2131
+ s3url,
2132
+ mimeType: dl.mimeType
2133
+ };
2134
+ } catch (err) {
2135
+ logger_default.error(`Download failed: ${s3url}`, { cause: err });
2136
+ return {
2137
+ uri: "",
2138
+ file_downloaded: false,
2139
+ s3url,
2140
+ mimeType: mimetype ?? "application/octet-stream"
2141
+ };
2142
+ }
2143
+ }
2144
+ if (isPlainObject(value)) {
2145
+ const pairs = await Promise.all(
2146
+ Object.entries(value).map(async ([k, v]) => [k, await hydrateDownloads(v, ctx)])
2147
+ );
2148
+ return Object.fromEntries(pairs);
2149
+ }
2150
+ if (Array.isArray(value)) {
2151
+ return Promise.all(value.map((item) => hydrateDownloads(item, ctx)));
2152
+ }
2153
+ return value;
2154
+ };
2155
+ function isPlainObject(val) {
2156
+ return typeof val === "object" && val !== null && !Array.isArray(val);
2157
+ }
2078
2158
  var FileToolModifier = class {
2079
2159
  client;
2080
2160
  constructor(client) {
@@ -2113,30 +2193,21 @@ var FileToolModifier = class {
2113
2193
  *
2114
2194
  */
2115
2195
  async fileUploadModifier(tool, options) {
2116
- const { arguments: args } = options.params;
2117
- if (!args) {
2118
- return options.params;
2119
- }
2120
- for (const key of Object.keys(args)) {
2121
- const toolProperty = tool.inputParameters?.properties?.[key];
2122
- if (toolProperty?.file_uploadable) {
2123
- logger_default.debug(`Processing file upload for: ${key}`);
2124
- try {
2125
- const fileData = await getFileDataAfterUploadingToS3(
2126
- args[key],
2127
- options.toolSlug,
2128
- options.toolkitSlug ?? "unknown",
2129
- this.client
2130
- );
2131
- args[key] = fileData;
2132
- } catch (error) {
2133
- throw new ComposioFileUploadError(`Failed to upload file: ${key}`, {
2134
- cause: error
2135
- });
2136
- }
2137
- }
2196
+ const { params, toolSlug, toolkitSlug = "unknown" } = options;
2197
+ const { arguments: args } = params;
2198
+ if (!args || typeof args !== "object") return params;
2199
+ try {
2200
+ const newArgs = await hydrateFiles(args, tool.inputParameters, {
2201
+ toolSlug,
2202
+ toolkitSlug,
2203
+ client: this.client
2204
+ });
2205
+ return { ...params, arguments: newArgs };
2206
+ } catch (error) {
2207
+ throw new ComposioFileUploadError("Failed to upload file", {
2208
+ cause: error
2209
+ });
2138
2210
  }
2139
- return options.params;
2140
2211
  }
2141
2212
  /**
2142
2213
  * Modifies the result to include the file download URL.
@@ -2148,39 +2219,10 @@ var FileToolModifier = class {
2148
2219
  * @param result - The result of the tool execution.
2149
2220
  * @returns The result with the file download URL included.
2150
2221
  */
2151
- async fileDownloadModifier(tool, options) {
2152
- console.log(JSON.stringify(options.result, null, 2));
2153
- console.log(JSON.stringify(tool.outputParameters, null, 2));
2154
- for (const [key, value] of Object.entries(options.result?.data)) {
2155
- const fileData = value;
2156
- if (!fileData?.s3url) continue;
2157
- logger_default.debug(`Downloading file from S3: ${fileData.s3url}`);
2158
- try {
2159
- const downloadedFile = await downloadFileFromS3({
2160
- toolSlug: options.toolSlug,
2161
- s3Url: fileData.s3url,
2162
- mimeType: fileData.mimetype || "application/txt"
2163
- });
2164
- logger_default.debug(`Downloaded file from S3: ${downloadedFile.filePath}`);
2165
- options.result.data[key] = {
2166
- uri: downloadedFile.filePath,
2167
- file_downloaded: true,
2168
- s3url: fileData.s3url,
2169
- mimeType: downloadedFile.mimeType
2170
- };
2171
- } catch (error) {
2172
- logger_default.error(`Failed to download file from S3: ${fileData.s3url}`, {
2173
- cause: error
2174
- });
2175
- options.result.data[key] = {
2176
- uri: "",
2177
- file_downloaded: false,
2178
- s3url: fileData.s3url,
2179
- mimeType: fileData.mimetype || "application/txt"
2180
- };
2181
- }
2182
- }
2183
- return options.result;
2222
+ async fileDownloadModifier(_tool, options) {
2223
+ const { result, toolSlug } = options;
2224
+ const dataWithDownloads = await hydrateDownloads(result.data, { toolSlug });
2225
+ return { ...result, data: dataWithDownloads };
2184
2226
  }
2185
2227
  };
2186
2228
 
@@ -2189,7 +2231,8 @@ var Tools = class {
2189
2231
  client;
2190
2232
  customTools;
2191
2233
  provider;
2192
- constructor(client, provider) {
2234
+ autoUploadDownloadFiles;
2235
+ constructor(client, provider, options) {
2193
2236
  if (!client) {
2194
2237
  throw new Error("ComposioClient is required");
2195
2238
  }
@@ -2199,6 +2242,7 @@ var Tools = class {
2199
2242
  this.client = client;
2200
2243
  this.customTools = new CustomTools(client);
2201
2244
  this.provider = provider;
2245
+ this.autoUploadDownloadFiles = options?.autoUploadDownloadFiles ?? true;
2202
2246
  this.execute = this.execute.bind(this);
2203
2247
  this.provider._setExecuteToolFn(this.execute);
2204
2248
  this.getRawComposioToolBySlug = this.getRawComposioToolBySlug.bind(this);
@@ -2322,12 +2366,16 @@ var Tools = class {
2322
2366
  * @returns The tools with the default schema modifiers applied
2323
2367
  */
2324
2368
  async applyDefaultSchemaModifiers(tools) {
2325
- const fileToolModifier = new FileToolModifier(this.client);
2326
- return await Promise.all(
2327
- tools.map(
2328
- (tool) => fileToolModifier.modifyToolSchema(tool.slug, tool.toolkit?.slug ?? "unknown", tool)
2329
- )
2330
- );
2369
+ if (this.autoUploadDownloadFiles) {
2370
+ const fileToolModifier = new FileToolModifier(this.client);
2371
+ return await Promise.all(
2372
+ tools.map(
2373
+ (tool) => fileToolModifier.modifyToolSchema(tool.slug, tool.toolkit?.slug ?? "unknown", tool)
2374
+ )
2375
+ );
2376
+ } else {
2377
+ return tools;
2378
+ }
2331
2379
  }
2332
2380
  /**
2333
2381
  * Applies the before execute modifiers to the tool execution params
@@ -2342,8 +2390,15 @@ var Tools = class {
2342
2390
  toolkitSlug,
2343
2391
  params
2344
2392
  }, modifier) {
2345
- const fileToolModifier = new FileToolModifier(this.client);
2346
2393
  let modifiedParams = params;
2394
+ if (this.autoUploadDownloadFiles) {
2395
+ const fileToolModifier = new FileToolModifier(this.client);
2396
+ modifiedParams = await fileToolModifier.fileUploadModifier(tool, {
2397
+ toolSlug,
2398
+ toolkitSlug,
2399
+ params: modifiedParams
2400
+ });
2401
+ }
2347
2402
  if (modifier) {
2348
2403
  if (typeof modifier === "function") {
2349
2404
  modifiedParams = await modifier({
@@ -2355,11 +2410,6 @@ var Tools = class {
2355
2410
  throw new ComposioInvalidModifierError("Invalid beforeExecute modifier. Not a function.");
2356
2411
  }
2357
2412
  }
2358
- modifiedParams = await fileToolModifier.fileUploadModifier(tool, {
2359
- toolSlug,
2360
- toolkitSlug,
2361
- params: modifiedParams
2362
- });
2363
2413
  return modifiedParams;
2364
2414
  }
2365
2415
  /**
@@ -2375,8 +2425,15 @@ var Tools = class {
2375
2425
  toolkitSlug,
2376
2426
  result
2377
2427
  }, modifier) {
2378
- const fileToolModifier = new FileToolModifier(this.client);
2379
2428
  let modifiedResult = result;
2429
+ if (this.autoUploadDownloadFiles) {
2430
+ const fileToolModifier = new FileToolModifier(this.client);
2431
+ modifiedResult = await fileToolModifier.fileDownloadModifier(tool, {
2432
+ toolSlug,
2433
+ toolkitSlug,
2434
+ result: modifiedResult
2435
+ });
2436
+ }
2380
2437
  if (modifier) {
2381
2438
  if (typeof modifier === "function") {
2382
2439
  modifiedResult = await modifier({
@@ -2388,11 +2445,6 @@ var Tools = class {
2388
2445
  throw new ComposioInvalidModifierError("Invalid afterExecute modifier. Not a function.");
2389
2446
  }
2390
2447
  }
2391
- modifiedResult = await fileToolModifier.fileDownloadModifier(tool, {
2392
- toolSlug,
2393
- toolkitSlug,
2394
- result: modifiedResult
2395
- });
2396
2448
  return modifiedResult;
2397
2449
  }
2398
2450
  /**
@@ -3930,17 +3982,38 @@ var Toolkits = class {
3930
3982
  authConfigIdToUse = authConfig.items[0]?.id;
3931
3983
  if (!authConfigIdToUse) {
3932
3984
  if (toolkit.authConfigDetails && toolkit.authConfigDetails.length > 0) {
3933
- const authConfig2 = await composioAuthConfig.create(toolkitSlug, {
3934
- type: "use_composio_managed_auth",
3935
- name: `${toolkit.name} Auth Config`
3936
- });
3937
- authConfigIdToUse = authConfig2.id;
3985
+ try {
3986
+ const authConfig2 = await composioAuthConfig.create(toolkitSlug, {
3987
+ type: "use_composio_managed_auth",
3988
+ name: `${toolkit.name} Auth Config`
3989
+ });
3990
+ authConfigIdToUse = authConfig2.id;
3991
+ } catch (error) {
3992
+ if (error instanceof ComposioClient2.APIError && error.status === 400) {
3993
+ throw new ComposioAuthConfigNotFoundError(
3994
+ `No Default auth config found for toolkit ${toolkitSlug}`,
3995
+ {
3996
+ meta: {
3997
+ toolkitSlug
3998
+ },
3999
+ cause: error,
4000
+ possibleFixes: [
4001
+ `Please Create an auth config for the toolkit ${toolkitSlug} via the dashboard`
4002
+ ]
4003
+ }
4004
+ );
4005
+ }
4006
+ throw error;
4007
+ }
3938
4008
  } else {
3939
- throw new ComposioAuthConfigNotFoundError("No auth config found for toolkit", {
3940
- meta: {
3941
- toolkitSlug
4009
+ throw new ComposioAuthConfigNotFoundError(
4010
+ `No auth configs found for toolkit ${toolkitSlug}`,
4011
+ {
4012
+ meta: {
4013
+ toolkitSlug
4014
+ }
3942
4015
  }
3943
- });
4016
+ );
3944
4017
  }
3945
4018
  }
3946
4019
  const composioConnectedAccount = new ConnectedAccounts(this.client);
@@ -5901,7 +5974,48 @@ var OpenAIProvider = class extends BaseNonAgenticProvider {
5901
5974
  };
5902
5975
 
5903
5976
  // package.json
5904
- var version = "0.1.29";
5977
+ var version = "0.1.31";
5978
+
5979
+ // src/models/Files.ts
5980
+ var Files = class {
5981
+ constructor(client) {
5982
+ this.client = client;
5983
+ telemetry.instrument(this);
5984
+ }
5985
+ /**
5986
+ * Upload a file to S3 and return the file data.
5987
+ * @param filePath - The path to the file to upload or a URL of the file to upload.
5988
+ * @param toolSlug - The slug of the tool that is uploading the file.
5989
+ * @param toolkitSlug - The slug of the toolkit that is uploading the file.
5990
+ * @returns The file data.
5991
+ */
5992
+ async upload({
5993
+ filePath,
5994
+ toolSlug,
5995
+ toolkitSlug
5996
+ }) {
5997
+ const fileData = await getFileDataAfterUploadingToS3({
5998
+ path: filePath,
5999
+ toolSlug,
6000
+ toolkitSlug,
6001
+ client: this.client
6002
+ });
6003
+ return fileData;
6004
+ }
6005
+ /**
6006
+ * Download a file from S3 and return the file data.
6007
+ * @param s3key - The S3 key of the file to download.
6008
+ * @returns The file data.
6009
+ */
6010
+ async download({
6011
+ toolSlug,
6012
+ s3Url,
6013
+ mimeType
6014
+ }) {
6015
+ const fileDownloadData = await downloadFileFromS3({ toolSlug, s3Url, mimeType });
6016
+ return fileDownloadData;
6017
+ }
6018
+ };
5905
6019
 
5906
6020
  // src/composio.ts
5907
6021
  var Composio = class _Composio {
@@ -5922,6 +6036,7 @@ var Composio = class _Composio {
5922
6036
  toolkits;
5923
6037
  triggers;
5924
6038
  provider;
6039
+ files;
5925
6040
  // auth configs
5926
6041
  authConfigs;
5927
6042
  // connected accounts
@@ -5937,7 +6052,6 @@ var Composio = class _Composio {
5937
6052
  * @param {string} [config.apiKey] - The API key for authenticating with the Composio API
5938
6053
  * @param {string} [config.baseURL] - The base URL for the Composio API (defaults to production URL)
5939
6054
  * @param {boolean} [config.allowTracking=true] - Whether to allow anonymous usage analytics
5940
- * @param {boolean} [config.allowTracing=true] - Whether to allow request tracing for debugging
5941
6055
  * @param {TProvider} [config.provider] - The provider to use for this Composio instance (defaults to OpenAIProvider)
5942
6056
  *
5943
6057
  * @example
@@ -5974,15 +6088,17 @@ var Composio = class _Composio {
5974
6088
  });
5975
6089
  this.config = {
5976
6090
  ...config,
5977
- allowTracking: config?.allowTracking ?? true,
5978
- allowTracing: config?.allowTracing ?? true
6091
+ allowTracking: config?.allowTracking ?? true
5979
6092
  };
5980
6093
  this.provider = config?.provider ?? new OpenAIProvider();
5981
- this.tools = new Tools(this.client, this.provider);
6094
+ this.tools = new Tools(this.client, this.provider, {
6095
+ autoUploadDownloadFiles: config?.autoUploadDownloadFiles ?? true
6096
+ });
5982
6097
  this.mcp = new MCP(this.client, this.provider);
5983
6098
  this.toolkits = new Toolkits(this.client);
5984
6099
  this.triggers = new Triggers(this.client);
5985
6100
  this.authConfigs = new AuthConfigs(this.client);
6101
+ this.files = new Files(this.client);
5986
6102
  this.connectedAccounts = new ConnectedAccounts(this.client);
5987
6103
  if (this.config.allowTracking) {
5988
6104
  telemetry.setup({
@@ -5992,11 +6108,7 @@ var Composio = class _Composio {
5992
6108
  version,
5993
6109
  isBrowser: typeof window !== "undefined",
5994
6110
  provider: this.provider?.name ?? "openai",
5995
- host: this.config.host,
5996
- // @TODO: Users might want to pass their own session id
5997
- // @TODO: We shouldn't be doing this as people might always have one session id throughout the process in server
5998
- sessionId: this.config.allowTracing ? getRandomUUID() : void 0
5999
- // @TODO: get the session id
6111
+ host: this.config.host
6000
6112
  });
6001
6113
  }
6002
6114
  telemetry.instrument(this);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@composio/core",
3
- "version": "0.1.29",
3
+ "version": "0.1.31",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",