@composio/core 0.1.30 → 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.
Files changed (3) hide show
  1. package/dist/index.cjs +130 -70
  2. package/dist/index.js +130 -70
  3. package/package.json +1 -1
package/dist/index.cjs CHANGED
@@ -2217,17 +2217,92 @@ var saveFile = (file, content, isTempFile = false) => {
2217
2217
  var transformProperties = (properties) => {
2218
2218
  const newProperties = {};
2219
2219
  for (const [key, property] of Object.entries(properties)) {
2220
- 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 {
2221
2234
  newProperties[key] = property;
2222
- continue;
2223
2235
  }
2224
- newProperties[key] = {
2225
- ...property,
2226
- format: "path"
2227
- };
2228
2236
  }
2229
2237
  return newProperties;
2230
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;
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
+ }
2231
2306
  var FileToolModifier = class {
2232
2307
  client;
2233
2308
  constructor(client) {
@@ -2266,30 +2341,21 @@ var FileToolModifier = class {
2266
2341
  *
2267
2342
  */
2268
2343
  async fileUploadModifier(tool, options) {
2269
- const { arguments: args } = options.params;
2270
- if (!args) {
2271
- return options.params;
2272
- }
2273
- for (const key of Object.keys(args)) {
2274
- const toolProperty = tool.inputParameters?.properties?.[key];
2275
- if (toolProperty?.file_uploadable) {
2276
- logger_default.debug(`Processing file upload for: ${key}`);
2277
- try {
2278
- const fileData = await getFileDataAfterUploadingToS3({
2279
- path: args[key],
2280
- toolSlug: options.toolSlug,
2281
- toolkitSlug: options.toolkitSlug ?? "unknown",
2282
- client: this.client
2283
- });
2284
- args[key] = fileData;
2285
- } catch (error) {
2286
- throw new ComposioFileUploadError(`Failed to upload file: ${key}`, {
2287
- cause: error
2288
- });
2289
- }
2290
- }
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
+ });
2291
2358
  }
2292
- return options.params;
2293
2359
  }
2294
2360
  /**
2295
2361
  * Modifies the result to include the file download URL.
@@ -2301,37 +2367,10 @@ var FileToolModifier = class {
2301
2367
  * @param result - The result of the tool execution.
2302
2368
  * @returns The result with the file download URL included.
2303
2369
  */
2304
- async fileDownloadModifier(tool, options) {
2305
- for (const [key, value] of Object.entries(options.result?.data)) {
2306
- const fileData = value;
2307
- if (!fileData?.s3url) continue;
2308
- logger_default.debug(`Downloading file from S3: ${fileData.s3url}`);
2309
- try {
2310
- const downloadedFile = await downloadFileFromS3({
2311
- toolSlug: options.toolSlug,
2312
- s3Url: fileData.s3url,
2313
- mimeType: fileData.mimetype || "application/txt"
2314
- });
2315
- logger_default.debug(`Downloaded file from S3: ${downloadedFile.filePath}`);
2316
- options.result.data[key] = {
2317
- uri: downloadedFile.filePath,
2318
- file_downloaded: true,
2319
- s3url: fileData.s3url,
2320
- mimeType: downloadedFile.mimeType
2321
- };
2322
- } catch (error) {
2323
- logger_default.error(`Failed to download file from S3: ${fileData.s3url}`, {
2324
- cause: error
2325
- });
2326
- options.result.data[key] = {
2327
- uri: "",
2328
- file_downloaded: false,
2329
- s3url: fileData.s3url,
2330
- mimeType: fileData.mimetype || "application/txt"
2331
- };
2332
- }
2333
- }
2334
- 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 };
2335
2374
  }
2336
2375
  };
2337
2376
 
