@composio/core 0.1.27 → 0.1.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +461 -86
- package/dist/index.d.cts +392 -214
- package/dist/index.d.ts +392 -214
- package/dist/index.js +460 -86
- package/package.json +2 -1
package/dist/index.js
CHANGED
|
@@ -29,19 +29,21 @@ var JSONSchemaType = z.enum([
|
|
|
29
29
|
"array",
|
|
30
30
|
"null"
|
|
31
31
|
]);
|
|
32
|
-
var
|
|
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(
|
|
36
|
-
oneOf: z.lazy(() => z.array(
|
|
37
|
-
allOf: z.lazy(() => z.array(
|
|
38
|
-
not: z.lazy(() =>
|
|
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(),
|
|
42
|
+
properties: z.lazy(() => z.record(z.string(), JSONSchemaPropertySchema)).optional(),
|
|
43
43
|
required: z.array(z.string()).optional(),
|
|
44
|
-
|
|
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(),
|
|
62
|
-
additionalProperties: z.union([z.boolean(), z.lazy(() =>
|
|
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(() =>
|
|
67
|
-
then: z.lazy(() =>
|
|
68
|
-
else: z.lazy(() =>
|
|
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(() =>
|
|
74
|
+
z.lazy(() => JSONSchemaPropertySchema)
|
|
73
75
|
).optional(),
|
|
74
76
|
$defs: z.record(
|
|
75
77
|
z.string(),
|
|
76
|
-
z.lazy(() =>
|
|
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(
|
|
82
|
-
oneOf: z.array(
|
|
83
|
-
allOf: z.array(
|
|
84
|
-
not:
|
|
85
|
-
properties: z.record(z.string(),
|
|
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,6 +1904,286 @@ 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 (path, toolSlug, toolkitSlug, client) => {
|
|
1979
|
+
const isURL = path.startsWith("http");
|
|
1980
|
+
const fileData = isURL ? await readFileContentFromURL(path) : await readFileContent(path);
|
|
1981
|
+
logger_default.debug(`Uploading file to S3: ${path}`);
|
|
1982
|
+
const s3key = await uploadFileToS3(
|
|
1983
|
+
pathModule.basename(path) || `${toolSlug}_${Date.now()}`,
|
|
1984
|
+
fileData.content,
|
|
1985
|
+
toolSlug,
|
|
1986
|
+
toolkitSlug,
|
|
1987
|
+
fileData.mimeType,
|
|
1988
|
+
client
|
|
1989
|
+
);
|
|
1990
|
+
logger_default.debug(`Done! File uploaded to S3: ${s3key}`, JSON.stringify(fileData, null, 2));
|
|
1991
|
+
return {
|
|
1992
|
+
name: pathModule.basename(path) || `${toolSlug}_${Date.now()}.${fileData.mimeType.split("/")[1]}`,
|
|
1993
|
+
mimetype: fileData.mimeType,
|
|
1994
|
+
s3key
|
|
1995
|
+
};
|
|
1996
|
+
};
|
|
1997
|
+
var downloadFileFromS3 = async ({
|
|
1998
|
+
toolSlug,
|
|
1999
|
+
s3Url,
|
|
2000
|
+
mimeType
|
|
2001
|
+
}) => {
|
|
2002
|
+
const response = await fetch(s3Url);
|
|
2003
|
+
if (!response.ok) {
|
|
2004
|
+
throw new Error(`Failed to download file: ${response.statusText}`);
|
|
2005
|
+
}
|
|
2006
|
+
const data = await response.arrayBuffer();
|
|
2007
|
+
const extension = mimeType.split("/")[1] || "txt";
|
|
2008
|
+
const fileName = `${toolSlug}_${Date.now()}.${extension}`;
|
|
2009
|
+
const filePath = saveFile(fileName, Buffer.from(data), true);
|
|
2010
|
+
return {
|
|
2011
|
+
name: fileName,
|
|
2012
|
+
mimeType,
|
|
2013
|
+
s3Key: s3Url,
|
|
2014
|
+
filePath
|
|
2015
|
+
};
|
|
2016
|
+
};
|
|
2017
|
+
var getComposioDir = (createDirIfNotExists = false) => {
|
|
2018
|
+
try {
|
|
2019
|
+
const os = __require("os");
|
|
2020
|
+
const path = __require("path");
|
|
2021
|
+
const fs = __require("fs");
|
|
2022
|
+
const composioDir = path.join(os.homedir(), COMPOSIO_DIR);
|
|
2023
|
+
if (createDirIfNotExists && !fs.existsSync(composioDir)) {
|
|
2024
|
+
fs.mkdirSync(composioDir, { recursive: true });
|
|
2025
|
+
}
|
|
2026
|
+
return composioDir;
|
|
2027
|
+
} catch (_error) {
|
|
2028
|
+
return null;
|
|
2029
|
+
}
|
|
2030
|
+
};
|
|
2031
|
+
var getComposioTempFilesDir = (createDirIfNotExists = false) => {
|
|
2032
|
+
try {
|
|
2033
|
+
const os = __require("os");
|
|
2034
|
+
const path = __require("path");
|
|
2035
|
+
const fs = __require("fs");
|
|
2036
|
+
const composioFilesDir = path.join(os.homedir(), COMPOSIO_DIR, TEMP_FILES_DIRECTORY_NAME);
|
|
2037
|
+
if (createDirIfNotExists && !fs.existsSync(composioFilesDir)) {
|
|
2038
|
+
fs.mkdirSync(composioFilesDir, { recursive: true });
|
|
2039
|
+
}
|
|
2040
|
+
return composioFilesDir;
|
|
2041
|
+
} catch (_error) {
|
|
2042
|
+
return null;
|
|
2043
|
+
}
|
|
2044
|
+
};
|
|
2045
|
+
var saveFile = (file, content, isTempFile = false) => {
|
|
2046
|
+
try {
|
|
2047
|
+
const path = __require("path");
|
|
2048
|
+
const fs = __require("fs");
|
|
2049
|
+
const composioFilesDir = isTempFile ? getComposioTempFilesDir(true) : getComposioDir(true);
|
|
2050
|
+
const filePath = path.join(composioFilesDir, path.basename(file));
|
|
2051
|
+
logger_default.info(`Saving file to: ${filePath}`);
|
|
2052
|
+
if (Buffer.isBuffer(content)) {
|
|
2053
|
+
fs.writeFileSync(filePath, content);
|
|
2054
|
+
} else {
|
|
2055
|
+
fs.writeFileSync(filePath, content, "utf8");
|
|
2056
|
+
}
|
|
2057
|
+
return filePath;
|
|
2058
|
+
} catch (_error) {
|
|
2059
|
+
return null;
|
|
2060
|
+
}
|
|
2061
|
+
};
|
|
2062
|
+
|
|
2063
|
+
// src/utils/modifiers/FileToolModifier.ts
|
|
2064
|
+
var transformProperties = (properties) => {
|
|
2065
|
+
const newProperties = {};
|
|
2066
|
+
for (const [key, property] of Object.entries(properties)) {
|
|
2067
|
+
if (!property.file_uploadable) {
|
|
2068
|
+
newProperties[key] = property;
|
|
2069
|
+
continue;
|
|
2070
|
+
}
|
|
2071
|
+
newProperties[key] = {
|
|
2072
|
+
...property,
|
|
2073
|
+
format: "path"
|
|
2074
|
+
};
|
|
2075
|
+
}
|
|
2076
|
+
return properties;
|
|
2077
|
+
};
|
|
2078
|
+
var FileToolModifier = class {
|
|
2079
|
+
client;
|
|
2080
|
+
constructor(client) {
|
|
2081
|
+
this.client = client;
|
|
2082
|
+
}
|
|
2083
|
+
/**
|
|
2084
|
+
* Modifies the tool schema to include the file upload URL.
|
|
2085
|
+
*
|
|
2086
|
+
* @description This modifier is used to upload a file to the Composio platform and replace the file path with the file upload URL.
|
|
2087
|
+
*
|
|
2088
|
+
* @param _toolSlug - The slug of the tool that is being executed.
|
|
2089
|
+
* @param _toolkitSlug - The slug of the toolkit that is being executed.
|
|
2090
|
+
* @param schema - The schema of the tool.
|
|
2091
|
+
* @returns The schema with the file upload URL included.
|
|
2092
|
+
*/
|
|
2093
|
+
async modifyToolSchema(toolSlug, toolkitSlug, schema) {
|
|
2094
|
+
if (!schema.inputParameters?.properties) {
|
|
2095
|
+
return schema;
|
|
2096
|
+
}
|
|
2097
|
+
const properties = transformProperties(schema.inputParameters.properties);
|
|
2098
|
+
return {
|
|
2099
|
+
...schema,
|
|
2100
|
+
inputParameters: {
|
|
2101
|
+
...schema.inputParameters,
|
|
2102
|
+
properties
|
|
2103
|
+
}
|
|
2104
|
+
};
|
|
2105
|
+
}
|
|
2106
|
+
/**
|
|
2107
|
+
* Modifies the input parameters to include the file upload URL.
|
|
2108
|
+
*
|
|
2109
|
+
* @description This modifier is used to upload a file to the Composio platform and replace the file path with the file upload URL.
|
|
2110
|
+
*
|
|
2111
|
+
* @param toolSlug - The slug of the tool that is being executed.
|
|
2112
|
+
* @param toolkitSlug - The slug of the toolkit that is being executed.
|
|
2113
|
+
*
|
|
2114
|
+
*/
|
|
2115
|
+
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
|
+
}
|
|
2138
|
+
}
|
|
2139
|
+
return options.params;
|
|
2140
|
+
}
|
|
2141
|
+
/**
|
|
2142
|
+
* Modifies the result to include the file download URL.
|
|
2143
|
+
*
|
|
2144
|
+
* @description This modifier is used to download a file and
|
|
2145
|
+
*
|
|
2146
|
+
* @param toolSlug - The slug of the tool that is being executed.
|
|
2147
|
+
* @param toolkitSlug - The slug of the toolkit that is being executed.
|
|
2148
|
+
* @param result - The result of the tool execution.
|
|
2149
|
+
* @returns The result with the file download URL included.
|
|
2150
|
+
*/
|
|
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;
|
|
2184
|
+
}
|
|
2185
|
+
};
|
|
2186
|
+
|
|
1905
2187
|
// src/models/Tools.ts
|
|
1906
2188
|
var Tools = class {
|
|
1907
2189
|
client;
|
|
@@ -2034,6 +2316,85 @@ var Tools = class {
|
|
|
2034
2316
|
}
|
|
2035
2317
|
return null;
|
|
2036
2318
|
}
|
|
2319
|
+
/**
|
|
2320
|
+
* Applies the default schema modifiers to the tools
|
|
2321
|
+
* @param tools - The tools to apply the default schema modifiers to
|
|
2322
|
+
* @returns The tools with the default schema modifiers applied
|
|
2323
|
+
*/
|
|
2324
|
+
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
|
+
);
|
|
2331
|
+
}
|
|
2332
|
+
/**
|
|
2333
|
+
* Applies the before execute modifiers to the tool execution params
|
|
2334
|
+
* @param options.toolSlug - The slug of the tool
|
|
2335
|
+
* @param options.toolkitSlug - The slug of the toolkit
|
|
2336
|
+
* @param options.params - The params of the tool execution
|
|
2337
|
+
* @param modifier - The modifier to apply
|
|
2338
|
+
* @returns The modified params
|
|
2339
|
+
*/
|
|
2340
|
+
async applyBeforeExecuteModifiers(tool, {
|
|
2341
|
+
toolSlug,
|
|
2342
|
+
toolkitSlug,
|
|
2343
|
+
params
|
|
2344
|
+
}, modifier) {
|
|
2345
|
+
const fileToolModifier = new FileToolModifier(this.client);
|
|
2346
|
+
let modifiedParams = params;
|
|
2347
|
+
if (modifier) {
|
|
2348
|
+
if (typeof modifier === "function") {
|
|
2349
|
+
modifiedParams = await modifier({
|
|
2350
|
+
toolSlug,
|
|
2351
|
+
toolkitSlug,
|
|
2352
|
+
params: modifiedParams
|
|
2353
|
+
});
|
|
2354
|
+
} else {
|
|
2355
|
+
throw new ComposioInvalidModifierError("Invalid beforeExecute modifier. Not a function.");
|
|
2356
|
+
}
|
|
2357
|
+
}
|
|
2358
|
+
modifiedParams = await fileToolModifier.fileUploadModifier(tool, {
|
|
2359
|
+
toolSlug,
|
|
2360
|
+
toolkitSlug,
|
|
2361
|
+
params: modifiedParams
|
|
2362
|
+
});
|
|
2363
|
+
return modifiedParams;
|
|
2364
|
+
}
|
|
2365
|
+
/**
|
|
2366
|
+
* Applies the after execute modifiers to the tool execution result
|
|
2367
|
+
* @param options.toolSlug - The slug of the tool
|
|
2368
|
+
* @param options.toolkitSlug - The slug of the toolkit
|
|
2369
|
+
* @param options.result - The result of the tool execution
|
|
2370
|
+
* @param modifier - The modifier to apply
|
|
2371
|
+
* @returns The modified result
|
|
2372
|
+
*/
|
|
2373
|
+
async applyAfterExecuteModifiers(tool, {
|
|
2374
|
+
toolSlug,
|
|
2375
|
+
toolkitSlug,
|
|
2376
|
+
result
|
|
2377
|
+
}, modifier) {
|
|
2378
|
+
const fileToolModifier = new FileToolModifier(this.client);
|
|
2379
|
+
let modifiedResult = result;
|
|
2380
|
+
if (modifier) {
|
|
2381
|
+
if (typeof modifier === "function") {
|
|
2382
|
+
modifiedResult = await modifier({
|
|
2383
|
+
toolSlug,
|
|
2384
|
+
toolkitSlug,
|
|
2385
|
+
result: modifiedResult
|
|
2386
|
+
});
|
|
2387
|
+
} else {
|
|
2388
|
+
throw new ComposioInvalidModifierError("Invalid afterExecute modifier. Not a function.");
|
|
2389
|
+
}
|
|
2390
|
+
}
|
|
2391
|
+
modifiedResult = await fileToolModifier.fileDownloadModifier(tool, {
|
|
2392
|
+
toolSlug,
|
|
2393
|
+
toolkitSlug,
|
|
2394
|
+
result: modifiedResult
|
|
2395
|
+
});
|
|
2396
|
+
return modifiedResult;
|
|
2397
|
+
}
|
|
2037
2398
|
/**
|
|
2038
2399
|
* Lists all tools available in the Composio SDK including custom tools.
|
|
2039
2400
|
*
|
|
@@ -2093,7 +2454,7 @@ var Tools = class {
|
|
|
2093
2454
|
..."scopes" in queryParams.data ? { scopes: queryParams.data.scopes } : {},
|
|
2094
2455
|
..."search" in queryParams.data ? { search: queryParams.data.search } : {}
|
|
2095
2456
|
};
|
|
2096
|
-
logger_default.
|
|
2457
|
+
logger_default.debug(`Fetching tools with filters: ${JSON.stringify(filters, null, 2)}`);
|
|
2097
2458
|
const tools = await this.client.tools.list(filters);
|
|
2098
2459
|
if (!tools) {
|
|
2099
2460
|
return [];
|
|
@@ -2102,11 +2463,18 @@ var Tools = class {
|
|
|
2102
2463
|
const customTools = await this.customTools.getCustomTools({
|
|
2103
2464
|
toolSlugs: "tools" in queryParams.data ? queryParams.data.tools : void 0
|
|
2104
2465
|
});
|
|
2105
|
-
let modifiedTools = [
|
|
2466
|
+
let modifiedTools = await this.applyDefaultSchemaModifiers([
|
|
2467
|
+
...caseTransformedTools,
|
|
2468
|
+
...customTools
|
|
2469
|
+
]);
|
|
2106
2470
|
if (modifier) {
|
|
2107
2471
|
if (typeof modifier === "function") {
|
|
2108
2472
|
const modifiedPromises = modifiedTools.map(
|
|
2109
|
-
(tool) => modifier(
|
|
2473
|
+
(tool) => modifier({
|
|
2474
|
+
toolSlug: tool.slug,
|
|
2475
|
+
toolkitSlug: tool.toolkit?.slug ?? "unknown",
|
|
2476
|
+
schema: tool
|
|
2477
|
+
})
|
|
2110
2478
|
);
|
|
2111
2479
|
modifiedTools = await Promise.all(modifiedPromises);
|
|
2112
2480
|
} else {
|
|
@@ -2142,10 +2510,14 @@ var Tools = class {
|
|
|
2142
2510
|
cause: error
|
|
2143
2511
|
});
|
|
2144
2512
|
}
|
|
2145
|
-
let modifiedTool = this.transformToolCases(tool);
|
|
2513
|
+
let [modifiedTool] = await this.applyDefaultSchemaModifiers([this.transformToolCases(tool)]);
|
|
2146
2514
|
if (modifier) {
|
|
2147
2515
|
if (typeof modifier === "function") {
|
|
2148
|
-
modifiedTool = await modifier(
|
|
2516
|
+
modifiedTool = await modifier({
|
|
2517
|
+
toolSlug: slug,
|
|
2518
|
+
toolkitSlug: modifiedTool.toolkit?.slug ?? "unknown",
|
|
2519
|
+
schema: modifiedTool
|
|
2520
|
+
});
|
|
2149
2521
|
} else {
|
|
2150
2522
|
throw new ComposioInvalidModifierError("Invalid schema modifier. Not a function.");
|
|
2151
2523
|
}
|
|
@@ -2205,7 +2577,11 @@ var Tools = class {
|
|
|
2205
2577
|
async handleCustomToolExecution(tool, body, modifiers) {
|
|
2206
2578
|
if (modifiers?.beforeExecute) {
|
|
2207
2579
|
if (typeof modifiers.beforeExecute === "function") {
|
|
2208
|
-
body = await modifiers.beforeExecute(
|
|
2580
|
+
body = await modifiers.beforeExecute({
|
|
2581
|
+
toolSlug: tool.slug,
|
|
2582
|
+
toolkitSlug: tool.toolkit?.slug ?? "unknown",
|
|
2583
|
+
params: body
|
|
2584
|
+
});
|
|
2209
2585
|
} else {
|
|
2210
2586
|
throw new ComposioInvalidModifierError("Invalid beforeExecute modifier. Not a function.");
|
|
2211
2587
|
}
|
|
@@ -2213,7 +2589,11 @@ var Tools = class {
|
|
|
2213
2589
|
let result = await this.customTools.executeCustomTool(tool.slug, body);
|
|
2214
2590
|
if (modifiers?.afterExecute) {
|
|
2215
2591
|
if (typeof modifiers.afterExecute === "function") {
|
|
2216
|
-
result = await modifiers.afterExecute(
|
|
2592
|
+
result = await modifiers.afterExecute({
|
|
2593
|
+
toolSlug: tool.slug,
|
|
2594
|
+
toolkitSlug: tool.toolkit?.slug ?? "unknown",
|
|
2595
|
+
result
|
|
2596
|
+
});
|
|
2217
2597
|
} else {
|
|
2218
2598
|
throw new ComposioInvalidModifierError("Invalid afterExecute modifier. Not a function.");
|
|
2219
2599
|
}
|
|
@@ -2229,13 +2609,15 @@ var Tools = class {
|
|
|
2229
2609
|
* @returns The response from the tool execution
|
|
2230
2610
|
*/
|
|
2231
2611
|
async handleComposioToolExecution(tool, body, modifiers) {
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2612
|
+
body = await this.applyBeforeExecuteModifiers(
|
|
2613
|
+
tool,
|
|
2614
|
+
{
|
|
2615
|
+
toolSlug: tool.slug,
|
|
2616
|
+
toolkitSlug: tool.toolkit?.slug ?? "unknown",
|
|
2617
|
+
params: body
|
|
2618
|
+
},
|
|
2619
|
+
modifiers?.beforeExecute
|
|
2620
|
+
);
|
|
2239
2621
|
let connectedAccountId = body.connectedAccountId;
|
|
2240
2622
|
if (!connectedAccountId) {
|
|
2241
2623
|
connectedAccountId = await this.getConnectedAccountIdForTool(body.userId, tool.slug) || void 0;
|
|
@@ -2250,13 +2632,15 @@ var Tools = class {
|
|
|
2250
2632
|
text: body.text
|
|
2251
2633
|
});
|
|
2252
2634
|
result = this.transformToolExecuteResponse(result);
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2635
|
+
result = await this.applyAfterExecuteModifiers(
|
|
2636
|
+
tool,
|
|
2637
|
+
{
|
|
2638
|
+
toolSlug: tool.slug,
|
|
2639
|
+
toolkitSlug: tool.toolkit?.slug ?? "unknown",
|
|
2640
|
+
result
|
|
2641
|
+
},
|
|
2642
|
+
modifiers?.afterExecute
|
|
2643
|
+
);
|
|
2260
2644
|
return result;
|
|
2261
2645
|
}
|
|
2262
2646
|
/**
|
|
@@ -4935,31 +5319,37 @@ var MCP = class {
|
|
|
4935
5319
|
return transformMcpGenerateUrlResponse(urlResponse);
|
|
4936
5320
|
}
|
|
4937
5321
|
/**
|
|
4938
|
-
|
|
4939
|
-
|
|
4940
|
-
|
|
4941
|
-
|
|
4942
|
-
|
|
4943
|
-
|
|
4944
|
-
|
|
4945
|
-
|
|
4946
|
-
|
|
4947
|
-
* @returns Transformed response in appropriate format
|
|
4948
|
-
*/
|
|
5322
|
+
* Transform MCP URL response into the appropriate format.
|
|
5323
|
+
* If the provider has a custom transform method, use it.
|
|
5324
|
+
* Otherwise, use the default transformation.
|
|
5325
|
+
*
|
|
5326
|
+
* @param data - The MCP URL response data (in camelCase)
|
|
5327
|
+
* @param serverName - Name of the MCP server
|
|
5328
|
+
|
|
5329
|
+
* @returns Transformed response in appropriate format
|
|
5330
|
+
*/
|
|
4949
5331
|
wrapMcpServerResponse(data, serverName, connectedAccountIds, userIds, toolkits) {
|
|
4950
5332
|
if (this.provider && typeof this.provider.wrapMcpServerResponse === "function") {
|
|
4951
|
-
|
|
4952
|
-
|
|
4953
|
-
|
|
4954
|
-
|
|
4955
|
-
|
|
4956
|
-
|
|
4957
|
-
|
|
4958
|
-
|
|
4959
|
-
|
|
4960
|
-
|
|
4961
|
-
|
|
4962
|
-
|
|
5333
|
+
let snakeCaseData;
|
|
5334
|
+
if (data.connectedAccountUrls?.length) {
|
|
5335
|
+
snakeCaseData = data.connectedAccountUrls.map((url, index) => ({
|
|
5336
|
+
name: serverName + "-" + connectedAccountIds?.[index],
|
|
5337
|
+
url
|
|
5338
|
+
}));
|
|
5339
|
+
} else if (data.userIdsUrl?.length) {
|
|
5340
|
+
snakeCaseData = data.userIdsUrl.map((url, index) => ({
|
|
5341
|
+
name: serverName + "-" + userIds?.[index],
|
|
5342
|
+
url
|
|
5343
|
+
}));
|
|
5344
|
+
} else {
|
|
5345
|
+
snakeCaseData = [
|
|
5346
|
+
{
|
|
5347
|
+
name: serverName,
|
|
5348
|
+
url: data.mcpUrl
|
|
5349
|
+
}
|
|
5350
|
+
];
|
|
5351
|
+
}
|
|
5352
|
+
const transformed = this.provider.wrapMcpServerResponse(snakeCaseData);
|
|
4963
5353
|
return transformed;
|
|
4964
5354
|
}
|
|
4965
5355
|
if (connectedAccountIds?.length && data.connectedAccountUrls) {
|
|
@@ -5114,30 +5504,13 @@ var OpenAIProvider = class extends BaseNonAgenticProvider {
|
|
|
5114
5504
|
* OpenAI uses the standard format by default.
|
|
5115
5505
|
*
|
|
5116
5506
|
* @param data - The MCP URL response data
|
|
5117
|
-
* @param serverName - Name of the MCP server
|
|
5118
|
-
* @param connectedAccountIds - Optional array of connected account IDs
|
|
5119
|
-
* @param userIds - Optional array of user IDs
|
|
5120
|
-
* @param toolkits - Optional array of toolkit names
|
|
5121
5507
|
* @returns Standard MCP server response format
|
|
5122
5508
|
*/
|
|
5123
|
-
wrapMcpServerResponse(data
|
|
5124
|
-
|
|
5125
|
-
|
|
5126
|
-
|
|
5127
|
-
|
|
5128
|
-
toolkit: toolkits?.[index]
|
|
5129
|
-
}));
|
|
5130
|
-
} else if (userIds?.length && data.user_ids_url) {
|
|
5131
|
-
return data.user_ids_url.map((url, index) => ({
|
|
5132
|
-
url: new URL(url),
|
|
5133
|
-
name: `${serverName}-${userIds[index]}`,
|
|
5134
|
-
toolkit: toolkits?.[index]
|
|
5135
|
-
}));
|
|
5136
|
-
}
|
|
5137
|
-
return {
|
|
5138
|
-
url: new URL(data.mcp_url),
|
|
5139
|
-
name: serverName
|
|
5140
|
-
};
|
|
5509
|
+
wrapMcpServerResponse(data) {
|
|
5510
|
+
return data.map((item) => ({
|
|
5511
|
+
url: new URL(item.url),
|
|
5512
|
+
name: item.name
|
|
5513
|
+
}));
|
|
5141
5514
|
}
|
|
5142
5515
|
/**
|
|
5143
5516
|
* Wraps a Composio tool in the OpenAI function calling format.
|
|
@@ -5528,7 +5901,7 @@ var OpenAIProvider = class extends BaseNonAgenticProvider {
|
|
|
5528
5901
|
};
|
|
5529
5902
|
|
|
5530
5903
|
// package.json
|
|
5531
|
-
var version = "0.1.
|
|
5904
|
+
var version = "0.1.29";
|
|
5532
5905
|
|
|
5533
5906
|
// src/composio.ts
|
|
5534
5907
|
var Composio = class _Composio {
|
|
@@ -5933,6 +6306,7 @@ export {
|
|
|
5933
6306
|
GenerateURLResponseCamelCaseSchema,
|
|
5934
6307
|
GenerateURLResponseSchema,
|
|
5935
6308
|
IncomingTriggerPayloadSchema,
|
|
6309
|
+
JSONSchemaPropertySchema,
|
|
5936
6310
|
JsonSchemaToZodError,
|
|
5937
6311
|
MCP,
|
|
5938
6312
|
MCPAuthOptionsSchema,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@composio/core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.29",
|
|
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",
|