@langchain/langgraph 0.3.1 → 0.3.3

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.
@@ -5,8 +5,8 @@ exports.getUpdateTypeSchema = getUpdateTypeSchema;
5
5
  exports.getInputTypeSchema = getInputTypeSchema;
6
6
  exports.getOutputTypeSchema = getOutputTypeSchema;
7
7
  exports.getConfigTypeSchema = getConfigTypeSchema;
8
- const zod_to_json_schema_1 = require("zod-to-json-schema");
9
- const state_js_1 = require("./state.cjs");
8
+ const json_schema_1 = require("@langchain/core/utils/json_schema");
9
+ const meta_js_1 = require("./meta.cjs");
10
10
  const PartialStateSchema = Symbol.for("langgraph.state.partial");
11
11
  function isGraphWithZodLike(graph) {
12
12
  if (!graph || typeof graph !== "object")
@@ -18,37 +18,59 @@ function isGraphWithZodLike(graph) {
18
18
  }
19
19
  return true;
20
20
  }
21
+ function applyJsonSchemaExtrasFromDescription(schema) {
22
+ if (Array.isArray(schema)) {
23
+ return schema.map(applyJsonSchemaExtrasFromDescription);
24
+ }
25
+ if (typeof schema === "object" && schema != null) {
26
+ const output = Object.fromEntries(Object.entries(schema).map(([key, value]) => [
27
+ key,
28
+ applyJsonSchemaExtrasFromDescription(value),
29
+ ]));
30
+ if ("description" in output &&
31
+ typeof output.description === "string" &&
32
+ output.description.startsWith(meta_js_1.META_EXTRAS_DESCRIPTION_PREFIX)) {
33
+ const strMeta = output.description.slice(meta_js_1.META_EXTRAS_DESCRIPTION_PREFIX.length);
34
+ delete output.description;
35
+ Object.assign(output, JSON.parse(strMeta));
36
+ }
37
+ return output;
38
+ }
39
+ return schema;
40
+ }
21
41
  function toJsonSchema(schema) {
22
- return (0, state_js_1.applyExtraFromDescription)((0, zod_to_json_schema_1.zodToJsonSchema)(schema));
42
+ return applyJsonSchemaExtrasFromDescription((0, json_schema_1.toJsonSchema)(schema));
23
43
  }
24
44
  /**
25
45
  * Get the state schema for a graph.
26
46
  * @param graph - The graph to get the state schema for.
27
47
  * @returns The state schema for the graph.
28
48
  */
