@composio/core 0.16.0 → 0.18.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 (51) hide show
  1. package/dist/{CustomTool-Bk38kFp0.d.mts → CustomTool-BKhHv2hJ.d.mts} +1 -1
  2. package/dist/{CustomTool-l-j5HtEf.mjs → CustomTool-C4tv-GL1.mjs} +1 -1
  3. package/dist/FileToolModifier.utils.neutral-D_YkHwZP.mjs +188 -0
  4. package/dist/{Telemetry-DuGJSwUt.mjs → Telemetry-CBtSnWrm.mjs} +27 -11
  5. package/dist/cancellation-jUVItfHw.mjs +704 -0
  6. package/dist/{composio-DSs-1AhC.d.mts → composio-CldtZUyC.d.mts} +254 -247
  7. package/dist/{BaseProvider-D7p2OPEx.d.mts → customTool.types-DC5fPOOi.d.mts} +2954 -82
  8. package/dist/docs/reference/sdk-reference/typescript/session-files.mdx +1 -1
  9. package/dist/{errors-BcEUHZbq.mjs → errors-DyZt79fi.mjs} +3 -0
  10. package/dist/experimental/index.d.mts +2 -2
  11. package/dist/experimental/index.mjs +1 -1
  12. package/dist/{fileUtils.node-BQ0fWge3.mjs → fileUtils.node-BwpUOF0s.mjs} +4 -4
  13. package/dist/index.d.mts +105 -7
  14. package/dist/index.mjs +94 -116
  15. package/dist/models/Files.node.mjs +2 -2
  16. package/dist/{sensitiveFileUploadPaths-BVEt0peg.mjs → sensitiveFileUploadPaths-B0w8dqpv.mjs} +23 -6
  17. package/dist/ssrfGuard.node-DlxO8uzr.mjs +307 -0
  18. package/dist/{types-B4k-qoOf.d.mts → types-BgsRW-XH.d.mts} +2 -2
  19. package/dist/utils/config-defaults/ConfigDefaults.node.d.mts +1 -1
  20. package/dist/utils/config-defaults/ConfigDefaults.workerd.d.mts +1 -1
  21. package/dist/utils/modifiers/FileToolModifier.node.d.mts +1 -1
  22. package/dist/utils/modifiers/FileToolModifier.node.mjs +57 -101
  23. package/dist/utils/modifiers/FileToolModifier.workerd.d.mts +1 -1
  24. package/dist/utils/modifiers/FileToolModifier.workerd.mjs +1 -1
  25. package/dist/utils/ssrfGuard.node.d.mts +25 -6
  26. package/dist/utils/ssrfGuard.node.mjs +2 -152
  27. package/dist/utils/ssrfGuard.workerd.d.mts +13 -1
  28. package/dist/utils/ssrfGuard.workerd.mjs +13 -1
  29. package/package.json +8 -4
  30. package/src/errors/ToolErrors.ts +1 -0
  31. package/src/errors/ValidationErrors.ts +2 -0
  32. package/src/index.ts +6 -0
  33. package/src/models/RemoteFile.ts +7 -2
  34. package/src/models/ToolRouterSession.ts +36 -8
  35. package/src/models/ToolRouterSessionFileMount.ts +14 -8
  36. package/src/models/Tools.ts +102 -39
  37. package/src/provider/BaseProvider.ts +53 -1
  38. package/src/provider/OpenAIProvider.ts +43 -15
  39. package/src/services/telemetry/TelemetryService.ts +27 -12
  40. package/src/types/provider.types.ts +15 -0
  41. package/src/utils/fileUtils.node.ts +8 -2
  42. package/src/utils/jsonSchema.ts +505 -27
  43. package/src/utils/modifiers/FileToolModifier.node.ts +85 -181
  44. package/src/utils/modifiers/FileToolModifier.utils.neutral.ts +199 -0
  45. package/src/utils/pinnedDispatcher.node.ts +118 -0
  46. package/src/utils/sensitiveFileUploadPaths.ts +36 -9
  47. package/src/utils/ssrfGuard.node.ts +100 -11
  48. package/src/utils/ssrfGuard.workerd.ts +16 -0
  49. package/dist/FileToolModifier.utils.neutral-B5rT711M.mjs +0 -72
  50. package/dist/cancellation-NVtGf3St.mjs +0 -364
  51. package/dist/customTool.types-cGHcIBX-.d.mts +0 -2859
@@ -1,4 +1,4 @@
1
- import { a as CreateCustomToolkitParams, f as CustomToolkit, o as CustomTool, r as CreateCustomToolParams, t as AnyZodSchema } from "./customTool.types-cGHcIBX-.mjs";
1
+ import { a as CreateCustomToolkitParams, f as CustomToolkit, o as CustomTool, r as CreateCustomToolParams, t as AnyZodSchema } from "./customTool.types-DC5fPOOi.mjs";
2
2
  import { SessionCreateResponse } from "@composio/client/resources/tool-router/session/session.mjs";
