@composio/core 0.13.0 → 0.14.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 (63) hide show
  1. package/README.md +62 -247
  2. package/dist/BaseProvider-lCxnjFKQ.d.mts +29395 -0
  3. package/dist/{CustomTool-D9qwyMrv.mjs → CustomTool-C_5NvBsX.mjs} +17 -15
  4. package/dist/{CustomTool-DrJpOhY2.d.mts → CustomTool-CmokRT9q.d.mts} +1 -1
  5. package/dist/{FileModifierErrors-3fSwIWoa.mjs → SsrfErrors-BQRozkeU.mjs} +33 -1
  6. package/dist/{Telemetry-DhGI_J4G.mjs → Telemetry-llfvticE.mjs} +40 -8
  7. package/dist/{jsonSchema-CFKdONpP.mjs → cancellation-W65QRyj2.mjs} +64 -19
  8. package/dist/{composio-DHIKRdeG.d.mts → composio-6C8kHtqc.d.mts} +1079 -1092
  9. package/dist/{customTool.types-CKH2R2ia.d.mts → customTool.types-kFhNYuzh.d.mts} +602 -549
  10. package/dist/docs/reference/sdk-reference/typescript/index.mdx +1 -22
  11. package/dist/docs/reference/sdk-reference/typescript/session.mdx +23 -0
  12. package/dist/docs/reference/sdk-reference/typescript/sessions.mdx +24 -0
  13. package/dist/{errors-DSIlYfl5.mjs → errors-B165yJUQ.mjs} +74 -74
  14. package/dist/experimental/index.d.mts +2 -2
  15. package/dist/experimental/index.mjs +1 -1
  16. package/dist/{fileUtils.node-BiO1JQsJ.mjs → fileUtils.node-iPFi2o4i.mjs} +182 -68
  17. package/dist/index.d.mts +1459 -1401
  18. package/dist/index.mjs +1437 -1375
  19. package/dist/models/Files.node.mjs +2 -2
  20. package/dist/platform/node.d.mts +1 -1
  21. package/dist/platform/node.mjs +3 -0
  22. package/dist/platform/workerd.d.mts +1 -1
  23. package/dist/platform/workerd.mjs +3 -0
  24. package/dist/sensitiveFileUploadPaths-B1OLsd8F.mjs +114 -0
  25. package/dist/{types-DdoCRzLj.d.mts → types-DY1r-kN9.d.mts} +9 -0
  26. package/dist/{types-D4Id3wXA.d.mts → types-yCrveqAj.d.mts} +2 -2
  27. package/dist/utils/config-defaults/ConfigDefaults.node.d.mts +1 -1
  28. package/dist/utils/config-defaults/ConfigDefaults.workerd.d.mts +1 -1
  29. package/dist/utils/modifiers/FileToolModifier.node.d.mts +1 -1
  30. package/dist/utils/modifiers/FileToolModifier.node.mjs +5 -5
  31. package/dist/utils/modifiers/FileToolModifier.workerd.d.mts +1 -1
  32. package/package.json +10 -10
  33. package/src/errors/SsrfErrors.ts +47 -0
  34. package/src/errors/index.ts +3 -0
  35. package/src/index.ts +10 -0
  36. package/src/lib/toolRouterSessionDelete.ts +30 -0
  37. package/src/models/CustomTool.ts +1 -3
  38. package/src/models/ToolRouter.ts +15 -0
  39. package/src/models/ToolRouterSession.ts +50 -16
  40. package/src/models/Tools.ts +32 -2
  41. package/src/models/Triggers.ts +16 -76
  42. package/src/platform/node.ts +4 -0
  43. package/src/platform/types.ts +10 -0
  44. package/src/platform/workerd.ts +6 -0
  45. package/src/provider/OpenAIProvider.ts +19 -14
  46. package/src/telemetry/Telemetry.ts +9 -6
  47. package/src/telemetry/redact.ts +40 -0
  48. package/src/types/tool.types.ts +36 -32
  49. package/src/types/toolRouter.types.ts +13 -0
  50. package/src/utils/fileUtils.node.ts +27 -4
  51. package/src/utils/jsonSchema.ts +58 -0
  52. package/src/utils/modifiers/FileToolModifier.node.ts +2 -1
  53. package/src/utils/sdk.ts +5 -4
  54. package/src/utils/{sensitiveFileUploadPaths.node.ts → sensitiveFileUploadPaths.ts} +29 -13
  55. package/src/utils/ssrfGuard.node.ts +202 -0
  56. package/src/utils/toolkitVersion.ts +21 -2
  57. package/dist/BaseProvider-BBnsv9kS.d.mts +0 -29425
  58. package/dist/BaseProvider-Brb3o86-.d.mts +0 -29425
  59. package/dist/CustomTool-Dmi6ti3I.d.mts +0 -74
  60. package/dist/buffer-PcbMMsgm.mjs +0 -33
  61. package/dist/composio-vMwhASRc.d.mts +0 -5698
  62. package/dist/customTool.types-DXin7Cfc.d.mts +0 -2773
  63. package/dist/types-qTbYYBJw.d.mts +0 -12
