@composio/core 0.13.1 → 0.14.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.
Files changed (68) hide show
  1. package/README.md +62 -247
  2. package/dist/BaseProvider-Dc5yKZhk.d.mts +29394 -0
  3. package/dist/{CustomTool-DLf7JeKt.d.mts → CustomTool-4nVuwLzO.d.mts} +1 -2
  4. package/dist/{CustomTool-D9qwyMrv.mjs → CustomTool-l-j5HtEf.mjs} +17 -15
  5. package/dist/FileModifierErrors-B8V8_3VE.mjs +97 -0
  6. package/dist/{FileModifierErrors-3fSwIWoa.mjs → SsrfErrors-DNJt57GL.mjs} +24 -85
  7. package/dist/{Telemetry-DhGI_J4G.mjs → Telemetry-CF0rNHu2.mjs} +40 -8
  8. package/dist/{jsonSchema-CFKdONpP.mjs → cancellation-BbJ-UQ__.mjs} +64 -19
  9. package/dist/{composio-BHSQwOUz.d.mts → composio-ChU3eD9F.d.mts} +1083 -1061
  10. package/dist/{customTool.types-9yFqPjdw.d.mts → customTool.types-CX2-LbfI.d.mts} +634 -601
  11. package/dist/docs/reference/sdk-reference/typescript/index.mdx +1 -22
  12. package/dist/docs/reference/sdk-reference/typescript/session-files.mdx +2 -0
  13. package/dist/{errors-DSIlYfl5.mjs → errors-BcEUHZbq.mjs} +75 -74
  14. package/dist/experimental/index.d.mts +2 -2
  15. package/dist/experimental/index.mjs +1 -1
  16. package/dist/{fileUtils.node-BiO1JQsJ.mjs → fileUtils.node-DOkW4PBg.mjs} +36 -70
  17. package/dist/index.d.mts +2446 -1563
  18. package/dist/index.mjs +1415 -1381
  19. package/dist/models/Files.node.d.mts +2 -11
  20. package/dist/models/Files.node.mjs +2 -2
  21. package/dist/models/Files.workerd.d.mts +0 -1
  22. package/dist/platform/node.d.mts +1 -2
  23. package/dist/platform/node.mjs +3 -0
  24. package/dist/platform/workerd.d.mts +1 -2
  25. package/dist/platform/workerd.mjs +30 -3
  26. package/dist/sensitiveFileUploadPaths-C43dHP7S.mjs +164 -0
  27. package/dist/{types-BJLCRj9q.d.mts → types-D5N60gUD.d.mts} +2 -3
  28. package/dist/{types-DdoCRzLj.d.mts → types-DY1r-kN9.d.mts} +9 -0
  29. package/dist/utils/config-defaults/ConfigDefaults.node.d.mts +1 -2
  30. package/dist/utils/config-defaults/ConfigDefaults.workerd.d.mts +1 -2
  31. package/dist/utils/modifiers/FileToolModifier.node.d.mts +1 -2
  32. package/dist/utils/modifiers/FileToolModifier.node.mjs +6 -5
  33. package/dist/utils/modifiers/FileToolModifier.workerd.d.mts +1 -2
  34. package/dist/utils/ssrfGuard.node.d.mts +22 -0
  35. package/dist/utils/ssrfGuard.node.mjs +152 -0
  36. package/dist/utils/ssrfGuard.workerd.d.mts +9 -0
  37. package/dist/utils/ssrfGuard.workerd.mjs +17 -0
  38. package/package.json +20 -15
  39. package/src/errors/SsrfErrors.ts +48 -0
  40. package/src/errors/index.ts +3 -0
  41. package/src/index.ts +10 -0
  42. package/src/models/CustomTool.ts +1 -3
  43. package/src/models/ToolRouterSession.ts +38 -16
  44. package/src/models/ToolRouterSessionFileMount.ts +7 -3
  45. package/src/models/Tools.ts +32 -2
  46. package/src/models/Triggers.ts +16 -76
  47. package/src/platform/node.ts +4 -0
  48. package/src/platform/types.ts +10 -0
  49. package/src/platform/workerd.ts +36 -3
  50. package/src/provider/OpenAIProvider.ts +19 -14
  51. package/src/telemetry/Telemetry.ts +9 -6
  52. package/src/telemetry/redact.ts +40 -0
  53. package/src/types/tool.types.ts +36 -32
  54. package/src/utils/fileUtils.node.ts +29 -6
  55. package/src/utils/jsonSchema.ts +58 -0
  56. package/src/utils/modifiers/FileToolModifier.node.ts +2 -1
  57. package/src/utils/readResponseBody.ts +63 -0
  58. package/src/utils/sdk.ts +5 -4
  59. package/src/utils/{sensitiveFileUploadPaths.node.ts → sensitiveFileUploadPaths.ts} +29 -13
  60. package/src/utils/ssrfGuard.node.ts +202 -0
  61. package/src/utils/ssrfGuard.workerd.ts +19 -0
  62. package/src/utils/toolkitVersion.ts +21 -2
  63. package/dist/BaseProvider-Brb3o86-.d.mts +0 -29425
  64. package/dist/CustomTool-NpHpqdnU.d.mts +0 -74
  65. package/dist/buffer-PcbMMsgm.mjs +0 -33
  66. package/dist/composio-DfPD7BAi.d.mts +0 -5666
  67. package/dist/customTool.types-D-6YqFdW.d.mts +0 -2826
  68. package/dist/types-CCh8qvui.d.mts +0 -12
