@langchain/langgraph-sdk 1.6.5 → 1.7.1

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 (223) hide show
  1. package/dist/_virtual/_rolldown/runtime.cjs +7 -13
  2. package/dist/auth/error.cjs +1 -2
  3. package/dist/auth/error.cjs.map +1 -1
  4. package/dist/auth/error.js +1 -1
  5. package/dist/auth/index.cjs +3 -4
  6. package/dist/auth/index.cjs.map +1 -1
  7. package/dist/auth/index.js +1 -2
  8. package/dist/auth/index.js.map +1 -1
  9. package/dist/client.cjs +9 -9
  10. package/dist/client.cjs.map +1 -1
  11. package/dist/client.d.cts.map +1 -1
  12. package/dist/client.d.ts.map +1 -1
  13. package/dist/client.js +3 -3
  14. package/dist/client.js.map +1 -1
  15. package/dist/index.cjs +5 -6
  16. package/dist/index.d.cts +4 -4
  17. package/dist/index.d.ts +4 -4
  18. package/dist/index.js +1 -2
  19. package/dist/logging/index.cjs +2 -3
  20. package/dist/logging/index.cjs.map +1 -1
  21. package/dist/logging/index.js +1 -1
  22. package/dist/react/index.cjs +46 -11
  23. package/dist/react/index.cjs.map +1 -0
  24. package/dist/react/index.d.cts +14 -11
  25. package/dist/react/index.d.cts.map +1 -0
  26. package/dist/react/index.d.ts +14 -11
  27. package/dist/react/index.d.ts.map +1 -0
  28. package/dist/react/index.js +13 -4
  29. package/dist/react/index.js.map +1 -0
  30. package/dist/react-ui/index.cjs +39 -15
  31. package/dist/react-ui/index.d.cts +1 -2
  32. package/dist/react-ui/index.d.ts +1 -2
  33. package/dist/react-ui/index.js +1 -8
  34. package/dist/react-ui/server/index.cjs +15 -6
  35. package/dist/react-ui/server/index.d.cts +1 -2
  36. package/dist/react-ui/server/index.d.ts +1 -2
  37. package/dist/react-ui/server/index.js +2 -4
  38. package/dist/singletons/fetch.cjs +1 -2
  39. package/dist/singletons/fetch.cjs.map +1 -1
  40. package/dist/singletons/fetch.js +1 -1
  41. package/dist/singletons/fetch.js.map +1 -1
  42. package/dist/types.messages.d.cts +5 -3
  43. package/dist/types.messages.d.cts.map +1 -1
  44. package/dist/types.messages.d.ts +5 -3
  45. package/dist/types.messages.d.ts.map +1 -1
  46. package/dist/ui/branching.cjs +25 -2
  47. package/dist/ui/branching.cjs.map +1 -1
  48. package/dist/ui/branching.d.cts +26 -1
  49. package/dist/ui/branching.d.cts.map +1 -1
  50. package/dist/ui/branching.d.ts +26 -1
  51. package/dist/ui/branching.d.ts.map +1 -1
  52. package/dist/ui/branching.js +25 -2
  53. package/dist/ui/branching.js.map +1 -1
  54. package/dist/ui/errors.cjs +1 -2
  55. package/dist/ui/errors.cjs.map +1 -1
  56. package/dist/ui/errors.js +1 -1
  57. package/dist/ui/index.cjs +30 -0
  58. package/dist/ui/index.d.cts +15 -0
  59. package/dist/ui/index.d.ts +15 -0
  60. package/dist/ui/index.js +10 -0
  61. package/dist/ui/interrupts.cjs +20 -0
  62. package/dist/ui/interrupts.cjs.map +1 -0
  63. package/dist/ui/interrupts.d.cts +11 -0
  64. package/dist/ui/interrupts.d.cts.map +1 -0
  65. package/dist/ui/interrupts.d.ts +11 -0
  66. package/dist/ui/interrupts.d.ts.map +1 -0
  67. package/dist/ui/interrupts.js +20 -0
  68. package/dist/ui/interrupts.js.map +1 -0
  69. package/dist/ui/manager.cjs +13 -15
  70. package/dist/ui/manager.cjs.map +1 -1
  71. package/dist/ui/manager.d.cts +224 -0
  72. package/dist/ui/manager.d.cts.map +1 -0
  73. package/dist/ui/manager.d.ts +224 -0
  74. package/dist/ui/manager.d.ts.map +1 -0
  75. package/dist/ui/manager.js +10 -12
  76. package/dist/ui/manager.js.map +1 -1
  77. package/dist/ui/messages.cjs +40 -3
  78. package/dist/ui/messages.cjs.map +1 -1
  79. package/dist/ui/messages.d.cts +56 -0
  80. package/dist/ui/messages.d.cts.map +1 -0
  81. package/dist/ui/messages.d.ts +56 -0
  82. package/dist/ui/messages.d.ts.map +1 -0
  83. package/dist/ui/messages.js +37 -3
  84. package/dist/ui/messages.js.map +1 -1
  85. package/dist/ui/queue.cjs +74 -0
  86. package/dist/ui/queue.cjs.map +1 -0
  87. package/dist/ui/queue.d.cts +72 -0
  88. package/dist/ui/queue.d.cts.map +1 -0
  89. package/dist/ui/queue.d.ts +72 -0
  90. package/dist/ui/queue.d.ts.map +1 -0
  91. package/dist/ui/queue.js +74 -0
  92. package/dist/ui/queue.js.map +1 -0
  93. package/dist/ui/stream/base.d.cts +11 -0
  94. package/dist/ui/stream/base.d.cts.map +1 -1
  95. package/dist/ui/stream/base.d.ts +11 -0
  96. package/dist/ui/stream/base.d.ts.map +1 -1
  97. package/dist/ui/stream/index.d.cts +4 -4
  98. package/dist/ui/stream/index.d.cts.map +1 -1
  99. package/dist/ui/stream/index.d.ts +4 -4
  100. package/dist/ui/stream/index.d.ts.map +1 -1
  101. package/dist/ui/subagents.cjs +7 -5
  102. package/dist/ui/subagents.cjs.map +1 -1
  103. package/dist/ui/subagents.d.cts +7 -0
  104. package/dist/ui/subagents.d.cts.map +1 -1
  105. package/dist/ui/subagents.d.ts +7 -0
  106. package/dist/ui/subagents.d.ts.map +1 -1
  107. package/dist/ui/subagents.js +5 -3
  108. package/dist/ui/subagents.js.map +1 -1
  109. package/dist/ui/transport.cjs +30 -0
  110. package/dist/ui/transport.cjs.map +1 -0
  111. package/dist/{react/stream.custom.d.cts → ui/transport.d.cts} +3 -3
  112. package/dist/ui/transport.d.cts.map +1 -0
  113. package/dist/{react/stream.custom.d.ts → ui/transport.d.ts} +3 -3
  114. package/dist/ui/transport.d.ts.map +1 -0
  115. package/dist/ui/transport.js +30 -0
  116. package/dist/ui/transport.js.map +1 -0
  117. package/dist/ui/types.d.cts +125 -16
  118. package/dist/ui/types.d.cts.map +1 -1
  119. package/dist/ui/types.d.ts +125 -16
  120. package/dist/ui/types.d.ts.map +1 -1
  121. package/dist/ui/utils.cjs +1 -2
  122. package/dist/ui/utils.cjs.map +1 -1
  123. package/dist/ui/utils.d.cts +7 -0
  124. package/dist/ui/utils.d.cts.map +1 -0
  125. package/dist/ui/utils.d.ts +7 -0
  126. package/dist/ui/utils.d.ts.map +1 -0
  127. package/dist/ui/utils.js +1 -1
  128. package/dist/utils/async_caller.cjs +3 -4
  129. package/dist/utils/async_caller.cjs.map +1 -1
  130. package/dist/utils/async_caller.js +1 -2
  131. package/dist/utils/async_caller.js.map +1 -1
  132. package/dist/utils/env.cjs +1 -2
  133. package/dist/utils/env.cjs.map +1 -1
  134. package/dist/utils/env.js +1 -1
  135. package/dist/utils/env.js.map +1 -1
  136. package/dist/utils/error.cjs +1 -2
  137. package/dist/utils/error.cjs.map +1 -1
  138. package/dist/utils/error.js +1 -1
  139. package/dist/utils/index.cjs +8 -0
  140. package/dist/utils/index.d.cts +4 -0
  141. package/dist/utils/index.d.ts +4 -0
  142. package/dist/utils/index.js +4 -0
  143. package/dist/utils/signals.cjs +1 -2
  144. package/dist/utils/signals.cjs.map +1 -1
  145. package/dist/utils/signals.js +1 -1
  146. package/dist/utils/signals.js.map +1 -1
  147. package/dist/utils/sse.cjs +1 -2
  148. package/dist/utils/sse.cjs.map +1 -1
  149. package/dist/utils/sse.d.cts +11 -0
  150. package/dist/utils/sse.d.cts.map +1 -0
  151. package/dist/utils/sse.d.ts +11 -0
  152. package/dist/utils/sse.d.ts.map +1 -0
  153. package/dist/utils/sse.js +1 -1
  154. package/dist/utils/sse.js.map +1 -1
  155. package/dist/utils/stream.cjs +2 -3
  156. package/dist/utils/stream.cjs.map +1 -1
  157. package/dist/utils/stream.d.cts +19 -0
  158. package/dist/utils/stream.d.cts.map +1 -0
  159. package/dist/utils/stream.d.ts +19 -0
  160. package/dist/utils/stream.d.ts.map +1 -0
  161. package/dist/utils/stream.js +1 -2
  162. package/dist/utils/stream.js.map +1 -1
  163. package/dist/utils/tools.cjs +27 -19
  164. package/dist/utils/tools.cjs.map +1 -1
  165. package/dist/utils/tools.d.cts +7 -0
  166. package/dist/utils/tools.d.cts.map +1 -0
  167. package/dist/utils/tools.d.ts +7 -0
  168. package/dist/utils/tools.d.ts.map +1 -0
  169. package/dist/utils/tools.js +27 -18
  170. package/dist/utils/tools.js.map +1 -1
  171. package/package.json +41 -12
  172. package/dist/react/stream.cjs +0 -18
  173. package/dist/react/stream.cjs.map +0 -1
  174. package/dist/react/stream.custom.cjs +0 -164
  175. package/dist/react/stream.custom.cjs.map +0 -1
  176. package/dist/react/stream.custom.d.cts.map +0 -1
  177. package/dist/react/stream.custom.d.ts.map +0 -1
  178. package/dist/react/stream.custom.js +0 -162
  179. package/dist/react/stream.custom.js.map +0 -1
  180. package/dist/react/stream.d.cts +0 -174
  181. package/dist/react/stream.d.cts.map +0 -1
  182. package/dist/react/stream.d.ts +0 -174
  183. package/dist/react/stream.d.ts.map +0 -1
  184. package/dist/react/stream.js +0 -17
  185. package/dist/react/stream.js.map +0 -1
  186. package/dist/react/stream.lgp.cjs +0 -544
  187. package/dist/react/stream.lgp.cjs.map +0 -1
  188. package/dist/react/stream.lgp.js +0 -543
  189. package/dist/react/stream.lgp.js.map +0 -1
  190. package/dist/react/thread.cjs +0 -21
  191. package/dist/react/thread.cjs.map +0 -1
  192. package/dist/react/thread.js +0 -20
  193. package/dist/react/thread.js.map +0 -1
  194. package/dist/react/types.d.cts +0 -79
  195. package/dist/react/types.d.cts.map +0 -1
  196. package/dist/react/types.d.ts +0 -79
  197. package/dist/react/types.d.ts.map +0 -1
  198. package/dist/react-ui/client.cjs +0 -138
  199. package/dist/react-ui/client.cjs.map +0 -1
  200. package/dist/react-ui/client.d.cts +0 -76
  201. package/dist/react-ui/client.d.cts.map +0 -1
  202. package/dist/react-ui/client.d.ts +0 -76
  203. package/dist/react-ui/client.d.ts.map +0 -1
  204. package/dist/react-ui/client.js +0 -132
  205. package/dist/react-ui/client.js.map +0 -1
  206. package/dist/react-ui/index.cjs.map +0 -1
  207. package/dist/react-ui/index.js.map +0 -1
  208. package/dist/react-ui/server/server.cjs +0 -57
  209. package/dist/react-ui/server/server.cjs.map +0 -1
  210. package/dist/react-ui/server/server.d.cts +0 -54
  211. package/dist/react-ui/server/server.d.cts.map +0 -1
  212. package/dist/react-ui/server/server.d.ts +0 -54
  213. package/dist/react-ui/server/server.d.ts.map +0 -1
  214. package/dist/react-ui/server/server.js +0 -56
  215. package/dist/react-ui/server/server.js.map +0 -1
  216. package/dist/react-ui/types.cjs +0 -38
  217. package/dist/react-ui/types.cjs.map +0 -1
  218. package/dist/react-ui/types.d.cts +0 -25
  219. package/dist/react-ui/types.d.cts.map +0 -1
  220. package/dist/react-ui/types.d.ts +0 -25
  221. package/dist/react-ui/types.d.ts.map +0 -1
  222. package/dist/react-ui/types.js +0 -35
  223. package/dist/react-ui/types.js.map +0 -1
