@composio/core 0.18.0 → 0.19.0

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 (62) hide show
  1. package/dist/{CustomTool-C4tv-GL1.mjs → CustomTool-BMlZfJVz.mjs} +16 -6
  2. package/dist/{CustomTool-BKhHv2hJ.d.mts → CustomTool-CB5vm1Jc.d.mts} +1 -1
  3. package/dist/{FileModifierErrors-B8V8_3VE.mjs → FileModifierErrors-BqFmpRsm.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-C91YhASE.mjs} +137 -13
  6. package/dist/{Telemetry-CBtSnWrm.mjs → Telemetry-HlftxMx6.mjs} +2 -34
  7. package/dist/{cancellation-jUVItfHw.mjs → cancellation-CXpfmiVo.mjs} +7 -5
  8. package/dist/{composio-CldtZUyC.d.mts → composio-DLGaeN70.d.mts} +333 -32
  9. package/dist/{customTool.types-DC5fPOOi.d.mts → customTool.types-BAmEh3MB.d.mts} +131 -38
  10. package/dist/docs/reference/sdk-reference/typescript/auth-configs.mdx +2 -2
  11. package/dist/docs/reference/sdk-reference/typescript/composio.mdx +3 -13
  12. package/dist/docs/reference/sdk-reference/typescript/session.mdx +50 -6
  13. package/dist/docs/reference/sdk-reference/typescript/toolkits.mdx +4 -4
  14. package/dist/docs/reference/sdk-reference/typescript/tools.mdx +33 -23
  15. package/dist/docs/reference/sdk-reference/typescript/triggers.mdx +3 -2
  16. package/dist/{errors-DyZt79fi.mjs → errors-BuEKehbI.mjs} +23 -3
  17. package/dist/experimental/index.d.mts +2 -2
  18. package/dist/experimental/index.mjs +1 -1
  19. package/dist/{fileUtils.node-BwpUOF0s.mjs → fileUtils.node-L7XD8UPr.mjs} +11 -9
  20. package/dist/index.d.mts +164 -104
  21. package/dist/index.mjs +382 -153
  22. package/dist/models/Files.node.d.mts +2 -3
  23. package/dist/models/Files.node.mjs +2 -2
  24. package/dist/models/Files.workerd.d.mts +2 -3
  25. package/dist/platform/node.d.mts +2 -3
  26. package/dist/platform/workerd.d.mts +2 -3
  27. package/dist/{sensitiveFileUploadPaths-B0w8dqpv.mjs → sensitiveFileUploadPaths-B6pBt9lO.mjs} +10 -7
  28. package/dist/{ssrfGuard.node-DlxO8uzr.mjs → ssrfGuard.node-B9xQB4za.mjs} +197 -30
  29. package/dist/{types-BgsRW-XH.d.mts → types-CxLPO0Xq.d.mts} +2 -2
  30. package/dist/utils/config-defaults/ConfigDefaults.node.d.mts +3 -4
  31. package/dist/utils/config-defaults/ConfigDefaults.workerd.d.mts +3 -4
  32. package/dist/utils/modifiers/FileToolModifier.node.d.mts +3 -4
  33. package/dist/utils/modifiers/FileToolModifier.node.mjs +6 -6
  34. package/dist/utils/modifiers/FileToolModifier.workerd.d.mts +3 -4
  35. package/dist/utils/modifiers/FileToolModifier.workerd.mjs +1 -1
  36. package/dist/utils/ssrfGuard.node.d.mts +19 -10
  37. package/dist/utils/ssrfGuard.node.mjs +1 -1
  38. package/dist/utils/ssrfGuard.workerd.d.mts +12 -4
  39. package/dist/utils/ssrfGuard.workerd.mjs +2 -2
  40. package/package.json +26 -8
  41. package/src/errors/ToolErrors.ts +24 -0
  42. package/src/index.ts +4 -0
  43. package/src/models/CustomTool.ts +41 -6
  44. package/src/models/MCP.ts +29 -15
  45. package/src/models/RemoteFile.ts +54 -36
  46. package/src/models/ToolRouter.ts +1 -0
  47. package/src/models/ToolRouterSession.ts +115 -13
  48. package/src/models/Toolkits.ts +1 -2
  49. package/src/models/Tools.ts +55 -25
  50. package/src/models/Triggers.ts +22 -2
  51. package/src/services/pusher/Pusher.ts +29 -10
  52. package/src/telemetry/redact.ts +133 -6
  53. package/src/types/toolRouter.types.ts +54 -3
  54. package/src/types/toolkit.types.ts +17 -0
  55. package/src/utils/fileUtils.node.ts +10 -2
  56. package/src/utils/jsonSchema.ts +4 -1
  57. package/src/utils/logger.ts +6 -6
  58. package/src/utils/pinnedDispatcher.node.ts +109 -13
  59. package/src/utils/sdk.ts +1 -1
  60. package/src/utils/ssrfGuard.node.ts +153 -27
  61. package/src/utils/ssrfGuard.workerd.ts +15 -1
  62. package/src/utils/transformers/toolkits.ts +79 -2
