@langchain/langgraph 1.0.14 → 1.1.0

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 (184) hide show
  1. package/dist/channels/base.cjs +11 -0
  2. package/dist/channels/base.cjs.map +1 -1
  3. package/dist/channels/base.d.cts +9 -0
  4. package/dist/channels/base.d.cts.map +1 -1
  5. package/dist/channels/base.d.ts +9 -0
  6. package/dist/channels/base.d.ts.map +1 -1
  7. package/dist/channels/base.js +11 -0
  8. package/dist/channels/base.js.map +1 -1
  9. package/dist/channels/binop.cjs +13 -0
  10. package/dist/channels/binop.cjs.map +1 -1
  11. package/dist/channels/binop.d.cts +6 -0
  12. package/dist/channels/binop.d.cts.map +1 -1
  13. package/dist/channels/binop.d.ts +6 -0
  14. package/dist/channels/binop.d.ts.map +1 -1
  15. package/dist/channels/binop.js +13 -0
  16. package/dist/channels/binop.js.map +1 -1
  17. package/dist/channels/index.cjs +2 -0
  18. package/dist/channels/index.d.cts +2 -1
  19. package/dist/channels/index.d.ts +2 -1
  20. package/dist/channels/index.js +2 -1
  21. package/dist/channels/untracked_value.cjs +83 -0
  22. package/dist/channels/untracked_value.cjs.map +1 -0
  23. package/dist/channels/untracked_value.d.cts +64 -0
  24. package/dist/channels/untracked_value.d.cts.map +1 -0
  25. package/dist/channels/untracked_value.d.ts +64 -0
  26. package/dist/channels/untracked_value.d.ts.map +1 -0
  27. package/dist/channels/untracked_value.js +83 -0
  28. package/dist/channels/untracked_value.js.map +1 -0
  29. package/dist/constants.cjs.map +1 -1
  30. package/dist/constants.d.cts +2 -2
  31. package/dist/constants.d.cts.map +1 -1
  32. package/dist/constants.d.ts +2 -2
  33. package/dist/constants.d.ts.map +1 -1
  34. package/dist/constants.js.map +1 -1
  35. package/dist/errors.cjs +36 -0
  36. package/dist/errors.cjs.map +1 -1
  37. package/dist/errors.d.cts +30 -1
  38. package/dist/errors.d.cts.map +1 -1
  39. package/dist/errors.d.ts +30 -1
  40. package/dist/errors.d.ts.map +1 -1
  41. package/dist/errors.js +36 -1
  42. package/dist/errors.js.map +1 -1
  43. package/dist/func/index.cjs +1 -1
  44. package/dist/func/index.cjs.map +1 -1
  45. package/dist/func/index.js +1 -1
  46. package/dist/func/index.js.map +1 -1
  47. package/dist/graph/index.cjs +1 -0
  48. package/dist/graph/index.js +2 -1
  49. package/dist/graph/message.cjs +2 -47
  50. package/dist/graph/message.cjs.map +1 -1
  51. package/dist/graph/message.d.cts +4 -11
  52. package/dist/graph/message.d.cts.map +1 -1
  53. package/dist/graph/message.d.ts +4 -11
  54. package/dist/graph/message.d.ts.map +1 -1
  55. package/dist/graph/message.js +2 -45
  56. package/dist/graph/message.js.map +1 -1
  57. package/dist/graph/messages_annotation.cjs +3 -3
  58. package/dist/graph/messages_annotation.cjs.map +1 -1
  59. package/dist/graph/messages_annotation.d.cts +2 -2
  60. package/dist/graph/messages_annotation.d.cts.map +1 -1
  61. package/dist/graph/messages_annotation.d.ts +1 -1
  62. package/dist/graph/messages_annotation.d.ts.map +1 -1
  63. package/dist/graph/messages_annotation.js +1 -1
  64. package/dist/graph/messages_annotation.js.map +1 -1
  65. package/dist/graph/messages_reducer.cjs +85 -0
  66. package/dist/graph/messages_reducer.cjs.map +1 -0
  67. package/dist/graph/messages_reducer.d.cts +54 -0
  68. package/dist/graph/messages_reducer.d.cts.map +1 -0
  69. package/dist/graph/messages_reducer.d.ts +54 -0
  70. package/dist/graph/messages_reducer.d.ts.map +1 -0
  71. package/dist/graph/messages_reducer.js +84 -0
  72. package/dist/graph/messages_reducer.js.map +1 -0
  73. package/dist/graph/state.cjs +30 -10
  74. package/dist/graph/state.cjs.map +1 -1
  75. package/dist/graph/state.d.cts +24 -15
  76. package/dist/graph/state.d.cts.map +1 -1
  77. package/dist/graph/state.d.ts +24 -15
  78. package/dist/graph/state.d.ts.map +1 -1
  79. package/dist/graph/state.js +31 -11
  80. package/dist/graph/state.js.map +1 -1
  81. package/dist/graph/types.d.cts +127 -0
  82. package/dist/graph/types.d.cts.map +1 -0
  83. package/dist/graph/types.d.ts +127 -0
  84. package/dist/graph/types.d.ts.map +1 -0
  85. package/dist/graph/zod/plugin.cjs +2 -2
  86. package/dist/graph/zod/plugin.cjs.map +1 -1
  87. package/dist/graph/zod/plugin.js +3 -3
  88. package/dist/graph/zod/plugin.js.map +1 -1
  89. package/dist/graph/zod/zod-registry.d.cts.map +1 -1
  90. package/dist/hash.cjs +4 -4
  91. package/dist/hash.cjs.map +1 -1
  92. package/dist/hash.js +4 -4
  93. package/dist/hash.js.map +1 -1
  94. package/dist/index.cjs +21 -3
  95. package/dist/index.cjs.map +1 -1
  96. package/dist/index.d.cts +12 -3
  97. package/dist/index.d.ts +12 -3
  98. package/dist/index.js +11 -3
  99. package/dist/index.js.map +1 -1
  100. package/dist/prebuilt/agent_executor.d.cts +5 -5
  101. package/dist/prebuilt/agent_executor.d.cts.map +1 -1
  102. package/dist/prebuilt/agent_executor.d.ts +5 -5
  103. package/dist/prebuilt/agent_executor.d.ts.map +1 -1
  104. package/dist/prebuilt/react_agent_executor.cjs +7 -6
  105. package/dist/prebuilt/react_agent_executor.cjs.map +1 -1
  106. package/dist/prebuilt/react_agent_executor.d.cts +4 -4
  107. package/dist/prebuilt/react_agent_executor.d.cts.map +1 -1
  108. package/dist/prebuilt/react_agent_executor.d.ts +4 -4
  109. package/dist/prebuilt/react_agent_executor.d.ts.map +1 -1
  110. package/dist/prebuilt/react_agent_executor.js +5 -4
  111. package/dist/prebuilt/react_agent_executor.js.map +1 -1
  112. package/dist/pregel/algo.cjs +19 -0
  113. package/dist/pregel/algo.cjs.map +1 -1
  114. package/dist/pregel/algo.d.cts.map +1 -1
  115. package/dist/pregel/algo.d.ts.map +1 -1
  116. package/dist/pregel/algo.js +19 -1
  117. package/dist/pregel/algo.js.map +1 -1
  118. package/dist/pregel/loop.cjs +18 -3
  119. package/dist/pregel/loop.cjs.map +1 -1
  120. package/dist/pregel/loop.js +20 -5
  121. package/dist/pregel/loop.js.map +1 -1
  122. package/dist/pregel/runner.cjs +1 -1
  123. package/dist/pregel/runner.cjs.map +1 -1
  124. package/dist/pregel/runner.js +1 -1
  125. package/dist/pregel/runner.js.map +1 -1
  126. package/dist/state/adapter.cjs +53 -0
  127. package/dist/state/adapter.cjs.map +1 -0
  128. package/dist/state/adapter.d.cts +33 -0
  129. package/dist/state/adapter.d.cts.map +1 -0
  130. package/dist/state/adapter.d.ts +33 -0
  131. package/dist/state/adapter.d.ts.map +1 -0
  132. package/dist/state/adapter.js +52 -0
  133. package/dist/state/adapter.js.map +1 -0
  134. package/dist/state/index.cjs +8 -0
  135. package/dist/state/index.js +10 -0
  136. package/dist/state/prebuilt/index.cjs +1 -0
  137. package/dist/state/prebuilt/index.js +3 -0
  138. package/dist/state/prebuilt/messages.cjs +19 -0
  139. package/dist/state/prebuilt/messages.cjs.map +1 -0
  140. package/dist/state/prebuilt/messages.d.cts +10 -0
  141. package/dist/state/prebuilt/messages.d.cts.map +1 -0
  142. package/dist/state/prebuilt/messages.d.ts +10 -0
  143. package/dist/state/prebuilt/messages.d.ts.map +1 -0
  144. package/dist/state/prebuilt/messages.js +19 -0
  145. package/dist/state/prebuilt/messages.js.map +1 -0
  146. package/dist/state/schema.cjs +171 -0
  147. package/dist/state/schema.cjs.map +1 -0
  148. package/dist/state/schema.d.cts +208 -0
  149. package/dist/state/schema.d.cts.map +1 -0
  150. package/dist/state/schema.d.ts +208 -0
  151. package/dist/state/schema.d.ts.map +1 -0
  152. package/dist/state/schema.js +171 -0
  153. package/dist/state/schema.js.map +1 -0
  154. package/dist/state/types.cjs +17 -0
  155. package/dist/state/types.cjs.map +1 -0
  156. package/dist/state/types.d.cts +128 -0
  157. package/dist/state/types.d.cts.map +1 -0
  158. package/dist/state/types.d.ts +128 -0
  159. package/dist/state/types.d.ts.map +1 -0
  160. package/dist/state/types.js +14 -0
  161. package/dist/state/types.js.map +1 -0
  162. package/dist/state/values/index.cjs +2 -0
  163. package/dist/state/values/index.js +4 -0
  164. package/dist/state/values/reduced.cjs +72 -0
  165. package/dist/state/values/reduced.cjs.map +1 -0
  166. package/dist/state/values/reduced.d.cts +155 -0
  167. package/dist/state/values/reduced.d.cts.map +1 -0
  168. package/dist/state/values/reduced.d.ts +155 -0
  169. package/dist/state/values/reduced.d.ts.map +1 -0
  170. package/dist/state/values/reduced.js +71 -0
  171. package/dist/state/values/reduced.js.map +1 -0
  172. package/dist/state/values/untracked.cjs +64 -0
  173. package/dist/state/values/untracked.cjs.map +1 -0
  174. package/dist/state/values/untracked.d.cts +74 -0
  175. package/dist/state/values/untracked.d.cts.map +1 -0
  176. package/dist/state/values/untracked.d.ts +74 -0
  177. package/dist/state/values/untracked.d.ts.map +1 -0
  178. package/dist/state/values/untracked.js +63 -0
  179. package/dist/state/values/untracked.js.map +1 -0
  180. package/dist/web.cjs +26 -7
  181. package/dist/web.d.cts +12 -3
  182. package/dist/web.d.ts +12 -3
  183. package/dist/web.js +13 -4
  184. package/package.json +5 -4
