@langchain/core 0.3.60 → 0.3.61
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.
|
@@ -17,7 +17,7 @@ Object.defineProperty(exports, "Validator", { enumerable: true, get: function ()
|
|
|
17
17
|
*/
|
|
18
18
|
function toJsonSchema(schema) {
|
|
19
19
|
if ((0, zod_js_1.isZodSchemaV4)(schema)) {
|
|
20
|
-
const inputSchema = (0, zod_js_1.interopZodTransformInputSchema)(schema);
|
|
20
|
+
const inputSchema = (0, zod_js_1.interopZodTransformInputSchema)(schema, true);
|
|
21
21
|
if ((0, zod_js_1.isZodObjectV4)(inputSchema)) {
|
|
22
22
|
const strictSchema = (0, zod_js_1.interopZodObjectStrict)(inputSchema, true);
|
|
23
23
|
return (0, core_1.toJSONSchema)(strictSchema);
|
|
@@ -10,7 +10,7 @@ export { deepCompareStrict, Validator } from "@cfworker/json-schema";
|
|
|
10
10
|
*/
|
|
11
11
|
export function toJsonSchema(schema) {
|
|
12
12
|
if (isZodSchemaV4(schema)) {
|
|
13
|
-
const inputSchema = interopZodTransformInputSchema(schema);
|
|
13
|
+
const inputSchema = interopZodTransformInputSchema(schema, true);
|
|
14
14
|
if (isZodObjectV4(inputSchema)) {
|
|
15
15
|
const strictSchema = interopZodObjectStrict(inputSchema, true);
|
|
16
16
|
return toJSONSchema(strictSchema);
|
package/dist/utils/types/zod.cjs
CHANGED
|
@@ -566,26 +566,54 @@ function isZodTransformV4(schema) {
|
|
|
566
566
|
}
|
|
567
567
|
/**
|
|
568
568
|
* Returns the input type of a Zod transform schema, for both v3 and v4.
|
|
569
|
-
* If the schema is not a transform, returns undefined.
|
|
569
|
+
* If the schema is not a transform, returns undefined. If `recursive` is true,
|
|
570
|
+
* recursively processes nested object schemas and arrays of object schemas.
|
|
570
571
|
*
|
|
571
572
|
* @param schema - The Zod schema instance (v3 or v4)
|
|
573
|
+
* @param {boolean} [recursive=false] - Whether to recursively process nested objects/arrays.
|
|
572
574
|
* @returns The input Zod schema of the transform, or undefined if not a transform
|
|
573
575
|
*/
|
|
574
|
-
function interopZodTransformInputSchema(schema) {
|
|
576
|
+
function interopZodTransformInputSchema(schema, recursive = false) {
|
|
575
577
|
// Zod v3: ._def.schema is the input schema for ZodEffects (transform)
|
|
576
578
|
if (isZodSchemaV3(schema)) {
|
|
577
579
|
if (isZodTransformV3(schema)) {
|
|
578
|
-
return interopZodTransformInputSchema(schema._def.schema);
|
|
580
|
+
return interopZodTransformInputSchema(schema._def.schema, recursive);
|
|
579
581
|
}
|
|
582
|
+
// TODO: v3 schemas aren't recursively handled here
|
|
583
|
+
// (currently not necessary since zodToJsonSchema handles this)
|
|
580
584
|
return schema;
|
|
581
585
|
}
|
|
582
586
|
// Zod v4: _def.type is the input schema for ZodEffects (transform)
|
|
583
587
|
if (isZodSchemaV4(schema)) {
|
|
588
|
+
let outputSchema = schema;
|
|
584
589
|
if (isZodTransformV4(schema)) {
|
|
585
|
-
|
|
586
|
-
return inner ?? schema;
|
|
590
|
+
outputSchema = interopZodTransformInputSchema(schema._zod.def.in, recursive);
|
|
587
591
|
}
|
|
588
|
-
|
|
592
|
+
if (recursive) {
|
|
593
|
+
// Handle nested object schemas
|
|
594
|
+
if (isZodObjectV4(outputSchema)) {
|
|
595
|
+
const outputShape = outputSchema._zod.def.shape;
|
|
596
|
+
for (const [key, keySchema] of Object.entries(outputSchema._zod.def.shape)) {
|
|
597
|
+
outputShape[key] = interopZodTransformInputSchema(keySchema, recursive);
|
|
598
|
+
}
|
|
599
|
+
outputSchema = (0, core_1.clone)(outputSchema, {
|
|
600
|
+
...outputSchema._zod.def,
|
|
601
|
+
shape: outputShape,
|
|
602
|
+
});
|
|
603
|
+
}
|
|
604
|
+
// Handle nested array schemas
|
|
605
|
+
else if (isZodArrayV4(outputSchema)) {
|
|
606
|
+
const elementSchema = interopZodTransformInputSchema(outputSchema._zod.def.element, recursive);
|
|
607
|
+
outputSchema = (0, core_1.clone)(outputSchema, {
|
|
608
|
+
...outputSchema._zod.def,
|
|
609
|
+
element: elementSchema,
|
|
610
|
+
});
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
const meta = core_1.globalRegistry.get(schema);
|
|
614
|
+
if (meta)
|
|
615
|
+
core_1.globalRegistry.add(outputSchema, meta);
|
|
616
|
+
return outputSchema;
|
|
589
617
|
}
|
|
590
618
|
throw new Error("Schema must be an instance of z3.ZodType or z4.$ZodType");
|
|
591
619
|
}
|
|
@@ -201,10 +201,12 @@ export declare function interopZodObjectPassthrough<T extends InteropZodObject>(
|
|
|
201
201
|
export declare function getInteropZodDefaultGetter<T extends InteropZodType>(schema: T): (() => InferInteropZodOutput<T>) | undefined;
|
|
202
202
|
/**
|
|
203
203
|
* Returns the input type of a Zod transform schema, for both v3 and v4.
|
|
204
|
-
* If the schema is not a transform, returns undefined.
|
|
204
|
+
* If the schema is not a transform, returns undefined. If `recursive` is true,
|
|
205
|
+
* recursively processes nested object schemas and arrays of object schemas.
|
|
205
206
|
*
|
|
206
207
|
* @param schema - The Zod schema instance (v3 or v4)
|
|
208
|
+
* @param {boolean} [recursive=false] - Whether to recursively process nested objects/arrays.
|
|
207
209
|
* @returns The input Zod schema of the transform, or undefined if not a transform
|
|
208
210
|
*/
|
|
209
|
-
export declare function interopZodTransformInputSchema(schema: InteropZodType): InteropZodType
|
|
211
|
+
export declare function interopZodTransformInputSchema(schema: InteropZodType, recursive?: boolean): InteropZodType;
|
|
210
212
|
export {};
|
package/dist/utils/types/zod.js
CHANGED
|
@@ -542,26 +542,54 @@ function isZodTransformV4(schema) {
|
|
|
542
542
|
}
|
|
543
543
|
/**
|
|
544
544
|
* Returns the input type of a Zod transform schema, for both v3 and v4.
|
|
545
|
-
* If the schema is not a transform, returns undefined.
|
|
545
|
+
* If the schema is not a transform, returns undefined. If `recursive` is true,
|
|
546
|
+
* recursively processes nested object schemas and arrays of object schemas.
|
|
546
547
|
*
|
|
547
548
|
* @param schema - The Zod schema instance (v3 or v4)
|
|
549
|
+
* @param {boolean} [recursive=false] - Whether to recursively process nested objects/arrays.
|
|
548
550
|
* @returns The input Zod schema of the transform, or undefined if not a transform
|
|
549
551
|
*/
|
|
550
|
-
export function interopZodTransformInputSchema(schema) {
|
|
552
|
+
export function interopZodTransformInputSchema(schema, recursive = false) {
|
|
551
553
|
// Zod v3: ._def.schema is the input schema for ZodEffects (transform)
|
|
552
554
|
if (isZodSchemaV3(schema)) {
|
|
553
555
|
if (isZodTransformV3(schema)) {
|
|
554
|
-
return interopZodTransformInputSchema(schema._def.schema);
|
|
556
|
+
return interopZodTransformInputSchema(schema._def.schema, recursive);
|
|
555
557
|
}
|
|
558
|
+
// TODO: v3 schemas aren't recursively handled here
|
|
559
|
+
// (currently not necessary since zodToJsonSchema handles this)
|
|
556
560
|
return schema;
|
|
557
561
|
}
|
|
558
562
|
// Zod v4: _def.type is the input schema for ZodEffects (transform)
|
|
559
563
|
if (isZodSchemaV4(schema)) {
|
|
564
|
+
let outputSchema = schema;
|
|
560
565
|
if (isZodTransformV4(schema)) {
|
|
561
|
-
|
|
562
|
-
return inner ?? schema;
|
|
566
|
+
outputSchema = interopZodTransformInputSchema(schema._zod.def.in, recursive);
|
|
563
567
|
}
|
|
564
|
-
|
|
568
|
+
if (recursive) {
|
|
569
|
+
// Handle nested object schemas
|
|
570
|
+
if (isZodObjectV4(outputSchema)) {
|
|
571
|
+
const outputShape = outputSchema._zod.def.shape;
|
|
572
|
+
for (const [key, keySchema] of Object.entries(outputSchema._zod.def.shape)) {
|
|
573
|
+
outputShape[key] = interopZodTransformInputSchema(keySchema, recursive);
|
|
574
|
+
}
|
|
575
|
+
outputSchema = clone(outputSchema, {
|
|
576
|
+
...outputSchema._zod.def,
|
|
577
|
+
shape: outputShape,
|
|
578
|
+
});
|
|
579
|
+
}
|
|
580
|
+
// Handle nested array schemas
|
|
581
|
+
else if (isZodArrayV4(outputSchema)) {
|
|
582
|
+
const elementSchema = interopZodTransformInputSchema(outputSchema._zod.def.element, recursive);
|
|
583
|
+
outputSchema = clone(outputSchema, {
|
|
584
|
+
...outputSchema._zod.def,
|
|
585
|
+
element: elementSchema,
|
|
586
|
+
});
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
const meta = globalRegistry.get(schema);
|
|
590
|
+
if (meta)
|
|
591
|
+
globalRegistry.add(outputSchema, meta);
|
|
592
|
+
return outputSchema;
|
|
565
593
|
}
|
|
566
594
|
throw new Error("Schema must be an instance of z3.ZodType or z4.$ZodType");
|
|
567
595
|
}
|