@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.cjs +488 -50
- package/dist/index.d.cts +431 -202
- package/dist/index.d.ts +431 -202
- package/dist/index.js +487 -50
- package/package.json +2 -1
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
|
|
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(
|
|
183
|
-
oneOf: import_zod.z.lazy(() => import_zod.z.array(
|
|
184
|
-
allOf: import_zod.z.lazy(() => import_zod.z.array(
|
|
185
|
-
not: import_zod.z.lazy(() =>
|
|
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(),
|
|
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
|
-
|
|
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(),
|
|
209
|
-
additionalProperties: import_zod.z.union([import_zod.z.boolean(), import_zod.z.lazy(() =>
|
|
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(() =>
|
|
214
|
-
then: import_zod.z.lazy(() =>
|
|
215
|
-
else: import_zod.z.lazy(() =>
|
|
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(() =>
|
|
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(() =>
|
|
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(
|
|
229
|
-
oneOf: import_zod.z.array(
|
|
230
|
-
allOf: import_zod.z.array(
|
|
231
|
-
not:
|
|
232
|
-
properties: import_zod.z.record(import_zod.z.string(),
|
|
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,12 +2052,296 @@ 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 ({
|
|
2127
|
+
path,
|
|
2128
|
+
toolSlug,
|
|
2129
|
+
toolkitSlug,
|
|
2130
|
+
client
|
|
2131
|
+
}) => {
|
|
2132
|
+
const isURL = path.startsWith("http");
|
|
2133
|
+
const fileData = isURL ? await readFileContentFromURL(path) : await readFileContent(path);
|
|
2134
|
+
logger_default.debug(`Uploading file to S3: ${path}`);
|
|
2135
|
+
const s3key = await uploadFileToS3(
|
|
2136
|
+
import_path.default.basename(path) || `${toolSlug}_${Date.now()}`,
|
|
2137
|
+
fileData.content,
|
|
2138
|
+
toolSlug,
|
|
2139
|
+
toolkitSlug,
|
|
2140
|
+
fileData.mimeType,
|
|
2141
|
+
client
|
|
2142
|
+
);
|
|
2143
|
+
logger_default.debug(`Done! File uploaded to S3: ${s3key}`, JSON.stringify(fileData, null, 2));
|
|
2144
|
+
return {
|
|
2145
|
+
name: import_path.default.basename(path) || `${toolSlug}_${Date.now()}.${fileData.mimeType.split("/")[1]}`,
|
|
2146
|
+
mimetype: fileData.mimeType,
|
|
2147
|
+
s3key
|
|
2148
|
+
};
|
|
2149
|
+
};
|
|
2150
|
+
var downloadFileFromS3 = async ({
|
|
2151
|
+
toolSlug,
|
|
2152
|
+
s3Url,
|
|
2153
|
+
mimeType
|
|
2154
|
+
}) => {
|
|
2155
|
+
const response = await fetch(s3Url);
|
|
2156
|
+
if (!response.ok) {
|
|
2157
|
+
throw new Error(`Failed to download file: ${response.statusText}`);
|
|
2158
|
+
}
|
|
2159
|
+
const data = await response.arrayBuffer();
|
|
2160
|
+
const extension = mimeType.split("/")[1] || "txt";
|
|
2161
|
+
const fileName = `${toolSlug}_${Date.now()}.${extension}`;
|
|
2162
|
+
const filePath = saveFile(fileName, Buffer.from(data), true);
|
|
2163
|
+
return {
|
|
2164
|
+
name: fileName,
|
|
2165
|
+
mimeType,
|
|
2166
|
+
s3Url,
|
|
2167
|
+
filePath
|
|
2168
|
+
};
|
|
2169
|
+
};
|
|
2170
|
+
var getComposioDir = (createDirIfNotExists = false) => {
|
|
2171
|
+
try {
|
|
2172
|
+
const os = require("os");
|
|
2173
|
+
const path = require("path");
|
|
2174
|
+
const fs = require("fs");
|
|
2175
|
+
const composioDir = path.join(os.homedir(), COMPOSIO_DIR);
|
|
2176
|
+
if (createDirIfNotExists && !fs.existsSync(composioDir)) {
|
|
2177
|
+
fs.mkdirSync(composioDir, { recursive: true });
|
|
2178
|
+
}
|
|
2179
|
+
return composioDir;
|
|
2180
|
+
} catch (_error) {
|
|
2181
|
+
return null;
|
|
2182
|
+
}
|
|
2183
|
+
};
|
|
2184
|
+
var getComposioTempFilesDir = (createDirIfNotExists = false) => {
|
|
2185
|
+
try {
|
|
2186
|
+
const os = require("os");
|
|
2187
|
+
const path = require("path");
|
|
2188
|
+
const fs = require("fs");
|
|
2189
|
+
const composioFilesDir = path.join(os.homedir(), COMPOSIO_DIR, TEMP_FILES_DIRECTORY_NAME);
|
|
2190
|
+
if (createDirIfNotExists && !fs.existsSync(composioFilesDir)) {
|
|
2191
|
+
fs.mkdirSync(composioFilesDir, { recursive: true });
|
|
2192
|
+
}
|
|
2193
|
+
return composioFilesDir;
|
|
2194
|
+
} catch (_error) {
|
|
2195
|
+
return null;
|
|
2196
|
+
}
|
|
2197
|
+
};
|
|
2198
|
+
var saveFile = (file, content, isTempFile = false) => {
|
|
2199
|
+
try {
|
|
2200
|
+
const path = require("path");
|
|
2201
|
+
const fs = require("fs");
|
|
2202
|
+
const composioFilesDir = isTempFile ? getComposioTempFilesDir(true) : getComposioDir(true);
|
|
2203
|
+
const filePath = path.join(composioFilesDir, path.basename(file));
|
|
2204
|
+
logger_default.info(`Saving file to: ${filePath}`);
|
|
2205
|
+
if (Buffer.isBuffer(content)) {
|
|
2206
|
+
fs.writeFileSync(filePath, content);
|
|
2207
|
+
} else {
|
|
2208
|
+
fs.writeFileSync(filePath, content, "utf8");
|
|
2209
|
+
}
|
|
2210
|
+
return filePath;
|
|
2211
|
+
} catch (_error) {
|
|
2212
|
+
return null;
|
|
2213
|
+
}
|
|
2214
|
+
};
|
|
2215
|
+
|
|
2216
|
+
// src/utils/modifiers/FileToolModifier.ts
|
|
2217
|
+
var transformProperties = (properties) => {
|
|
2218
|
+
const newProperties = {};
|
|
2219
|
+
for (const [key, property] of Object.entries(properties)) {
|
|
2220
|
+
if (!property.file_uploadable) {
|
|
2221
|
+
newProperties[key] = property;
|
|
2222
|
+
continue;
|
|
2223
|
+
}
|
|
2224
|
+
newProperties[key] = {
|
|
2225
|
+
...property,
|
|
2226
|
+
format: "path"
|
|
2227
|
+
};
|
|
2228
|
+
}
|
|
2229
|
+
return newProperties;
|
|
2230
|
+
};
|
|
2231
|
+
var FileToolModifier = class {
|
|
2232
|
+
client;
|
|
2233
|
+
constructor(client) {
|
|
2234
|
+
this.client = client;
|
|
2235
|
+
}
|
|
2236
|
+
/**
|
|
2237
|
+
* Modifies the tool schema to include the file upload URL.
|
|
2238
|
+
*
|
|
2239
|
+
* @description This modifier is used to upload a file to the Composio platform and replace the file path with the file upload URL.
|
|
2240
|
+
*
|
|
2241
|
+
* @param _toolSlug - The slug of the tool that is being executed.
|
|
2242
|
+
* @param _toolkitSlug - The slug of the toolkit that is being executed.
|
|
2243
|
+
* @param schema - The schema of the tool.
|
|
2244
|
+
* @returns The schema with the file upload URL included.
|
|
2245
|
+
*/
|
|
2246
|
+
async modifyToolSchema(toolSlug, toolkitSlug, schema) {
|
|
2247
|
+
if (!schema.inputParameters?.properties) {
|
|
2248
|
+
return schema;
|
|
2249
|
+
}
|
|
2250
|
+
const properties = transformProperties(schema.inputParameters.properties);
|
|
2251
|
+
return {
|
|
2252
|
+
...schema,
|
|
2253
|
+
inputParameters: {
|
|
2254
|
+
...schema.inputParameters,
|
|
2255
|
+
properties
|
|
2256
|
+
}
|
|
2257
|
+
};
|
|
2258
|
+
}
|
|
2259
|
+
/**
|
|
2260
|
+
* Modifies the input parameters to include the file upload URL.
|
|
2261
|
+
*
|
|
2262
|
+
* @description This modifier is used to upload a file to the Composio platform and replace the file path with the file upload URL.
|
|
2263
|
+
*
|
|
2264
|
+
* @param toolSlug - The slug of the tool that is being executed.
|
|
2265
|
+
* @param toolkitSlug - The slug of the toolkit that is being executed.
|
|
2266
|
+
*
|
|
2267
|
+
*/
|
|
2268
|
+
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
|
+
}
|
|
2291
|
+
}
|
|
2292
|
+
return options.params;
|
|
2293
|
+
}
|
|
2294
|
+
/**
|
|
2295
|
+
* Modifies the result to include the file download URL.
|
|
2296
|
+
*
|
|
2297
|
+
* @description This modifier is used to download a file and
|
|
2298
|
+
*
|
|
2299
|
+
* @param toolSlug - The slug of the tool that is being executed.
|
|
2300
|
+
* @param toolkitSlug - The slug of the toolkit that is being executed.
|
|
2301
|
+
* @param result - The result of the tool execution.
|
|
2302
|
+
* @returns The result with the file download URL included.
|
|
2303
|
+
*/
|
|
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;
|
|
2335
|
+
}
|
|
2336
|
+
};
|
|
2337
|
+
|
|
2052
2338
|
// src/models/Tools.ts
|
|
2053
2339
|
var Tools = class {
|
|
2054
2340
|
client;
|
|
2055
2341
|
customTools;
|
|
2056
2342
|
provider;
|
|
2057
|
-
|
|
2343
|
+
autoUploadDownloadFiles;
|
|
2344
|
+
constructor(client, provider, options) {
|
|
2058
2345
|
if (!client) {
|
|
2059
2346
|
throw new Error("ComposioClient is required");
|
|
2060
2347
|
}
|
|
@@ -2064,6 +2351,7 @@ var Tools = class {
|
|
|
2064
2351
|
this.client = client;
|
|
2065
2352
|
this.customTools = new CustomTools(client);
|
|
2066
2353
|
this.provider = provider;
|
|
2354
|
+
this.autoUploadDownloadFiles = options?.autoUploadDownloadFiles ?? true;
|
|
2067
2355
|
this.execute = this.execute.bind(this);
|
|
2068
2356
|
this.provider._setExecuteToolFn(this.execute);
|
|
2069
2357
|
this.getRawComposioToolBySlug = this.getRawComposioToolBySlug.bind(this);
|
|
@@ -2181,6 +2469,93 @@ var Tools = class {
|
|
|
2181
2469
|
}
|
|
2182
2470
|
return null;
|
|
2183
2471
|
}
|
|
2472
|
+
/**
|
|
2473
|
+
* Applies the default schema modifiers to the tools
|
|
2474
|
+
* @param tools - The tools to apply the default schema modifiers to
|
|
2475
|
+
* @returns The tools with the default schema modifiers applied
|
|
2476
|
+
*/
|
|
2477
|
+
async applyDefaultSchemaModifiers(tools) {
|
|
2478
|
+
if (this.autoUploadDownloadFiles) {
|
|
2479
|
+
const fileToolModifier = new FileToolModifier(this.client);
|
|
2480
|
+
return await Promise.all(
|
|
2481
|
+
tools.map(
|
|
2482
|
+
(tool) => fileToolModifier.modifyToolSchema(tool.slug, tool.toolkit?.slug ?? "unknown", tool)
|
|
2483
|
+
)
|
|
2484
|
+
);
|
|
2485
|
+
} else {
|
|
2486
|
+
return tools;
|
|
2487
|
+
}
|
|
2488
|
+
}
|
|
2489
|
+
/**
|
|
2490
|
+
* Applies the before execute modifiers to the tool execution params
|
|
2491
|
+
* @param options.toolSlug - The slug of the tool
|
|
2492
|
+
* @param options.toolkitSlug - The slug of the toolkit
|
|
2493
|
+
* @param options.params - The params of the tool execution
|
|
2494
|
+
* @param modifier - The modifier to apply
|
|
2495
|
+
* @returns The modified params
|
|
2496
|
+
*/
|
|
2497
|
+
async applyBeforeExecuteModifiers(tool, {
|
|
2498
|
+
toolSlug,
|
|
2499
|
+
toolkitSlug,
|
|
2500
|
+
params
|
|
2501
|
+
}, modifier) {
|
|
2502
|
+
let modifiedParams = params;
|
|
2503
|
+
if (this.autoUploadDownloadFiles) {
|
|
2504
|
+
const fileToolModifier = new FileToolModifier(this.client);
|
|
2505
|
+
modifiedParams = await fileToolModifier.fileUploadModifier(tool, {
|
|
2506
|
+
toolSlug,
|
|
2507
|
+
toolkitSlug,
|
|
2508
|
+
params: modifiedParams
|
|
2509
|
+
});
|
|
2510
|
+
}
|
|
2511
|
+
if (modifier) {
|
|
2512
|
+
if (typeof modifier === "function") {
|
|
2513
|
+
modifiedParams = await modifier({
|
|
2514
|
+
toolSlug,
|
|
2515
|
+
toolkitSlug,
|
|
2516
|
+
params: modifiedParams
|
|
2517
|
+
});
|
|
2518
|
+
} else {
|
|
2519
|
+
throw new ComposioInvalidModifierError("Invalid beforeExecute modifier. Not a function.");
|
|
2520
|
+
}
|
|
2521
|
+
}
|
|
2522
|
+
return modifiedParams;
|
|
2523
|
+
}
|
|
2524
|
+
/**
|
|
2525
|
+
* Applies the after execute modifiers to the tool execution result
|
|
2526
|
+
* @param options.toolSlug - The slug of the tool
|
|
2527
|
+
* @param options.toolkitSlug - The slug of the toolkit
|
|
2528
|
+
* @param options.result - The result of the tool execution
|
|
2529
|
+
* @param modifier - The modifier to apply
|
|
2530
|
+
* @returns The modified result
|
|
2531
|
+
*/
|
|
2532
|
+
async applyAfterExecuteModifiers(tool, {
|
|
2533
|
+
toolSlug,
|
|
2534
|
+
toolkitSlug,
|
|
2535
|
+
result
|
|
2536
|
+
}, modifier) {
|
|
2537
|
+
let modifiedResult = result;
|
|
2538
|
+
if (this.autoUploadDownloadFiles) {
|
|
2539
|
+
const fileToolModifier = new FileToolModifier(this.client);
|
|
2540
|
+
modifiedResult = await fileToolModifier.fileDownloadModifier(tool, {
|
|
2541
|
+
toolSlug,
|
|
2542
|
+
toolkitSlug,
|
|
2543
|
+
result: modifiedResult
|
|
2544
|
+
});
|
|
2545
|
+
}
|
|
2546
|
+
if (modifier) {
|
|
2547
|
+
if (typeof modifier === "function") {
|
|
2548
|
+
modifiedResult = await modifier({
|
|
2549
|
+
toolSlug,
|
|
2550
|
+
toolkitSlug,
|
|
2551
|
+
result: modifiedResult
|
|
2552
|
+
});
|
|
2553
|
+
} else {
|
|
2554
|
+
throw new ComposioInvalidModifierError("Invalid afterExecute modifier. Not a function.");
|
|
2555
|
+
}
|
|
2556
|
+
}
|
|
2557
|
+
return modifiedResult;
|
|
2558
|
+
}
|
|
2184
2559
|
/**
|
|
2185
2560
|
* Lists all tools available in the Composio SDK including custom tools.
|
|
2186
2561
|
*
|
|
@@ -2249,11 +2624,18 @@ var Tools = class {
|
|
|
2249
2624
|
const customTools = await this.customTools.getCustomTools({
|
|
2250
2625
|
toolSlugs: "tools" in queryParams.data ? queryParams.data.tools : void 0
|
|
2251
2626
|
});
|
|
2252
|
-
let modifiedTools = [
|
|
2627
|
+
let modifiedTools = await this.applyDefaultSchemaModifiers([
|
|
2628
|
+
...caseTransformedTools,
|
|
2629
|
+
...customTools
|
|
2630
|
+
]);
|
|
2253
2631
|
if (modifier) {
|
|
2254
2632
|
if (typeof modifier === "function") {
|
|
2255
2633
|
const modifiedPromises = modifiedTools.map(
|
|
2256
|
-
(tool) => modifier(
|
|
2634
|
+
(tool) => modifier({
|
|
2635
|
+
toolSlug: tool.slug,
|
|
2636
|
+
toolkitSlug: tool.toolkit?.slug ?? "unknown",
|
|
2637
|
+
schema: tool
|
|
2638
|
+
})
|
|
2257
2639
|
);
|
|
2258
2640
|
modifiedTools = await Promise.all(modifiedPromises);
|
|
2259
2641
|
} else {
|
|
@@ -2289,10 +2671,14 @@ var Tools = class {
|
|
|
2289
2671
|
cause: error
|
|
2290
2672
|
});
|
|
2291
2673
|
}
|
|
2292
|
-
let modifiedTool = this.transformToolCases(tool);
|
|
2674
|
+
let [modifiedTool] = await this.applyDefaultSchemaModifiers([this.transformToolCases(tool)]);
|
|
2293
2675
|
if (modifier) {
|
|
2294
2676
|
if (typeof modifier === "function") {
|
|
2295
|
-
modifiedTool = await modifier(
|
|
2677
|
+
modifiedTool = await modifier({
|
|
2678
|
+
toolSlug: slug,
|
|
2679
|
+
toolkitSlug: modifiedTool.toolkit?.slug ?? "unknown",
|
|
2680
|
+
schema: modifiedTool
|
|
2681
|
+
});
|
|
2296
2682
|
} else {
|
|
2297
2683
|
throw new ComposioInvalidModifierError("Invalid schema modifier. Not a function.");
|
|
2298
2684
|
}
|
|
@@ -2352,7 +2738,11 @@ var Tools = class {
|
|
|
2352
2738
|
async handleCustomToolExecution(tool, body, modifiers) {
|
|
2353
2739
|
if (modifiers?.beforeExecute) {
|
|
2354
2740
|
if (typeof modifiers.beforeExecute === "function") {
|
|
2355
|
-
body = await modifiers.beforeExecute(
|
|
2741
|
+
body = await modifiers.beforeExecute({
|
|
2742
|
+
toolSlug: tool.slug,
|
|
2743
|
+
toolkitSlug: tool.toolkit?.slug ?? "unknown",
|
|
2744
|
+
params: body
|
|
2745
|
+
});
|
|
2356
2746
|
} else {
|
|
2357
2747
|
throw new ComposioInvalidModifierError("Invalid beforeExecute modifier. Not a function.");
|
|
2358
2748
|
}
|
|
@@ -2360,7 +2750,11 @@ var Tools = class {
|
|
|
2360
2750
|
let result = await this.customTools.executeCustomTool(tool.slug, body);
|
|
2361
2751
|
if (modifiers?.afterExecute) {
|
|
2362
2752
|
if (typeof modifiers.afterExecute === "function") {
|
|
2363
|
-
result = await modifiers.afterExecute(
|
|
2753
|
+
result = await modifiers.afterExecute({
|
|
2754
|
+
toolSlug: tool.slug,
|
|
2755
|
+
toolkitSlug: tool.toolkit?.slug ?? "unknown",
|
|
2756
|
+
result
|
|
2757
|
+
});
|
|
2364
2758
|
} else {
|
|
2365
2759
|
throw new ComposioInvalidModifierError("Invalid afterExecute modifier. Not a function.");
|
|
2366
2760
|
}
|
|
@@ -2376,13 +2770,15 @@ var Tools = class {
|
|
|
2376
2770
|
* @returns The response from the tool execution
|
|
2377
2771
|
*/
|
|
2378
2772
|
async handleComposioToolExecution(tool, body, modifiers) {
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2773
|
+
body = await this.applyBeforeExecuteModifiers(
|
|
2774
|
+
tool,
|
|
2775
|
+
{
|
|
2776
|
+
toolSlug: tool.slug,
|
|
2777
|
+
toolkitSlug: tool.toolkit?.slug ?? "unknown",
|
|
2778
|
+
params: body
|
|
2779
|
+
},
|
|
2780
|
+
modifiers?.beforeExecute
|
|
2781
|
+
);
|
|
2386
2782
|
let connectedAccountId = body.connectedAccountId;
|
|
2387
2783
|
if (!connectedAccountId) {
|
|
2388
2784
|
connectedAccountId = await this.getConnectedAccountIdForTool(body.userId, tool.slug) || void 0;
|
|
@@ -2397,13 +2793,15 @@ var Tools = class {
|
|
|
2397
2793
|
text: body.text
|
|
2398
2794
|
});
|
|
2399
2795
|
result = this.transformToolExecuteResponse(result);
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2796
|
+
result = await this.applyAfterExecuteModifiers(
|
|
2797
|
+
tool,
|
|
2798
|
+
{
|
|
2799
|
+
toolSlug: tool.slug,
|
|
2800
|
+
toolkitSlug: tool.toolkit?.slug ?? "unknown",
|
|
2801
|
+
result
|
|
2802
|
+
},
|
|
2803
|
+
modifiers?.afterExecute
|
|
2804
|
+
);
|
|
2407
2805
|
return result;
|
|
2408
2806
|
}
|
|
2409
2807
|
/**
|
|
@@ -5664,7 +6062,48 @@ var OpenAIProvider = class extends BaseNonAgenticProvider {
|
|
|
5664
6062
|
};
|
|
5665
6063
|
|
|
5666
6064
|
// package.json
|
|
5667
|
-
var version = "0.1.
|
|
6065
|
+
var version = "0.1.30";
|
|
6066
|
+
|
|
6067
|
+
// src/models/Files.ts
|
|
6068
|
+
var Files = class {
|
|
6069
|
+
constructor(client) {
|
|
6070
|
+
this.client = client;
|
|
6071
|
+
telemetry.instrument(this);
|
|
6072
|
+
}
|
|
6073
|
+
/**
|
|
6074
|
+
* Upload a file to S3 and return the file data.
|
|
6075
|
+
* @param filePath - The path to the file to upload or a URL of the file to upload.
|
|
6076
|
+
* @param toolSlug - The slug of the tool that is uploading the file.
|
|
6077
|
+
* @param toolkitSlug - The slug of the toolkit that is uploading the file.
|
|
6078
|
+
* @returns The file data.
|
|
6079
|
+
*/
|
|
6080
|
+
async upload({
|
|
6081
|
+
filePath,
|
|
6082
|
+
toolSlug,
|
|
6083
|
+
toolkitSlug
|
|
6084
|
+
}) {
|
|
6085
|
+
const fileData = await getFileDataAfterUploadingToS3({
|
|
6086
|
+
path: filePath,
|
|
6087
|
+
toolSlug,
|
|
6088
|
+
toolkitSlug,
|
|
6089
|
+
client: this.client
|
|
6090
|
+
});
|
|
6091
|
+
return fileData;
|
|
6092
|
+
}
|
|
6093
|
+
/**
|
|
6094
|
+
* Download a file from S3 and return the file data.
|
|
6095
|
+
* @param s3key - The S3 key of the file to download.
|
|
6096
|
+
* @returns The file data.
|
|
6097
|
+
*/
|
|
6098
|
+
async download({
|
|
6099
|
+
toolSlug,
|
|
6100
|
+
s3Url,
|
|
6101
|
+
mimeType
|
|
6102
|
+
}) {
|
|
6103
|
+
const fileDownloadData = await downloadFileFromS3({ toolSlug, s3Url, mimeType });
|
|
6104
|
+
return fileDownloadData;
|
|
6105
|
+
}
|
|
6106
|
+
};
|
|
5668
6107
|
|
|
5669
6108
|
// src/composio.ts
|
|
5670
6109
|
var Composio = class _Composio {
|
|
@@ -5685,6 +6124,7 @@ var Composio = class _Composio {
|
|
|
5685
6124
|
toolkits;
|
|
5686
6125
|
triggers;
|
|
5687
6126
|
provider;
|
|
6127
|
+
files;
|
|
5688
6128
|
// auth configs
|
|
5689
6129
|
authConfigs;
|
|
5690
6130
|
// connected accounts
|
|
@@ -5700,7 +6140,6 @@ var Composio = class _Composio {
|
|
|
5700
6140
|
* @param {string} [config.apiKey] - The API key for authenticating with the Composio API
|
|
5701
6141
|
* @param {string} [config.baseURL] - The base URL for the Composio API (defaults to production URL)
|
|
5702
6142
|
* @param {boolean} [config.allowTracking=true] - Whether to allow anonymous usage analytics
|
|
5703
|
-
* @param {boolean} [config.allowTracing=true] - Whether to allow request tracing for debugging
|
|
5704
6143
|
* @param {TProvider} [config.provider] - The provider to use for this Composio instance (defaults to OpenAIProvider)
|
|
5705
6144
|
*
|
|
5706
6145
|
* @example
|
|
@@ -5737,15 +6176,17 @@ var Composio = class _Composio {
|
|
|
5737
6176
|
});
|
|
5738
6177
|
this.config = {
|
|
5739
6178
|
...config,
|
|
5740
|
-
allowTracking: config?.allowTracking ?? true
|
|
5741
|
-
allowTracing: config?.allowTracing ?? true
|
|
6179
|
+
allowTracking: config?.allowTracking ?? true
|
|
5742
6180
|
};
|
|
5743
6181
|
this.provider = config?.provider ?? new OpenAIProvider();
|
|
5744
|
-
this.tools = new Tools(this.client, this.provider
|
|
6182
|
+
this.tools = new Tools(this.client, this.provider, {
|
|
6183
|
+
autoUploadDownloadFiles: config?.autoUploadDownloadFiles ?? true
|
|
6184
|
+
});
|
|
5745
6185
|
this.mcp = new MCP(this.client, this.provider);
|
|
5746
6186
|
this.toolkits = new Toolkits(this.client);
|
|
5747
6187
|
this.triggers = new Triggers(this.client);
|
|
5748
6188
|
this.authConfigs = new AuthConfigs(this.client);
|
|
6189
|
+
this.files = new Files(this.client);
|
|
5749
6190
|
this.connectedAccounts = new ConnectedAccounts(this.client);
|
|
5750
6191
|
if (this.config.allowTracking) {
|
|
5751
6192
|
telemetry.setup({
|
|
@@ -5755,11 +6196,7 @@ var Composio = class _Composio {
|
|
|
5755
6196
|
version,
|
|
5756
6197
|
isBrowser: typeof window !== "undefined",
|
|
5757
6198
|
provider: this.provider?.name ?? "openai",
|
|
5758
|
-
host: this.config.host
|
|
5759
|
-
// @TODO: Users might want to pass their own session id
|
|
5760
|
-
// @TODO: We shouldn't be doing this as people might always have one session id throughout the process in server
|
|
5761
|
-
sessionId: this.config.allowTracing ? getRandomUUID() : void 0
|
|
5762
|
-
// @TODO: get the session id
|
|
6199
|
+
host: this.config.host
|
|
5763
6200
|
});
|
|
5764
6201
|
}
|
|
5765
6202
|
telemetry.instrument(this);
|
|
@@ -6070,6 +6507,7 @@ var AuthScheme = class {
|
|
|
6070
6507
|
GenerateURLResponseCamelCaseSchema,
|
|
6071
6508
|
GenerateURLResponseSchema,
|
|
6072
6509
|
IncomingTriggerPayloadSchema,
|
|
6510
|
+
JSONSchemaPropertySchema,
|
|
6073
6511
|
JsonSchemaToZodError,
|
|
6074
6512
|
MCP,
|
|
6075
6513
|
MCPAuthOptionsSchema,
|