3
3
  //#region src/models/CustomTool.d.ts
4
4
  /**
@@ -1,4 +1,4 @@
1
- import { _ as ValidationError } from "./errors-BcEUHZbq.mjs";
1
+ import { _ as ValidationError } from "./errors-DyZt79fi.mjs";
2
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";
@@ -0,0 +1,188 @@
1
+ //#region src/utils/modifiers/FileToolModifier.utils.neutral.ts
2
+ function isPlainObject(val) {
3
+ return typeof val === "object" && val !== null && !Array.isArray(val);
4
+ }
5
+ /**
6
+ * Transforms a single JSON schema property, recursively handling nested properties,
7
+ * anyOf, oneOf, and allOf.
8
+ */
9
+ const transformSchema = (property) => {
10
+ if (property.file_uploadable) return {
11
+ title: property.title,
12
+ description: property.description,
13
+ format: "path",
14
+ type: "string",
15
+ file_uploadable: true
16
+ };
17
+ const newProperty = { ...property };
18
+ if (property.type === "object" && property.properties) newProperty.properties = transformProperties(property.properties);
19
+ if (property.anyOf) newProperty.anyOf = property.anyOf.map(transformSchema);
20
+ if (property.oneOf) newProperty.oneOf = property.oneOf.map(transformSchema);
21
+ if (property.allOf) newProperty.allOf = property.allOf.map(transformSchema);
22
+ if (property.items) if (Array.isArray(property.items)) newProperty.items = property.items.map(transformSchema);
23
+ else newProperty.items = transformSchema(property.items);
24
+ return newProperty;
25
+ };
26
+ /**
27
+ * Transforms the properties of the tool schema to include the file upload URL.
28
+ *
29
+ * Attaches the format: 'path' to the properties that are file uploadable for agents.
30
+ *
31
+ * @param properties - The properties of the tool schema.
32
+ * @returns The transformed properties.
33
+ */
34
+ const transformProperties = (properties) => {
35
+ const newProperties = {};
36
+ for (const [key, property] of Object.entries(properties)) newProperties[key] = transformSchema(property);
37
+ return newProperties;
38
+ };
39
+ /**
40
+ * Recursively checks if a schema (or any of its variants) contains a specific file property.
41
+ */
42
+ const schemaHasFileProperty = (schema, property) => {
43
+ if (!schema) return false;
44
+ if (schema[property]) return true;
45
+ if (schema.properties) {
46
+ for (const prop of Object.values(schema.properties)) if (schemaHasFileProperty(prop, property)) return true;
47
+ }
48
+ if (schema.anyOf) {
49
+ for (const variant of schema.anyOf) if (schemaHasFileProperty(variant, property)) return true;
50
+ }
51
+ if (schema.oneOf) {
52
+ for (const variant of schema.oneOf) if (schemaHasFileProperty(variant, property)) return true;
53
+ }
54
+ if (schema.allOf) {
55
+ for (const variant of schema.allOf) if (schemaHasFileProperty(variant, property)) return true;
56
+ }
57
+ if (schema.items) {
58
+ if (Array.isArray(schema.items)) {
59
+ for (const item of schema.items) if (schemaHasFileProperty(item, property)) return true;
60
+ } else if (schemaHasFileProperty(schema.items, property)) return true;
61
+ }
62
+ for (const definitions of [schema.$defs, schema.definitions]) {
63
+ if (!definitions) continue;
64
+ for (const definition of Object.values(definitions)) if (schemaHasFileProperty(definition, property)) return true;
65
+ }
66
+ return false;
67
+ };
68
+ /**
69
+ * Recursively checks if a schema (or any of its variants) contains file_uploadable properties.
70
+ */
71
+ const schemaHasFileUploadable = (schema) => {
72
+ return schemaHasFileProperty(schema, "file_uploadable");
73
+ };
74
+ /**
75
+ * Sentinel a leaf handler returns to have {@link walkFileUploadableLeaves}
76
+ * omit that key/item from its parent container. `''` and `null` are legal
77
+ * payload values, so neither can double as "remove this".
78
+ */
79
+ const DELETE_VALUE = Symbol("composio.delete-value");
80
+ /**
81
+ * `''` at a `file_uploadable` leaf means "no file": it is never a staged
82
+ * `{ name, mimetype, s3key }` descriptor, so the backend rejects it with a
83
+ * validation error, while callers (and the playground UI) mean "absent". The
84
+ * walker omits the key instead. `null` is left alone — schemas with a `null`
85
+ * variant accept it, and the backend reports the mismatch otherwise.
86
+ */
87
+ const isEmptyFileValue = (value) => value === "";
88
+ const getSchemaVariants = (schema) => [
89
+ ...schema?.anyOf ?? [],
90
+ ...schema?.oneOf ?? [],
91
+ ...schema?.allOf ?? []
92
+ ];
93
+ /** Best-effort runtime shape match for selecting composed schema variants. */
94
+ const jsonSchemaTypeMatchesValue = (schema, value) => {
95
+ const schemaType = schema.type;
96
+ if (Array.isArray(schemaType)) return schemaType.some((type) => jsonSchemaTypeMatchesValue({
97
+ ...schema,
98
+ type
99
+ }, value));
100
+ if (schemaType === void 0) {
101
+ if (schema.properties) return isPlainObject(value);
102
+ if (schema.items) return Array.isArray(value);
103
+ return false;
104
+ }
105
+ switch (schemaType) {
106
+ case "array": return Array.isArray(value);
107
+ case "object": return isPlainObject(value);
108
+ case "string": return typeof value === "string";
109
+ case "integer": return Number.isInteger(value);
110
+ case "number": return typeof value === "number";
111
+ case "boolean": return typeof value === "boolean";
112
+ case "null": return value === null;
113
+ default: return false;
114
+ }
115
+ };
116
+ /** Mirrors the array-shape inference used by {@link jsonSchemaTypeMatchesValue}. */
117
+ const isArrayShapedSchema = (schema) => {
118
+ if (!schema) return false;
119
+ if (Array.isArray(schema.type)) return schema.type.includes("array");
120
+ return schema.type === "array" || schema.type === void 0 && schema.items !== void 0;
121
+ };
122
+ /** Mirrors the object-shape inference used by {@link jsonSchemaTypeMatchesValue}. */
123
+ const isObjectShapedSchema = (schema) => {
124
+ if (!schema) return false;
125
+ if (Array.isArray(schema.type)) return schema.type.includes("object");
126
+ return schema.type === "object" || schema.type === void 0 && schema.properties !== void 0;
127
+ };
128
+ /**
129
+ * Picks the file-bearing `anyOf`/`oneOf`/`allOf` variant whose JSON Schema
130
+ * shape matches the runtime value, falling back to the first file-bearing
131
+ * variant to preserve historical behavior.
132
+ */
133
+ const findSchemaVariantWithFileProperty = (schema, property, value) => {
134
+ const candidates = getSchemaVariants(schema).filter((variant) => schemaHasFileProperty(variant, property));
135
+ return candidates.find((candidate) => jsonSchemaTypeMatchesValue(candidate, value)) ?? candidates[0];
136
+ };
137
+ /**
138
+ * Recursively walks a runtime value alongside its (already dereferenced)
139
+ * JSON-Schema node and passes every value sitting at a `file_uploadable`
140
+ * node through `leaf`. A leaf returning {@link DELETE_VALUE} is omitted from
141
+ * its parent object/array. Returns a **new** value; nothing is mutated.
142
+ *
143
+ * Composed schemas are resolved to the single file-bearing variant whose
144
+ * shape matches the value: with `oneOf`, exactly one variant should apply at
145
+ * runtime, and applying several would stage the same file once per variant.
146
+ */
147
+ const walkFileUploadableLeaves = async (value, schema, leaf) => {
148
+ if (schema?.file_uploadable) return leaf(value);
149
+ const uploadableVariant = findSchemaVariantWithFileProperty(schema, "file_uploadable", value);
150
+ if (uploadableVariant) {
151
+ const matchingNonFileVariant = getSchemaVariants(schema).some((variant) => !schemaHasFileProperty(variant, "file_uploadable") && jsonSchemaTypeMatchesValue(variant, value));
152
+ if (isEmptyFileValue(value) && isArrayShapedSchema(uploadableVariant) && !matchingNonFileVariant) return leaf(value);
153
+ return walkFileUploadableLeaves(value, uploadableVariant, leaf);
154
+ }
155
+ if (isEmptyFileValue(value) && isArrayShapedSchema(schema) && schemaHasFileProperty(schema, "file_uploadable")) return leaf(value);
156
+ if (isObjectShapedSchema(schema) && schema?.properties && isPlainObject(value)) {
157
+ const transformed = {};
158
+ for (const [k, v] of Object.entries(value)) {
159
+ const propertySchema = Object.hasOwn(schema.properties, k) ? schema.properties[k] : void 0;
160
+ const walked = await walkFileUploadableLeaves(v, propertySchema, leaf);
161
+ if (walked !== DELETE_VALUE) Object.defineProperty(transformed, k, {
162
+ configurable: true,
163
+ enumerable: true,
164
+ value: walked,
165
+ writable: true
166
+ });
167
+ }
168
+ return transformed;
169
+ }
170
+ if (isArrayShapedSchema(schema) && schema?.items && Array.isArray(value)) {
171
+ const itemSchema = Array.isArray(schema.items) ? schema.items[0] : schema.items;
172
+ return (await Promise.all(value.map((item) => walkFileUploadableLeaves(item, itemSchema, leaf)))).filter((item) => item !== DELETE_VALUE);
173
+ }
174
+ return value;
175
+ };
176
+ /**
177
+ * Omits `''` at `file_uploadable` leaves of `args` without uploading
178
+ * anything. This is the schema-aware half of the upload modifier that needs
179
+ * no filesystem access, so it also runs when automatic upload is disabled:
180
+ * an empty file value is never a valid staged descriptor and the backend
181
+ * would reject it (https://github.com/ComposioHQ/composio/issues/4233).
182
+ * Any other value — a local path, a staged descriptor, a list — is
183
+ * forwarded untouched.
184
+ */
185
+ const dropEmptyFileUploads = (args, schema) => walkFileUploadableLeaves(args, schema, async (value) => isEmptyFileValue(value) ? DELETE_VALUE : value);
186
+
187
+ //#endregion
188
+ export { isEmptyFileValue as a, transformProperties as c, getSchemaVariants as i, walkFileUploadableLeaves as l, dropEmptyFileUploads as n, isPlainObject as o, findSchemaVariantWithFileProperty as r, schemaHasFileUploadable as s, DELETE_VALUE as t };
@@ -1,5 +1,5 @@
1
1
  import { i as logger, p as getEnvVariable, r as ComposioError$1 } from "./SsrfErrors-DNJt57GL.mjs";