@@ -1,5 +1,5 @@
1
- import { T as ValidationError } from "./errors-DSIlYfl5.mjs";
2
- import { z } from "zod/v3";
1
+ import { _ as ValidationError } from "./errors-B165yJUQ.mjs";
2
+ import { z as z$1 } from "zod/v3";
3
3
  import * as z4 from "zod/v4";
4
4
  import * as zodToJsonSchema from "zod-to-json-schema";
5
5
 
@@ -9,32 +9,32 @@ import * as zodToJsonSchema from "zod-to-json-schema";
9
9
  * Alphanumeric, underscores, and hyphens only. No `LOCAL_` or `COMPOSIO_` prefix.
10
10
  * Length is validated contextually (standalone vs extension vs toolkit) at creation time.
11
11
  */
12
- const CustomToolSlugSchema = z.string().min(1, "slug is required").regex(/^[A-Za-z0-9_-]+$/, "slug must only contain alphanumeric characters, underscores, and hyphens").refine((s) => !s.toUpperCase().startsWith("LOCAL_"), { message: "slug must not start with \"LOCAL_\" — this prefix is reserved for internal routing." }).refine((s) => !s.toUpperCase().startsWith("COMPOSIO_"), { message: "slug must not start with \"COMPOSIO_\" — this prefix is reserved for Composio meta tools." });
12
+ const CustomToolSlugSchema = z$1.string().min(1, "slug is required").regex(/^[A-Za-z0-9_-]+$/, "slug must only contain alphanumeric characters, underscores, and hyphens").refine((s) => !s.toUpperCase().startsWith("LOCAL_"), { message: "slug must not start with \"LOCAL_\" — this prefix is reserved for internal routing." }).refine((s) => !s.toUpperCase().startsWith("COMPOSIO_"), { message: "slug must not start with \"COMPOSIO_\" — this prefix is reserved for Composio meta tools." });
13
13
  /**
14
14
  * Zod schema for validating the string/scalar fields of createCustomTool() options.
15
15
  * Slug is validated separately as the first argument.
16
16
  * Used internally for validation — inputParams, outputParams, and execute are checked manually.
17
17
  */
