@langchain/core 0.3.59-rc.2 → 0.3.60

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.
Files changed (100) hide show
  1. package/dist/caches/base.cjs +28 -5
  2. package/dist/caches/base.d.ts +13 -1
  3. package/dist/caches/base.js +25 -2
  4. package/dist/callbacks/base.cjs +19 -9
  5. package/dist/callbacks/base.d.ts +37 -22
  6. package/dist/callbacks/dispatch/index.cjs +1 -2
  7. package/dist/callbacks/dispatch/web.cjs +1 -2
  8. package/dist/callbacks/manager.cjs +4 -4
  9. package/dist/callbacks/manager.d.ts +2 -2
  10. package/dist/errors/index.cjs +1 -2
  11. package/dist/example_selectors/conditional.cjs +3 -3
  12. package/dist/indexing/base.cjs +19 -7
  13. package/dist/indexing/base.d.ts +3 -0
  14. package/dist/indexing/base.js +14 -2
  15. package/dist/language_models/base.cjs +31 -7
  16. package/dist/language_models/base.d.ts +5 -0
  17. package/dist/language_models/base.js +29 -5
  18. package/dist/language_models/chat_models.cjs +2 -2
  19. package/dist/load/import_map.cjs +17 -7
  20. package/dist/load/index.cjs +18 -9
  21. package/dist/load/map_keys.cjs +3 -4
  22. package/dist/load/serializable.cjs +2 -2
  23. package/dist/memory.cjs +2 -2
  24. package/dist/messages/ai.cjs +3 -3
  25. package/dist/messages/base.cjs +10 -10
  26. package/dist/messages/chat.cjs +3 -3
  27. package/dist/messages/content_blocks.cjs +9 -10
  28. package/dist/messages/function.cjs +3 -3
  29. package/dist/messages/human.cjs +3 -3
  30. package/dist/messages/system.cjs +3 -3
  31. package/dist/messages/tool.cjs +5 -5
  32. package/dist/messages/transformers.cjs +4 -5
  33. package/dist/messages/utils.cjs +6 -7
  34. package/dist/output_parsers/openai_tools/json_output_tools_parsers.cjs +4 -4
  35. package/dist/output_parsers/xml.cjs +2 -2
  36. package/dist/prompts/base.cjs +36 -3
  37. package/dist/runnables/base.cjs +7 -5
  38. package/dist/runnables/base.d.ts +1 -1
  39. package/dist/runnables/base.js +3 -1
  40. package/dist/runnables/config.cjs +6 -6
  41. package/dist/runnables/graph_mermaid.cjs +2 -3
  42. package/dist/runnables/iter.cjs +5 -5
  43. package/dist/runnables/iter.d.ts +1 -1
  44. package/dist/runnables/utils.cjs +2 -2
  45. package/dist/runnables/wrappers.cjs +1 -2
  46. package/dist/runnables/wrappers.d.ts +1 -1
  47. package/dist/singletons/async_local_storage/context.cjs +3 -3
  48. package/dist/singletons/callbacks.cjs +3 -4
  49. package/dist/singletons/callbacks.d.ts +1 -1
  50. package/dist/structured_query/utils.cjs +7 -8
  51. package/dist/tools/index.cjs +2 -2
  52. package/dist/tools/types.cjs +4 -5
  53. package/dist/tools/utils.cjs +3 -3
  54. package/dist/tracers/base.cjs +2 -2
  55. package/dist/tracers/base.d.ts +84 -84
  56. package/dist/tracers/initialize.cjs +2 -3
  57. package/dist/utils/async_caller.cjs +9 -9
  58. package/dist/utils/async_caller.js +9 -9
  59. package/dist/utils/env.cjs +4 -4
  60. package/dist/utils/event_source_parse.cjs +5 -5
  61. package/dist/utils/fast-json-patch/index.cjs +17 -7
  62. package/dist/utils/fast-json-patch/index.d.ts +4 -4
  63. package/dist/utils/fast-json-patch/src/core.cjs +8 -8
  64. package/dist/utils/fast-json-patch/src/duplex.cjs +4 -5
  65. package/dist/utils/fast-json-patch/src/helpers.cjs +10 -10
  66. package/dist/utils/fast-json-patch/src/helpers.d.ts +3 -3
  67. package/dist/utils/function_calling.cjs +3 -3
  68. package/dist/utils/hash.cjs +3 -1
  69. package/dist/utils/hash.d.ts +7 -0
  70. package/dist/utils/hash.js +1 -0
  71. package/dist/utils/js-sha1/hash.cjs +17 -0
  72. package/dist/utils/js-sha1/hash.d.ts +4 -0
  73. package/dist/utils/js-sha1/hash.js +17 -0
  74. package/dist/utils/js-sha256/hash.cjs +448 -0
  75. package/dist/utils/js-sha256/hash.d.ts +1 -0
  76. package/dist/utils/js-sha256/hash.js +445 -0
  77. package/dist/utils/json.cjs +2 -3
  78. package/dist/utils/json_schema.cjs +11 -4
  79. package/dist/utils/json_schema.js +9 -2
  80. package/dist/utils/math.cjs +6 -7
  81. package/dist/utils/ml-distance/distances.cjs +1 -2
  82. package/dist/utils/ml-distance/similarities.cjs +1 -2
  83. package/dist/utils/ml-distance-euclidean/euclidean.cjs +2 -3
  84. package/dist/utils/sax-js/sax.cjs +35 -35
  85. package/dist/utils/sax-js/sax.js +35 -35
  86. package/dist/utils/signal.cjs +1 -2
  87. package/dist/utils/stream.cjs +4 -4
  88. package/dist/utils/tiktoken.cjs +2 -3
  89. package/dist/utils/types/zod.cjs +223 -56
  90. package/dist/utils/types/zod.d.ts +38 -1
  91. package/dist/utils/types/zod.js +202 -39
  92. package/package.json +30 -4
  93. package/utils/hash/insecure.cjs +1 -0
  94. package/utils/hash/insecure.d.cts +1 -0
  95. package/utils/hash/insecure.d.ts +1 -0
  96. package/utils/hash/insecure.js +1 -0
  97. package/utils/hash/sha256.cjs +1 -0
  98. package/utils/hash/sha256.d.cts +1 -0
  99. package/utils/hash/sha256.d.ts +1 -0
  100. package/utils/hash/sha256.js +1 -0