@@ -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-CBtSnWrm.mjs";
2
- import { n as getFileDataAfterUploadingToS3, t as downloadFileFromS3 } from "../fileUtils.node-BwpUOF0s.mjs";
1
+ import { t as telemetry } from "../Telemetry-HlftxMx6.mjs";
2
+ import { n as getFileDataAfterUploadingToS3, t as downloadFileFromS3 } from "../fileUtils.node-L7XD8UPr.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-BqFmpRsm.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-C91YhASE.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
  *
@@ -117,29 +187,106 @@ const hasCustomGlobalDispatcher = () => {
117
187
  * to a public address during validation and rebind to an internal one before
118
188
  * the connect — a TOCTOU window the Python guard closes the same way.
119
189
  *
120
- * Residual: a hop whose effective dispatcher is a configured route — a
190
+ * By default, 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
127
- * the same reason (`_proxy_applies`).
198
+ * the same reason (`_proxy_applies`). Callers that cannot accept that residual
199
+ * can set `requirePinnedConnection`, which fails closed before fetching.
128
200
  */
129
201
  const MAX_REDIRECTS = 5;
130
202
  /**
203
+ * The Fetch standard's "redirect status" set. A 3xx outside it is not a
204
+ * redirect to follow even when it carries a `location` — `304 Not Modified`
205
+ * and `305 Use Proxy` most of all, and following those would replay the
206
+ * request against a target the caller never asked for. The Python guard
207
+ * follows the same set (`_REDIRECT_STATUS_CODES`).
208
+ */
209
+ const REDIRECT_STATUS_CODES = /* @__PURE__ */ new Set([
210
+ 301,
211
+ 302,
212
+ 303,
213
+ 307,
214
+ 308
215
+ ]);
216
+ /**
217
+ * Headers that describe a request body, so they have to go when the body does:
218
+ * the Fetch standard's "request-body-header name" set, plus the two the Python
219
+ * guard also drops because `requests` recomputes them from the body it sends.
220
+ */
221
+ const BODY_HEADERS = [
222
+ "content-encoding",
223
+ "content-language",
224
+ "content-length",
225
+ "content-location",
226
+ "content-type",
227
+ "transfer-encoding"
228
+ ];
229
+ /**
230
+ * The method the hop after a redirect uses, or `null` to replay as-is. A
231
+ * returned method also means the request body goes.
232
+ *
233
+ * These are the Fetch standard's redirect rules, which following redirects by
234
+ * hand (`redirect: 'manual'`) means `fetch` never applies for us: `303` points
235
+ * at a result URL that has no use for the original body, so every method loses
236
+ * it and everything but `HEAD` becomes a `GET`; `301`/`302` do the same to a
237
+ * `POST` only; `307`/`308` replay both. Without this, a `303` answering an
238
+ * upload would PUT the payload again at a URL that expects a GET. The Python
239
+ * guard applies the same rules in `safe_request`.
240
+ */
241
+ const redirectRewrite = (status, method) => {
242
+ if (status === 303) return method === "HEAD" ? "HEAD" : "GET";
243
+ if ((status === 301 || status === 302) && method === "POST") return "GET";
244
+ return null;
245
+ };
246
+ /**
247
+ * Headers that carry a credential for the origin the request was addressed
248
+ * to, so they must not follow a redirect to a different origin. The Fetch
249
+ * standard strips `Authorization` on a cross-origin redirect; `Cookie` and
250
+ * `Proxy-Authorization` go with it the way `requests` and curl drop them on a
251
+ * host change. `redirect: 'manual'` means `fetch` never applies that rule for
252
+ * us either. The Python guard drops the same three (`_CREDENTIAL_HEADERS`).
253
+ */
254
+ const CREDENTIAL_HEADERS = [
255
+ "authorization",
256
+ "cookie",
257
+ "proxy-authorization"
258
+ ];
259
+ const applyRedirectSemantics = (init, status, fromUrl, toUrl) => {
260
+ const method = redirectRewrite(status, (init.method ?? "GET").toUpperCase());
261
+ const crossOrigin = new URL(fromUrl).origin !== new URL(toUrl).origin;
262
+ if (method === null && !crossOrigin) return init;
263
+ const headers = new Headers(init.headers);
264
+ if (method !== null) for (const name of BODY_HEADERS) headers.delete(name);
265
+ if (crossOrigin) for (const name of CREDENTIAL_HEADERS) headers.delete(name);
266
+ if (method === null) return {
267
+ ...init,
268
+ headers
269
+ };
270
+ return {
271
+ ...init,
272
+ method,
273
+ body: void 0,
274
+ headers
275
+ };
276
+ };
277
+ /**
131
278
  * 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.
279
+ * see into. Bun honors proxy environment variables automatically. Node's
280
+ * built-in `fetch` requires the `NODE_USE_ENV_PROXY` opt-in (Node >= 24), so
281
+ * a bare env-var check on Node would drop pinning for users whose fetch never
282
+ * proxied.
136
283
  *
137
284
  * `NO_PROXY=*` is the one bypass honored precisely (nothing is proxied, so
138
285
  * pinning is safe again); per-host `NO_PROXY` entries are treated
139
286
  * conservatively as proxied rather than parsed.
140
287
  */
141
- const envProxyApplies = (url) => {
142
- if (!["1", "true"].includes((process.env.NODE_USE_ENV_PROXY ?? "").toLowerCase())) return false;
288
+ const envProxyApplies = (url, isBun) => {
289
+ if (!(isBun || ["1", "true"].includes((process.env.NODE_USE_ENV_PROXY ?? "").toLowerCase()))) return false;
143
290
  if ((process.env.NO_PROXY ?? process.env.no_proxy ?? "") === "*") return false;
144
291
  const schemeVar = url.protocol === "https:" ? "HTTPS_PROXY" : "HTTP_PROXY";
145
292
  return Boolean(process.env[schemeVar] ?? process.env[schemeVar.toLowerCase()]);
@@ -157,6 +304,7 @@ const IPV4_BLOCKED_CIDRS = [
157
304
  ["172.16.0.0", 12],
158
305
  ["192.0.0.0", 24],
159
306
  ["192.0.2.0", 24],
307
+ ["192.88.99.0", 24],
160
308
  ["192.168.0.0", 16],
161
309
  ["198.18.0.0", 15],
162
310
  ["198.51.100.0", 24],
@@ -205,8 +353,14 @@ const isBlockedIpv6 = (ip) => {
205
353
  const isMappedOrCompat = h[0] === 0 && h[1] === 0 && h[2] === 0 && h[3] === 0 && h[4] === 0 && (h[5] === 65535 || h[5] === 0);
206
354
  const isNat64 = h[0] === 100 && h[1] === 65435 && h[2] === 0 && h[3] === 0 && h[4] === 0 && h[5] === 0;
207
355
  if (isMappedOrCompat || isNat64) return isBlockedIpv4Long((h[6] << 16 >>> 0 | h[7]) >>> 0);
356
+ if (h[0] === 8193 && (h[1] & 65024) === 0) return true;
357
+ if (h[0] === 8193 && h[1] === 3512) return true;
358
+ if (h[0] === 8194) return true;
359
+ if (h[0] === 100 && h[1] === 65435 && h[2] === 1) return true;
360
+ if (h[0] === 256 && h[1] === 0 && h[2] === 0 && h[3] === 0) return true;
208
361
  if ((h[0] & 65024) === 64512) return true;
209
362
  if ((h[0] & 65472) === 65152) return true;
363
+ if ((h[0] & 65472) === 65216) return true;
210
364
  if ((h[0] & 65280) === 65280) return true;
211
365
  return false;
212
366
  };
@@ -260,24 +414,35 @@ const assertSafeFetchTarget = async (rawUrl) => {
260
414
  * connects to the address it validated, and re-validates and re-pins every
261
415
  * redirect hop (redirects are followed manually up to {@link MAX_REDIRECTS}).
262
416
  * Intermediate redirect bodies are cancelled; non-redirect responses are
263
- * returned unchanged.
417
+ * returned unchanged. Each hop carries the method, body, and credential headers
418
+ * the Fetch standard says it should — see {@link applyRedirectSemantics}.
264
419
  *
265
- * A hop whose effective dispatcher is a configured route (caller-supplied
266
- * `init.dispatcher`, non-stock global dispatcher, env-proxy mode) is *not*
267
- * pinned — see the module residual above.
420
+ * By default, a hop whose effective dispatcher is a configured route
421
+ * (caller-supplied `init.dispatcher`, non-stock global dispatcher, env-proxy
422
+ * mode) is *not* pinned. Set `requirePinnedConnection` to fail closed instead.
268
423
  */
269
- const ssrfSafeFetch = async (rawUrl, init = {}, maxRedirects = MAX_REDIRECTS) => {
424
+ const ssrfSafeFetch = async (rawUrl, init = {}, optionsOrMaxRedirects = {}) => {
425
+ const options = typeof optionsOrMaxRedirects === "number" ? { maxRedirects: optionsOrMaxRedirects } : optionsOrMaxRedirects;
426
+ const maxRedirects = options.maxRedirects ?? MAX_REDIRECTS;
270
427
  let currentUrl = rawUrl;
428
+ let currentInit = init;
271
429
  for (let hop = 0; hop <= maxRedirects; hop++) {
272
430
  const addresses = await assertSafeFetchTarget(currentUrl);
273
- const dispatcher = init.dispatcher !== void 0 || envProxyApplies(new URL(currentUrl)) || hasCustomGlobalDispatcher() ? void 0 : await createPinnedDispatcher(addresses);
431
+ const isBun = typeof process.versions.bun === "string";
432
+ const respectConfiguredRoute = currentInit.dispatcher !== void 0 || envProxyApplies(new URL(currentUrl), isBun) || hasCustomGlobalDispatcher();
433
+ if (options.requirePinnedConnection && respectConfiguredRoute) throw new ComposioBlockedInternalUrlError("Refusing to fetch through a configured network route because the validated address cannot be pinned", { url: currentUrl });
434
+ const dispatcher = respectConfiguredRoute || isBun ? void 0 : await createPinnedDispatcher(addresses);
274
435
  let response;
275
436
  try {
276
- response = await fetch(currentUrl, dispatcher === void 0 ? {
277
- ...init,
437
+ if (isBun && !respectConfiguredRoute) response = await pinnedHttpFetch(currentUrl, {
438
+ ...currentInit,
439
+ redirect: "manual"
440
+ }, addresses);
441
+ else response = await fetch(currentUrl, dispatcher === void 0 ? {
442
+ ...currentInit,
278
443
  redirect: "manual"
279
444
  } : {
280
- ...init,
445
+ ...currentInit,
281
446
  redirect: "manual",
282
447
  dispatcher
283
448
  });
@@ -286,9 +451,11 @@ const ssrfSafeFetch = async (rawUrl, init = {}, maxRedirects = MAX_REDIRECTS) =>
286
451
  throw error;
287
452
  }
288
453
  if (dispatcher !== void 0) dispatcher.close().catch(() => void 0);
289
- if (!(response.status >= 300 && response.status < 400 && response.headers.has("location"))) return response;
454
+ if (!(REDIRECT_STATUS_CODES.has(response.status) && response.headers.has("location"))) return response;
290
455
  await response.body?.cancel().catch(() => void 0);
291
- currentUrl = new URL(response.headers.get("location"), currentUrl).toString();
456
+ const nextUrl = new URL(response.headers.get("location"), currentUrl).toString();
457
+ currentInit = applyRedirectSemantics(currentInit, response.status, currentUrl, nextUrl);
458
+ currentUrl = nextUrl;
292
459
  }
293
460
  throw new ComposioBlockedInternalUrlError(`Refusing to fetch: too many redirects (max ${maxRedirects})`, { url: rawUrl });
294
461
  };
@@ -1,5 +1,5 @@
1
- import { Mn as BaseComposioProvider } from "./customTool.types-DC5fPOOi.mjs";
2
- import { n as ComposioConfig } from "./composio-CldtZUyC.mjs";
1
+ import { Ln as BaseComposioProvider } from "./customTool.types-BAmEh3MB.mjs";
2
+ import { n as ComposioConfig } from "./composio-DLGaeN70.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-BgsRW-XH.mjs";
1
+ import { t as ConfigDefaults } from "../../types-CxLPO0Xq.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-BgsRW-XH.mjs";
1
+ import { t as ConfigDefaults } from "../../types-CxLPO0Xq.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-DC5fPOOi.mjs";
1
+ import { $i as Tool, ia as ToolExecuteResponse, na as ToolExecuteParams } from "../../customTool.types-BAmEh3MB.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-DyZt79fi.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-jUVItfHw.mjs";
6
- import { n as getFileDataAfterUploadingToS3, r as isHttpUrl, t as downloadFileFromS3 } from "../../fileUtils.node-BwpUOF0s.mjs";
1
+ import { i as logger } from "../../SsrfErrors-C91YhASE.mjs";
2
+ import { f as ComposioRequestCancelledError } from "../../errors-BuEKehbI.mjs";
3
+ import { a as ComposioSensitiveFilePathBlockedError, i as ComposioFileUploadPathNotAllowedError, n as ComposioFileUploadAbortedError, r as ComposioFileUploadError, t as ComposioFileNotFoundError } from "../../FileModifierErrors-BqFmpRsm.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-CXpfmiVo.mjs";
6
+ import { n as getFileDataAfterUploadingToS3, r as isHttpUrl, t as downloadFileFromS3 } from "../../fileUtils.node-L7XD8UPr.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-DC5fPOOi.mjs";
1
+ import { $i as Tool, ia as ToolExecuteResponse, na as ToolExecuteParams } from "../../customTool.types-BAmEh3MB.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).";
@@ -1,10 +1,19 @@
1
1
  //#region src/utils/ssrfGuard.node.d.ts
2
+ export interface SsrfSafeFetchOptions {
3
+ /** Maximum number of redirects to follow. Defaults to 5. */
4
+ maxRedirects?: number;
5
+ /**
6
+ * Refuse a request when a configured dispatcher or environment proxy means
7
+ * the connection cannot be pinned to the address validated by the guard.
8
+ */
9
+ requirePinnedConnection?: boolean;
10
+ }
2
11
  /**
3
12
  * True when `ip` is a private, loopback, link-local, or otherwise
4
13
  * non-publicly-routable address. Fails closed (returns `true`) for anything that
5
14
  * is not a valid IPv4/IPv6 literal.
6
15
  */
7
- declare const isBlockedIp: (ip: string) => boolean;
16
+ export declare const isBlockedIp: (ip: string) => boolean;
8
17
  /**
9
18
  * Validate a single URL: it must be http(s), its host must resolve, and every
10
19
  * resolved address must be publicly routable. Throws
@@ -14,19 +23,20 @@ declare const isBlockedIp: (ip: string) => boolean;
14
23
  * must connect to *those* rather than let the client resolve the hostname
15
24
  * again; see {@link ssrfSafeFetch}.
16
25
  */
17
- declare const assertSafeFetchTarget: (rawUrl: string) => Promise<string[]>;
26
+ export declare const assertSafeFetchTarget: (rawUrl: string) => Promise<string[]>;
18
27
  /**
19
28
  * Drop-in replacement for `fetch` that blocks SSRF. Validates the target, then
20
29
  * connects to the address it validated, and re-validates and re-pins every
21
30
  * redirect hop (redirects are followed manually up to {@link MAX_REDIRECTS}).
22
31
  * Intermediate redirect bodies are cancelled; non-redirect responses are
23
- * returned unchanged.
32
+ * returned unchanged. Each hop carries the method, body, and credential headers
33
+ * the Fetch standard says it should — see {@link applyRedirectSemantics}.
24
34
  *
25
- * A hop whose effective dispatcher is a configured route (caller-supplied
26
- * `init.dispatcher`, non-stock global dispatcher, env-proxy mode) is *not*
27
- * pinned — see the module residual above.
35
+ * By default, a hop whose effective dispatcher is a configured route
36
+ * (caller-supplied `init.dispatcher`, non-stock global dispatcher, env-proxy
37
+ * mode) is *not* pinned. Set `requirePinnedConnection` to fail closed instead.
28
38
  */
29
- declare const ssrfSafeFetch: (rawUrl: string, init?: RequestInit, maxRedirects?: number) => Promise<Response>;
39
+ export declare const ssrfSafeFetch: (rawUrl: string, init?: RequestInit, optionsOrMaxRedirects?: SsrfSafeFetchOptions | number) => Promise<Response>;
30
40
  /**
31
41
  * {@link ssrfSafeFetch} for call sites that must keep working on every runtime.
32
42
  *
@@ -36,6 +46,5 @@ declare const ssrfSafeFetch: (rawUrl: string, init?: RequestInit, maxRedirects?:
36
46
  * feature from Workers rather than close a hole reachable there. On Node this
37
47
  * is the full guard; only the edge build differs.
38
48
  */
39
- declare const ssrfSafeFetchWhereSupported: (rawUrl: string, init?: RequestInit, maxRedirects?: number) => Promise<Response>;
40
- //#endregion
41
- export { assertSafeFetchTarget, isBlockedIp, ssrfSafeFetch, ssrfSafeFetchWhereSupported };
49
+ export declare const ssrfSafeFetchWhereSupported: (rawUrl: string, init?: RequestInit, optionsOrMaxRedirects?: SsrfSafeFetchOptions | number) => Promise<Response>;
50
+ //#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-B9xQB4za.mjs";
2
2
 
3
3
  export { assertSafeFetchTarget, isBlockedIp, ssrfSafeFetch, ssrfSafeFetchWhereSupported };
@@ -1,10 +1,19 @@
1
1
  //#region src/utils/ssrfGuard.workerd.d.ts
2
+ export interface SsrfSafeFetchOptions {
3
+ /** Maximum number of redirects to follow. Defaults to 5. */
4
+ maxRedirects?: number;
5
+ /**
6
+ * Refuse a request when a configured dispatcher or environment proxy means
7
+ * the connection cannot be pinned to the address validated by the guard.
8
+ */
9
+ requirePinnedConnection?: boolean;
10
+ }
2
11
  /**
3
12
  * Edge runtimes do not expose the DNS resolution APIs needed to prove that a
4
13
  * hostname is publicly routable before connecting. Fail closed instead of
5
14
  * falling back to an unguarded fetch.
6
15
  */
7
- declare const ssrfSafeFetch: (rawUrl: string) => Promise<Response>;
16
+ export declare const ssrfSafeFetch: (rawUrl: string, _init?: RequestInit, _optionsOrMaxRedirects?: SsrfSafeFetchOptions | number) => Promise<Response>;
8
17
  /**
9
18
  * Unguarded `fetch`, for the call sites that must keep working here.
10
19
  *
@@ -16,6 +25,5 @@ declare const ssrfSafeFetch: (rawUrl: string) => Promise<Response>;
16
25
  * check, and its `fetch` does not originate inside the caller's network. The
17
26
  * Node build applies the full guard.
18
27
  */
19
- declare const ssrfSafeFetchWhereSupported: (rawUrl: string, init?: RequestInit) => Promise<Response>;
20
- //#endregion
21
- export { ssrfSafeFetch, ssrfSafeFetchWhereSupported };
28
+ export declare const ssrfSafeFetchWhereSupported: (rawUrl: string, init?: RequestInit) => Promise<Response>;
29
+ //#endregion
@@ -1,4 +1,4 @@
1
- import { t as ComposioBlockedInternalUrlError } from "../SsrfErrors-DNJt57GL.mjs";
1
+ import { t as ComposioBlockedInternalUrlError } from "../SsrfErrors-C91YhASE.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 = {}, _optionsOrMaxRedirects = {}) => {
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"]