@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.
- package/dist/{CustomTool-Uip-fhPw.d.mts → CustomTool-CwpeQhz2.d.mts} +1 -1
- package/dist/FileToolModifier.utils.neutral-D_YkHwZP.mjs +188 -0
- package/dist/{Telemetry-DuGJSwUt.mjs → Telemetry-DK1uAWnD.mjs} +1 -1
- package/dist/{cancellation-NVtGf3St.mjs → cancellation-C-qy8rcj.mjs} +1 -1
- package/dist/{composio-B27X6i6A.d.mts → composio-XjF7EMEe.d.mts} +256 -250
- package/dist/{customTool.types-B2Ava_j5.d.mts → customTool.types-DpJbYY5m.d.mts} +167 -167
- package/dist/experimental/index.d.mts +2 -2
- package/dist/{fileUtils.node-B1Wn848p.mjs → fileUtils.node-BwpUOF0s.mjs} +2 -2
- package/dist/index.d.mts +6 -5
- package/dist/index.mjs +58 -24
- package/dist/models/Files.node.mjs +2 -2
- package/dist/{sensitiveFileUploadPaths-BVEt0peg.mjs → sensitiveFileUploadPaths-B0w8dqpv.mjs} +23 -6
- package/dist/ssrfGuard.node-DlxO8uzr.mjs +307 -0
- package/dist/{types-DdZJuMm2.d.mts → types-C9kJAurw.d.mts} +2 -2
- package/dist/utils/config-defaults/ConfigDefaults.node.d.mts +1 -1
- package/dist/utils/config-defaults/ConfigDefaults.workerd.d.mts +1 -1
- package/dist/utils/modifiers/FileToolModifier.node.d.mts +1 -1
- package/dist/utils/modifiers/FileToolModifier.node.mjs +56 -100
- package/dist/utils/modifiers/FileToolModifier.workerd.d.mts +1 -1
- package/dist/utils/modifiers/FileToolModifier.workerd.mjs +1 -1
- package/dist/utils/ssrfGuard.node.d.mts +14 -5
- package/dist/utils/ssrfGuard.node.mjs +1 -161
- package/package.json +7 -3
- package/src/models/ToolRouterSession.ts +36 -8
- package/src/models/Tools.ts +102 -39
- package/src/utils/modifiers/FileToolModifier.node.ts +85 -181
- package/src/utils/modifiers/FileToolModifier.utils.neutral.ts +199 -0
- package/src/utils/pinnedDispatcher.node.ts +118 -0
- package/src/utils/sensitiveFileUploadPaths.ts +36 -9
- package/src/utils/ssrfGuard.node.ts +89 -11
- package/dist/FileToolModifier.utils.neutral-B5rT711M.mjs +0 -72
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as CreateCustomToolkitParams, f as CustomToolkit, o as CustomTool, r as CreateCustomToolParams, t as AnyZodSchema } from "./customTool.types-
|
|
1
|
+
import { a as CreateCustomToolkitParams, f as CustomToolkit, o as CustomTool, r as CreateCustomToolParams, t as AnyZodSchema } from "./customTool.types-DpJbYY5m.mjs";
|
|
2
2
|
import { SessionCreateResponse } from "@composio/client/resources/tool-router/session/session.mjs";
|
|
3
3
|
//#region src/models/CustomTool.d.ts
|
|
4
4
|
/**
|
|
@@ -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-
|
|
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
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { i as logger } from "./SsrfErrors-DNJt57GL.mjs";
|
|
2
2
|
import { f as ComposioRequestCancelledError, g as JsonSchemaToZodError, h as JsonSchemaRefResolutionError, m as isRequestAbortError } from "./errors-BcEUHZbq.mjs";
|
|
3
|
-
import {
|
|
3
|
+
import { o as isPlainObject } from "./FileToolModifier.utils.neutral-D_YkHwZP.mjs";
|
|
4
4
|
import { jsonSchemaToZod } from "@composio/json-schema-to-zod";
|
|
5
5
|
|
|
6
6
|
//#region src/utils/jsonSchema.ts
|