@@ -1,5 +1,4 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
-
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
2
  //#region src/logging/index.ts
4
3
  const GLOBAL_LOGGER = Symbol.for("langgraph.api.sdk-logger");
5
4
  /**
@@ -30,7 +29,7 @@ const getLogger = () => {
30
29
  if (GLOBAL_LOGGER in maybeGlobal) return maybeGlobal[GLOBAL_LOGGER];
31
30
  throw new Error("Logger not available in current environment. This method requires LangGraph Platform environment where a global logger is automatically registered. If you're developing locally, consider using `console.log` or a local logging library instead.");
32
31
  };
33
-
34
32
  //#endregion
35
33
  exports.getLogger = getLogger;
34
+
36
35
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":[],"sources":["../../src/logging/index.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\ninterface LeveledLogMethod {\n (message: string, ...meta: any[]): Logger;\n (message: any): Logger;\n (infoObject: object): Logger;\n}\n\ninterface Logger {\n error: LeveledLogMethod;\n warn: LeveledLogMethod;\n help: LeveledLogMethod;\n data: LeveledLogMethod;\n info: LeveledLogMethod;\n debug: LeveledLogMethod;\n prompt: LeveledLogMethod;\n http: LeveledLogMethod;\n verbose: LeveledLogMethod;\n input: LeveledLogMethod;\n silly: LeveledLogMethod;\n}\n\nconst GLOBAL_LOGGER = Symbol.for(\"langgraph.api.sdk-logger\");\ntype GLOBAL_LOGGER = typeof GLOBAL_LOGGER;\n\n/**\n * Retrieves the global logger instance for LangGraph Platform.\n *\n * The logger provides structured logging capabilities with\n * various log levels (error, warn, info, debug, etc.) and extra metadata such as node name etc.\n *\n * @returns {Logger} The global logger instance with leveled logging methods\n *\n * @throws {Error} When the logger is not available in the current environment\n *\n * @example\n * ```typescript\n * // Safe usage with fallback\n * const logger = getLogger();\n * logger.info(\"This will only work in LangGraph Platform environment\");\n * ```\n *\n * @remarks\n * This method is designed to work specifically within the LangGraph Platform\n * environment where a global logger is automatically registered. If you're\n * developing locally or in an environment where LangGraph Platform is not\n * available, this function will throw an error.\n */\nexport const getLogger = (): Logger => {\n const maybeGlobal = globalThis as unknown as { [GLOBAL_LOGGER]: Logger };\n if (GLOBAL_LOGGER in maybeGlobal) return maybeGlobal[GLOBAL_LOGGER];\n\n throw new Error(\n \"Logger not available in current environment. \" +\n \"This method requires LangGraph Platform environment where a global logger is automatically registered. \" +\n \"If you're developing locally, consider using `console.log` or a local logging library instead.\"\n );\n};\n"],"mappings":";;;AAqBA,MAAM,gBAAgB,OAAO,IAAI,2BAA2B;;;;;;;;;;;;;;;;;;;;;;;;AA0B5D,MAAa,kBAA0B;CACrC,MAAM,cAAc;AACpB,KAAI,iBAAiB,YAAa,QAAO,YAAY;AAErD,OAAM,IAAI,MACR,qPAGD"}
1
+ {"version":3,"file":"index.cjs","names":[],"sources":["../../src/logging/index.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\ninterface LeveledLogMethod {\n (message: string, ...meta: any[]): Logger;\n (message: any): Logger;\n (infoObject: object): Logger;\n}\n\ninterface Logger {\n error: LeveledLogMethod;\n warn: LeveledLogMethod;\n help: LeveledLogMethod;\n data: LeveledLogMethod;\n info: LeveledLogMethod;\n debug: LeveledLogMethod;\n prompt: LeveledLogMethod;\n http: LeveledLogMethod;\n verbose: LeveledLogMethod;\n input: LeveledLogMethod;\n silly: LeveledLogMethod;\n}\n\nconst GLOBAL_LOGGER = Symbol.for(\"langgraph.api.sdk-logger\");\ntype GLOBAL_LOGGER = typeof GLOBAL_LOGGER;\n\n/**\n * Retrieves the global logger instance for LangGraph Platform.\n *\n * The logger provides structured logging capabilities with\n * various log levels (error, warn, info, debug, etc.) and extra metadata such as node name etc.\n *\n * @returns {Logger} The global logger instance with leveled logging methods\n *\n * @throws {Error} When the logger is not available in the current environment\n *\n * @example\n * ```typescript\n * // Safe usage with fallback\n * const logger = getLogger();\n * logger.info(\"This will only work in LangGraph Platform environment\");\n * ```\n *\n * @remarks\n * This method is designed to work specifically within the LangGraph Platform\n * environment where a global logger is automatically registered. If you're\n * developing locally or in an environment where LangGraph Platform is not\n * available, this function will throw an error.\n */\nexport const getLogger = (): Logger => {\n const maybeGlobal = globalThis as unknown as { [GLOBAL_LOGGER]: Logger };\n if (GLOBAL_LOGGER in maybeGlobal) return maybeGlobal[GLOBAL_LOGGER];\n\n throw new Error(\n \"Logger not available in current environment. \" +\n \"This method requires LangGraph Platform environment where a global logger is automatically registered. \" +\n \"If you're developing locally, consider using `console.log` or a local logging library instead.\"\n );\n};\n"],"mappings":";;AAqBA,MAAM,gBAAgB,OAAO,IAAI,2BAA2B;;;;;;;;;;;;;;;;;;;;;;;;AA0B5D,MAAa,kBAA0B;CACrC,MAAM,cAAc;AACpB,KAAI,iBAAiB,YAAa,QAAO,YAAY;AAErD,OAAM,IAAI,MACR,qPAGD"}
@@ -28,7 +28,7 @@ const getLogger = () => {
28
28
  if (GLOBAL_LOGGER in maybeGlobal) return maybeGlobal[GLOBAL_LOGGER];
29
29
  throw new Error("Logger not available in current environment. This method requires LangGraph Platform environment where a global logger is automatically registered. If you're developing locally, consider using `console.log` or a local logging library instead.");
30
30
  };
31
-
32
31
  //#endregion
33
32
  export { getLogger };
33
+
34
34
  //# sourceMappingURL=index.js.map
@@ -1,12 +1,47 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_subagents = require('../ui/subagents.cjs');
3
- const require_stream_custom = require('./stream.custom.cjs');
4
- const require_stream = require('./stream.cjs');
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ require("../_virtual/_rolldown/runtime.cjs");
3
+ const require_messages = require("../ui/messages.cjs");
4
+ let _langchain_react = require("@langchain/react");
5
+ //#region src/react/index.ts
6
+ function useStream(...args) {
7
+ const options = args[0];
8
+ return (0, _langchain_react.useStream)({
9
+ ...options,
10
+ toMessage: require_messages.toMessageDict
11
+ });
12
+ }
13
+ //#endregion
14
+ exports.FetchStreamTransport = _langchain_react.FetchStreamTransport;
15
+ Object.defineProperty(exports, "SubagentManager", {
16
+ enumerable: true,
17
+ get: function() {
18
+ return _langchain_react.SubagentManager;
19
+ }
20
+ });
21
+ Object.defineProperty(exports, "calculateDepthFromNamespace", {
22
+ enumerable: true,
23
+ get: function() {
24
+ return _langchain_react.calculateDepthFromNamespace;
25
+ }
26
+ });
27
+ Object.defineProperty(exports, "extractParentIdFromNamespace", {
28
+ enumerable: true,
29
+ get: function() {
30
+ return _langchain_react.extractParentIdFromNamespace;
31
+ }
32
+ });
33
+ Object.defineProperty(exports, "extractToolCallIdFromNamespace", {
34
+ enumerable: true,
35
+ get: function() {
36
+ return _langchain_react.extractToolCallIdFromNamespace;
37
+ }
38
+ });
39
+ Object.defineProperty(exports, "isSubagentNamespace", {
40
+ enumerable: true,
41
+ get: function() {
42
+ return _langchain_react.isSubagentNamespace;
43
+ }
44
+ });
45
+ exports.useStream = useStream;
5
46
 
