@composio/core 0.17.0 → 1.0.0-beta.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 (31) hide show
  1. package/dist/{CustomTool-Uip-fhPw.d.mts → CustomTool-CwpeQhz2.d.mts} +1 -1
  2. package/dist/FileToolModifier.utils.neutral-D_YkHwZP.mjs +188 -0
  3. package/dist/{Telemetry-DuGJSwUt.mjs → Telemetry-DK1uAWnD.mjs} +1 -1
  4. package/dist/{cancellation-NVtGf3St.mjs → cancellation-C-qy8rcj.mjs} +1 -1
  5. package/dist/{composio-B27X6i6A.d.mts → composio-XjF7EMEe.d.mts} +256 -250
  6. package/dist/{customTool.types-B2Ava_j5.d.mts → customTool.types-DpJbYY5m.d.mts} +167 -167
  7. package/dist/experimental/index.d.mts +2 -2
  8. package/dist/{fileUtils.node-B1Wn848p.mjs → fileUtils.node-BwpUOF0s.mjs} +2 -2
  9. package/dist/index.d.mts +6 -5
  10. package/dist/index.mjs +58 -24
  11. package/dist/models/Files.node.mjs +2 -2
  12. package/dist/{sensitiveFileUploadPaths-BVEt0peg.mjs → sensitiveFileUploadPaths-B0w8dqpv.mjs} +23 -6
  13. package/dist/ssrfGuard.node-DlxO8uzr.mjs +307 -0
  14. package/dist/{types-DdZJuMm2.d.mts → types-C9kJAurw.d.mts} +2 -2
  15. package/dist/utils/config-defaults/ConfigDefaults.node.d.mts +1 -1
  16. package/dist/utils/config-defaults/ConfigDefaults.workerd.d.mts +1 -1
  17. package/dist/utils/modifiers/FileToolModifier.node.d.mts +1 -1
  18. package/dist/utils/modifiers/FileToolModifier.node.mjs +56 -100
  19. package/dist/utils/modifiers/FileToolModifier.workerd.d.mts +1 -1
  20. package/dist/utils/modifiers/FileToolModifier.workerd.mjs +1 -1
  21. package/dist/utils/ssrfGuard.node.d.mts +14 -5
  22. package/dist/utils/ssrfGuard.node.mjs +1 -161
  23. package/package.json +7 -3
  24. package/src/models/ToolRouterSession.ts +36 -8
  25. package/src/models/Tools.ts +102 -39
  26. package/src/utils/modifiers/FileToolModifier.node.ts +85 -181
  27. package/src/utils/modifiers/FileToolModifier.utils.neutral.ts +199 -0
  28. package/src/utils/pinnedDispatcher.node.ts +118 -0
  29. package/src/utils/sensitiveFileUploadPaths.ts +36 -9
  30. package/src/utils/ssrfGuard.node.ts +89 -11
  31. package/dist/FileToolModifier.utils.neutral-B5rT711M.mjs +0 -72
@@ -1,4 +1,4 @@
1
- import { t as ConfigDefaults } from "../../types-DdZJuMm2.mjs";
1
+ import { t as ConfigDefaults } from "../../types-C9kJAurw.mjs";
2
2
  //#region src/utils/config-defaults/ConfigDefaults.node.d.ts
3
3
  declare const CONFIG_DEFAULTS: ConfigDefaults;
4
4
  //#endregion
@@ -1,4 +1,4 @@
1
- import { t as ConfigDefaults } from "../../types-DdZJuMm2.mjs";
1
+ import { t as ConfigDefaults } from "../../types-C9kJAurw.mjs";
2
2
  //#region src/utils/config-defaults/ConfigDefaults.workerd.d.ts
3
3
  declare const CONFIG_DEFAULTS: ConfigDefaults;
4
4
  //#endregion
@@ -1,4 +1,4 @@
1
- import { $i as ToolExecuteResponse, Ji as Tool, Zi as ToolExecuteParams } from "../../customTool.types-B2Ava_j5.mjs";
1
+ import { $i as ToolExecuteResponse, Ji as Tool, Zi as ToolExecuteParams } from "../../customTool.types-DpJbYY5m.mjs";
2
2
  import ComposioClient from "@composio/client";