@@ -0,0 +1,33 @@
1
+ import { SerializableSchema } from "./types.js";
2
+
3
+ //#region src/state/adapter.d.ts
4
+
5
+ /**
6
+ * Get the JSON schema from a SerializableSchema.
7
+ */
8
+ declare function getJsonSchemaFromSchema(schema: SerializableSchema | unknown): Record<string, unknown> | undefined;
9
+ /**
10
+ * Detect if a schema has a default value by validating `undefined`.
11
+ *
12
+ * Uses the Standard Schema `~standard.validate` API to detect defaults.
13
+ * If the schema accepts `undefined` and returns a value, that value is the default.
14
+ *
15
+ * This approach is library-agnostic and works with any Standard Schema compliant
16
+ * library (Zod, Valibot, ArkType, etc.) without needing to introspect internals.
17
+ *
18
+ * @param schema - The schema to check for a default value.
19
+ * @returns A factory function returning the default, or undefined if no default exists.
20
+ *
21
+ * @example
22
+ * ```ts
23
+ * const getter = getSchemaDefaultGetter(z.string().default("hello"));
24
+ * getter?.(); // "hello"
25
+ *
26
+ * const noDefault = getSchemaDefaultGetter(z.string());
27
+ * noDefault; // undefined
28
+ * ```
29
+ */
30
+ declare function getSchemaDefaultGetter(schema: SerializableSchema | unknown): (() => unknown) | undefined;
31
+ //#endregion
32
+ export { getJsonSchemaFromSchema, getSchemaDefaultGetter };
33
+ //# sourceMappingURL=adapter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adapter.d.ts","names":["SerializableSchema","getJsonSchemaFromSchema","Record","getSchemaDefaultGetter"],"sources":["../../src/state/adapter.d.ts"],"sourcesContent":["/**\n * Adapter utilities for working with Standard Schema.\n */\nimport type { SerializableSchema } from \"./types.js\";\n/**\n * Get the JSON schema from a SerializableSchema.\n */\nexport declare function getJsonSchemaFromSchema(schema: SerializableSchema | unknown): Record<string, unknown> | undefined;\n/**\n * Detect if a schema has a default value by validating `undefined`.\n *\n * Uses the Standard Schema `~standard.validate` API to detect defaults.\n * If the schema accepts `undefined` and returns a value, that value is the default.\n *\n * This approach is library-agnostic and works with any Standard Schema compliant\n * library (Zod, Valibot, ArkType, etc.) without needing to introspect internals.\n *\n * @param schema - The schema to check for a default value.\n * @returns A factory function returning the default, or undefined if no default exists.\n *\n * @example\n * ```ts\n * const getter = getSchemaDefaultGetter(z.string().default(\"hello\"));\n * getter?.(); // \"hello\"\n *\n * const noDefault = getSchemaDefaultGetter(z.string());\n * noDefault; // undefined\n * ```\n */\nexport declare function getSchemaDefaultGetter(schema: SerializableSchema | unknown): (() => unknown) | undefined;\n"],"mappings":";;;;;;;AAO6F,iBAArEC,uBAAAA,CAAqE,MAAA,EAArCD,kBAAqC,GAAA,OAAA,CAAA,EAANE,MAAM,CAAA,MAAA,EAAA,OAAA,CAAA,GAAA,SAAA;AAsB7F;;;;;;;;;;;;;;;;;;;;;iBAAwBC,sBAAAA,SAA+BH"}
@@ -0,0 +1,52 @@
1
+ import { isStandardJSONSchema, isStandardSchema } from "./types.js";
2
+
3
+ //#region src/state/adapter.ts
4
+ /**
5
+ * Get the JSON schema from a SerializableSchema.
6
+ */
7
+ function getJsonSchemaFromSchema(schema) {
8
+ if (isStandardJSONSchema(schema)) try {
9
+ return schema["~standard"].jsonSchema.input({ target: "draft-07" });
10
+ } catch {
11
+ return;
12
+ }
13
+ }
14
+ /**
15
+ * Detect if a schema has a default value by validating `undefined`.
16
+ *
17
+ * Uses the Standard Schema `~standard.validate` API to detect defaults.
18
+ * If the schema accepts `undefined` and returns a value, that value is the default.
19
+ *
20
+ * This approach is library-agnostic and works with any Standard Schema compliant
21
+ * library (Zod, Valibot, ArkType, etc.) without needing to introspect internals.
22
+ *
23
+ * @param schema - The schema to check for a default value.
24
+ * @returns A factory function returning the default, or undefined if no default exists.
25
+ *
26
+ * @example
27
+ * ```ts
28
+ * const getter = getSchemaDefaultGetter(z.string().default("hello"));
29
+ * getter?.(); // "hello"
30
+ *
31
+ * const noDefault = getSchemaDefaultGetter(z.string());
32
+ * noDefault; // undefined
33
+ * ```
34
+ */
35
+ function getSchemaDefaultGetter(schema) {
36
+ if (schema == null) return;
37
+ if (!isStandardSchema(schema)) return;
38
+ try {
39
+ const result = schema["~standard"].validate(void 0);
40
+ if (result && typeof result === "object" && !("then" in result && typeof result.then === "function")) {
41
+ const syncResult = result;
42
+ if (!syncResult.issues) {
43
+ const defaultValue = syncResult.value;
44
+ return () => defaultValue;
45
+ }
46
+ }
47
+ } catch {}
48
+ }
49
+
50
+ //#endregion
51
+ export { getJsonSchemaFromSchema, getSchemaDefaultGetter };
52
+ //# sourceMappingURL=adapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adapter.js","names":[],"sources":["../../src/state/adapter.ts"],"sourcesContent":["/**\n * Adapter utilities for working with Standard Schema.\n */\nimport type { SerializableSchema } from \"./types.js\";\nimport { isStandardJSONSchema, isStandardSchema } from \"./types.js\";\n\n/**\n * Get the JSON schema from a SerializableSchema.\n */\nexport function getJsonSchemaFromSchema(\n schema: SerializableSchema | unknown\n): Record<string, unknown> | undefined {\n if (isStandardJSONSchema(schema)) {\n try {\n const standard = schema[\"~standard\"];\n return standard.jsonSchema.input({ target: \"draft-07\" });\n } catch {\n return undefined;\n }\n }\n return undefined;\n}\n\n/**\n * Detect if a schema has a default value by validating `undefined`.\n *\n * Uses the Standard Schema `~standard.validate` API to detect defaults.\n * If the schema accepts `undefined` and returns a value, that value is the default.\n *\n * This approach is library-agnostic and works with any Standard Schema compliant\n * library (Zod, Valibot, ArkType, etc.) without needing to introspect internals.\n *\n * @param schema - The schema to check for a default value.\n * @returns A factory function returning the default, or undefined if no default exists.\n *\n * @example\n * ```ts\n * const getter = getSchemaDefaultGetter(z.string().default(\"hello\"));\n * getter?.(); // \"hello\"\n *\n * const noDefault = getSchemaDefaultGetter(z.string());\n * noDefault; // undefined\n * ```\n */\nexport function getSchemaDefaultGetter(\n schema: SerializableSchema | unknown\n): (() => unknown) | undefined {\n if (schema == null) {\n return undefined;\n }\n\n if (!isStandardSchema(schema)) {\n return undefined;\n }\n\n try {\n const result = schema[\"~standard\"].validate(undefined);\n\n // Handle sync result (not a Promise)\n // Default values are always synchronous - async validation only happens\n // with async refinements, which don't affect default value resolution.\n if (\n result &&\n typeof result === \"object\" &&\n !(\"then\" in result && typeof result.then === \"function\")\n ) {\n const syncResult = result as { issues?: unknown; value?: unknown };\n if (!syncResult.issues) {\n const defaultValue = syncResult.value;\n return () => defaultValue;\n }\n }\n } catch {\n // Validation threw - no default\n }\n\n return undefined;\n}\n"],"mappings":";;;;;;AASA,SAAgB,wBACd,QACqC;AACrC,KAAI,qBAAqB,OAAO,CAC9B,KAAI;AAEF,SADiB,OAAO,aACR,WAAW,MAAM,EAAE,QAAQ,YAAY,CAAC;SAClD;AACN;;;;;;;;;;;;;;;;;;;;;;;;AA2BN,SAAgB,uBACd,QAC6B;AAC7B,KAAI,UAAU,KACZ;AAGF,KAAI,CAAC,iBAAiB,OAAO,CAC3B;AAGF,KAAI;EACF,MAAM,SAAS,OAAO,aAAa,SAAS,OAAU;AAKtD,MACE,UACA,OAAO,WAAW,YAClB,EAAE,UAAU,UAAU,OAAO,OAAO,SAAS,aAC7C;GACA,MAAM,aAAa;AACnB,OAAI,CAAC,WAAW,QAAQ;IACtB,MAAM,eAAe,WAAW;AAChC,iBAAa;;;SAGX"}
@@ -0,0 +1,8 @@
1
+ const require_types = require('./types.cjs');
2
+ const require_adapter = require('./adapter.cjs');
3
+ const require_reduced = require('./values/reduced.cjs');
4
+ const require_untracked = require('./values/untracked.cjs');
5
+ const require_schema = require('./schema.cjs');
6
+ const require_messages = require('./prebuilt/messages.cjs');
7
+ require('./prebuilt/index.cjs');
8
+ require('./values/index.cjs');
@@ -0,0 +1,10 @@
1
+ import { isSerializableSchema, isStandardSchema } from "./types.js";
2
+ import { getJsonSchemaFromSchema, getSchemaDefaultGetter } from "./adapter.js";
3
+ import { ReducedValue } from "./values/reduced.js";
4
+ import { UntrackedValue } from "./values/untracked.js";
5
+ import { StateSchema } from "./schema.js";
6
+ import { MessagesValue } from "./prebuilt/messages.js";
7
+ import "./prebuilt/index.js";
8
+ import "./values/index.js";
9
+
10
+ export { };
@@ -0,0 +1 @@
1
+ const require_messages = require('./messages.cjs');
@@ -0,0 +1,3 @@
1
+ import { MessagesValue } from "./messages.js";
2
+
3
+ export { };
@@ -0,0 +1,19 @@
1
+ const require_reduced = require('../values/reduced.cjs');
2
+ const require_messages_reducer = require('../../graph/messages_reducer.cjs');
3
+ let zod_v4 = require("zod/v4");
4
+
5
+ //#region src/state/prebuilt/messages.ts
6
+ const messagesValueSchema = zod_v4.z.custom().default(() => []);
7
+ const messagesInputSchema = zod_v4.z.custom();
8
+ const MessagesValue = new require_reduced.ReducedValue(messagesValueSchema, {
9
+ inputSchema: messagesInputSchema,
10
+ reducer: require_messages_reducer.messagesStateReducer,
11
+ jsonSchemaExtra: {
12
+ langgraph_type: "messages",
13
+ description: "A list of chat messages"
14
+ }
15
+ });
16
+
17
+ //#endregion
18
+ exports.MessagesValue = MessagesValue;
19
+ //# sourceMappingURL=messages.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"messages.cjs","names":["z","ReducedValue","messagesStateReducer"],"sources":["../../../src/state/prebuilt/messages.ts"],"sourcesContent":["import type { BaseMessage } from \"@langchain/core/messages\";\nimport { z } from \"zod/v4\";\n\nimport { ReducedValue } from \"../values/reduced.js\";\nimport {\n messagesStateReducer,\n type Messages,\n} from \"../../graph/messages_reducer.js\";\n\nconst messagesValueSchema = z.custom<BaseMessage[]>().default(() => []);\nconst messagesInputSchema = z.custom<Messages>();\n\nexport const MessagesValue = new ReducedValue(\n // Value schema: array of BaseMessage\n messagesValueSchema,\n {\n // Input schema: accepts flexible message types\n inputSchema: messagesInputSchema,\n // Use the existing messagesStateReducer\n reducer: messagesStateReducer,\n // JSON schema extras for Studio\n jsonSchemaExtra: {\n langgraph_type: \"messages\",\n description: \"A list of chat messages\",\n },\n }\n);\n"],"mappings":";;;;;AASA,MAAM,sBAAsBA,SAAE,QAAuB,CAAC,cAAc,EAAE,CAAC;AACvE,MAAM,sBAAsBA,SAAE,QAAkB;AAEhD,MAAa,gBAAgB,IAAIC,6BAE/B,qBACA;CAEE,aAAa;CAEb,SAASC;CAET,iBAAiB;EACf,gBAAgB;EAChB,aAAa;EACd;CACF,CACF"}
@@ -0,0 +1,10 @@
1
+ import { ReducedValue } from "../values/reduced.cjs";
2
+ import { Messages } from "../../graph/messages_reducer.cjs";
3
+ import * as _langchain_core_messages44 from "@langchain/core/messages";
4
+ import { BaseMessage } from "@langchain/core/messages";
5
+
6
+ //#region src/state/prebuilt/messages.d.ts
7
+ declare const MessagesValue: ReducedValue<BaseMessage<_langchain_core_messages44.MessageStructure<_langchain_core_messages44.MessageToolSet>, _langchain_core_messages44.MessageType>[], Messages>;
8
+ //#endregion
9
+ export { MessagesValue };
10
+ //# sourceMappingURL=messages.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"messages.d.cts","names":["BaseMessage","ReducedValue","Messages","MessagesValue","_langchain_core_messages44","MessageToolSet","MessageStructure","MessageType"],"sources":["../../../src/state/prebuilt/messages.d.ts"],"sourcesContent":["import type { BaseMessage } from \"@langchain/core/messages\";\nimport { ReducedValue } from \"../values/reduced.js\";\nimport { type Messages } from \"../../graph/messages_reducer.js\";\nexport declare const MessagesValue: ReducedValue<BaseMessage<import(\"@langchain/core/messages\").MessageStructure<import(\"@langchain/core/messages\").MessageToolSet>, import(\"@langchain/core/messages\").MessageType>[], Messages>;\n"],"mappings":";;;;;;cAGqBG,eAAeF,aAAaD,YAAiHI,0BAAAA,CAAlEE,iBAAiIF,0BAAAA,CAA7EC,cAAAA,GAApCD,0BAAAA,CAAwFG,WAAAA,KAAgBL"}
@@ -0,0 +1,10 @@
1
+ import { ReducedValue } from "../values/reduced.js";
2
+ import { Messages } from "../../graph/messages_reducer.js";
3
+ import * as _langchain_core_messages44 from "@langchain/core/messages";
4
+ import { BaseMessage } from "@langchain/core/messages";
5
+
6
+ //#region src/state/prebuilt/messages.d.ts
7
+ declare const MessagesValue: ReducedValue<BaseMessage<_langchain_core_messages44.MessageStructure<_langchain_core_messages44.MessageToolSet>, _langchain_core_messages44.MessageType>[], Messages>;
8
+ //#endregion
9
+ export { MessagesValue };
10
+ //# sourceMappingURL=messages.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"messages.d.ts","names":["BaseMessage","ReducedValue","Messages","MessagesValue","_langchain_core_messages44","MessageToolSet","MessageStructure","MessageType"],"sources":["../../../src/state/prebuilt/messages.d.ts"],"sourcesContent":["import type { BaseMessage } from \"@langchain/core/messages\";\nimport { ReducedValue } from \"../values/reduced.js\";\nimport { type Messages } from \"../../graph/messages_reducer.js\";\nexport declare const MessagesValue: ReducedValue<BaseMessage<import(\"@langchain/core/messages\").MessageStructure<import(\"@langchain/core/messages\").MessageToolSet>, import(\"@langchain/core/messages\").MessageType>[], Messages>;\n"],"mappings":";;;;;;cAGqBG,eAAeF,aAAaD,YAAiHI,0BAAAA,CAAlEE,iBAAiIF,0BAAAA,CAA7EC,cAAAA,GAApCD,0BAAAA,CAAwFG,WAAAA,KAAgBL"}
@@ -0,0 +1,19 @@
1
+ import { ReducedValue } from "../values/reduced.js";
2
+ import { messagesStateReducer } from "../../graph/messages_reducer.js";
3
+ import { z } from "zod/v4";
4
+
5
+ //#region src/state/prebuilt/messages.ts
6
+ const messagesValueSchema = z.custom().default(() => []);
7
+ const messagesInputSchema = z.custom();
8
+ const MessagesValue = new ReducedValue(messagesValueSchema, {
9
+ inputSchema: messagesInputSchema,
10
+ reducer: messagesStateReducer,
11
+ jsonSchemaExtra: {
12
+ langgraph_type: "messages",
13
+ description: "A list of chat messages"
14
+ }
15
+ });
16
+
17
+ //#endregion
18
+ export { MessagesValue };
19
+ //# sourceMappingURL=messages.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"messages.js","names":[],"sources":["../../../src/state/prebuilt/messages.ts"],"sourcesContent":["import type { BaseMessage } from \"@langchain/core/messages\";\nimport { z } from \"zod/v4\";\n\nimport { ReducedValue } from \"../values/reduced.js\";\nimport {\n messagesStateReducer,\n type Messages,\n} from \"../../graph/messages_reducer.js\";\n\nconst messagesValueSchema = z.custom<BaseMessage[]>().default(() => []);\nconst messagesInputSchema = z.custom<Messages>();\n\nexport const MessagesValue = new ReducedValue(\n // Value schema: array of BaseMessage\n messagesValueSchema,\n {\n // Input schema: accepts flexible message types\n inputSchema: messagesInputSchema,\n // Use the existing messagesStateReducer\n reducer: messagesStateReducer,\n // JSON schema extras for Studio\n jsonSchemaExtra: {\n langgraph_type: \"messages\",\n description: \"A list of chat messages\",\n },\n }\n);\n"],"mappings":";;;;;AASA,MAAM,sBAAsB,EAAE,QAAuB,CAAC,cAAc,EAAE,CAAC;AACvE,MAAM,sBAAsB,EAAE,QAAkB;AAEhD,MAAa,gBAAgB,IAAI,aAE/B,qBACA;CAEE,aAAa;CAEb,SAAS;CAET,iBAAiB;EACf,gBAAgB;EAChB,aAAa;EACd;CACF,CACF"}
@@ -0,0 +1,171 @@
1
+ const require_binop = require('../channels/binop.cjs');
2
+ const require_last_value = require('../channels/last_value.cjs');
3
+ const require_types = require('./types.cjs');
4
+ const require_adapter = require('./adapter.cjs');
5
+ const require_untracked_value = require('../channels/untracked_value.cjs');
6
+ require('../channels/index.cjs');
7
+ const require_reduced = require('./values/reduced.cjs');
8
+ const require_untracked = require('./values/untracked.cjs');
9
+
10
+ //#region src/state/schema.ts
11
+ const STATE_SCHEMA_SYMBOL = Symbol.for("langgraph.state.state_schema");
12
+ /**
13
+ * StateSchema provides a unified API for defining LangGraph state schemas.
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * import { z } from "zod";
18
+ * import { StateSchema, ReducedValue, MessagesValue } from "@langchain/langgraph";
19
+ *
20
+ * const AgentState = new StateSchema({
21
+ * // Prebuilt messages value
22
+ * messages: MessagesValue,
23
+ * // Basic LastValue channel from any standard schema
24
+ * currentStep: z.string(),
25
+ * // LastValue with native default
26
+ * count: z.number().default(0),
27
+ * // ReducedValue for fields needing reducers
28
+ * history: new ReducedValue(
29
+ * z.array(z.string()).default(() => []),
30
+ * {
31
+ * inputSchema: z.string(),
32
+ * reducer: (current, next) => [...current, next],
33
+ * }
34
+ * ),
35
+ * });
36
+ *
37
+ * // Extract types
38
+ * type State = typeof AgentState.State;
39
+ * type Update = typeof AgentState.Update;
40
+ *
41
+ * // Use in StateGraph
42
+ * const graph = new StateGraph(AgentState);
43
+ * ```
44
+ */
45
+ var StateSchema = class {
46
+ /**
47
+ * Symbol for runtime identification.
48
+ * @internal Used by isInstance for runtime type checking
49
+ */
50
+ [STATE_SCHEMA_SYMBOL] = true;
51
+ constructor(init) {
52
+ this.init = init;
53
+ this.init = init;
54
+ }
55
+ /**
56
+ * Get the channel definitions for use with StateGraph.
57
+ * This converts the StateSchema fields into BaseChannel instances.
58
+ */
59
+ getChannels() {
60
+ const channels = {};
61
+ for (const [key, value] of Object.entries(this.init)) if (require_reduced.ReducedValue.isInstance(value)) {
62
+ const defaultGetter = require_adapter.getSchemaDefaultGetter(value.valueSchema);
63
+ channels[key] = new require_binop.BinaryOperatorAggregate(value.reducer, defaultGetter);
64
+ } else if (require_untracked.UntrackedValue.isInstance(value)) {
65
+ const defaultGetter = value.schema ? require_adapter.getSchemaDefaultGetter(value.schema) : void 0;
66
+ channels[key] = new require_untracked_value.UntrackedValueChannel({
67
+ guard: value.guard,
68
+ initialValueFactory: defaultGetter
69
+ });
70
+ } else if (require_types.isStandardSchema(value)) channels[key] = new require_last_value.LastValue(require_adapter.getSchemaDefaultGetter(value));
71
+ else throw new Error(`Invalid state field "${key}": must be a schema, ReducedValue, UntrackedValue, or ManagedValue`);
72
+ return channels;
73
+ }
74
+ /**
75
+ * Get the JSON schema for the full state type.
76
+ * Used by Studio and API for schema introspection.
77
+ */
78
+ getJsonSchema() {
79
+ const properties = {};
80
+ const required = [];
81
+ for (const [key, value] of Object.entries(this.init)) {
82
+ let fieldSchema;
83
+ if (require_reduced.ReducedValue.isInstance(value)) {
84
+ fieldSchema = require_adapter.getJsonSchemaFromSchema(value.valueSchema);
85
+ if (fieldSchema && value.jsonSchemaExtra) fieldSchema = {
86
+ ...fieldSchema,
87
+ ...value.jsonSchemaExtra
88
+ };
89
+ } else if (require_untracked.UntrackedValue.isInstance(value)) fieldSchema = value.schema ? require_adapter.getJsonSchemaFromSchema(value.schema) : void 0;
90
+ else if (require_types.isStandardSchema(value)) fieldSchema = require_adapter.getJsonSchemaFromSchema(value);
91
+ if (fieldSchema) {
92
+ properties[key] = fieldSchema;
93
+ let hasDefault = false;
94
+ if (require_reduced.ReducedValue.isInstance(value)) hasDefault = require_adapter.getSchemaDefaultGetter(value.valueSchema) !== void 0;
95
+ else if (require_untracked.UntrackedValue.isInstance(value)) hasDefault = value.schema ? require_adapter.getSchemaDefaultGetter(value.schema) !== void 0 : false;
96
+ else hasDefault = require_adapter.getSchemaDefaultGetter(value) !== void 0;
97
+ if (!hasDefault) required.push(key);
98
+ }
99
+ }
100
+ return {
101
+ type: "object",
102
+ properties,
103
+ required: required.length > 0 ? required : void 0
104
+ };
105
+ }
106
+ /**
107
+ * Get the JSON schema for the update/input type.
108
+ * All fields are optional in updates.
109
+ */
110
+ getInputJsonSchema() {
111
+ const properties = {};
112
+ for (const [key, value] of Object.entries(this.init)) {
113
+ let fieldSchema;
114
+ if (require_reduced.ReducedValue.isInstance(value)) fieldSchema = require_adapter.getJsonSchemaFromSchema(value.inputSchema);
115
+ else if (require_untracked.UntrackedValue.isInstance(value)) fieldSchema = value.schema ? require_adapter.getJsonSchemaFromSchema(value.schema) : void 0;
116
+ else if (require_types.isStandardSchema(value)) fieldSchema = require_adapter.getJsonSchemaFromSchema(value);
117
+ if (fieldSchema) properties[key] = fieldSchema;
118
+ }
119
+ return {
120
+ type: "object",
121
+ properties
122
+ };
123
+ }
124
+ /**
125
+ * Get the list of channel keys (excluding managed values).
126
+ */
127
+ getChannelKeys() {
128
+ return Object.entries(this.init).map(([key]) => key);
129
+ }
130
+ /**
131
+ * Get all keys (channels + managed values).
132
+ */
133
+ getAllKeys() {
134
+ return Object.keys(this.init);
135
+ }
136
+ /**
137
+ * Validate input data against the schema.
138
+ * This validates each field using its corresponding schema.
139
+ *
140
+ * @param data - The input data to validate
141
+ * @returns The validated data with coerced types
142
+ */
143
+ async validateInput(data) {
144
+ if (data == null || typeof data !== "object") return data;
145
+ const result = {};
146
+ for (const [key, value] of Object.entries(data)) {
147
+ const fieldDef = this.init[key];
148
+ if (fieldDef === void 0) {
149
+ result[key] = value;
150
+ continue;
151
+ }
152
+ let schema;
153
+ if (require_reduced.ReducedValue.isInstance(fieldDef)) schema = fieldDef.inputSchema;
154
+ else if (require_untracked.UntrackedValue.isInstance(fieldDef)) schema = fieldDef.schema;
155
+ else if (require_types.isStandardSchema(fieldDef)) schema = fieldDef;
156
+ if (schema) {
157
+ const validationResult = await schema["~standard"].validate(value);
158
+ if (validationResult.issues) throw new Error(`Validation failed for field "${key}": ${JSON.stringify(validationResult.issues)}`);
159
+ result[key] = validationResult.value;
160
+ } else result[key] = value;
161
+ }
162
+ return result;
163
+ }
164
+ static isInstance(value) {
165
+ return typeof value === "object" && value !== null && STATE_SCHEMA_SYMBOL in value && value[STATE_SCHEMA_SYMBOL] === true;
166
+ }
167
+ };
168
+
169
+ //#endregion
170
+ exports.StateSchema = StateSchema;
171
+ //# sourceMappingURL=schema.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.cjs","names":["ReducedValue","getSchemaDefaultGetter","BinaryOperatorAggregate","UntrackedValue","UntrackedValueChannel","isStandardSchema","LastValue","getJsonSchemaFromSchema"],"sources":["../../src/state/schema.ts"],"sourcesContent":["import type { JSONSchema } from \"@langchain/core/utils/json_schema\";\nimport type { StandardSchemaV1 } from \"@standard-schema/spec\";\n\nimport type { RunnableLike } from \"../pregel/runnable_types.js\";\nimport {\n BaseChannel,\n LastValue,\n BinaryOperatorAggregate,\n} from \"../channels/index.js\";\nimport { UntrackedValueChannel } from \"../channels/untracked_value.js\";\n\nimport type { SerializableSchema } from \"./types.js\";\nimport { isStandardSchema } from \"./types.js\";\nimport { getJsonSchemaFromSchema, getSchemaDefaultGetter } from \"./adapter.js\";\nimport { ReducedValue } from \"./values/reduced.js\";\nimport { UntrackedValue } from \"./values/untracked.js\";\n\nconst STATE_SCHEMA_SYMBOL = Symbol.for(\"langgraph.state.state_schema\");\n\n/**\n * Maps a single StateSchema field definition to its corresponding Channel type.\n *\n * This utility type inspects the type of the field and returns an appropriate\n * `BaseChannel` type, parameterized with the state \"value\" and \"input\" types according to the field's shape.\n *\n * Rules:\n * - If the field (`F`) is a `ReducedValue<V, I>`, the channel will store values of type `V`\n * and accept input of type `I`.\n * - If the field is a `UntrackedValue<V>`, the channel will store and accept values of type `V`.\n * - If the field is a `SerializableSchema<I, O>`, the channel will store values of type `O`\n * (the schema's output/validated value) and accept input of type `I`.\n * - For all other types, a generic `BaseChannel<unknown, unknown>` is used as fallback.\n *\n * @template F - The StateSchema field type to map to a Channel type.\n *\n * @example\n * ```typescript\n * type MyField = ReducedValue<number, string>;\n * type ChannelType = StateSchemaFieldToChannel<MyField>;\n * // ChannelType is BaseChannel<number, string>\n * ```\n */\nexport type StateSchemaFieldToChannel<F> = F extends ReducedValue<\n infer V,\n infer I\n>\n ? BaseChannel<V, I>\n : F extends UntrackedValue<infer V>\n ? BaseChannel<V, V>\n : F extends SerializableSchema<infer I, infer O>\n ? BaseChannel<O, I>\n : BaseChannel<unknown, unknown>;\n\n/**\n * Converts a StateSchema \"init\" object (field map) into a strongly-typed\n * State Definition object, where each key is mapped to its channel type.\n *\n * This utility type is used internally to create the shape of the state channels for a given schema,\n * substituting each field with the result of `StateSchemaFieldToChannel`.\n *\n * If you define a state schema as:\n * ```typescript\n * const fields = {\n * a: ReducedValue<number, string>(),\n * b: UntrackedValue<boolean>(),\n * c: SomeSerializableSchemaType, // SerializableSchema<in, out>\n * }\n * ```\n * then `StateSchemaFieldsToStateDefinition<typeof fields>` yields:\n * ```typescript\n * {\n * a: BaseChannel<number, string>;\n * b: BaseChannel<boolean, boolean>;\n * c: BaseChannel<typeof schema's output type, typeof schema's input type>;\n * }\n * ```\n *\n * @template TInit - The mapping of field names to StateSchema field types.\n * @returns An object type mapping keys to channel types.\n *\n * @see StateSchemaFieldToChannel\n */\nexport type StateSchemaFieldsToStateDefinition<TInit extends StateSchemaInit> =\n {\n [K in keyof TInit]: StateSchemaFieldToChannel<TInit[K]>;\n };\n\n/**\n * Valid field types for StateSchema.\n * Either a LangGraph state value type or a raw schema (e.g., Zod schema).\n */\nexport type StateSchemaField<Input = unknown, Output = Input> =\n | ReducedValue<Input, Output>\n | UntrackedValue<Output>\n | SerializableSchema<Input, Output>;\n\n/**\n * Init object for StateSchema constructor.\n * Uses `any` to allow variance in generic types (e.g., ReducedValue<string, string[]>).\n */\nexport type StateSchemaInit = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n [key: string]: StateSchemaField<any, any>;\n};\n\n/**\n * Infer the State type from a StateSchemaInit.\n * This is the type of the full state object.\n *\n * - ReducedValue<Value, Input> → Value (the stored type)\n * - UntrackedValue<Value> → Value\n * - SerializableSchema<Input, Output> → Output (the validated type)\n */\nexport type InferStateSchemaValue<TInit extends StateSchemaInit> = {\n [K in keyof TInit]: TInit[K] extends { ValueType: infer TValue }\n ? TValue\n : TInit[K] extends UntrackedValue<infer TValue>\n ? TValue\n : TInit[K] extends SerializableSchema<unknown, infer TOutput>\n ? TOutput\n : never;\n};\n\n/**\n * Infer the Update type from a StateSchemaInit.\n * This is the type for partial updates to state.\n *\n * - ReducedValue<Value, Input> → Input (the reducer input type)\n * - UntrackedValue<Value> → Value\n * - SerializableSchema<Input, Output> → Input (what you provide)\n */\nexport type InferStateSchemaUpdate<TInit extends StateSchemaInit> = {\n [K in keyof TInit]?: TInit[K] extends { InputType: infer TInput }\n ? TInput\n : TInit[K] extends UntrackedValue<infer TValue>\n ? TValue\n : TInit[K] extends SerializableSchema<infer TInput, unknown>\n ? TInput\n : never;\n};\n\n/**\n * StateSchema provides a unified API for defining LangGraph state schemas.\n *\n * @example\n * ```ts\n * import { z } from \"zod\";\n * import { StateSchema, ReducedValue, MessagesValue } from \"@langchain/langgraph\";\n *\n * const AgentState = new StateSchema({\n * // Prebuilt messages value\n * messages: MessagesValue,\n * // Basic LastValue channel from any standard schema\n * currentStep: z.string(),\n * // LastValue with native default\n * count: z.number().default(0),\n * // ReducedValue for fields needing reducers\n * history: new ReducedValue(\n * z.array(z.string()).default(() => []),\n * {\n * inputSchema: z.string(),\n * reducer: (current, next) => [...current, next],\n * }\n * ),\n * });\n *\n * // Extract types\n * type State = typeof AgentState.State;\n * type Update = typeof AgentState.Update;\n *\n * // Use in StateGraph\n * const graph = new StateGraph(AgentState);\n * ```\n */\nexport class StateSchema<TInit extends StateSchemaInit> {\n /**\n * Symbol for runtime identification.\n * @internal Used by isInstance for runtime type checking\n */\n // @ts-expect-error - Symbol is read via `in` operator in isInstance\n private readonly [STATE_SCHEMA_SYMBOL] = true;\n\n /**\n * Type declaration for the full state type.\n * Use: `typeof myState.State`\n */\n declare State: InferStateSchemaValue<TInit>;\n\n /**\n * Type declaration for the update type.\n * Use: `typeof myState.Update`\n */\n declare Update: InferStateSchemaUpdate<TInit>;\n\n /**\n * Type declaration for node functions.\n * Use: `typeof myState.Node` to type node functions outside the graph builder.\n *\n * @example\n * ```typescript\n * const AgentState = new StateSchema({\n * count: z.number().default(0),\n * });\n *\n * const myNode: typeof AgentState.Node = (state) => {\n * return { count: state.count + 1 };\n * };\n * ```\n */\n declare Node: RunnableLike<\n InferStateSchemaValue<TInit>,\n InferStateSchemaUpdate<TInit>\n >;\n\n constructor(readonly init: TInit) {\n this.init = init;\n }\n\n /**\n * Get the channel definitions for use with StateGraph.\n * This converts the StateSchema fields into BaseChannel instances.\n */\n getChannels(): Record<string, BaseChannel> {\n const channels: Record<string, BaseChannel> = {};\n\n for (const [key, value] of Object.entries(this.init)) {\n if (ReducedValue.isInstance(value)) {\n // ReducedValue -> BinaryOperatorAggregate\n const defaultGetter = getSchemaDefaultGetter(value.valueSchema);\n channels[key] = new BinaryOperatorAggregate(\n value.reducer,\n defaultGetter\n );\n } else if (UntrackedValue.isInstance(value)) {\n // UntrackedValue -> UntrackedValueChannel\n const defaultGetter = value.schema\n ? getSchemaDefaultGetter(value.schema)\n : undefined;\n channels[key] = new UntrackedValueChannel({\n guard: value.guard,\n initialValueFactory: defaultGetter,\n });\n } else if (isStandardSchema(value)) {\n // Plain schema -> LastValue channel\n const defaultGetter = getSchemaDefaultGetter(value);\n channels[key] = new LastValue(defaultGetter);\n } else {\n throw new Error(\n `Invalid state field \"${key}\": must be a schema, ReducedValue, UntrackedValue, or ManagedValue`\n );\n }\n }\n\n return channels;\n }\n\n /**\n * Get the JSON schema for the full state type.\n * Used by Studio and API for schema introspection.\n */\n getJsonSchema(): JSONSchema {\n const properties: Record<string, JSONSchema> = {};\n const required: string[] = [];\n\n for (const [key, value] of Object.entries(this.init)) {\n let fieldSchema: JSONSchema | undefined;\n\n if (ReducedValue.isInstance(value)) {\n fieldSchema = getJsonSchemaFromSchema(value.valueSchema) as JSONSchema;\n if (fieldSchema && value.jsonSchemaExtra) {\n fieldSchema = { ...fieldSchema, ...value.jsonSchemaExtra };\n }\n } else if (UntrackedValue.isInstance(value)) {\n fieldSchema = value.schema\n ? (getJsonSchemaFromSchema(value.schema) as JSONSchema)\n : undefined;\n } else if (isStandardSchema(value)) {\n fieldSchema = getJsonSchemaFromSchema(value) as JSONSchema;\n }\n\n if (fieldSchema) {\n properties[key] = fieldSchema;\n\n // Field is required if it doesn't have a default\n let hasDefault = false;\n if (ReducedValue.isInstance(value)) {\n hasDefault = getSchemaDefaultGetter(value.valueSchema) !== undefined;\n } else if (UntrackedValue.isInstance(value)) {\n hasDefault = value.schema\n ? getSchemaDefaultGetter(value.schema) !== undefined\n : false;\n } else {\n hasDefault = getSchemaDefaultGetter(value) !== undefined;\n }\n\n if (!hasDefault) {\n required.push(key);\n }\n }\n }\n\n return {\n type: \"object\",\n properties,\n required: required.length > 0 ? required : undefined,\n };\n }\n\n /**\n * Get the JSON schema for the update/input type.\n * All fields are optional in updates.\n */\n getInputJsonSchema(): JSONSchema {\n const properties: Record<string, JSONSchema> = {};\n\n for (const [key, value] of Object.entries(this.init)) {\n let fieldSchema: JSONSchema | undefined;\n\n if (ReducedValue.isInstance(value)) {\n // Use input schema for updates\n fieldSchema = getJsonSchemaFromSchema(value.inputSchema) as JSONSchema;\n } else if (UntrackedValue.isInstance(value)) {\n fieldSchema = value.schema\n ? (getJsonSchemaFromSchema(value.schema) as JSONSchema)\n : undefined;\n } else if (isStandardSchema(value)) {\n fieldSchema = getJsonSchemaFromSchema(value) as JSONSchema;\n }\n\n if (fieldSchema) {\n properties[key] = fieldSchema;\n }\n }\n\n return {\n type: \"object\",\n properties,\n };\n }\n\n /**\n * Get the list of channel keys (excluding managed values).\n */\n getChannelKeys(): string[] {\n return Object.entries(this.init).map(([key]) => key);\n }\n\n /**\n * Get all keys (channels + managed values).\n */\n getAllKeys(): string[] {\n return Object.keys(this.init);\n }\n\n /**\n * Validate input data against the schema.\n * This validates each field using its corresponding schema.\n *\n * @param data - The input data to validate\n * @returns The validated data with coerced types\n */\n async validateInput<T>(data: T): Promise<T> {\n if (data == null || typeof data !== \"object\") {\n return data;\n }\n\n const result: Record<string, unknown> = {};\n\n for (const [key, value] of Object.entries(data)) {\n const fieldDef = this.init[key];\n\n if (fieldDef === undefined) {\n // Unknown field, pass through\n result[key] = value;\n continue;\n }\n\n // Get the schema to use for validation\n let schema: StandardSchemaV1 | undefined;\n\n if (ReducedValue.isInstance(fieldDef)) {\n schema = fieldDef.inputSchema;\n } else if (UntrackedValue.isInstance(fieldDef)) {\n schema = fieldDef.schema;\n } else if (isStandardSchema(fieldDef)) {\n schema = fieldDef;\n }\n\n if (schema) {\n // Validate using standard schema\n const validationResult = await schema[\"~standard\"].validate(value);\n if (validationResult.issues) {\n throw new Error(\n `Validation failed for field \"${key}\": ${JSON.stringify(\n validationResult.issues\n )}`\n );\n }\n result[key] = validationResult.value;\n } else {\n // No schema or not a standard schema, pass through\n result[key] = value;\n }\n }\n\n return result as T;\n }\n\n /**\n * Type guard to check if a value is a StateSchema instance.\n *\n * @param value - The value to check.\n * @returns True if the value is a StateSchema instance with the correct runtime tag.\n */\n static isInstance<TInit extends StateSchemaInit>(\n value: StateSchema<TInit>\n ): value is StateSchema<TInit>;\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n static isInstance(value: unknown): value is StateSchema<any>;\n\n static isInstance<TInit extends StateSchemaInit>(\n value: unknown\n ): value is StateSchema<TInit> {\n return (\n typeof value === \"object\" &&\n value !== null &&\n STATE_SCHEMA_SYMBOL in value &&\n value[STATE_SCHEMA_SYMBOL] === true\n );\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type AnyStateSchema = StateSchema<any>;\n"],"mappings":"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"}
@@ -0,0 +1,208 @@
1
+ import { BaseChannel } from "../channels/base.cjs";
2
+ import { RunnableLike } from "../pregel/runnable_types.cjs";
3
+ import { SerializableSchema } from "./types.cjs";
4
+ import { ReducedValue } from "./values/reduced.cjs";
5
+ import { UntrackedValue } from "./values/untracked.cjs";
6
+ import { JSONSchema } from "@langchain/core/utils/json_schema";
7
+
8
+ //#region src/state/schema.d.ts
9
+ declare const STATE_SCHEMA_SYMBOL: unique symbol;
10
+ /**
11
+ * Maps a single StateSchema field definition to its corresponding Channel type.
12
+ *
13
+ * This utility type inspects the type of the field and returns an appropriate
14
+ * `BaseChannel` type, parameterized with the state "value" and "input" types according to the field's shape.
15
+ *
16
+ * Rules:
17
+ * - If the field (`F`) is a `ReducedValue<V, I>`, the channel will store values of type `V`
18
+ * and accept input of type `I`.
19
+ * - If the field is a `UntrackedValue<V>`, the channel will store and accept values of type `V`.
20
+ * - If the field is a `SerializableSchema<I, O>`, the channel will store values of type `O`
21
+ * (the schema's output/validated value) and accept input of type `I`.
22
+ * - For all other types, a generic `BaseChannel<unknown, unknown>` is used as fallback.
23
+ *
24
+ * @template F - The StateSchema field type to map to a Channel type.
25
+ *
26
+ * @example
27
+ * ```typescript
28
+ * type MyField = ReducedValue<number, string>;
29
+ * type ChannelType = StateSchemaFieldToChannel<MyField>;
30
+ * // ChannelType is BaseChannel<number, string>
31
+ * ```
32
+ */
33
+ type StateSchemaFieldToChannel<F> = F extends ReducedValue<infer V, infer I> ? BaseChannel<V, I> : F extends UntrackedValue<infer V> ? BaseChannel<V, V> : F extends SerializableSchema<infer I, infer O> ? BaseChannel<O, I> : BaseChannel<unknown, unknown>;
34
+ /**
35
+ * Converts a StateSchema "init" object (field map) into a strongly-typed
36
+ * State Definition object, where each key is mapped to its channel type.
37
+ *
38
+ * This utility type is used internally to create the shape of the state channels for a given schema,
39
+ * substituting each field with the result of `StateSchemaFieldToChannel`.
40
+ *
41
+ * If you define a state schema as:
42
+ * ```typescript
43
+ * const fields = {
44
+ * a: ReducedValue<number, string>(),
45
+ * b: UntrackedValue<boolean>(),
46
+ * c: SomeSerializableSchemaType, // SerializableSchema<in, out>
47
+ * }
48
+ * ```
49
+ * then `StateSchemaFieldsToStateDefinition<typeof fields>` yields:
50
+ * ```typescript
51
+ * {
52
+ * a: BaseChannel<number, string>;
53
+ * b: BaseChannel<boolean, boolean>;
54
+ * c: BaseChannel<typeof schema's output type, typeof schema's input type>;
55
+ * }
56
+ * ```
57
+ *
58
+ * @template TInit - The mapping of field names to StateSchema field types.
59
+ * @returns An object type mapping keys to channel types.
60
+ *
61
+ * @see StateSchemaFieldToChannel
62
+ */
63
+ type StateSchemaFieldsToStateDefinition<TInit extends StateSchemaInit> = { [K in keyof TInit]: StateSchemaFieldToChannel<TInit[K]> };
64
+ /**
65
+ * Valid field types for StateSchema.
66
+ * Either a LangGraph state value type or a raw schema (e.g., Zod schema).
67
+ */
68
+ type StateSchemaField<Input = unknown, Output = Input> = ReducedValue<Input, Output> | UntrackedValue<Output> | SerializableSchema<Input, Output>;
69
+ /**
70
+ * Init object for StateSchema constructor.
71
+ * Uses `any` to allow variance in generic types (e.g., ReducedValue<string, string[]>).
72
+ */
73
+ type StateSchemaInit = {
74
+ [key: string]: StateSchemaField<any, any>;
75
+ };
76
+ /**
77
+ * Infer the State type from a StateSchemaInit.
78
+ * This is the type of the full state object.
79
+ *
80
+ * - ReducedValue<Value, Input> → Value (the stored type)
81
+ * - UntrackedValue<Value> → Value
82
+ * - SerializableSchema<Input, Output> → Output (the validated type)
83
+ */
84
+ type InferStateSchemaValue<TInit extends StateSchemaInit> = { [K in keyof TInit]: TInit[K] extends {
85
+ ValueType: infer TValue;
86
+ } ? TValue : TInit[K] extends UntrackedValue<infer TValue> ? TValue : TInit[K] extends SerializableSchema<unknown, infer TOutput> ? TOutput : never };
87
+ /**
88
+ * Infer the Update type from a StateSchemaInit.
89
+ * This is the type for partial updates to state.
90
+ *
91
+ * - ReducedValue<Value, Input> → Input (the reducer input type)
92
+ * - UntrackedValue<Value> → Value
93
+ * - SerializableSchema<Input, Output> → Input (what you provide)
94
+ */
95
+ type InferStateSchemaUpdate<TInit extends StateSchemaInit> = { [K in keyof TInit]?: TInit[K] extends {
96
+ InputType: infer TInput;
97
+ } ? TInput : TInit[K] extends UntrackedValue<infer TValue> ? TValue : TInit[K] extends SerializableSchema<infer TInput, unknown> ? TInput : never };
98
+ /**
99
+ * StateSchema provides a unified API for defining LangGraph state schemas.
100
+ *
101
+ * @example
102
+ * ```ts
103
+ * import { z } from "zod";
104
+ * import { StateSchema, ReducedValue, MessagesValue } from "@langchain/langgraph";
105
+ *
106
+ * const AgentState = new StateSchema({
107
+ * // Prebuilt messages value
108
+ * messages: MessagesValue,
109
+ * // Basic LastValue channel from any standard schema
110
+ * currentStep: z.string(),
111
+ * // LastValue with native default
112
+ * count: z.number().default(0),
113
+ * // ReducedValue for fields needing reducers
114
+ * history: new ReducedValue(
115
+ * z.array(z.string()).default(() => []),
116
+ * {
117
+ * inputSchema: z.string(),
118
+ * reducer: (current, next) => [...current, next],
119
+ * }
120
+ * ),
121
+ * });
122
+ *
123
+ * // Extract types
124
+ * type State = typeof AgentState.State;
125
+ * type Update = typeof AgentState.Update;
126
+ *
127
+ * // Use in StateGraph
128
+ * const graph = new StateGraph(AgentState);
129
+ * ```
130
+ */
131
+ declare class StateSchema<TInit extends StateSchemaInit> {
132
+ readonly init: TInit;
133
+ /**
134
+ * Symbol for runtime identification.
135
+ * @internal Used by isInstance for runtime type checking
136
+ */
137
+ private readonly [STATE_SCHEMA_SYMBOL];
138
+ /**
139
+ * Type declaration for the full state type.
140
+ * Use: `typeof myState.State`
141
+ */
142
+ State: InferStateSchemaValue<TInit>;
143
+ /**
144
+ * Type declaration for the update type.
145
+ * Use: `typeof myState.Update`
146
+ */
147
+ Update: InferStateSchemaUpdate<TInit>;
148
+ /**
149
+ * Type declaration for node functions.
150
+ * Use: `typeof myState.Node` to type node functions outside the graph builder.
151
+ *
152
+ * @example
153
+ * ```typescript
154
+ * const AgentState = new StateSchema({
155
+ * count: z.number().default(0),
156
+ * });
157
+ *
158
+ * const myNode: typeof AgentState.Node = (state) => {
159
+ * return { count: state.count + 1 };
160
+ * };
161
+ * ```
162
+ */
163
+ Node: RunnableLike<InferStateSchemaValue<TInit>, InferStateSchemaUpdate<TInit>>;
164
+ constructor(init: TInit);
165
+ /**
166
+ * Get the channel definitions for use with StateGraph.
167
+ * This converts the StateSchema fields into BaseChannel instances.
168
+ */
169
+ getChannels(): Record<string, BaseChannel>;
170
+ /**
171
+ * Get the JSON schema for the full state type.
172
+ * Used by Studio and API for schema introspection.
173
+ */
174
+ getJsonSchema(): JSONSchema;
175
+ /**
176
+ * Get the JSON schema for the update/input type.
177
+ * All fields are optional in updates.
178
+ */
179
+ getInputJsonSchema(): JSONSchema;
180
+ /**
181
+ * Get the list of channel keys (excluding managed values).
182
+ */
183
+ getChannelKeys(): string[];
184
+ /**
185
+ * Get all keys (channels + managed values).
186
+ */
187
+ getAllKeys(): string[];
188
+ /**
189
+ * Validate input data against the schema.
190
+ * This validates each field using its corresponding schema.
191
+ *
192
+ * @param data - The input data to validate
193
+ * @returns The validated data with coerced types
194
+ */
195
+ validateInput<T>(data: T): Promise<T>;
196
+ /**
197
+ * Type guard to check if a value is a StateSchema instance.
198
+ *
199
+ * @param value - The value to check.
200
+ * @returns True if the value is a StateSchema instance with the correct runtime tag.
201
+ */
202
+ static isInstance<TInit extends StateSchemaInit>(value: StateSchema<TInit>): value is StateSchema<TInit>;
203
+ static isInstance(value: unknown): value is StateSchema<any>;
204
+ }
205
+ type AnyStateSchema = StateSchema<any>;
206
+ //#endregion
207
+ export { AnyStateSchema, InferStateSchemaUpdate, InferStateSchemaValue, StateSchema, StateSchemaField, StateSchemaFieldsToStateDefinition, StateSchemaInit };
208
+ //# sourceMappingURL=schema.d.cts.map