6
- exports.FetchStreamTransport = require_stream_custom.FetchStreamTransport;
7
- exports.SubagentManager = require_subagents.SubagentManager;
8
- exports.calculateDepthFromNamespace = require_subagents.calculateDepthFromNamespace;
9
- exports.extractParentIdFromNamespace = require_subagents.extractParentIdFromNamespace;
10
- exports.extractToolCallIdFromNamespace = require_subagents.extractToolCallIdFromNamespace;
11
- exports.isSubagentNamespace = require_subagents.isSubagentNamespace;
12
- exports.useStream = require_stream.useStream;
47
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","names":["toMessageDict"],"sources":["../../src/react/index.ts"],"sourcesContent":["import {\n useStream as _useStream,\n FetchStreamTransport,\n} from \"@langchain/react\";\nimport type { BagTemplate } from \"@langchain/langgraph-sdk\";\nimport type {\n ResolveStreamInterface,\n ResolveStreamOptions,\n UseStreamCustomOptions,\n InferBag,\n InferStateType,\n} from \"@langchain/langgraph-sdk/ui\";\nimport { toMessageDict } from \"../ui/messages.js\";\n\nexport { FetchStreamTransport };\n\n/**\n * Re-export of useStream that forces plain Message[] output\n * for backward compatibility with @langchain/langgraph-sdk/react users.\n */\nexport function useStream<\n T = Record<string, unknown>,\n Bag extends BagTemplate = BagTemplate\n>(\n options: ResolveStreamOptions<T, InferBag<T, Bag>>\n): ResolveStreamInterface<T, InferBag<T, Bag>>;\n\nexport function useStream<\n T = Record<string, unknown>,\n Bag extends BagTemplate = BagTemplate\n>(\n options: UseStreamCustomOptions<InferStateType<T>, InferBag<T, Bag>>\n): ResolveStreamInterface<T, InferBag<T, Bag>>;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function useStream(...args: any[]): any {\n const options = args[0];\n return _useStream({\n ...options,\n toMessage: toMessageDict,\n });\n}\n\nexport type {\n UseStream,\n UseStreamCustom,\n SubagentStream,\n SubagentStreamInterface,\n} from \"@langchain/react\";\nexport type {\n BaseStream,\n UseAgentStream,\n UseAgentStreamOptions,\n UseDeepAgentStream,\n UseDeepAgentStreamOptions,\n ResolveStreamInterface,\n ResolveStreamOptions,\n InferStateType,\n InferToolCalls,\n InferSubagentStates,\n InferNodeNames,\n InferBag,\n} from \"@langchain/react\";\nexport type {\n MessageMetadata,\n UseStreamOptions,\n UseStreamCustomOptions,\n UseStreamTransport,\n UseStreamThread,\n GetToolCallsType,\n AgentTypeConfigLike,\n IsAgentLike,\n ExtractAgentConfig,\n InferAgentToolCalls,\n SubagentToolCall,\n SubagentStatus,\n SubAgentLike,\n CompiledSubAgentLike,\n DeepAgentTypeConfigLike,\n IsDeepAgentLike,\n ExtractDeepAgentConfig,\n ExtractSubAgentMiddleware,\n InferDeepAgentSubagents,\n InferSubagentByName,\n InferSubagentState,\n InferSubagentNames,\n SubagentStateMap,\n DefaultSubagentStates,\n BaseSubagentState,\n} from \"@langchain/react\";\nexport type {\n ToolCallWithResult,\n ToolCallState,\n DefaultToolCall,\n ToolCallFromTool,\n ToolCallsFromTools,\n} from \"@langchain/langgraph-sdk\";\nexport {\n SubagentManager,\n extractToolCallIdFromNamespace,\n calculateDepthFromNamespace,\n extractParentIdFromNamespace,\n isSubagentNamespace,\n} from \"@langchain/react\";\n"],"mappings":";;;;;AAmCA,SAAgB,UAAU,GAAG,MAAkB;CAC7C,MAAM,UAAU,KAAK;AACrB,SAAA,GAAA,iBAAA,WAAkB;EAChB,GAAG;EACH,WAAWA,iBAAAA;EACZ,CAAC"}
@@ -1,11 +1,14 @@
1
- import { DefaultToolCall, ToolCallFromTool, ToolCallState, ToolCallWithResult, ToolCallsFromTools } from "../types.messages.cjs";
2
- import { AgentTypeConfigLike, BaseSubagentState, CompiledSubAgentLike, DeepAgentTypeConfigLike, DefaultSubagentStates, ExtractAgentConfig, ExtractDeepAgentConfig, ExtractSubAgentMiddleware, GetToolCallsType, InferAgentToolCalls, InferDeepAgentSubagents, InferSubagentByName, InferSubagentNames, InferSubagentState, IsAgentLike, IsDeepAgentLike, MessageMetadata, SubAgentLike, SubagentStateMap, SubagentStatus, SubagentStream, SubagentStreamInterface, SubagentToolCall, UseStreamCustomOptions, UseStreamOptions, UseStreamThread, UseStreamTransport } from "../ui/types.cjs";
3
- import { BaseStream } from "../ui/stream/base.cjs";
4
- import { UseAgentStream, UseAgentStreamOptions } from "../ui/stream/agent.cjs";
5
- import { UseDeepAgentStream, UseDeepAgentStreamOptions } from "../ui/stream/deep-agent.cjs";
6
- import { InferBag, InferNodeNames, InferStateType, InferSubagentStates, InferToolCalls, ResolveStreamInterface, ResolveStreamOptions } from "../ui/stream/index.cjs";
7
- import { UseStream, UseStreamCustom } from "./types.cjs";
8
- import { useStream } from "./stream.cjs";
9
- import { FetchStreamTransport } from "./stream.custom.cjs";
10
- import { SubagentManager, calculateDepthFromNamespace, extractParentIdFromNamespace, extractToolCallIdFromNamespace, isSubagentNamespace } from "../ui/subagents.cjs";
11
- export { type AgentTypeConfigLike, type BaseStream, type BaseSubagentState, type CompiledSubAgentLike, type DeepAgentTypeConfigLike, type DefaultSubagentStates, type DefaultToolCall, type ExtractAgentConfig, type ExtractDeepAgentConfig, type ExtractSubAgentMiddleware, FetchStreamTransport, type GetToolCallsType, type InferAgentToolCalls, type InferBag, type InferDeepAgentSubagents, type InferNodeNames, type InferStateType, type InferSubagentByName, type InferSubagentNames, type InferSubagentState, type InferSubagentStates, type InferToolCalls, type IsAgentLike, type IsDeepAgentLike, type MessageMetadata, type ResolveStreamInterface, type ResolveStreamOptions, type SubAgentLike, SubagentManager, type SubagentStateMap, type SubagentStatus, type SubagentStream, type SubagentStreamInterface, type SubagentToolCall, type ToolCallFromTool, type ToolCallState, type ToolCallWithResult, type ToolCallsFromTools, type UseAgentStream, type UseAgentStreamOptions, type UseDeepAgentStream, type UseDeepAgentStreamOptions, type UseStream, type UseStreamCustom, type UseStreamCustomOptions, type UseStreamOptions, type UseStreamThread, type UseStreamTransport, calculateDepthFromNamespace, extractParentIdFromNamespace, extractToolCallIdFromNamespace, isSubagentNamespace, useStream };
1
+ import { AgentTypeConfigLike, BaseStream, BaseSubagentState, CompiledSubAgentLike, DeepAgentTypeConfigLike, DefaultSubagentStates, ExtractAgentConfig, ExtractDeepAgentConfig, ExtractSubAgentMiddleware, FetchStreamTransport, GetToolCallsType, InferAgentToolCalls, InferBag, InferDeepAgentSubagents, InferNodeNames, InferStateType, InferSubagentByName, InferSubagentNames, InferSubagentState, InferSubagentStates, InferToolCalls, IsAgentLike, IsDeepAgentLike, MessageMetadata, ResolveStreamInterface, ResolveStreamOptions, SubAgentLike, SubagentManager, SubagentStateMap, SubagentStatus, SubagentStream, SubagentStreamInterface, SubagentToolCall, UseAgentStream, UseAgentStreamOptions, UseDeepAgentStream, UseDeepAgentStreamOptions, UseStream, UseStreamCustom, UseStreamCustomOptions, UseStreamOptions, UseStreamThread, UseStreamTransport, calculateDepthFromNamespace, extractParentIdFromNamespace, extractToolCallIdFromNamespace, isSubagentNamespace } from "@langchain/react";
2
+ import { BagTemplate, DefaultToolCall, ToolCallFromTool, ToolCallState, ToolCallWithResult, ToolCallsFromTools } from "@langchain/langgraph-sdk";
3
+ import { InferBag as InferBag$1, InferStateType as InferStateType$1, ResolveStreamInterface as ResolveStreamInterface$1, ResolveStreamOptions as ResolveStreamOptions$1, UseStreamCustomOptions as UseStreamCustomOptions$1 } from "@langchain/langgraph-sdk/ui";
4
+
5
+ //#region src/react/index.d.ts
6
+ /**
7
+ * Re-export of useStream that forces plain Message[] output
8
+ * for backward compatibility with @langchain/langgraph-sdk/react users.
9
+ */
10
+ declare function useStream<T = Record<string, unknown>, Bag extends BagTemplate = BagTemplate>(options: ResolveStreamOptions$1<T, InferBag$1<T, Bag>>): ResolveStreamInterface$1<T, InferBag$1<T, Bag>>;
11
+ declare function useStream<T = Record<string, unknown>, Bag extends BagTemplate = BagTemplate>(options: UseStreamCustomOptions$1<InferStateType$1<T>, InferBag$1<T, Bag>>): ResolveStreamInterface$1<T, InferBag$1<T, Bag>>;
12
+ //#endregion
13
+ export { type AgentTypeConfigLike, type BaseStream, type BaseSubagentState, type CompiledSubAgentLike, type DeepAgentTypeConfigLike, type DefaultSubagentStates, type DefaultToolCall, type ExtractAgentConfig, type ExtractDeepAgentConfig, type ExtractSubAgentMiddleware, FetchStreamTransport, type GetToolCallsType, type InferAgentToolCalls, type InferBag, type InferDeepAgentSubagents, type InferNodeNames, type InferStateType, type InferSubagentByName, type InferSubagentNames, type InferSubagentState, type InferSubagentStates, type InferToolCalls, type IsAgentLike, type IsDeepAgentLike, type MessageMetadata, type ResolveStreamInterface, type ResolveStreamOptions, type SubAgentLike, SubagentManager, type SubagentStateMap, type SubagentStatus, type SubagentStream, type SubagentStreamInterface, type SubagentToolCall, type ToolCallFromTool, type ToolCallState, type ToolCallWithResult, type ToolCallsFromTools, type UseAgentStream, type UseAgentStreamOptions, type UseDeepAgentStream, type UseDeepAgentStreamOptions, type UseStream, type UseStreamCustom, type UseStreamCustomOptions, type UseStreamOptions, type UseStreamThread, type UseStreamTransport, calculateDepthFromNamespace, extractParentIdFromNamespace, extractToolCallIdFromNamespace, isSubagentNamespace, useStream };
14
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../../src/react/index.ts"],"mappings":";;;;;;AAoBA;;;iBAAgB,SAAA,KACV,MAAA,+BACQ,WAAA,GAAc,WAAA,CAAA,CAE1B,OAAA,EAAS,sBAAA,CAAqB,CAAA,EAAG,UAAA,CAAS,CAAA,EAAG,GAAA,KAC5C,wBAAA,CAAuB,CAAA,EAAG,UAAA,CAAS,CAAA,EAAG,GAAA;AAAA,iBAEzB,SAAA,KACV,MAAA,+BACQ,WAAA,GAAc,WAAA,CAAA,CAE1B,OAAA,EAAS,wBAAA,CAAuB,gBAAA,CAAe,CAAA,GAAI,UAAA,CAAS,CAAA,EAAG,GAAA,KAC9D,wBAAA,CAAuB,CAAA,EAAG,UAAA,CAAS,CAAA,EAAG,GAAA"}
@@ -1,11 +1,14 @@
1
- import { DefaultToolCall, ToolCallFromTool, ToolCallState, ToolCallWithResult, ToolCallsFromTools } from "../types.messages.js";
2
- import { AgentTypeConfigLike, BaseSubagentState, CompiledSubAgentLike, DeepAgentTypeConfigLike, DefaultSubagentStates, ExtractAgentConfig, ExtractDeepAgentConfig, ExtractSubAgentMiddleware, GetToolCallsType, InferAgentToolCalls, InferDeepAgentSubagents, InferSubagentByName, InferSubagentNames, InferSubagentState, IsAgentLike, IsDeepAgentLike, MessageMetadata, SubAgentLike, SubagentStateMap, SubagentStatus, SubagentStream, SubagentStreamInterface, SubagentToolCall, UseStreamCustomOptions, UseStreamOptions, UseStreamThread, UseStreamTransport } from "../ui/types.js";
3
- import { BaseStream } from "../ui/stream/base.js";
4
- import { UseAgentStream, UseAgentStreamOptions } from "../ui/stream/agent.js";
5
- import { UseDeepAgentStream, UseDeepAgentStreamOptions } from "../ui/stream/deep-agent.js";
6
- import { InferBag, InferNodeNames, InferStateType, InferSubagentStates, InferToolCalls, ResolveStreamInterface, ResolveStreamOptions } from "../ui/stream/index.js";
7
- import { UseStream, UseStreamCustom } from "./types.js";
8
- import { useStream } from "./stream.js";
9
- import { FetchStreamTransport } from "./stream.custom.js";
10
- import { SubagentManager, calculateDepthFromNamespace, extractParentIdFromNamespace, extractToolCallIdFromNamespace, isSubagentNamespace } from "../ui/subagents.js";
11
- export { type AgentTypeConfigLike, type BaseStream, type BaseSubagentState, type CompiledSubAgentLike, type DeepAgentTypeConfigLike, type DefaultSubagentStates, type DefaultToolCall, type ExtractAgentConfig, type ExtractDeepAgentConfig, type ExtractSubAgentMiddleware, FetchStreamTransport, type GetToolCallsType, type InferAgentToolCalls, type InferBag, type InferDeepAgentSubagents, type InferNodeNames, type InferStateType, type InferSubagentByName, type InferSubagentNames, type InferSubagentState, type InferSubagentStates, type InferToolCalls, type IsAgentLike, type IsDeepAgentLike, type MessageMetadata, type ResolveStreamInterface, type ResolveStreamOptions, type SubAgentLike, SubagentManager, type SubagentStateMap, type SubagentStatus, type SubagentStream, type SubagentStreamInterface, type SubagentToolCall, type ToolCallFromTool, type ToolCallState, type ToolCallWithResult, type ToolCallsFromTools, type UseAgentStream, type UseAgentStreamOptions, type UseDeepAgentStream, type UseDeepAgentStreamOptions, type UseStream, type UseStreamCustom, type UseStreamCustomOptions, type UseStreamOptions, type UseStreamThread, type UseStreamTransport, calculateDepthFromNamespace, extractParentIdFromNamespace, extractToolCallIdFromNamespace, isSubagentNamespace, useStream };
1
+ import { AgentTypeConfigLike, BaseStream, BaseSubagentState, CompiledSubAgentLike, DeepAgentTypeConfigLike, DefaultSubagentStates, ExtractAgentConfig, ExtractDeepAgentConfig, ExtractSubAgentMiddleware, FetchStreamTransport, GetToolCallsType, InferAgentToolCalls, InferBag, InferDeepAgentSubagents, InferNodeNames, InferStateType, InferSubagentByName, InferSubagentNames, InferSubagentState, InferSubagentStates, InferToolCalls, IsAgentLike, IsDeepAgentLike, MessageMetadata, ResolveStreamInterface, ResolveStreamOptions, SubAgentLike, SubagentManager, SubagentStateMap, SubagentStatus, SubagentStream, SubagentStreamInterface, SubagentToolCall, UseAgentStream, UseAgentStreamOptions, UseDeepAgentStream, UseDeepAgentStreamOptions, UseStream, UseStreamCustom, UseStreamCustomOptions, UseStreamOptions, UseStreamThread, UseStreamTransport, calculateDepthFromNamespace, extractParentIdFromNamespace, extractToolCallIdFromNamespace, isSubagentNamespace } from "@langchain/react";
2
+ import { BagTemplate, DefaultToolCall, ToolCallFromTool, ToolCallState, ToolCallWithResult, ToolCallsFromTools } from "@langchain/langgraph-sdk";
3
+ import { InferBag as InferBag$1, InferStateType as InferStateType$1, ResolveStreamInterface as ResolveStreamInterface$1, ResolveStreamOptions as ResolveStreamOptions$1, UseStreamCustomOptions as UseStreamCustomOptions$1 } from "@langchain/langgraph-sdk/ui";
4
+
5
+ //#region src/react/index.d.ts
6
+ /**
7
+ * Re-export of useStream that forces plain Message[] output
8
+ * for backward compatibility with @langchain/langgraph-sdk/react users.
9
+ */
10
+ declare function useStream<T = Record<string, unknown>, Bag extends BagTemplate = BagTemplate>(options: ResolveStreamOptions$1<T, InferBag$1<T, Bag>>): ResolveStreamInterface$1<T, InferBag$1<T, Bag>>;
11
+ declare function useStream<T = Record<string, unknown>, Bag extends BagTemplate = BagTemplate>(options: UseStreamCustomOptions$1<InferStateType$1<T>, InferBag$1<T, Bag>>): ResolveStreamInterface$1<T, InferBag$1<T, Bag>>;
12
+ //#endregion
13
+ export { type AgentTypeConfigLike, type BaseStream, type BaseSubagentState, type CompiledSubAgentLike, type DeepAgentTypeConfigLike, type DefaultSubagentStates, type DefaultToolCall, type ExtractAgentConfig, type ExtractDeepAgentConfig, type ExtractSubAgentMiddleware, FetchStreamTransport, type GetToolCallsType, type InferAgentToolCalls, type InferBag, type InferDeepAgentSubagents, type InferNodeNames, type InferStateType, type InferSubagentByName, type InferSubagentNames, type InferSubagentState, type InferSubagentStates, type InferToolCalls, type IsAgentLike, type IsDeepAgentLike, type MessageMetadata, type ResolveStreamInterface, type ResolveStreamOptions, type SubAgentLike, SubagentManager, type SubagentStateMap, type SubagentStatus, type SubagentStream, type SubagentStreamInterface, type SubagentToolCall, type ToolCallFromTool, type ToolCallState, type ToolCallWithResult, type ToolCallsFromTools, type UseAgentStream, type UseAgentStreamOptions, type UseDeepAgentStream, type UseDeepAgentStreamOptions, type UseStream, type UseStreamCustom, type UseStreamCustomOptions, type UseStreamOptions, type UseStreamThread, type UseStreamTransport, calculateDepthFromNamespace, extractParentIdFromNamespace, extractToolCallIdFromNamespace, isSubagentNamespace, useStream };
14
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../src/react/index.ts"],"mappings":";;;;;;AAoBA;;;iBAAgB,SAAA,KACV,MAAA,+BACQ,WAAA,GAAc,WAAA,CAAA,CAE1B,OAAA,EAAS,sBAAA,CAAqB,CAAA,EAAG,UAAA,CAAS,CAAA,EAAG,GAAA,KAC5C,wBAAA,CAAuB,CAAA,EAAG,UAAA,CAAS,CAAA,EAAG,GAAA;AAAA,iBAEzB,SAAA,KACV,MAAA,+BACQ,WAAA,GAAc,WAAA,CAAA,CAE1B,OAAA,EAAS,wBAAA,CAAuB,gBAAA,CAAe,CAAA,GAAI,UAAA,CAAS,CAAA,EAAG,GAAA,KAC9D,wBAAA,CAAuB,CAAA,EAAG,UAAA,CAAS,CAAA,EAAG,GAAA"}
@@ -1,5 +1,14 @@
1
- import { SubagentManager, calculateDepthFromNamespace, extractParentIdFromNamespace, extractToolCallIdFromNamespace, isSubagentNamespace } from "../ui/subagents.js";
2
- import { FetchStreamTransport } from "./stream.custom.js";
3
- import { useStream } from "./stream.js";
1
+ import { toMessageDict } from "../ui/messages.js";
2
+ import { FetchStreamTransport, SubagentManager, calculateDepthFromNamespace, extractParentIdFromNamespace, extractToolCallIdFromNamespace, isSubagentNamespace, useStream as useStream$1 } from "@langchain/react";
3
+ //#region src/react/index.ts
4
+ function useStream(...args) {
5
+ const options = args[0];
6
+ return useStream$1({
7
+ ...options,
8
+ toMessage: toMessageDict
9
+ });
10
+ }
11
+ //#endregion
12
+ export { FetchStreamTransport, SubagentManager, calculateDepthFromNamespace, extractParentIdFromNamespace, extractToolCallIdFromNamespace, isSubagentNamespace, useStream };
4
13
 
