@modelnex/sdk 0.5.6 → 0.5.7

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.js CHANGED
@@ -739,32 +739,64 @@ function captureDomSummary(tags) {
739
739
  var import_zod = require("zod");
740
740
  function zodToJsonSchema(schema) {
741
741
  if (!schema) return {};
742
- const def = schema._def;
742
+ const schemaWithCompat = schema;
743
+ if (typeof schemaWithCompat.toJSONSchema === "function") {
744
+ try {
745
+ return schemaWithCompat.toJSONSchema();
746
+ } catch {
747
+ }
748
+ }
749
+ const def = schemaWithCompat._def ?? schemaWithCompat.def;
743
750
  if (!def) return {};
744
- if (def.typeName === import_zod.z.ZodFirstPartyTypeKind.ZodObject) {
745
- const shape = schema.shape;
751
+ const typeName = def.typeName ?? def.type;
752
+ const getShape = (value) => {
753
+ if (value.shape) return value.shape;
754
+ const valueDef = value._def ?? value.def;
755
+ const defShape = valueDef?.shape;
756
+ return typeof defShape === "function" ? defShape() : defShape;
757
+ };
758
+ const getInnerType = (value) => {
759
+ const valueDef = value._def ?? value.def;
760
+ return valueDef?.innerType;
761
+ };
762
+ const getDescription = (value) => {
763
+ const valueWithCompat = value;
764
+ return valueWithCompat.description ?? valueWithCompat._def?.description ?? valueWithCompat.def?.description;
765
+ };
766
+ if (typeName === import_zod.z.ZodFirstPartyTypeKind.ZodObject || typeName === "object") {
767
+ const shape = getShape(schemaWithCompat);
768
+ if (!shape) return {};
746
769
  const properties = {};
747
770
  const required = [];
748
771
  for (const key in shape) {
749
772
  let isOptional = false;
750
773
  let fieldSchema = shape[key];
751
- if (fieldSchema._def.typeName === import_zod.z.ZodFirstPartyTypeKind.ZodOptional) {
774
+ const fieldDef = fieldSchema._def ?? fieldSchema.def;
775
+ const fieldTypeName = fieldDef?.typeName ?? fieldDef?.type;
776
+ if (fieldTypeName === import_zod.z.ZodFirstPartyTypeKind.ZodOptional || fieldTypeName === "optional") {
752
777
  isOptional = true;
753
- fieldSchema = fieldSchema._def.innerType;
778
+ fieldSchema = getInnerType(fieldSchema) ?? fieldSchema;
754
779
  }
755
780
  properties[key] = zodToJsonSchema(fieldSchema);
756
- if (fieldSchema._def.description || shape[key]._def.description) {
757
- properties[key].description = fieldSchema._def.description || shape[key]._def.description;
781
+ const description = getDescription(fieldSchema) ?? getDescription(shape[key]);
782
+ if (description) {
783
+ properties[key].description = description;
758
784
  }
759
785
  if (!isOptional) required.push(key);
760
786
  }
761
787
  return { type: "object", properties, required };
762
788
  }
763
- if (def.typeName === import_zod.z.ZodFirstPartyTypeKind.ZodString) return { type: "string" };
764
- if (def.typeName === import_zod.z.ZodFirstPartyTypeKind.ZodNumber) return { type: "number" };
765
- if (def.typeName === import_zod.z.ZodFirstPartyTypeKind.ZodBoolean) return { type: "boolean" };
766
- if (def.typeName === import_zod.z.ZodFirstPartyTypeKind.ZodEnum) return { type: "string", enum: def.values };
767
- if (def.typeName === import_zod.z.ZodFirstPartyTypeKind.ZodArray) return { type: "array", items: zodToJsonSchema(def.type) };
789
+ if (typeName === import_zod.z.ZodFirstPartyTypeKind.ZodString || typeName === "string") return { type: "string" };
790
+ if (typeName === import_zod.z.ZodFirstPartyTypeKind.ZodNumber || typeName === "number") return { type: "number" };
791
+ if (typeName === import_zod.z.ZodFirstPartyTypeKind.ZodBoolean || typeName === "boolean") return { type: "boolean" };
792
+ if (typeName === import_zod.z.ZodFirstPartyTypeKind.ZodEnum || typeName === "enum") {
793
+ const values = def.values ?? Object.values(def.entries ?? {});
794
+ return { type: "string", enum: values };
795
+ }
796
+ if (typeName === import_zod.z.ZodFirstPartyTypeKind.ZodArray || typeName === "array") {
797
+ const arrayType = def.type ?? def.element;
798
+ return { type: "array", items: zodToJsonSchema(arrayType ?? {}) };
799
+ }
768
800
  return {};
769
801
  }
770
802
  function serializeActions(actions) {
package/dist/index.mjs CHANGED
@@ -530,32 +530,64 @@ function captureDomSummary(tags) {
530
530
  import { z } from "zod";
531
531
  function zodToJsonSchema(schema) {
532
532
  if (!schema) return {};
533
- const def = schema._def;
533
+ const schemaWithCompat = schema;
534
+ if (typeof schemaWithCompat.toJSONSchema === "function") {
535
+ try {
536
+ return schemaWithCompat.toJSONSchema();
537
+ } catch {
538
+ }
539
+ }
540
+ const def = schemaWithCompat._def ?? schemaWithCompat.def;
534
541
  if (!def) return {};
535
- if (def.typeName === z.ZodFirstPartyTypeKind.ZodObject) {
536
- const shape = schema.shape;
542
+ const typeName = def.typeName ?? def.type;
543
+ const getShape = (value) => {
544
+ if (value.shape) return value.shape;
545
+ const valueDef = value._def ?? value.def;
546
+ const defShape = valueDef?.shape;
547
+ return typeof defShape === "function" ? defShape() : defShape;
548
+ };
549
+ const getInnerType = (value) => {
550
+ const valueDef = value._def ?? value.def;
551
+ return valueDef?.innerType;
552
+ };
553
+ const getDescription = (value) => {
554
+ const valueWithCompat = value;
555
+ return valueWithCompat.description ?? valueWithCompat._def?.description ?? valueWithCompat.def?.description;
556
+ };
557
+ if (typeName === z.ZodFirstPartyTypeKind.ZodObject || typeName === "object") {
558
+ const shape = getShape(schemaWithCompat);
559
+ if (!shape) return {};
537
560
  const properties = {};
538
561
  const required = [];
539
562
  for (const key in shape) {
540
563
  let isOptional = false;
541
564
  let fieldSchema = shape[key];
542
- if (fieldSchema._def.typeName === z.ZodFirstPartyTypeKind.ZodOptional) {
565
+ const fieldDef = fieldSchema._def ?? fieldSchema.def;
566
+ const fieldTypeName = fieldDef?.typeName ?? fieldDef?.type;
567
+ if (fieldTypeName === z.ZodFirstPartyTypeKind.ZodOptional || fieldTypeName === "optional") {
543
568
  isOptional = true;
544
- fieldSchema = fieldSchema._def.innerType;
569
+ fieldSchema = getInnerType(fieldSchema) ?? fieldSchema;
545
570
  }
546
571
  properties[key] = zodToJsonSchema(fieldSchema);
547
- if (fieldSchema._def.description || shape[key]._def.description) {
548
- properties[key].description = fieldSchema._def.description || shape[key]._def.description;
572
+ const description = getDescription(fieldSchema) ?? getDescription(shape[key]);
573
+ if (description) {
574
+ properties[key].description = description;
549
575
  }
550
576
  if (!isOptional) required.push(key);
551
577
  }
552
578
  return { type: "object", properties, required };
553
579
  }
554
- if (def.typeName === z.ZodFirstPartyTypeKind.ZodString) return { type: "string" };
555
- if (def.typeName === z.ZodFirstPartyTypeKind.ZodNumber) return { type: "number" };
556
- if (def.typeName === z.ZodFirstPartyTypeKind.ZodBoolean) return { type: "boolean" };
557
- if (def.typeName === z.ZodFirstPartyTypeKind.ZodEnum) return { type: "string", enum: def.values };
558
- if (def.typeName === z.ZodFirstPartyTypeKind.ZodArray) return { type: "array", items: zodToJsonSchema(def.type) };
580
+ if (typeName === z.ZodFirstPartyTypeKind.ZodString || typeName === "string") return { type: "string" };
581
+ if (typeName === z.ZodFirstPartyTypeKind.ZodNumber || typeName === "number") return { type: "number" };
582
+ if (typeName === z.ZodFirstPartyTypeKind.ZodBoolean || typeName === "boolean") return { type: "boolean" };
583
+ if (typeName === z.ZodFirstPartyTypeKind.ZodEnum || typeName === "enum") {
584
+ const values = def.values ?? Object.values(def.entries ?? {});
585
+ return { type: "string", enum: values };
586
+ }
587
+ if (typeName === z.ZodFirstPartyTypeKind.ZodArray || typeName === "array") {
588
+ const arrayType = def.type ?? def.element;
589
+ return { type: "array", items: zodToJsonSchema(arrayType ?? {}) };
590
+ }
559
591
  return {};
560
592
  }
561
593
  function serializeActions(actions) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@modelnex/sdk",
3
- "version": "0.5.6",
3
+ "version": "0.5.7",
4
4
  "description": "React SDK for natural language control of web apps via AI agents",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",