@composio/core 0.12.0 → 0.13.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-BBnsv9kS.d.mts → BaseProvider-Brb3o86-.d.mts} +80 -80
- package/dist/{CustomTool-DEB4BQPl.mjs → CustomTool-D9qwyMrv.mjs} +1 -1
- package/dist/{CustomTool-DH18rVQu.d.mts → CustomTool-DLf7JeKt.d.mts} +1 -1
- package/dist/CustomTool-NpHpqdnU.d.mts +74 -0
- package/dist/{composio-CHnEggnv.d.mts → composio-BHSQwOUz.d.mts} +503 -319
- package/dist/composio-DfPD7BAi.d.mts +5666 -0
- package/dist/{customTool.types-DpIdOJjL.d.mts → customTool.types-9yFqPjdw.d.mts} +448 -76
- package/dist/customTool.types-D-6YqFdW.d.mts +2826 -0
- package/dist/docs/error-consistency.md +97 -0
- package/dist/docs/reference/sdk-reference/typescript/auth-configs.mdx +306 -0
- package/dist/docs/reference/sdk-reference/typescript/composio.mdx +205 -0
- package/dist/docs/reference/sdk-reference/typescript/connected-accounts.mdx +488 -0
- package/dist/docs/reference/sdk-reference/typescript/experimental.mdx +94 -0
- package/dist/docs/reference/sdk-reference/typescript/index.mdx +67 -0
- package/dist/docs/reference/sdk-reference/typescript/mcp.mdx +304 -0
- package/dist/docs/reference/sdk-reference/typescript/meta.json +17 -0
- package/dist/docs/reference/sdk-reference/typescript/remote-file.mdx +107 -0
- package/dist/docs/reference/sdk-reference/typescript/session-files.mdx +163 -0
- package/dist/docs/reference/sdk-reference/typescript/session.mdx +252 -0
- package/dist/docs/reference/sdk-reference/typescript/sessions.mdx +155 -0
- package/dist/docs/reference/sdk-reference/typescript/toolkits.mdx +169 -0
- package/dist/docs/reference/sdk-reference/typescript/tools.mdx +453 -0
- package/dist/docs/reference/sdk-reference/typescript/triggers.mdx +434 -0
- package/dist/{errors-D5f4pfvI.mjs → errors-DSIlYfl5.mjs} +2 -2
- package/dist/experimental/index.d.mts +2 -2
- package/dist/experimental/index.mjs +1 -1
- package/dist/index.d.mts +36 -6
- package/dist/index.mjs +455 -123
- package/dist/{jsonSchema-daqF3S3d.mjs → jsonSchema-CFKdONpP.mjs} +1 -1
- package/dist/{types-CaI5Z4PA.d.mts → types-BJLCRj9q.d.mts} +2 -2
- package/dist/types-CCh8qvui.d.mts +12 -0
- package/dist/utils/config-defaults/ConfigDefaults.node.d.mts +1 -1
- package/dist/utils/config-defaults/ConfigDefaults.workerd.d.mts +1 -1
- package/dist/utils/modifiers/FileToolModifier.node.d.mts +1 -1
- package/dist/utils/modifiers/FileToolModifier.node.mjs +2 -2
- package/dist/utils/modifiers/FileToolModifier.workerd.d.mts +1 -1
- package/docs/error-consistency.md +97 -0
- package/package.json +4 -3
- package/src/composio.ts +509 -0
- package/src/errors/AuthConfigErrors.ts +23 -0
- package/src/errors/ComposioError.ts +408 -0
- package/src/errors/ConnectedAccountsErrors.ts +158 -0
- package/src/errors/ConnectionRequestErrors.ts +32 -0
- package/src/errors/FileModifierErrors.ts +100 -0
- package/src/errors/PusherErrors.ts +28 -0
- package/src/errors/RemoteFileErrors.ts +62 -0
- package/src/errors/SDKErrors.ts +92 -0
- package/src/errors/ToolErrors.ts +244 -0
- package/src/errors/ToolkitErrors.ts +39 -0
- package/src/errors/TriggerErrors.ts +120 -0
- package/src/errors/ValidationErrors.ts +99 -0
- package/src/errors/index.ts +41 -0
- package/src/experimental/index.ts +28 -0
- package/src/index.ts +64 -0
- package/src/lib/toolRouterConstants.ts +1 -0
- package/src/lib/toolRouterParams.ts +306 -0
- package/src/lib/toolRouterSessionDelete.ts +30 -0
- package/src/models/AuthConfigs.ts +398 -0
- package/src/models/AuthScheme.ts +206 -0
- package/src/models/ConnectedAccounts.ts +735 -0
- package/src/models/ConnectionRequest.ts +150 -0
- package/src/models/CustomTool.ts +676 -0
- package/src/models/Experimental.ts +202 -0
- package/src/models/Files.node.ts +93 -0
- package/src/models/Files.workerd.ts +49 -0
- package/src/models/MCP.ts +478 -0
- package/src/models/RemoteFile.ts +172 -0
- package/src/models/SessionContext.ts +147 -0
- package/src/models/Sessions.ts +21 -0
- package/src/models/ToolRouter.ts +406 -0
- package/src/models/ToolRouterSession.ts +839 -0
- package/src/models/ToolRouterSessionFileMount.ts +389 -0
- package/src/models/Toolkits.ts +412 -0
- package/src/models/Tools.ts +1260 -0
- package/src/models/Triggers.ts +1381 -0
- package/src/models/customToolExecution.ts +118 -0
- package/src/models/inlineCustomToolsPayload.ts +17 -0
- package/src/models/proxyParamsTransform.ts +26 -0
- package/src/provider/BaseProvider.ts +138 -0
- package/src/provider/ComposioProvider.ts +29 -0
- package/src/provider/OpenAIProvider.ts +547 -0
- package/src/services/internal/InternalService.ts +50 -0
- package/src/services/internal/InternalService.types.ts +14 -0
- package/src/services/pusher/Pusher.ts +230 -0
- package/src/services/telemetry/TelemetryService.ts +48 -0
- package/src/services/telemetry/TelemetryService.types.ts +67 -0
- package/src/telemetry/BatchProcessor.ts +77 -0
- package/src/telemetry/README.md +123 -0
- package/src/telemetry/Telemetry.ts +356 -0
- package/src/types/ToolRouterSessionFilesMount.types.ts +96 -0
- package/src/types/authConfigs.types.ts +174 -0
- package/src/types/composio.types.ts +1 -0
- package/src/types/connectedAccountAuthStates.types.ts +852 -0
- package/src/types/connectedAccounts.types.ts +395 -0
- package/src/types/connectionRequest.types.ts +16 -0
- package/src/types/customTool.types.ts +261 -0
- package/src/types/files.types.ts +15 -0
- package/src/types/mcp.experimental.types.ts +163 -0
- package/src/types/mcp.types.ts +362 -0
- package/src/types/modifiers.types.ts +663 -0
- package/src/types/org.types.ts +0 -0
- package/src/types/provider.types.ts +41 -0
- package/src/types/pusher.types.ts +18 -0
- package/src/types/requestOptions.types.ts +62 -0
- package/src/types/telemetry.types.ts +89 -0
- package/src/types/tool.types.ts +408 -0
- package/src/types/toolRouter.types.ts +774 -0
- package/src/types/toolkit.types.ts +130 -0
- package/src/types/triggers.types.ts +401 -0
- package/src/types/webhookEvents.types.ts +219 -0
- package/src/utils/buffer.ts +30 -0
- package/src/utils/cancellation.ts +22 -0
- package/src/utils/config-defaults/ConfigDefaults.node.ts +7 -0
- package/src/utils/config-defaults/ConfigDefaults.workerd.ts +10 -0
- package/src/utils/config-defaults/index.ts +1 -0
- package/src/utils/config-defaults/types.ts +14 -0
- package/src/utils/constants.ts +22 -0
- package/src/utils/crypto.ts +34 -0
- package/src/utils/env.ts +34 -0
- package/src/utils/fileDirs.ts +81 -0
- package/src/utils/fileUtils.node.ts +458 -0
- package/src/utils/json-schema.ts +1 -0
- package/src/utils/jsonSchema.ts +355 -0
- package/src/utils/logger.ts +99 -0
- package/src/utils/mime.ts +75 -0
- package/src/utils/modifiers/FileToolModifier.node.ts +477 -0
- package/src/utils/modifiers/FileToolModifier.utils.neutral.ts +132 -0
- package/src/utils/modifiers/FileToolModifier.workerd.ts +51 -0
- package/src/utils/pagination.ts +73 -0
- package/src/utils/pusher.ts +286 -0
- package/src/utils/schemaPropertyKeys.ts +433 -0
- package/src/utils/sdk.ts +110 -0
- package/src/utils/sensitiveFileUploadPaths.node.ts +105 -0
- package/src/utils/session.ts +114 -0
- package/src/utils/toolArguments.ts +73 -0
- package/src/utils/toolkitVersion.ts +26 -0
- package/src/utils/transform.ts +42 -0
- package/src/utils/transformers/authConfigs.ts +107 -0
- package/src/utils/transformers/connectedAccounts.ts +119 -0
- package/src/utils/transformers/mcp.ts +164 -0
- package/src/utils/transformers/toolRouterResponseTransform.ts +160 -0
- package/src/utils/transformers/toolkits.ts +100 -0
- package/src/utils/transformers/triggers.ts +118 -0
- package/src/utils/uploadDirAllowlist.node.ts +178 -0
- package/src/utils/uuid.ts +7 -0
- package/src/utils/version.ts +58 -0
- package/src/utils/zodSchema.ts +90 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview The `composio.experimental` namespace. Houses experimental
|
|
3
|
+
* SDK methods whose shape may change in future releases.
|
|
4
|
+
*
|
|
5
|
+
* Domain-specific mounts remain preferred when they exist (for example
|
|
6
|
+
* `composio.connectedAccounts.updateAcl(...)`). This namespace keeps
|
|
7
|
+
* compatibility aliases while those APIs are experimental. For experimental
|
|
8
|
+
* stateless factories (e.g. `experimental_createTool`), see the top-level
|
|
9
|
+
* `experimental_*` exports from `@composio/core`.
|
|
10
|
+
*/
|
|
11
|
+
import ComposioClient, { BadRequestError } from '@composio/client';
|
|
12
|
+
import {
|
|
13
|
+
ConnectedAccountPatchParams,
|
|
14
|
+
ConnectedAccountPatchResponse,
|
|
15
|
+
} from '@composio/client/resources/connected-accounts';
|
|
16
|
+
import {
|
|
17
|
+
ConnectedAccountExperimental,
|
|
18
|
+
UpdateConnectedAccountAclParams,
|
|
19
|
+
UpdateConnectedAccountAclParamsSchema,
|
|
20
|
+
} from '../types/connectedAccounts.types';
|
|
21
|
+
import { ValidationError } from '../errors/ValidationErrors';
|
|
22
|
+
import { ComposioAclOnlyForSharedError } from '../errors';
|
|
23
|
+
import { telemetry } from '../telemetry/Telemetry';
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Server-side 400 message the API uses to reject ACL writes against a
|
|
27
|
+
* PRIVATE connection. Substring-matched in `updateAcl` and in the sibling
|
|
28
|
+
* `connectedAccounts.link()` / `session.authorize()` call sites — kept as
|
|
29
|
+
* a single constant so a server-side message tweak only requires one edit.
|
|
30
|
+
*/
|
|
31
|
+
export const ACL_ONLY_FOR_SHARED_ERROR_FRAGMENT = 'acl_config_for_shared is only valid on SHARED';
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Structural shape of the wire's experimental block on requests. Both
|
|
35
|
+
* the `link.create` and `tool_router.session.link` wire types are
|
|
36
|
+
* Stainless-generated as nominally distinct namespaces but accept this
|
|
37
|
+
* shape — sharing one structural type keeps the SDK helpers reusable.
|
|
38
|
+
*/
|
|
39
|
+
type ExperimentalWire = {
|
|
40
|
+
account_type?: 'PRIVATE' | 'SHARED';
|
|
41
|
+
acl_config_for_shared?: {
|
|
42
|
+
allow_all_users?: boolean;
|
|
43
|
+
allowed_user_ids?: string[];
|
|
44
|
+
not_allowed_user_ids?: string[];
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Serialise the SDK's `aclConfigForShared` (camelCase) to the wire's
|
|
50
|
+
* `acl_config_for_shared` block. Returns `undefined` when the caller
|
|
51
|
+
* didn't pass anything (PATCH-style "don't touch ACL"); returns `{}`
|
|
52
|
+
* when the caller passed an explicit empty object.
|
|
53
|
+
*/
|
|
54
|
+
export function serializeAclConfigForWire(
|
|
55
|
+
acl:
|
|
56
|
+
| {
|
|
57
|
+
allowAllUsers?: boolean;
|
|
58
|
+
allowedUserIds?: string[];
|
|
59
|
+
notAllowedUserIds?: string[];
|
|
60
|
+
}
|
|
61
|
+
| undefined
|
|
62
|
+
): NonNullable<ExperimentalWire['acl_config_for_shared']> | undefined {
|
|
63
|
+
if (acl === undefined) return undefined;
|
|
64
|
+
return {
|
|
65
|
+
...(acl.allowAllUsers !== undefined && { allow_all_users: acl.allowAllUsers }),
|
|
66
|
+
...(acl.allowedUserIds !== undefined && { allowed_user_ids: acl.allowedUserIds }),
|
|
67
|
+
...(acl.notAllowedUserIds !== undefined && { not_allowed_user_ids: acl.notAllowedUserIds }),
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Serialise the SDK's `experimental` options block (camelCase) to the
|
|
73
|
+
* wire's `experimental` block (snake_case). Used by both
|
|
74
|
+
* `connectedAccounts.link()` and `session.authorize()`. Returns
|
|
75
|
+
* `undefined` when the caller didn't pass the block at all.
|
|
76
|
+
*/
|
|
77
|
+
export function serializeExperimentalForWire(
|
|
78
|
+
experimental: ConnectedAccountExperimental | undefined
|
|
79
|
+
): ExperimentalWire | undefined {
|
|
80
|
+
if (experimental === undefined) return undefined;
|
|
81
|
+
const aclWire = serializeAclConfigForWire(experimental.aclConfigForShared);
|
|
82
|
+
const wire: ExperimentalWire = {};
|
|
83
|
+
if (experimental.accountType !== undefined) {
|
|
84
|
+
wire.account_type = experimental.accountType;
|
|
85
|
+
}
|
|
86
|
+
if (aclWire !== undefined) {
|
|
87
|
+
wire.acl_config_for_shared = aclWire;
|
|
88
|
+
}
|
|
89
|
+
return wire;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* `composio.experimental` namespace. Keeps compatibility aliases for
|
|
94
|
+
* experimental surfaces while domain-specific mounts graduate. **Shape may
|
|
95
|
+
* change in future releases.**
|
|
96
|
+
*/
|
|
97
|
+
export async function updateConnectedAccountAcl(
|
|
98
|
+
client: ComposioClient,
|
|
99
|
+
nanoid: string,
|
|
100
|
+
params: UpdateConnectedAccountAclParams
|
|
101
|
+
): Promise<ConnectedAccountPatchResponse> {
|
|
102
|
+
const parsedParams = UpdateConnectedAccountAclParamsSchema.safeParse(params);
|
|
103
|
+
if (!parsedParams.success) {
|
|
104
|
+
throw new ValidationError('Failed to parse connected account ACL update params', {
|
|
105
|
+
cause: parsedParams.error,
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const body: ConnectedAccountPatchParams = {
|
|
110
|
+
experimental: {
|
|
111
|
+
acl_config_for_shared: serializeAclConfigForWire(parsedParams.data),
|
|
112
|
+
},
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
try {
|
|
116
|
+
return await client.connectedAccounts.patch(nanoid, body);
|
|
117
|
+
} catch (error) {
|
|
118
|
+
if (
|
|
119
|
+
error instanceof BadRequestError &&
|
|
120
|
+
typeof error.message === 'string' &&
|
|
121
|
+
error.message.includes(ACL_ONLY_FOR_SHARED_ERROR_FRAGMENT)
|
|
122
|
+
) {
|
|
123
|
+
throw new ComposioAclOnlyForSharedError(error.message, { cause: error });
|
|
124
|
+
}
|
|
125
|
+
throw error;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export class Experimental {
|
|
130
|
+
private client: ComposioClient;
|
|
131
|
+
|
|
132
|
+
constructor(client: ComposioClient) {
|
|
133
|
+
this.client = client;
|
|
134
|
+
telemetry.instrument(this, 'Experimental');
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Compatibility alias for `composio.connectedAccounts.updateAcl(...)`.
|
|
139
|
+
* Update the per-user ACL on a SHARED connected account.
|
|
140
|
+
* **Experimental — shape may change in future releases.**
|
|
141
|
+
*
|
|
142
|
+
* Only meaningful for SHARED connections — calling this on a PRIVATE
|
|
143
|
+
* connection raises `ComposioAclOnlyForSharedError` (400). ACL writes
|
|
144
|
+
* require the connection's creator or an API key.
|
|
145
|
+
*
|
|
146
|
+
* PATCH semantics: omit a field to leave it unchanged; pass an empty
|
|
147
|
+
* array to clear an allow/deny list. At least one field must be
|
|
148
|
+
* provided.
|
|
149
|
+
*
|
|
150
|
+
* Resolution rule (deny wins):
|
|
151
|
+
* 1. requesting `userId` in `notAllowedUserIds` → DENY
|
|
152
|
+
* 2. `allowAllUsers === true` → ALLOW
|
|
153
|
+
* 3. requesting `userId` in `allowedUserIds` → ALLOW
|
|
154
|
+
* 4. otherwise → DENY
|
|
155
|
+
*
|
|
156
|
+
* @example
|
|
157
|
+
* ```typescript
|
|
158
|
+
* import { Composio } from '@composio/core';
|
|
159
|
+
*
|
|
160
|
+
* const composio = new Composio({ apiKey: '...' });
|
|
161
|
+
*
|
|
162
|
+
* // Allow every userId to use this connection
|
|
163
|
+
* await composio.connectedAccounts.updateAcl('ca_abc', { allowAllUsers: true });
|
|
164
|
+
*
|
|
165
|
+
* // Everyone except a specific user
|
|
166
|
+
* await composio.connectedAccounts.updateAcl('ca_abc', {
|
|
167
|
+
* allowAllUsers: true,
|
|
168
|
+
* notAllowedUserIds: ['user_bob'],
|
|
169
|
+
* });
|
|
170
|
+
*
|
|
171
|
+
* // Targeted allow
|
|
172
|
+
* await composio.connectedAccounts.updateAcl('ca_abc', {
|
|
173
|
+
* allowedUserIds: ['user_alice', 'user_bob'],
|
|
174
|
+
* });
|
|
175
|
+
*
|
|
176
|
+
* // Revoke a previously-granted allow list (back to deny-by-default)
|
|
177
|
+
* await composio.connectedAccounts.updateAcl('ca_abc', { allowedUserIds: [] });
|
|
178
|
+
* ```
|
|
179
|
+
*
|
|
180
|
+
* **Empty-array semantics — read carefully.** Passing `[]` for either
|
|
181
|
+
* list **replaces** the list, it does not extend it:
|
|
182
|
+
*
|
|
183
|
+
* - `allowedUserIds: []` → revoke all previously-granted user IDs (state
|
|
184
|
+
* reverts to deny-by-default unless `allowAllUsers` is true).
|
|
185
|
+
* - `notAllowedUserIds: []` → **clears the deny list**, which silently
|
|
186
|
+
* re-grants access to users you previously blocked. Always pair an
|
|
187
|
+
* empty deny list with a deliberate audit of the allow side.
|
|
188
|
+
*
|
|
189
|
+
* @returns The PATCH response (`{ id, status, success }`). To read
|
|
190
|
+
* the updated ACL block, call
|
|
191
|
+
* `composio.connectedAccounts.get(nanoid)` after the promise
|
|
192
|
+
* resolves and inspect `account.experimental?.aclConfigForShared`.
|
|
193
|
+
*
|
|
194
|
+
* @deprecated Use `composio.connectedAccounts.updateAcl(...)` instead — ACL updates graduated onto the `connectedAccounts` mount. This experimental alias is kept only for backwards compatibility and will be removed once the API graduates. Prefer the `connectedAccounts` mount; do not generate new code against this alias.
|
|
195
|
+
*/
|
|
196
|
+
async updateAcl(
|
|
197
|
+
nanoid: string,
|
|
198
|
+
params: UpdateConnectedAccountAclParams
|
|
199
|
+
): Promise<ConnectedAccountPatchResponse> {
|
|
200
|
+
return updateConnectedAccountAcl(this.client, nanoid, params);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Files class for Composio SDK, used to manage files.
|
|
3
|
+
*
|
|
4
|
+
* @author Musthaq Ahamad <musthaq@composio.dev>
|
|
5
|
+
* @date 2025-06-23
|
|
6
|
+
* @module Files
|
|
7
|
+
*/
|
|
8
|
+
import ComposioClient from '@composio/client';
|
|
9
|
+
import { FileDownloadData, FileUploadData } from '../types/files.types';
|
|
10
|
+
import { downloadFileFromS3, getFileDataAfterUploadingToS3 } from '../utils/fileUtils.node';
|
|
11
|
+
import { telemetry } from '../telemetry/Telemetry';
|
|
12
|
+
|
|
13
|
+
export class Files {
|
|
14
|
+
private readonly fileOptions: {
|
|
15
|
+
sensitiveFileUploadProtection?: boolean;
|
|
16
|
+
fileUploadPathDenySegments?: string[];
|
|
17
|
+
fileDownloadDir?: string;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
constructor(
|
|
21
|
+
private readonly client: ComposioClient,
|
|
22
|
+
fileOptions: {
|
|
23
|
+
sensitiveFileUploadProtection?: boolean;
|
|
24
|
+
fileUploadPathDenySegments?: string[];
|
|
25
|
+
fileDownloadDir?: string;
|
|
26
|
+
} = {}
|
|
27
|
+
) {
|
|
28
|
+
this.fileOptions = fileOptions;
|
|
29
|
+
telemetry.instrument(this, 'Files');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Upload a file and return the file data.
|
|
34
|
+
*
|
|
35
|
+
* @param params - The upload parameters.
|
|
36
|
+
* @param {File | string} params.file - The path to the file to upload, a URL of the file, or a File object.
|
|
37
|
+
* @param {string} params.toolSlug - The slug of the tool that is uploading the file.
|
|
38
|
+
* @param {string} params.toolkitSlug - The slug of the toolkit that is uploading the file.
|
|
39
|
+
* @returns {Promise<FileUploadData>} The uploaded file data.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
*
|
|
43
|
+
* const fileData = await composio.files.upload({
|
|
44
|
+
* file: 'path/to/file.pdf',
|
|
45
|
+
* toolSlug: 'google_drive_upload',
|
|
46
|
+
* toolkitSlug: 'google_drive'
|
|
47
|
+
* });
|
|
48
|
+
* */
|
|
49
|
+
async upload({
|
|
50
|
+
file,
|
|
51
|
+
toolSlug,
|
|
52
|
+
toolkitSlug,
|
|
53
|
+
}: {
|
|
54
|
+
file: File | string;
|
|
55
|
+
toolSlug: string;
|
|
56
|
+
toolkitSlug: string;
|
|
57
|
+
}): Promise<FileUploadData> {
|
|
58
|
+
// Note: manual `composio.files.upload()` intentionally skips the
|
|
59
|
+
// `fileUploadDirs` allowlist. The allowlist only gates *automatic* upload
|
|
60
|
+
// during tool execution (see FileToolModifier).
|
|
61
|
+
const fileData = await getFileDataAfterUploadingToS3(file, {
|
|
62
|
+
toolSlug,
|
|
63
|
+
toolkitSlug,
|
|
64
|
+
client: this.client,
|
|
65
|
+
sensitiveFileUploadProtection: this.fileOptions.sensitiveFileUploadProtection,
|
|
66
|
+
fileUploadPathDenySegments: this.fileOptions.fileUploadPathDenySegments,
|
|
67
|
+
});
|
|
68
|
+
return fileData;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Download a file from S3 and return the file data.
|
|
73
|
+
* @param s3key - The S3 key of the file to download.
|
|
74
|
+
* @returns The file data.
|
|
75
|
+
*/
|
|
76
|
+
async download({
|
|
77
|
+
toolSlug,
|
|
78
|
+
s3Url,
|
|
79
|
+
mimeType,
|
|
80
|
+
}: {
|
|
81
|
+
s3Url: string;
|
|
82
|
+
toolSlug: string;
|
|
83
|
+
mimeType: string;
|
|
84
|
+
}): Promise<FileDownloadData> {
|
|
85
|
+
const fileDownloadData = await downloadFileFromS3({
|
|
86
|
+
toolSlug,
|
|
87
|
+
s3Url,
|
|
88
|
+
mimeType,
|
|
89
|
+
fileDownloadDir: this.fileOptions.fileDownloadDir,
|
|
90
|
+
});
|
|
91
|
+
return fileDownloadData;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
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
|
+
}
|