5
- export { FetchStreamTransport, SubagentManager, calculateDepthFromNamespace, extractParentIdFromNamespace, extractToolCallIdFromNamespace, isSubagentNamespace, useStream };
14
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["_useStream"],"sources":["../../src/react/index.ts"],"sourcesContent":["import {\n useStream as _useStream,\n FetchStreamTransport,\n} from \"@langchain/react\";\nimport type { BagTemplate } from \"@langchain/langgraph-sdk\";\nimport type {\n ResolveStreamInterface,\n ResolveStreamOptions,\n UseStreamCustomOptions,\n InferBag,\n InferStateType,\n} from \"@langchain/langgraph-sdk/ui\";\nimport { toMessageDict } from \"../ui/messages.js\";\n\nexport { FetchStreamTransport };\n\n/**\n * Re-export of useStream that forces plain Message[] output\n * for backward compatibility with @langchain/langgraph-sdk/react users.\n */\nexport function useStream<\n T = Record<string, unknown>,\n Bag extends BagTemplate = BagTemplate\n>(\n options: ResolveStreamOptions<T, InferBag<T, Bag>>\n): ResolveStreamInterface<T, InferBag<T, Bag>>;\n\nexport function useStream<\n T = Record<string, unknown>,\n Bag extends BagTemplate = BagTemplate\n>(\n options: UseStreamCustomOptions<InferStateType<T>, InferBag<T, Bag>>\n): ResolveStreamInterface<T, InferBag<T, Bag>>;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function useStream(...args: any[]): any {\n const options = args[0];\n return _useStream({\n ...options,\n toMessage: toMessageDict,\n });\n}\n\nexport type {\n UseStream,\n UseStreamCustom,\n SubagentStream,\n SubagentStreamInterface,\n} from \"@langchain/react\";\nexport type {\n BaseStream,\n UseAgentStream,\n UseAgentStreamOptions,\n UseDeepAgentStream,\n UseDeepAgentStreamOptions,\n ResolveStreamInterface,\n ResolveStreamOptions,\n InferStateType,\n InferToolCalls,\n InferSubagentStates,\n InferNodeNames,\n InferBag,\n} from \"@langchain/react\";\nexport type {\n MessageMetadata,\n UseStreamOptions,\n UseStreamCustomOptions,\n UseStreamTransport,\n UseStreamThread,\n GetToolCallsType,\n AgentTypeConfigLike,\n IsAgentLike,\n ExtractAgentConfig,\n InferAgentToolCalls,\n SubagentToolCall,\n SubagentStatus,\n SubAgentLike,\n CompiledSubAgentLike,\n DeepAgentTypeConfigLike,\n IsDeepAgentLike,\n ExtractDeepAgentConfig,\n ExtractSubAgentMiddleware,\n InferDeepAgentSubagents,\n InferSubagentByName,\n InferSubagentState,\n InferSubagentNames,\n SubagentStateMap,\n DefaultSubagentStates,\n BaseSubagentState,\n} from \"@langchain/react\";\nexport type {\n ToolCallWithResult,\n ToolCallState,\n DefaultToolCall,\n ToolCallFromTool,\n ToolCallsFromTools,\n} from \"@langchain/langgraph-sdk\";\nexport {\n SubagentManager,\n extractToolCallIdFromNamespace,\n calculateDepthFromNamespace,\n extractParentIdFromNamespace,\n isSubagentNamespace,\n} from \"@langchain/react\";\n"],"mappings":";;;AAmCA,SAAgB,UAAU,GAAG,MAAkB;CAC7C,MAAM,UAAU,KAAK;AACrB,QAAOA,YAAW;EAChB,GAAG;EACH,WAAW;EACZ,CAAC"}
@@ -1,15 +1,39 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_client = require('./client.cjs');
3
- const require_types = require('./types.cjs');
4
-
5
- //#region src/react-ui/index.ts
6
- require_client.bootstrapUiContext();
7
-
8
- //#endregion
9
- exports.LoadExternalComponent = require_client.LoadExternalComponent;
10
- exports.experimental_loadShare = require_client.experimental_loadShare;
11
- exports.isRemoveUIMessage = require_types.isRemoveUIMessage;
12
- exports.isUIMessage = require_types.isUIMessage;
13
- exports.uiMessageReducer = require_types.uiMessageReducer;
14
- exports.useStreamContext = require_client.useStreamContext;
15
- //# sourceMappingURL=index.cjs.map
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ require("../_virtual/_rolldown/runtime.cjs");
3
+ let _langchain_react_react_ui = require("@langchain/react/react-ui");
4
+ Object.defineProperty(exports, "LoadExternalComponent", {
5
+ enumerable: true,
6
+ get: function() {
7
+ return _langchain_react_react_ui.LoadExternalComponent;
8
+ }
9
+ });
10
+ Object.defineProperty(exports, "experimental_loadShare", {
11
+ enumerable: true,
12
+ get: function() {
13
+ return _langchain_react_react_ui.experimental_loadShare;
14
+ }
15
+ });
16
+ Object.defineProperty(exports, "isRemoveUIMessage", {
17
+ enumerable: true,
18
+ get: function() {
19
+ return _langchain_react_react_ui.isRemoveUIMessage;
20
+ }
21
+ });
22
+ Object.defineProperty(exports, "isUIMessage", {
23
+ enumerable: true,
24
+ get: function() {
25
+ return _langchain_react_react_ui.isUIMessage;
26
+ }
27
+ });
28
+ Object.defineProperty(exports, "uiMessageReducer", {
29
+ enumerable: true,
30
+ get: function() {
31
+ return _langchain_react_react_ui.uiMessageReducer;
32
+ }
33
+ });
34
+ Object.defineProperty(exports, "useStreamContext", {
35
+ enumerable: true,
36
+ get: function() {
37
+ return _langchain_react_react_ui.useStreamContext;
38
+ }
39
+ });
@@ -1,3 +1,2 @@
1
- import { RemoveUIMessage, UIMessage, isRemoveUIMessage, isUIMessage, uiMessageReducer } from "./types.cjs";
2
- import { LoadExternalComponent, experimental_loadShare, useStreamContext } from "./client.cjs";
1
+ import { LoadExternalComponent, RemoveUIMessage, UIMessage, experimental_loadShare, isRemoveUIMessage, isUIMessage, uiMessageReducer, useStreamContext } from "@langchain/react/react-ui";
3
2
  export { LoadExternalComponent, type RemoveUIMessage, type UIMessage, experimental_loadShare, isRemoveUIMessage, isUIMessage, uiMessageReducer, useStreamContext };