@@ -5,28 +5,7 @@ description: "Complete API reference for the Composio TypeScript SDK (@composio/
5
5
 
6
6
  ## Installation
7
7
 
8
- <Tabs groupId="package-manager" items={['npm', 'pnpm', 'yarn', 'bun']} persist>
9
- <Tab value="npm">
10
- ```bash
11
- npm install @composio/core
12
- ```
13
- </Tab>
14
- <Tab value="pnpm">
15
- ```bash
16
- pnpm add @composio/core
17
- ```
18
- </Tab>
19
- <Tab value="yarn">
20
- ```bash
21
- yarn add @composio/core
22
- ```
23
- </Tab>
24
- <Tab value="bun">
25
- ```bash
26
- bun add @composio/core
27
- ```
28
- </Tab>
29
- </Tabs>
8
+ <PackageInstall packages="@composio/core" />
30
9
 
31
10
  ## Classes
32
11
 
@@ -126,6 +126,8 @@ Uploads a file to the session's file mount.
126
126
 
127
127
  Accepts a file path (local or URL), a native File object, or a raw buffer.
128
128
  The file is stored in the virtual filesystem associated with the tool router session.
129
+ URL inputs require a Node.js or Bun runtime so the destination can be DNS-validated;
130
+ edge runtimes must fetch the file themselves and pass a File or ArrayBuffer.
129
131
 
