@composio/core 1.0.0-beta.0 → 1.0.0-beta.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 (82) hide show
  1. package/dist/{CustomTool-l-j5HtEf.mjs → CustomTool-CM-roKk7.mjs} +16 -6
  2. package/dist/{CustomTool-CwpeQhz2.d.mts → CustomTool-yMQjEyMz.d.mts} +1 -1
  3. package/dist/{FileModifierErrors-B8V8_3VE.mjs → FileModifierErrors-CdGSABoq.mjs} +1 -1
  4. package/dist/{FileToolModifier.utils.neutral-D_YkHwZP.mjs → FileToolModifier.utils.neutral-DWFpnsj2.mjs} +4 -2
  5. package/dist/{SsrfErrors-DNJt57GL.mjs → SsrfErrors-DiQldIdC.mjs} +154 -19
  6. package/dist/{Telemetry-DK1uAWnD.mjs → Telemetry-JRJJYS4I.mjs} +28 -44
  7. package/dist/cancellation-BEpFk2S8.mjs +706 -0
  8. package/dist/{composio-XjF7EMEe.d.mts → composio-BVNJTVYa.d.mts} +2450 -119
  9. package/dist/{customTool.types-DpJbYY5m.d.mts → customTool.types-CY5SXFfF.d.mts} +143 -28
  10. package/dist/docs/reference/sdk-reference/typescript/session-files.mdx +1 -1
  11. package/dist/docs/reference/sdk-reference/typescript/session.mdx +4 -3
  12. package/dist/{errors-BcEUHZbq.mjs → errors-CvZjP9CH.mjs} +42 -4
  13. package/dist/experimental/index.d.mts +2 -2
  14. package/dist/experimental/index.mjs +1 -1
  15. package/dist/{fileUtils.node-BwpUOF0s.mjs → fileUtils.node-HQsywtTj.mjs} +11 -9
  16. package/dist/index.d.mts +393 -142
  17. package/dist/index.mjs +1945 -171
  18. package/dist/models/Files.node.d.mts +2 -3
  19. package/dist/models/Files.node.mjs +2 -2
  20. package/dist/models/Files.workerd.d.mts +2 -3
  21. package/dist/platform/node.d.mts +2 -3
  22. package/dist/platform/workerd.d.mts +2 -3
  23. package/dist/{sensitiveFileUploadPaths-B0w8dqpv.mjs → sensitiveFileUploadPaths-BlLp-Yo2.mjs} +10 -7
  24. package/dist/{ssrfGuard.node-DlxO8uzr.mjs → ssrfGuard.node-BK50mYTq.mjs} +187 -24
  25. package/dist/{types-C9kJAurw.d.mts → types-CqGfjlZg.d.mts} +2 -2
  26. package/dist/utils/config-defaults/ConfigDefaults.node.d.mts +3 -4
  27. package/dist/utils/config-defaults/ConfigDefaults.workerd.d.mts +3 -4
  28. package/dist/utils/modifiers/FileToolModifier.node.d.mts +3 -4
  29. package/dist/utils/modifiers/FileToolModifier.node.mjs +6 -6
  30. package/dist/utils/modifiers/FileToolModifier.workerd.d.mts +3 -4
  31. package/dist/utils/modifiers/FileToolModifier.workerd.mjs +1 -1
  32. package/dist/utils/ssrfGuard.node.d.mts +7 -7
  33. package/dist/utils/ssrfGuard.node.mjs +1 -1
  34. package/dist/utils/ssrfGuard.workerd.d.mts +3 -4
  35. package/dist/utils/ssrfGuard.workerd.mjs +2 -2
  36. package/package.json +25 -7
  37. package/src/composio.ts +86 -2
  38. package/src/errors/ConnectedAccountsErrors.ts +47 -0
  39. package/src/errors/ToolErrors.ts +1 -0
  40. package/src/errors/ValidationErrors.ts +2 -0
  41. package/src/index.ts +21 -0
  42. package/src/models/ConnectedAccounts.ts +118 -2
  43. package/src/models/CustomTool.ts +41 -6
  44. package/src/models/CustomToolkits.ts +169 -0
  45. package/src/models/Experimental.ts +27 -0
  46. package/src/models/Keyring.ts +65 -0
  47. package/src/models/Logs.ts +101 -0
  48. package/src/models/RemoteFile.ts +54 -36
  49. package/src/models/ToolRouterSession.ts +60 -4
  50. package/src/models/Toolkits.ts +180 -0
  51. package/src/models/Tools.ts +3 -1
  52. package/src/models/Triggers.ts +17 -87
  53. package/src/models/Usage.ts +119 -0
  54. package/src/models/Webhooks.ts +520 -0
  55. package/src/services/telemetry/TelemetryService.ts +27 -12
  56. package/src/telemetry/redact.ts +133 -6
  57. package/src/types/authConfigs.types.ts +2 -0
  58. package/src/types/connectedAccounts.types.ts +54 -0
  59. package/src/types/customToolkits.types.ts +102 -0
  60. package/src/types/keyring.types.ts +32 -0
  61. package/src/types/logs.types.ts +108 -0
  62. package/src/types/toolRouter.types.ts +49 -1
  63. package/src/types/toolkit.types.ts +131 -0
  64. package/src/types/usage.types.ts +81 -0
  65. package/src/types/webhooks.types.ts +143 -0
  66. package/src/utils/constants.ts +1 -5
  67. package/src/utils/fileUtils.node.ts +10 -2
  68. package/src/utils/jsonSchema.ts +509 -28
  69. package/src/utils/logger.ts +45 -13
  70. package/src/utils/pinnedDispatcher.node.ts +109 -13
  71. package/src/utils/sdk.ts +1 -1
  72. package/src/utils/ssrfGuard.node.ts +124 -21
  73. package/src/utils/ssrfGuard.workerd.ts +5 -1
  74. package/src/utils/transformers/connectedAccounts.ts +37 -2
  75. package/src/utils/transformers/customToolkits.ts +98 -0
  76. package/src/utils/transformers/keyring.ts +24 -0
  77. package/src/utils/transformers/logs.ts +85 -0
  78. package/src/utils/transformers/toolkits.ts +100 -1
  79. package/src/utils/transformers/triggers.ts +2 -2
  80. package/src/utils/transformers/usage.ts +77 -0
  81. package/src/utils/transformers/webhooks.ts +139 -0
  82. package/dist/cancellation-C-qy8rcj.mjs +0 -364