@@ -1,3 +1,2 @@
1
- import { RemoveUIMessage, UIMessage, isRemoveUIMessage, isUIMessage, uiMessageReducer } from "./types.js";
2
- import { LoadExternalComponent, experimental_loadShare, useStreamContext } from "./client.js";
1
+ import { LoadExternalComponent, RemoveUIMessage, UIMessage, experimental_loadShare, isRemoveUIMessage, isUIMessage, uiMessageReducer, useStreamContext } from "@langchain/react/react-ui";
3
2
  export { LoadExternalComponent, type RemoveUIMessage, type UIMessage, experimental_loadShare, isRemoveUIMessage, isUIMessage, uiMessageReducer, useStreamContext };
@@ -1,9 +1,2 @@
1
- import { LoadExternalComponent, bootstrapUiContext, experimental_loadShare, useStreamContext } from "./client.js";
2
- import { isRemoveUIMessage, isUIMessage, uiMessageReducer } from "./types.js";
3
-
4
- //#region src/react-ui/index.ts
5
- bootstrapUiContext();
6
-
7
- //#endregion
1
+ import { LoadExternalComponent, experimental_loadShare, isRemoveUIMessage, isUIMessage, uiMessageReducer, useStreamContext } from "@langchain/react/react-ui";
8
2
  export { LoadExternalComponent, experimental_loadShare, isRemoveUIMessage, isUIMessage, uiMessageReducer, useStreamContext };
9
- //# sourceMappingURL=index.js.map
@@ -1,6 +1,15 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_types = require('../types.cjs');
3
- const require_server = require('./server.cjs');
4
-
5
- exports.typedUi = require_server.typedUi;
6
- exports.uiMessageReducer = require_types.uiMessageReducer;
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ require("../../_virtual/_rolldown/runtime.cjs");
3
+ let _langchain_react_react_ui_server = require("@langchain/react/react-ui/server");
4
+ Object.defineProperty(exports, "typedUi", {
5
+ enumerable: true,
6
+ get: function() {
7
+ return _langchain_react_react_ui_server.typedUi;
8
+ }
9
+ });
10
+ Object.defineProperty(exports, "uiMessageReducer", {
11
+ enumerable: true,
12
+ get: function() {
13
+ return _langchain_react_react_ui_server.uiMessageReducer;
14
+ }
15
+ });
@@ -1,3 +1,2 @@
1
- import { RemoveUIMessage, UIMessage, uiMessageReducer } from "../types.cjs";
2
- import { typedUi } from "./server.cjs";
1
+ import { RemoveUIMessage, UIMessage, typedUi, uiMessageReducer } from "@langchain/react/react-ui/server";
3
2
  export { type RemoveUIMessage, type UIMessage, typedUi, uiMessageReducer };
@@ -1,3 +1,2 @@
1
- import { RemoveUIMessage, UIMessage, uiMessageReducer } from "../types.js";
2
- import { typedUi } from "./server.js";
1
+ import { RemoveUIMessage, UIMessage, typedUi, uiMessageReducer } from "@langchain/react/react-ui/server";
3
2
  export { type RemoveUIMessage, type UIMessage, typedUi, uiMessageReducer };
@@ -1,4 +1,2 @@
1
- import { uiMessageReducer } from "../types.js";
2
- import { typedUi } from "./server.js";
3
-
4
- export { typedUi, uiMessageReducer };
1
+ import { typedUi, uiMessageReducer } from "@langchain/react/react-ui/server";
2
+ export { typedUi, uiMessageReducer };
@@ -1,4 +1,3 @@
1
-
2
1
  //#region src/singletons/fetch.ts
3
2
  const DEFAULT_FETCH_IMPLEMENTATION = (...args) => fetch(...args);
4
3
  const LANGSMITH_FETCH_IMPLEMENTATION_KEY = Symbol.for("lg:fetch_implementation");
