@mantyx/sdk 0.15.0 → 0.16.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/index.cjs CHANGED
@@ -581,7 +581,20 @@ function parseEventBlock(block) {
581
581
 
582
582
  // src/zod-to-json-schema.ts
583
583
  var import_zod = require("zod");
584
+ function isZodSchema(value) {
585
+ if (!value || typeof value !== "object") return false;
586
+ const o = value;
587
+ return typeof o._def !== "undefined" || typeof o._zod !== "undefined";
588
+ }
584
589
  function zodToJsonSchema(schema) {
590
+ const instance = schema;
591
+ if (typeof instance.toJSONSchema === "function") {
592
+ try {
593
+ const out = instance.toJSONSchema();
594
+ if (out && typeof out === "object") return out;
595
+ } catch {
596
+ }
597
+ }
585
598
  const builtIn = import_zod.z.toJSONSchema;
586
599
  if (typeof builtIn === "function") {
587
600
  try {
@@ -592,24 +605,40 @@ function zodToJsonSchema(schema) {
592
605
  }
593
606
  return convertNode(schema);
594
607
  }
608
+ function schemaKind(def) {
609
+ if (!def) return void 0;
610
+ if (typeof def.typeName === "string") return def.typeName;
611
+ if (typeof def.type === "string") return def.type;
612
+ return void 0;
613
+ }
614
+ function isOptionalField(field) {
615
+ const kind = schemaKind(field._def);
616
+ return kind === "ZodOptional" || kind === "ZodDefault" || kind === "optional" || kind === "default";
617
+ }
595
618
  function convertNode(schema) {
596
619
  const def = schema._def;
597
- const typeName = def?.typeName;
598
- switch (typeName) {
620
+ const kind = schemaKind(def);
621
+ switch (kind) {
599
622
  case "ZodString":
623
+ case "string":
600
624
  return { type: "string" };
601
625
  case "ZodNumber":
626
+ case "number":
602
627
  return { type: "number" };
603
628
  case "ZodBoolean":
629
+ case "boolean":
604
630
  return { type: "boolean" };
605
631
  case "ZodNull":
632
+ case "null":
606
633
  return { type: "null" };
607
- case "ZodLiteral": {
608
- const value = def.value;
634
+ case "ZodLiteral":
635
+ case "literal": {
636
+ const value = def?.value;
609
637
  return { const: value, type: typeof value };
610
638
  }
611
- case "ZodEnum": {
612
- const values = def.values ?? [];
639
+ case "ZodEnum":
640
+ case "enum": {
641
+ const values = def?.values ?? [];
613
642
  return { type: "string", enum: [...values] };
614
643
  }
615
644
  case "ZodArray": {
@@ -619,26 +648,35 @@ function convertNode(schema) {
619
648
  items: inner ? convertNode(inner) : {}
620
649
  };
621
650
  }
651
+ case "array": {
652
+ const inner = def?.element;
653
+ return {
654
+ type: "array",
655
+ items: inner ? convertNode(inner) : {}
656
+ };
657
+ }
622
658
  case "ZodOptional":
623
- case "ZodNullable": {
624
- const inner = def.innerType;
659
+ case "ZodNullable":
660
+ case "optional":
661
+ case "nullable": {
662
+ const inner = def?.innerType;
625
663
  return inner ? convertNode(inner) : {};
626
664
  }
627
- case "ZodDefault": {
628
- const inner = def.innerType;
665
+ case "ZodDefault":
666
+ case "default": {
667
+ const inner = def?.innerType;
629
668
  return inner ? convertNode(inner) : {};
630
669
  }
631
- case "ZodObject": {
632
- const shape = def.shape;
670
+ case "ZodObject":
671
+ case "object": {
672
+ const shape = def?.shape;
633
673
  const fields = typeof shape === "function" ? shape() : shape;
634
674
  const properties = {};
635
675
  const required = [];
636
676
  if (fields) {
637
677
  for (const [key, value] of Object.entries(fields)) {
638
678
  properties[key] = convertNode(value);
639
- const innerDef = value._def;
640
- const innerTypeName = innerDef?.typeName;
641
- if (innerTypeName !== "ZodOptional" && innerTypeName !== "ZodDefault") {
679
+ if (!isOptionalField(value)) {
642
680
  required.push(key);
643
681
  }
644
682
  }
@@ -653,7 +691,7 @@ function convertNode(schema) {
653
691
  }
654
692
  function toToolParametersWire(parameters) {
655
693
  if (!parameters) return { type: "object", properties: {} };
656
- if (typeof parameters._def !== "undefined") {
694
+ if (isZodSchema(parameters)) {
657
695
  return zodToJsonSchema(parameters);
658
696
  }
659
697
  return parameters;
@@ -1476,23 +1514,24 @@ function normalizeLoopDetection(value) {
1476
1514
  }
1477
1515
  return out;
1478
1516
  }
1479
- function assertThreshold(label, value, min) {
1517
+ function assertThreshold(label, value, min, max = LOOP_DETECTION_THRESHOLD_MAX) {
1480
1518
  if (typeof value !== "number" || !Number.isFinite(value) || !Number.isInteger(value)) {
1481
1519
  throw new MantyxError(`${label} must be an integer, got ${JSON.stringify(value)}`);
1482
1520
  }
1483
1521
  if (value < min) {
1484
1522
  throw new MantyxError(`${label} must be >= ${min}, got ${value}`);
1485
1523
  }
1486
- if (value > LOOP_DETECTION_THRESHOLD_MAX) {
1487
- throw new MantyxError(
1488
- `${label} must be <= ${LOOP_DETECTION_THRESHOLD_MAX} (server-enforced), got ${value}`
1489
- );
1524
+ if (value > max) {
1525
+ throw new MantyxError(`${label} must be <= ${max} (server-enforced), got ${value}`);
1490
1526
  }
1491
1527
  return value;
1492
1528
  }
1493
1529
  var TOOL_BUDGETS_MAX_ENTRIES = 32;
1494
1530
  var TOOL_BUDGET_MAX_NAME_LEN = 120;
1495
1531
  var TOOL_BUDGET_MAX_CALLS = 1e3;
1532
+ var SUPERVISOR_INTERVAL_MAX = 100;
1533
+ var SUPERVISOR_REASONING_CHARS_MAX = 5e4;
1534
+ var SUPERVISOR_REASONING_MS_MAX = 6e5;
1496
1535
  function normalizeSupervisor(value) {
1497
1536
  if (value === false) return false;
1498
1537
  if (!value || typeof value !== "object" || Array.isArray(value)) {
@@ -1502,7 +1541,35 @@ function normalizeSupervisor(value) {
1502
1541
  }
1503
1542
  const out = {};
1504
1543
  if (value.interval !== void 0) {
1505
- out.interval = assertThreshold("supervisor.interval", value.interval, 1);
1544
+ out.interval = assertThreshold("supervisor.interval", value.interval, 1, SUPERVISOR_INTERVAL_MAX);
1545
+ }
1546
+ if (value.reasoningTrigger !== void 0) {
1547
+ if (value.reasoningTrigger === false) {
1548
+ out.reasoningTrigger = false;
1549
+ } else if (!value.reasoningTrigger || typeof value.reasoningTrigger !== "object" || Array.isArray(value.reasoningTrigger)) {
1550
+ throw new MantyxError(
1551
+ `supervisor.reasoningTrigger must be \`false\` or an object { chars?, ms? }, got ${JSON.stringify(value.reasoningTrigger)}`
1552
+ );
1553
+ } else {
1554
+ const rt = {};
1555
+ if (value.reasoningTrigger.chars !== void 0) {
1556
+ rt.chars = assertThreshold(
1557
+ "supervisor.reasoningTrigger.chars",
1558
+ value.reasoningTrigger.chars,
1559
+ 1,
1560
+ SUPERVISOR_REASONING_CHARS_MAX
1561
+ );
1562
+ }
1563
+ if (value.reasoningTrigger.ms !== void 0) {
1564
+ rt.ms = assertThreshold(
1565
+ "supervisor.reasoningTrigger.ms",
1566
+ value.reasoningTrigger.ms,
1567
+ 1,
1568
+ SUPERVISOR_REASONING_MS_MAX
1569
+ );
1570
+ }
1571
+ out.reasoningTrigger = rt;
1572
+ }
1506
1573
  }
1507
1574
  return out;
1508
1575
  }
@@ -1915,7 +1982,7 @@ function normalizeScope(scope) {
1915
1982
  }
1916
1983
 
1917
1984
  // src/version.ts
1918
- var SDK_VERSION = "0.15.0";
1985
+ var SDK_VERSION = "0.16.0";
1919
1986
  // Annotate the CommonJS export names for ESM import in node:
1920
1987
  0 && (module.exports = {
1921
1988
  AgentSession,