@@ -282,41 +282,41 @@ const initializeSax = function () {
282
282
  }
283
283
  var S = 0;
284
284
  sax.STATE = {
285
- BEGIN: S++,
286
- BEGIN_WHITESPACE: S++,
287
- TEXT: S++,
288
- TEXT_ENTITY: S++,
289
- OPEN_WAKA: S++,
290
- SGML_DECL: S++,
291
- SGML_DECL_QUOTED: S++,
292
- DOCTYPE: S++,
293
- DOCTYPE_QUOTED: S++,
294
- DOCTYPE_DTD: S++,
295
- DOCTYPE_DTD_QUOTED: S++,
296
- COMMENT_STARTING: S++,
297
- COMMENT: S++,
298
- COMMENT_ENDING: S++,
299
- COMMENT_ENDED: S++,
300
- CDATA: S++,
301
- CDATA_ENDING: S++,
302
- CDATA_ENDING_2: S++,
303
- PROC_INST: S++,
304
- PROC_INST_BODY: S++,
305
- PROC_INST_ENDING: S++,
306
- OPEN_TAG: S++,
307
- OPEN_TAG_SLASH: S++,
308
- ATTRIB: S++,
309
- ATTRIB_NAME: S++,
310
- ATTRIB_NAME_SAW_WHITE: S++,
311
- ATTRIB_VALUE: S++,
312
- ATTRIB_VALUE_QUOTED: S++,
313
- ATTRIB_VALUE_CLOSED: S++,
314
- ATTRIB_VALUE_UNQUOTED: S++,
315
- ATTRIB_VALUE_ENTITY_Q: S++,
316
- ATTRIB_VALUE_ENTITY_U: S++,
317
- CLOSE_TAG: S++,
318
- CLOSE_TAG_SAW_WHITE: S++,
319
- SCRIPT: S++,
285
+ BEGIN: S++, // leading byte order mark or whitespace
286
+ BEGIN_WHITESPACE: S++, // leading whitespace
287
+ TEXT: S++, // general stuff
288
+ TEXT_ENTITY: S++, // &amp and such.
289
+ OPEN_WAKA: S++, // <
290
+ SGML_DECL: S++, // <!BLARG
291
+ SGML_DECL_QUOTED: S++, // <!BLARG foo "bar
292
+ DOCTYPE: S++, // <!DOCTYPE
293
+ DOCTYPE_QUOTED: S++, // <!DOCTYPE "//blah
294
+ DOCTYPE_DTD: S++, // <!DOCTYPE "//blah" [ ...
295
+ DOCTYPE_DTD_QUOTED: S++, // <!DOCTYPE "//blah" [ "foo
296
+ COMMENT_STARTING: S++, // <!-
297
+ COMMENT: S++, // <!--
298
+ COMMENT_ENDING: S++, // <!-- blah -
299
+ COMMENT_ENDED: S++, // <!-- blah --
300
+ CDATA: S++, // <![CDATA[ something
301
+ CDATA_ENDING: S++, // ]
302
+ CDATA_ENDING_2: S++, // ]]
303
+ PROC_INST: S++, // <?hi
304
+ PROC_INST_BODY: S++, // <?hi there
305
+ PROC_INST_ENDING: S++, // <?hi "there" ?
306
+ OPEN_TAG: S++, // <strong
307
+ OPEN_TAG_SLASH: S++, // <strong /
308
+ ATTRIB: S++, // <a
309
+ ATTRIB_NAME: S++, // <a foo
310
+ ATTRIB_NAME_SAW_WHITE: S++, // <a foo _
311
+ ATTRIB_VALUE: S++, // <a foo=
312
+ ATTRIB_VALUE_QUOTED: S++, // <a foo="bar
313
+ ATTRIB_VALUE_CLOSED: S++, // <a foo="bar"
314
+ ATTRIB_VALUE_UNQUOTED: S++, // <a foo=bar
315
+ ATTRIB_VALUE_ENTITY_Q: S++, // <foo bar="&quot;"
316
+ ATTRIB_VALUE_ENTITY_U: S++, // <foo bar=&quot
317
+ CLOSE_TAG: S++, // </a
318
+ CLOSE_TAG_SAW_WHITE: S++, // </a >
319
+ SCRIPT: S++, // <script> ...
320
320
  SCRIPT_ENDING: S++, // <script> ... <
321
321
  };
