@composio/core 0.1.31 → 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 +69 -32
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +69 -32
- 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
|
};
|
|
@@ -2238,10 +2269,9 @@ var transformProperties = (properties) => {
|
|
|
2238
2269
|
};
|
|
2239
2270
|
var hydrateFiles = async (value, schema, ctx) => {
|
|
2240
2271
|
if (schema?.file_uploadable) {
|
|
2241
|
-
if (typeof value !== "string") return value;
|
|
2272
|
+
if (typeof value !== "string" && !(value instanceof File)) return value;
|
|
2242
2273
|
logger_default.debug(`Uploading file "${value}"`);
|
|
2243
|
-
return getFileDataAfterUploadingToS3({
|
|
2244
|
-
path: value,
|
|
2274
|
+
return getFileDataAfterUploadingToS3(value, {
|
|
2245
2275
|
toolSlug: ctx.toolSlug,
|
|
2246
2276
|
toolkitSlug: ctx.toolkitSlug,
|
|
2247
2277
|
client: ctx.client
|
|
@@ -2275,7 +2305,7 @@ var hydrateDownloads = async (value, ctx) => {
|
|
|
2275
2305
|
logger_default.debug(`Downloaded \u2192 ${dl.filePath}`);
|
|
2276
2306
|
return {
|
|
2277
2307
|
uri: dl.filePath,
|
|
2278
|
-
file_downloaded: true,
|
|
2308
|
+
file_downloaded: dl.filePath ? true : false,
|
|
2279
2309
|
s3url,
|
|
2280
2310
|
mimeType: dl.mimeType
|
|
2281
2311
|
};
|
|
@@ -5900,9 +5930,17 @@ var OpenAIProvider = class extends BaseNonAgenticProvider {
|
|
|
5900
5930
|
const outputs = [];
|
|
5901
5931
|
for (const message of chatCompletion.choices) {
|
|
5902
5932
|
if (message.message.tool_calls) {
|
|
5903
|
-
|
|
5904
|
-
|
|
5933
|
+
const toolResult = await this.executeToolCall(
|
|
5934
|
+
userId,
|
|
5935
|
+
message.message.tool_calls[0],
|
|
5936
|
+
options,
|
|
5937
|
+
modifiers
|
|
5905
5938
|
);
|
|
5939
|
+
outputs.push({
|
|
5940
|
+
role: "tool",
|
|
5941
|
+
tool_call_id: message.message.tool_calls[0].id,
|
|
5942
|
+
content: toolResult
|
|
5943
|
+
});
|
|
5906
5944
|
}
|
|
5907
5945
|
}
|
|
5908
5946
|
return outputs;
|
|
@@ -6122,7 +6160,7 @@ var OpenAIProvider = class extends BaseNonAgenticProvider {
|
|
|
6122
6160
|
};
|
|
6123
6161
|
|
|
6124
6162
|
// package.json
|
|
6125
|
-
var version = "0.1.
|
|
6163
|
+
var version = "0.1.32";
|
|
6126
6164
|
|
|
6127
6165
|
// src/models/Files.ts
|
|
6128
6166
|
var Files = class {
|
|
@@ -6138,12 +6176,11 @@ var Files = class {
|
|
|
6138
6176
|
* @returns The file data.
|
|
6139
6177
|
*/
|
|
6140
6178
|
async upload({
|
|
6141
|
-
|
|
6179
|
+
file,
|
|
6142
6180
|
toolSlug,
|
|
6143
6181
|
toolkitSlug
|
|
6144
6182
|
}) {
|
|
6145
|
-
const fileData = await getFileDataAfterUploadingToS3({
|
|
6146
|
-
path: filePath,
|
|
6183
|
+
const fileData = await getFileDataAfterUploadingToS3(file, {
|
|
6147
6184
|
toolSlug,
|
|
6148
6185
|
toolkitSlug,
|
|
6149
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
|
};
|
|
@@ -2090,10 +2121,9 @@ var transformProperties = (properties) => {
|
|
|
2090
2121
|
};
|
|
2091
2122
|
var hydrateFiles = async (value, schema, ctx) => {
|
|
2092
2123
|
if (schema?.file_uploadable) {
|
|
2093
|
-
if (typeof value !== "string") return value;
|
|
2124
|
+
if (typeof value !== "string" && !(value instanceof File)) return value;
|
|
2094
2125
|
logger_default.debug(`Uploading file "${value}"`);
|
|
2095
|
-
return getFileDataAfterUploadingToS3({
|
|
2096
|
-
path: value,
|
|
2126
|
+
return getFileDataAfterUploadingToS3(value, {
|
|
2097
2127
|
toolSlug: ctx.toolSlug,
|
|
2098
2128
|
toolkitSlug: ctx.toolkitSlug,
|
|
2099
2129
|
client: ctx.client
|
|
@@ -2127,7 +2157,7 @@ var hydrateDownloads = async (value, ctx) => {
|
|
|
2127
2157
|
logger_default.debug(`Downloaded \u2192 ${dl.filePath}`);
|
|
2128
2158
|
return {
|
|
2129
2159
|
uri: dl.filePath,
|
|
2130
|
-
file_downloaded: true,
|
|
2160
|
+
file_downloaded: dl.filePath ? true : false,
|
|
2131
2161
|
s3url,
|
|
2132
2162
|
mimeType: dl.mimeType
|
|
2133
2163
|
};
|
|
@@ -5752,9 +5782,17 @@ var OpenAIProvider = class extends BaseNonAgenticProvider {
|
|
|
5752
5782
|
const outputs = [];
|
|
5753
5783
|
for (const message of chatCompletion.choices) {
|
|
5754
5784
|
if (message.message.tool_calls) {
|
|
5755
|
-
|
|
5756
|
-
|
|
5785
|
+
const toolResult = await this.executeToolCall(
|
|
5786
|
+
userId,
|
|
5787
|
+
message.message.tool_calls[0],
|
|
5788
|
+
options,
|
|
5789
|
+
modifiers
|
|
5757
5790
|
);
|
|
5791
|
+
outputs.push({
|
|
5792
|
+
role: "tool",
|
|
5793
|
+
tool_call_id: message.message.tool_calls[0].id,
|
|
5794
|
+
content: toolResult
|
|
5795
|
+
});
|
|
5758
5796
|
}
|
|
5759
5797
|
}
|
|
5760
5798
|
return outputs;
|
|
@@ -5974,7 +6012,7 @@ var OpenAIProvider = class extends BaseNonAgenticProvider {
|
|
|
5974
6012
|
};
|
|
5975
6013
|
|
|
5976
6014
|
// package.json
|
|
5977
|
-
var version = "0.1.
|
|
6015
|
+
var version = "0.1.32";
|
|
5978
6016
|
|
|
5979
6017
|
// src/models/Files.ts
|
|
5980
6018
|
var Files = class {
|
|
@@ -5990,12 +6028,11 @@ var Files = class {
|
|
|
5990
6028
|
* @returns The file data.
|
|
5991
6029
|
*/
|
|
5992
6030
|
async upload({
|
|
5993
|
-
|
|
6031
|
+
file,
|
|
5994
6032
|
toolSlug,
|
|
5995
6033
|
toolkitSlug
|
|
5996
6034
|
}) {
|
|
5997
|
-
const fileData = await getFileDataAfterUploadingToS3({
|
|
5998
|
-
path: filePath,
|
|
6035
|
+
const fileData = await getFileDataAfterUploadingToS3(file, {
|
|
5999
6036
|
toolSlug,
|
|
6000
6037
|
toolkitSlug,
|
|
6001
6038
|
client: this.client
|