@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,364 +0,0 @@
1
- import { i as logger } from "./SsrfErrors-DNJt57GL.mjs";
2
- import { f as ComposioRequestCancelledError, g as JsonSchemaToZodError, h as JsonSchemaRefResolutionError, m as isRequestAbortError } from "./errors-BcEUHZbq.mjs";
3
- import { t as isPlainObject } from "./FileToolModifier.utils.neutral-B5rT711M.mjs";
4
- import { jsonSchemaToZod } from "@composio/json-schema-to-zod";
5
-
6
- //#region src/utils/jsonSchema.ts
7
- const MAX_REF_CHAIN_DEPTH = 100;
8
- const MAX_NODE_DEPTH = 512;
9
- const CYCLE_BREAK_SENTINEL = {
10
- type: "object",
11
- additionalProperties: true
12
- };
13
- /**
14
- * In-band hint attached to the cycle-break sentinel when lenient mode
15
- * substitutes it for a dangling `$ref`. Makes the degradation visible to
16
- * LLMs that read the wrapped tool's schema — without it the LLM sees a
17
- * useless permissive object and no prose context. Wording is intentionally
18
- * context-neutral ("Schema shape", not "Output shape") because the helper
19
- * is used for both `inputParameters` and `outputParameters`. Overridden
20
- * when the caller's `$ref` node carries its own `description` sibling
21
- * (Draft 2020-12 sibling-keyword semantics).
22
- */
23
- const UNRESOLVED_REF_DESCRIPTION = "Schema shape unresolved at the source — validate loosely. See https://github.com/ComposioHQ/composio/issues/3307.";
24
- const POLLUTING_KEYS = /* @__PURE__ */ new Set([
25
- "__proto__",
26
- "constructor",
27
- "prototype"
28
- ]);
29
- const REF_RESOLUTION_FIXES = ["Ensure the $ref pointer matches a path in $defs or definitions", "External $ref pointers (http://, https://, file://, …) are not resolved by the SDK"];
30
- const decodePointerSegment = (segment) => segment.replace(/~1/g, "/").replace(/~0/g, "~");
31
- const tryStep = (cursor, segment) => {
32
- if (cursor === null || typeof cursor !== "object") return {
33
- kind: "unresolved",
34
- reason: "missing-target",
35
- failedAt: segment
36
- };
37
- if (Array.isArray(cursor)) {
38
- const i = Number(segment);
39
- if (!Number.isInteger(i) || i < 0 || i >= cursor.length) return {
40
- kind: "unresolved",
41
- reason: "missing-target",
42
- failedAt: segment
43
- };
44
- return {
45
- kind: "ok",
46
- value: cursor[i]
47
- };
48
- }
49
- const obj = cursor;
50
- if (!Object.prototype.hasOwnProperty.call(obj, segment)) return {
51
- kind: "unresolved",
52
- reason: "missing-target",
53
- failedAt: segment
54
- };
55
- return {
56
- kind: "ok",
57
- value: obj[segment]
58
- };
59
- };
60
- const tryResolvePointer = (root, pointer) => {
61
- if (pointer === "#" || pointer === "") return {
62
- kind: "ok",
63
- value: root
64
- };
65
- if (!pointer.startsWith("#/")) return {
66
- kind: "unresolved",
67
- reason: "malformed-pointer"
68
- };
69
- const segments = pointer.slice(2).split("/").map(decodePointerSegment);
70
- let cursor = root;
71
- for (const seg of segments) {
72
- const step = tryStep(cursor, seg);
73
- if (step.kind === "unresolved") return step;
74
- cursor = step.value;
75
- }
76
- return {
77
- kind: "ok",
78
- value: cursor
79
- };
80
- };
81
- const throwResolutionError = (pointer, result) => {
82
- if (result.reason === "malformed-pointer") throw new JsonSchemaRefResolutionError(`Unsupported $ref pointer: ${pointer}`, {
83
- meta: { ref: pointer },
84
- possibleFixes: REF_RESOLUTION_FIXES
85
- });
86
- throw new JsonSchemaRefResolutionError(`Cannot resolve $ref ${pointer}`, {
87
- meta: {
88
- ref: pointer,
89
- ...result.failedAt !== void 0 ? { failedAt: result.failedAt } : {}
90
- },
91
- possibleFixes: REF_RESOLUTION_FIXES
92
- });
93
- };
94
- /**
95
- * Inlines internal JSON Schema `$ref` pointers (`#/$defs/...` and legacy
96
- * `#/definitions/...`) so the returned schema can be safely handed to
97
- * consumers that don't tolerate unresolved references (e.g. AJV in
98
- * `@mastra/schema-compat`). External (`http://`, `https://`, …) refs are
99
- * left untouched. Cycles are broken with `{ type: 'object',
100
- * additionalProperties: true }`. The input is never mutated.
101
- *
102
- * By default, unresolved internal refs throw `JsonSchemaRefResolutionError`.
103
- * Pass `{ onUnresolved: 'sentinel' }` to replace the offending node with the
104
- * cycle-break sentinel instead — appropriate for schemas sourced from an
105
- * upstream service the caller cannot edit (the Composio API ships some
106
- * `outputParameters` with a `$ref` into `#/$defs/...` but never declares
107
- * `$defs`; see https://github.com/ComposioHQ/composio/issues/3307).
108
- *
109
- * @throws {JsonSchemaRefResolutionError} on malformed pointers, missing
110
- * targets (strict mode only), or chains past the depth cap (both modes).
111
- */
112
- function dereferenceJsonSchema(schema, options) {
113
- if (!isPlainObject(schema)) return schema;
114
- const strategy = options?.onUnresolved ?? "throw";
115
- const onReplace = options?.onReplace;
116
- const root = schema;
117
- const visiting = /* @__PURE__ */ new WeakSet();
118
- const cloneChildren = (obj, visitedRefs, chainDepth, nodeDepth) => Object.fromEntries(Object.entries(obj).filter(([k]) => !POLLUTING_KEYS.has(k)).map(([k, v]) => [k, walk(v, visitedRefs, chainDepth, nodeDepth + 1)]));
119
- function walk(node, visitedRefs, chainDepth, nodeDepth) {
120
- if (nodeDepth >= MAX_NODE_DEPTH) throw new JsonSchemaRefResolutionError(`JSON Schema node depth exceeded cap (${MAX_NODE_DEPTH})`, { possibleFixes: REF_RESOLUTION_FIXES });
121
- if (Array.isArray(node)) {
122
- if (visiting.has(node)) return { ...CYCLE_BREAK_SENTINEL };
123
- visiting.add(node);
124
- try {
125
- return node.map((item) => walk(item, visitedRefs, chainDepth, nodeDepth + 1));
126
- } finally {
127
- visiting.delete(node);
128
- }
129
- }
130
- if (!isPlainObject(node)) return node;
131
- if (visiting.has(node)) return { ...CYCLE_BREAK_SENTINEL };
132
- visiting.add(node);
133
- try {
134
- const ref = typeof node.$ref === "string" ? node.$ref : null;
135
- if (ref === null || !ref.startsWith("#")) {
136
- if (ref !== null) logger.warn(`Leaving external $ref untouched: ${ref}`);
137
- return cloneChildren(node, visitedRefs, chainDepth, nodeDepth);
138
- }
139
- if (chainDepth >= MAX_REF_CHAIN_DEPTH) throw new JsonSchemaRefResolutionError(`JSON Schema $ref chain exceeded depth cap (${MAX_REF_CHAIN_DEPTH}): ${ref}`, {
140
- meta: { ref },
141
- possibleFixes: REF_RESOLUTION_FIXES
142
- });
143
- if (visitedRefs.has(ref)) return { ...CYCLE_BREAK_SENTINEL };
144
- const result = tryResolvePointer(root, ref);
145
- let target;
146
- if (result.kind === "ok") target = result.value;
147
- else if (strategy === "sentinel") {
148
- onReplace?.(ref, result.reason);
149
- target = {
150
- ...CYCLE_BREAK_SENTINEL,
151
- description: UNRESOLVED_REF_DESCRIPTION
152
- };
153
- } else throwResolutionError(ref, result);
154
- const nextRefs = new Set(visitedRefs).add(ref);
155
- const resolved = walk(target, nextRefs, chainDepth + 1, nodeDepth + 1);
156
- const siblings = { ...node };
157
- delete siblings.$ref;
158
- if (Object.keys(siblings).length === 0 || !isPlainObject(resolved)) return resolved;
159
- return {
160
- ...resolved,
161
- ...cloneChildren(siblings, visitedRefs, chainDepth, nodeDepth)
162
- };
163
- } finally {
164
- visiting.delete(node);
165
- }
166
- }
167
- const out = walk(root, /* @__PURE__ */ new Set(), 0, 0);
168
- if (isPlainObject(out)) {
169
- delete out.$defs;
170
- delete out.definitions;
171
- }
172
- return out;
173
- }
174
- /**
175
- * Returns a deep-cloned JSON Schema in which every node that carries a
176
- * `properties` keyword also carries `type: "object"` when it has no explicit
177
- * `type`. OpenAI tolerates the omission, but Google Gemini enforces OpenAPI
178
- * 3.0 strictly and rejects function declarations whose nested objects are
179
- * missing the `type` (see https://github.com/ComposioHQ/composio/issues/4022).
180
- *
181
- * The function follows JSON Schema's schema-bearing keywords while keeping
182
- * property maps and instance values as containers. Nodes that already declare
183
- * a `type` are left untouched.
184
- */
185
- function ensureObjectTypeOnProperties(schema) {
186
- const schemaKeywords = /* @__PURE__ */ new Set([
187
- "additionalItems",
188
- "additionalProperties",
189
- "contains",
190
- "contentSchema",
191
- "else",
192
- "if",
193
- "not",
194
- "propertyNames",
195
- "then",
196
- "unevaluatedItems",
197
- "unevaluatedProperties"
198
- ]);
199
- const schemaArrayKeywords = /* @__PURE__ */ new Set([
200
- "allOf",
201
- "anyOf",
202
- "oneOf",
203
- "prefixItems"
204
- ]);
205
- const schemaMapKeywords = /* @__PURE__ */ new Set([
206
- "$defs",
207
- "definitions",
208
- "dependentSchemas",
209
- "patternProperties",
210
- "properties"
211
- ]);
212
- function walk(value, mode, depth = 0) {
213
- if (depth > MAX_NODE_DEPTH) throw new RangeError(`JSON Schema exceeds maximum nesting depth of ${MAX_NODE_DEPTH}`);
214
- if (Array.isArray(value)) {
215
- const itemMode = mode === "schema-array" ? "schema" : "value";
216
- return value.map((item) => walk(item, itemMode, depth + 1));
217
- }
218
- if (!isPlainObject(value)) return value;
219
- const clone = {};
220
- for (const [key, child] of Object.entries(value)) {
221
- let childMode = "value";
222
- if (mode === "schema-map") childMode = "schema";
223
- else if (mode === "dependencies-map") childMode = Array.isArray(child) ? "value" : "schema";
224
- else if (mode === "schema") {
225
- if (schemaMapKeywords.has(key)) childMode = "schema-map";
226
- else if (schemaArrayKeywords.has(key) || key === "items" && Array.isArray(child)) childMode = "schema-array";
227
- else if (schemaKeywords.has(key) || key === "items") childMode = "schema";
228
- else if (key === "dependencies") childMode = "dependencies-map";
229
- }
230
- Object.defineProperty(clone, key, {
231
- configurable: true,
232
- enumerable: true,
233
- value: walk(child, childMode, depth + 1),
234
- writable: true
235
- });
236
- }
237
- if (mode === "schema" && clone.properties !== void 0 && clone.type === void 0) clone.type = "object";
238
- return clone;
239
- }
240
- return walk(schema, "schema");
241
- }
242
- /**
243
- * Returns a deep-cloned JSON Schema whose `required` arrays contain each entry
244
- * at most once. Duplicate entries are invalid in JSON Schema 2020-12 but do
245
- * not change the schema's meaning, so preserving the first occurrence is safe.
246
- *
247
- * Tool schemas originate both from the Composio API and direct provider calls.
248
- * Keeping this normalization provider-agnostic lets every SDK provider receive
249
- * canonical API schemas, while providers that further transform a schema can
250
- * reapply it at their own emission boundary.
251
- */
252
- function deduplicateJsonSchemaRequiredArrays(schema) {
253
- const seenSchemaValues = /* @__PURE__ */ new WeakMap();
254
- const seenInstanceValues = /* @__PURE__ */ new WeakMap();
255
- const instanceValueKeywords = /* @__PURE__ */ new Set([
256
- "const",
257
- "default",
258
- "enum",
259
- "examples"
260
- ]);
261
- function walk(value, isSchema, depth = 0) {
262
- if (depth > MAX_NODE_DEPTH) throw new RangeError(`JSON Schema exceeds maximum nesting depth of ${MAX_NODE_DEPTH}`);
263
- const seen = isSchema ? seenSchemaValues : seenInstanceValues;
264
- if (Array.isArray(value)) {
265
- const existing = seen.get(value);
266
- if (existing) return existing;
267
- const clone = [];
268
- seen.set(value, clone);
269
- for (const item of value) clone.push(walk(item, isSchema, depth + 1));
270
- return clone;
271
- }
272
- if (!isPlainObject(value)) return value;
273
- const existing = seen.get(value);
274
- if (existing) return existing;
275
- const clone = {};
276
- seen.set(value, clone);
277
- for (const [key, child] of Object.entries(value)) Object.defineProperty(clone, key, {
278
- configurable: true,
279
- enumerable: true,
280
- value: isSchema && key === "required" && Array.isArray(child) ? [...new Set(walk(child, false, depth + 1))] : walk(child, isSchema && !instanceValueKeywords.has(key), depth + 1),
281
- writable: true
282
- });
283
- return clone;
284
- }
285
- return walk(schema, true);
286
- }
287
- /**
288
- * Removes all non-required properties from the schema
289
- *
290
- * if no items are required, the schema is returned as is
291
- * @param schema - The JSON schema to remove non-required properties from
292
- * @returns The JSON schema with all non-required properties removed
293
- */
294
- const removeNonRequiredProperties = (schema) => {
295
- if (schema && schema.type === "object" && schema.required?.length) schema.properties = Object.fromEntries(Object.entries(schema.properties || {}).filter(([key]) => schema.required.includes(key)));
296
- schema.additionalProperties = false;
297
- return schema;
298
- };
299
- /**
300
- * Convert a JSON schema to a Zod schema
301
- * @param jsonSchema - The JSON schema to convert
302
- * @param strict - Eliminates all non-required properties from the schema
303
- * @returns The Zod schema
304
- *
305
- * @throws {JsonSchemaToZodError} If the JSON schema is invalid
306
- *
307
- * @example
308
- * ```ts
309
- * const zodSchema = jsonSchemaToZodSchema({
310
- * type: 'object',
311
- * properties: {
312
- * name: { type: 'string' },
313
- * },
314
- * });
315
- *
316
- * console.log(zodSchema);
317
- * ```
318
- *
319
- * @example
320
- * ```ts
321
- * const zodSchema = jsonSchemaToZodSchema({
322
- * type: 'object',
323
- * properties: {
324
- * name: { type: 'string' },
325
- * age: { type: 'number' },
326
- * },
327
- * required: ['name'],
328
- * }, { strict: true });
329
- *
330
- * console.log(zodSchema);
331
- *
332
- * // Output:
333
- * // z.object({
334
- * // name: z.string(),
335
- * // })
336
- * ```
337
- */
338
- function jsonSchemaToZodSchema(jsonSchema, { strict } = { strict: false }) {
339
- try {
340
- let schema = jsonSchema;
341
- if (strict && schema) schema = removeNonRequiredProperties(schema);
342
- return jsonSchemaToZod(schema);
343
- } catch (error) {
344
- throw new JsonSchemaToZodError("Failed to convert JSON Schema to Zod Schema", { cause: error });
345
- }
346
- }
347
-
348
- //#endregion
349
- //#region src/utils/cancellation.ts
350
- /** @internal */
351
- async function withCancellation(call, signal) {
352
- try {
353
- return await call();
354
- } catch (error) {
355
- if (signal?.aborted && isRequestAbortError(error)) {
356
- const underlyingMessage = error instanceof Error ? error.message : "";
357
- throw new ComposioRequestCancelledError(underlyingMessage ? `Request was cancelled by the caller: ${underlyingMessage}` : "Request was cancelled by the caller", { cause: error instanceof Error ? error : void 0 });
358
- }
359
- throw error;
360
- }
361
- }
362
-
363
- //#endregion
364
- export { jsonSchemaToZodSchema as a, ensureObjectTypeOnProperties as i, deduplicateJsonSchemaRequiredArrays as n, removeNonRequiredProperties as o, dereferenceJsonSchema as r, withCancellation as t };