@composio/core 0.21.0 → 0.23.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-BHOYxLZX.d.mts → CustomTool-CnHdegDK.d.mts} +1 -1
- package/dist/{CustomTool-B-_VjWpy.mjs → CustomTool-CnJxXr07.mjs} +1 -1
- package/dist/{Telemetry-JRJJYS4I.mjs → Telemetry-41JkqpZ7.mjs} +3 -2
- package/dist/{cancellation-DV8CIi52.mjs → cancellation-BQibgpRG.mjs} +166 -34
- package/dist/{composio-BTZsFajb.d.mts → composio-Dq708dZS.d.mts} +81 -185
- package/dist/{customTool.types-D_w21L56.d.mts → customTool.types-B8lVpHOP.d.mts} +77 -59
- package/dist/docs/reference/sdk-reference/typescript/logs.mdx +4 -4
- package/dist/docs/reference/sdk-reference/typescript/remote-file.mdx +1 -1
- package/dist/docs/reference/sdk-reference/typescript/session.mdx +2 -2
- package/dist/docs/reference/sdk-reference/typescript/tools.mdx +2 -2
- package/dist/docs/reference/sdk-reference/typescript/usage.mdx +2 -2
- package/dist/{errors-Dyiu3ifQ.mjs → errors-BN15NcCW.mjs} +34 -2
- package/dist/experimental/index.d.mts +2 -2
- package/dist/experimental/index.mjs +1 -1
- package/dist/index.d.mts +46 -6
- package/dist/index.mjs +315 -363
- package/dist/models/Files.node.mjs +1 -1
- package/dist/platform/node.d.mts +1 -1
- package/dist/platform/node.mjs +13 -0
- package/dist/platform/workerd.d.mts +1 -1
- package/dist/platform/workerd.mjs +3 -0
- package/dist/{types-D5A2wzBl.d.mts → types-DuVZKrXO.d.mts} +2 -0
- package/dist/{types-CgRsUGqm.d.mts → types-eTw8Yw7Y.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/package.json +10 -7
- package/src/errors/ToolRouterErrors.ts +65 -0
- package/src/lib/toolRouterParams.ts +8 -10
- package/src/models/AuthConfigs.ts +0 -9
- package/src/models/ConnectionRequest.ts +21 -18
- package/src/models/CustomToolkits.ts +1 -1
- package/src/models/Logs.ts +2 -2
- package/src/models/RemoteFile.ts +24 -5
- package/src/models/SessionContext.ts +24 -4
- package/src/models/ToolRouter.ts +3 -3
- package/src/models/ToolRouterSession.ts +45 -13
- package/src/models/Tools.ts +21 -37
- package/src/models/Usage.ts +2 -1
- package/src/models/customToolExecution.ts +10 -0
- package/src/platform/node.ts +16 -0
- package/src/platform/types.ts +3 -0
- package/src/platform/workerd.ts +4 -0
- package/src/provider/BaseProvider.ts +2 -1
- package/src/provider/OpenAIProvider.ts +0 -283
- package/src/telemetry/Telemetry.ts +4 -2
- package/src/types/logs.types.ts +9 -1
- package/src/types/tool.types.ts +8 -3
- package/src/types/toolRouter.types.ts +27 -19
- package/src/types/usage.types.ts +2 -0
- package/src/utils/jsonSchema.ts +191 -36
- package/src/utils/retries.ts +20 -0
- package/src/utils/safePath.ts +135 -54
- package/src/utils/session.ts +31 -2
- package/src/utils/transformers/logs.ts +3 -2
- package/src/utils/transformers/toolRouterResponseTransform.ts +69 -12
- package/src/utils/transformers/usage.ts +1 -0
|
@@ -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-B8lVpHOP.mjs";
|
|
2
2
|
import { SessionCreateResponse } from "@composio/client/resources/tool-router/session/session.mjs";
|
|
3
3
|
//#region src/models/CustomTool.d.ts
|
|
4
4
|
/**
|
|
@@ -180,8 +180,9 @@ var TelemetryTransport = class {
|
|
|
180
180
|
*/
|
|
181
181
|
instrument(instance, fileName) {
|
|
182
182
|
const proto = Object.getPrototypeOf(instance);
|
|
183
|
-
const
|
|
184
|
-
|
|
183
|
+
const methodSource = proto === Object.prototype || proto === null ? instance : proto;
|
|
184
|
+
const methodNames = Object.getOwnPropertyNames(methodSource).filter((key) => {
|
|
185
|
+
const descriptor = Object.getOwnPropertyDescriptor(methodSource, key);
|
|
185
186
|
return key !== "constructor" && descriptor && typeof descriptor.value === "function" && descriptor.value.constructor.name === "AsyncFunction";
|
|
186
187
|
});
|
|
187
188
|
const instrumentedClassName = fileName ?? instance.constructor?.name ?? "unknown";
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { i as logger } from "./SsrfErrors-DiQldIdC.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { S as JsonSchemaToZodError, _ as ComposioRequestCancelledError, b as isRequestAbortError, x as JsonSchemaRefResolutionError } from "./errors-BN15NcCW.mjs";
|
|
3
3
|
import { o as isPlainObject } from "./FileToolModifier.utils.neutral-DWFpnsj2.mjs";
|
|
4
4
|
import { jsonSchemaToZod } from "@composio/json-schema-to-zod";
|
|
5
5
|
|
|
6
6
|
//#region src/utils/jsonSchema.ts
|
|
7
7
|
const MAX_REF_CHAIN_DEPTH = 100;
|
|
8
8
|
const MAX_NODE_DEPTH = 512;
|
|
9
|
+
const MAX_NULL_CHECK_DEPTH = 64;
|
|
10
|
+
const MAX_NULL_CHECK_NODES = 2e3;
|
|
9
11
|
const CYCLE_BREAK_SENTINEL = {
|
|
10
12
|
type: "object",
|
|
11
13
|
additionalProperties: true
|
|
@@ -384,25 +386,44 @@ function setOwn(target, key, value) {
|
|
|
384
386
|
});
|
|
385
387
|
}
|
|
386
388
|
/**
|
|
387
|
-
*
|
|
388
|
-
*
|
|
389
|
+
* The only keywords that can reject a `null` instance; every other keyword
|
|
390
|
+
* constrains strings, numbers, arrays or objects and ignores `null`.
|
|
389
391
|
*/
|
|
390
|
-
|
|
391
|
-
|
|
392
|
+
const NULL_CONSTRAINT_KEYWORDS = [
|
|
393
|
+
"type",
|
|
394
|
+
"enum",
|
|
395
|
+
"const",
|
|
396
|
+
"$ref",
|
|
397
|
+
"anyOf",
|
|
398
|
+
"oneOf",
|
|
399
|
+
"allOf",
|
|
400
|
+
"not",
|
|
401
|
+
"if",
|
|
402
|
+
"then",
|
|
403
|
+
"else"
|
|
404
|
+
];
|
|
405
|
+
/**
|
|
406
|
+
* Widens a property schema so that `null` is an accepted value while keeping
|
|
407
|
+
* every other constraint it declares. A node whose only obstacle is `type` or
|
|
408
|
+
* `anyOf` is widened in place. Anything else is wrapped whole, because JSON
|
|
409
|
+
* Schema keywords apply together: adding `null` to `type` does not lift a
|
|
410
|
+
* sibling `enum`. `acceptsNull` must answer for the strict output.
|
|
411
|
+
*/
|
|
412
|
+
function widenToNullable(node, acceptsNull) {
|
|
413
|
+
if (acceptsNull(node)) return node;
|
|
414
|
+
const constraints = NULL_CONSTRAINT_KEYWORDS.filter((key) => key in node);
|
|
415
|
+
if (constraints.length === 1 && constraints[0] === "type") {
|
|
416
|
+
const members = Array.isArray(node.type) ? node.type : [node.type];
|
|
417
|
+
return {
|
|
418
|
+
...node,
|
|
419
|
+
type: [...members, "null"]
|
|
420
|
+
};
|
|
421
|
+
}
|
|
422
|
+
if (constraints.length === 1 && constraints[0] === "anyOf" && Array.isArray(node.anyOf)) return {
|
|
392
423
|
...node,
|
|
393
424
|
anyOf: [...node.anyOf, { type: "null" }]
|
|
394
425
|
};
|
|
395
|
-
if (typeof node.type === "string") return node.type === "null" ? node : {
|
|
396
|
-
...node,
|
|
397
|
-
type: [node.type, "null"]
|
|
398
|
-
};
|
|
399
|
-
if (Array.isArray(node.type)) return node.type.includes("null") ? node : {
|
|
400
|
-
...node,
|
|
401
|
-
type: [...node.type, "null"]
|
|
402
|
-
};
|
|
403
|
-
if (Array.isArray(node.enum) && node.enum.includes(null) || node.const === null) return node;
|
|
404
426
|
const { description, title, ...rest } = node;
|
|
405
|
-
if (Object.keys(rest).length === 0) return node;
|
|
406
427
|
return {
|
|
407
428
|
...description !== void 0 ? { description } : {},
|
|
408
429
|
...title !== void 0 ? { title } : {},
|
|
@@ -423,19 +444,117 @@ function resolveLocalRefs(node, root) {
|
|
|
423
444
|
}
|
|
424
445
|
return current;
|
|
425
446
|
}
|
|
426
|
-
/**
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
447
|
+
/**
|
|
448
|
+
* Creates the check for whether schemas of one document accept `null` as an
|
|
449
|
+
* instance: every keyword in `NULL_CONSTRAINT_KEYWORDS` that is present must
|
|
450
|
+
* accept it. This is the single definition of null acceptance; the strict
|
|
451
|
+
* rewrite and `omitNullToolArguments` both decide with it.
|
|
452
|
+
*
|
|
453
|
+
* `strictOutput` answers for the schema `toStrictJsonSchema` emits instead of
|
|
454
|
+
* the one it was given: the rewrite types every node that declares
|
|
455
|
+
* `properties` as an object, so such a node stops accepting null.
|
|
456
|
+
*
|
|
457
|
+
* One check serves a whole document, and an answer is computed once per node.
|
|
458
|
+
* A reference cycle never yields a null by itself, so a node met again while
|
|
459
|
+
* it is being evaluated counts as rejecting. An answer that leans on that is
|
|
460
|
+
* provisional until the node it leans on is done: it is kept if that node
|
|
461
|
+
* does reject null and discarded otherwise.
|
|
462
|
+
*
|
|
463
|
+
* Each check is bounded in depth and in nodes visited. A check that meets a
|
|
464
|
+
* bound proves nothing, so it rejects null whatever its other branches say,
|
|
465
|
+
* which costs at most a redundant null branch or a dropped null. The nodes it
|
|
466
|
+
* went through stay marked as unproven, so a later check that reaches one of
|
|
467
|
+
* them neither repeats the work nor trusts the answer.
|
|
468
|
+
*/
|
|
469
|
+
function createNullCheck(root, strictOutput = false) {
|
|
470
|
+
const NOTHING = 65;
|
|
471
|
+
const A_BOUND = -1;
|
|
472
|
+
const answers = /* @__PURE__ */ new Map();
|
|
473
|
+
const provisional = [];
|
|
474
|
+
const path = /* @__PURE__ */ new Map();
|
|
475
|
+
const metAgain = /* @__PURE__ */ new Set();
|
|
476
|
+
let budget = 0;
|
|
477
|
+
let leansOn = NOTHING;
|
|
478
|
+
const accepts = (schema) => {
|
|
479
|
+
if (typeof schema === "boolean") return schema;
|
|
480
|
+
if (!isPlainObject(schema)) return true;
|
|
481
|
+
const remembered = answers.get(schema);
|
|
482
|
+
if (remembered !== void 0) {
|
|
483
|
+
if (path.size === 0) return remembered.answer && remembered.leansOn !== A_BOUND;
|
|
484
|
+
leansOn = Math.min(leansOn, remembered.leansOn);
|
|
485
|
+
return remembered.answer;
|
|
486
|
+
}
|
|
487
|
+
const onPath = path.get(schema);
|
|
488
|
+
if (onPath !== void 0) {
|
|
489
|
+
metAgain.add(onPath);
|
|
490
|
+
leansOn = Math.min(leansOn, onPath);
|
|
491
|
+
return false;
|
|
492
|
+
}
|
|
493
|
+
const depth = path.size;
|
|
494
|
+
if (depth === 0) budget = MAX_NULL_CHECK_NODES;
|
|
495
|
+
if (depth >= MAX_NULL_CHECK_DEPTH || budget <= 0) {
|
|
496
|
+
leansOn = A_BOUND;
|
|
497
|
+
return false;
|
|
498
|
+
}
|
|
499
|
+
budget -= 1;
|
|
500
|
+
const outer = leansOn;
|
|
501
|
+
leansOn = NOTHING;
|
|
502
|
+
const mark = provisional.length;
|
|
503
|
+
path.set(schema, depth);
|
|
504
|
+
let answer = keywordsAccept(schema);
|
|
505
|
+
path.delete(schema);
|
|
506
|
+
const own = leansOn;
|
|
507
|
+
const settled = own >= depth;
|
|
508
|
+
const below = provisional.splice(mark);
|
|
509
|
+
if (answer && metAgain.has(depth)) for (const other of below) answers.delete(other);
|
|
510
|
+
else for (const other of below) {
|
|
511
|
+
const entry = answers.get(other);
|
|
512
|
+
if (entry === void 0) continue;
|
|
513
|
+
if (settled) entry.leansOn = NOTHING;
|
|
514
|
+
else {
|
|
515
|
+
if (entry.leansOn >= depth) entry.leansOn = own;
|
|
516
|
+
provisional.push(other);
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
metAgain.delete(depth);
|
|
520
|
+
if (depth === 0 && own === A_BOUND) answer = false;
|
|
521
|
+
answers.set(schema, {
|
|
522
|
+
answer,
|
|
523
|
+
leansOn: settled ? NOTHING : own
|
|
524
|
+
});
|
|
525
|
+
if (!settled) provisional.push(schema);
|
|
526
|
+
leansOn = settled ? outer : Math.min(outer, own);
|
|
527
|
+
if (depth === 0) {
|
|
528
|
+
provisional.length = 0;
|
|
529
|
+
leansOn = NOTHING;
|
|
530
|
+
}
|
|
531
|
+
return answer;
|
|
532
|
+
};
|
|
533
|
+
const keywordsAccept = (node) => {
|
|
534
|
+
if (typeof node.type === "string" && node.type !== "null") return false;
|
|
535
|
+
if (Array.isArray(node.type) && !node.type.includes("null")) return false;
|
|
536
|
+
if (strictOutput && !("type" in node) && isPlainObject(node.properties)) return false;
|
|
537
|
+
if (Array.isArray(node.enum) && !node.enum.includes(null)) return false;
|
|
538
|
+
if ("const" in node && node.const !== null) return false;
|
|
539
|
+
if ("$ref" in node) {
|
|
540
|
+
const resolution = typeof node.$ref === "string" ? tryResolvePointer(root, node.$ref) : void 0;
|
|
541
|
+
if (resolution === void 0 || resolution.kind === "unresolved") return false;
|
|
542
|
+
if (!accepts(resolution.value)) return false;
|
|
543
|
+
}
|
|
544
|
+
if (Array.isArray(node.anyOf) && !node.anyOf.some(accepts)) return false;
|
|
545
|
+
if (Array.isArray(node.oneOf)) {
|
|
546
|
+
const matches = node.oneOf.filter(accepts).length;
|
|
547
|
+
if (matches === 0 || matches > 1 && !strictOutput) return false;
|
|
548
|
+
}
|
|
549
|
+
if (Array.isArray(node.allOf) && !node.allOf.every(accepts)) return false;
|
|
550
|
+
if ("not" in node && accepts(node.not)) return false;
|
|
551
|
+
if ("if" in node) {
|
|
552
|
+
const branch = accepts(node.if) ? "then" : "else";
|
|
553
|
+
if (branch in node && !accepts(node[branch])) return false;
|
|
554
|
+
}
|
|
555
|
+
return true;
|
|
556
|
+
};
|
|
557
|
+
return accepts;
|
|
439
558
|
}
|
|
440
559
|
/**
|
|
441
560
|
* Normalizes a tool parameter schema for OpenAI structured outputs
|
|
@@ -470,12 +589,14 @@ function schemaAcceptsNull(schema, root) {
|
|
|
470
589
|
function toStrictJsonSchema(schema) {
|
|
471
590
|
const changes = [];
|
|
472
591
|
const unsupported = [];
|
|
592
|
+
const references = [];
|
|
473
593
|
let totalChanges = 0;
|
|
474
594
|
const recordChange = (change) => {
|
|
475
595
|
totalChanges += 1;
|
|
476
596
|
if (changes.length < MAX_STRICT_CHANGES) changes.push(change);
|
|
477
597
|
};
|
|
478
598
|
const root = isPlainObject(schema) ? schema : {};
|
|
599
|
+
const acceptsNullInOutput = createNullCheck(root, true);
|
|
479
600
|
function walkChildren(node, mode, depth, path) {
|
|
480
601
|
const clone = {};
|
|
481
602
|
for (const [key, child] of Object.entries(node)) {
|
|
@@ -559,6 +680,10 @@ function toStrictJsonSchema(schema) {
|
|
|
559
680
|
keyword: "$ref",
|
|
560
681
|
detail: `unresolved $ref "${node.$ref}"`
|
|
561
682
|
});
|
|
683
|
+
else references.push({
|
|
684
|
+
path,
|
|
685
|
+
ref: node.$ref
|
|
686
|
+
});
|
|
562
687
|
return out;
|
|
563
688
|
}
|
|
564
689
|
if (!(out.type === "object" || Array.isArray(out.type) && out.type.includes("object")) && !isPlainObject(out.properties)) return out;
|
|
@@ -576,7 +701,7 @@ function toStrictJsonSchema(schema) {
|
|
|
576
701
|
continue;
|
|
577
702
|
}
|
|
578
703
|
if (declaredRequired.has(name) || !isPlainObject(propertySchema)) continue;
|
|
579
|
-
setOwn(properties, name, widenToNullable(propertySchema));
|
|
704
|
+
setOwn(properties, name, widenToNullable(propertySchema, acceptsNullInOutput));
|
|
580
705
|
recordChange({
|
|
581
706
|
path: joinPath(path, `properties.${name}`),
|
|
582
707
|
reason: "optional-property-nullable",
|
|
@@ -608,6 +733,13 @@ function toStrictJsonSchema(schema) {
|
|
|
608
733
|
};
|
|
609
734
|
}
|
|
610
735
|
const normalized = walk(root, "schema", 0, "");
|
|
736
|
+
if (isPlainObject(normalized)) {
|
|
737
|
+
for (const { path, ref } of references) if (tryResolvePointer(normalized, ref).kind === "unresolved") unsupported.push({
|
|
738
|
+
path,
|
|
739
|
+
keyword: "$ref",
|
|
740
|
+
detail: `$ref "${ref}" target moved by the rewrite`
|
|
741
|
+
});
|
|
742
|
+
}
|
|
611
743
|
if (!isPlainObject(normalized) || !isObjectType(normalized.type)) unsupported.push({
|
|
612
744
|
path: "",
|
|
613
745
|
keyword: "type",
|
|
@@ -639,7 +771,7 @@ function toStrictJsonSchema(schema) {
|
|
|
639
771
|
*/
|
|
640
772
|
function omitNullToolArguments(args, schema) {
|
|
641
773
|
const root = isPlainObject(schema) ? schema : {};
|
|
642
|
-
return omitNulls(args, root, root, 0);
|
|
774
|
+
return omitNulls(args, root, root, 0, createNullCheck(root));
|
|
643
775
|
}
|
|
644
776
|
/**
|
|
645
777
|
* Picks the composition branch that describes a value's shape: the first
|
|
@@ -665,12 +797,12 @@ function selectBranchFor(schema, value, root) {
|
|
|
665
797
|
};
|
|
666
798
|
return find(resolved, 0) ?? resolved;
|
|
667
799
|
}
|
|
668
|
-
function omitNulls(value, schema, root, depth) {
|
|
800
|
+
function omitNulls(value, schema, root, depth, acceptsNull) {
|
|
669
801
|
if (depth > MAX_NODE_DEPTH) throw new RangeError(`Tool arguments exceed maximum nesting depth of ${MAX_NODE_DEPTH}`);
|
|
670
802
|
const node = selectBranchFor(schema, value, root);
|
|
671
803
|
if (Array.isArray(value)) {
|
|
672
804
|
const items = node && isPlainObject(node.items) ? node.items : void 0;
|
|
673
|
-
return value.map((item) => omitNulls(item, items, root, depth + 1));
|
|
805
|
+
return value.map((item) => omitNulls(item, items, root, depth + 1, acceptsNull));
|
|
674
806
|
}
|
|
675
807
|
if (!isPlainObject(value)) return value;
|
|
676
808
|
const properties = node && isPlainObject(node.properties) ? node.properties : {};
|
|
@@ -678,10 +810,10 @@ function omitNulls(value, schema, root, depth) {
|
|
|
678
810
|
for (const [key, child] of Object.entries(value)) {
|
|
679
811
|
const propertySchema = Object.prototype.hasOwnProperty.call(properties, key) ? properties[key] : void 0;
|
|
680
812
|
if (child === null) {
|
|
681
|
-
if (propertySchema === void 0 ||
|
|
813
|
+
if (propertySchema === void 0 || acceptsNull(propertySchema)) setOwn(clone, key, child);
|
|
682
814
|
continue;
|
|
683
815
|
}
|
|
684
|
-
setOwn(clone, key, omitNulls(child, propertySchema, root, depth + 1));
|
|
816
|
+
setOwn(clone, key, omitNulls(child, propertySchema, root, depth + 1, acceptsNull));
|
|
685
817
|
}
|
|
686
818
|
return clone;
|
|
687
819
|
}
|