@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
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import "../chunk-
|
|
2
|
-
import
|
|
1
|
+
import "../chunk-Dx2NuYGI.mjs";
|
|
2
|
+
import "../buffer-BFpVRahf.mjs";
|
|
3
|
+
import { t as telemetry } from "../Telemetry-Bn5VseVi.mjs";
|
|
4
|
+
import { n as getFileDataAfterUploadingToS3, t as downloadFileFromS3 } from "../fileUtils.node-MOEGtpnI.mjs";
|
|
3
5
|
|
|
4
6
|
//#region src/models/Files.node.ts
|
|
5
7
|
var Files = class {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
|
|
2
2
|
//#region src/models/Files.workerd.ts
|
|
3
|
-
const UNSUPPORTED_MESSAGE = "File operations (upload/download) are not supported in Cloudflare Workers or Edge runtimes. These operations require Node.js-specific APIs (
|
|
3
|
+
const UNSUPPORTED_MESSAGE = "File operations (upload/download) are not supported in Cloudflare Workers or Edge runtimes. These operations require Node.js-specific APIs (e.g., `node:crypto`, `node:fs`) that are not available in this environment. Please use a Node.js runtime for file operations.";
|
|
4
4
|
/**
|
|
5
5
|
* Creates a Proxy that throws a user-friendly error when any method is accessed.
|
|
6
6
|
* This ensures that users get a clear error message when attempting to use
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
//#region src/models/Files.workerd.ts
|
|
2
|
-
const UNSUPPORTED_MESSAGE = "File operations (upload/download) are not supported in Cloudflare Workers or Edge runtimes. These operations require Node.js-specific APIs (
|
|
2
|
+
const UNSUPPORTED_MESSAGE = "File operations (upload/download) are not supported in Cloudflare Workers or Edge runtimes. These operations require Node.js-specific APIs (e.g., `node:crypto`, `node:fs`) that are not available in this environment. Please use a Node.js runtime for file operations.";
|
|
3
3
|
/**
|
|
4
4
|
* Creates a Proxy that throws a user-friendly error when any method is accessed.
|
|
5
5
|
* This ensures that users get a clear error message when attempting to use
|
package/dist/platform/node.cjs
CHANGED
|
@@ -33,11 +33,14 @@ const platform = {
|
|
|
33
33
|
node_fs.mkdirSync(dirPath, { recursive: true });
|
|
34
34
|
},
|
|
35
35
|
readFileSync(filePath, encoding) {
|
|
36
|
-
if (encoding
|
|
37
|
-
|
|
36
|
+
if (encoding === void 0) {
|
|
37
|
+
const buf = node_fs.readFileSync(filePath, { encoding: null });
|
|
38
|
+
return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
39
|
+
}
|
|
40
|
+
return node_fs.readFileSync(filePath, { encoding });
|
|
38
41
|
},
|
|
39
42
|
writeFileSync(filePath, content, encoding) {
|
|
40
|
-
if (encoding && typeof content === "string") node_fs.writeFileSync(filePath, content, encoding);
|
|
43
|
+
if (encoding && typeof content === "string") node_fs.writeFileSync(filePath, content, { encoding });
|
|
41
44
|
else node_fs.writeFileSync(filePath, content);
|
|
42
45
|
}
|
|
43
46
|
};
|
package/dist/platform/node.d.cts
CHANGED
package/dist/platform/node.d.mts
CHANGED
package/dist/platform/node.mjs
CHANGED
|
@@ -29,11 +29,14 @@ const platform = {
|
|
|
29
29
|
fs.mkdirSync(dirPath, { recursive: true });
|
|
30
30
|
},
|
|
31
31
|
readFileSync(filePath, encoding) {
|
|
32
|
-
if (encoding
|
|
33
|
-
|
|
32
|
+
if (encoding === void 0) {
|
|
33
|
+
const buf = fs.readFileSync(filePath, { encoding: null });
|
|
34
|
+
return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
35
|
+
}
|
|
36
|
+
return fs.readFileSync(filePath, { encoding });
|
|
34
37
|
},
|
|
35
38
|
writeFileSync(filePath, content, encoding) {
|
|
36
|
-
if (encoding && typeof content === "string") fs.writeFileSync(filePath, content, encoding);
|
|
39
|
+
if (encoding && typeof content === "string") fs.writeFileSync(filePath, content, { encoding });
|
|
37
40
|
else fs.writeFileSync(filePath, content);
|
|
38
41
|
}
|
|
39
42
|
};
|
|
@@ -35,22 +35,25 @@ interface Platform {
|
|
|
35
35
|
/**
|
|
36
36
|
* Reads a file synchronously and returns its contents.
|
|
37
37
|
* @param filePath - The path to the file.
|
|
38
|
-
* @param encoding - Optional encoding (e.g., 'utf8'). If not provided, returns
|
|
39
|
-
* @returns The file contents as a string (if encoding provided) or
|
|
38
|
+
* @param encoding - Optional encoding (e.g., 'utf8'). If not provided, returns an Uint8Array.
|
|
39
|
+
* @returns The file contents as a string (if encoding provided) or Uint8Array.
|
|
40
40
|
*/
|
|
41
|
-
readFileSync(filePath: string, encoding?:
|
|
41
|
+
readFileSync(filePath: string, encoding?: never): Uint8Array;
|
|
42
|
+
readFileSync(filePath: string, encoding: Uint8ArrayEncoding): string;
|
|
42
43
|
/**
|
|
43
44
|
* Writes content to a file synchronously.
|
|
44
45
|
* @param filePath - The path to the file.
|
|
45
|
-
* @param content - The content to write (string or
|
|
46
|
+
* @param content - The content to write (string or Uint8Array).
|
|
46
47
|
* @param encoding - Optional encoding for string content.
|
|
47
48
|
*/
|
|
48
|
-
writeFileSync(filePath: string, content:
|
|
49
|
+
writeFileSync(filePath: string, content: Uint8Array, encoding?: never): void;
|
|
50
|
+
writeFileSync(filePath: string, content: string, encoding: Uint8ArrayEncoding): void;
|
|
49
51
|
/**
|
|
50
52
|
* Indicates whether this platform supports file system operations.
|
|
51
53
|
* Edge runtimes like Cloudflare Workers return false.
|
|
52
54
|
*/
|
|
53
55
|
readonly supportsFileSystem: boolean;
|
|
54
56
|
}
|
|
57
|
+
type Uint8ArrayEncoding = 'utf8';
|
|
55
58
|
//#endregion
|
|
56
59
|
export { Platform as t };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { n as BaseComposioProvider } from "./BaseProvider-dBg5sg9H.cjs";
|
|
2
|
+
import { n as ComposioConfig } from "./composio-h_UeXpQT.cjs";
|
|
3
|
+
|
|
4
|
+
//#region src/utils/config-defaults/types.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Configuration defaults for Composio.
|
|
8
|
+
* These are the required fields that must have default values.
|
|
9
|
+
* The provider type is set to never since defaults don't include a provider instance.
|
|
10
|
+
*/
|
|
11
|
+
type ConfigDefaults = Required<Pick<ComposioConfig<BaseComposioProvider<never, never, never>>, 'autoUploadDownloadFiles' | 'allowTracking' | 'toolkitVersions'>>;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { ConfigDefaults as t };
|
|
@@ -35,22 +35,25 @@ interface Platform {
|
|
|
35
35
|
/**
|
|
36
36
|
* Reads a file synchronously and returns its contents.
|
|
37
37
|
* @param filePath - The path to the file.
|
|
38
|
-
* @param encoding - Optional encoding (e.g., 'utf8'). If not provided, returns
|
|
39
|
-
* @returns The file contents as a string (if encoding provided) or
|
|
38
|
+
* @param encoding - Optional encoding (e.g., 'utf8'). If not provided, returns an Uint8Array.
|
|
39
|
+
* @returns The file contents as a string (if encoding provided) or Uint8Array.
|
|
40
40
|
*/
|
|
41
|
-
readFileSync(filePath: string, encoding?:
|
|
41
|
+
readFileSync(filePath: string, encoding?: never): Uint8Array;
|
|
42
|
+
readFileSync(filePath: string, encoding: Uint8ArrayEncoding): string;
|
|
42
43
|
/**
|
|
43
44
|
* Writes content to a file synchronously.
|
|
44
45
|
* @param filePath - The path to the file.
|
|
45
|
-
* @param content - The content to write (string or
|
|
46
|
+
* @param content - The content to write (string or Uint8Array).
|
|
46
47
|
* @param encoding - Optional encoding for string content.
|
|
47
48
|
*/
|
|
48
|
-
writeFileSync(filePath: string, content:
|
|
49
|
+
writeFileSync(filePath: string, content: Uint8Array, encoding?: never): void;
|
|
50
|
+
writeFileSync(filePath: string, content: string, encoding: Uint8ArrayEncoding): void;
|
|
49
51
|
/**
|
|
50
52
|
* Indicates whether this platform supports file system operations.
|
|
51
53
|
* Edge runtimes like Cloudflare Workers return false.
|
|
52
54
|
*/
|
|
53
55
|
readonly supportsFileSystem: boolean;
|
|
54
56
|
}
|
|
57
|
+
type Uint8ArrayEncoding = 'utf8';
|
|
55
58
|
//#endregion
|
|
56
59
|
export { Platform as t };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { n as BaseComposioProvider } from "./BaseProvider-QPPZprGx.mjs";
|
|
2
|
+
import { n as ComposioConfig } from "./composio-ivOweCw4.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/utils/config-defaults/types.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Configuration defaults for Composio.
|
|
8
|
+
* These are the required fields that must have default values.
|
|
9
|
+
* The provider type is set to never since defaults don't include a provider instance.
|
|
10
|
+
*/
|
|
11
|
+
type ConfigDefaults = Required<Pick<ComposioConfig<BaseComposioProvider<never, never, never>>, 'autoUploadDownloadFiles' | 'allowTracking' | 'toolkitVersions'>>;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { ConfigDefaults as t };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import "../../BaseProvider-QPPZprGx.mjs";
|
|
2
|
+
import "../../composio-ivOweCw4.mjs";
|
|
3
|
+
import { t as ConfigDefaults } from "../../types-anOdQ7KW.mjs";
|
|
4
|
+
|
|
5
|
+
//#region src/utils/config-defaults/ConfigDefaults.node.d.ts
|
|
6
|
+
declare const CONFIG_DEFAULTS: ConfigDefaults;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { CONFIG_DEFAULTS };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import "../../BaseProvider-QPPZprGx.mjs";
|
|
2
|
+
import "../../composio-ivOweCw4.mjs";
|
|
3
|
+
import { t as ConfigDefaults } from "../../types-anOdQ7KW.mjs";
|
|
4
|
+
|
|
5
|
+
//#region src/utils/config-defaults/ConfigDefaults.workerd.d.ts
|
|
6
|
+
declare const CONFIG_DEFAULTS: ConfigDefaults;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { CONFIG_DEFAULTS };
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
const require_buffer = require('../../buffer-CYf1Z6Sd.cjs');
|
|
2
|
+
const require_fileUtils_node = require('../../fileUtils.node-DLp53qm1.cjs');
|
|
3
|
+
const require_FileToolModifier_utils_neutral = require('../../FileToolModifier.utils.neutral-Bcl7LVf4.cjs');
|
|
4
|
+
|
|
5
|
+
//#region src/errors/FileModifierErrors.ts
|
|
6
|
+
const FileModifierErrorCodes = { FILE_UPLOAD_FAILED: "FILE_UPLOAD_FAILED" };
|
|
7
|
+
var ComposioFileUploadError = class extends require_buffer.ComposioError {
|
|
8
|
+
constructor(message = "Failed to upload file", options = {}) {
|
|
9
|
+
super(message, {
|
|
10
|
+
...options,
|
|
11
|
+
code: FileModifierErrorCodes.FILE_UPLOAD_FAILED,
|
|
12
|
+
possibleFixes: options.possibleFixes || ["Check if the file exists in the location provided"]
|
|
13
|
+
});
|
|
14
|
+
this.name = "ComposioFileUploadError";
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
//#endregion
|
|
19
|
+
//#region src/utils/modifiers/FileToolModifier.node.ts
|
|
20
|
+
/**
|
|
21
|
+
* Recursively walks a runtime value and its matching JSON-Schema node,
|
|
22
|
+
* uploading any string path whose schema node has `file_uploadable: true`.
|
|
23
|
+
* The function returns a **new** value with all substitutions applied;
|
|
24
|
+
* nothing is mutated in-place.
|
|
25
|
+
*/
|
|
26
|
+
const hydrateFiles = async (value, schema, ctx) => {
|
|
27
|
+
if (schema?.file_uploadable) {
|
|
28
|
+
if (typeof value !== "string" && !(value instanceof File)) return value;
|
|
29
|
+
require_buffer.logger_default.debug(`Uploading file "${value}"`);
|
|
30
|
+
return require_fileUtils_node.getFileDataAfterUploadingToS3(value, {
|
|
31
|
+
toolSlug: ctx.toolSlug,
|
|
32
|
+
toolkitSlug: ctx.toolkitSlug,
|
|
33
|
+
client: ctx.client
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
const schemaVariants = [
|
|
37
|
+
...schema?.anyOf ?? [],
|
|
38
|
+
...schema?.oneOf ?? [],
|
|
39
|
+
...schema?.allOf ?? []
|
|
40
|
+
];
|
|
41
|
+
if (schemaVariants.length > 0) {
|
|
42
|
+
const uploadableVariants = schemaVariants.filter(require_FileToolModifier_utils_neutral.schemaHasFileUploadable);
|
|
43
|
+
if (uploadableVariants.length > 0) {
|
|
44
|
+
let result = value;
|
|
45
|
+
for (const variant of uploadableVariants) result = await hydrateFiles(result, variant, ctx);
|
|
46
|
+
return result;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (schema?.type === "object" && schema.properties && require_FileToolModifier_utils_neutral.isPlainObject(value)) {
|
|
50
|
+
const transformed = {};
|
|
51
|
+
for (const [k, v] of Object.entries(value)) transformed[k] = await hydrateFiles(v, schema.properties[k], ctx);
|
|
52
|
+
return transformed;
|
|
53
|
+
}
|
|
54
|
+
if (schema?.type === "array" && schema.items && Array.isArray(value)) {
|
|
55
|
+
const itemSchema = Array.isArray(schema.items) ? schema.items[0] : schema.items;
|
|
56
|
+
return Promise.all(value.map((item) => hydrateFiles(item, itemSchema, ctx)));
|
|
57
|
+
}
|
|
58
|
+
return value;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Downloads a file from S3 and returns a replacement object.
|
|
62
|
+
*/
|
|
63
|
+
const downloadS3File = async (value, ctx) => {
|
|
64
|
+
const { s3url, mimetype } = value;
|
|
65
|
+
try {
|
|
66
|
+
require_buffer.logger_default.debug(`Downloading from S3: ${s3url}`);
|
|
67
|
+
const dl = await require_fileUtils_node.downloadFileFromS3({
|
|
68
|
+
toolSlug: ctx.toolSlug,
|
|
69
|
+
s3Url: s3url,
|
|
70
|
+
mimeType: mimetype ?? "application/octet-stream"
|
|
71
|
+
});
|
|
72
|
+
require_buffer.logger_default.debug(`Downloaded → ${dl.filePath}`);
|
|
73
|
+
return {
|
|
74
|
+
uri: dl.filePath,
|
|
75
|
+
file_downloaded: dl.filePath ? true : false,
|
|
76
|
+
s3url,
|
|
77
|
+
mimeType: dl.mimeType
|
|
78
|
+
};
|
|
79
|
+
} catch (err) {
|
|
80
|
+
require_buffer.logger_default.error(`Download failed: ${s3url}`, { cause: err });
|
|
81
|
+
return {
|
|
82
|
+
uri: "",
|
|
83
|
+
file_downloaded: false,
|
|
84
|
+
s3url,
|
|
85
|
+
mimeType: mimetype ?? "application/octet-stream"
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* Recursively walks an arbitrary value and its matching JSON-Schema node.
|
|
91
|
+
* Whenever it encounters an object that represents a file reference
|
|
92
|
+
* (i.e. has an `s3url`), it downloads the file and returns a replacement:
|
|
93
|
+
* {
|
|
94
|
+
* uri: "<local-path>",
|
|
95
|
+
* file_downloaded: true | false,
|
|
96
|
+
* s3url: "<original S3 URL>",
|
|
97
|
+
* mimeType: "<detected-or-fallback-mime-type>"
|
|
98
|
+
* }
|
|
99
|
+
*
|
|
100
|
+
* The function is side-effect-free: it never mutates the input value.
|
|
101
|
+
*/
|
|
102
|
+
const hydrateDownloads = async (value, schema, ctx) => {
|
|
103
|
+
if (require_FileToolModifier_utils_neutral.isPlainObject(value) && typeof value.s3url === "string") return downloadS3File(value, ctx);
|
|
104
|
+
if (schema?.file_downloadable && require_FileToolModifier_utils_neutral.isPlainObject(value) && typeof value.s3url === "string") return downloadS3File(value, ctx);
|
|
105
|
+
const schemaVariants = [
|
|
106
|
+
...schema?.anyOf ?? [],
|
|
107
|
+
...schema?.oneOf ?? [],
|
|
108
|
+
...schema?.allOf ?? []
|
|
109
|
+
];
|
|
110
|
+
if (schemaVariants.length > 0) {
|
|
111
|
+
const downloadableVariants = schemaVariants.filter(require_FileToolModifier_utils_neutral.schemaHasFileDownloadable);
|
|
112
|
+
let result = value;
|
|
113
|
+
for (const variant of downloadableVariants) result = await hydrateDownloads(result, variant, ctx);
|
|
114
|
+
if (downloadableVariants.length === 0) return hydrateDownloads(value, void 0, ctx);
|
|
115
|
+
return result;
|
|
116
|
+
}
|
|
117
|
+
if (require_FileToolModifier_utils_neutral.isPlainObject(value)) {
|
|
118
|
+
const pairs = await Promise.all(Object.entries(value).map(async ([k, v]) => [k, await hydrateDownloads(v, schema?.properties?.[k], ctx)]));
|
|
119
|
+
return Object.fromEntries(pairs);
|
|
120
|
+
}
|
|
121
|
+
if (Array.isArray(value)) {
|
|
122
|
+
const itemSchema = schema?.items ? Array.isArray(schema.items) ? schema.items[0] : schema.items : void 0;
|
|
123
|
+
return Promise.all(value.map((item) => hydrateDownloads(item, itemSchema, ctx)));
|
|
124
|
+
}
|
|
125
|
+
return value;
|
|
126
|
+
};
|
|
127
|
+
var FileToolModifier = class {
|
|
128
|
+
client;
|
|
129
|
+
constructor(client) {
|
|
130
|
+
this.client = client;
|
|
131
|
+
}
|
|
132
|
+
async modifyToolSchema(toolSlug, toolkitSlug, schema) {
|
|
133
|
+
if (!schema.inputParameters?.properties) return schema;
|
|
134
|
+
const properties = require_FileToolModifier_utils_neutral.transformProperties(schema.inputParameters.properties);
|
|
135
|
+
return {
|
|
136
|
+
...schema,
|
|
137
|
+
inputParameters: {
|
|
138
|
+
...schema.inputParameters,
|
|
139
|
+
properties
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
async fileUploadModifier(tool, options) {
|
|
144
|
+
const { params, toolSlug, toolkitSlug = "unknown" } = options;
|
|
145
|
+
const { arguments: args } = params;
|
|
146
|
+
if (!args || typeof args !== "object") return params;
|
|
147
|
+
try {
|
|
148
|
+
const newArgs = await hydrateFiles(args, tool.inputParameters, {
|
|
149
|
+
toolSlug,
|
|
150
|
+
toolkitSlug,
|
|
151
|
+
client: this.client
|
|
152
|
+
});
|
|
153
|
+
return {
|
|
154
|
+
...params,
|
|
155
|
+
arguments: newArgs
|
|
156
|
+
};
|
|
157
|
+
} catch (error) {
|
|
158
|
+
throw new ComposioFileUploadError("Failed to upload file", { cause: error });
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
async fileDownloadModifier(tool, options) {
|
|
162
|
+
const { result, toolSlug } = options;
|
|
163
|
+
const dataWithDownloads = await hydrateDownloads(result.data, tool.outputParameters, { toolSlug });
|
|
164
|
+
return {
|
|
165
|
+
...result,
|
|
166
|
+
data: dataWithDownloads
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
//#endregion
|
|
172
|
+
exports.FileToolModifier = FileToolModifier;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { _n as ToolExecuteResponse, fn as Tool, hn as ToolExecuteParams } from "../../BaseProvider-dBg5sg9H.cjs";
|
|
2
|
+
import ComposioClient from "@composio/client";
|
|
3
|
+
|
|
4
|
+
//#region src/utils/modifiers/FileToolModifier.node.d.ts
|
|
5
|
+
declare class FileToolModifier {
|
|
6
|
+
private client;
|
|
7
|
+
constructor(client: ComposioClient);
|
|
8
|
+
modifyToolSchema(toolSlug: string, toolkitSlug: string, schema: Tool): Promise<Tool>;
|
|
9
|
+
fileUploadModifier(tool: Tool, options: {
|
|
10
|
+
toolSlug: string;
|
|
11
|
+
toolkitSlug?: string;
|
|
12
|
+
params: ToolExecuteParams;
|
|
13
|
+
}): Promise<ToolExecuteParams>;
|
|
14
|
+
fileDownloadModifier(tool: Tool, options: {
|
|
15
|
+
toolSlug: string;
|
|
16
|
+
toolkitSlug: string;
|
|
17
|
+
result: ToolExecuteResponse;
|
|
18
|
+
}): Promise<ToolExecuteResponse>;
|
|
19
|
+
}
|
|
20
|
+
//#endregion
|
|
21
|
+
export { FileToolModifier };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { _n as ToolExecuteResponse, fn as Tool, hn as ToolExecuteParams } from "../../BaseProvider-QPPZprGx.mjs";
|
|
2
|
+
import ComposioClient from "@composio/client";
|
|
3
|
+
|
|
4
|
+
//#region src/utils/modifiers/FileToolModifier.node.d.ts
|
|
5
|
+
declare class FileToolModifier {
|
|
6
|
+
private client;
|
|
7
|
+
constructor(client: ComposioClient);
|
|
8
|
+
modifyToolSchema(toolSlug: string, toolkitSlug: string, schema: Tool): Promise<Tool>;
|
|
9
|
+
fileUploadModifier(tool: Tool, options: {
|
|
10
|
+
toolSlug: string;
|
|
11
|
+
toolkitSlug?: string;
|
|
12
|
+
params: ToolExecuteParams;
|
|
13
|
+
}): Promise<ToolExecuteParams>;
|
|
14
|
+
fileDownloadModifier(tool: Tool, options: {
|
|
15
|
+
toolSlug: string;
|
|
16
|
+
toolkitSlug: string;
|
|
17
|
+
result: ToolExecuteResponse;
|
|
18
|
+
}): Promise<ToolExecuteResponse>;
|
|
19
|
+
}
|
|
20
|
+
//#endregion
|
|
21
|
+
export { FileToolModifier };
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import "../../chunk-Dx2NuYGI.mjs";
|
|
2
|
+
import { o as ComposioError, s as logger_default } from "../../buffer-BFpVRahf.mjs";
|
|
3
|
+
import { n as getFileDataAfterUploadingToS3, t as downloadFileFromS3 } from "../../fileUtils.node-MOEGtpnI.mjs";
|
|
4
|
+
import { i as transformProperties, n as schemaHasFileDownloadable, r as schemaHasFileUploadable, t as isPlainObject } from "../../FileToolModifier.utils.neutral-BN_L8usp.mjs";
|
|
5
|
+
|
|
6
|
+
//#region src/errors/FileModifierErrors.ts
|
|
7
|
+
const FileModifierErrorCodes = { FILE_UPLOAD_FAILED: "FILE_UPLOAD_FAILED" };
|
|
8
|
+
var ComposioFileUploadError = class extends ComposioError {
|
|
9
|
+
constructor(message = "Failed to upload file", options = {}) {
|
|
10
|
+
super(message, {
|
|
11
|
+
...options,
|
|
12
|
+
code: FileModifierErrorCodes.FILE_UPLOAD_FAILED,
|
|
13
|
+
possibleFixes: options.possibleFixes || ["Check if the file exists in the location provided"]
|
|
14
|
+
});
|
|
15
|
+
this.name = "ComposioFileUploadError";
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
//#endregion
|
|
20
|
+
//#region src/utils/modifiers/FileToolModifier.node.ts
|
|
21
|
+
/**
|
|
22
|
+
* Recursively walks a runtime value and its matching JSON-Schema node,
|
|
23
|
+
* uploading any string path whose schema node has `file_uploadable: true`.
|
|
24
|
+
* The function returns a **new** value with all substitutions applied;
|
|
25
|
+
* nothing is mutated in-place.
|
|
26
|
+
*/
|
|
27
|
+
const hydrateFiles = async (value, schema, ctx) => {
|
|
28
|
+
if (schema?.file_uploadable) {
|
|
29
|
+
if (typeof value !== "string" && !(value instanceof File)) return value;
|
|
30
|
+
logger_default.debug(`Uploading file "${value}"`);
|
|
31
|
+
return getFileDataAfterUploadingToS3(value, {
|
|
32
|
+
toolSlug: ctx.toolSlug,
|
|
33
|
+
toolkitSlug: ctx.toolkitSlug,
|
|
34
|
+
client: ctx.client
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
const schemaVariants = [
|
|
38
|
+
...schema?.anyOf ?? [],
|
|
39
|
+
...schema?.oneOf ?? [],
|
|
40
|
+
...schema?.allOf ?? []
|
|
41
|
+
];
|
|
42
|
+
if (schemaVariants.length > 0) {
|
|
43
|
+
const uploadableVariants = schemaVariants.filter(schemaHasFileUploadable);
|
|
44
|
+
if (uploadableVariants.length > 0) {
|
|
45
|
+
let result = value;
|
|
46
|
+
for (const variant of uploadableVariants) result = await hydrateFiles(result, variant, ctx);
|
|
47
|
+
return result;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (schema?.type === "object" && schema.properties && isPlainObject(value)) {
|
|
51
|
+
const transformed = {};
|
|
52
|
+
for (const [k, v] of Object.entries(value)) transformed[k] = await hydrateFiles(v, schema.properties[k], ctx);
|
|
53
|
+
return transformed;
|
|
54
|
+
}
|
|
55
|
+
if (schema?.type === "array" && schema.items && Array.isArray(value)) {
|
|
56
|
+
const itemSchema = Array.isArray(schema.items) ? schema.items[0] : schema.items;
|
|
57
|
+
return Promise.all(value.map((item) => hydrateFiles(item, itemSchema, ctx)));
|
|
58
|
+
}
|
|
59
|
+
return value;
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Downloads a file from S3 and returns a replacement object.
|
|
63
|
+
*/
|
|
64
|
+
const downloadS3File = async (value, ctx) => {
|
|
65
|
+
const { s3url, mimetype } = value;
|
|
66
|
+
try {
|
|
67
|
+
logger_default.debug(`Downloading from S3: ${s3url}`);
|
|
68
|
+
const dl = await downloadFileFromS3({
|
|
69
|
+
toolSlug: ctx.toolSlug,
|
|
70
|
+
s3Url: s3url,
|
|
71
|
+
mimeType: mimetype ?? "application/octet-stream"
|
|
72
|
+
});
|
|
73
|
+
logger_default.debug(`Downloaded → ${dl.filePath}`);
|
|
74
|
+
return {
|
|
75
|
+
uri: dl.filePath,
|
|
76
|
+
file_downloaded: dl.filePath ? true : false,
|
|
77
|
+
s3url,
|
|
78
|
+
mimeType: dl.mimeType
|
|
79
|
+
};
|
|
80
|
+
} catch (err) {
|
|
81
|
+
logger_default.error(`Download failed: ${s3url}`, { cause: err });
|
|
82
|
+
return {
|
|
83
|
+
uri: "",
|
|
84
|
+
file_downloaded: false,
|
|
85
|
+
s3url,
|
|
86
|
+
mimeType: mimetype ?? "application/octet-stream"
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* Recursively walks an arbitrary value and its matching JSON-Schema node.
|
|
92
|
+
* Whenever it encounters an object that represents a file reference
|
|
93
|
+
* (i.e. has an `s3url`), it downloads the file and returns a replacement:
|
|
94
|
+
* {
|
|
95
|
+
* uri: "<local-path>",
|
|
96
|
+
* file_downloaded: true | false,
|
|
97
|
+
* s3url: "<original S3 URL>",
|
|
98
|
+
* mimeType: "<detected-or-fallback-mime-type>"
|
|
99
|
+
* }
|
|
100
|
+
*
|
|
101
|
+
* The function is side-effect-free: it never mutates the input value.
|
|
102
|
+
*/
|
|
103
|
+
const hydrateDownloads = async (value, schema, ctx) => {
|
|
104
|
+
if (isPlainObject(value) && typeof value.s3url === "string") return downloadS3File(value, ctx);
|
|
105
|
+
if (schema?.file_downloadable && isPlainObject(value) && typeof value.s3url === "string") return downloadS3File(value, ctx);
|
|
106
|
+
const schemaVariants = [
|
|
107
|
+
...schema?.anyOf ?? [],
|
|
108
|
+
...schema?.oneOf ?? [],
|
|
109
|
+
...schema?.allOf ?? []
|
|
110
|
+
];
|
|
111
|
+
if (schemaVariants.length > 0) {
|
|
112
|
+
const downloadableVariants = schemaVariants.filter(schemaHasFileDownloadable);
|
|
113
|
+
let result = value;
|
|
114
|
+
for (const variant of downloadableVariants) result = await hydrateDownloads(result, variant, ctx);
|
|
115
|
+
if (downloadableVariants.length === 0) return hydrateDownloads(value, void 0, ctx);
|
|
116
|
+
return result;
|
|
117
|
+
}
|
|
118
|
+
if (isPlainObject(value)) {
|
|
119
|
+
const pairs = await Promise.all(Object.entries(value).map(async ([k, v]) => [k, await hydrateDownloads(v, schema?.properties?.[k], ctx)]));
|
|
120
|
+
return Object.fromEntries(pairs);
|
|
121
|
+
}
|
|
122
|
+
if (Array.isArray(value)) {
|
|
123
|
+
const itemSchema = schema?.items ? Array.isArray(schema.items) ? schema.items[0] : schema.items : void 0;
|
|
124
|
+
return Promise.all(value.map((item) => hydrateDownloads(item, itemSchema, ctx)));
|
|
125
|
+
}
|
|
126
|
+
return value;
|
|
127
|
+
};
|
|
128
|
+
var FileToolModifier = class {
|
|
129
|
+
client;
|
|
130
|
+
constructor(client) {
|
|
131
|
+
this.client = client;
|
|
132
|
+
}
|
|
133
|
+
async modifyToolSchema(toolSlug, toolkitSlug, schema) {
|
|
134
|
+
if (!schema.inputParameters?.properties) return schema;
|
|
135
|
+
const properties = transformProperties(schema.inputParameters.properties);
|
|
136
|
+
return {
|
|
137
|
+
...schema,
|
|
138
|
+
inputParameters: {
|
|
139
|
+
...schema.inputParameters,
|
|
140
|
+
properties
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
async fileUploadModifier(tool, options) {
|
|
145
|
+
const { params, toolSlug, toolkitSlug = "unknown" } = options;
|
|
146
|
+
const { arguments: args } = params;
|
|
147
|
+
if (!args || typeof args !== "object") return params;
|
|
148
|
+
try {
|
|
149
|
+
const newArgs = await hydrateFiles(args, tool.inputParameters, {
|
|
150
|
+
toolSlug,
|
|
151
|
+
toolkitSlug,
|
|
152
|
+
client: this.client
|
|
153
|
+
});
|
|
154
|
+
return {
|
|
155
|
+
...params,
|
|
156
|
+
arguments: newArgs
|
|
157
|
+
};
|
|
158
|
+
} catch (error) {
|
|
159
|
+
throw new ComposioFileUploadError("Failed to upload file", { cause: error });
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
async fileDownloadModifier(tool, options) {
|
|
163
|
+
const { result, toolSlug } = options;
|
|
164
|
+
const dataWithDownloads = await hydrateDownloads(result.data, tool.outputParameters, { toolSlug });
|
|
165
|
+
return {
|
|
166
|
+
...result,
|
|
167
|
+
data: dataWithDownloads
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
//#endregion
|
|
173
|
+
export { FileToolModifier };
|