322
322
  sax.XML_ENTITIES = {
@@ -279,41 +279,41 @@ const initializeSax = function () {
279
279
  }
280
280
  var S = 0;
281
281
  sax.STATE = {
282
- BEGIN: S++,
283
- BEGIN_WHITESPACE: S++,
284
- TEXT: S++,
285
- TEXT_ENTITY: S++,
286
- OPEN_WAKA: S++,
287
- SGML_DECL: S++,
288
- SGML_DECL_QUOTED: S++,
289
- DOCTYPE: S++,
290
- DOCTYPE_QUOTED: S++,
291
- DOCTYPE_DTD: S++,
292
- DOCTYPE_DTD_QUOTED: S++,
293
- COMMENT_STARTING: S++,
294
- COMMENT: S++,
295
- COMMENT_ENDING: S++,
296
- COMMENT_ENDED: S++,
297
- CDATA: S++,
298
- CDATA_ENDING: S++,
299
- CDATA_ENDING_2: S++,
300
- PROC_INST: S++,
301
- PROC_INST_BODY: S++,
302
- PROC_INST_ENDING: S++,
303
- OPEN_TAG: S++,
304
- OPEN_TAG_SLASH: S++,
305
- ATTRIB: S++,
306
- ATTRIB_NAME: S++,
307
- ATTRIB_NAME_SAW_WHITE: S++,
308
- ATTRIB_VALUE: S++,
309
- ATTRIB_VALUE_QUOTED: S++,
310
- ATTRIB_VALUE_CLOSED: S++,
311
- ATTRIB_VALUE_UNQUOTED: S++,
312
- ATTRIB_VALUE_ENTITY_Q: S++,
313
- ATTRIB_VALUE_ENTITY_U: S++,
314
- CLOSE_TAG: S++,
315
- CLOSE_TAG_SAW_WHITE: S++,
316
- SCRIPT: S++,
282
+ BEGIN: S++, // leading byte order mark or whitespace
283
+ BEGIN_WHITESPACE: S++, // leading whitespace
284
+ TEXT: S++, // general stuff
285
+ TEXT_ENTITY: S++, // &amp and such.
286
+ OPEN_WAKA: S++, // <
287
+ SGML_DECL: S++, // <!BLARG
288
+ SGML_DECL_QUOTED: S++, // <!BLARG foo "bar
289
+ DOCTYPE: S++, // <!DOCTYPE
290
+ DOCTYPE_QUOTED: S++, // <!DOCTYPE "//blah
291
+ DOCTYPE_DTD: S++, // <!DOCTYPE "//blah" [ ...
292
+ DOCTYPE_DTD_QUOTED: S++, // <!DOCTYPE "//blah" [ "foo
293
+ COMMENT_STARTING: S++, // <!-
294
+ COMMENT: S++, // <!--
295
+ COMMENT_ENDING: S++, // <!-- blah -
296
+ COMMENT_ENDED: S++, // <!-- blah --
297
+ CDATA: S++, // <![CDATA[ something
298
+ CDATA_ENDING: S++, // ]
299
+ CDATA_ENDING_2: S++, // ]]
300
+ PROC_INST: S++, // <?hi
301
+ PROC_INST_BODY: S++, // <?hi there
302
+ PROC_INST_ENDING: S++, // <?hi "there" ?
303
+ OPEN_TAG: S++, // <strong
304
+ OPEN_TAG_SLASH: S++, // <strong /
305
+ ATTRIB: S++, // <a
306
+ ATTRIB_NAME: S++, // <a foo
307
+ ATTRIB_NAME_SAW_WHITE: S++, // <a foo _
308
+ ATTRIB_VALUE: S++, // <a foo=
309
+ ATTRIB_VALUE_QUOTED: S++, // <a foo="bar
310
+ ATTRIB_VALUE_CLOSED: S++, // <a foo="bar"
311
+ ATTRIB_VALUE_UNQUOTED: S++, // <a foo=bar
312
+ ATTRIB_VALUE_ENTITY_Q: S++, // <foo bar="&quot;"
313
+ ATTRIB_VALUE_ENTITY_U: S++, // <foo bar=&quot
314
+ CLOSE_TAG: S++, // </a
315
+ CLOSE_TAG_SAW_WHITE: S++, // </a >
316
+ SCRIPT: S++, // <script> ...
317
317
  SCRIPT_ENDING: S++, // <script> ... <
318
318
  };
319
319
  sax.XML_ENTITIES = {
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.raceWithSignal = void 0;
3
+ exports.raceWithSignal = raceWithSignal;
4
4
  async function raceWithSignal(promise, signal) {
5
5
  if (signal === undefined) {
6
6
  return promise;
@@ -27,4 +27,3 @@ async function raceWithSignal(promise, signal) {
27
27
  }),
28
28
  ]).finally(() => signal.removeEventListener("abort", listener));
29
29
  }