3
3
  //#region src/utils/modifiers/FileToolModifier.node.d.ts
4
4
  declare class FileToolModifier {
@@ -1,9 +1,9 @@
1
1
  import { i as logger } from "../../SsrfErrors-DNJt57GL.mjs";
2
2
  import { f as ComposioRequestCancelledError } from "../../errors-BcEUHZbq.mjs";
3
3
  import { a as ComposioSensitiveFilePathBlockedError, i as ComposioFileUploadPathNotAllowedError, n as ComposioFileUploadAbortedError, r as ComposioFileUploadError, t as ComposioFileNotFoundError } from "../../FileModifierErrors-B8V8_3VE.mjs";
4
- import { i as transformProperties, n as schemaHasFileProperty, t as isPlainObject } from "../../FileToolModifier.utils.neutral-B5rT711M.mjs";
5
- import { r as dereferenceJsonSchema, t as withCancellation } from "../../cancellation-NVtGf3St.mjs";
6
- import { n as getFileDataAfterUploadingToS3, r as isHttpUrl, t as downloadFileFromS3 } from "../../fileUtils.node-B1Wn848p.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";
7
7
 
8
8
  //#region src/utils/modifiers/FileToolModifier.node.ts
9
9
  /**
@@ -17,61 +17,50 @@ import { n as getFileDataAfterUploadingToS3, r as isHttpUrl, t as downloadFileFr
17
17
  * https://github.com/ComposioHQ/composio/issues/3307) instead of throwing.
18
18
  */
19
19
  const resolveFileSchema = (schema) => schema ? dereferenceJsonSchema(schema, { onUnresolved: "sentinel" }) : schema;
20
- const getSchemaVariants = (schema) => [
21
- ...schema?.anyOf ?? [],
22
- ...schema?.oneOf ?? [],
23
- ...schema?.allOf ?? []
24
- ];
25
- const jsonSchemaTypeMatchesValue = (schema, value) => {
26
- const schemaType = schema.type;
27
- if (Array.isArray(schemaType)) return schemaType.some((type) => jsonSchemaTypeMatchesValue({
28
- ...schema,
29
- type
30
- }, value));
31
- if (schemaType === void 0) {
32
- if (schema.properties) return isPlainObject(value);
33
- if (schema.items) return Array.isArray(value);
34
- return false;
35
- }
36
- switch (schemaType) {
37
- case "array": return Array.isArray(value);
38
- case "object": return isPlainObject(value);
39
- case "string": return typeof value === "string";
40
- case "integer": return Number.isInteger(value);
41
- case "number": return typeof value === "number";
42
- case "boolean": return typeof value === "boolean";
43
- case "null": return value === null;
44
- default: return false;
45
- }
46
- };
47
- const findSchemaVariantWithFileProperty = (schema, property, value) => {
48
- const candidates = getSchemaVariants(schema).filter((variant) => schemaHasFileProperty(variant, property));
49
- return candidates.find((candidate) => jsonSchemaTypeMatchesValue(candidate, value)) ?? candidates[0];
50
- };
51
20
  /**
52
- * Recursively walks a runtime value and its matching JSON-Schema node,
53
- * uploading any string path whose schema node has `file_uploadable: true`.
54
- * The function returns a **new** value with all substitutions applied;
55
- * nothing is mutated in-place.
21
+ * Stages one `file_uploadable` leaf: a local path / URL string or a `File`
22
+ * is uploaded to S3 and replaced by its `{ name, mimetype, s3key }`
23
+ * descriptor; `''` means "no file" and is dropped from the request;
24
+ * anything else (e.g. an already-staged descriptor) passes through.
56
25
  */
57
- const hydrateFiles = async (value, schema, ctx) => {
58
- if (schema?.file_uploadable) {
59
- if (typeof value !== "string" && !(value instanceof File)) return value;
60
- const runBeforeFileUpload = async (path, source) => {
61
- if (!ctx.beforeFileUpload) return path;
62
- const out = await ctx.beforeFileUpload({
63
- path,
64
- source,
65
- toolSlug: ctx.toolSlug,
66
- toolkitSlug: ctx.toolkitSlug
67
- });
68
- if (out === false) throw new ComposioFileUploadAbortedError("File upload was aborted because beforeFileUpload returned false.");
69
- return out;
70
- };
71
- if (typeof value === "string") {
72
- const pathOrUrl = await runBeforeFileUpload(value, isHttpUrl(value) ? "url" : "path");
73
- logger.debug(`Uploading file "${pathOrUrl}"`);
74
- return getFileDataAfterUploadingToS3(pathOrUrl, {
26
+ const stageFileValue = async (value, ctx) => {
27
+ if (isEmptyFileValue(value)) return DELETE_VALUE;
28
+ if (typeof value !== "string" && !(value instanceof File)) return value;
29
+ const runBeforeFileUpload = async (path, source) => {
30
+ if (!ctx.beforeFileUpload) return path;
31
+ const out = await ctx.beforeFileUpload({
32
+ path,
33
+ source,
34
+ toolSlug: ctx.toolSlug,
35
+ toolkitSlug: ctx.toolkitSlug
36
+ });
37
+ if (out === false) throw new ComposioFileUploadAbortedError("File upload was aborted because beforeFileUpload returned false.");
38
+ return out;
39
+ };
40
+ if (typeof value === "string") {
41
+ const pathOrUrl = await runBeforeFileUpload(value, isHttpUrl(value) ? "url" : "path");
42
+ logger.debug(`Uploading file "${pathOrUrl}"`);
43
+ return getFileDataAfterUploadingToS3(pathOrUrl, {
44
+ toolSlug: ctx.toolSlug,
45
+ toolkitSlug: ctx.toolkitSlug,
46
+ client: ctx.client,
47
+ sensitiveFileUploadProtection: ctx.sensitiveFileUploadProtection,
48
+ fileUploadPathDenySegments: ctx.fileUploadPathDenySegments,
49
+ fileUploadAllowlist: ctx.fileUploadAllowlist,
50
+ signal: ctx.signal
51
+ });
52
+ }
53
+ if (ctx.beforeFileUpload) {
54
+ const out = await ctx.beforeFileUpload({
55
+ path: value.name,
56
+ source: "file",
57
+ toolSlug: ctx.toolSlug,
58
+ toolkitSlug: ctx.toolkitSlug
59
+ });
60
+ if (out === false) throw new ComposioFileUploadAbortedError("File upload was aborted because beforeFileUpload returned false.");
61
+ if (typeof out === "string" && out !== value.name) {
62
+ logger.debug(`Uploading file from path "${out}" (replaced File: ${value.name})`);
63
+ return getFileDataAfterUploadingToS3(out, {
75
64
  toolSlug: ctx.toolSlug,
76
65
  toolkitSlug: ctx.toolkitSlug,
77
66
  client: ctx.client,
@@ -81,49 +70,16 @@ const hydrateFiles = async (value, schema, ctx) => {
81
70
  signal: ctx.signal
82
71
  });
83
72
  }
84
- if (ctx.beforeFileUpload) {
85
- const out = await ctx.beforeFileUpload({
86
- path: value.name,
87
- source: "file",
88
- toolSlug: ctx.toolSlug,
89
- toolkitSlug: ctx.toolkitSlug
90
- });
91
- if (out === false) throw new ComposioFileUploadAbortedError("File upload was aborted because beforeFileUpload returned false.");
92
- if (typeof out === "string" && out !== value.name) {
93
- logger.debug(`Uploading file from path "${out}" (replaced File: ${value.name})`);
94
- return getFileDataAfterUploadingToS3(out, {
95
- toolSlug: ctx.toolSlug,
96
- toolkitSlug: ctx.toolkitSlug,
97
- client: ctx.client,
98
- sensitiveFileUploadProtection: ctx.sensitiveFileUploadProtection,
99
- fileUploadPathDenySegments: ctx.fileUploadPathDenySegments,
100
- fileUploadAllowlist: ctx.fileUploadAllowlist,
101
- signal: ctx.signal
102
- });
103
- }
104
- }
105
- logger.debug(`Uploading file "${value.name}"`);
106
- return getFileDataAfterUploadingToS3(value, {
107
- toolSlug: ctx.toolSlug,
108
- toolkitSlug: ctx.toolkitSlug,
109
- client: ctx.client,
110
- sensitiveFileUploadProtection: ctx.sensitiveFileUploadProtection,
111
- fileUploadPathDenySegments: ctx.fileUploadPathDenySegments,
112
- signal: ctx.signal
113
- });
114
- }
115
- const uploadableVariant = findSchemaVariantWithFileProperty(schema, "file_uploadable", value);
116
- if (uploadableVariant) return hydrateFiles(value, uploadableVariant, ctx);
117
- if (schema?.type === "object" && schema.properties && isPlainObject(value)) {
118
- const transformed = {};
119
- for (const [k, v] of Object.entries(value)) transformed[k] = await hydrateFiles(v, schema.properties[k], ctx);
120
- return transformed;
121
73
  }
122
- if (schema?.type === "array" && schema.items && Array.isArray(value)) {
123
- const itemSchema = Array.isArray(schema.items) ? schema.items[0] : schema.items;
124
- return Promise.all(value.map((item) => hydrateFiles(item, itemSchema, ctx)));
125
- }
126
- return value;
74
+ logger.debug(`Uploading file "${value.name}"`);
75
+ return getFileDataAfterUploadingToS3(value, {
76
+ toolSlug: ctx.toolSlug,
77
+ toolkitSlug: ctx.toolkitSlug,
78
+ client: ctx.client,
79
+ sensitiveFileUploadProtection: ctx.sensitiveFileUploadProtection,
80
+ fileUploadPathDenySegments: ctx.fileUploadPathDenySegments,
81
+ signal: ctx.signal
82
+ });
127
83
  };
128
84
  /**
129
85
  * Downloads a file from S3 and returns a replacement object.
@@ -212,13 +168,13 @@ var FileToolModifier = class {
212
168
  const { arguments: args } = params;
213
169
  if (!args || typeof args !== "object") return params;
214
170
  try {
215
- const newArgs = await withCancellation(() => hydrateFiles(args, resolveFileSchema(tool.inputParameters), {
171
+ const newArgs = await withCancellation(() => walkFileUploadableLeaves(args, resolveFileSchema(tool.inputParameters), (value) => stageFileValue(value, {
216
172
  toolSlug,
217
173
  toolkitSlug,
218
174
  client: this.client,
219
175
  ...this.fileUploadPathOptions,
220
176
  signal
221
- }), signal);
177
+ })), signal);
222
178
  return {
223
179
  ...params,
224
180
  arguments: newArgs
@@ -1,4 +1,4 @@
1
- import { $i as ToolExecuteResponse, Ji as Tool, Zi as ToolExecuteParams } from "../../customTool.types-B2Ava_j5.mjs";
1
+ import { $i as ToolExecuteResponse, Ji as Tool, Zi as ToolExecuteParams } from "../../customTool.types-DpJbYY5m.mjs";
2
2
  import ComposioClient from "@composio/client";
3
3
  //#region src/utils/modifiers/FileToolModifier.workerd.d.ts
4
4
  declare class FileToolModifier {
@@ -1,4 +1,4 @@
1
- import { i as transformProperties } from "../../FileToolModifier.utils.neutral-B5rT711M.mjs";
1
+ import { c as transformProperties } from "../../FileToolModifier.utils.neutral-D_YkHwZP.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).";
@@ -9,13 +9,22 @@ declare const isBlockedIp: (ip: string) => boolean;
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
11
11
  * {@link ComposioBlockedInternalUrlError} otherwise.
12
+ *
13
+ * @returns the validated addresses to connect to, in resolver order. Callers
14
+ * must connect to *those* rather than let the client resolve the hostname
15
+ * again; see {@link ssrfSafeFetch}.
12
16
  */
13
- declare const assertSafeFetchTarget: (rawUrl: string) => Promise<void>;
17
+ declare const assertSafeFetchTarget: (rawUrl: string) => Promise<string[]>;
14
18
  /**
15
- * Drop-in replacement for `fetch` that blocks SSRF. Validates the target before
16
- * connecting and re-validates every redirect hop (redirects are followed
17
- * manually up to {@link MAX_REDIRECTS}). Intermediate redirect bodies are
18
- * cancelled; non-redirect responses are returned unchanged.
19
+ * Drop-in replacement for `fetch` that blocks SSRF. Validates the target, then
20
+ * connects to the address it validated, and re-validates and re-pins every
21
+ * redirect hop (redirects are followed manually up to {@link MAX_REDIRECTS}).
22
+ * Intermediate redirect bodies are cancelled; non-redirect responses are
23
+ * returned unchanged.
24
+ *
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.
19
28
  */
20
29
  declare const ssrfSafeFetch: (rawUrl: string, init?: RequestInit, maxRedirects?: number) => Promise<Response>;
21
30
  /**
@@ -1,163 +1,3 @@
1
- import { t as ComposioBlockedInternalUrlError } from "../SsrfErrors-DNJt57GL.mjs";
2
- import { lookup } from "node:dns/promises";
3
- import { isIP } from "node:net";
1
+ import { i as ssrfSafeFetchWhereSupported, n as isBlockedIp, r as ssrfSafeFetch, t as assertSafeFetchTarget } from "../ssrfGuard.node-DlxO8uzr.mjs";
4
2
 
5
- //#region src/utils/ssrfGuard.node.ts
6
- /**
7
- * SSRF guard for user-supplied URL file inputs.
8
- *
9
- * `composio.files.upload(url)`, Tool Router session file uploads, and automatic
10
- * file upload during tool execution fetch arbitrary user-provided URLs. Without
11
- * a guard, a caller (or a tool argument produced by an LLM) can point the SDK at
12
- * internal infrastructure — loopback, RFC1918 ranges, link-local cloud-metadata
13
- * endpoints (`169.254.169.254`), or a public URL that 3xx-redirects into internal
14
- * space — turning the SDK into a server-side request forgery probe.
15
- *
16
- * This module validates the *resolved* address (not just the hostname string,
17
- * which defeats decimal/octal/hex IP obfuscation) before every fetch, and
18
- * follows redirects manually so each hop is re-validated.
19
- *
20
- * Known residual: a DNS name could resolve to a public address here and rebind
21
- * to an internal one before the underlying `fetch` connects (a TOCTOU / DNS
22
- * rebinding window). Closing that fully requires pinning the validated IP at
23
- * connect time (a custom dispatcher), which is out of scope for this guard.
24
- */
25
- const MAX_REDIRECTS = 5;
26
- const ipv4ToLong = (ip) => {
27
- const [a, b, c, d] = ip.split(".").map(Number);
28
- return (a << 24 >>> 0 | b << 16 | c << 8 | d) >>> 0;
29
- };
30
- const IPV4_BLOCKED_CIDRS = [
31
- ["0.0.0.0", 8],
32
- ["10.0.0.0", 8],
33
- ["100.64.0.0", 10],
34
- ["127.0.0.0", 8],
35
- ["169.254.0.0", 16],
36
- ["172.16.0.0", 12],
37
- ["192.0.0.0", 24],
38
- ["192.0.2.0", 24],
39
- ["192.168.0.0", 16],
40
- ["198.18.0.0", 15],
41
- ["198.51.100.0", 24],
42
- ["203.0.113.0", 24],
43
- ["224.0.0.0", 4],
44
- ["240.0.0.0", 4]
45
- ];
46
- const isBlockedIpv4Long = (long) => IPV4_BLOCKED_CIDRS.some(([base, bits]) => {
47
- const mask = bits === 0 ? 0 : 4294967295 << 32 - bits >>> 0;
48
- return (long & mask) === (ipv4ToLong(base) & mask);
49
- });
50
- /**
51
- * Expand an IPv6 string into its 8 16-bit groups, converting any trailing
52
- * dotted-quad (e.g. `::ffff:1.2.3.4`) into hex groups first. Returns `null` when
53
- * the input cannot be parsed.
54
- */
55
- const expandIpv6 = (ip) => {
56
- let addr = ip;
57
- const v4Match = addr.match(/^(.*:)(\d+\.\d+\.\d+\.\d+)$/);
58
- if (v4Match) {
59
- const long = ipv4ToLong(v4Match[2]);
60
- addr = `${v4Match[1]}${(long >>> 16 & 65535).toString(16)}:${(long & 65535).toString(16)}`;
61
- }
62
- const halves = addr.split("::");
63
- if (halves.length > 2) return null;
64
- const head = halves[0] ? halves[0].split(":") : [];
65
- const tail = halves.length === 2 ? halves[1] ? halves[1].split(":") : [] : [];
66
- let groups;
67
- if (halves.length === 2) {
68
- const missing = 8 - head.length - tail.length;
69
- if (missing < 0) return null;
70
- groups = [
71
- ...head,
72
- ...Array(missing).fill("0"),
73
- ...tail
74
- ];
75
- } else groups = head;
76
- if (groups.length !== 8) return null;
77
- return groups.map((g) => parseInt(g || "0", 16));
78
- };
79
- const isBlockedIpv6 = (ip) => {
80
- const h = expandIpv6(ip);
81
- if (!h) return true;
82
- if (h.every((x) => x === 0)) return true;
83
- if (h.slice(0, 7).every((x) => x === 0) && h[7] === 1) return true;
84
- const isMappedOrCompat = h[0] === 0 && h[1] === 0 && h[2] === 0 && h[3] === 0 && h[4] === 0 && (h[5] === 65535 || h[5] === 0);
85
- const isNat64 = h[0] === 100 && h[1] === 65435 && h[2] === 0 && h[3] === 0 && h[4] === 0 && h[5] === 0;
86
- if (isMappedOrCompat || isNat64) return isBlockedIpv4Long((h[6] << 16 >>> 0 | h[7]) >>> 0);
87
- if ((h[0] & 65024) === 64512) return true;
88
- if ((h[0] & 65472) === 65152) return true;
89
- if ((h[0] & 65280) === 65280) return true;
90
- return false;
91
- };
92
- /**
93
- * True when `ip` is a private, loopback, link-local, or otherwise
94
- * non-publicly-routable address. Fails closed (returns `true`) for anything that
95
- * is not a valid IPv4/IPv6 literal.
96
- */
97
- const isBlockedIp = (ip) => {
98
- const family = isIP(ip);
99
- if (family === 4) return isBlockedIpv4Long(ipv4ToLong(ip));
100
- if (family === 6) return isBlockedIpv6(ip);
101
- return true;
102
- };
103
- /**
104
- * Validate a single URL: it must be http(s), its host must resolve, and every
105
- * resolved address must be publicly routable. Throws
106
- * {@link ComposioBlockedInternalUrlError} otherwise.
107
- */
108
- const assertSafeFetchTarget = async (rawUrl) => {
109
- let url;
110
- try {
111
- url = new URL(rawUrl);
112
- } catch {
113
- throw new ComposioBlockedInternalUrlError("Refusing to fetch a malformed URL", { url: rawUrl });
114
- }
115
- if (url.protocol !== "http:" && url.protocol !== "https:") throw new ComposioBlockedInternalUrlError(`Refusing to fetch a non-http(s) URL (scheme "${url.protocol}")`, { url: rawUrl });
116
- const host = url.hostname.replace(/^\[|\]$/g, "");
117
- let resolved;
118
- try {
119
- resolved = await lookup(host, {
120
- all: true,
121
- verbatim: true
122
- });
123
- } catch {
124
- throw new ComposioBlockedInternalUrlError(`Could not resolve host "${host}"`, { url: rawUrl });
125
- }
126
- for (const { address } of resolved) if (isBlockedIp(address)) throw new ComposioBlockedInternalUrlError(`Refusing to fetch "${host}" — it resolves to a private, loopback, or link-local address`, {
127
- url: rawUrl,
128
- resolvedIp: address
129
- });
130
- };
131
- /**
132
- * Drop-in replacement for `fetch` that blocks SSRF. Validates the target before
133
- * connecting and re-validates every redirect hop (redirects are followed
134
- * manually up to {@link MAX_REDIRECTS}). Intermediate redirect bodies are
135
- * cancelled; non-redirect responses are returned unchanged.
136
- */
137
- const ssrfSafeFetch = async (rawUrl, init = {}, maxRedirects = MAX_REDIRECTS) => {
138
- let currentUrl = rawUrl;
139
- for (let hop = 0; hop <= maxRedirects; hop++) {
140
- await assertSafeFetchTarget(currentUrl);
141
- const response = await fetch(currentUrl, {
142
- ...init,
143
- redirect: "manual"
144
- });
145
- if (!(response.status >= 300 && response.status < 400 && response.headers.has("location"))) return response;
146
- await response.body?.cancel().catch(() => void 0);
147
- currentUrl = new URL(response.headers.get("location"), currentUrl).toString();
148
- }
149
- throw new ComposioBlockedInternalUrlError(`Refusing to fetch: too many redirects (max ${maxRedirects})`, { url: rawUrl });
150
- };
151
- /**
152
- * {@link ssrfSafeFetch} for call sites that must keep working on every runtime.
153
- *
154
- * `ssrfSafeFetch` fails closed in edge runtimes, which is right for a URL the
155
- * caller chose to upload — the alternative is fetching it unvalidated — but not
156
- * for Tool Router session file transfers, where refusing would remove a working
157
- * feature from Workers rather than close a hole reachable there. On Node this
158
- * is the full guard; only the edge build differs.
159
- */
160
- const ssrfSafeFetchWhereSupported = ssrfSafeFetch;
161
-
162
- //#endregion
163
3
  export { assertSafeFetchTarget, isBlockedIp, ssrfSafeFetch, ssrfSafeFetchWhereSupported };
package/package.json CHANGED
@@ -1,7 +1,10 @@
1
1
  {
2
2
  "name": "@composio/core",
3
3
  "type": "module",
4
- "version": "0.17.0",
4
+ "engines": {
5
+ "node": ">=22.22.3"
6
+ },
7
+ "version": "1.0.0-beta.0",
5
8
  "description": "",
6
9
  "main": "dist/index.mjs",
7
10
  "publishConfig": {
@@ -95,20 +98,21 @@
95
98
  "tsx": "^4.23.12",
96
99
  "typedoc": "^0.28.20",
97
100
  "typescript": "npm:@typescript/typescript6@^6.0.2",
98
- "vitest": "^4.1.10",
101
+ "vitest": "^4.1.11",
99
102
  "zod": "^4.4.3"
100
103
  },
101
104
  "peerDependencies": {
102
105
  "zod": ">=3.25.76 <5"
103
106
  },
104
107
  "dependencies": {
105
- "@composio/client": "0.1.0-alpha.76",
108
+ "@composio/client": "2.0.0-rc.6",
106
109
  "@types/json-schema": "^7.0.15",
107
110
  "is-fs-case-sensitive": "^2.0.0",
108
111
  "openai": "^7.2.0",
109
112
  "picocolors": "^1.1.1",
110
113
  "pusher-js": "^8.6.0",
111
114
  "semver": "^7.8.5",
115
+ "undici": "^7.29.0",
112
116
  "zod-to-json-schema": "^3.25.2",
113
117
  "@composio/json-schema-to-zod": "0.3.0"
114
118
  },
@@ -41,7 +41,11 @@ import { ACL_ONLY_FOR_SHARED_ERROR_FRAGMENT, serializeExperimentalForWire } from
41
41
  import { z } from 'zod/v3';
42
42
  import { transform } from '../utils/transform';
43
43
  import { ToolkitConnectionStateSchema } from '../types/toolRouter.types';
44
- import { ComposioAclOnlyForSharedError, ValidationError } from '../errors';
44
+ import {
45
+ ComposioAclOnlyForSharedError,
46
+ ComposioInvalidModifierError,
47
+ ValidationError,
48
+ } from '../errors';
45
49
  import { Tools } from './Tools';
46
50
  import { ToolRouterSessionFilesMount } from './ToolRouterSessionFileMount';
47
51
  import type {
@@ -51,7 +55,7 @@ import type {
51
55
  RegisteredCustomTool,
52
56
  RegisteredCustomToolkit,
53
57
  } from '../types/customTool.types';
54
- import type { Tool, ToolExecuteResponse } from '../types/tool.types';
58
+ import { ToolSchema, type Tool, type ToolExecuteResponse } from '../types/tool.types';
55
59
  import type { SessionProxyExecuteParams } from '../types/toolRouter.types';
56
60
  import type {
57
61
  SessionExecuteParams,
@@ -190,13 +194,14 @@ export class ToolRouterSession<
190
194
  requestOptions?: ComposioRequestOptions
191
195
  ): Promise<ReturnType<TProvider['wrapTools']>> {
192
196
  const ToolsModel = new Tools<TToolCollection, TTool, TProvider>(this.client, this.config);
193
- const tools = await ToolsModel.getRawToolRouterSessionTools(
197
+ const rawTools = await ToolsModel.getRawToolRouterSessionTools(
194
198
  this.sessionId,
195
- modifiers?.modifySchema ? { modifySchema: modifiers.modifySchema } : undefined,
199
+ undefined,
196
200
  requestOptions
197
201
  );
202
+ const tools = await this.applySchemaModifier(rawTools, modifiers?.modifySchema);
198
203
  const sessionTools = await this.addPreloadedCustomTools(tools, modifiers);
199
- const toolBySlug = new Map(sessionTools.map(tool => [tool.slug.toUpperCase(), tool]));
204
+ const rawToolBySlug = new Map(rawTools.map(tool => [tool.slug.toUpperCase(), tool]));
200
205
 
201
206
  if (this.hasCustomTools()) {
202
207
  // Create an execute function that splits local/remote tools in COMPOSIO_MULTI_EXECUTE_TOOL
@@ -205,7 +210,7 @@ export class ToolRouterSession<
205
210
  input: Record<string, unknown>
206
211
  ): Promise<ToolExecuteResponse> => {
207
212
  if (toolSlug === COMPOSIO_MULTI_EXECUTE_TOOL) {
208
- return this.routeMultiExecute(input, ToolsModel, sessionTools, modifiers);
213
+ return this.routeMultiExecute(input, ToolsModel, rawTools, modifiers);
209
214
  }
210
215
  const customTool = findCustomTool(this.customToolsMap, toolSlug);
211
216
  if (customTool) {
@@ -217,7 +222,7 @@ export class ToolRouterSession<
217
222
  toolSlug,
218
223
  input,
219
224
  modifiers,
220
- toolBySlug.get(toolSlug.toUpperCase())
225
+ rawToolBySlug.get(toolSlug.toUpperCase())
221
226
  );
222
227
  };
223
228
 
@@ -233,10 +238,33 @@ export class ToolRouterSession<
233
238
  }
234
239
 
235
240
  // Standard path (no local tools)
236
- const wrappedTools = ToolsModel.wrapToolsForToolRouter(this.sessionId, sessionTools, modifiers);
241
+ const wrappedTools = modifiers?.modifySchema
242
+ ? ToolsModel.wrapToolsForToolRouter(this.sessionId, sessionTools, modifiers, rawTools)
243
+ : ToolsModel.wrapToolsForToolRouter(this.sessionId, sessionTools, modifiers);
237
244
  return wrappedTools as ReturnType<TProvider['wrapTools']>;
238
245
  }
239
246
 
247
+ private async applySchemaModifier(
248
+ tools: Tool[],
249
+ modifier?: SessionMetaToolOptions['modifySchema']
250
+ ): Promise<Tool[]> {
251
+ if (!modifier) {
252
+ return tools;
253
+ }
254
+ if (typeof modifier !== 'function') {
255
+ throw new ComposioInvalidModifierError('Invalid schema modifier. Not a function.');
256
+ }
257
+ return Promise.all(
258
+ tools.map(tool =>
259
+ modifier({
260
+ toolSlug: tool.slug,
261
+ toolkitSlug: tool.toolkit?.slug ?? 'unknown',
262
+ schema: ToolSchema.parse(tool),
263
+ })
264
+ )
265
+ );
266
+ }
267
+
240
268
  private async addPreloadedCustomTools(
241
269
  tools: Tool[],
242
270
  modifiers?: SessionMetaToolOptions