130
132
  ```typescript
131
133
  async upload(input: string | File | ArrayBuffer | Uint8Array, options?: ToolRouterSessionFilesMountUploadOptions): Promise<RemoteFile>
@@ -1,7 +1,26 @@
1
- import { s as ComposioError$1 } from "./FileModifierErrors-3fSwIWoa.mjs";
1
+ import { r as ComposioError$1 } from "./SsrfErrors-DNJt57GL.mjs";
2
+ import "./FileModifierErrors-B8V8_3VE.mjs";
2
3
  import { APIError, APIUserAbortError } from "@composio/client";
3
4
  import { ZodError } from "zod/v3";
4
5
 
6
+ //#region src/errors/AuthConfigErrors.ts
7
+ const AuthConfigErrorCodes = { AUTH_CONFIG_NOT_FOUND: "AUTH_CONFIG_NOT_FOUND" };
8
+ var ComposioAuthConfigNotFoundError = class extends ComposioError$1 {
9
+ constructor(message = "Auth config not found", options = {}) {
10
+ super(message, {
11
+ ...options,
12
+ code: AuthConfigErrorCodes.AUTH_CONFIG_NOT_FOUND,
13
+ possibleFixes: options.possibleFixes || [
14
+ "Check if the auth config exists",
15
+ "Check if the auth config id is correct",
16
+ "Check if the auth config is enabled"
17
+ ]
18
+ });
19
+ this.name = "ComposioAuthConfigNotFoundError";
20
+ }
21
+ };
22
+
23
+ //#endregion
5
24
  //#region src/errors/ConnectedAccountsErrors.ts
6
25
  const ConnectedAccountErrorCodes = {
7
26
  CONNECTED_ACCOUNT_NOT_FOUND: "CONNECTED_ACCOUNT_NOT_FOUND",
@@ -119,6 +138,31 @@ var ComposioLegacyConnectedAccountsEndpointRetiredError = class extends Composio
119
138
  }
120
139
  };
121
140
 
141
+ //#endregion
142
+ //#region src/errors/ConnectionRequestErrors.ts
143
+ const ConnectionRequestErrorCodes = {
144
+ CONNECTION_REQUEST_TIMEOUT: "CONNECTION_REQUEST_TIMEOUT",
145
+ CONNECTION_REQUEST_FAILED: "CONNECTION_REQUEST_FAILED"
146
+ };
147
+ var ConnectionRequestTimeoutError = class extends ComposioError$1 {
148
+ constructor(message = "Connection request timed out", options = {}) {
149
+ super(message, {
150
+ ...options,
151
+ code: ConnectionRequestErrorCodes.CONNECTION_REQUEST_TIMEOUT
152
+ });
153
+ this.name = "ConnectionRequestTimeoutError";
154
+ }
155
+ };
156
+ var ConnectionRequestFailedError = class extends ComposioError$1 {
157
+ constructor(message = "Connection request failed", options = {}) {
158
+ super(message, {
159
+ ...options,
160
+ code: ConnectionRequestErrorCodes.CONNECTION_REQUEST_FAILED
161
+ });
162
+ this.name = "ConnectionRequestFailedError";
163
+ }
164
+ };
165
+
122
166
  //#endregion
123
167
  //#region src/errors/ToolErrors.ts
124
168
  const ToolErrorCodes = {
@@ -279,7 +323,7 @@ var ComposioToolVersionRequiredError = class extends ComposioError$1 {
279
323
  });
280
324
  }
281
325
  };
282
- const ERROR_CODE_HANDLERS = new Map([[1803, (msg) => new ComposioConnectedAccountNotFoundError(msg)]]);
326
+ const ERROR_CODE_HANDLERS = /* @__PURE__ */ new Map([[1803, (msg) => new ComposioConnectedAccountNotFoundError(msg)]]);
283
327
  const handleToolExecutionError = (tool, actualError) => {
284
328
  if (actualError instanceof APIError && actualError.error) {
285
329
  const errorBody = actualError.error;
@@ -293,6 +337,34 @@ const handleToolExecutionError = (tool, actualError) => {
293
337
  });
294
338
  };
295
339
 
340
+ //#endregion
341
+ //#region src/errors/ToolkitErrors.ts
342
+ const ToolkitErrorCodes = { TOOLKIT_NOT_FOUND: "TOOLKIT_NOT_FOUND" };
343
+ var ComposioToolkitNotFoundError = class extends ComposioError$1 {
344
+ constructor(message = "Toolkit not found", options = {}) {
345
+ super(message, {
346
+ ...options,
347
+ code: "TOOLKIT_NOT_FOUND",
348
+ possibleFixes: options.possibleFixes || ["Ensure the toolkit is correctly configured and the slug is valid"]
349
+ });
350
+ this.name = "ComposioToolkitNotFoundError";
351
+ }
352
+ };
353
+ var ComposioToolkitFetchError = class extends ComposioError$1 {
354
+ constructor(message = "Failed to fetch toolkit", options = {}) {
355
+ super(message, {
356
+ ...options,
357
+ code: "TOOLKIT_FETCH_ERROR",
358
+ possibleFixes: options.possibleFixes || [
359
+ "Ensure the toolkit slug is valid",
360
+ "Ensure you are using the correct API key",
361
+ "Ensure you are using the correct API endpoint / Base URL and it is working"
362
+ ]
363
+ });
364
+ this.name = "ComposioToolkitFetchError";
365
+ }
366
+ };
367
+
296
368
  //#endregion
297
369
  //#region src/errors/ValidationErrors.ts
298
370
  /**
@@ -420,77 +492,6 @@ function _isRequestAbortErrorAt(error, depth) {
420
492
  return false;
421
493
  }
422
494
 
423
- //#endregion
424
- //#region src/errors/AuthConfigErrors.ts
425
- const AuthConfigErrorCodes = { AUTH_CONFIG_NOT_FOUND: "AUTH_CONFIG_NOT_FOUND" };
426
- var ComposioAuthConfigNotFoundError = class extends ComposioError$1 {
427
- constructor(message = "Auth config not found", options = {}) {
428
- super(message, {
429
- ...options,
430
- code: AuthConfigErrorCodes.AUTH_CONFIG_NOT_FOUND,
431
- possibleFixes: options.possibleFixes || [
432
- "Check if the auth config exists",
433
- "Check if the auth config id is correct",
434
- "Check if the auth config is enabled"
435
- ]
436
- });
437
- this.name = "ComposioAuthConfigNotFoundError";
438
- }
439
- };
440
-
441
- //#endregion
442
- //#region src/errors/ConnectionRequestErrors.ts
443
- const ConnectionRequestErrorCodes = {
444
- CONNECTION_REQUEST_TIMEOUT: "CONNECTION_REQUEST_TIMEOUT",
445
- CONNECTION_REQUEST_FAILED: "CONNECTION_REQUEST_FAILED"
446
- };
447
- var ConnectionRequestTimeoutError = class extends ComposioError$1 {
448
- constructor(message = "Connection request timed out", options = {}) {
449
- super(message, {
450
- ...options,
451
- code: ConnectionRequestErrorCodes.CONNECTION_REQUEST_TIMEOUT
452
- });
453
- this.name = "ConnectionRequestTimeoutError";
454
- }
455
- };
456
- var ConnectionRequestFailedError = class extends ComposioError$1 {
457
- constructor(message = "Connection request failed", options = {}) {
458
- super(message, {
459
- ...options,
460
- code: ConnectionRequestErrorCodes.CONNECTION_REQUEST_FAILED
461
- });
462
- this.name = "ConnectionRequestFailedError";
463
- }
464
- };
465
-
466
- //#endregion
467
- //#region src/errors/ToolkitErrors.ts
468
- const ToolkitErrorCodes = { TOOLKIT_NOT_FOUND: "TOOLKIT_NOT_FOUND" };
469
- var ComposioToolkitNotFoundError = class extends ComposioError$1 {
470
- constructor(message = "Toolkit not found", options = {}) {
471
- super(message, {
472
- ...options,
473
- code: "TOOLKIT_NOT_FOUND",
474
- possibleFixes: options.possibleFixes || ["Ensure the toolkit is correctly configured and the slug is valid"]
475
- });
476
- this.name = "ComposioToolkitNotFoundError";
477
- }
478
- };
479
- var ComposioToolkitFetchError = class extends ComposioError$1 {
480
- constructor(message = "Failed to fetch toolkit", options = {}) {
481
- super(message, {
482
- ...options,
483
- code: "TOOLKIT_FETCH_ERROR",
484
- possibleFixes: options.possibleFixes || [
485
- "Ensure the toolkit slug is valid",
486
- "Ensure you are using the correct API key",
487
- "Ensure you are using the correct API endpoint / Base URL and it is working"
488
- ]
489
- });
490
- this.name = "ComposioToolkitFetchError";
491
- }
492
- };
493
-
494
495
  //#endregion
495
496
  //#region src/errors/TriggerErrors.ts
496
497
  const TriggerErrorCodes = {
@@ -614,4 +615,4 @@ var RemoteFileDownloadError = class extends ComposioError$1 {
614
615
  };
615
616
 
616
617
  //#endregion
617
- export { ComposioInvalidToolArgumentsError as A, ComposioLegacyConnectedAccountsEndpointRetiredError as B, JsonSchemaRefResolutionError as C, ComposioGlobalExecuteToolFnNotSetError as D, ValidationErrorCodes as E, ToolErrorCodes as F, ComposioSharedAccessDeniedError as H, handleToolExecutionError as I, ComposioAclOnlyForSharedError as L, ComposioToolExecutionError as M, ComposioToolNotFoundError as N, ComposioInvalidExecuteFunctionError as O, ComposioToolVersionRequiredError as P, ComposioConnectedAccountNotFoundError as R, isRequestAbortError as S, ValidationError as T, ComposioSharedConnectionNotAccessibleError as U, ComposioMultipleConnectedAccountsError as V, ConnectedAccountErrorCodes as W, AuthConfigErrorCodes as _, ComposioFailedToSubscribeToPusherChannelError as a, ComposioRequestCancelledError as b, ComposioWebhookPayloadError as c, ComposioToolkitFetchError as d, ComposioToolkitNotFoundError as f, ConnectionRequestTimeoutError as g, ConnectionRequestFailedError as h, ComposioFailedToGetSDKRealtimeCredentialsError as i, ComposioProviderNotDefinedError as j, ComposioInvalidModifierError as k, ComposioWebhookSignatureVerificationError as l, ConnectionRequestErrorCodes as m, RemoteFileErrorCodes as n, ComposioFailedToUnsubscribeFromPusherChannelError as o, ToolkitErrorCodes as p, ComposioFailedToCreatePusherClientError as r, ComposioTriggerTypeNotFoundError as s, RemoteFileDownloadError as t, TriggerErrorCodes as u, ComposioAuthConfigNotFoundError as v, JsonSchemaToZodError as w, SDKErrorCodes as x, ComposioNoAPIKeyError as y, ComposioFailedToCreateConnectedAccountLink as z };
618
+ export { ToolErrorCodes as A, ComposioSharedAccessDeniedError as B, ComposioInvalidExecuteFunctionError as C, ComposioToolExecutionError as D, ComposioProviderNotDefinedError as E, ComposioAclOnlyForSharedError as F, ConnectedAccountErrorCodes as H, ComposioConnectedAccountNotFoundError as I, ComposioFailedToCreateConnectedAccountLink as L, ConnectionRequestErrorCodes as M, ConnectionRequestFailedError as N, ComposioToolNotFoundError as O, ConnectionRequestTimeoutError as P, ComposioLegacyConnectedAccountsEndpointRetiredError as R, ComposioGlobalExecuteToolFnNotSetError as S, ComposioInvalidToolArgumentsError as T, AuthConfigErrorCodes as U, ComposioSharedConnectionNotAccessibleError as V, ComposioAuthConfigNotFoundError as W, ValidationError as _, ComposioFailedToSubscribeToPusherChannelError as a, ComposioToolkitNotFoundError as b, ComposioWebhookPayloadError as c, ComposioNoAPIKeyError as d, ComposioRequestCancelledError as f, JsonSchemaToZodError as g, JsonSchemaRefResolutionError as h, ComposioFailedToGetSDKRealtimeCredentialsError as i, handleToolExecutionError as j, ComposioToolVersionRequiredError as k, ComposioWebhookSignatureVerificationError as l, isRequestAbortError as m, RemoteFileErrorCodes as n, ComposioFailedToUnsubscribeFromPusherChannelError as o, SDKErrorCodes as p, ComposioFailedToCreatePusherClientError as r, ComposioTriggerTypeNotFoundError as s, RemoteFileDownloadError as t, TriggerErrorCodes as u, ValidationErrorCodes as v, ComposioInvalidModifierError as w, ToolkitErrorCodes as x, ComposioToolkitFetchError as y, ComposioMultipleConnectedAccountsError as z };
@@ -1,3 +1,3 @@
1
- import { S as SessionContext, a as CreateCustomToolkitParams, c as CustomToolExecuteFn, f as CustomToolkit, o as CustomTool, r as CreateCustomToolParams } from "../customTool.types-D-6YqFdW.mjs";
2
- import { n as createCustomToolkit, t as createCustomTool } from "../CustomTool-NpHpqdnU.mjs";
1
+ import { S as SessionContext, a as CreateCustomToolkitParams, c as CustomToolExecuteFn, f as CustomToolkit, o as CustomTool, r as CreateCustomToolParams } from "../customTool.types-CX2-LbfI.mjs";
2
+ import { n as createCustomToolkit, t as createCustomTool } from "../CustomTool-4nVuwLzO.mjs";
3
3
  export { type CreateCustomToolParams, type CreateCustomToolkitParams, type CustomTool, type CustomToolExecuteFn, type CustomToolkit, type SessionContext, createCustomTool as experimental_createTool, createCustomToolkit as experimental_createToolkit };
@@ -1,3 +1,3 @@
1
- import { a as createCustomToolkit, i as createCustomTool } from "../CustomTool-D9qwyMrv.mjs";
1
+ import { a as createCustomToolkit, i as createCustomTool } from "../CustomTool-l-j5HtEf.mjs";
2
2
 
3
3
  export { createCustomTool as experimental_createTool, createCustomToolkit as experimental_createToolkit };
@@ -1,69 +1,12 @@
1
- import { a as ComposioSensitiveFilePathBlockedError, c as logger, i as ComposioFileUploadPathNotAllowedError, l as COMPOSIO_DIR, m as TEMP_FILES_DIRECTORY_NAME, t as ComposioFileNotFoundError } from "./FileModifierErrors-3fSwIWoa.mjs";
2
- import { i as getRandomShortId, n as base64ToUint8Array, r as uint8ArrayToBase64 } from "./buffer-PcbMMsgm.mjs";
1
+ import { a as COMPOSIO_DIR, i as logger, u as TEMP_FILES_DIRECTORY_NAME } from "./SsrfErrors-DNJt57GL.mjs";
2
+ import { i as ComposioFileUploadPathNotAllowedError, t as ComposioFileNotFoundError } from "./FileModifierErrors-B8V8_3VE.mjs";
3
+ import { c as getRandomShortId, i as readResponseBodyWithLimit, n as assertSafeFileUploadPath, o as base64ToUint8Array, s as uint8ArrayToBase64 } from "./sensitiveFileUploadPaths-C43dHP7S.mjs";
4
+ import { ssrfSafeFetch } from "./utils/ssrfGuard.node.mjs";
3
5
  import { platform } from "#platform";
4
6
  import fs from "node:fs";
5
7
  import * as path from "node:path";
6
8
  import crypto from "node:crypto";
7
9
 
8
- //#region src/utils/sensitiveFileUploadPaths.node.ts
9
- /**
10
- * Blocks accidental upload of local files from well-known secret/credential locations
11
- * during auto file upload (and {@link getFileDataAfterUploadingToS3}).
12
- */
13
- /**
14
- * Path segments (a single path component) that indicate a sensitive directory when
15
- * they appear anywhere in a resolved local path. Compared case-insensitively on Windows.
16
- */
17
- const BUILTIN_FILE_UPLOAD_PATH_DENY_SEGMENTS = [
18
- ".ssh",
19
- ".aws",
20
- ".azure",
21
- ".gnupg",
22
- ".kube",
23
- ".docker",
24
- ".claude",
25
- ".password-store",
26
- "keychains"
27
- ];
28
- const SECRET_LIKE_BASENAME = /^(\.env(\.|$)|\.netrc$|\.pgpass$)/i;
29
- /** Default SSH private key basenames (public keys like id_rsa.pub are allowed). */
30
- const DEFAULT_PRIVATE_KEY_BASENAME = /^id_(rsa|ed25519|ecdsa|dsa|ecdsa_sk)(\.old)?$/i;
31
- /**
32
- * Returns normalized path segments, resolving symlinks when the path exists.
33
- */
34
- function normalizePathSegments(filePath) {
35
- const absolute = path.resolve(filePath);
36
- let resolved = absolute;
37
- try {
38
- if (fs.existsSync(absolute)) resolved = fs.realpathSync(absolute);
39
- } catch {}
40
- return resolved.split(/[/\\]+/).filter(Boolean);
41
- }
42
- function getSensitiveFileUploadPathBlockReason(filePath, additionalDenySegments) {
43
- const segments = normalizePathSegments(filePath);
44
- const isWin = process.platform === "win32";
45
- const deny = new Set([...BUILTIN_FILE_UPLOAD_PATH_DENY_SEGMENTS, ...(additionalDenySegments ?? []).map((s) => s.trim()).filter(Boolean)].map((s) => isWin ? s.toLowerCase() : s));
46
- const segmentsForMatch = isWin ? segments.map((s) => s.toLowerCase()) : segments;
47
- for (let i = 0; i < segments.length; i++) if (deny.has(segmentsForMatch[i])) return `path segment "${segments[i]}" is in the sensitive file upload denylist`;
48
- const basename = segments.length > 0 ? segments[segments.length - 1] : "";
49
- if (basename) {
50
- if (SECRET_LIKE_BASENAME.test(basename) || DEFAULT_PRIVATE_KEY_BASENAME.test(basename)) return `file name "${basename}" looks like a credential, env, or private key file`;
51
- if (basename.toLowerCase() === "credentials") return "file name \"credentials\" is often used for cloud/API credential stores";
52
- }
53
- return null;
54
- }
55
- /**
56
- * @throws {ComposioSensitiveFilePathBlockedError} if the path is not allowed
57
- */
58
- function assertSafeFileUploadPath(filePath, options) {
59
- const reason = getSensitiveFileUploadPathBlockReason(filePath, options?.additionalDenySegments);
60
- if (reason) throw new ComposioSensitiveFilePathBlockedError(`Refusing to upload: ${reason}. To upload from this path anyway, set sensitiveFileUploadProtection: false on Composio (not recommended) or use a copy outside sensitive locations.`, { meta: {
61
- filePath,
62
- reason
63
- } });
64
- }
65
-
66
- //#endregion
67
10
  //#region src/utils/uploadDirAllowlist.node.ts
68
11
  /**
69
12
  * Allowlist for automatic file upload during tool execution.
@@ -210,6 +153,24 @@ function assertPathInsideUploadDirs(filePath, allowlist) {
210
153
 
211
154
  //#endregion
212
155
  //#region src/utils/fileUtils.node.ts
156
+ /**
157
+ * Checks whether `value` is an absolute http(s) URL rather than a local path.
158
+ *
159
+ * A bare `startsWith('http')` check also matches local paths like
160
+ * `http_export/report.csv` or `httpdocs/.env`, which routes them into the URL
161
+ * fetch branch and skips the allowlist/denylist checks in
162
+ * {@link getFileDataAfterUploadingToS3}. `new URL()` requires a real scheme
163
+ * (`http:` or `https:`) followed by `//`, so relative-looking paths correctly
164
+ * fail to parse and are treated as local.
165
+ */
166
+ const isHttpUrl = (value) => {
167
+ try {
168
+ const url = new URL(value);
169
+ return url.protocol === "http:" || url.protocol === "https:";
170
+ } catch {
171
+ return false;
172
+ }
173
+ };
213
174
  const getExtensionFromMimeType = (mimeType) => {
214
175
  const mimeToExt = {
215
176
  "text/plain": "txt",
@@ -290,15 +251,19 @@ const readFileContent = async (filePath) => {
290
251
  }
291
252
  };
292
253
  const readFileContentFromURL = async (path, signal) => {
293
- const response = await fetch(path, { signal });
254
+ const response = await ssrfSafeFetch(path, { signal });
294
255
  if (!response.ok) throw new Error(`Failed to fetch file: ${response.statusText}`);
295
- const arrayBuffer = await response.arrayBuffer();
296
- const content = new Uint8Array(arrayBuffer);
256
+ const content = await readResponseBodyWithLimit(response);
297
257
  const mimeType = response.headers.get("content-type") || "application/octet-stream";
298
258
  const pathname = new URL(path).pathname;
299
259
  let fileName = platform.basename(pathname);
300
- if (!fileName || fileName === "/") fileName = generateTimestampedFilename(getExtensionFromMimeType(mimeType));
301
- else if (!fileName.includes(".")) fileName = generateTimestampedFilename(getExtensionFromMimeType(mimeType));
260
+ if (!fileName || fileName === "/") {
261
+ const extension = getExtensionFromMimeType(mimeType);
262
+ fileName = generateTimestampedFilename(extension);
263
+ } else if (!fileName.includes(".")) {
264
+ const extension = getExtensionFromMimeType(mimeType);
265
+ fileName = generateTimestampedFilename(extension);
266
+ }
302
267
  return {
303
268
  content: uint8ArrayToBase64(content),
304
269
  mimeType,
@@ -334,13 +299,13 @@ const readFile = async (file, signal) => {
334
299
  content: uint8ArrayToBase64(new Uint8Array(content)),
335
300
  mimeType: file.type
336
301
  };
337
- } else if (typeof file === "string") if (file.startsWith("http")) return await readFileContentFromURL(file, signal);
302
+ } else if (typeof file === "string") if (isHttpUrl(file)) return await readFileContentFromURL(file, signal);
338
303
  else return await readFileContent(file);
339
304
  throw new Error("Invalid file type");
340
305
  };