29
- function getStateTypeSchema(graph) {
49
+ function getStateTypeSchema(graph, registry = meta_js_1.schemaMetaRegistry) {
30
50
  if (!isGraphWithZodLike(graph))
31
51
  return undefined;
32
52
  const schemaDef = graph.builder._schemaRuntimeDefinition;
33
53
  if (!schemaDef)
34
54
  return undefined;
35
- return toJsonSchema((0, state_js_1.applyZodPlugin)(schemaDef, { jsonSchemaExtra: true }));
55
+ return toJsonSchema(registry.getExtendedChannelSchemas(schemaDef, {
56
+ withJsonSchemaExtrasAsDescription: true,
57
+ }));
36
58
  }
37
59
  /**
38
60
  * Get the update schema for a graph.
39
61
  * @param graph - The graph to get the update schema for.
40
62
  * @returns The update schema for the graph.
41
63
  */
42
- function getUpdateTypeSchema(graph) {
64
+ function getUpdateTypeSchema(graph, registry = meta_js_1.schemaMetaRegistry) {
43
65
  if (!isGraphWithZodLike(graph))
44
66
  return undefined;
45
67
  const schemaDef = graph.builder._schemaRuntimeDefinition;
46
68
  if (!schemaDef)
47
69
  return undefined;
48
- return toJsonSchema((0, state_js_1.applyZodPlugin)(schemaDef, {
49
- reducer: true,
50
- jsonSchemaExtra: true,
51
- partial: true,
70
+ return toJsonSchema(registry.getExtendedChannelSchemas(schemaDef, {
71
+ withReducerSchema: true,
72
+ withJsonSchemaExtrasAsDescription: true,
73
+ asPartial: true,
52
74
  }));
53
75
  }
54
76
  /**
@@ -56,7 +78,7 @@ function getUpdateTypeSchema(graph) {
56
78
  * @param graph - The graph to get the input schema for.
57
79
  * @returns The input schema for the graph.
58
80
  */
59
- function getInputTypeSchema(graph) {
81
+ function getInputTypeSchema(graph, registry = meta_js_1.schemaMetaRegistry) {
60
82
  if (!isGraphWithZodLike(graph))
61
83
  return undefined;
62
84
  let schemaDef = graph.builder._inputRuntimeDefinition;
@@ -66,10 +88,10 @@ function getInputTypeSchema(graph) {
66
88
  }
67
89
  if (!schemaDef)
68
90
  return undefined;
69
- return toJsonSchema((0, state_js_1.applyZodPlugin)(schemaDef, {
70
- reducer: true,
71
- jsonSchemaExtra: true,
72
- partial: true,
91
+ return toJsonSchema(registry.getExtendedChannelSchemas(schemaDef, {
92
+ withReducerSchema: true,
93
+ withJsonSchemaExtrasAsDescription: true,
94
+ asPartial: true,
73
95
  }));
74
96
  }
75
97
  /**
@@ -77,25 +99,29 @@ function getInputTypeSchema(graph) {
77
99
  * @param graph - The graph to get the output schema for.
78
100
  * @returns The output schema for the graph.
79
101
  */
80
- function getOutputTypeSchema(graph) {
102
+ function getOutputTypeSchema(graph, registry = meta_js_1.schemaMetaRegistry) {
81
103
  if (!isGraphWithZodLike(graph))
82
104
  return undefined;
83
105
  const schemaDef = graph.builder._outputRuntimeDefinition;
84
106
  if (!schemaDef)
85
107
  return undefined;
86
- return toJsonSchema((0, state_js_1.applyZodPlugin)(schemaDef, { jsonSchemaExtra: true }));
108
+ return toJsonSchema(registry.getExtendedChannelSchemas(schemaDef, {
109
+ withJsonSchemaExtrasAsDescription: true,
110
+ }));
87
111
  }
88
112
  /**
89
113
  * Get the config schema for a graph.
90
114
  * @param graph - The graph to get the config schema for.
91
115
  * @returns The config schema for the graph.
92
116
  */
93
- function getConfigTypeSchema(graph) {
117
+ function getConfigTypeSchema(graph, registry = meta_js_1.schemaMetaRegistry) {
94
118
  if (!isGraphWithZodLike(graph))
95
119
  return undefined;
96
120
  const configDef = graph.builder._configRuntimeSchema;
97
121
  if (!configDef)
98
122
  return undefined;
99
- return toJsonSchema((0, state_js_1.applyZodPlugin)(configDef, { jsonSchemaExtra: true }));
123
+ return toJsonSchema(registry.getExtendedChannelSchemas(configDef, {
124
+ withJsonSchemaExtrasAsDescription: true,
125
+ }));
100
126
  }
101
127
  //# sourceMappingURL=schema.js.map
@@ -1,33 +1,32 @@
1
- import { zodToJsonSchema as _zodToJsonSchema } from "zod-to-json-schema";
2
- type JsonSchema = ReturnType<typeof _zodToJsonSchema>;
1
+ import { type JSONSchema } from "@langchain/core/utils/json_schema";
2
+ import { SchemaMetaRegistry } from "./meta.js";
3
3
  /**
4
4
  * Get the state schema for a graph.
5
5
  * @param graph - The graph to get the state schema for.
6
6
  * @returns The state schema for the graph.
7
7
  */
8
- export declare function getStateTypeSchema(graph: unknown): JsonSchema | undefined;
8
+ export declare function getStateTypeSchema(graph: unknown, registry?: SchemaMetaRegistry): JSONSchema | undefined;
9
9
  /**
10
10
  * Get the update schema for a graph.
11
11
  * @param graph - The graph to get the update schema for.
12
12
  * @returns The update schema for the graph.
13
13
  */
14
- export declare function getUpdateTypeSchema(graph: unknown): JsonSchema | undefined;
14
+ export declare function getUpdateTypeSchema(graph: unknown, registry?: SchemaMetaRegistry): JSONSchema | undefined;
15
15
  /**
16
16
  * Get the input schema for a graph.
17
17
  * @param graph - The graph to get the input schema for.
18
18
  * @returns The input schema for the graph.
19
19
  */
20
- export declare function getInputTypeSchema(graph: unknown): JsonSchema | undefined;
20
+ export declare function getInputTypeSchema(graph: unknown, registry?: SchemaMetaRegistry): JSONSchema | undefined;
21
21
  /**
22
22
  * Get the output schema for a graph.
23
23
  * @param graph - The graph to get the output schema for.
24
24
  * @returns The output schema for the graph.
25
25
  */
26
- export declare function getOutputTypeSchema(graph: unknown): JsonSchema | undefined;
26
+ export declare function getOutputTypeSchema(graph: unknown, registry?: SchemaMetaRegistry): JSONSchema | undefined;
27
27
  /**
28
28
  * Get the config schema for a graph.
29
29
  * @param graph - The graph to get the config schema for.
30
30
  * @returns The config schema for the graph.
31
31
  */
32
- export declare function getConfigTypeSchema(graph: unknown): JsonSchema | undefined;
33
- export {};
32
+ export declare function getConfigTypeSchema(graph: unknown, registry?: SchemaMetaRegistry): JSONSchema | undefined;
@@ -1,5 +1,5 @@
1
- import { zodToJsonSchema as _zodToJsonSchema } from "zod-to-json-schema";
2
- import { applyZodPlugin, applyExtraFromDescription } from "./state.js";
1
+ import { toJsonSchema as interopToJsonSchema, } from "@langchain/core/utils/json_schema";
2
+ import { META_EXTRAS_DESCRIPTION_PREFIX, schemaMetaRegistry, } from "./meta.js";
3
3
  const PartialStateSchema = Symbol.for("langgraph.state.partial");
4
4
  function isGraphWithZodLike(graph) {
5
5
  if (!graph || typeof graph !== "object")
@@ -11,37 +11,59 @@ function isGraphWithZodLike(graph) {
11
11
  }
12
12
  return true;
13
13
  }
14
+ function applyJsonSchemaExtrasFromDescription(schema) {
15
+ if (Array.isArray(schema)) {
16
+ return schema.map(applyJsonSchemaExtrasFromDescription);
17
+ }
18
+ if (typeof schema === "object" && schema != null) {
19
+ const output = Object.fromEntries(Object.entries(schema).map(([key, value]) => [
20
+ key,
21
+ applyJsonSchemaExtrasFromDescription(value),
22
+ ]));
23
+ if ("description" in output &&
24
+ typeof output.description === "string" &&
25
+ output.description.startsWith(META_EXTRAS_DESCRIPTION_PREFIX)) {
26
+ const strMeta = output.description.slice(META_EXTRAS_DESCRIPTION_PREFIX.length);
27
+ delete output.description;
28
+ Object.assign(output, JSON.parse(strMeta));
29
+ }
30
+ return output;
31
+ }
32
+ return schema;
33
+ }
14
34
  function toJsonSchema(schema) {
15
- return applyExtraFromDescription(_zodToJsonSchema(schema));
35
+ return applyJsonSchemaExtrasFromDescription(interopToJsonSchema(schema));
16
36
  }
17
37
  /**
18
38
  * Get the state schema for a graph.
19
39
  * @param graph - The graph to get the state schema for.
20
40
  * @returns The state schema for the graph.
21
41
  */
22
- export function getStateTypeSchema(graph) {
42
+ export function getStateTypeSchema(graph, registry = schemaMetaRegistry) {
23
43
  if (!isGraphWithZodLike(graph))
24
44
  return undefined;
25
45
  const schemaDef = graph.builder._schemaRuntimeDefinition;
26
46
  if (!schemaDef)
27
47
  return undefined;
28
- return toJsonSchema(applyZodPlugin(schemaDef, { jsonSchemaExtra: true }));
48
+ return toJsonSchema(registry.getExtendedChannelSchemas(schemaDef, {
49
+ withJsonSchemaExtrasAsDescription: true,
50
+ }));
29
51
  }
30
52
  /**
31
53
  * Get the update schema for a graph.
32
54
  * @param graph - The graph to get the update schema for.
33
55
  * @returns The update schema for the graph.
34
56
  */
35
- export function getUpdateTypeSchema(graph) {
57
+ export function getUpdateTypeSchema(graph, registry = schemaMetaRegistry) {
36
58
  if (!isGraphWithZodLike(graph))
37
59
  return undefined;
38
60
  const schemaDef = graph.builder._schemaRuntimeDefinition;
39
61
  if (!schemaDef)
40
62
  return undefined;
41
- return toJsonSchema(applyZodPlugin(schemaDef, {
42
- reducer: true,
43
- jsonSchemaExtra: true,
44
- partial: true,
63
+ return toJsonSchema(registry.getExtendedChannelSchemas(schemaDef, {
64
+ withReducerSchema: true,
65
+ withJsonSchemaExtrasAsDescription: true,
66
+ asPartial: true,
45
67
  }));
46
68
  }
47
69
  /**
@@ -49,7 +71,7 @@ export function getUpdateTypeSchema(graph) {
49
71
  * @param graph - The graph to get the input schema for.
50
72
  * @returns The input schema for the graph.
51
73
  */
52
- export function getInputTypeSchema(graph) {
74
+ export function getInputTypeSchema(graph, registry = schemaMetaRegistry) {
53
75
  if (!isGraphWithZodLike(graph))
54
76
  return undefined;
55
77
  let schemaDef = graph.builder._inputRuntimeDefinition;
@@ -59,10 +81,10 @@ export function getInputTypeSchema(graph) {
59
81
  }
60
82
  if (!schemaDef)
61
83
  return undefined;
62
- return toJsonSchema(applyZodPlugin(schemaDef, {
63
- reducer: true,
64
- jsonSchemaExtra: true,
65
- partial: true,
84
+ return toJsonSchema(registry.getExtendedChannelSchemas(schemaDef, {
85
+ withReducerSchema: true,
86
+ withJsonSchemaExtrasAsDescription: true,
87
+ asPartial: true,
66
88
  }));
67
89
  }
68
90
  /**
@@ -70,25 +92,29 @@ export function getInputTypeSchema(graph) {
70
92
  * @param graph - The graph to get the output schema for.
71
93
  * @returns The output schema for the graph.
72
94
  */
73
- export function getOutputTypeSchema(graph) {
95
+ export function getOutputTypeSchema(graph, registry = schemaMetaRegistry) {
74
96
  if (!isGraphWithZodLike(graph))
75
97
  return undefined;
76
98
  const schemaDef = graph.builder._outputRuntimeDefinition;
77
99
  if (!schemaDef)
78
100
  return undefined;
79
- return toJsonSchema(applyZodPlugin(schemaDef, { jsonSchemaExtra: true }));
101
+ return toJsonSchema(registry.getExtendedChannelSchemas(schemaDef, {
102
+ withJsonSchemaExtrasAsDescription: true,
103
+ }));
80
104
  }
81
105
  /**
82
106
  * Get the config schema for a graph.
83
107
  * @param graph - The graph to get the config schema for.
84
108
  * @returns The config schema for the graph.
85
109
  */
86
- export function getConfigTypeSchema(graph) {
110
+ export function getConfigTypeSchema(graph, registry = schemaMetaRegistry) {
87
111
  if (!isGraphWithZodLike(graph))
88
112
  return undefined;
89
113
  const configDef = graph.builder._configRuntimeSchema;
90
114
  if (!configDef)
91
115
  return undefined;
92
- return toJsonSchema(applyZodPlugin(configDef, { jsonSchemaExtra: true }));
116
+ return toJsonSchema(registry.getExtendedChannelSchemas(configDef, {
117
+ withJsonSchemaExtrasAsDescription: true,
118
+ }));
93
119
  }
94
120
  //# sourceMappingURL=schema.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../src/graph/zod/schema.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,IAAI,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACzE,OAAO,EAAE,cAAc,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAC;AAEvE,MAAM,kBAAkB,GAAG,MAAM,CAAC,GAAG,CAAC,yBAAyB,CAAC,CAAC;AAcjE,SAAS,kBAAkB,CAAC,KAAc;IACxC,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IACtD,IACE,CAAC,CAAC,SAAS,IAAI,KAAK,CAAC;QACrB,OAAO,KAAK,CAAC,OAAO,KAAK,QAAQ;QACjC,KAAK,CAAC,OAAO,IAAI,IAAI,EACrB,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAED,SAAS,YAAY,CAAC,MAAiB;IACrC,OAAO,yBAAyB,CAAC,gBAAgB,CAAC,MAAM,CAAC,CA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AIG;AACH,MAAM,UAAU,mBAAmB,CACjC,KAAc,EACd,WAA+B,kBAAkB;IAEjD,IAAI,CAAC,kBAAkB,CAAC,KAAK,CAAC;QAAE,OAAO,SAAS,CAAC;IACjD,MAAM,SAAS,GAAG,KAAK,CAAC,OAAO,CAAC,wBAAwB,CAAC;IACzD,IAAI,CAAC,SAAS;QAAE,OAAO,SAAS,CAAC;IAEjC,OAAO,YAAY,CACjB,QAAQ,CAAC,yBAAyB,CAAC,SAAS,EAAE;QAC5C,iCAAiC,EAAE,IAAI;KACxC,CAAC,CACH,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CACjC,KAAc,EACd,WAA+B,kBAAkB;IAEjD,IAAI,CAAC,kBAAkB,CAAC,KAAK,CAAC;QAAE,OAAO,SAAS,CAAC;IACjD,MAAM,SAAS,GAAG,KAAK,CAAC,OAAO,CAAC,oBAAoB,CAAC;IACrD,IAAI,CAAC,SAAS;QAAE,OAAO,SAAS,CAAC;IAEjC,OAAO,YAAY,CACjB,QAAQ,CAAC,yBAAyB,CAAC,SAAS,EAAE;QAC5C,iCAAiC,EAAE,IAAI;KACxC,CAAC,CACH,CAAC;AACJ,CAAC"}
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.registry = exports.LanggraphZodMetaRegistry = void 0;
4
+ const types_1 = require("@langchain/core/utils/types");
5
+ const core_1 = require("zod/v4/core");
6
+ const meta_js_1 = require("./meta.cjs");
7
+ /**
8
+ * A Zod v4-compatible meta registry that extends the base registry.
9
+ *
10
+ * This registry allows you to associate and retrieve metadata for Zod schemas,
11
+ * leveraging the base registry for storage. It is compatible with Zod v4 and
12
+ * interoperates with the base registry to ensure consistent metadata management
13
+ * across different Zod versions.
14
+ *
15
+ * @template Meta - The type of metadata associated with each schema.
16
+ * @template Schema - The Zod schema type.
17
+ */
18
+ class LanggraphZodMetaRegistry extends core_1.$ZodRegistry {
19
+ /**
20
+ * Creates a new LanggraphZodMetaRegistry instance.
21
+ *
22
+ * @param parent - The base SchemaMetaRegistry to use for metadata storage.
23
+ */
24
+ constructor(parent) {
25
+ super();
26
+ Object.defineProperty(this, "parent", {
27
+ enumerable: true,
28
+ configurable: true,
29
+ writable: true,
30
+ value: parent
31
+ });
32
+ // Use the parent's map for metadata storage
33
+ this._map = this.parent._map;
34
+ }
35
+ add(schema, ..._meta) {
36
+ const firstMeta = _meta[0];
37
+ if (firstMeta && !firstMeta?.default) {
38
+ const defaultValueGetter = (0, types_1.getInteropZodDefaultGetter)(schema);
39
+ if (defaultValueGetter != null) {
40
+ // eslint-disable-next-line no-param-reassign
41
+ firstMeta.default = defaultValueGetter;
42
+ }
43
+ }
44
+ return super.add(schema, ..._meta);
45
+ }
46
+ }
47
+ exports.LanggraphZodMetaRegistry = LanggraphZodMetaRegistry;
48
+ exports.registry = new LanggraphZodMetaRegistry(meta_js_1.schemaMetaRegistry);
49
+ //# sourceMappingURL=zod-registry.js.map
@@ -0,0 +1,24 @@
1
+ import { $ZodType, $ZodRegistry, $replace } from "zod/v4/core";
2
+ import { SchemaMeta, SchemaMetaRegistry } from "./meta.js";
3
+ /**
4
+ * A Zod v4-compatible meta registry that extends the base registry.
5
+ *
6
+ * This registry allows you to associate and retrieve metadata for Zod schemas,
7
+ * leveraging the base registry for storage. It is compatible with Zod v4 and
8
+ * interoperates with the base registry to ensure consistent metadata management
9
+ * across different Zod versions.
10
+ *
11
+ * @template Meta - The type of metadata associated with each schema.
12
+ * @template Schema - The Zod schema type.
13
+ */
14
+ export declare class LanggraphZodMetaRegistry<Meta extends SchemaMeta = SchemaMeta, Schema extends $ZodType = $ZodType> extends $ZodRegistry<Meta, Schema> {
15
+ protected parent: SchemaMetaRegistry;
16
+ /**
17
+ * Creates a new LanggraphZodMetaRegistry instance.
18
+ *
19
+ * @param parent - The base SchemaMetaRegistry to use for metadata storage.
20
+ */
21
+ constructor(parent: SchemaMetaRegistry);
22
+ add<S extends Schema>(schema: S, ..._meta: undefined extends Meta ? [$replace<Meta, S>?] : [$replace<Meta, S>]): this;
23
+ }
24
+ export declare const registry: LanggraphZodMetaRegistry<SchemaMeta<any, any>, $ZodType<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>>>;
@@ -0,0 +1,45 @@
1
+ import { getInteropZodDefaultGetter } from "@langchain/core/utils/types";
2
+ import { $ZodRegistry } from "zod/v4/core";
3
+ import { schemaMetaRegistry } from "./meta.js";
4
+ /**
5
+ * A Zod v4-compatible meta registry that extends the base registry.
6
+ *
7
+ * This registry allows you to associate and retrieve metadata for Zod schemas,
8
+ * leveraging the base registry for storage. It is compatible with Zod v4 and
9
+ * interoperates with the base registry to ensure consistent metadata management
10
+ * across different Zod versions.
11
+ *
12
+ * @template Meta - The type of metadata associated with each schema.
13
+ * @template Schema - The Zod schema type.
14
+ */
15
+ export class LanggraphZodMetaRegistry extends $ZodRegistry {
16
+ /**
17
+ * Creates a new LanggraphZodMetaRegistry instance.
18
+ *
19
+ * @param parent - The base SchemaMetaRegistry to use for metadata storage.
20
+ */
21
+ constructor(parent) {
22
+ super();
23
+ Object.defineProperty(this, "parent", {
24
+ enumerable: true,
25
+ configurable: true,
26
+ writable: true,
27
+ value: parent
28
+ });
29
+ // Use the parent's map for metadata storage
30
+ this._map = this.parent._map;
31
+ }
32
+ add(schema, ..._meta) {
33
+ const firstMeta = _meta[0];
34
+ if (firstMeta && !firstMeta?.default) {
35
+ const defaultValueGetter = getInteropZodDefaultGetter(schema);
36
+ if (defaultValueGetter != null) {
37
+ // eslint-disable-next-line no-param-reassign
38
+ firstMeta.default = defaultValueGetter;
39
+ }
40
+ }
41
+ return super.add(schema, ..._meta);
42
+ }
43
+ }
44
+ export const registry = new LanggraphZodMetaRegistry(schemaMetaRegistry);
45
+ //# sourceMappingURL=zod-registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"zod-registry.js","sourceRoot":"","sources":["../../../src/graph/zod/zod-registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAE,MAAM,6BAA6B,CAAC;AACzE,OAAO,EAAY,YAAY,EAAY,MAAM,aAAa,CAAC;AAC/D,OAAO,EAAkC,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAE/E;;;;;;;;;;GAUG;AACH,MAAM,OAAO,wBAGX,SAAQ,YAA0B;IAClC;;;;OAIG;IACH,YAAsB,MAA0B;QAC9C,KAAK,EAAE,CAAC;QADE;;;;mBAAU,MAAM;WAAoB;QAE9C,4CAA4C;QAC5C,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,IAA+C,CAAC;IAC1E,CAAC;IAED,GAAG,CACD,MAAS,EACT,GAAG,KAEoB;QAEvB,MAAM,SAAS,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QAC3B,IAAI,SAAS,IAAI,CAAC,SAAS,EAAE,OAAO,EAAE,CAAC;YACrC,MAAM,kBAAkB,GAAG,0BAA0B,CAAC,MAAM,CAAC,CAAC;YAC9D,IAAI,kBAAkB,IAAI,IAAI,EAAE,CAAC;gBAC/B,6CAA6C;gBAC7C,SAAS,CAAC,OAAO,GAAG,kBAAkB,CAAC;YACzC,CAAC;QACH,CAAC;QACD,OAAO,KAAK,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,KAAK,CAAC,CAAC;IACrC,CAAC;CACF;AAED,MAAM,CAAC,MAAM,QAAQ,GAAG,IAAI,wBAAwB,CAAC,kBAAkB,CAAC,CAAC"}
@@ -3,8 +3,8 @@ import { LanguageModelLike } from "@langchain/core/language_models/base";
3
3
  import { BaseMessage, BaseMessageLike, SystemMessage } from "@langchain/core/messages";
4
4
  import { Runnable, RunnableToolLike, type RunnableLike } from "@langchain/core/runnables";
5
5
  import { DynamicTool, StructuredToolInterface } from "@langchain/core/tools";
6
+ import { InteropZodType } from "@langchain/core/utils/types";
6
7
  import { All, BaseCheckpointSaver, BaseStore } from "@langchain/langgraph-checkpoint";
7
- import { z } from "zod";
8
8
  import { type CompiledStateGraph, AnnotationRoot } from "../graph/index.js";
9
9
  import { MessagesAnnotation } from "../graph/messages_annotation.js";
10
10
  import { ToolNode } from "./tool_node.js";
@@ -18,7 +18,7 @@ export interface AgentState<StructuredResponseType extends Record<string, any> =
18
18
  export type N = typeof START | "agent" | "tools";
19
19
  export type StructuredResponseSchemaAndPrompt<StructuredResponseType> = {
20
20
  prompt: string;
21
- schema: z.ZodType<StructuredResponseType> | Record<string, any>;
21
+ schema: InteropZodType<StructuredResponseType> | Record<string, any>;
22
22
  };
23
23
  type ServerTool = Record<string, unknown>;
24
24
  type ClientTool = StructuredToolInterface | DynamicTool | RunnableToolLike;
@@ -101,7 +101,7 @@ export type CreateReactAgentParams<A extends AnnotationRoot<any> = AnnotationRoo
101
101
  * **Note**: The graph will make a separate call to the LLM to generate the structured response after the agent loop is finished.
102
102
  * This is not the only strategy to get structured responses, see more options in [this guide](https://langchain-ai.github.io/langgraph/how-tos/react-agent-structured-output/).
103
103
  */
104
- responseFormat?: z.ZodType<StructuredResponseType> | StructuredResponseSchemaAndPrompt<StructuredResponseType> | Record<string, any>;
104
+ responseFormat?: InteropZodType<StructuredResponseType> | StructuredResponseSchemaAndPrompt<StructuredResponseType> | Record<string, any>;
105
105
  /**
106
106
  * An optional name for the agent.
107
107
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@langchain/langgraph",
3
- "version": "0.3.1",
3
+ "version": "0.3.3",
4
4
  "description": "LangGraph",
5
5
  "type": "module",
6
6
  "engines": {
@@ -35,10 +35,10 @@
35
35
  "@langchain/langgraph-checkpoint": "~0.0.18",
36
36
  "@langchain/langgraph-sdk": "~0.0.32",
37
37
  "uuid": "^10.0.0",
38
- "zod": "^3.23.8"
38
+ "zod": "^3.25.32"
39
39
  },
40
40
  "peerDependencies": {
41
- "@langchain/core": ">=0.2.36 <0.3.0 || >=0.3.40 < 0.4.0",
41
+ "@langchain/core": ">=0.3.58 < 0.4.0",
42
42
  "zod-to-json-schema": "^3.x"
43
43
  },
44
44
  "peerDependenciesMeta": {
@@ -49,9 +49,9 @@
49
49
  "devDependencies": {
50
50
  "@langchain/anthropic": "^0.3.12",
51
51
  "@langchain/community": "^0.3.27",
52
- "@langchain/core": "^0.3.40",
53
- "@langchain/langgraph-checkpoint-postgres": "0.0.5",
54
- "@langchain/langgraph-checkpoint-sqlite": "0.1.5",
52
+ "@langchain/core": "^0.3.58",
53
+ "@langchain/langgraph-checkpoint-postgres": "workspace:*",
54
+ "@langchain/langgraph-checkpoint-sqlite": "workspace:*",
55
55
  "@langchain/openai": "^0.4.0",
56
56
  "@langchain/scripts": ">=0.1.3 <0.2.0",
57
57
  "@swc/core": "^1.3.90",
@@ -185,4 +185,4 @@
185
185
  "zod/schema.d.ts",
186
186
  "zod/schema.d.cts"
187
187
  ]
188
- }
188
+ }
@@ -1,135 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isZodDefault = isZodDefault;
4
- exports.isAnyZodObject = isAnyZodObject;
5
- exports.withLangGraph = withLangGraph;
6
- exports.getMeta = getMeta;
7
- exports.extendMeta = extendMeta;
8
- exports.getChannelsFromZod = getChannelsFromZod;
9
- exports.applyZodPlugin = applyZodPlugin;
10
- exports.applyExtraFromDescription = applyExtraFromDescription;
11
- const binop_js_1 = require("../../channels/binop.cjs");
12
- const last_value_js_1 = require("../../channels/last_value.cjs");
13
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
14
- const META_MAP = new WeakMap();
15
- function isZodType(value) {
16
- return (typeof value === "object" &&
17
- value != null &&
18
- "_parse" in value &&
19
- typeof value._parse === "function");
20
- }
21
- /**
22
- * @internal
23
- */
24
- function isZodDefault(value) {
25
- return (isZodType(value) &&
26
- "removeDefault" in value &&
27
- typeof value.removeDefault === "function");
28
- }
29
- /**
30
- * @internal
31
- */
32
- function isAnyZodObject(value) {
33
- return (isZodType(value) &&
34
- "partial" in value &&
35
- typeof value.partial === "function");
36
- }
37
- function withLangGraph(schema, meta) {
38
- if (meta.reducer && !meta.default) {
39
- const defaultValue = isZodDefault(schema)
40
- ? schema._def.defaultValue
41
- : undefined;
42
- if (defaultValue != null) {
43
- // eslint-disable-next-line no-param-reassign
44
- meta.default = defaultValue;
45
- }
46
- }
47
- META_MAP.set(schema, meta);
48
- return schema;
49
- }
50
- function getMeta(schema) {
51
- return META_MAP.get(schema);
52
- }
53
- function extendMeta(schema, update) {
54
- const existingMeta = getMeta(schema);
55
- const newMeta = update(existingMeta);
56
- META_MAP.set(schema, newMeta);
57
- }
58
- function getChannelsFromZod(schema) {
59
- const channels = {};
60
- for (const key in schema.shape) {
61
- if (Object.prototype.hasOwnProperty.call(schema.shape, key)) {
62
- const keySchema = schema.shape[key];
63
- const meta = getMeta(keySchema);
64
- if (meta?.reducer) {
65
- channels[key] = new binop_js_1.BinaryOperatorAggregate(meta.reducer.fn, meta.default);
66
- }
67
- else {
68
- channels[key] = new last_value_js_1.LastValue();
69
- }
70
- }
71
- }
72
- return channels;
73
- }
74
- const ZOD_TYPE_CACHE = {};
75
- const ZOD_DESCRIPTION_PREFIX = "lg:";
76
- function applyZodPlugin(schema, actions) {
77
- const cacheKey = [
78
- `reducer:${actions.reducer ?? false}`,
79
- `jsonSchemaExtra:${actions.jsonSchemaExtra ?? false}`,
80
- `partial:${actions.partial ?? false}`,
81
- ].join("|");
82
- ZOD_TYPE_CACHE[cacheKey] ??= new WeakMap();
83
- const cache = ZOD_TYPE_CACHE[cacheKey];
84
- if (cache.has(schema))
85
- return cache.get(schema);
86
- let shape = schema.extend({
87
- ...Object.fromEntries(Object.entries(schema.shape).map(([key, input]) => {
88
- const meta = getMeta(input);
89
- let output = actions.reducer ? meta?.reducer?.schema ?? input : input;
90
- if (actions.jsonSchemaExtra) {
91
- const strMeta = JSON.stringify({
92
- ...meta?.jsonSchemaExtra,
93
- description: output.description ?? input.description,
94
- });
95
- if (strMeta !== "{}") {
96
- output = output.describe(`${ZOD_DESCRIPTION_PREFIX}${strMeta}`);
97
- }
98
- }
99
- return [key, output];
100
- })),
101
- });
102
- // using zObject.extend() will set `unknownKeys` to `passthrough`
103
- // which trips up `zod-to-json-schema`
104
- if ("_def" in shape &&
105
- shape._def != null &&
106
- typeof shape._def === "object" &&
107
- "unknownKeys" in shape._def) {
108
- shape._def.unknownKeys = "strip";
109
- }
110
- if (actions.partial)
111
- shape = shape.partial();
112
- cache.set(schema, shape);
113
- return shape;
114
- }
115
- function applyExtraFromDescription(schema) {
116
- if (Array.isArray(schema)) {
117
- return schema.map(applyExtraFromDescription);
118
- }
119
- if (typeof schema === "object" && schema != null) {
120
- const output = Object.fromEntries(Object.entries(schema).map(([key, value]) => [
121
- key,
122
- applyExtraFromDescription(value),
123
- ]));
124
- if ("description" in output &&
125
- typeof output.description === "string" &&
126
- output.description.startsWith(ZOD_DESCRIPTION_PREFIX)) {
127
- const strMeta = output.description.slice(ZOD_DESCRIPTION_PREFIX.length);
128
- delete output.description;
129
- Object.assign(output, JSON.parse(strMeta));
130
- }
131
- return output;
132
- }
133
- return schema;
134
- }
135
- //# sourceMappingURL=state.js.map