@@ -4091,17 +4130,38 @@ var Toolkits = class {
4091
4130
  authConfigIdToUse = authConfig.items[0]?.id;
4092
4131
  if (!authConfigIdToUse) {
4093
4132
  if (toolkit.authConfigDetails && toolkit.authConfigDetails.length > 0) {
4094
- const authConfig2 = await composioAuthConfig.create(toolkitSlug, {
4095
- type: "use_composio_managed_auth",
4096
- name: `${toolkit.name} Auth Config`
4097
- });
4098
- 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
+ }
4099
4156
  } else {
4100
- throw new ComposioAuthConfigNotFoundError("No auth config found for toolkit", {
4101
- meta: {
4102
- toolkitSlug
4157
+ throw new ComposioAuthConfigNotFoundError(
4158
+ `No auth configs found for toolkit ${toolkitSlug}`,
4159
+ {
4160
+ meta: {
4161
+ toolkitSlug
4162
+ }
4103
4163
  }
4104
- });
4164
+ );
4105
4165
  }
4106
4166
  }
4107
4167
  const composioConnectedAccount = new ConnectedAccounts(this.client);
@@ -6062,7 +6122,7 @@ var OpenAIProvider = class extends BaseNonAgenticProvider {
6062
6122
  };
6063
6123
 
6064
6124
  // package.json
6065
- var version = "0.1.30";
6125
+ var version = "0.1.31";
6066
6126
 
6067
6127
  // src/models/Files.ts
6068
6128
  var Files = class {
package/dist/index.js CHANGED
@@ -2069,17 +2069,92 @@ var saveFile = (file, content, isTempFile = false) => {
2069
2069
  var transformProperties = (properties) => {
2070
2070
  const newProperties = {};
2071
2071
  for (const [key, property] of Object.entries(properties)) {
2072
- 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 {
2073
2086
  newProperties[key] = property;
2074
- continue;
2075
2087
  }
2076
- newProperties[key] = {
2077
- ...property,
2078
- format: "path"
2079
- };
2080
2088
  }
2081
2089
  return newProperties;
2082
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;
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
+ }
2083
2158
  var FileToolModifier = class {
2084
2159
  client;
2085
2160
  constructor(client) {
@@ -2118,30 +2193,21 @@ var FileToolModifier = class {
2118
2193
  *
2119
2194
  */
2120
2195
  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
- }
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
+ });
2143
2210
  }
2144
- return options.params;
2145
2211
  }
2146
2212
  /**
2147
2213
  * Modifies the result to include the file download URL.
@@ -2153,37 +2219,10 @@ var FileToolModifier = class {
2153
2219
  * @param result - The result of the tool execution.
2154
2220
  * @returns The result with the file download URL included.
2155
2221
  */
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;
2222
+ async fileDownloadModifier(_tool, options) {
2223
+ const { result, toolSlug } = options;
2224
+ const dataWithDownloads = await hydrateDownloads(result.data, { toolSlug });
2225
+ return { ...result, data: dataWithDownloads };
2187
2226
  }
2188
2227
  };
2189
2228
 
@@ -3943,17 +3982,38 @@ var Toolkits = class {
3943
3982
  authConfigIdToUse = authConfig.items[0]?.id;
3944
3983
  if (!authConfigIdToUse) {
3945
3984
  if (toolkit.authConfigDetails && toolkit.authConfigDetails.length > 0) {
3946
- const authConfig2 = await composioAuthConfig.create(toolkitSlug, {
3947
- type: "use_composio_managed_auth",
3948
- name: `${toolkit.name} Auth Config`
3949
- });
3950
- 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
+ }
3951
4008
  } else {
3952
- throw new ComposioAuthConfigNotFoundError("No auth config found for toolkit", {
3953
- meta: {
3954
- toolkitSlug
4009
+ throw new ComposioAuthConfigNotFoundError(
4010
+ `No auth configs found for toolkit ${toolkitSlug}`,
4011
+ {
4012
+ meta: {
4013
+ toolkitSlug
4014
+ }
3955
4015
  }
3956
- });
4016
+ );
3957
4017
  }
3958
4018
  }
3959
4019
  const composioConnectedAccount = new ConnectedAccounts(this.client);
@@ -5914,7 +5974,7 @@ var OpenAIProvider = class extends BaseNonAgenticProvider {
5914
5974
  };
5915
5975
 
5916
5976
  // package.json
5917
- var version = "0.1.30";
5977
+ var version = "0.1.31";
5918
5978
 
5919
5979
  // src/models/Files.ts
5920
5980
  var Files = class {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@composio/core",
3
- "version": "0.1.30",
3
+ "version": "0.1.31",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",