18
- const CreateCustomToolBaseSchema = z.object({
19
- name: z.string().min(1, "createCustomTool: name is required"),
20
- description: z.string().min(1, "createCustomTool: description is required"),
18
+ const CreateCustomToolBaseSchema = z$1.object({
19
+ name: z$1.string().min(1, "createCustomTool: name is required"),
20
+ description: z$1.string().min(1, "createCustomTool: description is required"),
21
21
  /**
22
22
  * Composio toolkit slug that this tool extends (inherits auth from).
23
23
  * Must be a valid Composio toolkit slug (e.g. `'gmail'`, `'github'`, `'meta_ads'`).
24
24
  * The backend validates this against the toolkit catalog.
25
25
  * Leave empty for tools that don't need any Composio-managed authentication.
26
26
  */
27
- extendsToolkit: z.string().optional(),
28
- preload: z.boolean().optional().describe("When true, include this custom tool in session.tools() so it can be called without searching first.")
27
+ extendsToolkit: z$1.string().optional(),
28
+ preload: z$1.boolean().optional().describe("When true, include this custom tool in session.tools() so it can be called without searching first.")
29
29
  });
30
30
  /**
31
31
  * Zod schema for validating the string/scalar fields of createCustomToolkit() options.
32
32
  * Slug is validated separately as the first argument.
33
33
  */
34
- const CreateCustomToolkitBaseSchema = z.object({
35
- name: z.string().min(1, "createCustomToolkit: name is required"),
36
- description: z.string().min(1, "createCustomToolkit: description is required"),
37
- preload: z.boolean().optional().describe("When true, include tools from this custom toolkit in session.tools(). Tool-level preload values override this default.")
34
+ const CreateCustomToolkitBaseSchema = z$1.object({
35
+ name: z$1.string().min(1, "createCustomToolkit: name is required"),
36
+ description: z$1.string().min(1, "createCustomToolkit: description is required"),
37
+ preload: z$1.boolean().optional().describe("When true, include tools from this custom toolkit in session.tools(). Tool-level preload values override this default.")
38
38
  });
39
39
 
40
40
  //#endregion
@@ -56,11 +56,12 @@ const isZodObjectSchema = (value) => {
56
56
  };
57
57
  const zodSchemaToJsonSchema = (schema, name = "schema", mode = "output") => {
58
58
  if (isZodV4Schema(schema)) return stripSchemaKeyword(z4.toJSONSchema(schema, { io: mode }));
59
- return stripSchemaKeyword(getNamedDefinition(zodToJsonSchema.default(schema, {
59
+ const converted = zodToJsonSchema.default(schema, {
60
60
  name,
61
61
  pipeStrategy: mode,
62
62
  effectStrategy: mode === "input" ? "input" : "any"
63
- }), name));
63
+ });
64
+ return stripSchemaKeyword(getNamedDefinition(converted, name));
64
65
  };
65
66
  const zodObjectSchemaToJsonSchema = (schema, name = "schema", mode = "input") => {
66
67
  if (!isZodObjectSchema(schema)) throw new Error("Expected a z.object() schema.");
@@ -114,7 +115,8 @@ function validateSlugLength(toolSlug, toolkitSlug, context) {
114
115
  const finalLength = computeFinalSlugLength(toolSlug, toolkitSlug);
115
116
  if (finalLength > MAX_SLUG_LENGTH) {
116
117
  const prefix = LOCAL_TOOL_PREFIX + (toolkitSlug ? `${toolkitSlug.toUpperCase()}_` : "");
117
- throw new ValidationError(`${context}: slug "${toolSlug}" is too long. With prefix "${prefix}", the final slug would be ${finalLength} characters (max ${MAX_SLUG_LENGTH}). Shorten the slug to at most ${MAX_SLUG_LENGTH - prefix.length} characters.`);
118
+ const available = MAX_SLUG_LENGTH - prefix.length;
119
+ throw new ValidationError(`${context}: slug "${toolSlug}" is too long. With prefix "${prefix}", the final slug would be ${finalLength} characters (max ${MAX_SLUG_LENGTH}). Shorten the slug to at most ${available} characters.`);
118
120
  }
119
121
  }
120
122
  /**
@@ -1,4 +1,4 @@
1
- import { a as CreateCustomToolkitParams, f as CustomToolkit, o as CustomTool, r as CreateCustomToolParams, t as AnyZodSchema } from "./customTool.types-DXin7Cfc.mjs";
1
+ import { a as CreateCustomToolkitParams, f as CustomToolkit, o as CustomTool, r as CreateCustomToolParams, t as AnyZodSchema } from "./customTool.types-kFhNYuzh.mjs";
2
2
  import { SessionCreateResponse } from "@composio/client/resources/tool-router/session/session.mjs";
3
3
 
4
4
  //#region src/models/CustomTool.d.ts
@@ -442,4 +442,36 @@ var ComposioFileNotFoundError = class extends ComposioFileUploadError {
442
442
  };
443
443
 
444
444
  //#endregion
445
- export { getEnvVariable as _, ComposioSensitiveFilePathBlockedError as a, logger as c, DEFAULT_BASE_URL as d, DEFAULT_TOOL_ROUTER_SESSION_FILES_MOUNT_ID as f, constants_exports as g, USER_DATA_FILE_NAME as h, ComposioFileUploadPathNotAllowedError as i, COMPOSIO_DIR as l, TEMP_FILES_DIRECTORY_NAME as m, ComposioFileUploadAbortedError as n, FileModifierErrorCodes as o, IS_DEVELOPMENT_OR_CI as p, ComposioFileUploadError as r, ComposioError$1 as s, ComposioFileNotFoundError as t, COMPOSIO_LOG_LEVEL as u, getEnvsWithPrefix as v };
445
+ //#region src/errors/SsrfErrors.ts
446
+ const SsrfErrorCodes = { BLOCKED_INTERNAL_URL: "BLOCKED_INTERNAL_URL" };
447
+ /**
448
+ * Thrown when a URL file input resolves to a private, loopback, link-local, or
449
+ * otherwise internal address, or points at a non-http(s) scheme. Guards against
450
+ * turning `composio.files.upload(url)` (and automatic upload during tool
451
+ * execution) into a server-side request forgery (SSRF) probe of internal
452
+ * infrastructure such as cloud metadata endpoints (`169.254.169.254`).
453
+ */
454
+ var ComposioBlockedInternalUrlError = class extends ComposioError$1 {
455
+ constructor(message = "Refusing to fetch an internal or non-public URL", options = {}) {
456
+ const { url, resolvedIp, meta: optionsMeta, ...rest } = options;
457
+ const meta = {
458
+ ...optionsMeta,
459
+ ...url && { url },
460
+ ...resolvedIp && { resolvedIp }
461
+ };
462
+ super(message, {
463
+ ...rest,
464
+ code: SsrfErrorCodes.BLOCKED_INTERNAL_URL,
465
+ meta: Object.keys(meta).length > 0 ? meta : void 0,
466
+ possibleFixes: options.possibleFixes ?? [
467
+ "Use a publicly reachable http(s) URL",
468
+ "Do not point file inputs at localhost, link-local, or private-network hosts",
469
+ "If the source is internal, download it yourself and pass a File/Blob instead of a URL"
470
+ ]
471
+ });
472
+ this.name = "ComposioBlockedInternalUrlError";
473
+ }
474
+ };
475
+
476
+ //#endregion
477
+ export { USER_DATA_FILE_NAME as _, ComposioFileUploadError as a, getEnvsWithPrefix as b, FileModifierErrorCodes as c, COMPOSIO_DIR as d, COMPOSIO_LOG_LEVEL as f, TEMP_FILES_DIRECTORY_NAME as g, IS_DEVELOPMENT_OR_CI as h, ComposioFileUploadAbortedError as i, ComposioError$1 as l, DEFAULT_TOOL_ROUTER_SESSION_FILES_MOUNT_ID as m, SsrfErrorCodes as n, ComposioFileUploadPathNotAllowedError as o, DEFAULT_BASE_URL as p, ComposioFileNotFoundError as r, ComposioSensitiveFilePathBlockedError as s, ComposioBlockedInternalUrlError as t, logger as u, constants_exports as v, getEnvVariable as y };
@@ -1,5 +1,5 @@
1
- import { _ as getEnvVariable, c as logger, s as ComposioError$1 } from "./FileModifierErrors-3fSwIWoa.mjs";
2
- import { a as getRandomUUID } from "./buffer-PcbMMsgm.mjs";
1
+ import { l as ComposioError$1, u as logger, y as getEnvVariable } from "./SsrfErrors-BQRozkeU.mjs";
2
+ import { c as getRandomUUID } from "./sensitiveFileUploadPaths-B1OLsd8F.mjs";
3
3
  import { ComposioError } from "@composio/client";
4
4
 
5
5
  //#region src/types/telemetry.types.ts
@@ -99,6 +99,38 @@ var TelemetryService = class {
99
99
  }
100
100
  };
101
101
 
102
+ //#endregion
103
+ //#region src/telemetry/redact.ts
104
+ /**
105
+ * Best-effort redaction of secrets from free-form error text before it is sent
106
+ * to the telemetry endpoint.
107
+ *
108
+ * Error `message` and `stack` fields routinely interpolate URLs (with
109
+ * query-string tokens / presigned signatures), `Authorization` headers, API
110
+ * keys, and connected-account identifiers. None of that should leave the
111
+ * process. Structured telemetry fields never carry raw secrets, so only the two
112
+ * free-form strings are passed through here.
113
+ *
114
+ * This is defence-in-depth, not a proof: it targets the shapes we have seen
115
+ * leak. When in doubt it over-redacts rather than under-redacts.
116
+ */
117
+ const REDACTED = "[REDACTED]";
118
+ const REDACTION_RULES = [
119
+ [/(\bhttps?:\/\/[^\s?#'"]+)\?[^\s'"]*/gi, `$1?${REDACTED}`],
120
+ [/\b(bearer|basic)\s+[A-Za-z0-9._~+/=-]+/gi, `$1 ${REDACTED}`],
121
+ [/\b(authorization|api[-_]?key|apikey|x-api-key|access[-_]?token|refresh[-_]?token|client[-_]?secret|secret|password|passwd|pwd)\b(\s*[:=]+\s*)(["']?)([^\s"',}&]+)\3/gi, `$1$2$3${REDACTED}$3`]
122
+ ];
123
+ /**
124
+ * Redact common secret shapes from a free-form string. Returns the input
125
+ * unchanged when it is empty or `undefined`.
126
+ */
127
+ const redactSensitiveText = (input) => {
128
+ if (!input) return input;
129
+ let output = input;
130
+ for (const [pattern, replacement] of REDACTION_RULES) output = output.replace(pattern, replacement);
131
+ return output;
132
+ };
133
+
102
134
  //#endregion
103
135
  //#region src/telemetry/Telemetry.ts
104
136
  /**
@@ -244,21 +276,21 @@ var TelemetryTransport = class {
244
276
  if (error instanceof ComposioError) telemetryPayload.error = {
245
277
  errorId: error.errorId,
246
278
  name: error.name,
247
- message: error.message,
248
- stack: error.stack
279
+ message: redactSensitiveText(error.message),
280
+ stack: redactSensitiveText(error.stack)
249
281
  };
250
282
  else if (error instanceof ComposioError$1) telemetryPayload.error = {
251
283
  errorId: error.errorId,
252
284
  name: error.name,
253
285
  code: error.code,
254
- message: error.message,
255
- stack: error.stack
286
+ message: redactSensitiveText(error.message),
287
+ stack: redactSensitiveText(error.stack)
256
288
  };
257
289
  else if (error instanceof Error) telemetryPayload.error = {
258
290
  errorId: error.errorId,
259
291
  name: error.name ?? "Unknown error",
260
- message: error.message,
261
- stack: error.stack
292
+ message: redactSensitiveText(error.message),
293
+ stack: redactSensitiveText(error.stack)
262
294
  };
263
295
  this.deferTelemetry(() => this.sendErrorTelemetry(telemetryPayload));
264
296
  }
@@ -1,23 +1,8 @@
1
- import { c as logger } from "./FileModifierErrors-3fSwIWoa.mjs";
2
- import { C as JsonSchemaRefResolutionError, S as isRequestAbortError, b as ComposioRequestCancelledError, w as JsonSchemaToZodError } from "./errors-DSIlYfl5.mjs";
1
+ import { u as logger } from "./SsrfErrors-BQRozkeU.mjs";
2
+ import { f as ComposioRequestCancelledError, g as JsonSchemaToZodError, h as JsonSchemaRefResolutionError, m as isRequestAbortError } from "./errors-B165yJUQ.mjs";
3
3
  import { t as isPlainObject } from "./FileToolModifier.utils.neutral-B5rT711M.mjs";
4
4
  import { jsonSchemaToZod } from "@composio/json-schema-to-zod";
5
5
 
6
- //#region src/utils/cancellation.ts
7
- /** @internal */
8
- async function withCancellation(call, signal) {
9
- try {
10
- return await call();
11
- } catch (error) {
12
- if (signal?.aborted && isRequestAbortError(error)) {
13
- const underlyingMessage = error instanceof Error ? error.message : "";
14
- throw new ComposioRequestCancelledError(underlyingMessage ? `Request was cancelled by the caller: ${underlyingMessage}` : "Request was cancelled by the caller", { cause: error instanceof Error ? error : void 0 });
15
- }
16
- throw error;
17
- }
18
- }
19
-
20
- //#endregion
21
6
  //#region src/utils/jsonSchema.ts
22
7
  const MAX_REF_CHAIN_DEPTH = 100;
23
8
  const MAX_NODE_DEPTH = 512;
@@ -36,7 +21,7 @@ const CYCLE_BREAK_SENTINEL = {
36
21
  * (Draft 2020-12 sibling-keyword semantics).
37
22
  */
38
23
  const UNRESOLVED_REF_DESCRIPTION = "Schema shape unresolved at the source — validate loosely. See https://github.com/ComposioHQ/composio/issues/3307.";
39
- const POLLUTING_KEYS = new Set([
24
+ const POLLUTING_KEYS = /* @__PURE__ */ new Set([
40
25
  "__proto__",
41
26
  "constructor",
42
27
  "prototype"
@@ -187,6 +172,51 @@ function dereferenceJsonSchema(schema, options) {
187
172
  return out;
188
173
  }
189
174
  /**
175
+ * Returns a deep-cloned JSON Schema whose `required` arrays contain each entry
176
+ * at most once. Duplicate entries are invalid in JSON Schema 2020-12 but do
177
+ * not change the schema's meaning, so preserving the first occurrence is safe.
178
+ *
179
+ * Tool schemas originate both from the Composio API and direct provider calls.
180
+ * Keeping this normalization provider-agnostic lets every SDK provider receive
181
+ * canonical API schemas, while providers that further transform a schema can
182
+ * reapply it at their own emission boundary.
183
+ */
184
+ function deduplicateJsonSchemaRequiredArrays(schema) {
185
+ const seenSchemaValues = /* @__PURE__ */ new WeakMap();
186
+ const seenInstanceValues = /* @__PURE__ */ new WeakMap();
187
+ const instanceValueKeywords = /* @__PURE__ */ new Set([
188
+ "const",
189
+ "default",
190
+ "enum",
191
+ "examples"
192
+ ]);
193
+ function walk(value, isSchema, depth = 0) {
194
+ if (depth > MAX_NODE_DEPTH) throw new RangeError(`JSON Schema exceeds maximum nesting depth of ${MAX_NODE_DEPTH}`);
195
+ const seen = isSchema ? seenSchemaValues : seenInstanceValues;
196
+ if (Array.isArray(value)) {
197
+ const existing = seen.get(value);
198
+ if (existing) return existing;
199
+ const clone = [];
200
+ seen.set(value, clone);
201
+ for (const item of value) clone.push(walk(item, isSchema, depth + 1));
202
+ return clone;
203
+ }
204
+ if (!isPlainObject(value)) return value;
205
+ const existing = seen.get(value);
206
+ if (existing) return existing;
207
+ const clone = {};
208
+ seen.set(value, clone);
209
+ for (const [key, child] of Object.entries(value)) Object.defineProperty(clone, key, {
210
+ configurable: true,
211
+ enumerable: true,
212
+ value: isSchema && key === "required" && Array.isArray(child) ? [...new Set(walk(child, false, depth + 1))] : walk(child, isSchema && !instanceValueKeywords.has(key), depth + 1),
213
+ writable: true
214
+ });
215
+ return clone;
216
+ }
217
+ return walk(schema, true);
218
+ }
219
+ /**
190
220
  * Removes all non-required properties from the schema
191
221
  *
192
222
  * if no items are required, the schema is returned as is
@@ -248,4 +278,19 @@ function jsonSchemaToZodSchema(jsonSchema, { strict } = { strict: false }) {
248
278
  }
249
279
 
250
280
  //#endregion
251
- export { withCancellation as i, jsonSchemaToZodSchema as n, removeNonRequiredProperties as r, dereferenceJsonSchema as t };
281
+ //#region src/utils/cancellation.ts
282
+ /** @internal */
283
+ async function withCancellation(call, signal) {
284
+ try {
285
+ return await call();
286
+ } catch (error) {
287
+ if (signal?.aborted && isRequestAbortError(error)) {
288
+ const underlyingMessage = error instanceof Error ? error.message : "";
289
+ throw new ComposioRequestCancelledError(underlyingMessage ? `Request was cancelled by the caller: ${underlyingMessage}` : "Request was cancelled by the caller", { cause: error instanceof Error ? error : void 0 });
290
+ }
291
+ throw error;
292
+ }
293
+ }
294
+
295
+ //#endregion
296
+ export { removeNonRequiredProperties as a, jsonSchemaToZodSchema as i, deduplicateJsonSchemaRequiredArrays as n, dereferenceJsonSchema as r, withCancellation as t };