@composio/core 0.5.5 → 0.6.1
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/BaseProvider-QPPZprGx.d.mts +26875 -0
- package/dist/BaseProvider-dBg5sg9H.d.cts +26875 -0
- package/dist/FileToolModifier.utils.neutral-BN_L8usp.mjs +78 -0
- package/dist/FileToolModifier.utils.neutral-Bcl7LVf4.cjs +102 -0
- package/dist/Telemetry-Bn5VseVi.mjs +331 -0
- package/dist/Telemetry-DErMJqj0.cjs +337 -0
- package/dist/buffer-BFpVRahf.mjs +382 -0
- package/dist/buffer-CYf1Z6Sd.cjs +478 -0
- package/dist/composio-h_UeXpQT.d.cts +6325 -0
- package/dist/composio-ivOweCw4.d.mts +6325 -0
- package/dist/fileUtils.node-DLp53qm1.cjs +232 -0
- package/dist/fileUtils.node-MOEGtpnI.mjs +219 -0
- package/dist/index.cjs +273 -417
- package/dist/index.d.cts +6 -33161
- package/dist/index.d.mts +6 -33161
- package/dist/index.mjs +182 -325
- package/dist/models/Files.node.cjs +6 -4
- package/dist/models/Files.node.d.cts +1 -1
- package/dist/models/Files.node.d.mts +1 -1
- package/dist/models/Files.node.mjs +4 -2
- package/dist/models/Files.workerd.cjs +1 -1
- package/dist/models/Files.workerd.mjs +1 -1
- package/dist/platform/node.cjs +6 -3
- package/dist/platform/node.d.cts +1 -1
- package/dist/platform/node.d.mts +1 -1
- package/dist/platform/node.mjs +6 -3
- package/dist/platform/workerd.d.cts +1 -1
- package/dist/platform/workerd.d.mts +1 -1
- package/dist/{types-BaUqjuX3.d.mts → types-BF2OQZRP.d.cts} +8 -5
- package/dist/types-BXCpxUsu.d.cts +13 -0
- package/dist/{types-BrsW5suw.d.cts → types-Cvt_yFsu.d.mts} +8 -5
- package/dist/types-anOdQ7KW.d.mts +13 -0
- package/dist/utils/config-defaults/ConfigDefaults.node.cjs +10 -0
- package/dist/utils/config-defaults/ConfigDefaults.node.d.cts +7 -0
- package/dist/utils/config-defaults/ConfigDefaults.node.d.mts +8 -0
- package/dist/utils/config-defaults/ConfigDefaults.node.mjs +9 -0
- package/dist/utils/config-defaults/ConfigDefaults.workerd.cjs +10 -0
- package/dist/utils/config-defaults/ConfigDefaults.workerd.d.cts +7 -0
- package/dist/utils/config-defaults/ConfigDefaults.workerd.d.mts +8 -0
- package/dist/utils/config-defaults/ConfigDefaults.workerd.mjs +9 -0
- package/dist/utils/modifiers/FileToolModifier.node.cjs +172 -0
- package/dist/utils/modifiers/FileToolModifier.node.d.cts +21 -0
- package/dist/utils/modifiers/FileToolModifier.node.d.mts +21 -0
- package/dist/utils/modifiers/FileToolModifier.node.mjs +173 -0
- package/dist/utils/modifiers/FileToolModifier.workerd.cjs +27 -0
- package/dist/utils/modifiers/FileToolModifier.workerd.d.cts +20 -0
- package/dist/utils/modifiers/FileToolModifier.workerd.d.mts +20 -0
- package/dist/utils/modifiers/FileToolModifier.workerd.mjs +27 -0
- package/package.json +25 -1
- package/src/platform/index.ts +1 -1
- package/src/platform/node.ts +17 -9
- package/src/platform/types.ts +9 -5
- package/src/platform/workerd.ts +7 -3
- package/dist/fileUtils-2bnnG7dq.cjs +0 -979
- package/dist/fileUtils-Dbn-fnh5.mjs +0 -900
- /package/dist/{chunk-0j-ceAHr.mjs → chunk-Dx2NuYGI.mjs} +0 -0
- /package/dist/{files.types-B7P5A1Z5.d.mts → files.types-BDqIUdfP.d.mts} +0 -0
- /package/dist/{files.types-D-RzIOHq.d.cts → files.types-nK6eTNnc.d.cts} +0 -0
package/dist/index.mjs
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import "./chunk-
|
|
2
|
-
import {
|
|
1
|
+
import "./chunk-Dx2NuYGI.mjs";
|
|
2
|
+
import { c as COMPOSIO_DIR, d as IS_DEVELOPMENT_OR_CI, g as getEnvsWithPrefix, h as getEnvVariable, l as COMPOSIO_LOG_LEVEL, m as constants_exports, o as ComposioError, p as USER_DATA_FILE_NAME, s as logger_default, t as arrayBufferToBase64, u as DEFAULT_BASE_URL } from "./buffer-BFpVRahf.mjs";
|
|
3
|
+
import { t as telemetry } from "./Telemetry-Bn5VseVi.mjs";
|
|
3
4
|
import ComposioClient, { APIError } from "@composio/client";
|
|
5
|
+
import { FileToolModifier } from "#file_tool_modifier";
|
|
4
6
|
import z, { ZodError, z as z$1 } from "zod/v3";
|
|
5
7
|
import * as zodToJsonSchema from "zod-to-json-schema";
|
|
6
|
-
import
|
|
7
|
-
import { platform } from "#platform";
|
|
8
|
+
import { CONFIG_DEFAULTS } from "#config_defaults";
|
|
8
9
|
import { APIError as APIError$1 } from "openai";
|
|
10
|
+
import { platform } from "#platform";
|
|
9
11
|
import semver from "semver";
|
|
10
12
|
import { Files } from "#files";
|
|
11
13
|
import { jsonSchemaToZod } from "@composio/json-schema-to-zod";
|
|
@@ -1728,277 +1730,6 @@ var CustomTools = class {
|
|
|
1728
1730
|
}
|
|
1729
1731
|
};
|
|
1730
1732
|
|
|
1731
|
-
//#endregion
|
|
1732
|
-
//#region src/errors/FileModifierErrors.ts
|
|
1733
|
-
const FileModifierErrorCodes = { FILE_UPLOAD_FAILED: "FILE_UPLOAD_FAILED" };
|
|
1734
|
-
var ComposioFileUploadError = class extends ComposioError {
|
|
1735
|
-
constructor(message = "Failed to upload file", options = {}) {
|
|
1736
|
-
super(message, {
|
|
1737
|
-
...options,
|
|
1738
|
-
code: FileModifierErrorCodes.FILE_UPLOAD_FAILED,
|
|
1739
|
-
possibleFixes: options.possibleFixes || ["Check if the file exists in the location provided"]
|
|
1740
|
-
});
|
|
1741
|
-
this.name = "ComposioFileUploadError";
|
|
1742
|
-
}
|
|
1743
|
-
};
|
|
1744
|
-
|
|
1745
|
-
//#endregion
|
|
1746
|
-
//#region src/utils/modifiers/FileToolModifier.ts
|
|
1747
|
-
/**
|
|
1748
|
-
* Transforms a single JSON schema property, recursively handling nested properties,
|
|
1749
|
-
* anyOf, oneOf, and allOf.
|
|
1750
|
-
*/
|
|
1751
|
-
const transformSchema = (property) => {
|
|
1752
|
-
if (property.file_uploadable) return {
|
|
1753
|
-
title: property.title,
|
|
1754
|
-
description: property.description,
|
|
1755
|
-
format: "path",
|
|
1756
|
-
type: "string",
|
|
1757
|
-
file_uploadable: true
|
|
1758
|
-
};
|
|
1759
|
-
const newProperty = { ...property };
|
|
1760
|
-
if (property.type === "object" && property.properties) newProperty.properties = transformProperties(property.properties);
|
|
1761
|
-
if (property.anyOf) newProperty.anyOf = property.anyOf.map(transformSchema);
|
|
1762
|
-
if (property.oneOf) newProperty.oneOf = property.oneOf.map(transformSchema);
|
|
1763
|
-
if (property.allOf) newProperty.allOf = property.allOf.map(transformSchema);
|
|
1764
|
-
if (property.items) if (Array.isArray(property.items)) newProperty.items = property.items.map(transformSchema);
|
|
1765
|
-
else newProperty.items = transformSchema(property.items);
|
|
1766
|
-
return newProperty;
|
|
1767
|
-
};
|
|
1768
|
-
/**
|
|
1769
|
-
* Transforms the properties of the tool schema to include the file upload URL.
|
|
1770
|
-
*
|
|
1771
|
-
* Attaches the format: 'path' to the properties that are file uploadable for agents.
|
|
1772
|
-
*
|
|
1773
|
-
* @param properties - The properties of the tool schema.
|
|
1774
|
-
* @returns The transformed properties.
|
|
1775
|
-
*/
|
|
1776
|
-
const transformProperties = (properties) => {
|
|
1777
|
-
const newProperties = {};
|
|
1778
|
-
for (const [key, property] of Object.entries(properties)) newProperties[key] = transformSchema(property);
|
|
1779
|
-
return newProperties;
|
|
1780
|
-
};
|
|
1781
|
-
/**
|
|
1782
|
-
* Recursively checks if a schema (or any of its variants) contains a specific file property.
|
|
1783
|
-
*/
|
|
1784
|
-
const schemaHasFileProperty = (schema, property) => {
|
|
1785
|
-
if (!schema) return false;
|
|
1786
|
-
if (schema[property]) return true;
|
|
1787
|
-
if (schema.properties) {
|
|
1788
|
-
for (const prop of Object.values(schema.properties)) if (schemaHasFileProperty(prop, property)) return true;
|
|
1789
|
-
}
|
|
1790
|
-
if (schema.anyOf) {
|
|
1791
|
-
for (const variant of schema.anyOf) if (schemaHasFileProperty(variant, property)) return true;
|
|
1792
|
-
}
|
|
1793
|
-
if (schema.oneOf) {
|
|
1794
|
-
for (const variant of schema.oneOf) if (schemaHasFileProperty(variant, property)) return true;
|
|
1795
|
-
}
|
|
1796
|
-
if (schema.allOf) {
|
|
1797
|
-
for (const variant of schema.allOf) if (schemaHasFileProperty(variant, property)) return true;
|
|
1798
|
-
}
|
|
1799
|
-
if (schema.items) {
|
|
1800
|
-
if (Array.isArray(schema.items)) {
|
|
1801
|
-
for (const item of schema.items) if (schemaHasFileProperty(item, property)) return true;
|
|
1802
|
-
} else if (schemaHasFileProperty(schema.items, property)) return true;
|
|
1803
|
-
}
|
|
1804
|
-
return false;
|
|
1805
|
-
};
|
|
1806
|
-
/**
|
|
1807
|
-
* Recursively checks if a schema (or any of its variants) contains file_uploadable properties.
|
|
1808
|
-
*/
|
|
1809
|
-
const schemaHasFileUploadable = (schema) => {
|
|
1810
|
-
return schemaHasFileProperty(schema, "file_uploadable");
|
|
1811
|
-
};
|
|
1812
|
-
/**
|
|
1813
|
-
* Recursively checks if a schema (or any of its variants) contains file_downloadable properties.
|
|
1814
|
-
*/
|
|
1815
|
-
const schemaHasFileDownloadable = (schema) => {
|
|
1816
|
-
return schemaHasFileProperty(schema, "file_downloadable");
|
|
1817
|
-
};
|
|
1818
|
-
/**
|
|
1819
|
-
* Recursively walks a runtime value and its matching JSON-Schema node,
|
|
1820
|
-
* uploading any string path whose schema node has `file_uploadable: true`.
|
|
1821
|
-
* The function returns a **new** value with all substitutions applied;
|
|
1822
|
-
* nothing is mutated in-place.
|
|
1823
|
-
*/
|
|
1824
|
-
const hydrateFiles = async (value, schema, ctx) => {
|
|
1825
|
-
if (schema?.file_uploadable) {
|
|
1826
|
-
if (typeof value !== "string" && !(value instanceof File)) return value;
|
|
1827
|
-
logger_default.debug(`Uploading file "${value}"`);
|
|
1828
|
-
return getFileDataAfterUploadingToS3(value, {
|
|
1829
|
-
toolSlug: ctx.toolSlug,
|
|
1830
|
-
toolkitSlug: ctx.toolkitSlug,
|
|
1831
|
-
client: ctx.client
|
|
1832
|
-
});
|
|
1833
|
-
}
|
|
1834
|
-
const schemaVariants = [
|
|
1835
|
-
...schema?.anyOf ?? [],
|
|
1836
|
-
...schema?.oneOf ?? [],
|
|
1837
|
-
...schema?.allOf ?? []
|
|
1838
|
-
];
|
|
1839
|
-
if (schemaVariants.length > 0) {
|
|
1840
|
-
const uploadableVariants = schemaVariants.filter(schemaHasFileUploadable);
|
|
1841
|
-
if (uploadableVariants.length > 0) {
|
|
1842
|
-
let result = value;
|
|
1843
|
-
for (const variant of uploadableVariants) result = await hydrateFiles(result, variant, ctx);
|
|
1844
|
-
return result;
|
|
1845
|
-
}
|
|
1846
|
-
}
|
|
1847
|
-
if (schema?.type === "object" && schema.properties && isPlainObject(value)) {
|
|
1848
|
-
const transformed = {};
|
|
1849
|
-
for (const [k, v] of Object.entries(value)) transformed[k] = await hydrateFiles(v, schema.properties[k], ctx);
|
|
1850
|
-
return transformed;
|
|
1851
|
-
}
|
|
1852
|
-
if (schema?.type === "array" && schema.items && Array.isArray(value)) {
|
|
1853
|
-
const itemSchema = Array.isArray(schema.items) ? schema.items[0] : schema.items;
|
|
1854
|
-
return Promise.all(value.map((item) => hydrateFiles(item, itemSchema, ctx)));
|
|
1855
|
-
}
|
|
1856
|
-
return value;
|
|
1857
|
-
};
|
|
1858
|
-
/**
|
|
1859
|
-
* Downloads a file from S3 and returns a replacement object.
|
|
1860
|
-
*/
|
|
1861
|
-
const downloadS3File = async (value, ctx) => {
|
|
1862
|
-
const { s3url, mimetype } = value;
|
|
1863
|
-
try {
|
|
1864
|
-
logger_default.debug(`Downloading from S3: ${s3url}`);
|
|
1865
|
-
const dl = await downloadFileFromS3({
|
|
1866
|
-
toolSlug: ctx.toolSlug,
|
|
1867
|
-
s3Url: s3url,
|
|
1868
|
-
mimeType: mimetype ?? "application/octet-stream"
|
|
1869
|
-
});
|
|
1870
|
-
logger_default.debug(`Downloaded → ${dl.filePath}`);
|
|
1871
|
-
return {
|
|
1872
|
-
uri: dl.filePath,
|
|
1873
|
-
file_downloaded: dl.filePath ? true : false,
|
|
1874
|
-
s3url,
|
|
1875
|
-
mimeType: dl.mimeType
|
|
1876
|
-
};
|
|
1877
|
-
} catch (err) {
|
|
1878
|
-
logger_default.error(`Download failed: ${s3url}`, { cause: err });
|
|
1879
|
-
return {
|
|
1880
|
-
uri: "",
|
|
1881
|
-
file_downloaded: false,
|
|
1882
|
-
s3url,
|
|
1883
|
-
mimeType: mimetype ?? "application/octet-stream"
|
|
1884
|
-
};
|
|
1885
|
-
}
|
|
1886
|
-
};
|
|
1887
|
-
/**
|
|
1888
|
-
* Recursively walks an arbitrary value and its matching JSON-Schema node.
|
|
1889
|
-
* Whenever it encounters an object that represents a file reference
|
|
1890
|
-
* (i.e. has an `s3url`), it downloads the file and returns a replacement:
|
|
1891
|
-
* {
|
|
1892
|
-
* uri: "<local-path>",
|
|
1893
|
-
* file_downloaded: true | false,
|
|
1894
|
-
* s3url: "<original S3 URL>",
|
|
1895
|
-
* mimeType: "<detected-or-fallback-mime-type>"
|
|
1896
|
-
* }
|
|
1897
|
-
*
|
|
1898
|
-
* The function is side-effect-free: it never mutates the input value.
|
|
1899
|
-
*/
|
|
1900
|
-
const hydrateDownloads = async (value, schema, ctx) => {
|
|
1901
|
-
if (isPlainObject(value) && typeof value.s3url === "string") return downloadS3File(value, ctx);
|
|
1902
|
-
if (schema?.file_downloadable && isPlainObject(value) && typeof value.s3url === "string") return downloadS3File(value, ctx);
|
|
1903
|
-
const schemaVariants = [
|
|
1904
|
-
...schema?.anyOf ?? [],
|
|
1905
|
-
...schema?.oneOf ?? [],
|
|
1906
|
-
...schema?.allOf ?? []
|
|
1907
|
-
];
|
|
1908
|
-
if (schemaVariants.length > 0) {
|
|
1909
|
-
const downloadableVariants = schemaVariants.filter(schemaHasFileDownloadable);
|
|
1910
|
-
let result = value;
|
|
1911
|
-
for (const variant of downloadableVariants) result = await hydrateDownloads(result, variant, ctx);
|
|
1912
|
-
if (downloadableVariants.length === 0) return hydrateDownloads(value, void 0, ctx);
|
|
1913
|
-
return result;
|
|
1914
|
-
}
|
|
1915
|
-
if (isPlainObject(value)) {
|
|
1916
|
-
const pairs = await Promise.all(Object.entries(value).map(async ([k, v]) => [k, await hydrateDownloads(v, schema?.properties?.[k], ctx)]));
|
|
1917
|
-
return Object.fromEntries(pairs);
|
|
1918
|
-
}
|
|
1919
|
-
if (Array.isArray(value)) {
|
|
1920
|
-
const itemSchema = schema?.items ? Array.isArray(schema.items) ? schema.items[0] : schema.items : void 0;
|
|
1921
|
-
return Promise.all(value.map((item) => hydrateDownloads(item, itemSchema, ctx)));
|
|
1922
|
-
}
|
|
1923
|
-
return value;
|
|
1924
|
-
};
|
|
1925
|
-
function isPlainObject(val) {
|
|
1926
|
-
return typeof val === "object" && val !== null && !Array.isArray(val);
|
|
1927
|
-
}
|
|
1928
|
-
var FileToolModifier = class {
|
|
1929
|
-
client;
|
|
1930
|
-
constructor(client) {
|
|
1931
|
-
this.client = client;
|
|
1932
|
-
}
|
|
1933
|
-
/**
|
|
1934
|
-
* Modifies the tool schema to include the file upload URL.
|
|
1935
|
-
*
|
|
1936
|
-
* @description This modifier is used to upload a file to the Composio platform and replace the file path with the file upload URL.
|
|
1937
|
-
*
|
|
1938
|
-
* @param _toolSlug - The slug of the tool that is being executed.
|
|
1939
|
-
* @param _toolkitSlug - The slug of the toolkit that is being executed.
|
|
1940
|
-
* @param schema - The schema of the tool.
|
|
1941
|
-
* @returns The schema with the file upload URL included.
|
|
1942
|
-
*/
|
|
1943
|
-
async modifyToolSchema(toolSlug, toolkitSlug, schema) {
|
|
1944
|
-
if (!schema.inputParameters?.properties) return schema;
|
|
1945
|
-
const properties = transformProperties(schema.inputParameters.properties);
|
|
1946
|
-
return {
|
|
1947
|
-
...schema,
|
|
1948
|
-
inputParameters: {
|
|
1949
|
-
...schema.inputParameters,
|
|
1950
|
-
properties
|
|
1951
|
-
}
|
|
1952
|
-
};
|
|
1953
|
-
}
|
|
1954
|
-
/**
|
|
1955
|
-
* Modifies the input parameters to include the file upload URL.
|
|
1956
|
-
*
|
|
1957
|
-
* @description This modifier is used to upload a file to the Composio platform and replace the file path with the file upload URL.
|
|
1958
|
-
*
|
|
1959
|
-
* @param toolSlug - The slug of the tool that is being executed.
|
|
1960
|
-
* @param toolkitSlug - The slug of the toolkit that is being executed.
|
|
1961
|
-
*
|
|
1962
|
-
*/
|
|
1963
|
-
async fileUploadModifier(tool, options) {
|
|
1964
|
-
const { params, toolSlug, toolkitSlug = "unknown" } = options;
|
|
1965
|
-
const { arguments: args } = params;
|
|
1966
|
-
if (!args || typeof args !== "object") return params;
|
|
1967
|
-
try {
|
|
1968
|
-
const newArgs = await hydrateFiles(args, tool.inputParameters, {
|
|
1969
|
-
toolSlug,
|
|
1970
|
-
toolkitSlug,
|
|
1971
|
-
client: this.client
|
|
1972
|
-
});
|
|
1973
|
-
return {
|
|
1974
|
-
...params,
|
|
1975
|
-
arguments: newArgs
|
|
1976
|
-
};
|
|
1977
|
-
} catch (error) {
|
|
1978
|
-
throw new ComposioFileUploadError("Failed to upload file", { cause: error });
|
|
1979
|
-
}
|
|
1980
|
-
}
|
|
1981
|
-
/**
|
|
1982
|
-
* Modifies the result to include the file download URL.
|
|
1983
|
-
*
|
|
1984
|
-
* @description This modifier is used to download a file and
|
|
1985
|
-
*
|
|
1986
|
-
* @param tool - The tool schema containing output parameters.
|
|
1987
|
-
* @param toolSlug - The slug of the tool that is being executed.
|
|
1988
|
-
* @param toolkitSlug - The slug of the toolkit that is being executed.
|
|
1989
|
-
* @param result - The result of the tool execution.
|
|
1990
|
-
* @returns The result with the file download URL included.
|
|
1991
|
-
*/
|
|
1992
|
-
async fileDownloadModifier(tool, options) {
|
|
1993
|
-
const { result, toolSlug } = options;
|
|
1994
|
-
const dataWithDownloads = await hydrateDownloads(result.data, tool.outputParameters, { toolSlug });
|
|
1995
|
-
return {
|
|
1996
|
-
...result,
|
|
1997
|
-
data: dataWithDownloads
|
|
1998
|
-
};
|
|
1999
|
-
}
|
|
2000
|
-
};
|
|
2001
|
-
|
|
2002
1733
|
//#endregion
|
|
2003
1734
|
//#region src/utils/toolkitVersion.ts
|
|
2004
1735
|
/**
|
|
@@ -2032,8 +1763,8 @@ var Tools = class {
|
|
|
2032
1763
|
this.client = client;
|
|
2033
1764
|
this.customTools = new CustomTools(client);
|
|
2034
1765
|
this.provider = config.provider;
|
|
2035
|
-
this.autoUploadDownloadFiles = config?.autoUploadDownloadFiles ??
|
|
2036
|
-
this.toolkitVersions = config?.toolkitVersions ??
|
|
1766
|
+
this.autoUploadDownloadFiles = config?.autoUploadDownloadFiles ?? CONFIG_DEFAULTS.autoUploadDownloadFiles;
|
|
1767
|
+
this.toolkitVersions = config?.toolkitVersions ?? CONFIG_DEFAULTS.toolkitVersions;
|
|
2037
1768
|
this.execute = this.execute.bind(this);
|
|
2038
1769
|
this.provider._setExecuteToolFn(this.createExecuteFnForProviders());
|
|
2039
1770
|
this.getRawComposioToolBySlug = this.getRawComposioToolBySlug.bind(this);
|
|
@@ -2323,7 +2054,8 @@ var Tools = class {
|
|
|
2323
2054
|
} else logger_default.debug(`Tool ${slug} is not a custom tool. Fetching from Composio API`);
|
|
2324
2055
|
let tool;
|
|
2325
2056
|
try {
|
|
2326
|
-
|
|
2057
|
+
const retrieveParams = options?.version ? { version: options.version } : { toolkit_versions: this.toolkitVersions };
|
|
2058
|
+
tool = await this.client.tools.retrieve(slug, retrieveParams);
|
|
2327
2059
|
} catch (error) {
|
|
2328
2060
|
throw new ComposioToolNotFoundError(`Unable to retrieve tool with slug ${slug}`, { cause: error });
|
|
2329
2061
|
}
|
|
@@ -2541,7 +2273,7 @@ var Tools = class {
|
|
|
2541
2273
|
const executeParams = ToolExecuteParamsSchema.safeParse(body);
|
|
2542
2274
|
if (!executeParams.success) throw new ValidationError("Invalid tool execute parameters", { cause: executeParams.error });
|
|
2543
2275
|
const customTool = await this.customTools.getCustomToolBySlug(slug);
|
|
2544
|
-
const tool = customTool ?? await this.getRawComposioToolBySlug(slug);
|
|
2276
|
+
const tool = customTool ?? await this.getRawComposioToolBySlug(slug, { version: body.version });
|
|
2545
2277
|
const toolkitSlug = tool.toolkit?.slug ?? "unknown";
|
|
2546
2278
|
const params = await this.applyBeforeExecuteModifiers(tool, {
|
|
2547
2279
|
toolSlug: slug,
|
|
@@ -3972,11 +3704,26 @@ const WebhookVersions = {
|
|
|
3972
3704
|
* Parameters for verifying a webhook signature
|
|
3973
3705
|
*/
|
|
3974
3706
|
const VerifyWebhookParamsSchema = z$1.object({
|
|
3975
|
-
id: z$1.string(
|
|
3976
|
-
|
|
3977
|
-
|
|
3978
|
-
|
|
3979
|
-
|
|
3707
|
+
id: z$1.string({
|
|
3708
|
+
required_error: "Missing 'id' parameter. Pass the value of the 'webhook-id' HTTP header.",
|
|
3709
|
+
invalid_type_error: "Invalid 'id' parameter. Expected string from 'webhook-id' HTTP header."
|
|
3710
|
+
}),
|
|
3711
|
+
payload: z$1.string({
|
|
3712
|
+
required_error: "Missing 'payload' parameter. Pass the raw request body as a string (do not parse it).",
|
|
3713
|
+
invalid_type_error: "Invalid 'payload' parameter. Expected string (raw request body)."
|
|
3714
|
+
}),
|
|
3715
|
+
secret: z$1.string({
|
|
3716
|
+
required_error: "Missing 'secret' parameter. Get your webhook secret from the Composio dashboard.",
|
|
3717
|
+
invalid_type_error: "Invalid 'secret' parameter. Expected string."
|
|
3718
|
+
}),
|
|
3719
|
+
signature: z$1.string({
|
|
3720
|
+
required_error: "Missing 'signature' parameter. Pass the value of the 'webhook-signature' HTTP header.",
|
|
3721
|
+
invalid_type_error: "Invalid 'signature' parameter. Expected string from 'webhook-signature' HTTP header."
|
|
3722
|
+
}),
|
|
3723
|
+
timestamp: z$1.string({
|
|
3724
|
+
required_error: "Missing 'timestamp' parameter. Pass the value of the 'webhook-timestamp' HTTP header.",
|
|
3725
|
+
invalid_type_error: "Invalid 'timestamp' parameter. Expected string from 'webhook-timestamp' HTTP header."
|
|
3726
|
+
}),
|
|
3980
3727
|
tolerance: z$1.number().optional().default(300)
|
|
3981
3728
|
});
|
|
3982
3729
|
|
|
@@ -4242,9 +3989,44 @@ function transformTriggerInstanceListActiveResponse(response) {
|
|
|
4242
3989
|
}));
|
|
4243
3990
|
}
|
|
4244
3991
|
|
|
3992
|
+
//#endregion
|
|
3993
|
+
//#region src/utils/crypto.ts
|
|
3994
|
+
/**
|
|
3995
|
+
* Computes HMAC-SHA256 using Web Crypto API
|
|
3996
|
+
*/
|
|
3997
|
+
async function hmacSha256Base64(secret, message) {
|
|
3998
|
+
const encoder = new TextEncoder();
|
|
3999
|
+
const keyData = encoder.encode(secret);
|
|
4000
|
+
const key = await globalThis.crypto.subtle.importKey("raw", keyData, {
|
|
4001
|
+
name: "HMAC",
|
|
4002
|
+
hash: "SHA-256"
|
|
4003
|
+
}, false, ["sign"]);
|
|
4004
|
+
const signatureData = encoder.encode(message);
|
|
4005
|
+
return arrayBufferToBase64(await globalThis.crypto.subtle.sign("HMAC", key, signatureData));
|
|
4006
|
+
}
|
|
4007
|
+
/**
|
|
4008
|
+
* Constant-time comparison of two strings to prevent timing attacks
|
|
4009
|
+
*/
|
|
4010
|
+
function timingSafeEqual(a, b) {
|
|
4011
|
+
if (a.length !== b.length) return false;
|
|
4012
|
+
let result = 0;
|
|
4013
|
+
for (let i = 0; i < a.length; i++) result |= a.charCodeAt(i) ^ b.charCodeAt(i);
|
|
4014
|
+
return result === 0;
|
|
4015
|
+
}
|
|
4016
|
+
|
|
4245
4017
|
//#endregion
|
|
4246
4018
|
//#region src/models/Triggers.ts
|
|
4247
4019
|
/**
|
|
4020
|
+
* Safely converts a value to a string, returning the default if the value is null, undefined, or empty.
|
|
4021
|
+
* This prevents runtime crashes when calling string methods like `.toLowerCase()` on non-string values.
|
|
4022
|
+
* @private
|
|
4023
|
+
*/
|
|
4024
|
+
const toStringOrDefault = (value, defaultValue) => {
|
|
4025
|
+
if (value === null || value === void 0) return defaultValue;
|
|
4026
|
+
const str = String(value);
|
|
4027
|
+
return str.length > 0 ? str : defaultValue;
|
|
4028
|
+
};
|
|
4029
|
+
/**
|
|
4248
4030
|
* Trigger (Instance) class
|
|
4249
4031
|
* /api/v3/trigger_instances
|
|
4250
4032
|
*
|
|
@@ -4256,7 +4038,7 @@ var Triggers = class {
|
|
|
4256
4038
|
constructor(client, config) {
|
|
4257
4039
|
this.client = client;
|
|
4258
4040
|
this.pusherService = new PusherService(client);
|
|
4259
|
-
this.toolkitVersions = config?.toolkitVersions ??
|
|
4041
|
+
this.toolkitVersions = config?.toolkitVersions ?? CONFIG_DEFAULTS.toolkitVersions;
|
|
4260
4042
|
telemetry.instrument(this, "Triggers");
|
|
4261
4043
|
}
|
|
4262
4044
|
/**
|
|
@@ -4478,7 +4260,7 @@ var Triggers = class {
|
|
|
4478
4260
|
logger_default.debug("🔄 Subscribing to triggers with filters: ", JSON.stringify(filters, null, 2));
|
|
4479
4261
|
await this.pusherService.subscribe((_data) => {
|
|
4480
4262
|
logger_default.debug("Received raw trigger data", JSON.stringify(_data, null, 2));
|
|
4481
|
-
const parsedData =
|
|
4263
|
+
const parsedData = this.parsePusherPayload(_data);
|
|
4482
4264
|
if (this.shouldSendTriggerAfterFilters(parsedFilters.data, parsedData)) try {
|
|
4483
4265
|
fn(parsedData);
|
|
4484
4266
|
} catch (error) {
|
|
@@ -4488,6 +4270,86 @@ var Triggers = class {
|
|
|
4488
4270
|
});
|
|
4489
4271
|
}
|
|
4490
4272
|
/**
|
|
4273
|
+
* Tries to parse data as V1, V2, or V3 webhook payload format.
|
|
4274
|
+
* Returns the parsed result with version info, or null if no format matches.
|
|
4275
|
+
* Also returns any schema validation errors for debugging purposes.
|
|
4276
|
+
* @private
|
|
4277
|
+
*/
|
|
4278
|
+
tryParseVersionedPayload(data) {
|
|
4279
|
+
const v3Result = WebhookPayloadV3Schema.safeParse(data);
|
|
4280
|
+
if (v3Result.success) return {
|
|
4281
|
+
ok: true,
|
|
4282
|
+
version: WebhookVersions.V3,
|
|
4283
|
+
rawPayload: v3Result.data,
|
|
4284
|
+
normalizedPayload: this.normalizeV3Payload(v3Result.data)
|
|
4285
|
+
};
|
|
4286
|
+
const v2Result = WebhookPayloadV2Schema.safeParse(data);
|
|
4287
|
+
if (v2Result.success) return {
|
|
4288
|
+
ok: true,
|
|
4289
|
+
version: WebhookVersions.V2,
|
|
4290
|
+
rawPayload: v2Result.data,
|
|
4291
|
+
normalizedPayload: this.normalizeV2Payload(v2Result.data)
|
|
4292
|
+
};
|
|
4293
|
+
const v1Result = WebhookPayloadV1Schema.safeParse(data);
|
|
4294
|
+
if (v1Result.success) return {
|
|
4295
|
+
ok: true,
|
|
4296
|
+
version: WebhookVersions.V1,
|
|
4297
|
+
rawPayload: v1Result.data,
|
|
4298
|
+
normalizedPayload: this.normalizeV1Payload(v1Result.data)
|
|
4299
|
+
};
|
|
4300
|
+
return {
|
|
4301
|
+
ok: false,
|
|
4302
|
+
v1Error: v1Result.error.message,
|
|
4303
|
+
v2Error: v2Result.error.message,
|
|
4304
|
+
v3Error: v3Result.error.message
|
|
4305
|
+
};
|
|
4306
|
+
}
|
|
4307
|
+
/**
|
|
4308
|
+
* Parses incoming Pusher payload, supporting V1, V2, V3, and legacy TriggerData formats.
|
|
4309
|
+
* @private
|
|
4310
|
+
*/
|
|
4311
|
+
parsePusherPayload(data) {
|
|
4312
|
+
const versionedResult = this.tryParseVersionedPayload(data);
|
|
4313
|
+
if (versionedResult.ok) {
|
|
4314
|
+
logger_default.debug(`Parsed Pusher payload as ${versionedResult.version} format`);
|
|
4315
|
+
return versionedResult.normalizedPayload;
|
|
4316
|
+
}
|
|
4317
|
+
const legacyData = data;
|
|
4318
|
+
if (legacyData.metadata?.nanoId && legacyData.appName) {
|
|
4319
|
+
logger_default.debug("Parsed Pusher payload as legacy TriggerData format");
|
|
4320
|
+
return transformIncomingTriggerPayload(legacyData);
|
|
4321
|
+
}
|
|
4322
|
+
logger_default.warn("Unknown Pusher payload format. Payload keys: " + Object.keys(data).join(", "));
|
|
4323
|
+
const id = toStringOrDefault(data.id, toStringOrDefault(data.trigger_id, "unknown"));
|
|
4324
|
+
const uuid = toStringOrDefault(data.uuid, toStringOrDefault(data.id, "unknown"));
|
|
4325
|
+
const triggerSlug = toStringOrDefault(data.triggerSlug, toStringOrDefault(data.trigger_name, "UNKNOWN"));
|
|
4326
|
+
const toolkitSlug = toStringOrDefault(data.toolkitSlug, toStringOrDefault(data.appName, "UNKNOWN"));
|
|
4327
|
+
return {
|
|
4328
|
+
id,
|
|
4329
|
+
uuid,
|
|
4330
|
+
triggerSlug,
|
|
4331
|
+
toolkitSlug,
|
|
4332
|
+
userId: toStringOrDefault(data.userId, ""),
|
|
4333
|
+
payload: data.payload || data,
|
|
4334
|
+
originalPayload: data.originalPayload || data,
|
|
4335
|
+
metadata: {
|
|
4336
|
+
id,
|
|
4337
|
+
uuid,
|
|
4338
|
+
triggerSlug,
|
|
4339
|
+
toolkitSlug,
|
|
4340
|
+
triggerConfig: {},
|
|
4341
|
+
connectedAccount: {
|
|
4342
|
+
id: "",
|
|
4343
|
+
uuid: "",
|
|
4344
|
+
authConfigId: "",
|
|
4345
|
+
authConfigUUID: "",
|
|
4346
|
+
userId: "",
|
|
4347
|
+
status: "ACTIVE"
|
|
4348
|
+
}
|
|
4349
|
+
}
|
|
4350
|
+
};
|
|
4351
|
+
}
|
|
4352
|
+
/**
|
|
4491
4353
|
* Unsubscribe from all the triggers
|
|
4492
4354
|
*
|
|
4493
4355
|
* @returns {Promise<void>}
|
|
@@ -4530,9 +4392,9 @@ var Triggers = class {
|
|
|
4530
4392
|
* @example
|
|
4531
4393
|
* ```ts
|
|
4532
4394
|
* // In an Express.js webhook handler
|
|
4533
|
-
* app.post('/webhook', express.raw({ type: 'application/json' }), (req, res) => {
|
|
4395
|
+
* app.post('/webhook', express.raw({ type: 'application/json' }), async (req, res) => {
|
|
4534
4396
|
* try {
|
|
4535
|
-
* const result = composio.triggers.verifyWebhook({
|
|
4397
|
+
* const result = await composio.triggers.verifyWebhook({
|
|
4536
4398
|
* payload: req.body.toString(),
|
|
4537
4399
|
* signature: req.headers['webhook-signature'] as string,
|
|
4538
4400
|
* webhookId: req.headers['webhook-id'] as string,
|
|
@@ -4551,12 +4413,24 @@ var Triggers = class {
|
|
|
4551
4413
|
* });
|
|
4552
4414
|
* ```
|
|
4553
4415
|
*/
|
|
4554
|
-
verifyWebhook(params) {
|
|
4416
|
+
async verifyWebhook(params) {
|
|
4555
4417
|
const parsedParams = VerifyWebhookParamsSchema.safeParse(params);
|
|
4556
|
-
if (!parsedParams.success)
|
|
4418
|
+
if (!parsedParams.success) {
|
|
4419
|
+
const missingParams = parsedParams.error.issues.filter((issue) => issue.code === "invalid_type" && issue.received === "undefined").map((issue) => {
|
|
4420
|
+
const paramName = issue.path[0];
|
|
4421
|
+
const headerName = {
|
|
4422
|
+
id: "webhook-id",
|
|
4423
|
+
timestamp: "webhook-timestamp",
|
|
4424
|
+
signature: "webhook-signature"
|
|
4425
|
+
}[paramName];
|
|
4426
|
+
return headerName ? `'${paramName}' (from '${headerName}' header)` : `'${paramName}'`;
|
|
4427
|
+
});
|
|
4428
|
+
if (missingParams.length > 0) throw new ValidationError(`Missing required parameters: ${missingParams.join(", ")}. Extract these values from the HTTP request headers and body.`, { cause: parsedParams.error });
|
|
4429
|
+
throw new ValidationError("Invalid parameters passed to verifyWebhook", { cause: parsedParams.error });
|
|
4430
|
+
}
|
|
4557
4431
|
const { payload, signature, secret, id: webhookId, timestamp: webhookTimestamp, tolerance } = parsedParams.data;
|
|
4558
4432
|
if (tolerance > 0) this.validateWebhookTimestamp(webhookTimestamp, tolerance);
|
|
4559
|
-
this.verifyWebhookSignature(webhookId, webhookTimestamp, payload, signature, secret);
|
|
4433
|
+
await this.verifyWebhookSignature(webhookId, webhookTimestamp, payload, signature, secret);
|
|
4560
4434
|
const { version: version$1, rawPayload, normalizedPayload } = this.parseWebhookPayload(payload);
|
|
4561
4435
|
return {
|
|
4562
4436
|
version: version$1,
|
|
@@ -4575,28 +4449,16 @@ var Triggers = class {
|
|
|
4575
4449
|
} catch (error) {
|
|
4576
4450
|
throw new ComposioWebhookPayloadError("Failed to parse webhook payload as JSON", { cause: error });
|
|
4577
4451
|
}
|
|
4578
|
-
const
|
|
4579
|
-
if (
|
|
4580
|
-
|
|
4581
|
-
|
|
4582
|
-
|
|
4583
|
-
};
|
|
4584
|
-
const v2Result = WebhookPayloadV2Schema.safeParse(jsonPayload);
|
|
4585
|
-
if (v2Result.success) return {
|
|
4586
|
-
version: WebhookVersions.V2,
|
|
4587
|
-
rawPayload: v2Result.data,
|
|
4588
|
-
normalizedPayload: this.normalizeV2Payload(v2Result.data)
|
|
4589
|
-
};
|
|
4590
|
-
const v1Result = WebhookPayloadV1Schema.safeParse(jsonPayload);
|
|
4591
|
-
if (v1Result.success) return {
|
|
4592
|
-
version: WebhookVersions.V1,
|
|
4593
|
-
rawPayload: v1Result.data,
|
|
4594
|
-
normalizedPayload: this.normalizeV1Payload(v1Result.data)
|
|
4595
|
-
};
|
|
4452
|
+
const result = this.tryParseVersionedPayload(jsonPayload);
|
|
4453
|
+
if (result.ok) {
|
|
4454
|
+
const { ok, ...rest } = result;
|
|
4455
|
+
return rest;
|
|
4456
|
+
}
|
|
4457
|
+
const { v1Error, v2Error, v3Error } = result;
|
|
4596
4458
|
throw new ComposioWebhookPayloadError("Webhook payload does not match any known version (V1, V2, or V3). Please ensure you are using a supported webhook payload format.", { cause: {
|
|
4597
|
-
v1Error
|
|
4598
|
-
v2Error
|
|
4599
|
-
v3Error
|
|
4459
|
+
v1Error,
|
|
4460
|
+
v2Error,
|
|
4461
|
+
v3Error
|
|
4600
4462
|
} });
|
|
4601
4463
|
}
|
|
4602
4464
|
/**
|
|
@@ -4702,7 +4564,7 @@ var Triggers = class {
|
|
|
4702
4564
|
* The signing input is: `${msgId}.${timestamp}.${payload}`
|
|
4703
4565
|
* @private
|
|
4704
4566
|
*/
|
|
4705
|
-
verifyWebhookSignature(webhookId, webhookTimestamp, payload, signature, secret) {
|
|
4567
|
+
async verifyWebhookSignature(webhookId, webhookTimestamp, payload, signature, secret) {
|
|
4706
4568
|
if (payload.length === 0) throw new ComposioWebhookSignatureVerificationError("No webhook payload was provided.");
|
|
4707
4569
|
if (signature.length === 0) throw new ComposioWebhookSignatureVerificationError("No signature header value was provided. Please pass the value of the 'webhook-signature' header.");
|
|
4708
4570
|
if (secret.length === 0) throw new ComposioWebhookSignatureVerificationError("No webhook secret was provided. You can find your webhook secret in your Composio dashboard.");
|
|
@@ -4715,16 +4577,11 @@ var Triggers = class {
|
|
|
4715
4577
|
if (version$1 === "v1" && value) v1Signatures.push(value);
|
|
4716
4578
|
}
|
|
4717
4579
|
if (v1Signatures.length === 0) throw new ComposioWebhookSignatureVerificationError("No valid v1 signature found in the webhook-signature header. Expected format: 'v1,base64EncodedSignature'");
|
|
4718
|
-
const
|
|
4719
|
-
const expectedSignature = crypto$1.createHmac("sha256", secret).update(toSign, "utf8").digest("base64");
|
|
4580
|
+
const expectedSignature = await hmacSha256Base64(secret, `${webhookId}.${webhookTimestamp}.${payload}`);
|
|
4720
4581
|
let isValid = false;
|
|
4721
|
-
for (const providedSignature of v1Signatures) {
|
|
4722
|
-
|
|
4723
|
-
|
|
4724
|
-
if (signatureBuffer.length === expectedBuffer.length && crypto$1.timingSafeEqual(signatureBuffer, expectedBuffer)) {
|
|
4725
|
-
isValid = true;
|
|
4726
|
-
break;
|
|
4727
|
-
}
|
|
4582
|
+
for (const providedSignature of v1Signatures) if (timingSafeEqual(providedSignature, expectedSignature)) {
|
|
4583
|
+
isValid = true;
|
|
4584
|
+
break;
|
|
4728
4585
|
}
|
|
4729
4586
|
if (!isValid) throw new ComposioWebhookSignatureVerificationError("The signature provided is invalid. Please ensure you are using the correct webhook secret.");
|
|
4730
4587
|
}
|
|
@@ -5723,7 +5580,7 @@ var OpenAIProvider = class extends BaseNonAgenticProvider {
|
|
|
5723
5580
|
|
|
5724
5581
|
//#endregion
|
|
5725
5582
|
//#region package.json
|
|
5726
|
-
var version = "0.
|
|
5583
|
+
var version = "0.6.1";
|
|
5727
5584
|
|
|
5728
5585
|
//#endregion
|
|
5729
5586
|
//#region src/utils/session.ts
|
|
@@ -6248,8 +6105,8 @@ var Composio = class Composio {
|
|
|
6248
6105
|
baseURL: baseURLParsed,
|
|
6249
6106
|
apiKey: apiKeyParsed,
|
|
6250
6107
|
toolkitVersions: getToolkitVersionsFromEnv(config?.toolkitVersions),
|
|
6251
|
-
allowTracking: config?.allowTracking ??
|
|
6252
|
-
autoUploadDownloadFiles: config?.autoUploadDownloadFiles ??
|
|
6108
|
+
allowTracking: config?.allowTracking ?? CONFIG_DEFAULTS.allowTracking,
|
|
6109
|
+
autoUploadDownloadFiles: config?.autoUploadDownloadFiles ?? CONFIG_DEFAULTS.autoUploadDownloadFiles,
|
|
6253
6110
|
provider: config?.provider ?? this.provider
|
|
6254
6111
|
};
|
|
6255
6112
|
/**
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
require('../buffer-CYf1Z6Sd.cjs');
|
|
2
|
+
const require_Telemetry = require('../Telemetry-DErMJqj0.cjs');
|
|
3
|
+
const require_fileUtils_node = require('../fileUtils.node-DLp53qm1.cjs');
|
|
2
4
|
|
|
3
5
|
//#region src/models/Files.node.ts
|
|
4
6
|
var Files = class {
|
|
5
7
|
constructor(client) {
|
|
6
8
|
this.client = client;
|
|
7
|
-
|
|
9
|
+
require_Telemetry.telemetry.instrument(this, "Files");
|
|
8
10
|
}
|
|
9
11
|
/**
|
|
10
12
|
* Upload a file and return the file data.
|
|
@@ -24,7 +26,7 @@ var Files = class {
|
|
|
24
26
|
* });
|
|
25
27
|
* */
|
|
26
28
|
async upload({ file, toolSlug, toolkitSlug }) {
|
|
27
|
-
return await
|
|
29
|
+
return await require_fileUtils_node.getFileDataAfterUploadingToS3(file, {
|
|
28
30
|
toolSlug,
|
|
29
31
|
toolkitSlug,
|
|
30
32
|
client: this.client
|
|
@@ -36,7 +38,7 @@ var Files = class {
|
|
|
36
38
|
* @returns The file data.
|
|
37
39
|
*/
|
|
38
40
|
async download({ toolSlug, s3Url, mimeType }) {
|
|
39
|
-
return await
|
|
41
|
+
return await require_fileUtils_node.downloadFileFromS3({
|
|
40
42
|
toolSlug,
|
|
41
43
|
s3Url,
|
|
42
44
|
mimeType
|