@@ -1,7 +1,7 @@
1
1
  import { n as FileUploadData, t as FileDownloadData } from "../files.types-DeMC_mAW.mjs";
2
2
  import ComposioClient from "@composio/client";
3
3
  //#region src/models/Files.node.d.ts
4
- declare class Files {
4
+ export declare class Files {
5
5
  private readonly client;
6
6
  private readonly fileOptions;
7
7
  constructor(client: ComposioClient, fileOptions?: {
@@ -42,5 +42,4 @@ declare class Files {
42
42
  mimeType: string;
43
43
  }): Promise<FileDownloadData>;
44
44
  }
45
- //#endregion
46
- export { Files };
45
+ //#endregion
@@ -1,5 +1,5 @@
1
- import { t as telemetry } from "../Telemetry-DK1uAWnD.mjs";
2
- import { n as getFileDataAfterUploadingToS3, t as downloadFileFromS3 } from "../fileUtils.node-BwpUOF0s.mjs";
1
+ import { t as telemetry } from "../Telemetry-JRJJYS4I.mjs";
2
+ import { n as getFileDataAfterUploadingToS3, t as downloadFileFromS3 } from "../fileUtils.node-HQsywtTj.mjs";
3
3
 
4
4
  //#region src/models/Files.node.ts
5
5
  var Files = class {
@@ -4,8 +4,7 @@ import ComposioClient from "@composio/client";
4
4
  * Files class for Cloudflare Workers / Edge runtimes.
5
5
  * All methods throw an error indicating that file operations are not supported.
6
6
  */
7
- declare class Files {
7
+ export declare class Files {
8
8
  constructor(_client: ComposioClient);
9
9
  }
10
- //#endregion
11
- export { Files };
10
+ //#endregion
@@ -4,6 +4,5 @@ import { t as Platform } from "../types-D5A2wzBl.mjs";
4
4
  * Node.js platform implementation.
5
5
  * Provides full file system and OS operations using Node.js built-in modules.
6
6
  */
7
- declare const platform: Platform;
8
- //#endregion
9
- export { platform };
7
+ export declare const platform: Platform;
8
+ //#endregion
@@ -5,6 +5,5 @@ import { t as Platform } from "../types-D5A2wzBl.mjs";
5
5
  * Provides stub implementations for file system operations that are unavailable in edge runtimes.
6
6
  * All file system operations gracefully return null/empty values or throw descriptive errors.
7
7
  */
8
- declare const platform: Platform;
9
- //#endregion
10
- export { platform };
8
+ export declare const platform: Platform;
9
+ //#endregion
@@ -1,4 +1,4 @@
1
- import { a as ComposioSensitiveFilePathBlockedError } from "./FileModifierErrors-B8V8_3VE.mjs";
1
+ import { a as ComposioSensitiveFilePathBlockedError } from "./FileModifierErrors-CdGSABoq.mjs";
2
2
  import { platform } from "#platform";
3
3
 
4
4
  //#region src/utils/uuid.ts
@@ -35,7 +35,7 @@ const uint8ArrayToBase64 = (bytes) => {
35
35
  //#endregion
36
36
  //#region src/utils/readResponseBody.ts
37
37
  /** Maximum size accepted for files fetched from user-supplied URLs (100 MiB). */
38
- const MAX_URL_UPLOAD_SIZE_BYTES = 100 * 1024 * 1024;
38
+ const MAX_URL_UPLOAD_SIZE_BYTES = 104857600;
39
39
  const sizeLimitError = (actualSize, maxBytes) => /* @__PURE__ */ new Error(`File size (${actualSize} bytes) exceeds maximum allowed size (${maxBytes} bytes)`);
40
40
  /**
41
41
  * Read a fetch response without allowing an untrusted server to exhaust memory.
@@ -176,11 +176,14 @@ const DEFAULT_REMEDIATION = "To upload from this path anyway, set sensitiveFileU
176
176
  */
177
177
  function assertSafeFileUploadPath(filePath, options) {
178
178
  const reason = getSensitiveFileUploadPathBlockReason(filePath, options?.additionalDenySegments);
179
- if (reason) throw new ComposioSensitiveFilePathBlockedError(`Refusing to upload: ${reason}. ${options?.remediation ?? DEFAULT_REMEDIATION}`, { meta: {
180
- filePath,
181
- reason
182
- } });
179
+ if (reason) {
180
+ const remediation = options?.remediation ?? DEFAULT_REMEDIATION;
181
+ throw new ComposioSensitiveFilePathBlockedError(`Refusing to upload: ${reason}. ${remediation}`, { meta: {
182
+ filePath,
183
+ reason
184
+ } });
185
+ }
183
186
  }
184
187
 
185
188
  //#endregion
186
- export { arrayBufferToBase64 as a, getRandomShortId as c, readResponseBodyWithLimit as i, getRandomUUID as l, assertSafeFileUploadPath as n, base64ToUint8Array as o, isBlockedSensitiveFileUploadPath as r, uint8ArrayToBase64 as s, BUILTIN_FILE_UPLOAD_PATH_DENY_SEGMENTS as t };
189
+ export { readResponseBodyWithLimit as a, uint8ArrayToBase64 as c, MAX_URL_UPLOAD_SIZE_BYTES as i, getRandomShortId as l, assertSafeFileUploadPath as n, arrayBufferToBase64 as o, isBlockedSensitiveFileUploadPath as r, base64ToUint8Array as s, BUILTIN_FILE_UPLOAD_PATH_DENY_SEGMENTS as t, getRandomUUID as u };
@@ -1,6 +1,9 @@
1
- import { t as ComposioBlockedInternalUrlError } from "./SsrfErrors-DNJt57GL.mjs";
1
+ import { t as ComposioBlockedInternalUrlError } from "./SsrfErrors-DiQldIdC.mjs";
2
2
  import { lookup } from "node:dns/promises";
3
3
  import { isIP } from "node:net";
4
+ import { request } from "node:http";
5
+ import { request as request$1 } from "node:https";
6
+ import { Readable } from "node:stream";
4
7
 
5
8
  //#region src/utils/pinnedDispatcher.node.ts
6
9
  /**
@@ -33,6 +36,25 @@ const GLOBAL_DISPATCHER_SYMBOLS = [Symbol.for("undici.globalDispatcher.1"), Symb
33
36
  */
34
37
  let undici;
35
38
  const loadUndici = () => undici ??= import("undici");
39
+ const lookupPinnedAddresses = (addresses, options, callback) => {
40
+ if (options.all) {
41
+ callback(null, addresses.map((address) => ({
42
+ address,
43
+ family: isIP(address)
44
+ })));
45
+ return;
46
+ }
47
+ const [address] = addresses;
48
+ callback(null, address, isIP(address));
49
+ };
50
+ const knownBodyLength = (body) => {
51
+ if (body === null || body === void 0) return void 0;
52
+ if (typeof body === "string") return new TextEncoder().encode(body).byteLength;
53
+ if (body instanceof URLSearchParams) return new TextEncoder().encode(body.toString()).byteLength;
54
+ if (body instanceof ArrayBuffer) return body.byteLength;
55
+ if (ArrayBuffer.isView(body)) return body.byteLength;
56
+ if (body instanceof Blob) return body.size;
57
+ };
36
58
  /**
37
59
  * A `fetch` dispatcher that connects to `addresses` instead of resolving the
38
60
  * hostname again.
@@ -59,18 +81,66 @@ const loadUndici = () => undici ??= import("undici");
59
81
  const createPinnedDispatcher = async (addresses) => {
60
82
  const { Agent } = await loadUndici();
61
83
  return new Agent({ connect: { lookup: (_hostname, options, callback) => {
62
- if (options.all) {
63
- callback(null, addresses.map((address) => ({
64
- address,
65
- family: isIP(address)
66
- })));
67
- return;
68
- }
69
- const [address] = addresses;
70
- callback(null, address, isIP(address));
84
+ lookupPinnedAddresses(addresses, options, callback);
71
85
  } } });
72
86
  };
73
87
  /**
88
+ * Fetch through the Node-compatible HTTP client while pinning DNS resolution.
89
+ *
90
+ * Bun implements the Node HTTP client and its `lookup` hook, but its native
91
+ * `fetch` ignores undici's `dispatcher` option. This transport preserves the
92
+ * original hostname for Host and TLS SNI while making the socket use an
93
+ * address that the SSRF guard already validated.
94
+ */
95
+ const pinnedHttpFetch = async (rawUrl, init, addresses) => {
96
+ const normalized = new Request(rawUrl, init);
97
+ const url = new URL(rawUrl);
98
+ const request$2 = url.protocol === "https:" ? request$1 : request;
99
+ const headers = new Headers(normalized.headers);
100
+ const bodyLength = knownBodyLength(init.body);
101
+ if (bodyLength !== void 0 && !headers.has("content-length")) headers.set("content-length", String(bodyLength));
102
+ return new Promise((resolve, reject) => {
103
+ const outgoing = request$2(url, {
104
+ method: normalized.method,
105
+ headers: Object.fromEntries(headers.entries()),
106
+ signal: normalized.signal,
107
+ lookup: (_hostname, options, callback) => lookupPinnedAddresses(addresses, options, callback)
108
+ }, (incoming) => {
109
+ const headers = new Headers();
110
+ for (let index = 0; index < incoming.rawHeaders.length; index += 2) headers.append(incoming.rawHeaders[index], incoming.rawHeaders[index + 1]);
111
+ const status = incoming.statusCode ?? 500;
112
+ const body = [
113
+ 101,
114
+ 103,
115
+ 204,
116
+ 205,
117
+ 304
118
+ ].includes(status) ? null : Readable.toWeb(incoming);
119
+ resolve(new Response(body, {
120
+ status,
121
+ statusText: incoming.statusMessage,
122
+ headers
123
+ }));
124
+ });
125
+ outgoing.once("error", reject);
126
+ (async () => {
127
+ try {
128
+ if (normalized.body) {
129
+ const reader = normalized.body.getReader();
130
+ while (true) {
131
+ const { done, value } = await reader.read();
132
+ if (done) break;
133
+ if (!outgoing.write(value)) await new Promise((resolveDrain) => outgoing.once("drain", resolveDrain));
134
+ }
135
+ }
136
+ outgoing.end();
137
+ } catch (error) {
138
+ outgoing.destroy(error instanceof Error ? error : new Error(String(error)));
139
+ }
140
+ })();
141
+ });
142
+ };
143
+ /**
74
144
  * Whether the process-wide dispatcher `fetch` falls back to (when a request
75
145
  * carries no `dispatcher` of its own) is something other than a stock `Agent`.
76
146
  *
@@ -120,7 +190,8 @@ const hasCustomGlobalDispatcher = () => {
120
190
  * Residual: a hop whose effective dispatcher is a configured route — a
121
191
  * caller-supplied `init.dispatcher`, a non-stock global dispatcher (a
122
192
  * `ProxyAgent` or `EnvHttpProxyAgent` installed via `setGlobalDispatcher`), or
123
- * the runtime's env-proxy mode (`NODE_USE_ENV_PROXY`) — keeps only the
193
+ * the runtime's env-proxy mode (automatic on Bun, opt-in via
194
+ * `NODE_USE_ENV_PROXY` on Node) — keeps only the
124
195
  * pre-flight validation. Pinning would dial the validated address instead of
125
196
  * the proxy, and the proxy resolves the hostname itself where the SDK cannot
126
197
  * see or pin that resolution. The Python guard carries the same residual for
@@ -128,18 +199,93 @@ const hasCustomGlobalDispatcher = () => {
128
199
  */
129
200
  const MAX_REDIRECTS = 5;
130
201
  /**
202
+ * The Fetch standard's "redirect status" set. A 3xx outside it is not a
203
+ * redirect to follow even when it carries a `location` — `304 Not Modified`
204
+ * and `305 Use Proxy` most of all, and following those would replay the
205
+ * request against a target the caller never asked for. The Python guard
206
+ * follows the same set (`_REDIRECT_STATUS_CODES`).
207
+ */
208
+ const REDIRECT_STATUS_CODES = /* @__PURE__ */ new Set([
209
+ 301,
210
+ 302,
211
+ 303,
212
+ 307,
213
+ 308
214
+ ]);
215
+ /**
216
+ * Headers that describe a request body, so they have to go when the body does:
217
+ * the Fetch standard's "request-body-header name" set, plus the two the Python
218
+ * guard also drops because `requests` recomputes them from the body it sends.
219
+ */
220
+ const BODY_HEADERS = [
221
+ "content-encoding",
222
+ "content-language",
223
+ "content-length",
224
+ "content-location",
225
+ "content-type",
226
+ "transfer-encoding"
227
+ ];
228
+ /**
229
+ * The method the hop after a redirect uses, or `null` to replay as-is. A
230
+ * returned method also means the request body goes.
231
+ *
232
+ * These are the Fetch standard's redirect rules, which following redirects by
233
+ * hand (`redirect: 'manual'`) means `fetch` never applies for us: `303` points
234
+ * at a result URL that has no use for the original body, so every method loses
235
+ * it and everything but `HEAD` becomes a `GET`; `301`/`302` do the same to a
236
+ * `POST` only; `307`/`308` replay both. Without this, a `303` answering an
237
+ * upload would PUT the payload again at a URL that expects a GET. The Python
238
+ * guard applies the same rules in `safe_request`.
239
+ */
240
+ const redirectRewrite = (status, method) => {
241
+ if (status === 303) return method === "HEAD" ? "HEAD" : "GET";
242
+ if ((status === 301 || status === 302) && method === "POST") return "GET";
243
+ return null;
244
+ };
245
+ /**
246
+ * Headers that carry a credential for the origin the request was addressed
247
+ * to, so they must not follow a redirect to a different origin. The Fetch
248
+ * standard strips `Authorization` on a cross-origin redirect; `Cookie` and
249
+ * `Proxy-Authorization` go with it the way `requests` and curl drop them on a
250
+ * host change. `redirect: 'manual'` means `fetch` never applies that rule for
251
+ * us either. The Python guard drops the same three (`_CREDENTIAL_HEADERS`).
252
+ */
253
+ const CREDENTIAL_HEADERS = [
254
+ "authorization",
255
+ "cookie",
256
+ "proxy-authorization"
257
+ ];
258
+ const applyRedirectSemantics = (init, status, fromUrl, toUrl) => {
259
+ const method = redirectRewrite(status, (init.method ?? "GET").toUpperCase());
260
+ const crossOrigin = new URL(fromUrl).origin !== new URL(toUrl).origin;
261
+ if (method === null && !crossOrigin) return init;
262
+ const headers = new Headers(init.headers);
263
+ if (method !== null) for (const name of BODY_HEADERS) headers.delete(name);
264
+ if (crossOrigin) for (const name of CREDENTIAL_HEADERS) headers.delete(name);
265
+ if (method === null) return {
266
+ ...init,
267
+ headers
268
+ };
269
+ return {
270
+ ...init,
271
+ method,
272
+ body: void 0,
273
+ headers
274
+ };
275
+ };
276
+ /**
131
277
  * Whether the runtime would route `url` through an env proxy the SDK cannot
132
- * see into. Only meaningful when `NODE_USE_ENV_PROXY` opts the built-in
133
- * `fetch` into env proxies (Node >= 24); without that flag the runtime's
134
- * `fetch` ignores `HTTP_PROXY`/`HTTPS_PROXY` entirely, so mirroring Python's
135
- * bare env-var check would drop pinning for users whose fetch never proxied.
278
+ * see into. Bun honors proxy environment variables automatically. Node's
279
+ * built-in `fetch` requires the `NODE_USE_ENV_PROXY` opt-in (Node >= 24), so
280
+ * a bare env-var check on Node would drop pinning for users whose fetch never
281
+ * proxied.
136
282
  *
137
283
  * `NO_PROXY=*` is the one bypass honored precisely (nothing is proxied, so
138
284
  * pinning is safe again); per-host `NO_PROXY` entries are treated
139
285
  * conservatively as proxied rather than parsed.
140
286
  */
141
- const envProxyApplies = (url) => {
142
- if (!["1", "true"].includes((process.env.NODE_USE_ENV_PROXY ?? "").toLowerCase())) return false;
287
+ const envProxyApplies = (url, isBun) => {
288
+ if (!(isBun || ["1", "true"].includes((process.env.NODE_USE_ENV_PROXY ?? "").toLowerCase()))) return false;
143
289
  if ((process.env.NO_PROXY ?? process.env.no_proxy ?? "") === "*") return false;
144
290
  const schemeVar = url.protocol === "https:" ? "HTTPS_PROXY" : "HTTP_PROXY";
145
291
  return Boolean(process.env[schemeVar] ?? process.env[schemeVar.toLowerCase()]);
@@ -157,6 +303,7 @@ const IPV4_BLOCKED_CIDRS = [
157
303
  ["172.16.0.0", 12],
158
304
  ["192.0.0.0", 24],
159
305
  ["192.0.2.0", 24],
306
+ ["192.88.99.0", 24],
160
307
  ["192.168.0.0", 16],
161
308
  ["198.18.0.0", 15],
162
309
  ["198.51.100.0", 24],
@@ -205,8 +352,14 @@ const isBlockedIpv6 = (ip) => {
205
352
  const isMappedOrCompat = h[0] === 0 && h[1] === 0 && h[2] === 0 && h[3] === 0 && h[4] === 0 && (h[5] === 65535 || h[5] === 0);
206
353
  const isNat64 = h[0] === 100 && h[1] === 65435 && h[2] === 0 && h[3] === 0 && h[4] === 0 && h[5] === 0;
207
354
  if (isMappedOrCompat || isNat64) return isBlockedIpv4Long((h[6] << 16 >>> 0 | h[7]) >>> 0);
355
+ if (h[0] === 8193 && (h[1] & 65024) === 0) return true;
356
+ if (h[0] === 8193 && h[1] === 3512) return true;
357
+ if (h[0] === 8194) return true;
358
+ if (h[0] === 100 && h[1] === 65435 && h[2] === 1) return true;
359
+ if (h[0] === 256 && h[1] === 0 && h[2] === 0 && h[3] === 0) return true;
208
360
  if ((h[0] & 65024) === 64512) return true;
209
361
  if ((h[0] & 65472) === 65152) return true;
362
+ if ((h[0] & 65472) === 65216) return true;
210
363
  if ((h[0] & 65280) === 65280) return true;
211
364
  return false;
212
365
  };
@@ -260,7 +413,8 @@ const assertSafeFetchTarget = async (rawUrl) => {
260
413
  * connects to the address it validated, and re-validates and re-pins every
261
414
  * redirect hop (redirects are followed manually up to {@link MAX_REDIRECTS}).
262
415
  * Intermediate redirect bodies are cancelled; non-redirect responses are
263
- * returned unchanged.
416
+ * returned unchanged. Each hop carries the method, body, and credential headers
417
+ * the Fetch standard says it should — see {@link applyRedirectSemantics}.
264
418
  *
265
419
  * A hop whose effective dispatcher is a configured route (caller-supplied
266
420
  * `init.dispatcher`, non-stock global dispatcher, env-proxy mode) is *not*
@@ -268,16 +422,23 @@ const assertSafeFetchTarget = async (rawUrl) => {
268
422
  */
269
423
  const ssrfSafeFetch = async (rawUrl, init = {}, maxRedirects = MAX_REDIRECTS) => {
270
424
  let currentUrl = rawUrl;
425
+ let currentInit = init;
271
426
  for (let hop = 0; hop <= maxRedirects; hop++) {
272
427
  const addresses = await assertSafeFetchTarget(currentUrl);
273
- const dispatcher = init.dispatcher !== void 0 || envProxyApplies(new URL(currentUrl)) || hasCustomGlobalDispatcher() ? void 0 : await createPinnedDispatcher(addresses);
428
+ const isBun = typeof process.versions.bun === "string";
429
+ const respectConfiguredRoute = currentInit.dispatcher !== void 0 || envProxyApplies(new URL(currentUrl), isBun) || hasCustomGlobalDispatcher();
430
+ const dispatcher = respectConfiguredRoute || isBun ? void 0 : await createPinnedDispatcher(addresses);
274
431
  let response;
275
432
  try {
276
- response = await fetch(currentUrl, dispatcher === void 0 ? {
277
- ...init,
433
+ if (isBun && !respectConfiguredRoute) response = await pinnedHttpFetch(currentUrl, {
434
+ ...currentInit,
435
+ redirect: "manual"
436
+ }, addresses);
437
+ else response = await fetch(currentUrl, dispatcher === void 0 ? {
438
+ ...currentInit,
278
439
  redirect: "manual"
279
440
  } : {
280
- ...init,
441
+ ...currentInit,
281
442
  redirect: "manual",
282
443
  dispatcher
283
444
  });
@@ -286,9 +447,11 @@ const ssrfSafeFetch = async (rawUrl, init = {}, maxRedirects = MAX_REDIRECTS) =>
286
447
  throw error;
287
448
  }
288
449
  if (dispatcher !== void 0) dispatcher.close().catch(() => void 0);
289
- if (!(response.status >= 300 && response.status < 400 && response.headers.has("location"))) return response;
450
+ if (!(REDIRECT_STATUS_CODES.has(response.status) && response.headers.has("location"))) return response;
290
451
  await response.body?.cancel().catch(() => void 0);
291
- currentUrl = new URL(response.headers.get("location"), currentUrl).toString();
452
+ const nextUrl = new URL(response.headers.get("location"), currentUrl).toString();
453
+ currentInit = applyRedirectSemantics(currentInit, response.status, currentUrl, nextUrl);
454
+ currentUrl = nextUrl;
292
455
  }
293
456
  throw new ComposioBlockedInternalUrlError(`Refusing to fetch: too many redirects (max ${maxRedirects})`, { url: rawUrl });
294
457
  };
@@ -1,5 +1,5 @@
1
- import { Mn as BaseComposioProvider } from "./customTool.types-DpJbYY5m.mjs";
2
- import { n as ComposioConfig } from "./composio-XjF7EMEe.mjs";
1
+ import { Kn as BaseComposioProvider } from "./customTool.types-CY5SXFfF.mjs";
2
+ import { n as ComposioConfig } from "./composio-BVNJTVYa.mjs";
3
3
  //#region src/utils/config-defaults/types.d.ts
4
4
  /**
5
5
  * Configuration defaults for Composio.
@@ -1,5 +1,4 @@
1
- import { t as ConfigDefaults } from "../../types-C9kJAurw.mjs";
1
+ import { t as ConfigDefaults } from "../../types-CqGfjlZg.mjs";
2
2
  //#region src/utils/config-defaults/ConfigDefaults.node.d.ts
3
- declare const CONFIG_DEFAULTS: ConfigDefaults;
4
- //#endregion
5
- export { CONFIG_DEFAULTS };
3
+ export declare const CONFIG_DEFAULTS: ConfigDefaults;
4
+ //#endregion
@@ -1,5 +1,4 @@
1
- import { t as ConfigDefaults } from "../../types-C9kJAurw.mjs";
1
+ import { t as ConfigDefaults } from "../../types-CqGfjlZg.mjs";
2
2
  //#region src/utils/config-defaults/ConfigDefaults.workerd.d.ts
3
- declare const CONFIG_DEFAULTS: ConfigDefaults;
4
- //#endregion
5
- export { CONFIG_DEFAULTS };
3
+ export declare const CONFIG_DEFAULTS: ConfigDefaults;
4
+ //#endregion
@@ -1,7 +1,7 @@
1
- import { $i as ToolExecuteResponse, Ji as Tool, Zi as ToolExecuteParams } from "../../customTool.types-DpJbYY5m.mjs";
1
+ import { ca as Tool, da as ToolExecuteParams, pa as ToolExecuteResponse } from "../../customTool.types-CY5SXFfF.mjs";
2
2
  import ComposioClient from "@composio/client";
3
3
  //#region src/utils/modifiers/FileToolModifier.node.d.ts
4
- declare class FileToolModifier {
4
+ export declare class FileToolModifier {
5
5
  private client;
6
6
  private fileUploadPathOptions;
7
7
  constructor(client: ComposioClient, fileUploadPathOptions?: FileToolModifier['fileUploadPathOptions']);
@@ -19,5 +19,4 @@ declare class FileToolModifier {
19
19
  signal?: AbortSignal;
20
20
  }): Promise<ToolExecuteResponse>;
21
21
  }
22
- //#endregion
23
- export { FileToolModifier };
22
+ //#endregion
@@ -1,9 +1,9 @@
1
- import { i as logger } from "../../SsrfErrors-DNJt57GL.mjs";
2
- import { f as ComposioRequestCancelledError } from "../../errors-BcEUHZbq.mjs";
3
- import { a as ComposioSensitiveFilePathBlockedError, i as ComposioFileUploadPathNotAllowedError, n as ComposioFileUploadAbortedError, r as ComposioFileUploadError, t as ComposioFileNotFoundError } from "../../FileModifierErrors-B8V8_3VE.mjs";
4
- import { a as isEmptyFileValue, c as transformProperties, i as getSchemaVariants, l as walkFileUploadableLeaves, o as isPlainObject, r as findSchemaVariantWithFileProperty, t as DELETE_VALUE } from "../../FileToolModifier.utils.neutral-D_YkHwZP.mjs";
5
- import { r as dereferenceJsonSchema, t as withCancellation } from "../../cancellation-C-qy8rcj.mjs";
6
- import { n as getFileDataAfterUploadingToS3, r as isHttpUrl, t as downloadFileFromS3 } from "../../fileUtils.node-BwpUOF0s.mjs";
1
+ import { i as logger } from "../../SsrfErrors-DiQldIdC.mjs";
2
+ import { f as ComposioRequestCancelledError } from "../../errors-CvZjP9CH.mjs";
3
+ import { a as ComposioSensitiveFilePathBlockedError, i as ComposioFileUploadPathNotAllowedError, n as ComposioFileUploadAbortedError, r as ComposioFileUploadError, t as ComposioFileNotFoundError } from "../../FileModifierErrors-CdGSABoq.mjs";
4
+ import { a as isEmptyFileValue, c as transformProperties, i as getSchemaVariants, l as walkFileUploadableLeaves, o as isPlainObject, r as findSchemaVariantWithFileProperty, t as DELETE_VALUE } from "../../FileToolModifier.utils.neutral-DWFpnsj2.mjs";
5
+ import { r as dereferenceJsonSchema, t as withCancellation } from "../../cancellation-BEpFk2S8.mjs";
6
+ import { n as getFileDataAfterUploadingToS3, r as isHttpUrl, t as downloadFileFromS3 } from "../../fileUtils.node-HQsywtTj.mjs";
7
7
 
8
8
  //#region src/utils/modifiers/FileToolModifier.node.ts
9
9
  /**
@@ -1,7 +1,7 @@
1
- import { $i as ToolExecuteResponse, Ji as Tool, Zi as ToolExecuteParams } from "../../customTool.types-DpJbYY5m.mjs";
1
+ import { ca as Tool, da as ToolExecuteParams, pa as ToolExecuteResponse } from "../../customTool.types-CY5SXFfF.mjs";
2
2
  import ComposioClient from "@composio/client";
3
3
  //#region src/utils/modifiers/FileToolModifier.workerd.d.ts
4
- declare class FileToolModifier {
4
+ export declare class FileToolModifier {
5
5
  constructor(_client: ComposioClient);
6
6
  modifyToolSchema(schema: Tool): Promise<Tool>;
7
7
  fileUploadModifier(_tool: Tool, _options: {
@@ -17,5 +17,4 @@ declare class FileToolModifier {
17
17
  signal?: AbortSignal;
18
18
  }): Promise<ToolExecuteResponse>;
19
19
  }
20
- //#endregion
21
- export { FileToolModifier };
20
+ //#endregion
@@ -1,4 +1,4 @@
1
- import { c as transformProperties } from "../../FileToolModifier.utils.neutral-D_YkHwZP.mjs";
1
+ import { c as transformProperties } from "../../FileToolModifier.utils.neutral-DWFpnsj2.mjs";
2
2
 
3
3
  //#region src/utils/modifiers/FileToolModifier.workerd.ts
4
4
  const UNSUPPORTED_MESSAGE = "File upload/download modifiers are not available on edge runtimes yet. Please set `dangerouslyAllowAutoUploadDownloadFiles: false` (or unset it; it defaults to false) or run Composio in another JS runtime (Node.js / Bun).";
@@ -4,7 +4,7 @@
4
4
  * non-publicly-routable address. Fails closed (returns `true`) for anything that
5
5
  * is not a valid IPv4/IPv6 literal.
6
6
  */
7
- declare const isBlockedIp: (ip: string) => boolean;
7
+ export declare const isBlockedIp: (ip: string) => boolean;
8
8
  /**
9
9
  * Validate a single URL: it must be http(s), its host must resolve, and every
10
10
  * resolved address must be publicly routable. Throws
@@ -14,19 +14,20 @@ declare const isBlockedIp: (ip: string) => boolean;
14
14
  * must connect to *those* rather than let the client resolve the hostname
15
15
  * again; see {@link ssrfSafeFetch}.
16
16
  */
17
- declare const assertSafeFetchTarget: (rawUrl: string) => Promise<string[]>;
17
+ export declare const assertSafeFetchTarget: (rawUrl: string) => Promise<string[]>;
18
18
  /**
19
19
  * Drop-in replacement for `fetch` that blocks SSRF. Validates the target, then
20
20
  * connects to the address it validated, and re-validates and re-pins every
21
21
  * redirect hop (redirects are followed manually up to {@link MAX_REDIRECTS}).
22
22
  * Intermediate redirect bodies are cancelled; non-redirect responses are
23
- * returned unchanged.
23
+ * returned unchanged. Each hop carries the method, body, and credential headers
24
+ * the Fetch standard says it should — see {@link applyRedirectSemantics}.
24
25
  *
25
26
  * A hop whose effective dispatcher is a configured route (caller-supplied
26
27
  * `init.dispatcher`, non-stock global dispatcher, env-proxy mode) is *not*
27
28
  * pinned — see the module residual above.
28
29
  */
29
- declare const ssrfSafeFetch: (rawUrl: string, init?: RequestInit, maxRedirects?: number) => Promise<Response>;
30
+ export declare const ssrfSafeFetch: (rawUrl: string, init?: RequestInit, maxRedirects?: number) => Promise<Response>;
30
31
  /**
31
32
  * {@link ssrfSafeFetch} for call sites that must keep working on every runtime.
32
33
  *
@@ -36,6 +37,5 @@ declare const ssrfSafeFetch: (rawUrl: string, init?: RequestInit, maxRedirects?:
36
37
  * feature from Workers rather than close a hole reachable there. On Node this
37
38
  * is the full guard; only the edge build differs.
38
39
  */
39
- declare const ssrfSafeFetchWhereSupported: (rawUrl: string, init?: RequestInit, maxRedirects?: number) => Promise<Response>;
40
- //#endregion
41
- export { assertSafeFetchTarget, isBlockedIp, ssrfSafeFetch, ssrfSafeFetchWhereSupported };
40
+ export declare const ssrfSafeFetchWhereSupported: (rawUrl: string, init?: RequestInit, maxRedirects?: number) => Promise<Response>;
41
+ //#endregion
@@ -1,3 +1,3 @@
1
- import { i as ssrfSafeFetchWhereSupported, n as isBlockedIp, r as ssrfSafeFetch, t as assertSafeFetchTarget } from "../ssrfGuard.node-DlxO8uzr.mjs";
1
+ import { i as ssrfSafeFetchWhereSupported, n as isBlockedIp, r as ssrfSafeFetch, t as assertSafeFetchTarget } from "../ssrfGuard.node-BK50mYTq.mjs";
2
2
 
3
3
  export { assertSafeFetchTarget, isBlockedIp, ssrfSafeFetch, ssrfSafeFetchWhereSupported };
@@ -4,7 +4,7 @@
4
4
  * hostname is publicly routable before connecting. Fail closed instead of
5
5
  * falling back to an unguarded fetch.
6
6
  */
7
- declare const ssrfSafeFetch: (rawUrl: string) => Promise<Response>;
7
+ export declare const ssrfSafeFetch: (rawUrl: string, _init?: RequestInit, _maxRedirects?: number) => Promise<Response>;
8
8
  /**
9
9
  * Unguarded `fetch`, for the call sites that must keep working here.
10
10
  *
@@ -16,6 +16,5 @@ declare const ssrfSafeFetch: (rawUrl: string) => Promise<Response>;
16
16
  * check, and its `fetch` does not originate inside the caller's network. The
17
17
  * Node build applies the full guard.
18
18
  */
19
- declare const ssrfSafeFetchWhereSupported: (rawUrl: string, init?: RequestInit) => Promise<Response>;
20
- //#endregion
21
- export { ssrfSafeFetch, ssrfSafeFetchWhereSupported };
19
+ export declare const ssrfSafeFetchWhereSupported: (rawUrl: string, init?: RequestInit) => Promise<Response>;
20
+ //#endregion
@@ -1,4 +1,4 @@
1
- import { t as ComposioBlockedInternalUrlError } from "../SsrfErrors-DNJt57GL.mjs";
1
+ import { t as ComposioBlockedInternalUrlError } from "../SsrfErrors-DiQldIdC.mjs";
2
2
 
3
3
  //#region src/utils/ssrfGuard.workerd.ts
4
4
  /**
@@ -6,7 +6,7 @@ import { t as ComposioBlockedInternalUrlError } from "../SsrfErrors-DNJt57GL.mjs
6
6
  * hostname is publicly routable before connecting. Fail closed instead of
7
7
  * falling back to an unguarded fetch.
8
8
  */
9
- const ssrfSafeFetch = async (rawUrl) => {
9
+ const ssrfSafeFetch = async (rawUrl, _init = {}, _maxRedirects) => {
10
10
  throw new ComposioBlockedInternalUrlError("URL file uploads are not supported in edge runtimes because the destination cannot be safely validated", {
11
11
  url: rawUrl,
12
12
  possibleFixes: ["Fetch the public URL yourself and pass a File or ArrayBuffer instead", "Run the URL upload in a Node.js or Bun runtime"]
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "engines": {
5
5
  "node": ">=22.22.3"
6
6
  },
7
- "version": "1.0.0-beta.0",
7
+ "version": "1.0.0-beta.1",
8
8
  "description": "",
9
9
  "main": "dist/index.mjs",
10
10
  "publishConfig": {
@@ -73,6 +73,24 @@
73
73
  "types": "./dist/utils/json-schema.d.mts",
74
74
  "default": "./dist/utils/json-schema.mjs"
75
75
  },
76
+ "./utils/ssrf-guard": {
77
+ "workerd": {
78
+ "types": "./dist/utils/ssrfGuard.workerd.d.mts",
79
+ "default": "./dist/utils/ssrfGuard.workerd.mjs"
80
+ },
81
+ "edge-light": {
82
+ "types": "./dist/utils/ssrfGuard.workerd.d.mts",
83
+ "default": "./dist/utils/ssrfGuard.workerd.mjs"
84
+ },
85
+ "node": {
86
+ "types": "./dist/utils/ssrfGuard.node.d.mts",
87
+ "default": "./dist/utils/ssrfGuard.node.mjs"
88
+ },
89
+ "default": {
90
+ "types": "./dist/utils/ssrfGuard.node.d.mts",
91
+ "default": "./dist/utils/ssrfGuard.node.mjs"
92
+ }
93
+ },
76
94
  "./generated": {
77
95
  "types": "./generated/index.d.ts",
78
96
  "default": "./generated/index.js"
@@ -94,27 +112,27 @@
94
112
  "devDependencies": {
95
113
  "@type-challenges/utils": "^0.1.1",
96
114
  "@types/semver": "^7.8.0",
97
- "tsdown": "^0.22.14",
98
- "tsx": "^4.23.12",
115
+ "tsdown": "^0.23.0",
116
+ "tsx": "^4.23.13",
99
117
  "typedoc": "^0.28.20",
100
118
  "typescript": "npm:@typescript/typescript6@^6.0.2",
101
119
  "vitest": "^4.1.11",
102
- "zod": "^4.4.3"
120
+ "zod": "^4.5.4"
103
121
  },
104
122
  "peerDependencies": {
105
123
  "zod": ">=3.25.76 <5"
106
124
  },
107
125
  "dependencies": {
108
- "@composio/client": "2.0.0-rc.6",
126
+ "@composio/client": "2.0.0-rc.7",
109
127
  "@types/json-schema": "^7.0.15",
110
128
  "is-fs-case-sensitive": "^2.0.0",
111
- "openai": "^7.2.0",
129
+ "openai": "^7.10.0",
112
130
  "picocolors": "^1.1.1",
113
131
  "pusher-js": "^8.6.0",
114
132
  "semver": "^7.8.5",
115
133
  "undici": "^7.29.0",
116
134
  "zod-to-json-schema": "^3.25.2",
117
- "@composio/json-schema-to-zod": "0.3.0"
135
+ "@composio/json-schema-to-zod": "0.3.3-beta.0"
118
136
  },
119
137
  "gitHead": "4fae6e54d5c150fba955cc5fa314281da5a1e064",
120
138
  "repository": {