@@ -17,8 +16,8 @@ const overrideFetchImplementation = (fetch) => {
17
16
  const _getFetchImplementation = () => {
18
17
  return globalThis[LANGSMITH_FETCH_IMPLEMENTATION_KEY] ?? DEFAULT_FETCH_IMPLEMENTATION;
19
18
  };
20
-
21
19
  //#endregion
22
20
  exports._getFetchImplementation = _getFetchImplementation;
23
21
  exports.overrideFetchImplementation = overrideFetchImplementation;
22
+
24
23
  //# sourceMappingURL=fetch.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"fetch.cjs","names":[],"sources":["../../src/singletons/fetch.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n// Wrap the default fetch call due to issues with illegal invocations\n// in some environments:\n// https://stackoverflow.com/questions/69876859/why-does-bind-fix-failed-to-execute-fetch-on-window-illegal-invocation-err\n// @ts-expect-error Broad typing to support a range of fetch implementations\nconst DEFAULT_FETCH_IMPLEMENTATION = (...args: any[]) => fetch(...args);\n\nconst LANGSMITH_FETCH_IMPLEMENTATION_KEY = Symbol.for(\n \"lg:fetch_implementation\"\n);\n\n/**\n * Overrides the fetch implementation used for LangSmith calls.\n * You should use this if you need to use an implementation of fetch\n * other than the default global (e.g. for dealing with proxies).\n * @param fetch The new fetch function to use.\n */\nexport const overrideFetchImplementation = (fetch: (...args: any[]) => any) => {\n (globalThis as any)[LANGSMITH_FETCH_IMPLEMENTATION_KEY] = fetch;\n};\n\n/**\n * @internal\n */\nexport const _getFetchImplementation: () => (...args: any[]) => any = () => {\n return (\n (globalThis as any)[LANGSMITH_FETCH_IMPLEMENTATION_KEY] ??\n DEFAULT_FETCH_IMPLEMENTATION\n );\n};\n"],"mappings":";;AAKA,MAAM,gCAAgC,GAAG,SAAgB,MAAM,GAAG,KAAK;AAEvE,MAAM,qCAAqC,OAAO,IAChD,0BACD;;;;;;;AAQD,MAAa,+BAA+B,UAAmC;AAC7E,CAAC,WAAmB,sCAAsC;;;;;AAM5D,MAAa,gCAA+D;AAC1E,QACG,WAAmB,uCACpB"}
1
+ {"version":3,"file":"fetch.cjs","names":[],"sources":["../../src/singletons/fetch.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n// Wrap the default fetch call due to issues with illegal invocations\n// in some environments:\n// https://stackoverflow.com/questions/69876859/why-does-bind-fix-failed-to-execute-fetch-on-window-illegal-invocation-err\n// @ts-expect-error Broad typing to support a range of fetch implementations\nconst DEFAULT_FETCH_IMPLEMENTATION = (...args: any[]) => fetch(...args);\n\nconst LANGSMITH_FETCH_IMPLEMENTATION_KEY = Symbol.for(\n \"lg:fetch_implementation\"\n);\n\n/**\n * Overrides the fetch implementation used for LangSmith calls.\n * You should use this if you need to use an implementation of fetch\n * other than the default global (e.g. for dealing with proxies).\n * @param fetch The new fetch function to use.\n */\nexport const overrideFetchImplementation = (fetch: (...args: any[]) => any) => {\n (globalThis as any)[LANGSMITH_FETCH_IMPLEMENTATION_KEY] = fetch;\n};\n\n/**\n * @internal\n */\nexport const _getFetchImplementation: () => (...args: any[]) => any = () => {\n return (\n (globalThis as any)[LANGSMITH_FETCH_IMPLEMENTATION_KEY] ??\n DEFAULT_FETCH_IMPLEMENTATION\n );\n};\n"],"mappings":";AAKA,MAAM,gCAAgC,GAAG,SAAgB,MAAM,GAAG,KAAK;AAEvE,MAAM,qCAAqC,OAAO,IAChD,0BACD;;;;;;;AAQD,MAAa,+BAA+B,UAAmC;AAC5E,YAAmB,sCAAsC;;;;;AAM5D,MAAa,gCAA+D;AAC1E,QACG,WAAmB,uCACpB"}
@@ -16,7 +16,7 @@ const overrideFetchImplementation = (fetch) => {
16
16
  const _getFetchImplementation = () => {
17
17
  return globalThis[LANGSMITH_FETCH_IMPLEMENTATION_KEY] ?? DEFAULT_FETCH_IMPLEMENTATION;
18
18
  };
19
-
20
19
  //#endregion
21
20
  export { _getFetchImplementation, overrideFetchImplementation };
21
+
22
22
  //# sourceMappingURL=fetch.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"fetch.js","names":[],"sources":["../../src/singletons/fetch.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n// Wrap the default fetch call due to issues with illegal invocations\n// in some environments:\n// https://stackoverflow.com/questions/69876859/why-does-bind-fix-failed-to-execute-fetch-on-window-illegal-invocation-err\n// @ts-expect-error Broad typing to support a range of fetch implementations\nconst DEFAULT_FETCH_IMPLEMENTATION = (...args: any[]) => fetch(...args);\n\nconst LANGSMITH_FETCH_IMPLEMENTATION_KEY = Symbol.for(\n \"lg:fetch_implementation\"\n);\n\n/**\n * Overrides the fetch implementation used for LangSmith calls.\n * You should use this if you need to use an implementation of fetch\n * other than the default global (e.g. for dealing with proxies).\n * @param fetch The new fetch function to use.\n */\nexport const overrideFetchImplementation = (fetch: (...args: any[]) => any) => {\n (globalThis as any)[LANGSMITH_FETCH_IMPLEMENTATION_KEY] = fetch;\n};\n\n/**\n * @internal\n */\nexport const _getFetchImplementation: () => (...args: any[]) => any = () => {\n return (\n (globalThis as any)[LANGSMITH_FETCH_IMPLEMENTATION_KEY] ??\n DEFAULT_FETCH_IMPLEMENTATION\n );\n};\n"],"mappings":";AAKA,MAAM,gCAAgC,GAAG,SAAgB,MAAM,GAAG,KAAK;AAEvE,MAAM,qCAAqC,OAAO,IAChD,0BACD;;;;;;;AAQD,MAAa,+BAA+B,UAAmC;AAC7E,CAAC,WAAmB,sCAAsC;;;;;AAM5D,MAAa,gCAA+D;AAC1E,QACG,WAAmB,uCACpB"}
1
+ {"version":3,"file":"fetch.js","names":[],"sources":["../../src/singletons/fetch.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n// Wrap the default fetch call due to issues with illegal invocations\n// in some environments:\n// https://stackoverflow.com/questions/69876859/why-does-bind-fix-failed-to-execute-fetch-on-window-illegal-invocation-err\n// @ts-expect-error Broad typing to support a range of fetch implementations\nconst DEFAULT_FETCH_IMPLEMENTATION = (...args: any[]) => fetch(...args);\n\nconst LANGSMITH_FETCH_IMPLEMENTATION_KEY = Symbol.for(\n \"lg:fetch_implementation\"\n);\n\n/**\n * Overrides the fetch implementation used for LangSmith calls.\n * You should use this if you need to use an implementation of fetch\n * other than the default global (e.g. for dealing with proxies).\n * @param fetch The new fetch function to use.\n */\nexport const overrideFetchImplementation = (fetch: (...args: any[]) => any) => {\n (globalThis as any)[LANGSMITH_FETCH_IMPLEMENTATION_KEY] = fetch;\n};\n\n/**\n * @internal\n */\nexport const _getFetchImplementation: () => (...args: any[]) => any = () => {\n return (\n (globalThis as any)[LANGSMITH_FETCH_IMPLEMENTATION_KEY] ??\n DEFAULT_FETCH_IMPLEMENTATION\n );\n};\n"],"mappings":";AAKA,MAAM,gCAAgC,GAAG,SAAgB,MAAM,GAAG,KAAK;AAEvE,MAAM,qCAAqC,OAAO,IAChD,0BACD;;;;;;;AAQD,MAAa,+BAA+B,UAAmC;AAC5E,YAAmB,sCAAsC;;;;;AAM5D,MAAa,gCAA+D;AAC1E,QACG,WAAmB,uCACpB"}
@@ -226,8 +226,10 @@ type ToolCallState = "pending" | "completed" | "error";
226
226
  * Useful for rendering tool invocations and their outputs together.
227
227
  *
228
228
  * @template ToolCall The type of the tool call.
229
+ * @template TToolMessage The type of the tool result message. Defaults to the SDK's plain ToolMessage interface.
230
+ * @template TAIMessage The type of the AI message. Defaults to the SDK's plain AIMessage interface.
229
231
  */
230
- type ToolCallWithResult<ToolCall = DefaultToolCall> = {
232
+ type ToolCallWithResult<ToolCall = DefaultToolCall, TToolMessage = ToolMessage, TAIMessage = AIMessage<ToolCall>> = {
231
233
  /**
232
234
  * Unique identifier for this tool call.
233
235
  * Uses the tool call's id if available, otherwise generates one from aiMessage.id and index.
@@ -241,11 +243,11 @@ type ToolCallWithResult<ToolCall = DefaultToolCall> = {
241
243
  * The result message from tool execution.
242
244
  * `undefined` if the tool is still being executed or no result was received.
243
245
  */
244
- result: ToolMessage | undefined;
246
+ result: TToolMessage | undefined;
245
247
  /**
246
248
  * The AI message that initiated this tool call.
247
249
  */
248
- aiMessage: AIMessage<ToolCall>;
250
+ aiMessage: TAIMessage;
249
251
  /**
250
252
  * Index of this tool call within the AI message's tool_calls array.
251
253
  */
@@ -1 +1 @@
1
- {"version":3,"file":"types.messages.d.cts","names":[],"sources":["../src/types.messages.ts"],"mappings":";KAAK,WAAA;AAAA,KACA,sBAAA;EACH,IAAA;EACA,SAAA;IAAsB,GAAA;IAAa,MAAA,GAAS,WAAA;EAAA;AAAA;AAAA,KAGzC,kBAAA;EAAuB,IAAA;EAAc,IAAA;AAAA;AAAA,KACrC,qBAAA,GAA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BAAA,CAAiB,CAAA;;;;;;;;;;;;;;;;;;;;;;;AA3BH;KAsDN,gBAAA,MAAsB,CAAA;EAAY,IAAA;AAAA,IAC1C,cAAA,CAAe,CAAA,uBACb,IAAA,yBAGA,IAAA,SAAa,MAAA;EACT,IAAA,EAAM,CAAA;EAAG,IAAA,EAAM,IAAA;EAAM,EAAA;EAAa,IAAA;AAAA;;;;;;;;AA/CpC;;;;;;;;;;;;;;;;;;;;;;KAiFI,kBAAA,iCACV,CAAA,iDACI,gBAAA,CAAiB,KAAA,IAAS,kBAAA,CAAmB,IAAA;AA1CnD;;;;;;;AAAA,KAoDY,aAAA;;;;;;;;;KAUA,kBAAA,YACC,eAAA,iBACI,WAAA,eACF,SAAA,CAAU,QAAA;EAhEW;;;;EAsElC,EAAA;EAjEc;;;EAsEd,IAAA,EAAM,QAAA;EAtEoC;;;AAkC5C;EA0CE,MAAA,EAAQ,YAAA;EA1CoB;;;EA+C5B,SAAA,EAAW,UAAA;EA7CsC;;;EAkDjD,KAAA;EApD6B;;;;;;;EA6D7B,KAAA,EAAO,aAAA;AAAA"}
@@ -226,8 +226,10 @@ type ToolCallState = "pending" | "completed" | "error";
226
226
  * Useful for rendering tool invocations and their outputs together.
227
227
  *
228
228
  * @template ToolCall The type of the tool call.
229
+ * @template TToolMessage The type of the tool result message. Defaults to the SDK's plain ToolMessage interface.
230
+ * @template TAIMessage The type of the AI message. Defaults to the SDK's plain AIMessage interface.
229
231
  */
230
- type ToolCallWithResult<ToolCall = DefaultToolCall> = {
232
+ type ToolCallWithResult<ToolCall = DefaultToolCall, TToolMessage = ToolMessage, TAIMessage = AIMessage<ToolCall>> = {
231
233
  /**
232
234
  * Unique identifier for this tool call.
233
235
  * Uses the tool call's id if available, otherwise generates one from aiMessage.id and index.
@@ -241,11 +243,11 @@ type ToolCallWithResult<ToolCall = DefaultToolCall> = {
241
243
  * The result message from tool execution.
242
244
  * `undefined` if the tool is still being executed or no result was received.
243
245
  */
244
- result: ToolMessage | undefined;
246
+ result: TToolMessage | undefined;
245
247
  /**
246
248
  * The AI message that initiated this tool call.
247
249
  */
248
- aiMessage: AIMessage<ToolCall>;
250
+ aiMessage: TAIMessage;
249
251
  /**
250
252
  * Index of this tool call within the AI message's tool_calls array.
251
253
  */
@@ -1 +1 @@
1
- {"version":3,"file":"types.messages.d.ts","names":[],"sources":["../src/types.messages.ts"],"mappings":";KAAK,WAAA;AAAA,KACA,sBAAA;EACH,IAAA;EACA,SAAA;IAAsB,GAAA;IAAa,MAAA,GAAS,WAAA;EAAA;AAAA;AAAA,KAGzC,kBAAA;EAAuB,IAAA;EAAc,IAAA;AAAA;AAAA,KACrC,qBAAA,GAAwB,kBAAA,GAAqB,sBAAA;AAAA,KAC7C,cAAA,YAA0B,qBAAA;;;;KAK1B,uBAAA,GAA0B,MAAA;AAAA,KAE1B,WAAA;EACH,iBAAA,GAAoB,uBAAA;EACpB,OAAA,EAAS,cAAA;EACT,EAAA;EACA,IAAA;EACA,iBAAA,GAAoB,MAAA;AAAA;AAAA,KAGV,YAAA,GAAe,WAAA;EACzB,IAAA;EACA,OAAA;AAAA;;;;KAMU,eAAA;EACV,IAAA;EAEA,IAAA;IAAA,CAAS,CAAA;EAAA;EACT,EAAA;EACA,IAAA;AAAA;;;;KAMU,eAAA;EACV,IAAA;EACA,IAAA;EACA,EAAA;EACA,KAAA;EACA,IAAA;AAAA;;;;KAMU,aAAA;EACV,YAAA;EACA,aAAA;EACA,YAAA;EACA,mBAAA;IAEM,KAAA;IACA,UAAA;IACA,cAAA;EAAA;EAGN,oBAAA;IACM,KAAA;IAA4B,SAAA;EAAA;AAAA;;;;;;;;;AAvBpC;;;;;;;;;;;AAWA;;;;;;;;KA2CY,SAAA,YAAqB,eAAA,IAAmB,WAAA;EAClD,IAAA;EACA,OAAA;EACA,UAAA,GAAa,QAAA;EACb,kBAAA,GAAqB,eAAA;EACrB,cAAA,GAAiB,aAAA;AAAA;AAAA,KAGP,WAAA,GAAc,WAAA;EACxB,IAAA;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AA,GAAgB,WAAA;EAC1B,IAAA;AAAA;;;AAxBF;;;KAgCY,OAAA,YAAmB,eAAA,IAC3B,YAAA,GACA,SAAA,CAAU,QAAA,IACV,WAAA,GACA,aAAA,GACA,eAAA,GACA,aAAA;;;;;;;;KAUC,gBAAA,MAAsB,CAAA;EAAY,IAAA;IAAQ,KAAA;EAAA;AAAA,IAC3C,IAAA,GACA,CAAA;EAAY,MAAA;AAAA,IACZ,IAAA;;;;AA5BJ;;KAoCK,cAAA,MAAoB,CAAA;EAEvB,KAAA,GAAQ,GAAA,iBAAoB,IAAA;AAAA,IAE1B,IAAA,GACA,CAAA;EAAY,MAAA;AAAA,IACZ,gBAAA,CAAiB,CAAA;;;;;;;;;;;;;;;;;;;;;;;AA3BH;KAsDN,gBAAA,MAAsB,CAAA;EAAY,IAAA;AAAA,IAC1C,cAAA,CAAe,CAAA,uBACb,IAAA,yBAGA,IAAA,SAAa,MAAA;EACT,IAAA,EAAM,CAAA;EAAG,IAAA,EAAM,IAAA;EAAM,EAAA;EAAa,IAAA;AAAA;;;;;;;;AA/CpC;;;;;;;;;;;;;;;;;;;;;;KAiFI,kBAAA,iCACV,CAAA,iDACI,gBAAA,CAAiB,KAAA,IAAS,kBAAA,CAAmB,IAAA;AA1CnD;;;;;;;AAAA,KAoDY,aAAA;;;;;;;;;KAUA,kBAAA,YACC,eAAA,iBACI,WAAA,eACF,SAAA,CAAU,QAAA;EAhEW;;;;EAsElC,EAAA;EAjEc;;;EAsEd,IAAA,EAAM,QAAA;EAtEoC;;;AAkC5C;EA0CE,MAAA,EAAQ,YAAA;EA1CoB;;;EA+C5B,SAAA,EAAW,UAAA;EA7CsC;;;EAkDjD,KAAA;EApD6B;;;;;;;EA6D7B,KAAA,EAAO,aAAA;AAAA"}
@@ -1,4 +1,4 @@
1
-
1
+ const require_utils = require("./utils.cjs");
2
2
  //#region src/ui/branching.ts
3
3
  function getBranchSequence(history) {
4
4
  const nodeIds = /* @__PURE__ */ new Set();
@@ -147,7 +147,30 @@ function getBranchContext(branch, history) {
147
147
  threadHead: flatHistory.at(-1)
148
148
  };
149
149
  }
150
-
150
+ function getMessagesMetadataMap(options) {
151
+ const currentValues = options.branchContext.threadHead?.values ?? options.initialValues ?? {};
152
+ const alreadyShown = /* @__PURE__ */ new Set();
153
+ return options.getMessages(currentValues).map((message, idx) => {
154
+ const messageId = message.id ?? idx;
155
+ const firstSeenState = require_utils.findLast(options.history ?? [], (state) => options.getMessages(state.values).map((m, idx) => m.id ?? idx).includes(messageId));
156
+ const checkpointId = firstSeenState?.checkpoint?.checkpoint_id;
157
+ let branch = checkpointId != null ? options.branchContext.branchByCheckpoint[checkpointId] : void 0;
158
+ if (!branch?.branch?.length) branch = void 0;
159
+ const optionsShown = branch?.branchOptions?.flat(2).join(",");
160
+ if (optionsShown) {
161
+ if (alreadyShown.has(optionsShown)) branch = void 0;
162
+ alreadyShown.add(optionsShown);
163
+ }
164
+ return {
165
+ messageId: messageId.toString(),
166
+ firstSeenState,
167
+ branch: branch?.branch,
168
+ branchOptions: branch?.branchOptions
169
+ };
170
+ });
171
+ }
151
172
  //#endregion
152
173
  exports.getBranchContext = getBranchContext;
174
+ exports.getMessagesMetadataMap = getMessagesMetadataMap;
175
+
153
176
  //# sourceMappingURL=branching.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"branching.cjs","names":[],"sources":["../../src/ui/branching.ts"],"sourcesContent":["import type { ThreadState } from \"../schema.js\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ninterface Node<StateType = any> {\n type: \"node\";\n value: ThreadState<StateType>;\n path: string[];\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ninterface Fork<StateType = any> {\n type: \"fork\";\n items: Array<Sequence<StateType>>;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport interface Sequence<StateType = any> {\n type: \"sequence\";\n items: Array<Node<StateType> | Fork<StateType>>;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ninterface ValidFork<StateType = any> {\n type: \"fork\";\n items: Array<ValidSequence<StateType>>;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ninterface ValidSequence<StateType = any> {\n type: \"sequence\";\n items: [Node<StateType>, ...(Node<StateType> | ValidFork<StateType>)[]];\n}\n\nexport function getBranchSequence<StateType extends Record<string, unknown>>(\n history: ThreadState<StateType>[]\n) {\n const nodeIds = new Set<string>();\n const childrenMap: Record<string, ThreadState<StateType>[]> = {};\n\n // Short circuit if there's only a singular one state\n if (history.length <= 1) {\n return {\n rootSequence: {\n type: \"sequence\",\n items: history.map((value) => ({ type: \"node\", value, path: [] })),\n } satisfies Sequence<StateType>,\n paths: [],\n };\n }\n\n // First pass - collect nodes for each checkpoint\n history.forEach((state) => {\n const checkpointId = state.parent_checkpoint?.checkpoint_id ?? \"$\";\n childrenMap[checkpointId] ??= [];\n childrenMap[checkpointId].push(state);\n\n if (state.checkpoint?.checkpoint_id != null) {\n nodeIds.add(state.checkpoint.checkpoint_id);\n }\n });\n\n // If dealing with partial history, take the branch\n // with the latest checkpoint and mark it as the root.\n const maxId = (...ids: (string | null)[]) =>\n ids\n .filter((i): i is string => i != null)\n .sort((a, b) => a.localeCompare(b))\n .at(-1)!;\n\n const lastOrphanedNode =\n childrenMap.$ == null\n ? Object.keys(childrenMap)\n .filter((parentId) => !nodeIds.has(parentId))\n .map((parentId) => {\n const queue: string[] = [parentId];\n const seen = new Set<string>();\n\n let lastId = parentId;\n\n while (queue.length > 0) {\n const current = queue.shift()!;\n\n if (seen.has(current)) continue;\n seen.add(current);\n\n const children = (childrenMap[current] ?? []).flatMap(\n (i) => i.checkpoint?.checkpoint_id ?? []\n );\n\n lastId = maxId(lastId, ...children);\n queue.push(...children);\n }\n\n return { parentId, lastId };\n })\n .sort((a, b) => a.lastId.localeCompare(b.lastId))\n .at(-1)?.parentId\n : undefined;\n\n if (lastOrphanedNode != null) childrenMap.$ = childrenMap[lastOrphanedNode];\n\n // Second pass - create a tree of sequences\n type Task = { id: string; sequence: Sequence; path: string[] };\n const rootSequence: Sequence = { type: \"sequence\", items: [] };\n const queue: Task[] = [{ id: \"$\", sequence: rootSequence, path: [] }];\n\n const paths: string[][] = [];\n\n const visited = new Set<string>();\n while (queue.length > 0) {\n const task = queue.shift()!;\n if (visited.has(task.id)) continue;\n visited.add(task.id);\n\n const children = childrenMap[task.id];\n if (children == null || children.length === 0) continue;\n\n // If we've encountered a fork (2+ children), push the fork\n // to the sequence and add a new sequence for each child\n let fork: Fork | undefined;\n if (children.length > 1) {\n fork = { type: \"fork\", items: [] };\n task.sequence.items.push(fork);\n }\n\n for (const value of children) {\n const id = value.checkpoint?.checkpoint_id;\n if (id == null) continue;\n\n let { sequence } = task;\n let { path } = task;\n if (fork != null) {\n sequence = { type: \"sequence\", items: [] };\n fork.items.unshift(sequence);\n\n path = path.slice();\n path.push(id);\n paths.push(path);\n }\n\n sequence.items.push({ type: \"node\", value, path });\n queue.push({ id, sequence, path });\n }\n }\n\n return { rootSequence, paths };\n}\n\nconst PATH_SEP = \">\";\nconst ROOT_ID = \"$\";\n\n// Get flat view\nexport function getBranchView<StateType extends Record<string, unknown>>(\n sequence: Sequence<StateType>,\n paths: string[][],\n branch: string\n) {\n const path = branch.split(PATH_SEP);\n const pathMap: Record<string, string[][]> = {};\n\n for (const path of paths) {\n const parent = path.at(-2) ?? ROOT_ID;\n pathMap[parent] ??= [];\n pathMap[parent].unshift(path);\n }\n\n const history: ThreadState<StateType>[] = [];\n const branchByCheckpoint: Record<\n string,\n { branch: string | undefined; branchOptions: string[] | undefined }\n > = {};\n\n const forkStack = path.slice();\n const queue: (Node<StateType> | Fork<StateType>)[] = [...sequence.items];\n\n while (queue.length > 0) {\n const item = queue.shift()!;\n\n if (item.type === \"node\") {\n history.push(item.value);\n const checkpointId = item.value.checkpoint?.checkpoint_id;\n if (checkpointId == null) continue;\n\n branchByCheckpoint[checkpointId] = {\n branch: item.path.join(PATH_SEP),\n branchOptions: (item.path.length > 0\n ? pathMap[item.path.at(-2) ?? ROOT_ID] ?? []\n : []\n ).map((p) => p.join(PATH_SEP)),\n };\n }\n if (item.type === \"fork\") {\n const forkId = forkStack.shift();\n const index =\n forkId != null\n ? item.items.findIndex((value) => {\n const firstItem = value.items.at(0);\n if (!firstItem || firstItem.type !== \"node\") return false;\n return firstItem.value.checkpoint?.checkpoint_id === forkId;\n })\n : -1;\n\n const nextItems = item.items.at(index)?.items ?? [];\n queue.push(...nextItems);\n }\n }\n\n return { history, branchByCheckpoint };\n}\n\nexport function getBranchContext<StateType extends Record<string, unknown>>(\n branch: string,\n history: ThreadState<StateType>[] | undefined\n) {\n const { rootSequence: branchTree, paths } = getBranchSequence(history ?? []);\n const { history: flatHistory, branchByCheckpoint } = getBranchView(\n branchTree,\n paths,\n branch\n );\n\n return {\n branchTree,\n flatHistory,\n branchByCheckpoint,\n threadHead: flatHistory.at(-1),\n };\n}\n"],"mappings":";;AAiCA,SAAgB,kBACd,SACA;CACA,MAAM,0BAAU,IAAI,KAAa;CACjC,MAAM,cAAwD,EAAE;AAGhE,KAAI,QAAQ,UAAU,EACpB,QAAO;EACL,cAAc;GACZ,MAAM;GACN,OAAO,QAAQ,KAAK,WAAW;IAAE,MAAM;IAAQ;IAAO,MAAM,EAAE;IAAE,EAAE;GACnE;EACD,OAAO,EAAE;EACV;AAIH,SAAQ,SAAS,UAAU;EACzB,MAAM,eAAe,MAAM,mBAAmB,iBAAiB;AAC/D,cAAY,kBAAkB,EAAE;AAChC,cAAY,cAAc,KAAK,MAAM;AAErC,MAAI,MAAM,YAAY,iBAAiB,KACrC,SAAQ,IAAI,MAAM,WAAW,cAAc;GAE7C;CAIF,MAAM,SAAS,GAAG,QAChB,IACG,QAAQ,MAAmB,KAAK,KAAK,CACrC,MAAM,GAAG,MAAM,EAAE,cAAc,EAAE,CAAC,CAClC,GAAG,GAAG;CAEX,MAAM,mBACJ,YAAY,KAAK,OACb,OAAO,KAAK,YAAY,CACrB,QAAQ,aAAa,CAAC,QAA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MAAM,WAAW,UAAU;IAC9B,MAAM,YAAY,MAAM,MAAM,GAAG,EAAE;AACnC,QAAI,CAAC,aAAa,UAAU,SAAS,OAAQ,QAAO;AACpD,WAAO,UAAU,MAAM,YAAY,kBAAkB;KACrD,GACF;GAEN,MAAM,YAAY,KAAK,MAAM,GAAG,MAAM,EAAE,SAAS,EAAE;AACnD,SAAM,KAAK,GAAG,UAAU;;;AAI5B,QAAO;EAAE;EAAS;EAAoB;;AAGxC,SAAgB,iBACd,QACA,SACA;CACA,MAAM,EAAE,cAAc,YAAY,UAAU,kBAAkB,WAAW,EAAE,CAAC;CAC5E,MAAM,EAAE,SAAS,aAAa,uBAAuB,cACnD,YACA,OACA,OACD;AAED,QAAO;EACL;EACA;EACA;EACA,YAAY,YAAY,GAAG,GAAG;EAC/B"}
1
+ {"version":3,"file":"branching.cjs","names":["findLast"],"sources":["../../src/ui/branching.ts"],"sourcesContent":["import type { ThreadState } from \"../schema.js\";\nimport { Message } from \"../types.messages.js\";\nimport { findLast } from \"./utils.js\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ninterface Node<StateType = any> {\n type: \"node\";\n value: ThreadState<StateType>;\n path: string[];\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ninterface Fork<StateType = any> {\n type: \"fork\";\n items: Array<Sequence<StateType>>;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport interface Sequence<StateType = any> {\n type: \"sequence\";\n items: Array<Node<StateType> | Fork<StateType>>;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ninterface ValidFork<StateType = any> {\n type: \"fork\";\n items: Array<ValidSequence<StateType>>;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ninterface ValidSequence<StateType = any> {\n type: \"sequence\";\n items: [Node<StateType>, ...(Node<StateType> | ValidFork<StateType>)[]];\n}\n\nexport function getBranchSequence<StateType extends Record<string, unknown>>(\n history: ThreadState<StateType>[]\n) {\n const nodeIds = new Set<string>();\n const childrenMap: Record<string, ThreadState<StateType>[]> = {};\n\n // Short circuit if there's only a singular one state\n if (history.length <= 1) {\n return {\n rootSequence: {\n type: \"sequence\",\n items: history.map((value) => ({ type: \"node\", value, path: [] })),\n } satisfies Sequence<StateType>,\n paths: [],\n };\n }\n\n // First pass - collect nodes for each checkpoint\n history.forEach((state) => {\n const checkpointId = state.parent_checkpoint?.checkpoint_id ?? \"$\";\n childrenMap[checkpointId] ??= [];\n childrenMap[checkpointId].push(state);\n\n if (state.checkpoint?.checkpoint_id != null) {\n nodeIds.add(state.checkpoint.checkpoint_id);\n }\n });\n\n // If dealing with partial history, take the branch\n // with the latest checkpoint and mark it as the root.\n const maxId = (...ids: (string | null)[]) =>\n ids\n .filter((i): i is string => i != null)\n .sort((a, b) => a.localeCompare(b))\n .at(-1)!;\n\n const lastOrphanedNode =\n childrenMap.$ == null\n ? Object.keys(childrenMap)\n .filter((parentId) => !nodeIds.has(parentId))\n .map((parentId) => {\n const queue: string[] = [parentId];\n const seen = new Set<string>();\n\n let lastId = parentId;\n\n while (queue.length > 0) {\n const current = queue.shift()!;\n\n if (seen.has(current)) continue;\n seen.add(current);\n\n const children = (childrenMap[current] ?? []).flatMap(\n (i) => i.checkpoint?.checkpoint_id ?? []\n );\n\n lastId = maxId(lastId, ...children);\n queue.push(...children);\n }\n\n return { parentId, lastId };\n })\n .sort((a, b) => a.lastId.localeCompare(b.lastId))\n .at(-1)?.parentId\n : undefined;\n\n if (lastOrphanedNode != null) childrenMap.$ = childrenMap[lastOrphanedNode];\n\n // Second pass - create a tree of sequences\n type Task = { id: string; sequence: Sequence; path: string[] };\n const rootSequence: Sequence = { type: \"sequence\", items: [] };\n const queue: Task[] = [{ id: \"$\", sequence: rootSequence, path: [] }];\n\n const paths: string[][] = [];\n\n const visited = new Set<string>();\n while (queue.length > 0) {\n const task = queue.shift()!;\n if (visited.has(task.id)) continue;\n visited.add(task.id);\n\n const children = childrenMap[task.id];\n if (children == null || children.length === 0) continue;\n\n // If we've encountered a fork (2+ children), push the fork\n // to the sequence and add a new sequence for each child\n let fork: Fork | undefined;\n if (children.length > 1) {\n fork = { type: \"fork\", items: [] };\n task.sequence.items.push(fork);\n }\n\n for (const value of children) {\n const id = value.checkpoint?.checkpoint_id;\n if (id == null) continue;\n\n let { sequence } = task;\n let { path } = task;\n if (fork != null) {\n sequence = { type: \"sequence\", items: [] };\n fork.items.unshift(sequence);\n\n path = path.slice();\n path.push(id);\n paths.push(path);\n }\n\n sequence.items.push({ type: \"node\", value, path });\n queue.push({ id, sequence, path });\n }\n }\n\n return { rootSequence, paths };\n}\n\nconst PATH_SEP = \">\";\nconst ROOT_ID = \"$\";\n\ntype BranchByCheckpoint = Record<\n string,\n { branch: string | undefined; branchOptions: string[] | undefined }\n>;\n\n// Get flat view\nexport function getBranchView<StateType extends Record<string, unknown>>(\n sequence: Sequence<StateType>,\n paths: string[][],\n branch: string\n) {\n const path = branch.split(PATH_SEP);\n const pathMap: Record<string, string[][]> = {};\n\n for (const path of paths) {\n const parent = path.at(-2) ?? ROOT_ID;\n pathMap[parent] ??= [];\n pathMap[parent].unshift(path);\n }\n\n const history: ThreadState<StateType>[] = [];\n const branchByCheckpoint: BranchByCheckpoint = {};\n\n const forkStack = path.slice();\n const queue: (Node<StateType> | Fork<StateType>)[] = [...sequence.items];\n\n while (queue.length > 0) {\n const item = queue.shift()!;\n\n if (item.type === \"node\") {\n history.push(item.value);\n const checkpointId = item.value.checkpoint?.checkpoint_id;\n if (checkpointId == null) continue;\n\n branchByCheckpoint[checkpointId] = {\n branch: item.path.join(PATH_SEP),\n branchOptions: (item.path.length > 0\n ? pathMap[item.path.at(-2) ?? ROOT_ID] ?? []\n : []\n ).map((p) => p.join(PATH_SEP)),\n };\n }\n if (item.type === \"fork\") {\n const forkId = forkStack.shift();\n const index =\n forkId != null\n ? item.items.findIndex((value) => {\n const firstItem = value.items.at(0);\n if (!firstItem || firstItem.type !== \"node\") return false;\n return firstItem.value.checkpoint?.checkpoint_id === forkId;\n })\n : -1;\n\n const nextItems = item.items.at(index)?.items ?? [];\n queue.push(...nextItems);\n }\n }\n\n return { history, branchByCheckpoint };\n}\n\nexport function getBranchContext<StateType extends Record<string, unknown>>(\n branch: string,\n history: ThreadState<StateType>[] | undefined\n) {\n const { rootSequence: branchTree, paths } = getBranchSequence(history ?? []);\n const { history: flatHistory, branchByCheckpoint } = getBranchView(\n branchTree,\n paths,\n branch\n );\n\n return {\n branchTree,\n flatHistory,\n branchByCheckpoint,\n threadHead: flatHistory.at(-1),\n };\n}\n\nexport function getMessagesMetadataMap<\n StateType extends Record<string, unknown>\n>(options: {\n initialValues: StateType | null | undefined;\n history: ThreadState<StateType>[] | null | undefined;\n getMessages: (values: StateType) => Message[];\n\n branchContext: {\n threadHead: ThreadState<StateType> | undefined;\n branchByCheckpoint: BranchByCheckpoint;\n };\n}) {\n const currentValues =\n options.branchContext.threadHead?.values ??\n options.initialValues ??\n ({} as StateType);\n\n const alreadyShown = new Set<string>();\n return options.getMessages(currentValues).map((message, idx) => {\n const messageId = message.id ?? idx;\n\n // Find the first checkpoint where the message was seen\n const firstSeenState = findLast(options.history ?? [], (state) =>\n options\n .getMessages(state.values)\n .map((m, idx) => m.id ?? idx)\n .includes(messageId)\n );\n\n const checkpointId = firstSeenState?.checkpoint?.checkpoint_id;\n let branch =\n checkpointId != null\n ? options.branchContext.branchByCheckpoint[checkpointId]\n : undefined;\n if (!branch?.branch?.length) branch = undefined;\n\n // serialize branches\n const optionsShown = branch?.branchOptions?.flat(2).join(\",\");\n if (optionsShown) {\n if (alreadyShown.has(optionsShown)) branch = undefined;\n alreadyShown.add(optionsShown);\n }\n\n return {\n messageId: messageId.toString(),\n firstSeenState,\n\n branch: branch?.branch,\n branchOptions: branch?.branchOptions,\n };\n });\n}\n"],"mappings":";;AAmCA,SAAgB,kBACd,SACA;CACA,MAAM,0BAAU,IAAI,KAAa;CACjC,MAAM,cAAwD,EAAE;AAGhE,KAAI,QAAQ,UAAU,EACpB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;EAC9D,MAAM,YAAY,QAAQ,MAAM;EAGhC,MAAM,iBAAiBA,cAAAA,SAAS,QAAQ,WAAW,EAAE,GAAG,UACtD,QACG,YAAY,MAAM,OAAO,CACzB,KAAK,GAAG,QAAQ,EAAE,MAAM,IAAI,CAC5B,SAAS,UAAU,CACvB;EAED,MAAM,eAAe,gBAAgB,YAAY;EACjD,IAAI,SACF,gBAAgB,OACZ,QAAQ,cAAc,mBAAmB,gBACzC,KAAA;AACN,MAAI,CAAC,QAAQ,QAAQ,OAAQ,UAAS,KAAA;EAGtC,MAAM,eAAe,QAAQ,eAAe,KAAK,EAAE,CAAC,KAAK,IAAI;AAC7D,MAAI,cAAc;AAChB,OAAI,aAAa,IAAI,aAAa,CAAE,UAAS,KAAA;AAC7C,gBAAa,IAAI,aAAa;;AAGhC,SAAO;GACL,WAAW,UAAU,UAAU;GAC/B;GAEA,QAAQ,QAAQ;GAChB,eAAe,QAAQ;GACxB;GACD"}
@@ -1,4 +1,5 @@
1
1
  import { ThreadState } from "../schema.cjs";
2
+ import { Message } from "../types.messages.cjs";
2
3
 
3
4
  //#region src/ui/branching.d.ts
4
5
  interface Node<StateType = any> {
@@ -14,6 +15,30 @@ interface Sequence<StateType = any> {
14
15
  type: "sequence";
15
16
  items: Array<Node<StateType> | Fork<StateType>>;
16
17
  }
18
+ type BranchByCheckpoint = Record<string, {
19
+ branch: string | undefined;
20
+ branchOptions: string[] | undefined;
21
+ }>;
22
+ declare function getBranchContext<StateType extends Record<string, unknown>>(branch: string, history: ThreadState<StateType>[] | undefined): {
23
+ branchTree: Sequence<any>;
24
+ flatHistory: ThreadState<any>[];
25
+ branchByCheckpoint: BranchByCheckpoint;
26
+ threadHead: ThreadState<any> | undefined;
27
+ };
28
+ declare function getMessagesMetadataMap<StateType extends Record<string, unknown>>(options: {
29
+ initialValues: StateType | null | undefined;
30
+ history: ThreadState<StateType>[] | null | undefined;
31
+ getMessages: (values: StateType) => Message[];
32
+ branchContext: {
33
+ threadHead: ThreadState<StateType> | undefined;
34
+ branchByCheckpoint: BranchByCheckpoint;
35
+ };
36
+ }): {
37
+ messageId: string;
38
+ firstSeenState: ThreadState<StateType> | undefined;
39
+ branch: string | undefined;
40
+ branchOptions: string[] | undefined;
41
+ }[];
17
42
  //#endregion
18
- export { Sequence };
43
+ export { Sequence, getBranchContext, getMessagesMetadataMap };
19
44
  //# sourceMappingURL=branching.d.cts.map