341
306
  const getFileDataAfterUploadingToS3 = async (file, { toolSlug, toolkitSlug, client, sensitiveFileUploadProtection, fileUploadPathDenySegments, fileUploadAllowlist, signal }) => {
342
307
  if (!file) throw new Error("Either path or blob must be provided");
343
- const isLocalPath = typeof file === "string" && !file.startsWith("http");
308
+ const isLocalPath = typeof file === "string" && !isHttpUrl(file);
344
309
  if (isLocalPath && fileUploadAllowlist !== void 0) assertPathInsideUploadDirs(file, fileUploadAllowlist);
345
310
  if (sensitiveFileUploadProtection !== false && isLocalPath) assertSafeFileUploadPath(file, { additionalDenySegments: fileUploadPathDenySegments });
346
311
  const fileData = await readFile(file, signal);
@@ -357,7 +322,8 @@ const downloadFileFromS3 = async ({ toolSlug, s3Url, mimeType, fileDownloadDir,
357
322
  const response = await fetch(s3Url, { signal });
358
323
  if (!response.ok) throw new Error(`Failed to download file: ${response.statusText}`);
359
324
  const data = await response.arrayBuffer();
360
- const fileName = generateTimestampedFilename(getExtensionFromMimeType(mimeType), `${toolSlug}_`);
325
+ const extension = getExtensionFromMimeType(mimeType);
326
+ const fileName = generateTimestampedFilename(extension, `${toolSlug}_`);
361
327
  return {
362
328
  name: fileName,
363
329
  mimeType,
@@ -445,4 +411,4 @@ const saveFile = (file, content, options = {}) => {
445
411
  };
446
412
 
447
413
  //#endregion
448
- export { getFileDataAfterUploadingToS3 as n, downloadFileFromS3 as t };
414
+ export { getFileDataAfterUploadingToS3 as n, isHttpUrl as r, downloadFileFromS3 as t };