2
- import { l as getRandomUUID } from "./sensitiveFileUploadPaths-BVEt0peg.mjs";
2
+ import { l as getRandomUUID } from "./sensitiveFileUploadPaths-B0w8dqpv.mjs";
3
3
  import { ComposioError } from "@composio/client";
4
4
 
5
5
  //#region src/types/telemetry.types.ts
@@ -64,7 +64,31 @@ var BatchProcessor = class {
64
64
  //#endregion
65
65
  //#region src/services/telemetry/TelemetryService.ts
66
66
  const TELEMETRY_URL = "https://telemetry.composio.dev/v1";
67
+ const TELEMETRY_TIMEOUT_MS = 3e3;
67
68
  var TelemetryService = class {
69
+ /**
70
+ * POSTs a best-effort telemetry payload, bounding the request so a stalled
71
+ * endpoint cannot leave it pending indefinitely.
72
+ *
73
+ * A hand-rolled timer rather than AbortSignal.timeout so it can be cleared the
74
+ * moment the response lands: an uncleared timer is itself pending work, which on
75
+ * workerd pins the request context open for the full timeout on every successful
76
+ * send. Mirrors the bound applied to the npm version check.
77
+ */
78
+ static async postWithTimeout(url, payload) {
79
+ const controller = new AbortController();
80
+ const timer = setTimeout(() => controller.abort(), TELEMETRY_TIMEOUT_MS);
81
+ try {
82
+ return await fetch(url, {
83
+ method: "POST",
84
+ headers: { "Content-Type": "application/json" },
85
+ body: JSON.stringify(payload),
86
+ signal: controller.signal
87
+ });
88
+ } finally {
89
+ clearTimeout(timer);
90
+ }
91
+ }
68
92
  /**
69
93
  * Sends a metric to the Telemetry API.
70
94
  * @param payload - The payload to send to the Telemetry API.
@@ -72,11 +96,7 @@ var TelemetryService = class {
72
96
  */
73
97
  static async sendMetric(payload) {
74
98
  try {
75
- return await fetch(`${TELEMETRY_URL}/metrics/invocations`, {
76
- method: "POST",
77
- headers: { "Content-Type": "application/json" },
78
- body: JSON.stringify(payload)
79
- });
99
+ return await this.postWithTimeout(`${TELEMETRY_URL}/metrics/invocations`, payload);
80
100
  } catch (error) {
81
101
  logger.debug("Error sending metric telemetry", error);
82
102
  }
@@ -88,11 +108,7 @@ var TelemetryService = class {
88
108
  */
89
109
  static async sendErrorLog(payload) {
90
110
  try {
91
- return await fetch(`${TELEMETRY_URL}/errors`, {
92
- method: "POST",
93
- headers: { "Content-Type": "application/json" },
94
- body: JSON.stringify(payload)
95
- });
111
+ return await this.postWithTimeout(`${TELEMETRY_URL}/errors`, payload);
96
112
  } catch (error) {
97
113
  logger.debug("Error sending error telemetry", error);
98
114
  }