30
- exports.raceWithSignal = raceWithSignal;
@@ -1,6 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.pipeGeneratorWithSetup = exports.AsyncGeneratorWithSetup = exports.concat = exports.atee = exports.IterableReadableStream = void 0;
3
+ exports.AsyncGeneratorWithSetup = exports.IterableReadableStream = void 0;
4
+ exports.atee = atee;
5
+ exports.concat = concat;
6
+ exports.pipeGeneratorWithSetup = pipeGeneratorWithSetup;
4
7
  const config_js_1 = require("../runnables/config.cjs");
5
8
  const index_js_1 = require("../singletons/index.cjs");
6
9
  const signal_js_1 = require("./signal.cjs");
@@ -136,7 +139,6 @@ function atee(iter, length = 2) {
136
139
  }
137
140
  });
138
141
  }
139
- exports.atee = atee;
140
142
  function concat(first, second) {
141
143
  if (Array.isArray(first) && Array.isArray(second)) {
142
144
  return first.concat(second);
@@ -173,7 +175,6 @@ function concat(first, second) {
173
175
  throw new Error(`Cannot concat ${typeof first} and ${typeof second}`);
174
176
  }
175
177
  }
176
- exports.concat = concat;
177
178
  class AsyncGeneratorWithSetup {
178
179
  constructor(params) {
179
180
  Object.defineProperty(this, "generator", {
@@ -271,4 +272,3 @@ async function pipeGeneratorWithSetup(to, generator, startSetup, signal, ...args
271
272
  const setup = await gen.setup;
272
273
  return { output: to(gen, setup, ...args), setup };
273
274
  }
274
- exports.pipeGeneratorWithSetup = pipeGeneratorWithSetup;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.encodingForModel = exports.getEncoding = void 0;
3
+ exports.getEncoding = getEncoding;
4
+ exports.encodingForModel = encodingForModel;
4
5
  const lite_1 = require("js-tiktoken/lite");
5
6
  const async_caller_js_1 = require("./async_caller.cjs");
6
7
  const cache = {};
@@ -18,8 +19,6 @@ async function getEncoding(encoding) {
18
19
  }
19
20
  return await cache[encoding];
20
21
  }
21
- exports.getEncoding = getEncoding;
22
22
  async function encodingForModel(model) {
23
23
  return getEncoding((0, lite_1.getEncodingNameForModel)(model));
24
24
  }
25
- exports.encodingForModel = encodingForModel;
@@ -1,6 +1,27 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getInteropZodDefaultGetter = exports.interopZodObjectPassthrough = exports.interopZodObjectPartial = exports.extendInteropZodObject = exports.getInteropZodObjectShape = exports.isInteropZodObject = exports.isSimpleStringZodSchema = exports.isShapelessZodSchema = exports.getSchemaDescription = exports.interopParse = exports.interopSafeParse = exports.interopParseAsync = exports.interopSafeParseAsync = exports.isInteropZodSchema = exports.isZodSchema = exports.isZodSchemaV3 = exports.isZodSchemaV4 = void 0;
3
+ exports.isZodSchemaV4 = isZodSchemaV4;
4
+ exports.isZodSchemaV3 = isZodSchemaV3;
5
+ exports.isZodSchema = isZodSchema;
6
+ exports.isInteropZodSchema = isInteropZodSchema;
7
+ exports.interopSafeParseAsync = interopSafeParseAsync;
8
+ exports.interopParseAsync = interopParseAsync;
9
+ exports.interopSafeParse = interopSafeParse;
10
+ exports.interopParse = interopParse;
11
+ exports.getSchemaDescription = getSchemaDescription;
12
+ exports.isShapelessZodSchema = isShapelessZodSchema;
13
+ exports.isSimpleStringZodSchema = isSimpleStringZodSchema;
14
+ exports.isZodObjectV3 = isZodObjectV3;
15
+ exports.isZodObjectV4 = isZodObjectV4;
16
+ exports.isZodArrayV4 = isZodArrayV4;
17
+ exports.isInteropZodObject = isInteropZodObject;
18
+ exports.getInteropZodObjectShape = getInteropZodObjectShape;
19
+ exports.extendInteropZodObject = extendInteropZodObject;
20
+ exports.interopZodObjectPartial = interopZodObjectPartial;
21
+ exports.interopZodObjectStrict = interopZodObjectStrict;
22
+ exports.interopZodObjectPassthrough = interopZodObjectPassthrough;
23
+ exports.getInteropZodDefaultGetter = getInteropZodDefaultGetter;
24
+ exports.interopZodTransformInputSchema = interopZodTransformInputSchema;
4
25
  const core_1 = require("zod/v4/core");
5
26
  function isZodSchemaV4(schema) {
6
27
  if (typeof schema !== "object" || schema === null) {
@@ -15,7 +36,6 @@ function isZodSchemaV4(schema) {
15
36
  zod !== null &&
16
37
  "def" in zod);
17
38
  }
18
- exports.isZodSchemaV4 = isZodSchemaV4;
19
39
  function isZodSchemaV3(schema) {
20
40
  if (typeof schema !== "object" || schema === null) {
21
41
  return false;
@@ -29,7 +49,6 @@ function isZodSchemaV3(schema) {
29
49
  def != null &&
30
50
  "typeName" in def);
31
51
  }
32
- exports.isZodSchemaV3 = isZodSchemaV3;
33
52
  /** Backward compatible isZodSchema for Zod 3 */
34
53
  function isZodSchema(schema) {
35
54
  if (isZodSchemaV4(schema)) {
@@ -37,7 +56,6 @@ function isZodSchema(schema) {
37
56
  }
38
57
  return isZodSchemaV3(schema);
39
58
  }
40
- exports.isZodSchema = isZodSchema;
41
59
  /**
42
60
  * Given either a Zod schema, or plain object, determine if the input is a Zod schema.
43
61
  *
@@ -60,7 +78,6 @@ function isInteropZodSchema(input) {
60
78
  }
61
79
  return false;
62
80
  }
63
- exports.isInteropZodSchema = isInteropZodSchema;
64
81
  /**
65
82
  * Asynchronously parses the input using the provided Zod schema (v3 or v4) and returns a safe parse result.
66
83
  * This function handles both Zod v3 and v4 schemas, returning a result object indicating success or failure.
@@ -92,7 +109,6 @@ async function interopSafeParseAsync(schema, input) {
92
109
  }
93
110
  throw new Error("Schema must be an instance of z3.ZodType or z4.$ZodType");
94
111
  }
95
- exports.interopSafeParseAsync = interopSafeParseAsync;
96
112
  /**
97
113
  * Asynchronously parses the input using the provided Zod schema (v3 or v4) and returns the parsed value.
98
114
  * Throws an error if parsing fails or if the schema is not a recognized Zod v3 or v4 schema.
@@ -112,7 +128,6 @@ async function interopParseAsync(schema, input) {
112
128
  }
113
129
  throw new Error("Schema must be an instance of z3.ZodType or z4.$ZodType");
114
130
  }
115
- exports.interopParseAsync = interopParseAsync;
116
131
  /**
117
132
  * Safely parses the input using the provided Zod schema (v3 or v4) and returns a result object
118
133
  * indicating success or failure. This function is compatible with both Zod v3 and v4 schemas.
@@ -145,7 +160,6 @@ function interopSafeParse(schema, input) {
145
160
  }
146
161
  throw new Error("Schema must be an instance of z3.ZodType or z4.$ZodType");
147
162
  }
148
- exports.interopSafeParse = interopSafeParse;
149
163
  /**
150
164
  * Parses the input using the provided Zod schema (v3 or v4) and returns the parsed value.
151
165
  * Throws an error if parsing fails or if the schema is not a recognized Zod v3 or v4 schema.
@@ -165,7 +179,6 @@ function interopParse(schema, input) {
165
179
  }
166
180
  throw new Error("Schema must be an instance of z3.ZodType or z4.$ZodType");
167
181
  }
168
- exports.interopParse = interopParse;
169
182
  /**
170
183
  * Retrieves the description from a schema definition (v3, v4, or plain object), if available.
171
184
  *
@@ -184,7 +197,6 @@ function getSchemaDescription(schema) {
184
197
  }
185
198
  return undefined;
186
199
  }
187
- exports.getSchemaDescription = getSchemaDescription;
188
200
  /**
189
201
  * Determines if the provided Zod schema is "shapeless".
190
202
  * A shapeless schema is one that does not define any object shape,
@@ -234,7 +246,6 @@ function isShapelessZodSchema(schema) {
234
246
  }
235
247
  return false;
236
248
  }
237
- exports.isShapelessZodSchema = isShapelessZodSchema;
238
249
  /**
239
250
  * Determines if the provided Zod schema should be treated as a simple string schema
240
251
  * that maps to DynamicTool. This aligns with the type-level constraint of
@@ -277,7 +288,55 @@ function isSimpleStringZodSchema(schema) {
277
288
  }
278
289
  return false;
279
290
  }
280
- exports.isSimpleStringZodSchema = isSimpleStringZodSchema;
291
+ function isZodObjectV3(obj) {
292
+ // Zod v3 object schemas have _def.typeName === "ZodObject"
293
+ if (typeof obj === "object" &&
294
+ obj !== null &&
295
+ "_def" in obj &&
296
+ typeof obj._def === "object" &&
297
+ obj._def !== null &&
298
+ "typeName" in obj._def &&
299
+ obj._def.typeName === "ZodObject") {
300
+ return true;
301
+ }
302
+ return false;
303
+ }
304
+ function isZodObjectV4(obj) {
305
+ if (!isZodSchemaV4(obj))
306
+ return false;
307
+ // Zod v4 object schemas have _zod.def.type === "object"
308
+ if (typeof obj === "object" &&
309
+ obj !== null &&
310
+ "_zod" in obj &&
311
+ typeof obj._zod === "object" &&
312
+ obj._zod !== null &&
313
+ "def" in obj._zod &&
314
+ typeof obj._zod.def === "object" &&
315
+ obj._zod.def !== null &&
316
+ "type" in obj._zod.def &&
317
+ obj._zod.def.type === "object") {
318
+ return true;
319
+ }
320
+ return false;
321
+ }
322
+ function isZodArrayV4(obj) {
323
+ if (!isZodSchemaV4(obj))
324
+ return false;
325
+ // Zod v4 array schemas have _zod.def.type === "array"
326
+ if (typeof obj === "object" &&
327
+ obj !== null &&
328
+ "_zod" in obj &&
329
+ typeof obj._zod === "object" &&
330
+ obj._zod !== null &&
331
+ "def" in obj._zod &&
332
+ typeof obj._zod.def === "object" &&
333
+ obj._zod.def !== null &&
334
+ "type" in obj._zod.def &&
335
+ obj._zod.def.type === "array") {
336
+ return true;
337
+ }
338
+ return false;
339
+ }
281
340
  /**
282
341
  * Determines if the provided value is an InteropZodObject (Zod v3 or v4 object schema).
283
342
  *
@@ -285,36 +344,12 @@ exports.isSimpleStringZodSchema = isSimpleStringZodSchema;
285
344
  * @returns {boolean} True if the value is a Zod v3 or v4 object schema, false otherwise.
286
345
  */
287
346
  function isInteropZodObject(obj) {
288
- if (isZodSchemaV3(obj)) {
289
- // Zod v3 object schemas have _def.typeName === "ZodObject"
290
- if (typeof obj === "object" &&
291
- obj !== null &&
292
- "_def" in obj &&
293
- typeof obj._def === "object" &&
294
- obj._def !== null &&
295
- "typeName" in obj._def &&
296
- obj._def.typeName === "ZodObject") {
297
- return true;
298
- }
299
- }
300
- if (isZodSchemaV4(obj)) {
301
- // Zod v4 object schemas have _zod.def.type === "object"
302
- if (typeof obj === "object" &&
303
- obj !== null &&
304
- "_zod" in obj &&
305
- typeof obj._zod === "object" &&
306
- obj._zod !== null &&
307
- "def" in obj._zod &&
308
- typeof obj._zod.def === "object" &&
309
- obj._zod.def !== null &&
310
- "type" in obj._zod.def &&
311
- obj._zod.def.type === "object") {
312
- return true;
313
- }
314
- }
347
+ if (isZodObjectV3(obj))
348
+ return true;
349
+ if (isZodObjectV4(obj))
350
+ return true;
315
351
  return false;
316
352
  }
317
- exports.isInteropZodObject = isInteropZodObject;
318
353
  /**
319
354
  * Retrieves the shape (fields) of a Zod object schema, supporting both Zod v3 and v4.
320
355
  *
@@ -332,7 +367,6 @@ function getInteropZodObjectShape(schema) {
332
367
  }
333
368
  throw new Error("Schema must be an instance of z3.ZodObject or z4.$ZodObject");
334
369
  }
335
- exports.getInteropZodObjectShape = getInteropZodObjectShape;
336
370
  /**
337
371
  * Extends a Zod object schema with additional fields, supporting both Zod v3 and v4.
338
372
  *
@@ -351,7 +385,6 @@ function extendInteropZodObject(schema, extension) {
351
385
  }
352
386
  throw new Error("Schema must be an instance of z3.ZodObject or z4.$ZodObject");
353
387
  }
354
- exports.extendInteropZodObject = extendInteropZodObject;
355
388
  /**
356
389
  * Returns a partial version of a Zod object schema, making all fields optional.
357
390
  * Supports both Zod v3 and v4.
@@ -372,24 +405,126 @@ function interopZodObjectPartial(schema) {
372
405
  }
373
406
  throw new Error("Schema must be an instance of z3.ZodObject or z4.$ZodObject");
374
407
  }
375
- exports.interopZodObjectPartial = interopZodObjectPartial;
376
- function interopZodObjectPassthrough(schema) {
377
- if (isInteropZodObject(schema)) {
378
- if (isZodSchemaV3(schema)) {
379
- return schema.passthrough();
408
+ /**
409
+ * Returns a strict version of a Zod object schema, disallowing unknown keys.
410
+ * Supports both Zod v3 and v4 object schemas. If `recursive` is true, applies strictness
411
+ * recursively to all nested object schemas and arrays of object schemas.
412
+ *
413
+ * @template T - The type of the Zod object schema.
414
+ * @param {T} schema - The Zod object schema instance (either v3 or v4).
415
+ * @param {boolean} [recursive=false] - Whether to apply strictness recursively to nested objects/arrays.
416
+ * @returns {InteropZodObject} The strict Zod object schema.
417
+ * @throws {Error} If the schema is not a Zod v3 or v4 object.
418
+ */
419
+ function interopZodObjectStrict(schema, recursive = false) {
420
+ if (isZodSchemaV3(schema)) {
421
+ // TODO: v3 schemas aren't recursively handled here
422
+ // (currently not necessary since zodToJsonSchema handles this)
423
+ return schema.strict();
424
+ }
425
+ if (isZodObjectV4(schema)) {
426
+ const outputShape = schema._zod.def.shape;
427
+ if (recursive) {
428
+ for (const [key, keySchema] of Object.entries(schema._zod.def.shape)) {
429
+ // If the shape key is a v4 object schema, we need to make it strict
430
+ if (isZodObjectV4(keySchema)) {
431
+ const outputSchema = interopZodObjectStrict(keySchema, recursive);
432
+ outputShape[key] = outputSchema;
433
+ }
434
+ // If the shape key is a v4 array schema, we need to make the element
435
+ // schema strict if it's an object schema
436
+ else if (isZodArrayV4(keySchema)) {
437
+ let elementSchema = keySchema._zod.def.element;
438
+ if (isZodObjectV4(elementSchema)) {
439
+ elementSchema = interopZodObjectStrict(elementSchema, recursive);
440
+ }
441
+ outputShape[key] = (0, core_1.clone)(keySchema, {
442
+ ...keySchema._zod.def,
443
+ element: elementSchema,
444
+ });
445
+ }
446
+ // Otherwise, just use the keySchema
447
+ else {
448
+ outputShape[key] = keySchema;
449
+ }
450
+ // Assign meta fields to the keySchema
451
+ const meta = core_1.globalRegistry.get(keySchema);
452
+ if (meta)
453
+ core_1.globalRegistry.add(outputShape[key], meta);
454
+ }
380
455
  }
381
- if (isZodSchemaV4(schema)) {
382
- // Type reassign since ZodObjectV4 assumes that generics should be washed
383
- const objectSchema = schema;
384
- return (0, core_1.clone)(objectSchema, {
385
- ...objectSchema._zod.def,
386
- catchall: (0, core_1._unknown)(core_1.$ZodUnknown),
387
- });
456
+ const modifiedSchema = (0, core_1.clone)(schema, {
457
+ ...schema._zod.def,
458
+ shape: outputShape,
459
+ catchall: (0, core_1._never)(core_1.$ZodNever),
460
+ });
461
+ const meta = core_1.globalRegistry.get(schema);
462
+ if (meta)
463
+ core_1.globalRegistry.add(modifiedSchema, meta);
464
+ return modifiedSchema;
465
+ }
466
+ throw new Error("Schema must be an instance of z3.ZodObject or z4.$ZodObject");
467
+ }
468
+ /**
469
+ * Returns a passthrough version of a Zod object schema, allowing unknown keys.
470
+ * Supports both Zod v3 and v4 object schemas. If `recursive` is true, applies passthrough
471
+ * recursively to all nested object schemas and arrays of object schemas.
472
+ *
473
+ * @template T - The type of the Zod object schema.
474
+ * @param {T} schema - The Zod object schema instance (either v3 or v4).
475
+ * @param {boolean} [recursive=false] - Whether to apply passthrough recursively to nested objects/arrays.
476
+ * @returns {InteropZodObject} The passthrough Zod object schema.
477
+ * @throws {Error} If the schema is not a Zod v3 or v4 object.
478
+ */
479
+ function interopZodObjectPassthrough(schema, recursive = false) {
480
+ if (isZodObjectV3(schema)) {
481
+ // TODO: v3 schemas aren't recursively handled here
482
+ // (currently not necessary since zodToJsonSchema handles this)
483
+ return schema.passthrough();
484
+ }
485
+ if (isZodObjectV4(schema)) {
486
+ const outputShape = schema._zod.def.shape;
487
+ if (recursive) {
488
+ for (const [key, keySchema] of Object.entries(schema._zod.def.shape)) {
489
+ // If the shape key is a v4 object schema, we need to make it passthrough
490
+ if (isZodObjectV4(keySchema)) {
491
+ const outputSchema = interopZodObjectPassthrough(keySchema, recursive);
492
+ outputShape[key] = outputSchema;
493
+ }
494
+ // If the shape key is a v4 array schema, we need to make the element
495
+ // schema passthrough if it's an object schema
496
+ else if (isZodArrayV4(keySchema)) {
497
+ let elementSchema = keySchema._zod.def.element;
498
+ if (isZodObjectV4(elementSchema)) {
499
+ elementSchema = interopZodObjectPassthrough(elementSchema, recursive);
500
+ }
501
+ outputShape[key] = (0, core_1.clone)(keySchema, {
502
+ ...keySchema._zod.def,
503
+ element: elementSchema,
504
+ });
505
+ }
506
+ // Otherwise, just use the keySchema
507
+ else {
508
+ outputShape[key] = keySchema;
509
+ }
510
+ // Assign meta fields to the keySchema
511
+ const meta = core_1.globalRegistry.get(keySchema);
512
+ if (meta)
513
+ core_1.globalRegistry.add(outputShape[key], meta);
514
+ }
388
515
  }
516
+ const modifiedSchema = (0, core_1.clone)(schema, {
517
+ ...schema._zod.def,
518
+ shape: outputShape,
519
+ catchall: (0, core_1._unknown)(core_1.$ZodUnknown),
520
+ });
521
+ const meta = core_1.globalRegistry.get(schema);
522
+ if (meta)
523
+ core_1.globalRegistry.add(modifiedSchema, meta);
524
+ return modifiedSchema;
389
525
  }
390
526
  throw new Error("Schema must be an instance of z3.ZodObject or z4.$ZodObject");
391
527
  }
392
- exports.interopZodObjectPassthrough = interopZodObjectPassthrough;
393
528
  /**
394
529
  * Returns a getter function for the default value of a Zod schema, if one is defined.
395
530
  * Supports both Zod v3 and v4 schemas. If the schema has a default value,
@@ -421,4 +556,36 @@ function getInteropZodDefaultGetter(schema) {
421
556
  }
422
557
  return undefined;
423
558
  }
424
- exports.getInteropZodDefaultGetter = getInteropZodDefaultGetter;
559
+ function isZodTransformV3(schema) {
560
+ return (isZodSchemaV3(schema) &&
561
+ "typeName" in schema._def &&
562
+ schema._def.typeName === "ZodEffects");
563
+ }
564
+ function isZodTransformV4(schema) {
565
+ return isZodSchemaV4(schema) && schema._zod.def.type === "pipe";
566
+ }
567
+ /**
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.
570
+ *
571
+ * @param schema - The Zod schema instance (v3 or v4)
572
+ * @returns The input Zod schema of the transform, or undefined if not a transform
573
+ */
574
+ function interopZodTransformInputSchema(schema) {
575
+ // Zod v3: ._def.schema is the input schema for ZodEffects (transform)
576
+ if (isZodSchemaV3(schema)) {
577
+ if (isZodTransformV3(schema)) {
578
+ return interopZodTransformInputSchema(schema._def.schema);
579
+ }
580
+ return schema;
581
+ }
582
+ // Zod v4: _def.type is the input schema for ZodEffects (transform)
583
+ if (isZodSchemaV4(schema)) {
584
+ if (isZodTransformV4(schema)) {
585
+ const inner = interopZodTransformInputSchema(schema._zod.def.in);
586
+ return inner ?? schema;
587
+ }
588
+ return schema;
589
+ }
590
+ throw new Error("Schema must be an instance of z3.ZodType or z4.$ZodType");
591
+ }