@composio/core 0.15.0 → 0.17.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-zjeDpZ91.d.mts → CustomTool-Uip-fhPw.d.mts} +1 -1
- package/dist/{cancellation-BbJ-UQ__.mjs → cancellation-NVtGf3St.mjs} +69 -1
- package/dist/{composio-Bf8hnBBq.d.mts → composio-B27X6i6A.d.mts} +253 -247
- package/dist/{BaseProvider-BN2-Nktx.d.mts → customTool.types-B2Ava_j5.d.mts} +3020 -126
- package/dist/experimental/index.d.mts +2 -2
- package/dist/{fileUtils.node-BQ0fWge3.mjs → fileUtils.node-B1Wn848p.mjs} +2 -2
- package/dist/index.d.mts +18 -7
- package/dist/index.mjs +91 -120
- package/dist/models/Files.node.mjs +1 -1
- package/dist/{types-CePuCfD-.d.mts → types-DdZJuMm2.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 +2 -2
- package/dist/utils/modifiers/FileToolModifier.workerd.d.mts +1 -1
- package/dist/utils/ssrfGuard.node.d.mts +11 -1
- package/dist/utils/ssrfGuard.node.mjs +11 -1
- package/dist/utils/ssrfGuard.workerd.d.mts +13 -1
- package/dist/utils/ssrfGuard.workerd.mjs +13 -1
- package/package.json +3 -3
- package/src/index.ts +1 -0
- package/src/models/RemoteFile.ts +7 -2
- package/src/models/ToolRouterSessionFileMount.ts +14 -8
- package/src/models/Tools.ts +108 -77
- package/src/provider/BaseProvider.ts +53 -1
- package/src/provider/OpenAIProvider.ts +43 -15
- package/src/types/provider.types.ts +15 -0
- package/src/types/tool.types.ts +8 -2
- package/src/utils/fileUtils.node.ts +8 -2
- package/src/utils/jsonSchema.ts +86 -1
- package/src/utils/ssrfGuard.node.ts +11 -0
- package/src/utils/ssrfGuard.workerd.ts +16 -0
- package/dist/customTool.types-Bhom9a2R.d.mts +0 -2859
package/src/types/tool.types.ts
CHANGED
|
@@ -139,13 +139,19 @@ const ParametersSchema = z.preprocess(
|
|
|
139
139
|
oneOf: z.array(JSONSchemaPropertySchema).optional(),
|
|
140
140
|
allOf: z.array(JSONSchemaPropertySchema).optional(),
|
|
141
141
|
not: JSONSchemaPropertySchema.optional(),
|
|
142
|
-
properties: z.record(z.string(), JSONSchemaPropertySchema),
|
|
142
|
+
properties: z.record(z.string(), JSONSchemaPropertySchema).optional(),
|
|
143
143
|
required: z.array(z.string()).optional(),
|
|
144
144
|
title: z.string().optional(),
|
|
145
145
|
default: z.unknown().optional(),
|
|
146
146
|
nullable: z.boolean().optional(),
|
|
147
147
|
description: z.string().optional(),
|
|
148
|
-
|
|
148
|
+
// Dynamic-key constraints the Composio API ships at the parameters root.
|
|
149
|
+
// Both were previously lost on parse: `patternProperties` was stripped as an
|
|
150
|
+
// unknown key, and a schema-valued `additionalProperties` was rejected
|
|
151
|
+
// outright by the boolean-only schema. Omission still stays omission —
|
|
152
|
+
// downstream converters, not the parser, decide the implicit policy.
|
|
153
|
+
patternProperties: z.record(z.string(), JSONSchemaPropertySchema).optional(),
|
|
154
|
+
additionalProperties: z.union([z.boolean(), JSONSchemaPropertySchema]).optional(),
|
|
149
155
|
// Definition blocks targeted by `$ref` pointers. The Composio API ships
|
|
150
156
|
// these at the parameters root (e.g. `data` → `$ref` → `#/$defs/...`), but
|
|
151
157
|
// because `z.object` strips unknown keys they were being dropped on parse —
|
|
@@ -246,7 +246,10 @@ const uploadFileToS3 = async (
|
|
|
246
246
|
// `InvalidArgumentError: invalid content-length header`, which surfaces as
|
|
247
247
|
// `TypeError: fetch failed` and breaks every `file_uploadable` connector tool
|
|
248
248
|
// on Node 22+.
|
|
249
|
-
|
|
249
|
+
// SSRF guard: `new_presigned_url` comes from the API response, which the SDK
|
|
250
|
+
// treats as untrusted — a response naming an internal address would otherwise
|
|
251
|
+
// have the file's bytes PUT to it. See ssrfGuard.node.ts.
|
|
252
|
+
const uploadResponse = await ssrfSafeFetch(signedURL, {
|
|
250
253
|
method: 'PUT',
|
|
251
254
|
body: uploadBuffer,
|
|
252
255
|
signal,
|
|
@@ -348,7 +351,10 @@ export const downloadFileFromS3 = async ({
|
|
|
348
351
|
fileDownloadDir?: string;
|
|
349
352
|
signal?: AbortSignal;
|
|
350
353
|
}): Promise<FileDownloadData> => {
|
|
351
|
-
|
|
354
|
+
// SSRF guard: `s3Url` is a field of the tool-execution response, so it is no
|
|
355
|
+
// more trusted than a user-supplied URL — and the bytes it returns are
|
|
356
|
+
// written to disk. See ssrfGuard.node.ts.
|
|
357
|
+
const response = await ssrfSafeFetch(s3Url, { signal });
|
|
352
358
|
if (!response.ok) {
|
|
353
359
|
throw new Error(`Failed to download file: ${response.statusText}`);
|
|
354
360
|
}
|
package/src/utils/jsonSchema.ts
CHANGED
|
@@ -258,6 +258,91 @@ export function dereferenceJsonSchema<T = unknown>(
|
|
|
258
258
|
return out as T;
|
|
259
259
|
}
|
|
260
260
|
|
|
261
|
+
/**
|
|
262
|
+
* Returns a deep-cloned JSON Schema in which every node that carries a
|
|
263
|
+
* `properties` keyword also carries `type: "object"` when it has no explicit
|
|
264
|
+
* `type`. OpenAI tolerates the omission, but Google Gemini enforces OpenAPI
|
|
265
|
+
* 3.0 strictly and rejects function declarations whose nested objects are
|
|
266
|
+
* missing the `type` (see https://github.com/ComposioHQ/composio/issues/4022).
|
|
267
|
+
*
|
|
268
|
+
* The function follows JSON Schema's schema-bearing keywords while keeping
|
|
269
|
+
* property maps and instance values as containers. Nodes that already declare
|
|
270
|
+
* a `type` are left untouched.
|
|
271
|
+
*/
|
|
272
|
+
export function ensureObjectTypeOnProperties<T = unknown>(schema: T): T {
|
|
273
|
+
type WalkMode = 'schema' | 'schema-array' | 'schema-map' | 'dependencies-map' | 'value';
|
|
274
|
+
|
|
275
|
+
const schemaKeywords = new Set([
|
|
276
|
+
'additionalItems',
|
|
277
|
+
'additionalProperties',
|
|
278
|
+
'contains',
|
|
279
|
+
'contentSchema',
|
|
280
|
+
'else',
|
|
281
|
+
'if',
|
|
282
|
+
'not',
|
|
283
|
+
'propertyNames',
|
|
284
|
+
'then',
|
|
285
|
+
'unevaluatedItems',
|
|
286
|
+
'unevaluatedProperties',
|
|
287
|
+
]);
|
|
288
|
+
const schemaArrayKeywords = new Set(['allOf', 'anyOf', 'oneOf', 'prefixItems']);
|
|
289
|
+
const schemaMapKeywords = new Set([
|
|
290
|
+
'$defs',
|
|
291
|
+
'definitions',
|
|
292
|
+
'dependentSchemas',
|
|
293
|
+
'patternProperties',
|
|
294
|
+
'properties',
|
|
295
|
+
]);
|
|
296
|
+
|
|
297
|
+
function walk(value: unknown, mode: WalkMode, depth = 0): unknown {
|
|
298
|
+
if (depth > MAX_NODE_DEPTH) {
|
|
299
|
+
throw new RangeError(`JSON Schema exceeds maximum nesting depth of ${MAX_NODE_DEPTH}`);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
if (Array.isArray(value)) {
|
|
303
|
+
const itemMode = mode === 'schema-array' ? 'schema' : 'value';
|
|
304
|
+
return value.map(item => walk(item, itemMode, depth + 1));
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
if (!isPlainObject(value)) return value;
|
|
308
|
+
|
|
309
|
+
const clone: Record<string, unknown> = {};
|
|
310
|
+
for (const [key, child] of Object.entries(value)) {
|
|
311
|
+
let childMode: WalkMode = 'value';
|
|
312
|
+
if (mode === 'schema-map') {
|
|
313
|
+
childMode = 'schema';
|
|
314
|
+
} else if (mode === 'dependencies-map') {
|
|
315
|
+
childMode = Array.isArray(child) ? 'value' : 'schema';
|
|
316
|
+
} else if (mode === 'schema') {
|
|
317
|
+
if (schemaMapKeywords.has(key)) {
|
|
318
|
+
childMode = 'schema-map';
|
|
319
|
+
} else if (schemaArrayKeywords.has(key) || (key === 'items' && Array.isArray(child))) {
|
|
320
|
+
childMode = 'schema-array';
|
|
321
|
+
} else if (schemaKeywords.has(key) || key === 'items') {
|
|
322
|
+
childMode = 'schema';
|
|
323
|
+
} else if (key === 'dependencies') {
|
|
324
|
+
childMode = 'dependencies-map';
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
Object.defineProperty(clone, key, {
|
|
329
|
+
configurable: true,
|
|
330
|
+
enumerable: true,
|
|
331
|
+
value: walk(child, childMode, depth + 1),
|
|
332
|
+
writable: true,
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
if (mode === 'schema' && clone.properties !== undefined && clone.type === undefined) {
|
|
337
|
+
clone.type = 'object';
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
return clone;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
return walk(schema, 'schema') as T;
|
|
344
|
+
}
|
|
345
|
+
|
|
261
346
|
/**
|
|
262
347
|
* Returns a deep-cloned JSON Schema whose `required` arrays contain each entry
|
|
263
348
|
* at most once. Duplicate entries are invalid in JSON Schema 2020-12 but do
|
|
@@ -328,7 +413,7 @@ export const removeNonRequiredProperties = <
|
|
|
328
413
|
type: 'object';
|
|
329
414
|
properties: Record<string, unknown>;
|
|
330
415
|
required?: string[];
|
|
331
|
-
additionalProperties?:
|
|
416
|
+
additionalProperties?: unknown;
|
|
332
417
|
},
|
|
333
418
|
>(
|
|
334
419
|
schema: T
|
|
@@ -204,3 +204,14 @@ export const ssrfSafeFetch = async (
|
|
|
204
204
|
{ url: rawUrl }
|
|
205
205
|
);
|
|
206
206
|
};
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* {@link ssrfSafeFetch} for call sites that must keep working on every runtime.
|
|
210
|
+
*
|
|
211
|
+
* `ssrfSafeFetch` fails closed in edge runtimes, which is right for a URL the
|
|
212
|
+
* caller chose to upload — the alternative is fetching it unvalidated — but not
|
|
213
|
+
* for Tool Router session file transfers, where refusing would remove a working
|
|
214
|
+
* feature from Workers rather than close a hole reachable there. On Node this
|
|
215
|
+
* is the full guard; only the edge build differs.
|
|
216
|
+
*/
|
|
217
|
+
export const ssrfSafeFetchWhereSupported = ssrfSafeFetch;
|
|
@@ -17,3 +17,19 @@ export const ssrfSafeFetch = async (rawUrl: string): Promise<Response> => {
|
|
|
17
17
|
}
|
|
18
18
|
);
|
|
19
19
|
};
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Unguarded `fetch`, for the call sites that must keep working here.
|
|
23
|
+
*
|
|
24
|
+
* Failing closed is the right default for a URL the caller chose to upload, but
|
|
25
|
+
* applying it to Tool Router session file transfers would take a working
|
|
26
|
+
* feature away from Workers instead of closing a hole reachable there. The
|
|
27
|
+
* guard exists to stop a URL from reaching private address space the SDK's host
|
|
28
|
+
* can see; an edge worker has no such vantage point — it cannot resolve DNS to
|
|
29
|
+
* check, and its `fetch` does not originate inside the caller's network. The
|
|
30
|
+
* Node build applies the full guard.
|
|
31
|
+
*/
|
|
32
|
+
export const ssrfSafeFetchWhereSupported = async (
|
|
33
|
+
rawUrl: string,
|
|
34
|
+
init: RequestInit = {}
|
|
35
|
+
): Promise<Response> => fetch(rawUrl, init);
|