Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

next
ts 49 lines 1.56 KB
Raw
1 /**
2 * @fileoverview Files class stub for Cloudflare Workers / Edge runtimes.
3 * File upload and download operations are not supported in these environments.
4 *
5 * @author Composio Team
6 * @module Files
7 */
8 import ComposioClient from '@composio/client';
9
10 const UNSUPPORTED_MESSAGE =
11 'File operations (upload/download) are not supported in Cloudflare Workers or Edge runtimes. ' +
12 'These operations require Node.js-specific APIs (e.g., `node:crypto`, `node:fs`) that are not available ' +
13 'in this environment. Please use a Node.js runtime for file operations.';
14
15 /**
16 * Creates a Proxy that throws a user-friendly error when any method is accessed.
17 * This ensures that users get a clear error message when attempting to use
18 * file operations in unsupported environments.
19 */
20 const createUnsupportedFilesProxy = (): Files => {
21 const handler: ProxyHandler<object> = {
22 get(_target, prop) {
23 // Allow access to constructor name for debugging
24 if (prop === Symbol.toStringTag) {
25 return 'Files';
26 }
27 if (prop === 'constructor') {
28 return Files;
29 }
30 // For any method access, return a function that throws
31 return () => {
32 throw new Error(UNSUPPORTED_MESSAGE);
33 };
34 },
35 };
36
37 return new Proxy({}, handler) as Files;
38 };
39
40 /**
41 * Files class for Cloudflare Workers / Edge runtimes.
42 * All methods throw an error indicating that file operations are not supported.
43 */
44 export class Files {
45 constructor(_client: ComposioClient) {
46 // Return a Proxy instead of the actual instance
47 return createUnsupportedFilesProxy();
48 }
49 }