@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 +44 -12
- package/dist/index.mjs +44 -12
- package/package.json +1 -1
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
|
|
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
|
-
|
|
745
|
-
|
|
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
|
-
|
|
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
|
|
778
|
+
fieldSchema = getInnerType(fieldSchema) ?? fieldSchema;
|
|
754
779
|
}
|
|
755
780
|
properties[key] = zodToJsonSchema(fieldSchema);
|
|
756
|
-
|
|
757
|
-
|
|
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 (
|
|
764
|
-
if (
|
|
765
|
-
if (
|
|
766
|
-
if (
|
|
767
|
-
|
|
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
|
|
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
|
-
|
|
536
|
-
|
|
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
|
-
|
|
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
|
|
569
|
+
fieldSchema = getInnerType(fieldSchema) ?? fieldSchema;
|
|
545
570
|
}
|
|
546
571
|
properties[key] = zodToJsonSchema(fieldSchema);
|
|
547
|
-
|
|
548
|
-
|
|
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 (
|
|
555
|
-
if (
|
|
556
|
-
if (
|
|
557
|
-
if (
|
|
558
|
-
|
|
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) {
|