@composio/core 0.1.30 → 0.1.32
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 +194 -97
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +194 -97
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -843,13 +843,18 @@ var TelemetryService = class {
|
|
|
843
843
|
* @returns The response from the Telemetry API.
|
|
844
844
|
*/
|
|
845
845
|
static async sendMetric(payload) {
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
846
|
+
try {
|
|
847
|
+
const result = await fetch(`${TELEMETRY_URL2}/metrics/invocations`, {
|
|
848
|
+
method: "POST",
|
|
849
|
+
headers: {
|
|
850
|
+
"Content-Type": "application/json"
|
|
851
|
+
},
|
|
852
|
+
body: JSON.stringify(payload)
|
|
853
|
+
});
|
|
854
|
+
return result;
|
|
855
|
+
} catch (error) {
|
|
856
|
+
logger_default.debug("Error sending metric telemetry", error);
|
|
857
|
+
}
|
|
853
858
|
}
|
|
854
859
|
/**
|
|
855
860
|
* Sends an error log to the Telemetry API.
|
|
@@ -857,13 +862,18 @@ var TelemetryService = class {
|
|
|
857
862
|
* @returns The response from the Telemetry API.
|
|
858
863
|
*/
|
|
859
864
|
static async sendErrorLog(payload) {
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
865
|
+
try {
|
|
866
|
+
const result = await fetch(`${TELEMETRY_URL2}/errors`, {
|
|
867
|
+
method: "POST",
|
|
868
|
+
headers: {
|
|
869
|
+
"Content-Type": "application/json"
|
|
870
|
+
},
|
|
871
|
+
body: JSON.stringify(payload)
|
|
872
|
+
});
|
|
873
|
+
return result;
|
|
874
|
+
} catch (error) {
|
|
875
|
+
logger_default.debug("Error sending error telemetry", error);
|
|
876
|
+
}
|
|
867
877
|
}
|
|
868
878
|
};
|
|
869
879
|
|
|
@@ -2074,6 +2084,7 @@ var readFileContent = async (path) => {
|
|
|
2074
2084
|
try {
|
|
2075
2085
|
const content = require("fs").readFileSync(path);
|
|
2076
2086
|
return {
|
|
2087
|
+
fileName: path,
|
|
2077
2088
|
content: content.toString("base64"),
|
|
2078
2089
|
mimeType: "application/octet-stream"
|
|
2079
2090
|
};
|
|
@@ -2091,7 +2102,8 @@ var readFileContentFromURL = async (path) => {
|
|
|
2091
2102
|
const mimeType = response.headers.get("content-type") || "application/octet-stream";
|
|
2092
2103
|
return {
|
|
2093
2104
|
content: content.toString("base64"),
|
|
2094
|
-
mimeType
|
|
2105
|
+
mimeType,
|
|
2106
|
+
fileName: path
|
|
2095
2107
|
};
|
|
2096
2108
|
};
|
|
2097
2109
|
var uploadFileToS3 = async (fileName, content, toolSlug, toolkitSlug, mimeType, client) => {
|
|
@@ -2123,17 +2135,35 @@ var uploadFileToS3 = async (fileName, content, toolSlug, toolkitSlug, mimeType,
|
|
|
2123
2135
|
}
|
|
2124
2136
|
return key;
|
|
2125
2137
|
};
|
|
2126
|
-
var
|
|
2127
|
-
|
|
2138
|
+
var readFile = async (file) => {
|
|
2139
|
+
if (file instanceof File) {
|
|
2140
|
+
const content = await file.arrayBuffer();
|
|
2141
|
+
return {
|
|
2142
|
+
fileName: file.name,
|
|
2143
|
+
content: Buffer.from(content).toString("base64"),
|
|
2144
|
+
mimeType: file.type
|
|
2145
|
+
};
|
|
2146
|
+
} else if (typeof file === "string") {
|
|
2147
|
+
if (file.startsWith("http")) {
|
|
2148
|
+
return await readFileContentFromURL(file);
|
|
2149
|
+
} else {
|
|
2150
|
+
return await readFileContent(file);
|
|
2151
|
+
}
|
|
2152
|
+
}
|
|
2153
|
+
throw new Error("Invalid file type");
|
|
2154
|
+
};
|
|
2155
|
+
var getFileDataAfterUploadingToS3 = async (file, {
|
|
2128
2156
|
toolSlug,
|
|
2129
2157
|
toolkitSlug,
|
|
2130
2158
|
client
|
|
2131
2159
|
}) => {
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2160
|
+
if (!file) {
|
|
2161
|
+
throw new Error("Either path or blob must be provided");
|
|
2162
|
+
}
|
|
2163
|
+
const fileData = await readFile(file);
|
|
2164
|
+
logger_default.debug(`Uploading file to S3...`);
|
|
2135
2165
|
const s3key = await uploadFileToS3(
|
|
2136
|
-
import_path.default.basename(
|
|
2166
|
+
import_path.default.basename(fileData.fileName),
|
|
2137
2167
|
fileData.content,
|
|
2138
2168
|
toolSlug,
|
|
2139
2169
|
toolkitSlug,
|
|
@@ -2142,7 +2172,7 @@ var getFileDataAfterUploadingToS3 = async ({
|
|
|
2142
2172
|
);
|
|
2143
2173
|
logger_default.debug(`Done! File uploaded to S3: ${s3key}`, JSON.stringify(fileData, null, 2));
|
|
2144
2174
|
return {
|
|
2145
|
-
name:
|
|
2175
|
+
name: fileData.fileName,
|
|
2146
2176
|
mimetype: fileData.mimeType,
|
|
2147
2177
|
s3key
|
|
2148
2178
|
};
|
|
@@ -2209,6 +2239,7 @@ var saveFile = (file, content, isTempFile = false) => {
|
|
|
2209
2239
|
}
|
|
2210
2240
|
return filePath;
|
|
2211
2241
|
} catch (_error) {
|
|
2242
|
+
logger_default.debug(`Error saving file: ${_error}`);
|
|
2212
2243
|
return null;
|
|
2213
2244
|
}
|
|
2214
2245
|
};
|
|
@@ -2217,17 +2248,91 @@ var saveFile = (file, content, isTempFile = false) => {
|
|
|
2217
2248
|
var transformProperties = (properties) => {
|
|
2218
2249
|
const newProperties = {};
|
|
2219
2250
|
for (const [key, property] of Object.entries(properties)) {
|
|
2220
|
-
if (
|
|
2251
|
+
if (property.file_uploadable) {
|
|
2252
|
+
newProperties[key] = {
|
|
2253
|
+
title: property.title,
|
|
2254
|
+
description: property.description,
|
|
2255
|
+
format: "path",
|
|
2256
|
+
type: "string",
|
|
2257
|
+
file_uploadable: true
|
|
2258
|
+
};
|
|
2259
|
+
} else if (property.type === "object" && property.properties) {
|
|
2260
|
+
newProperties[key] = {
|
|
2261
|
+
...property,
|
|
2262
|
+
properties: transformProperties(property.properties)
|
|
2263
|
+
};
|
|
2264
|
+
} else {
|
|
2221
2265
|
newProperties[key] = property;
|
|
2222
|
-
continue;
|
|
2223
2266
|
}
|
|
2224
|
-
newProperties[key] = {
|
|
2225
|
-
...property,
|
|
2226
|
-
format: "path"
|
|
2227
|
-
};
|
|
2228
2267
|
}
|
|
2229
2268
|
return newProperties;
|
|
2230
2269
|
};
|
|
2270
|
+
var hydrateFiles = async (value, schema, ctx) => {
|
|
2271
|
+
if (schema?.file_uploadable) {
|
|
2272
|
+
if (typeof value !== "string" && !(value instanceof File)) return value;
|
|
2273
|
+
logger_default.debug(`Uploading file "${value}"`);
|
|
2274
|
+
return getFileDataAfterUploadingToS3(value, {
|
|
2275
|
+
toolSlug: ctx.toolSlug,
|
|
2276
|
+
toolkitSlug: ctx.toolkitSlug,
|
|
2277
|
+
client: ctx.client
|
|
2278
|
+
});
|
|
2279
|
+
}
|
|
2280
|
+
if (schema?.type === "object" && schema.properties && isPlainObject(value)) {
|
|
2281
|
+
const transformed = {};
|
|
2282
|
+
for (const [k, v] of Object.entries(value)) {
|
|
2283
|
+
transformed[k] = await hydrateFiles(v, schema.properties[k], ctx);
|
|
2284
|
+
}
|
|
2285
|
+
return transformed;
|
|
2286
|
+
}
|
|
2287
|
+
if (schema?.type === "array" && schema.items && Array.isArray(value)) {
|
|
2288
|
+
const itemSchema = Array.isArray(schema.items) ? schema.items[0] : schema.items;
|
|
2289
|
+
return Promise.all(
|
|
2290
|
+
value.map((item) => hydrateFiles(item, itemSchema, ctx))
|
|
2291
|
+
);
|
|
2292
|
+
}
|
|
2293
|
+
return value;
|
|
2294
|
+
};
|
|
2295
|
+
var hydrateDownloads = async (value, ctx) => {
|
|
2296
|
+
if (isPlainObject(value) && typeof value.s3url === "string") {
|
|
2297
|
+
const { s3url, mimetype } = value;
|
|
2298
|
+
try {
|
|
2299
|
+
logger_default.debug(`Downloading from S3: ${s3url}`);
|
|
2300
|
+
const dl = await downloadFileFromS3({
|
|
2301
|
+
toolSlug: ctx.toolSlug,
|
|
2302
|
+
s3Url: s3url,
|
|
2303
|
+
mimeType: mimetype ?? "application/octet-stream"
|
|
2304
|
+
});
|
|
2305
|
+
logger_default.debug(`Downloaded \u2192 ${dl.filePath}`);
|
|
2306
|
+
return {
|
|
2307
|
+
uri: dl.filePath,
|
|
2308
|
+
file_downloaded: dl.filePath ? true : false,
|
|
2309
|
+
s3url,
|
|
2310
|
+
mimeType: dl.mimeType
|
|
2311
|
+
};
|
|
2312
|
+
} catch (err) {
|
|
2313
|
+
logger_default.error(`Download failed: ${s3url}`, { cause: err });
|
|
2314
|
+
return {
|
|
2315
|
+
uri: "",
|
|
2316
|
+
file_downloaded: false,
|
|
2317
|
+
s3url,
|
|
2318
|
+
mimeType: mimetype ?? "application/octet-stream"
|
|
2319
|
+
};
|
|
2320
|
+
}
|
|
2321
|
+
}
|
|
2322
|
+
if (isPlainObject(value)) {
|
|
2323
|
+
const pairs = await Promise.all(
|
|
2324
|
+
Object.entries(value).map(async ([k, v]) => [k, await hydrateDownloads(v, ctx)])
|
|
2325
|
+
);
|
|
2326
|
+
return Object.fromEntries(pairs);
|
|
2327
|
+
}
|
|
2328
|
+
if (Array.isArray(value)) {
|
|
2329
|
+
return Promise.all(value.map((item) => hydrateDownloads(item, ctx)));
|
|
2330
|
+
}
|
|
2331
|
+
return value;
|
|
2332
|
+
};
|
|
2333
|
+
function isPlainObject(val) {
|
|
2334
|
+
return typeof val === "object" && val !== null && !Array.isArray(val);
|
|
2335
|
+
}
|
|
2231
2336
|
var FileToolModifier = class {
|
|
2232
2337
|
client;
|
|
2233
2338
|
constructor(client) {
|
|
@@ -2266,30 +2371,21 @@ var FileToolModifier = class {
|
|
|
2266
2371
|
*
|
|
2267
2372
|
*/
|
|
2268
2373
|
async fileUploadModifier(tool, options) {
|
|
2269
|
-
const {
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
});
|
|
2284
|
-
args[key] = fileData;
|
|
2285
|
-
} catch (error) {
|
|
2286
|
-
throw new ComposioFileUploadError(`Failed to upload file: ${key}`, {
|
|
2287
|
-
cause: error
|
|
2288
|
-
});
|
|
2289
|
-
}
|
|
2290
|
-
}
|
|
2374
|
+
const { params, toolSlug, toolkitSlug = "unknown" } = options;
|
|
2375
|
+
const { arguments: args } = params;
|
|
2376
|
+
if (!args || typeof args !== "object") return params;
|
|
2377
|
+
try {
|
|
2378
|
+
const newArgs = await hydrateFiles(args, tool.inputParameters, {
|
|
2379
|
+
toolSlug,
|
|
2380
|
+
toolkitSlug,
|
|
2381
|
+
client: this.client
|
|
2382
|
+
});
|
|
2383
|
+
return { ...params, arguments: newArgs };
|
|
2384
|
+
} catch (error) {
|
|
2385
|
+
throw new ComposioFileUploadError("Failed to upload file", {
|
|
2386
|
+
cause: error
|
|
2387
|
+
});
|
|
2291
2388
|
}
|
|
2292
|
-
return options.params;
|
|
2293
2389
|
}
|
|
2294
2390
|
/**
|
|
2295
2391
|
* Modifies the result to include the file download URL.
|
|
@@ -2301,37 +2397,10 @@ var FileToolModifier = class {
|
|
|
2301
2397
|
* @param result - The result of the tool execution.
|
|
2302
2398
|
* @returns The result with the file download URL included.
|
|
2303
2399
|
*/
|
|
2304
|
-
async fileDownloadModifier(
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
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;
|
|
2400
|
+
async fileDownloadModifier(_tool, options) {
|
|
2401
|
+
const { result, toolSlug } = options;
|
|
2402
|
+
const dataWithDownloads = await hydrateDownloads(result.data, { toolSlug });
|
|
2403
|
+
return { ...result, data: dataWithDownloads };
|
|
2335
2404
|
}
|
|
2336
2405
|
};
|
|
2337
2406
|
|
|
@@ -4091,17 +4160,38 @@ var Toolkits = class {
|
|
|
4091
4160
|
authConfigIdToUse = authConfig.items[0]?.id;
|
|
4092
4161
|
if (!authConfigIdToUse) {
|
|
4093
4162
|
if (toolkit.authConfigDetails && toolkit.authConfigDetails.length > 0) {
|
|
4094
|
-
|
|
4095
|
-
|
|
4096
|
-
|
|
4097
|
-
|
|
4098
|
-
|
|
4163
|
+
try {
|
|
4164
|
+
const authConfig2 = await composioAuthConfig.create(toolkitSlug, {
|
|
4165
|
+
type: "use_composio_managed_auth",
|
|
4166
|
+
name: `${toolkit.name} Auth Config`
|
|
4167
|
+
});
|
|
4168
|
+
authConfigIdToUse = authConfig2.id;
|
|
4169
|
+
} catch (error) {
|
|
4170
|
+
if (error instanceof import_client4.default.APIError && error.status === 400) {
|
|
4171
|
+
throw new ComposioAuthConfigNotFoundError(
|
|
4172
|
+
`No Default auth config found for toolkit ${toolkitSlug}`,
|
|
4173
|
+
{
|
|
4174
|
+
meta: {
|
|
4175
|
+
toolkitSlug
|
|
4176
|
+
},
|
|
4177
|
+
cause: error,
|
|
4178
|
+
possibleFixes: [
|
|
4179
|
+
`Please Create an auth config for the toolkit ${toolkitSlug} via the dashboard`
|
|
4180
|
+
]
|
|
4181
|
+
}
|
|
4182
|
+
);
|
|
4183
|
+
}
|
|
4184
|
+
throw error;
|
|
4185
|
+
}
|
|
4099
4186
|
} else {
|
|
4100
|
-
throw new ComposioAuthConfigNotFoundError(
|
|
4101
|
-
|
|
4102
|
-
|
|
4187
|
+
throw new ComposioAuthConfigNotFoundError(
|
|
4188
|
+
`No auth configs found for toolkit ${toolkitSlug}`,
|
|
4189
|
+
{
|
|
4190
|
+
meta: {
|
|
4191
|
+
toolkitSlug
|
|
4192
|
+
}
|
|
4103
4193
|
}
|
|
4104
|
-
|
|
4194
|
+
);
|
|
4105
4195
|
}
|
|
4106
4196
|
}
|
|
4107
4197
|
const composioConnectedAccount = new ConnectedAccounts(this.client);
|
|
@@ -5840,9 +5930,17 @@ var OpenAIProvider = class extends BaseNonAgenticProvider {
|
|
|
5840
5930
|
const outputs = [];
|
|
5841
5931
|
for (const message of chatCompletion.choices) {
|
|
5842
5932
|
if (message.message.tool_calls) {
|
|
5843
|
-
|
|
5844
|
-
|
|
5933
|
+
const toolResult = await this.executeToolCall(
|
|
5934
|
+
userId,
|
|
5935
|
+
message.message.tool_calls[0],
|
|
5936
|
+
options,
|
|
5937
|
+
modifiers
|
|
5845
5938
|
);
|
|
5939
|
+
outputs.push({
|
|
5940
|
+
role: "tool",
|
|
5941
|
+
tool_call_id: message.message.tool_calls[0].id,
|
|
5942
|
+
content: toolResult
|
|
5943
|
+
});
|
|
5846
5944
|
}
|
|
5847
5945
|
}
|
|
5848
5946
|
return outputs;
|
|
@@ -6062,7 +6160,7 @@ var OpenAIProvider = class extends BaseNonAgenticProvider {
|
|
|
6062
6160
|
};
|
|
6063
6161
|
|
|
6064
6162
|
// package.json
|
|
6065
|
-
var version = "0.1.
|
|
6163
|
+
var version = "0.1.32";
|
|
6066
6164
|
|
|
6067
6165
|
// src/models/Files.ts
|
|
6068
6166
|
var Files = class {
|
|
@@ -6078,12 +6176,11 @@ var Files = class {
|
|
|
6078
6176
|
* @returns The file data.
|
|
6079
6177
|
*/
|
|
6080
6178
|
async upload({
|
|
6081
|
-
|
|
6179
|
+
file,
|
|
6082
6180
|
toolSlug,
|
|
6083
6181
|
toolkitSlug
|
|
6084
6182
|
}) {
|
|
6085
|
-
const fileData = await getFileDataAfterUploadingToS3({
|
|
6086
|
-
path: filePath,
|
|
6183
|
+
const fileData = await getFileDataAfterUploadingToS3(file, {
|
|
6087
6184
|
toolSlug,
|
|
6088
6185
|
toolkitSlug,
|
|
6089
6186
|
client: this.client
|
package/dist/index.d.cts
CHANGED
|
@@ -40307,7 +40307,7 @@ declare class OpenAIProvider extends BaseNonAgenticProvider<OpenAiToolCollection
|
|
|
40307
40307
|
* console.log(results); // Array of tool execution results
|
|
40308
40308
|
* ```
|
|
40309
40309
|
*/
|
|
40310
|
-
handleToolCalls(userId: string, chatCompletion: OpenAI.ChatCompletion, options?: ExecuteToolFnOptions, modifiers?: ExecuteToolModifiers): Promise<
|
|
40310
|
+
handleToolCalls(userId: string, chatCompletion: OpenAI.ChatCompletion, options?: ExecuteToolFnOptions, modifiers?: ExecuteToolModifiers): Promise<OpenAI.ChatCompletionToolMessageParam[]>;
|
|
40311
40311
|
/**
|
|
40312
40312
|
* Handles all the tool calls from the OpenAI Assistant API.
|
|
40313
40313
|
*
|
|
@@ -40468,8 +40468,8 @@ declare class Files {
|
|
|
40468
40468
|
* @param toolkitSlug - The slug of the toolkit that is uploading the file.
|
|
40469
40469
|
* @returns The file data.
|
|
40470
40470
|
*/
|
|
40471
|
-
upload({
|
|
40472
|
-
|
|
40471
|
+
upload({ file, toolSlug, toolkitSlug, }: {
|
|
40472
|
+
file: File | string;
|
|
40473
40473
|
toolSlug: string;
|
|
40474
40474
|
toolkitSlug: string;
|
|
40475
40475
|
}): Promise<FileUploadData>;
|
package/dist/index.d.ts
CHANGED
|
@@ -40307,7 +40307,7 @@ declare class OpenAIProvider extends BaseNonAgenticProvider<OpenAiToolCollection
|
|
|
40307
40307
|
* console.log(results); // Array of tool execution results
|
|
40308
40308
|
* ```
|
|
40309
40309
|
*/
|
|
40310
|
-
handleToolCalls(userId: string, chatCompletion: OpenAI.ChatCompletion, options?: ExecuteToolFnOptions, modifiers?: ExecuteToolModifiers): Promise<
|
|
40310
|
+
handleToolCalls(userId: string, chatCompletion: OpenAI.ChatCompletion, options?: ExecuteToolFnOptions, modifiers?: ExecuteToolModifiers): Promise<OpenAI.ChatCompletionToolMessageParam[]>;
|
|
40311
40311
|
/**
|
|
40312
40312
|
* Handles all the tool calls from the OpenAI Assistant API.
|
|
40313
40313
|
*
|
|
@@ -40468,8 +40468,8 @@ declare class Files {
|
|
|
40468
40468
|
* @param toolkitSlug - The slug of the toolkit that is uploading the file.
|
|
40469
40469
|
* @returns The file data.
|
|
40470
40470
|
*/
|
|
40471
|
-
upload({
|
|
40472
|
-
|
|
40471
|
+
upload({ file, toolSlug, toolkitSlug, }: {
|
|
40472
|
+
file: File | string;
|
|
40473
40473
|
toolSlug: string;
|
|
40474
40474
|
toolkitSlug: string;
|
|
40475
40475
|
}): Promise<FileUploadData>;
|
package/dist/index.js
CHANGED
|
@@ -695,13 +695,18 @@ var TelemetryService = class {
|
|
|
695
695
|
* @returns The response from the Telemetry API.
|
|
696
696
|
*/
|
|
697
697
|
static async sendMetric(payload) {
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
698
|
+
try {
|
|
699
|
+
const result = await fetch(`${TELEMETRY_URL2}/metrics/invocations`, {
|
|
700
|
+
method: "POST",
|
|
701
|
+
headers: {
|
|
702
|
+
"Content-Type": "application/json"
|
|
703
|
+
},
|
|
704
|
+
body: JSON.stringify(payload)
|
|
705
|
+
});
|
|
706
|
+
return result;
|
|
707
|
+
} catch (error) {
|
|
708
|
+
logger_default.debug("Error sending metric telemetry", error);
|
|
709
|
+
}
|
|
705
710
|
}
|
|
706
711
|
/**
|
|
707
712
|
* Sends an error log to the Telemetry API.
|
|
@@ -709,13 +714,18 @@ var TelemetryService = class {
|
|
|
709
714
|
* @returns The response from the Telemetry API.
|
|
710
715
|
*/
|
|
711
716
|
static async sendErrorLog(payload) {
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
717
|
+
try {
|
|
718
|
+
const result = await fetch(`${TELEMETRY_URL2}/errors`, {
|
|
719
|
+
method: "POST",
|
|
720
|
+
headers: {
|
|
721
|
+
"Content-Type": "application/json"
|
|
722
|
+
},
|
|
723
|
+
body: JSON.stringify(payload)
|
|
724
|
+
});
|
|
725
|
+
return result;
|
|
726
|
+
} catch (error) {
|
|
727
|
+
logger_default.debug("Error sending error telemetry", error);
|
|
728
|
+
}
|
|
719
729
|
}
|
|
720
730
|
};
|
|
721
731
|
|
|
@@ -1926,6 +1936,7 @@ var readFileContent = async (path) => {
|
|
|
1926
1936
|
try {
|
|
1927
1937
|
const content = __require("fs").readFileSync(path);
|
|
1928
1938
|
return {
|
|
1939
|
+
fileName: path,
|
|
1929
1940
|
content: content.toString("base64"),
|
|
1930
1941
|
mimeType: "application/octet-stream"
|
|
1931
1942
|
};
|
|
@@ -1943,7 +1954,8 @@ var readFileContentFromURL = async (path) => {
|
|
|
1943
1954
|
const mimeType = response.headers.get("content-type") || "application/octet-stream";
|
|
1944
1955
|
return {
|
|
1945
1956
|
content: content.toString("base64"),
|
|
1946
|
-
mimeType
|
|
1957
|
+
mimeType,
|
|
1958
|
+
fileName: path
|
|
1947
1959
|
};
|
|
1948
1960
|
};
|
|
1949
1961
|
var uploadFileToS3 = async (fileName, content, toolSlug, toolkitSlug, mimeType, client) => {
|
|
@@ -1975,17 +1987,35 @@ var uploadFileToS3 = async (fileName, content, toolSlug, toolkitSlug, mimeType,
|
|
|
1975
1987
|
}
|
|
1976
1988
|
return key;
|
|
1977
1989
|
};
|
|
1978
|
-
var
|
|
1979
|
-
|
|
1990
|
+
var readFile = async (file) => {
|
|
1991
|
+
if (file instanceof File) {
|
|
1992
|
+
const content = await file.arrayBuffer();
|
|
1993
|
+
return {
|
|
1994
|
+
fileName: file.name,
|
|
1995
|
+
content: Buffer.from(content).toString("base64"),
|
|
1996
|
+
mimeType: file.type
|
|
1997
|
+
};
|
|
1998
|
+
} else if (typeof file === "string") {
|
|
1999
|
+
if (file.startsWith("http")) {
|
|
2000
|
+
return await readFileContentFromURL(file);
|
|
2001
|
+
} else {
|
|
2002
|
+
return await readFileContent(file);
|
|
2003
|
+
}
|
|
2004
|
+
}
|
|
2005
|
+
throw new Error("Invalid file type");
|
|
2006
|
+
};
|
|
2007
|
+
var getFileDataAfterUploadingToS3 = async (file, {
|
|
1980
2008
|
toolSlug,
|
|
1981
2009
|
toolkitSlug,
|
|
1982
2010
|
client
|
|
1983
2011
|
}) => {
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
2012
|
+
if (!file) {
|
|
2013
|
+
throw new Error("Either path or blob must be provided");
|
|
2014
|
+
}
|
|
2015
|
+
const fileData = await readFile(file);
|
|
2016
|
+
logger_default.debug(`Uploading file to S3...`);
|
|
1987
2017
|
const s3key = await uploadFileToS3(
|
|
1988
|
-
pathModule.basename(
|
|
2018
|
+
pathModule.basename(fileData.fileName),
|
|
1989
2019
|
fileData.content,
|
|
1990
2020
|
toolSlug,
|
|
1991
2021
|
toolkitSlug,
|
|
@@ -1994,7 +2024,7 @@ var getFileDataAfterUploadingToS3 = async ({
|
|
|
1994
2024
|
);
|
|
1995
2025
|
logger_default.debug(`Done! File uploaded to S3: ${s3key}`, JSON.stringify(fileData, null, 2));
|
|
1996
2026
|
return {
|
|
1997
|
-
name:
|
|
2027
|
+
name: fileData.fileName,
|
|
1998
2028
|
mimetype: fileData.mimeType,
|
|
1999
2029
|
s3key
|
|
2000
2030
|
};
|
|
@@ -2061,6 +2091,7 @@ var saveFile = (file, content, isTempFile = false) => {
|
|
|
2061
2091
|
}
|
|
2062
2092
|
return filePath;
|
|
2063
2093
|
} catch (_error) {
|
|
2094
|
+
logger_default.debug(`Error saving file: ${_error}`);
|
|
2064
2095
|
return null;
|
|
2065
2096
|
}
|
|
2066
2097
|
};
|
|
@@ -2069,17 +2100,91 @@ var saveFile = (file, content, isTempFile = false) => {
|
|
|
2069
2100
|
var transformProperties = (properties) => {
|
|
2070
2101
|
const newProperties = {};
|
|
2071
2102
|
for (const [key, property] of Object.entries(properties)) {
|
|
2072
|
-
if (
|
|
2103
|
+
if (property.file_uploadable) {
|
|
2104
|
+
newProperties[key] = {
|
|
2105
|
+
title: property.title,
|
|
2106
|
+
description: property.description,
|
|
2107
|
+
format: "path",
|
|
2108
|
+
type: "string",
|
|
2109
|
+
file_uploadable: true
|
|
2110
|
+
};
|
|
2111
|
+
} else if (property.type === "object" && property.properties) {
|
|
2112
|
+
newProperties[key] = {
|
|
2113
|
+
...property,
|
|
2114
|
+
properties: transformProperties(property.properties)
|
|
2115
|
+
};
|
|
2116
|
+
} else {
|
|
2073
2117
|
newProperties[key] = property;
|
|
2074
|
-
continue;
|
|
2075
2118
|
}
|
|
2076
|
-
newProperties[key] = {
|
|
2077
|
-
...property,
|
|
2078
|
-
format: "path"
|
|
2079
|
-
};
|
|
2080
2119
|
}
|
|
2081
2120
|
return newProperties;
|
|
2082
2121
|
};
|
|
2122
|
+
var hydrateFiles = async (value, schema, ctx) => {
|
|
2123
|
+
if (schema?.file_uploadable) {
|
|
2124
|
+
if (typeof value !== "string" && !(value instanceof File)) return value;
|
|
2125
|
+
logger_default.debug(`Uploading file "${value}"`);
|
|
2126
|
+
return getFileDataAfterUploadingToS3(value, {
|
|
2127
|
+
toolSlug: ctx.toolSlug,
|
|
2128
|
+
toolkitSlug: ctx.toolkitSlug,
|
|
2129
|
+
client: ctx.client
|
|
2130
|
+
});
|
|
2131
|
+
}
|
|
2132
|
+
if (schema?.type === "object" && schema.properties && isPlainObject(value)) {
|
|
2133
|
+
const transformed = {};
|
|
2134
|
+
for (const [k, v] of Object.entries(value)) {
|
|
2135
|
+
transformed[k] = await hydrateFiles(v, schema.properties[k], ctx);
|
|
2136
|
+
}
|
|
2137
|
+
return transformed;
|
|
2138
|
+
}
|
|
2139
|
+
if (schema?.type === "array" && schema.items && Array.isArray(value)) {
|
|
2140
|
+
const itemSchema = Array.isArray(schema.items) ? schema.items[0] : schema.items;
|
|
2141
|
+
return Promise.all(
|
|
2142
|
+
value.map((item) => hydrateFiles(item, itemSchema, ctx))
|
|
2143
|
+
);
|
|
2144
|
+
}
|
|
2145
|
+
return value;
|
|
2146
|
+
};
|
|
2147
|
+
var hydrateDownloads = async (value, ctx) => {
|
|
2148
|
+
if (isPlainObject(value) && typeof value.s3url === "string") {
|
|
2149
|
+
const { s3url, mimetype } = value;
|
|
2150
|
+
try {
|
|
2151
|
+
logger_default.debug(`Downloading from S3: ${s3url}`);
|
|
2152
|
+
const dl = await downloadFileFromS3({
|
|
2153
|
+
toolSlug: ctx.toolSlug,
|
|
2154
|
+
s3Url: s3url,
|
|
2155
|
+
mimeType: mimetype ?? "application/octet-stream"
|
|
2156
|
+
});
|
|
2157
|
+
logger_default.debug(`Downloaded \u2192 ${dl.filePath}`);
|
|
2158
|
+
return {
|
|
2159
|
+
uri: dl.filePath,
|
|
2160
|
+
file_downloaded: dl.filePath ? true : false,
|
|
2161
|
+
s3url,
|
|
2162
|
+
mimeType: dl.mimeType
|
|
2163
|
+
};
|
|
2164
|
+
} catch (err) {
|
|
2165
|
+
logger_default.error(`Download failed: ${s3url}`, { cause: err });
|
|
2166
|
+
return {
|
|
2167
|
+
uri: "",
|
|
2168
|
+
file_downloaded: false,
|
|
2169
|
+
s3url,
|
|
2170
|
+
mimeType: mimetype ?? "application/octet-stream"
|
|
2171
|
+
};
|
|
2172
|
+
}
|
|
2173
|
+
}
|
|
2174
|
+
if (isPlainObject(value)) {
|
|
2175
|
+
const pairs = await Promise.all(
|
|
2176
|
+
Object.entries(value).map(async ([k, v]) => [k, await hydrateDownloads(v, ctx)])
|
|
2177
|
+
);
|
|
2178
|
+
return Object.fromEntries(pairs);
|
|
2179
|
+
}
|
|
2180
|
+
if (Array.isArray(value)) {
|
|
2181
|
+
return Promise.all(value.map((item) => hydrateDownloads(item, ctx)));
|
|
2182
|
+
}
|
|
2183
|
+
return value;
|
|
2184
|
+
};
|
|
2185
|
+
function isPlainObject(val) {
|
|
2186
|
+
return typeof val === "object" && val !== null && !Array.isArray(val);
|
|
2187
|
+
}
|
|
2083
2188
|
var FileToolModifier = class {
|
|
2084
2189
|
client;
|
|
2085
2190
|
constructor(client) {
|
|
@@ -2118,30 +2223,21 @@ var FileToolModifier = class {
|
|
|
2118
2223
|
*
|
|
2119
2224
|
*/
|
|
2120
2225
|
async fileUploadModifier(tool, options) {
|
|
2121
|
-
const {
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
});
|
|
2136
|
-
args[key] = fileData;
|
|
2137
|
-
} catch (error) {
|
|
2138
|
-
throw new ComposioFileUploadError(`Failed to upload file: ${key}`, {
|
|
2139
|
-
cause: error
|
|
2140
|
-
});
|
|
2141
|
-
}
|
|
2142
|
-
}
|
|
2226
|
+
const { params, toolSlug, toolkitSlug = "unknown" } = options;
|
|
2227
|
+
const { arguments: args } = params;
|
|
2228
|
+
if (!args || typeof args !== "object") return params;
|
|
2229
|
+
try {
|
|
2230
|
+
const newArgs = await hydrateFiles(args, tool.inputParameters, {
|
|
2231
|
+
toolSlug,
|
|
2232
|
+
toolkitSlug,
|
|
2233
|
+
client: this.client
|
|
2234
|
+
});
|
|
2235
|
+
return { ...params, arguments: newArgs };
|
|
2236
|
+
} catch (error) {
|
|
2237
|
+
throw new ComposioFileUploadError("Failed to upload file", {
|
|
2238
|
+
cause: error
|
|
2239
|
+
});
|
|
2143
2240
|
}
|
|
2144
|
-
return options.params;
|
|
2145
2241
|
}
|
|
2146
2242
|
/**
|
|
2147
2243
|
* Modifies the result to include the file download URL.
|
|
@@ -2153,37 +2249,10 @@ var FileToolModifier = class {
|
|
|
2153
2249
|
* @param result - The result of the tool execution.
|
|
2154
2250
|
* @returns The result with the file download URL included.
|
|
2155
2251
|
*/
|
|
2156
|
-
async fileDownloadModifier(
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
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;
|
|
2252
|
+
async fileDownloadModifier(_tool, options) {
|
|
2253
|
+
const { result, toolSlug } = options;
|
|
2254
|
+
const dataWithDownloads = await hydrateDownloads(result.data, { toolSlug });
|
|
2255
|
+
return { ...result, data: dataWithDownloads };
|
|
2187
2256
|
}
|
|
2188
2257
|
};
|
|
2189
2258
|
|
|
@@ -3943,17 +4012,38 @@ var Toolkits = class {
|
|
|
3943
4012
|
authConfigIdToUse = authConfig.items[0]?.id;
|
|
3944
4013
|
if (!authConfigIdToUse) {
|
|
3945
4014
|
if (toolkit.authConfigDetails && toolkit.authConfigDetails.length > 0) {
|
|
3946
|
-
|
|
3947
|
-
|
|
3948
|
-
|
|
3949
|
-
|
|
3950
|
-
|
|
4015
|
+
try {
|
|
4016
|
+
const authConfig2 = await composioAuthConfig.create(toolkitSlug, {
|
|
4017
|
+
type: "use_composio_managed_auth",
|
|
4018
|
+
name: `${toolkit.name} Auth Config`
|
|
4019
|
+
});
|
|
4020
|
+
authConfigIdToUse = authConfig2.id;
|
|
4021
|
+
} catch (error) {
|
|
4022
|
+
if (error instanceof ComposioClient2.APIError && error.status === 400) {
|
|
4023
|
+
throw new ComposioAuthConfigNotFoundError(
|
|
4024
|
+
`No Default auth config found for toolkit ${toolkitSlug}`,
|
|
4025
|
+
{
|
|
4026
|
+
meta: {
|
|
4027
|
+
toolkitSlug
|
|
4028
|
+
},
|
|
4029
|
+
cause: error,
|
|
4030
|
+
possibleFixes: [
|
|
4031
|
+
`Please Create an auth config for the toolkit ${toolkitSlug} via the dashboard`
|
|
4032
|
+
]
|
|
4033
|
+
}
|
|
4034
|
+
);
|
|
4035
|
+
}
|
|
4036
|
+
throw error;
|
|
4037
|
+
}
|
|
3951
4038
|
} else {
|
|
3952
|
-
throw new ComposioAuthConfigNotFoundError(
|
|
3953
|
-
|
|
3954
|
-
|
|
4039
|
+
throw new ComposioAuthConfigNotFoundError(
|
|
4040
|
+
`No auth configs found for toolkit ${toolkitSlug}`,
|
|
4041
|
+
{
|
|
4042
|
+
meta: {
|
|
4043
|
+
toolkitSlug
|
|
4044
|
+
}
|
|
3955
4045
|
}
|
|
3956
|
-
|
|
4046
|
+
);
|
|
3957
4047
|
}
|
|
3958
4048
|
}
|
|
3959
4049
|
const composioConnectedAccount = new ConnectedAccounts(this.client);
|
|
@@ -5692,9 +5782,17 @@ var OpenAIProvider = class extends BaseNonAgenticProvider {
|
|
|
5692
5782
|
const outputs = [];
|
|
5693
5783
|
for (const message of chatCompletion.choices) {
|
|
5694
5784
|
if (message.message.tool_calls) {
|
|
5695
|
-
|
|
5696
|
-
|
|
5785
|
+
const toolResult = await this.executeToolCall(
|
|
5786
|
+
userId,
|
|
5787
|
+
message.message.tool_calls[0],
|
|
5788
|
+
options,
|
|
5789
|
+
modifiers
|
|
5697
5790
|
);
|
|
5791
|
+
outputs.push({
|
|
5792
|
+
role: "tool",
|
|
5793
|
+
tool_call_id: message.message.tool_calls[0].id,
|
|
5794
|
+
content: toolResult
|
|
5795
|
+
});
|
|
5698
5796
|
}
|
|
5699
5797
|
}
|
|
5700
5798
|
return outputs;
|
|
@@ -5914,7 +6012,7 @@ var OpenAIProvider = class extends BaseNonAgenticProvider {
|
|
|
5914
6012
|
};
|
|
5915
6013
|
|
|
5916
6014
|
// package.json
|
|
5917
|
-
var version = "0.1.
|
|
6015
|
+
var version = "0.1.32";
|
|
5918
6016
|
|
|
5919
6017
|
// src/models/Files.ts
|
|
5920
6018
|
var Files = class {
|
|
@@ -5930,12 +6028,11 @@ var Files = class {
|
|
|
5930
6028
|
* @returns The file data.
|
|
5931
6029
|
*/
|
|
5932
6030
|
async upload({
|
|
5933
|
-
|
|
6031
|
+
file,
|
|
5934
6032
|
toolSlug,
|
|
5935
6033
|
toolkitSlug
|
|
5936
6034
|
}) {
|
|
5937
|
-
const fileData = await getFileDataAfterUploadingToS3({
|
|
5938
|
-
path: filePath,
|
|
6035
|
+
const fileData = await getFileDataAfterUploadingToS3(file, {
|
|
5939
6036
|
toolSlug,
|
|
5940
6037
|
toolkitSlug,
|
|
5941
6038
|
client: this.client
|