@composio/core 0.5.2 → 0.5.4
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 +126 -55
- package/dist/index.d.cts +66 -66
- package/dist/index.d.mts +66 -66
- package/dist/index.mjs +126 -55
- package/dist/models/Files.node.cjs +16 -6
- package/dist/models/Files.node.d.cts +16 -6
- package/dist/models/Files.node.d.mts +16 -6
- package/dist/models/Files.node.mjs +16 -6
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -1740,6 +1740,27 @@ var ComposioFileUploadError = class extends ComposioError {
|
|
|
1740
1740
|
//#endregion
|
|
1741
1741
|
//#region src/utils/modifiers/FileToolModifier.ts
|
|
1742
1742
|
/**
|
|
1743
|
+
* Transforms a single JSON schema property, recursively handling nested properties,
|
|
1744
|
+
* anyOf, oneOf, and allOf.
|
|
1745
|
+
*/
|
|
1746
|
+
const transformSchema = (property) => {
|
|
1747
|
+
if (property.file_uploadable) return {
|
|
1748
|
+
title: property.title,
|
|
1749
|
+
description: property.description,
|
|
1750
|
+
format: "path",
|
|
1751
|
+
type: "string",
|
|
1752
|
+
file_uploadable: true
|
|
1753
|
+
};
|
|
1754
|
+
const newProperty = { ...property };
|
|
1755
|
+
if (property.type === "object" && property.properties) newProperty.properties = transformProperties(property.properties);
|
|
1756
|
+
if (property.anyOf) newProperty.anyOf = property.anyOf.map(transformSchema);
|
|
1757
|
+
if (property.oneOf) newProperty.oneOf = property.oneOf.map(transformSchema);
|
|
1758
|
+
if (property.allOf) newProperty.allOf = property.allOf.map(transformSchema);
|
|
1759
|
+
if (property.items) if (Array.isArray(property.items)) newProperty.items = property.items.map(transformSchema);
|
|
1760
|
+
else newProperty.items = transformSchema(property.items);
|
|
1761
|
+
return newProperty;
|
|
1762
|
+
};
|
|
1763
|
+
/**
|
|
1743
1764
|
* Transforms the properties of the tool schema to include the file upload URL.
|
|
1744
1765
|
*
|
|
1745
1766
|
* Attaches the format: 'path' to the properties that are file uploadable for agents.
|
|
@@ -1749,21 +1770,47 @@ var ComposioFileUploadError = class extends ComposioError {
|
|
|
1749
1770
|
*/
|
|
1750
1771
|
const transformProperties = (properties) => {
|
|
1751
1772
|
const newProperties = {};
|
|
1752
|
-
for (const [key, property] of Object.entries(properties))
|
|
1753
|
-
title: property.title,
|
|
1754
|
-
description: property.description,
|
|
1755
|
-
format: "path",
|
|
1756
|
-
type: "string",
|
|
1757
|
-
file_uploadable: true
|
|
1758
|
-
};
|
|
1759
|
-
else if (property.type === "object" && property.properties) newProperties[key] = {
|
|
1760
|
-
...property,
|
|
1761
|
-
properties: transformProperties(property.properties)
|
|
1762
|
-
};
|
|
1763
|
-
else newProperties[key] = property;
|
|
1773
|
+
for (const [key, property] of Object.entries(properties)) newProperties[key] = transformSchema(property);
|
|
1764
1774
|
return newProperties;
|
|
1765
1775
|
};
|
|
1766
1776
|
/**
|
|
1777
|
+
* Recursively checks if a schema (or any of its variants) contains a specific file property.
|
|
1778
|
+
*/
|
|
1779
|
+
const schemaHasFileProperty = (schema, property) => {
|
|
1780
|
+
if (!schema) return false;
|
|
1781
|
+
if (schema[property]) return true;
|
|
1782
|
+
if (schema.properties) {
|
|
1783
|
+
for (const prop of Object.values(schema.properties)) if (schemaHasFileProperty(prop, property)) return true;
|
|
1784
|
+
}
|
|
1785
|
+
if (schema.anyOf) {
|
|
1786
|
+
for (const variant of schema.anyOf) if (schemaHasFileProperty(variant, property)) return true;
|
|
1787
|
+
}
|
|
1788
|
+
if (schema.oneOf) {
|
|
1789
|
+
for (const variant of schema.oneOf) if (schemaHasFileProperty(variant, property)) return true;
|
|
1790
|
+
}
|
|
1791
|
+
if (schema.allOf) {
|
|
1792
|
+
for (const variant of schema.allOf) if (schemaHasFileProperty(variant, property)) return true;
|
|
1793
|
+
}
|
|
1794
|
+
if (schema.items) {
|
|
1795
|
+
if (Array.isArray(schema.items)) {
|
|
1796
|
+
for (const item of schema.items) if (schemaHasFileProperty(item, property)) return true;
|
|
1797
|
+
} else if (schemaHasFileProperty(schema.items, property)) return true;
|
|
1798
|
+
}
|
|
1799
|
+
return false;
|
|
1800
|
+
};
|
|
1801
|
+
/**
|
|
1802
|
+
* Recursively checks if a schema (or any of its variants) contains file_uploadable properties.
|
|
1803
|
+
*/
|
|
1804
|
+
const schemaHasFileUploadable = (schema) => {
|
|
1805
|
+
return schemaHasFileProperty(schema, "file_uploadable");
|
|
1806
|
+
};
|
|
1807
|
+
/**
|
|
1808
|
+
* Recursively checks if a schema (or any of its variants) contains file_downloadable properties.
|
|
1809
|
+
*/
|
|
1810
|
+
const schemaHasFileDownloadable = (schema) => {
|
|
1811
|
+
return schemaHasFileProperty(schema, "file_downloadable");
|
|
1812
|
+
};
|
|
1813
|
+
/**
|
|
1767
1814
|
* Recursively walks a runtime value and its matching JSON-Schema node,
|
|
1768
1815
|
* uploading any string path whose schema node has `file_uploadable: true`.
|
|
1769
1816
|
* The function returns a **new** value with all substitutions applied;
|
|
@@ -1779,6 +1826,19 @@ const hydrateFiles = async (value, schema, ctx) => {
|
|
|
1779
1826
|
client: ctx.client
|
|
1780
1827
|
});
|
|
1781
1828
|
}
|
|
1829
|
+
const schemaVariants = [
|
|
1830
|
+
...schema?.anyOf ?? [],
|
|
1831
|
+
...schema?.oneOf ?? [],
|
|
1832
|
+
...schema?.allOf ?? []
|
|
1833
|
+
];
|
|
1834
|
+
if (schemaVariants.length > 0) {
|
|
1835
|
+
const uploadableVariants = schemaVariants.filter(schemaHasFileUploadable);
|
|
1836
|
+
if (uploadableVariants.length > 0) {
|
|
1837
|
+
let result = value;
|
|
1838
|
+
for (const variant of uploadableVariants) result = await hydrateFiles(result, variant, ctx);
|
|
1839
|
+
return result;
|
|
1840
|
+
}
|
|
1841
|
+
}
|
|
1782
1842
|
if (schema?.type === "object" && schema.properties && isPlainObject(value)) {
|
|
1783
1843
|
const transformed = {};
|
|
1784
1844
|
for (const [k, v] of Object.entries(value)) transformed[k] = await hydrateFiles(v, schema.properties[k], ctx);
|
|
@@ -1791,6 +1851,35 @@ const hydrateFiles = async (value, schema, ctx) => {
|
|
|
1791
1851
|
return value;
|
|
1792
1852
|
};
|
|
1793
1853
|
/**
|
|
1854
|
+
* Downloads a file from S3 and returns a replacement object.
|
|
1855
|
+
*/
|
|
1856
|
+
const downloadS3File = async (value, ctx) => {
|
|
1857
|
+
const { s3url, mimetype } = value;
|
|
1858
|
+
try {
|
|
1859
|
+
logger_default.debug(`Downloading from S3: ${s3url}`);
|
|
1860
|
+
const dl = await downloadFileFromS3({
|
|
1861
|
+
toolSlug: ctx.toolSlug,
|
|
1862
|
+
s3Url: s3url,
|
|
1863
|
+
mimeType: mimetype ?? "application/octet-stream"
|
|
1864
|
+
});
|
|
1865
|
+
logger_default.debug(`Downloaded → ${dl.filePath}`);
|
|
1866
|
+
return {
|
|
1867
|
+
uri: dl.filePath,
|
|
1868
|
+
file_downloaded: dl.filePath ? true : false,
|
|
1869
|
+
s3url,
|
|
1870
|
+
mimeType: dl.mimeType
|
|
1871
|
+
};
|
|
1872
|
+
} catch (err) {
|
|
1873
|
+
logger_default.error(`Download failed: ${s3url}`, { cause: err });
|
|
1874
|
+
return {
|
|
1875
|
+
uri: "",
|
|
1876
|
+
file_downloaded: false,
|
|
1877
|
+
s3url,
|
|
1878
|
+
mimeType: mimetype ?? "application/octet-stream"
|
|
1879
|
+
};
|
|
1880
|
+
}
|
|
1881
|
+
};
|
|
1882
|
+
/**
|
|
1794
1883
|
* Recursively walks an arbitrary value and its matching JSON-Schema node.
|
|
1795
1884
|
* Whenever it encounters an object that represents a file reference
|
|
1796
1885
|
* (i.e. has an `s3url`), it downloads the file and returns a replacement:
|
|
@@ -1803,49 +1892,29 @@ const hydrateFiles = async (value, schema, ctx) => {
|
|
|
1803
1892
|
*
|
|
1804
1893
|
* The function is side-effect-free: it never mutates the input value.
|
|
1805
1894
|
*/
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
const
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
try {
|
|
1821
|
-
logger_default.debug(`Downloading from S3: ${s3url}`);
|
|
1822
|
-
const dl = await downloadFileFromS3({
|
|
1823
|
-
toolSlug: ctx.toolSlug,
|
|
1824
|
-
s3Url: s3url,
|
|
1825
|
-
mimeType: mimetype ?? "application/octet-stream"
|
|
1826
|
-
});
|
|
1827
|
-
logger_default.debug(`Downloaded → ${dl.filePath}`);
|
|
1828
|
-
return {
|
|
1829
|
-
uri: dl.filePath,
|
|
1830
|
-
file_downloaded: dl.filePath ? true : false,
|
|
1831
|
-
s3url,
|
|
1832
|
-
mimeType: dl.mimeType
|
|
1833
|
-
};
|
|
1834
|
-
} catch (err) {
|
|
1835
|
-
logger_default.error(`Download failed: ${s3url}`, { cause: err });
|
|
1836
|
-
return {
|
|
1837
|
-
uri: "",
|
|
1838
|
-
file_downloaded: false,
|
|
1839
|
-
s3url,
|
|
1840
|
-
mimeType: mimetype ?? "application/octet-stream"
|
|
1841
|
-
};
|
|
1842
|
-
}
|
|
1895
|
+
const hydrateDownloads = async (value, schema, ctx) => {
|
|
1896
|
+
if (isPlainObject(value) && typeof value.s3url === "string") return downloadS3File(value, ctx);
|
|
1897
|
+
if (schema?.file_downloadable && isPlainObject(value) && typeof value.s3url === "string") return downloadS3File(value, ctx);
|
|
1898
|
+
const schemaVariants = [
|
|
1899
|
+
...schema?.anyOf ?? [],
|
|
1900
|
+
...schema?.oneOf ?? [],
|
|
1901
|
+
...schema?.allOf ?? []
|
|
1902
|
+
];
|
|
1903
|
+
if (schemaVariants.length > 0) {
|
|
1904
|
+
const downloadableVariants = schemaVariants.filter(schemaHasFileDownloadable);
|
|
1905
|
+
let result = value;
|
|
1906
|
+
for (const variant of downloadableVariants) result = await hydrateDownloads(result, variant, ctx);
|
|
1907
|
+
if (downloadableVariants.length === 0) return hydrateDownloads(value, void 0, ctx);
|
|
1908
|
+
return result;
|
|
1843
1909
|
}
|
|
1844
1910
|
if (isPlainObject(value)) {
|
|
1845
|
-
const pairs = await Promise.all(Object.entries(value).map(async ([k, v]) => [k, await hydrateDownloads(v, ctx)]));
|
|
1911
|
+
const pairs = await Promise.all(Object.entries(value).map(async ([k, v]) => [k, await hydrateDownloads(v, schema?.properties?.[k], ctx)]));
|
|
1846
1912
|
return Object.fromEntries(pairs);
|
|
1847
1913
|
}
|
|
1848
|
-
if (Array.isArray(value))
|
|
1914
|
+
if (Array.isArray(value)) {
|
|
1915
|
+
const itemSchema = schema?.items ? Array.isArray(schema.items) ? schema.items[0] : schema.items : void 0;
|
|
1916
|
+
return Promise.all(value.map((item) => hydrateDownloads(item, itemSchema, ctx)));
|
|
1917
|
+
}
|
|
1849
1918
|
return value;
|
|
1850
1919
|
};
|
|
1851
1920
|
function isPlainObject(val) {
|
|
@@ -1909,14 +1978,15 @@ var FileToolModifier = class {
|
|
|
1909
1978
|
*
|
|
1910
1979
|
* @description This modifier is used to download a file and
|
|
1911
1980
|
*
|
|
1981
|
+
* @param tool - The tool schema containing output parameters.
|
|
1912
1982
|
* @param toolSlug - The slug of the tool that is being executed.
|
|
1913
1983
|
* @param toolkitSlug - The slug of the toolkit that is being executed.
|
|
1914
1984
|
* @param result - The result of the tool execution.
|
|
1915
1985
|
* @returns The result with the file download URL included.
|
|
1916
1986
|
*/
|
|
1917
|
-
async fileDownloadModifier(
|
|
1987
|
+
async fileDownloadModifier(tool, options) {
|
|
1918
1988
|
const { result, toolSlug } = options;
|
|
1919
|
-
const dataWithDownloads = await hydrateDownloads(result.data, { toolSlug });
|
|
1989
|
+
const dataWithDownloads = await hydrateDownloads(result.data, tool.outputParameters, { toolSlug });
|
|
1920
1990
|
return {
|
|
1921
1991
|
...result,
|
|
1922
1992
|
data: dataWithDownloads
|
|
@@ -3278,7 +3348,8 @@ var ConnectedAccounts = class {
|
|
|
3278
3348
|
async initiate(userId, authConfigId, options) {
|
|
3279
3349
|
const connectedAccount = await this.list({
|
|
3280
3350
|
userIds: [userId],
|
|
3281
|
-
authConfigIds: [authConfigId]
|
|
3351
|
+
authConfigIds: [authConfigId],
|
|
3352
|
+
statuses: [ConnectedAccountStatuses.ACTIVE]
|
|
3282
3353
|
});
|
|
3283
3354
|
if (connectedAccount.items.length > 0 && !options?.allowMultiple) throw new ComposioMultipleConnectedAccountsError(`Multiple connected accounts found for user ${userId} in auth config ${authConfigId}. Please use the allowMultiple option to allow multiple connected accounts.`);
|
|
3284
3355
|
else if (connectedAccount.items.length > 0) logger_default.warn(`[Warn:AllowMultiple] Multiple connected accounts found for user ${userId} in auth config ${authConfigId}`);
|
|
@@ -5633,7 +5704,7 @@ var OpenAIProvider = class extends BaseNonAgenticProvider {
|
|
|
5633
5704
|
|
|
5634
5705
|
//#endregion
|
|
5635
5706
|
//#region package.json
|
|
5636
|
-
var version = "0.5.
|
|
5707
|
+
var version = "0.5.4";
|
|
5637
5708
|
|
|
5638
5709
|
//#endregion
|
|
5639
5710
|
//#region src/utils/session.ts
|
|
@@ -7,12 +7,22 @@ var Files = class {
|
|
|
7
7
|
require_fileUtils.telemetry.instrument(this, "Files");
|
|
8
8
|
}
|
|
9
9
|
/**
|
|
10
|
-
* Upload a file
|
|
11
|
-
*
|
|
12
|
-
* @param
|
|
13
|
-
* @param
|
|
14
|
-
* @
|
|
15
|
-
|
|
10
|
+
* Upload a file and return the file data.
|
|
11
|
+
*
|
|
12
|
+
* @param params - The upload parameters.
|
|
13
|
+
* @param {File | string} params.file - The path to the file to upload, a URL of the file, or a File object.
|
|
14
|
+
* @param {string} params.toolSlug - The slug of the tool that is uploading the file.
|
|
15
|
+
* @param {string} params.toolkitSlug - The slug of the toolkit that is uploading the file.
|
|
16
|
+
* @returns {Promise<FileUploadData>} The uploaded file data.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
*
|
|
20
|
+
* const fileData = await composio.files.upload({
|
|
21
|
+
* file: 'path/to/file.pdf',
|
|
22
|
+
* toolSlug: 'google_drive_upload',
|
|
23
|
+
* toolkitSlug: 'google_drive'
|
|
24
|
+
* });
|
|
25
|
+
* */
|
|
16
26
|
async upload({ file, toolSlug, toolkitSlug }) {
|
|
17
27
|
return await require_fileUtils.getFileDataAfterUploadingToS3(file, {
|
|
18
28
|
toolSlug,
|
|
@@ -7,12 +7,22 @@ declare class Files {
|
|
|
7
7
|
private readonly client;
|
|
8
8
|
constructor(client: ComposioClient);
|
|
9
9
|
/**
|
|
10
|
-
* Upload a file
|
|
11
|
-
*
|
|
12
|
-
* @param
|
|
13
|
-
* @param
|
|
14
|
-
* @
|
|
15
|
-
|
|
10
|
+
* Upload a file and return the file data.
|
|
11
|
+
*
|
|
12
|
+
* @param params - The upload parameters.
|
|
13
|
+
* @param {File | string} params.file - The path to the file to upload, a URL of the file, or a File object.
|
|
14
|
+
* @param {string} params.toolSlug - The slug of the tool that is uploading the file.
|
|
15
|
+
* @param {string} params.toolkitSlug - The slug of the toolkit that is uploading the file.
|
|
16
|
+
* @returns {Promise<FileUploadData>} The uploaded file data.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
*
|
|
20
|
+
* const fileData = await composio.files.upload({
|
|
21
|
+
* file: 'path/to/file.pdf',
|
|
22
|
+
* toolSlug: 'google_drive_upload',
|
|
23
|
+
* toolkitSlug: 'google_drive'
|
|
24
|
+
* });
|
|
25
|
+
* */
|
|
16
26
|
upload({
|
|
17
27
|
file,
|
|
18
28
|
toolSlug,
|
|
@@ -7,12 +7,22 @@ declare class Files {
|
|
|
7
7
|
private readonly client;
|
|
8
8
|
constructor(client: ComposioClient);
|
|
9
9
|
/**
|
|
10
|
-
* Upload a file
|
|
11
|
-
*
|
|
12
|
-
* @param
|
|
13
|
-
* @param
|
|
14
|
-
* @
|
|
15
|
-
|
|
10
|
+
* Upload a file and return the file data.
|
|
11
|
+
*
|
|
12
|
+
* @param params - The upload parameters.
|
|
13
|
+
* @param {File | string} params.file - The path to the file to upload, a URL of the file, or a File object.
|
|
14
|
+
* @param {string} params.toolSlug - The slug of the tool that is uploading the file.
|
|
15
|
+
* @param {string} params.toolkitSlug - The slug of the toolkit that is uploading the file.
|
|
16
|
+
* @returns {Promise<FileUploadData>} The uploaded file data.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
*
|
|
20
|
+
* const fileData = await composio.files.upload({
|
|
21
|
+
* file: 'path/to/file.pdf',
|
|
22
|
+
* toolSlug: 'google_drive_upload',
|
|
23
|
+
* toolkitSlug: 'google_drive'
|
|
24
|
+
* });
|
|
25
|
+
* */
|
|
16
26
|
upload({
|
|
17
27
|
file,
|
|
18
28
|
toolSlug,
|
|
@@ -8,12 +8,22 @@ var Files = class {
|
|
|
8
8
|
telemetry.instrument(this, "Files");
|
|
9
9
|
}
|
|
10
10
|
/**
|
|
11
|
-
* Upload a file
|
|
12
|
-
*
|
|
13
|
-
* @param
|
|
14
|
-
* @param
|
|
15
|
-
* @
|
|
16
|
-
|
|
11
|
+
* Upload a file and return the file data.
|
|
12
|
+
*
|
|
13
|
+
* @param params - The upload parameters.
|
|
14
|
+
* @param {File | string} params.file - The path to the file to upload, a URL of the file, or a File object.
|
|
15
|
+
* @param {string} params.toolSlug - The slug of the tool that is uploading the file.
|
|
16
|
+
* @param {string} params.toolkitSlug - The slug of the toolkit that is uploading the file.
|
|
17
|
+
* @returns {Promise<FileUploadData>} The uploaded file data.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
*
|
|
21
|
+
* const fileData = await composio.files.upload({
|
|
22
|
+
* file: 'path/to/file.pdf',
|
|
23
|
+
* toolSlug: 'google_drive_upload',
|
|
24
|
+
* toolkitSlug: 'google_drive'
|
|
25
|
+
* });
|
|
26
|
+
* */
|
|
17
27
|
async upload({ file, toolSlug, toolkitSlug }) {
|
|
18
28
|
return await getFileDataAfterUploadingToS3(file, {
|
|
19
29
|
toolSlug,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@composio/core",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.5.
|
|
4
|
+
"version": "0.5.4",
|
|
5
5
|
"description": "",
|
|
6
6
|
"main": "dist/index.mjs",
|
|
7
7
|
"publishConfig": {
|
|
@@ -118,7 +118,7 @@
|
|
|
118
118
|
"gitHead": "4fae6e54d5c150fba955cc5fa314281da5a1e064",
|
|
119
119
|
"scripts": {
|
|
120
120
|
"clean": "git clean -xdf node_modules",
|
|
121
|
-
"build": "tsdown",
|
|
121
|
+
"build": "bun run --bun tsdown",
|
|
122
122
|
"test": "vitest run",
|
|
123
123
|
"typecheck": "tsc --noEmit --skipLibCheck && tsc --noEmit --skipLibCheck -p tsconfig.type-tests.json",
|
|
124
124
|
"generate:docs": "tsx scripts/generate-docs.ts"
|