@langchain/core 1.1.32 → 1.1.33-dev-1773709997654

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 (1187) hide show
  1. package/dist/_virtual/_rolldown/runtime.cjs +12 -22
  2. package/dist/_virtual/_rolldown/runtime.js +6 -11
  3. package/dist/agents.cjs +8 -10
  4. package/dist/agents.js +1 -2
  5. package/dist/caches/index.cjs +11 -12
  6. package/dist/caches/index.cjs.map +1 -1
  7. package/dist/caches/index.js +1 -2
  8. package/dist/caches/index.js.map +1 -1
  9. package/dist/callbacks/base.cjs +10 -11
  10. package/dist/callbacks/base.cjs.map +1 -1
  11. package/dist/callbacks/base.js +1 -2
  12. package/dist/callbacks/base.js.map +1 -1
  13. package/dist/callbacks/dispatch/index.cjs +7 -8
  14. package/dist/callbacks/dispatch/index.cjs.map +1 -1
  15. package/dist/callbacks/dispatch/index.d.ts +0 -2
  16. package/dist/callbacks/dispatch/index.d.ts.map +1 -1
  17. package/dist/callbacks/dispatch/index.js +1 -2
  18. package/dist/callbacks/dispatch/index.js.map +1 -1
  19. package/dist/callbacks/dispatch/web.cjs +3 -4
  20. package/dist/callbacks/dispatch/web.cjs.map +1 -1
  21. package/dist/callbacks/dispatch/web.d.ts +0 -2
  22. package/dist/callbacks/dispatch/web.d.ts.map +1 -1
  23. package/dist/callbacks/dispatch/web.js +1 -2
  24. package/dist/callbacks/dispatch/web.js.map +1 -1
  25. package/dist/callbacks/manager.cjs +18 -19
  26. package/dist/callbacks/manager.cjs.map +1 -1
  27. package/dist/callbacks/manager.js +1 -2
  28. package/dist/callbacks/manager.js.map +1 -1
  29. package/dist/callbacks/promises.cjs +9 -10
  30. package/dist/callbacks/promises.js +1 -2
  31. package/dist/chat_history.cjs +12 -13
  32. package/dist/chat_history.cjs.map +1 -1
  33. package/dist/chat_history.d.ts +0 -2
  34. package/dist/chat_history.d.ts.map +1 -1
  35. package/dist/chat_history.js +1 -2
  36. package/dist/chat_history.js.map +1 -1
  37. package/dist/context.cjs +6 -7
  38. package/dist/context.cjs.map +1 -1
  39. package/dist/context.js +1 -2
  40. package/dist/context.js.map +1 -1
  41. package/dist/document_loaders/base.cjs +8 -10
  42. package/dist/document_loaders/base.cjs.map +1 -1
  43. package/dist/document_loaders/base.js +1 -2
  44. package/dist/document_loaders/base.js.map +1 -1
  45. package/dist/document_loaders/langsmith.cjs +9 -10
  46. package/dist/document_loaders/langsmith.cjs.map +1 -1
  47. package/dist/document_loaders/langsmith.js +1 -2
  48. package/dist/document_loaders/langsmith.js.map +1 -1
  49. package/dist/documents/document.cjs +1 -2
  50. package/dist/documents/document.cjs.map +1 -1
  51. package/dist/documents/document.js +1 -1
  52. package/dist/documents/document.js.map +1 -1
  53. package/dist/documents/index.cjs +10 -11
  54. package/dist/documents/index.js +1 -2
  55. package/dist/documents/transformers.cjs +2 -3
  56. package/dist/documents/transformers.cjs.map +1 -1
  57. package/dist/documents/transformers.js +1 -2
  58. package/dist/documents/transformers.js.map +1 -1
  59. package/dist/embeddings.cjs +9 -10
  60. package/dist/embeddings.cjs.map +1 -1
  61. package/dist/embeddings.js +1 -2
  62. package/dist/embeddings.js.map +1 -1
  63. package/dist/errors/index.cjs +9 -10
  64. package/dist/errors/index.cjs.map +1 -1
  65. package/dist/errors/index.js +1 -2
  66. package/dist/errors/index.js.map +1 -1
  67. package/dist/example_selectors/base.cjs +2 -3
  68. package/dist/example_selectors/base.cjs.map +1 -1
  69. package/dist/example_selectors/base.js +1 -2
  70. package/dist/example_selectors/base.js.map +1 -1
  71. package/dist/example_selectors/conditional.cjs +1 -2
  72. package/dist/example_selectors/conditional.cjs.map +1 -1
  73. package/dist/example_selectors/conditional.js +1 -1
  74. package/dist/example_selectors/index.cjs +12 -13
  75. package/dist/example_selectors/index.js +1 -2
  76. package/dist/example_selectors/length_based.cjs +2 -3
  77. package/dist/example_selectors/length_based.cjs.map +1 -1
  78. package/dist/example_selectors/length_based.js +1 -2
  79. package/dist/example_selectors/length_based.js.map +1 -1
  80. package/dist/example_selectors/semantic_similarity.cjs +3 -4
  81. package/dist/example_selectors/semantic_similarity.cjs.map +1 -1
  82. package/dist/example_selectors/semantic_similarity.js +1 -2
  83. package/dist/example_selectors/semantic_similarity.js.map +1 -1
  84. package/dist/index.cjs +8 -10
  85. package/dist/index.js +1 -2
  86. package/dist/indexing/base.cjs +6 -7
  87. package/dist/indexing/base.cjs.map +1 -1
  88. package/dist/indexing/base.js +1 -2
  89. package/dist/indexing/base.js.map +1 -1
  90. package/dist/indexing/index.cjs +10 -11
  91. package/dist/indexing/index.js +1 -2
  92. package/dist/indexing/record_manager.cjs +2 -3
  93. package/dist/indexing/record_manager.cjs.map +1 -1
  94. package/dist/indexing/record_manager.js +1 -2
  95. package/dist/indexing/record_manager.js.map +1 -1
  96. package/dist/language_models/base.cjs +15 -16
  97. package/dist/language_models/base.cjs.map +1 -1
  98. package/dist/language_models/base.d.ts +0 -2
  99. package/dist/language_models/base.d.ts.map +1 -1
  100. package/dist/language_models/base.js +2 -3
  101. package/dist/language_models/base.js.map +1 -1
  102. package/dist/language_models/chat_models.cjs +26 -27
  103. package/dist/language_models/chat_models.cjs.map +1 -1
  104. package/dist/language_models/chat_models.d.ts +0 -3
  105. package/dist/language_models/chat_models.d.ts.map +1 -1
  106. package/dist/language_models/chat_models.js +1 -2
  107. package/dist/language_models/chat_models.js.map +1 -1
  108. package/dist/language_models/llms.cjs +13 -14
  109. package/dist/language_models/llms.cjs.map +1 -1
  110. package/dist/language_models/llms.d.ts +0 -1
  111. package/dist/language_models/llms.d.ts.map +1 -1
  112. package/dist/language_models/llms.js +1 -2
  113. package/dist/language_models/llms.js.map +1 -1
  114. package/dist/language_models/profile.cjs +8 -10
  115. package/dist/language_models/profile.js +1 -2
  116. package/dist/language_models/structured_output.cjs +19 -20
  117. package/dist/language_models/structured_output.cjs.map +1 -1
  118. package/dist/language_models/structured_output.d.ts +0 -5
  119. package/dist/language_models/structured_output.d.ts.map +1 -1
  120. package/dist/language_models/structured_output.js +1 -2
  121. package/dist/language_models/structured_output.js.map +1 -1
  122. package/dist/language_models/utils.cjs +1 -2
  123. package/dist/language_models/utils.cjs.map +1 -1
  124. package/dist/language_models/utils.js +1 -1
  125. package/dist/load/import_constants.cjs +1 -2
  126. package/dist/load/import_constants.cjs.map +1 -1
  127. package/dist/load/import_constants.js +1 -1
  128. package/dist/load/import_map.cjs +69 -70
  129. package/dist/load/import_map.js +1 -2
  130. package/dist/load/index.cjs +8 -9
  131. package/dist/load/index.cjs.map +1 -1
  132. package/dist/load/index.js +1 -2
  133. package/dist/load/index.js.map +1 -1
  134. package/dist/load/map_keys.cjs +2 -3
  135. package/dist/load/map_keys.cjs.map +1 -1
  136. package/dist/load/map_keys.js +1 -2
  137. package/dist/load/map_keys.js.map +1 -1
  138. package/dist/load/serializable.cjs +10 -11
  139. package/dist/load/serializable.cjs.map +1 -1
  140. package/dist/load/serializable.js +1 -2
  141. package/dist/load/serializable.js.map +1 -1
  142. package/dist/load/validation.cjs +3 -4
  143. package/dist/load/validation.cjs.map +1 -1
  144. package/dist/load/validation.js +3 -3
  145. package/dist/load/validation.js.map +1 -1
  146. package/dist/memory.cjs +8 -10
  147. package/dist/memory.cjs.map +1 -1
  148. package/dist/memory.js +1 -2
  149. package/dist/memory.js.map +1 -1
  150. package/dist/messages/ai.cjs +6 -7
  151. package/dist/messages/ai.cjs.map +1 -1
  152. package/dist/messages/ai.js +1 -2
  153. package/dist/messages/ai.js.map +1 -1
  154. package/dist/messages/base.cjs +8 -9
  155. package/dist/messages/base.cjs.map +1 -1
  156. package/dist/messages/base.js +1 -2
  157. package/dist/messages/base.js.map +1 -1
  158. package/dist/messages/block_translators/anthropic.cjs +2 -3
  159. package/dist/messages/block_translators/anthropic.cjs.map +1 -1
  160. package/dist/messages/block_translators/anthropic.js +1 -2
  161. package/dist/messages/block_translators/anthropic.js.map +1 -1
  162. package/dist/messages/block_translators/bedrock_converse.cjs +2 -3
  163. package/dist/messages/block_translators/bedrock_converse.cjs.map +1 -1
  164. package/dist/messages/block_translators/bedrock_converse.js +1 -2
  165. package/dist/messages/block_translators/bedrock_converse.js.map +1 -1
  166. package/dist/messages/block_translators/data.cjs +3 -4
  167. package/dist/messages/block_translators/data.cjs.map +1 -1
  168. package/dist/messages/block_translators/data.js +1 -2
  169. package/dist/messages/block_translators/data.js.map +1 -1
  170. package/dist/messages/block_translators/deepseek.cjs +2 -3
  171. package/dist/messages/block_translators/deepseek.cjs.map +1 -1
  172. package/dist/messages/block_translators/deepseek.js +1 -2
  173. package/dist/messages/block_translators/deepseek.js.map +1 -1
  174. package/dist/messages/block_translators/google.cjs +2 -3
  175. package/dist/messages/block_translators/google.cjs.map +1 -1
  176. package/dist/messages/block_translators/google.js +1 -2
  177. package/dist/messages/block_translators/google.js.map +1 -1
  178. package/dist/messages/block_translators/google_genai.cjs +2 -3
  179. package/dist/messages/block_translators/google_genai.cjs.map +1 -1
  180. package/dist/messages/block_translators/google_genai.js +1 -2
  181. package/dist/messages/block_translators/google_genai.js.map +1 -1
  182. package/dist/messages/block_translators/google_vertexai.cjs +2 -3
  183. package/dist/messages/block_translators/google_vertexai.cjs.map +1 -1
  184. package/dist/messages/block_translators/google_vertexai.js +1 -2
  185. package/dist/messages/block_translators/google_vertexai.js.map +1 -1
  186. package/dist/messages/block_translators/groq.cjs +2 -3
  187. package/dist/messages/block_translators/groq.cjs.map +1 -1
  188. package/dist/messages/block_translators/groq.js +1 -2
  189. package/dist/messages/block_translators/groq.js.map +1 -1
  190. package/dist/messages/block_translators/index.cjs +11 -12
  191. package/dist/messages/block_translators/index.cjs.map +1 -1
  192. package/dist/messages/block_translators/index.js +1 -2
  193. package/dist/messages/block_translators/index.js.map +1 -1
  194. package/dist/messages/block_translators/ollama.cjs +2 -3
  195. package/dist/messages/block_translators/ollama.cjs.map +1 -1
  196. package/dist/messages/block_translators/ollama.js +1 -2
  197. package/dist/messages/block_translators/ollama.js.map +1 -1
  198. package/dist/messages/block_translators/openai.cjs +29 -4
  199. package/dist/messages/block_translators/openai.cjs.map +1 -1
  200. package/dist/messages/block_translators/openai.js +27 -2
  201. package/dist/messages/block_translators/openai.js.map +1 -1
  202. package/dist/messages/block_translators/utils.cjs +1 -2
  203. package/dist/messages/block_translators/utils.cjs.map +1 -1
  204. package/dist/messages/block_translators/utils.js +1 -1
  205. package/dist/messages/block_translators/xai.cjs +2 -3
  206. package/dist/messages/block_translators/xai.cjs.map +1 -1
  207. package/dist/messages/block_translators/xai.js +1 -2
  208. package/dist/messages/block_translators/xai.js.map +1 -1
  209. package/dist/messages/chat.cjs +2 -3
  210. package/dist/messages/chat.cjs.map +1 -1
  211. package/dist/messages/chat.js +1 -2
  212. package/dist/messages/chat.js.map +1 -1
  213. package/dist/messages/content/data.cjs +1 -2
  214. package/dist/messages/content/data.cjs.map +1 -1
  215. package/dist/messages/content/data.js +1 -1
  216. package/dist/messages/content/index.cjs +3 -4
  217. package/dist/messages/content/index.cjs.map +1 -1
  218. package/dist/messages/content/index.js +1 -2
  219. package/dist/messages/content/index.js.map +1 -1
  220. package/dist/messages/content/multimodal.cjs +1 -2
  221. package/dist/messages/content/multimodal.cjs.map +1 -1
  222. package/dist/messages/content/multimodal.js +1 -1
  223. package/dist/messages/content/tools.cjs +1 -2
  224. package/dist/messages/content/tools.cjs.map +1 -1
  225. package/dist/messages/content/tools.js +1 -1
  226. package/dist/messages/format.cjs +1 -2
  227. package/dist/messages/format.cjs.map +1 -1
  228. package/dist/messages/format.js +1 -1
  229. package/dist/messages/function.cjs +2 -3
  230. package/dist/messages/function.cjs.map +1 -1
  231. package/dist/messages/function.js +1 -2
  232. package/dist/messages/function.js.map +1 -1
  233. package/dist/messages/human.cjs +2 -3
  234. package/dist/messages/human.cjs.map +1 -1
  235. package/dist/messages/human.js +1 -2
  236. package/dist/messages/human.js.map +1 -1
  237. package/dist/messages/index.cjs +22 -23
  238. package/dist/messages/index.js +1 -2
  239. package/dist/messages/message.cjs +1 -2
  240. package/dist/messages/message.cjs.map +1 -1
  241. package/dist/messages/message.js +1 -1
  242. package/dist/messages/metadata.cjs +2 -3
  243. package/dist/messages/metadata.cjs.map +1 -1
  244. package/dist/messages/metadata.js +1 -2
  245. package/dist/messages/metadata.js.map +1 -1
  246. package/dist/messages/modifier.cjs +2 -3
  247. package/dist/messages/modifier.cjs.map +1 -1
  248. package/dist/messages/modifier.js +1 -2
  249. package/dist/messages/modifier.js.map +1 -1
  250. package/dist/messages/system.cjs +2 -3
  251. package/dist/messages/system.cjs.map +1 -1
  252. package/dist/messages/system.js +1 -2
  253. package/dist/messages/system.js.map +1 -1
  254. package/dist/messages/tool.cjs +9 -10
  255. package/dist/messages/tool.cjs.map +1 -1
  256. package/dist/messages/tool.js +1 -2
  257. package/dist/messages/tool.js.map +1 -1
  258. package/dist/messages/transformers.cjs +11 -12
  259. package/dist/messages/transformers.cjs.map +1 -1
  260. package/dist/messages/transformers.js +1 -2
  261. package/dist/messages/transformers.js.map +1 -1
  262. package/dist/messages/utils.cjs +12 -13
  263. package/dist/messages/utils.cjs.map +1 -1
  264. package/dist/messages/utils.js +1 -2
  265. package/dist/messages/utils.js.map +1 -1
  266. package/dist/output_parsers/base.cjs +4 -5
  267. package/dist/output_parsers/base.cjs.map +1 -1
  268. package/dist/output_parsers/base.d.ts +0 -4
  269. package/dist/output_parsers/base.d.ts.map +1 -1
  270. package/dist/output_parsers/base.js +1 -2
  271. package/dist/output_parsers/base.js.map +1 -1
  272. package/dist/output_parsers/bytes.cjs +2 -3
  273. package/dist/output_parsers/bytes.cjs.map +1 -1
  274. package/dist/output_parsers/bytes.js +1 -2
  275. package/dist/output_parsers/bytes.js.map +1 -1
  276. package/dist/output_parsers/index.cjs +18 -19
  277. package/dist/output_parsers/index.js +1 -2
  278. package/dist/output_parsers/json.cjs +5 -6
  279. package/dist/output_parsers/json.cjs.map +1 -1
  280. package/dist/output_parsers/json.d.ts +0 -1
  281. package/dist/output_parsers/json.d.ts.map +1 -1
  282. package/dist/output_parsers/json.js +2 -3
  283. package/dist/output_parsers/json.js.map +1 -1
  284. package/dist/output_parsers/list.cjs +3 -4
  285. package/dist/output_parsers/list.cjs.map +1 -1
  286. package/dist/output_parsers/list.d.ts +0 -1
  287. package/dist/output_parsers/list.d.ts.map +1 -1
  288. package/dist/output_parsers/list.js +1 -2
  289. package/dist/output_parsers/list.js.map +1 -1
  290. package/dist/output_parsers/openai_functions/index.cjs +9 -10
  291. package/dist/output_parsers/openai_functions/index.js +1 -2
  292. package/dist/output_parsers/openai_functions/json_output_functions_parsers.cjs +7 -8
  293. package/dist/output_parsers/openai_functions/json_output_functions_parsers.cjs.map +1 -1
  294. package/dist/output_parsers/openai_functions/json_output_functions_parsers.d.ts +0 -1
  295. package/dist/output_parsers/openai_functions/json_output_functions_parsers.d.ts.map +1 -1
  296. package/dist/output_parsers/openai_functions/json_output_functions_parsers.js +1 -2
  297. package/dist/output_parsers/openai_functions/json_output_functions_parsers.js.map +1 -1
  298. package/dist/output_parsers/openai_tools/index.cjs +9 -10
  299. package/dist/output_parsers/openai_tools/index.js +1 -2
  300. package/dist/output_parsers/openai_tools/json_output_tools_parsers.cjs +7 -8
  301. package/dist/output_parsers/openai_tools/json_output_tools_parsers.cjs.map +1 -1
  302. package/dist/output_parsers/openai_tools/json_output_tools_parsers.js +1 -2
  303. package/dist/output_parsers/openai_tools/json_output_tools_parsers.js.map +1 -1
  304. package/dist/output_parsers/standard_schema.cjs +4 -5
  305. package/dist/output_parsers/standard_schema.cjs.map +1 -1
  306. package/dist/output_parsers/standard_schema.js +1 -2
  307. package/dist/output_parsers/standard_schema.js.map +1 -1
  308. package/dist/output_parsers/string.cjs +2 -3
  309. package/dist/output_parsers/string.cjs.map +1 -1
  310. package/dist/output_parsers/string.d.ts +0 -1
  311. package/dist/output_parsers/string.d.ts.map +1 -1
  312. package/dist/output_parsers/string.js +1 -2
  313. package/dist/output_parsers/string.js.map +1 -1
  314. package/dist/output_parsers/structured.cjs +5 -6
  315. package/dist/output_parsers/structured.cjs.map +1 -1
  316. package/dist/output_parsers/structured.js +1 -2
  317. package/dist/output_parsers/structured.js.map +1 -1
  318. package/dist/output_parsers/transform.cjs +6 -7
  319. package/dist/output_parsers/transform.cjs.map +1 -1
  320. package/dist/output_parsers/transform.js +1 -2
  321. package/dist/output_parsers/transform.js.map +1 -1
  322. package/dist/output_parsers/xml.cjs +5 -6
  323. package/dist/output_parsers/xml.cjs.map +1 -1
  324. package/dist/output_parsers/xml.js +1 -2
  325. package/dist/output_parsers/xml.js.map +1 -1
  326. package/dist/outputs.cjs +8 -10
  327. package/dist/outputs.cjs.map +1 -1
  328. package/dist/outputs.js +1 -2
  329. package/dist/outputs.js.map +1 -1
  330. package/dist/prompt_values.cjs +11 -12
  331. package/dist/prompt_values.cjs.map +1 -1
  332. package/dist/prompt_values.js +1 -2
  333. package/dist/prompt_values.js.map +1 -1
  334. package/dist/prompts/base.cjs +2 -3
  335. package/dist/prompts/base.cjs.map +1 -1
  336. package/dist/prompts/base.d.ts +0 -2
  337. package/dist/prompts/base.d.ts.map +1 -1
  338. package/dist/prompts/base.js +1 -2
  339. package/dist/prompts/base.js.map +1 -1
  340. package/dist/prompts/chat.cjs +17 -18
  341. package/dist/prompts/chat.cjs.map +1 -1
  342. package/dist/prompts/chat.d.ts +0 -1
  343. package/dist/prompts/chat.d.ts.map +1 -1
  344. package/dist/prompts/chat.js +1 -2
  345. package/dist/prompts/chat.js.map +1 -1
  346. package/dist/prompts/dict.cjs +3 -4
  347. package/dist/prompts/dict.cjs.map +1 -1
  348. package/dist/prompts/dict.js +1 -2
  349. package/dist/prompts/dict.js.map +1 -1
  350. package/dist/prompts/few_shot.cjs +5 -6
  351. package/dist/prompts/few_shot.cjs.map +1 -1
  352. package/dist/prompts/few_shot.d.ts +0 -1
  353. package/dist/prompts/few_shot.d.ts.map +1 -1
  354. package/dist/prompts/few_shot.js +1 -2
  355. package/dist/prompts/few_shot.js.map +1 -1
  356. package/dist/prompts/image.cjs +4 -5
  357. package/dist/prompts/image.cjs.map +1 -1
  358. package/dist/prompts/image.d.ts +0 -1
  359. package/dist/prompts/image.d.ts.map +1 -1
  360. package/dist/prompts/image.js +1 -2
  361. package/dist/prompts/image.js.map +1 -1
  362. package/dist/prompts/index.cjs +18 -19
  363. package/dist/prompts/index.js +1 -2
  364. package/dist/prompts/pipeline.cjs +3 -4
  365. package/dist/prompts/pipeline.cjs.map +1 -1
  366. package/dist/prompts/pipeline.js +1 -2
  367. package/dist/prompts/pipeline.js.map +1 -1
  368. package/dist/prompts/prompt.cjs +3 -4
  369. package/dist/prompts/prompt.cjs.map +1 -1
  370. package/dist/prompts/prompt.d.ts +0 -1
  371. package/dist/prompts/prompt.d.ts.map +1 -1
  372. package/dist/prompts/prompt.js +1 -2
  373. package/dist/prompts/prompt.js.map +1 -1
  374. package/dist/prompts/serde.d.ts +0 -1
  375. package/dist/prompts/serde.d.ts.map +1 -1
  376. package/dist/prompts/string.cjs +3 -4
  377. package/dist/prompts/string.cjs.map +1 -1
  378. package/dist/prompts/string.js +1 -2
  379. package/dist/prompts/string.js.map +1 -1
  380. package/dist/prompts/structured.cjs +3 -4
  381. package/dist/prompts/structured.cjs.map +1 -1
  382. package/dist/prompts/structured.d.ts +0 -1
  383. package/dist/prompts/structured.d.ts.map +1 -1
  384. package/dist/prompts/structured.js +1 -2
  385. package/dist/prompts/structured.js.map +1 -1
  386. package/dist/prompts/template.cjs +3 -4
  387. package/dist/prompts/template.cjs.map +1 -1
  388. package/dist/prompts/template.d.ts +0 -2
  389. package/dist/prompts/template.d.ts.map +1 -1
  390. package/dist/prompts/template.js +1 -2
  391. package/dist/prompts/template.js.map +1 -1
  392. package/dist/retrievers/document_compressors/index.cjs +8 -10
  393. package/dist/retrievers/document_compressors/index.cjs.map +1 -1
  394. package/dist/retrievers/document_compressors/index.js +1 -2
  395. package/dist/retrievers/document_compressors/index.js.map +1 -1
  396. package/dist/retrievers/index.cjs +11 -12
  397. package/dist/retrievers/index.cjs.map +1 -1
  398. package/dist/retrievers/index.d.ts +0 -1
  399. package/dist/retrievers/index.d.ts.map +1 -1
  400. package/dist/retrievers/index.js +1 -2
  401. package/dist/retrievers/index.js.map +1 -1
  402. package/dist/runnables/base.cjs +32 -36
  403. package/dist/runnables/base.cjs.map +1 -1
  404. package/dist/runnables/base.d.cts.map +1 -1
  405. package/dist/runnables/base.d.ts.map +1 -1
  406. package/dist/runnables/base.js +15 -19
  407. package/dist/runnables/base.js.map +1 -1
  408. package/dist/runnables/branch.cjs +4 -5
  409. package/dist/runnables/branch.cjs.map +1 -1
  410. package/dist/runnables/branch.d.ts +0 -1
  411. package/dist/runnables/branch.d.ts.map +1 -1
  412. package/dist/runnables/branch.js +1 -2
  413. package/dist/runnables/branch.js.map +1 -1
  414. package/dist/runnables/config.cjs +4 -7
  415. package/dist/runnables/config.cjs.map +1 -1
  416. package/dist/runnables/config.js +2 -4
  417. package/dist/runnables/config.js.map +1 -1
  418. package/dist/runnables/graph.cjs +11 -12
  419. package/dist/runnables/graph.cjs.map +1 -1
  420. package/dist/runnables/graph.js +1 -2
  421. package/dist/runnables/graph.js.map +1 -1
  422. package/dist/runnables/graph_mermaid.cjs +2 -3
  423. package/dist/runnables/graph_mermaid.cjs.map +1 -1
  424. package/dist/runnables/graph_mermaid.js +1 -2
  425. package/dist/runnables/graph_mermaid.js.map +1 -1
  426. package/dist/runnables/history.cjs +7 -8
  427. package/dist/runnables/history.cjs.map +1 -1
  428. package/dist/runnables/history.d.ts +0 -2
  429. package/dist/runnables/history.d.ts.map +1 -1
  430. package/dist/runnables/history.js +1 -2
  431. package/dist/runnables/history.js.map +1 -1
  432. package/dist/runnables/index.cjs +15 -16
  433. package/dist/runnables/index.js +1 -2
  434. package/dist/runnables/iter.cjs +4 -5
  435. package/dist/runnables/iter.cjs.map +1 -1
  436. package/dist/runnables/iter.js +1 -2
  437. package/dist/runnables/iter.js.map +1 -1
  438. package/dist/runnables/passthrough.cjs +4 -5
  439. package/dist/runnables/passthrough.cjs.map +1 -1
  440. package/dist/runnables/passthrough.d.ts +0 -1
  441. package/dist/runnables/passthrough.d.ts.map +1 -1
  442. package/dist/runnables/passthrough.js +1 -2
  443. package/dist/runnables/passthrough.js.map +1 -1
  444. package/dist/runnables/router.cjs +3 -4
  445. package/dist/runnables/router.cjs.map +1 -1
  446. package/dist/runnables/router.d.ts +0 -1
  447. package/dist/runnables/router.d.ts.map +1 -1
  448. package/dist/runnables/router.js +1 -2
  449. package/dist/runnables/router.js.map +1 -1
  450. package/dist/runnables/utils.cjs +1 -2
  451. package/dist/runnables/utils.cjs.map +1 -1
  452. package/dist/runnables/utils.js +1 -1
  453. package/dist/runnables/utils.js.map +1 -1
  454. package/dist/runnables/wrappers.cjs +2 -3
  455. package/dist/runnables/wrappers.cjs.map +1 -1
  456. package/dist/runnables/wrappers.js +1 -2
  457. package/dist/runnables/wrappers.js.map +1 -1
  458. package/dist/singletons/async_local_storage/context.cjs +3 -4
  459. package/dist/singletons/async_local_storage/context.cjs.map +1 -1
  460. package/dist/singletons/async_local_storage/context.js +1 -2
  461. package/dist/singletons/async_local_storage/context.js.map +1 -1
  462. package/dist/singletons/async_local_storage/globals.cjs +1 -2
  463. package/dist/singletons/async_local_storage/globals.cjs.map +1 -1
  464. package/dist/singletons/async_local_storage/globals.js +1 -1
  465. package/dist/singletons/async_local_storage/globals.js.map +1 -1
  466. package/dist/singletons/async_local_storage/index.cjs +4 -5
  467. package/dist/singletons/async_local_storage/index.cjs.map +1 -1
  468. package/dist/singletons/async_local_storage/index.js +1 -2
  469. package/dist/singletons/async_local_storage/index.js.map +1 -1
  470. package/dist/singletons/callbacks.cjs +4 -5
  471. package/dist/singletons/callbacks.cjs.map +1 -1
  472. package/dist/singletons/callbacks.js +1 -2
  473. package/dist/singletons/callbacks.js.map +1 -1
  474. package/dist/singletons/index.cjs +10 -11
  475. package/dist/singletons/index.js +1 -2
  476. package/dist/singletons/tracer.cjs +3 -4
  477. package/dist/singletons/tracer.cjs.map +1 -1
  478. package/dist/singletons/tracer.js +1 -2
  479. package/dist/singletons/tracer.js.map +1 -1
  480. package/dist/stores.cjs +9 -10
  481. package/dist/stores.cjs.map +1 -1
  482. package/dist/stores.js +1 -2
  483. package/dist/stores.js.map +1 -1
  484. package/dist/structured_query/base.cjs +3 -4
  485. package/dist/structured_query/base.cjs.map +1 -1
  486. package/dist/structured_query/base.js +1 -2
  487. package/dist/structured_query/base.js.map +1 -1
  488. package/dist/structured_query/functional.cjs +4 -5
  489. package/dist/structured_query/functional.cjs.map +1 -1
  490. package/dist/structured_query/functional.js +1 -2
  491. package/dist/structured_query/functional.js.map +1 -1
  492. package/dist/structured_query/index.cjs +12 -13
  493. package/dist/structured_query/index.js +1 -2
  494. package/dist/structured_query/ir.cjs +1 -2
  495. package/dist/structured_query/ir.cjs.map +1 -1
  496. package/dist/structured_query/ir.js +1 -1
  497. package/dist/structured_query/ir.js.map +1 -1
  498. package/dist/structured_query/utils.cjs +1 -2
  499. package/dist/structured_query/utils.cjs.map +1 -1
  500. package/dist/structured_query/utils.js +1 -1
  501. package/dist/testing/fake_model_builder.cjs +6 -7
  502. package/dist/testing/fake_model_builder.cjs.map +1 -1
  503. package/dist/testing/fake_model_builder.d.ts +0 -1
  504. package/dist/testing/fake_model_builder.d.ts.map +1 -1
  505. package/dist/testing/fake_model_builder.js +1 -2
  506. package/dist/testing/fake_model_builder.js.map +1 -1
  507. package/dist/testing/index.cjs +10 -11
  508. package/dist/testing/index.js +1 -2
  509. package/dist/testing/matchers.cjs +7 -8
  510. package/dist/testing/matchers.cjs.map +1 -1
  511. package/dist/testing/matchers.js +1 -2
  512. package/dist/testing/matchers.js.map +1 -1
  513. package/dist/tools/index.cjs +20 -21
  514. package/dist/tools/index.cjs.map +1 -1
  515. package/dist/tools/index.d.cts +1 -1
  516. package/dist/tools/index.d.cts.map +1 -1
  517. package/dist/tools/index.d.ts +1 -3
  518. package/dist/tools/index.d.ts.map +1 -1
  519. package/dist/tools/index.js +1 -2
  520. package/dist/tools/index.js.map +1 -1
  521. package/dist/tools/types.cjs +3 -4
  522. package/dist/tools/types.cjs.map +1 -1
  523. package/dist/tools/types.d.ts +0 -2
  524. package/dist/tools/types.d.ts.map +1 -1
  525. package/dist/tools/types.js +1 -2
  526. package/dist/tools/types.js.map +1 -1
  527. package/dist/tools/utils.cjs +1 -2
  528. package/dist/tools/utils.cjs.map +1 -1
  529. package/dist/tools/utils.js +1 -1
  530. package/dist/tracers/base.cjs +10 -11
  531. package/dist/tracers/base.cjs.map +1 -1
  532. package/dist/tracers/base.js +1 -2
  533. package/dist/tracers/base.js.map +1 -1
  534. package/dist/tracers/console.cjs +9 -10
  535. package/dist/tracers/console.cjs.map +1 -1
  536. package/dist/tracers/console.js +1 -2
  537. package/dist/tracers/console.js.map +1 -1
  538. package/dist/tracers/event_stream.cjs +5 -6
  539. package/dist/tracers/event_stream.cjs.map +1 -1
  540. package/dist/tracers/event_stream.d.ts +0 -2
  541. package/dist/tracers/event_stream.d.ts.map +1 -1
  542. package/dist/tracers/event_stream.js +1 -2
  543. package/dist/tracers/event_stream.js.map +1 -1
  544. package/dist/tracers/log_stream.cjs +13 -14
  545. package/dist/tracers/log_stream.cjs.map +1 -1
  546. package/dist/tracers/log_stream.js +1 -2
  547. package/dist/tracers/log_stream.js.map +1 -1
  548. package/dist/tracers/root_listener.cjs +2 -3
  549. package/dist/tracers/root_listener.cjs.map +1 -1
  550. package/dist/tracers/root_listener.js +1 -2
  551. package/dist/tracers/root_listener.js.map +1 -1
  552. package/dist/tracers/run_collector.cjs +9 -10
  553. package/dist/tracers/run_collector.cjs.map +1 -1
  554. package/dist/tracers/run_collector.js +1 -2
  555. package/dist/tracers/run_collector.js.map +1 -1
  556. package/dist/tracers/tracer_langchain.cjs +12 -13
  557. package/dist/tracers/tracer_langchain.cjs.map +1 -1
  558. package/dist/tracers/tracer_langchain.js +1 -2
  559. package/dist/tracers/tracer_langchain.js.map +1 -1
  560. package/dist/types/stream.cjs +8 -10
  561. package/dist/types/stream.js +1 -2
  562. package/dist/utils/async_caller.cjs +10 -11
  563. package/dist/utils/async_caller.cjs.map +1 -1
  564. package/dist/utils/async_caller.js +1 -2
  565. package/dist/utils/async_caller.js.map +1 -1
  566. package/dist/utils/callbacks.cjs +2 -3
  567. package/dist/utils/callbacks.cjs.map +1 -1
  568. package/dist/utils/callbacks.js +1 -2
  569. package/dist/utils/callbacks.js.map +1 -1
  570. package/dist/utils/chunk_array.cjs +8 -10
  571. package/dist/utils/chunk_array.cjs.map +1 -1
  572. package/dist/utils/chunk_array.js +1 -2
  573. package/dist/utils/chunk_array.js.map +1 -1
  574. package/dist/utils/context.cjs +8 -10
  575. package/dist/utils/context.cjs.map +1 -1
  576. package/dist/utils/context.js +1 -2
  577. package/dist/utils/context.js.map +1 -1
  578. package/dist/utils/env.cjs +8 -10
  579. package/dist/utils/env.cjs.map +1 -1
  580. package/dist/utils/env.js +1 -2
  581. package/dist/utils/env.js.map +1 -1
  582. package/dist/utils/event_source_parse.cjs +9 -10
  583. package/dist/utils/event_source_parse.cjs.map +1 -1
  584. package/dist/utils/event_source_parse.js +1 -2
  585. package/dist/utils/event_source_parse.js.map +1 -1
  586. package/dist/utils/fast-json-patch/index.cjs +5 -16
  587. package/dist/utils/fast-json-patch/index.cjs.map +1 -1
  588. package/dist/utils/fast-json-patch/index.js +6 -17
  589. package/dist/utils/fast-json-patch/index.js.map +1 -1
  590. package/dist/utils/fast-json-patch/src/core.cjs +8 -9
  591. package/dist/utils/fast-json-patch/src/core.cjs.map +1 -1
  592. package/dist/utils/fast-json-patch/src/core.js +1 -2
  593. package/dist/utils/fast-json-patch/src/core.js.map +1 -1
  594. package/dist/utils/fast-json-patch/src/duplex.cjs +3 -4
  595. package/dist/utils/fast-json-patch/src/duplex.cjs.map +1 -1
  596. package/dist/utils/fast-json-patch/src/duplex.js +1 -2
  597. package/dist/utils/fast-json-patch/src/duplex.js.map +1 -1
  598. package/dist/utils/fast-json-patch/src/helpers.cjs +1 -2
  599. package/dist/utils/fast-json-patch/src/helpers.cjs.map +1 -1
  600. package/dist/utils/fast-json-patch/src/helpers.js +1 -1
  601. package/dist/utils/fast-json-patch/src/helpers.js.map +1 -1
  602. package/dist/utils/format.cjs +8 -10
  603. package/dist/utils/format.js +1 -2
  604. package/dist/utils/function_calling.cjs +10 -11
  605. package/dist/utils/function_calling.cjs.map +1 -1
  606. package/dist/utils/function_calling.js +1 -2
  607. package/dist/utils/function_calling.js.map +1 -1
  608. package/dist/utils/hash.cjs +9 -10
  609. package/dist/utils/hash.js +1 -2
  610. package/dist/utils/is-network-error/index.cjs +1 -2
  611. package/dist/utils/is-network-error/index.cjs.map +1 -1
  612. package/dist/utils/is-network-error/index.js +1 -1
  613. package/dist/utils/is-network-error/index.js.map +1 -1
  614. package/dist/utils/js-sha256/hash.cjs +1 -3
  615. package/dist/utils/js-sha256/hash.cjs.map +1 -1
  616. package/dist/utils/js-sha256/hash.js +1 -1
  617. package/dist/utils/js-sha256/hash.js.map +1 -1
  618. package/dist/utils/json.cjs +1 -2
  619. package/dist/utils/json.cjs.map +1 -1
  620. package/dist/utils/json.js +1 -1
  621. package/dist/utils/json_patch.cjs +11 -12
  622. package/dist/utils/json_patch.js +1 -2
  623. package/dist/utils/json_schema.cjs +22 -23
  624. package/dist/utils/json_schema.cjs.map +1 -1
  625. package/dist/utils/json_schema.d.ts +0 -1
  626. package/dist/utils/json_schema.d.ts.map +1 -1
  627. package/dist/utils/json_schema.js +1 -2
  628. package/dist/utils/json_schema.js.map +1 -1
  629. package/dist/utils/math.cjs +11 -12
  630. package/dist/utils/math.cjs.map +1 -1
  631. package/dist/utils/math.js +1 -2
  632. package/dist/utils/math.js.map +1 -1
  633. package/dist/utils/ml-distance/distances.cjs +1 -2
  634. package/dist/utils/ml-distance/distances.cjs.map +1 -1
  635. package/dist/utils/ml-distance/distances.js +1 -1
  636. package/dist/utils/ml-distance/similarities.cjs +1 -2
  637. package/dist/utils/ml-distance/similarities.cjs.map +1 -1
  638. package/dist/utils/ml-distance/similarities.js +1 -1
  639. package/dist/utils/ml-distance-euclidean/euclidean.cjs +1 -2
  640. package/dist/utils/ml-distance-euclidean/euclidean.cjs.map +1 -1
  641. package/dist/utils/ml-distance-euclidean/euclidean.js +1 -1
  642. package/dist/utils/namespace.cjs +1 -2
  643. package/dist/utils/namespace.cjs.map +1 -1
  644. package/dist/utils/namespace.js +1 -1
  645. package/dist/utils/p-retry/index.cjs +2 -3
  646. package/dist/utils/p-retry/index.cjs.map +1 -1
  647. package/dist/utils/p-retry/index.js +1 -2
  648. package/dist/utils/p-retry/index.js.map +1 -1
  649. package/dist/utils/sax-js/sax.cjs +1 -2
  650. package/dist/utils/sax-js/sax.cjs.map +1 -1
  651. package/dist/utils/sax-js/sax.js +1 -1
  652. package/dist/utils/signal.cjs +1 -2
  653. package/dist/utils/signal.cjs.map +1 -1
  654. package/dist/utils/signal.js +1 -1
  655. package/dist/utils/signal.js.map +1 -1
  656. package/dist/utils/ssrf.cjs +8 -10
  657. package/dist/utils/ssrf.cjs.map +1 -1
  658. package/dist/utils/ssrf.js +1 -2
  659. package/dist/utils/ssrf.js.map +1 -1
  660. package/dist/utils/standard_schema.cjs +8 -10
  661. package/dist/utils/standard_schema.cjs.map +1 -1
  662. package/dist/utils/standard_schema.js +1 -2
  663. package/dist/utils/standard_schema.js.map +1 -1
  664. package/dist/utils/stream.cjs +13 -14
  665. package/dist/utils/stream.cjs.map +1 -1
  666. package/dist/utils/stream.d.cts.map +1 -1
  667. package/dist/utils/stream.d.ts.map +1 -1
  668. package/dist/utils/stream.js +2 -3
  669. package/dist/utils/stream.js.map +1 -1
  670. package/dist/utils/testing/chat_models.cjs +7 -8
  671. package/dist/utils/testing/chat_models.cjs.map +1 -1
  672. package/dist/utils/testing/chat_models.d.ts +0 -1
  673. package/dist/utils/testing/chat_models.d.ts.map +1 -1
  674. package/dist/utils/testing/chat_models.js +1 -2
  675. package/dist/utils/testing/chat_models.js.map +1 -1
  676. package/dist/utils/testing/embeddings.cjs +2 -3
  677. package/dist/utils/testing/embeddings.cjs.map +1 -1
  678. package/dist/utils/testing/embeddings.js +1 -2
  679. package/dist/utils/testing/embeddings.js.map +1 -1
  680. package/dist/utils/testing/index.cjs +18 -19
  681. package/dist/utils/testing/index.js +1 -2
  682. package/dist/utils/testing/llms.cjs +2 -3
  683. package/dist/utils/testing/llms.cjs.map +1 -1
  684. package/dist/utils/testing/llms.js +1 -2
  685. package/dist/utils/testing/llms.js.map +1 -1
  686. package/dist/utils/testing/message_history.cjs +6 -7
  687. package/dist/utils/testing/message_history.cjs.map +1 -1
  688. package/dist/utils/testing/message_history.d.ts +0 -1
  689. package/dist/utils/testing/message_history.d.ts.map +1 -1
  690. package/dist/utils/testing/message_history.js +1 -2
  691. package/dist/utils/testing/message_history.js.map +1 -1
  692. package/dist/utils/testing/output_parsers.cjs +2 -3
  693. package/dist/utils/testing/output_parsers.cjs.map +1 -1
  694. package/dist/utils/testing/output_parsers.js +1 -2
  695. package/dist/utils/testing/output_parsers.js.map +1 -1
  696. package/dist/utils/testing/retrievers.cjs +3 -4
  697. package/dist/utils/testing/retrievers.cjs.map +1 -1
  698. package/dist/utils/testing/retrievers.js +1 -2
  699. package/dist/utils/testing/retrievers.js.map +1 -1
  700. package/dist/utils/testing/runnables.cjs +2 -3
  701. package/dist/utils/testing/runnables.cjs.map +1 -1
  702. package/dist/utils/testing/runnables.js +1 -2
  703. package/dist/utils/testing/runnables.js.map +1 -1
  704. package/dist/utils/testing/tools.cjs +2 -3
  705. package/dist/utils/testing/tools.cjs.map +1 -1
  706. package/dist/utils/testing/tools.js +1 -2
  707. package/dist/utils/testing/tools.js.map +1 -1
  708. package/dist/utils/testing/tracers.cjs +2 -3
  709. package/dist/utils/testing/tracers.cjs.map +1 -1
  710. package/dist/utils/testing/tracers.js +1 -2
  711. package/dist/utils/testing/tracers.js.map +1 -1
  712. package/dist/utils/testing/vectorstores.cjs +4 -5
  713. package/dist/utils/testing/vectorstores.cjs.map +1 -1
  714. package/dist/utils/testing/vectorstores.js +1 -2
  715. package/dist/utils/testing/vectorstores.js.map +1 -1
  716. package/dist/utils/tiktoken.cjs +9 -10
  717. package/dist/utils/tiktoken.cjs.map +1 -1
  718. package/dist/utils/tiktoken.js +1 -2
  719. package/dist/utils/tiktoken.js.map +1 -1
  720. package/dist/utils/types/index.cjs +9 -10
  721. package/dist/utils/types/index.js +1 -2
  722. package/dist/utils/types/zod.cjs +2 -3
  723. package/dist/utils/types/zod.cjs.map +1 -1
  724. package/dist/utils/types/zod.js +1 -2
  725. package/dist/utils/types/zod.js.map +1 -1
  726. package/dist/utils/zod-to-json-schema/Options.cjs +1 -2
  727. package/dist/utils/zod-to-json-schema/Options.cjs.map +1 -1
  728. package/dist/utils/zod-to-json-schema/Options.d.ts +1 -3
  729. package/dist/utils/zod-to-json-schema/Options.js +1 -1
  730. package/dist/utils/zod-to-json-schema/Options.js.map +1 -1
  731. package/dist/utils/zod-to-json-schema/Refs.cjs +2 -3
  732. package/dist/utils/zod-to-json-schema/Refs.cjs.map +1 -1
  733. package/dist/utils/zod-to-json-schema/Refs.d.ts +1 -3
  734. package/dist/utils/zod-to-json-schema/Refs.js +1 -2
  735. package/dist/utils/zod-to-json-schema/Refs.js.map +1 -1
  736. package/dist/utils/zod-to-json-schema/errorMessages.cjs +1 -2
  737. package/dist/utils/zod-to-json-schema/errorMessages.cjs.map +1 -1
  738. package/dist/utils/zod-to-json-schema/errorMessages.d.ts +0 -2
  739. package/dist/utils/zod-to-json-schema/errorMessages.d.ts.map +1 -1
  740. package/dist/utils/zod-to-json-schema/errorMessages.js +1 -1
  741. package/dist/utils/zod-to-json-schema/getRelativePath.cjs +1 -2
  742. package/dist/utils/zod-to-json-schema/getRelativePath.cjs.map +1 -1
  743. package/dist/utils/zod-to-json-schema/getRelativePath.js +1 -1
  744. package/dist/utils/zod-to-json-schema/index.cjs +37 -37
  745. package/dist/utils/zod-to-json-schema/index.d.ts +1 -14
  746. package/dist/utils/zod-to-json-schema/index.js +38 -39
  747. package/dist/utils/zod-to-json-schema/parseDef.cjs +5 -6
  748. package/dist/utils/zod-to-json-schema/parseDef.cjs.map +1 -1
  749. package/dist/utils/zod-to-json-schema/parseDef.d.ts +1 -3
  750. package/dist/utils/zod-to-json-schema/parseDef.js +1 -2
  751. package/dist/utils/zod-to-json-schema/parseDef.js.map +1 -1
  752. package/dist/utils/zod-to-json-schema/parsers/any.cjs +2 -3
  753. package/dist/utils/zod-to-json-schema/parsers/any.cjs.map +1 -1
  754. package/dist/utils/zod-to-json-schema/parsers/any.d.ts +0 -2
  755. package/dist/utils/zod-to-json-schema/parsers/any.d.ts.map +1 -1
  756. package/dist/utils/zod-to-json-schema/parsers/any.js +1 -2
  757. package/dist/utils/zod-to-json-schema/parsers/any.js.map +1 -1
  758. package/dist/utils/zod-to-json-schema/parsers/array.cjs +4 -5
  759. package/dist/utils/zod-to-json-schema/parsers/array.cjs.map +1 -1
  760. package/dist/utils/zod-to-json-schema/parsers/array.d.ts +0 -3
  761. package/dist/utils/zod-to-json-schema/parsers/array.d.ts.map +1 -1
  762. package/dist/utils/zod-to-json-schema/parsers/array.js +1 -2
  763. package/dist/utils/zod-to-json-schema/parsers/array.js.map +1 -1
  764. package/dist/utils/zod-to-json-schema/parsers/bigint.cjs +2 -3
  765. package/dist/utils/zod-to-json-schema/parsers/bigint.cjs.map +1 -1
  766. package/dist/utils/zod-to-json-schema/parsers/bigint.d.ts +0 -3
  767. package/dist/utils/zod-to-json-schema/parsers/bigint.d.ts.map +1 -1
  768. package/dist/utils/zod-to-json-schema/parsers/bigint.js +1 -2
  769. package/dist/utils/zod-to-json-schema/parsers/bigint.js.map +1 -1
  770. package/dist/utils/zod-to-json-schema/parsers/boolean.cjs +1 -2
  771. package/dist/utils/zod-to-json-schema/parsers/boolean.cjs.map +1 -1
  772. package/dist/utils/zod-to-json-schema/parsers/boolean.js +1 -1
  773. package/dist/utils/zod-to-json-schema/parsers/branded.cjs +2 -3
  774. package/dist/utils/zod-to-json-schema/parsers/branded.cjs.map +1 -1
  775. package/dist/utils/zod-to-json-schema/parsers/branded.d.ts +1 -3
  776. package/dist/utils/zod-to-json-schema/parsers/branded.js +1 -2
  777. package/dist/utils/zod-to-json-schema/parsers/branded.js.map +1 -1
  778. package/dist/utils/zod-to-json-schema/parsers/catch.cjs +2 -3
  779. package/dist/utils/zod-to-json-schema/parsers/catch.cjs.map +1 -1
  780. package/dist/utils/zod-to-json-schema/parsers/catch.d.ts +1 -3
  781. package/dist/utils/zod-to-json-schema/parsers/catch.js +1 -2
  782. package/dist/utils/zod-to-json-schema/parsers/catch.js.map +1 -1
  783. package/dist/utils/zod-to-json-schema/parsers/date.cjs +2 -3
  784. package/dist/utils/zod-to-json-schema/parsers/date.cjs.map +1 -1
  785. package/dist/utils/zod-to-json-schema/parsers/date.d.ts +0 -4
  786. package/dist/utils/zod-to-json-schema/parsers/date.d.ts.map +1 -1
  787. package/dist/utils/zod-to-json-schema/parsers/date.js +1 -2
  788. package/dist/utils/zod-to-json-schema/parsers/date.js.map +1 -1
  789. package/dist/utils/zod-to-json-schema/parsers/default.cjs +2 -3
  790. package/dist/utils/zod-to-json-schema/parsers/default.cjs.map +1 -1
  791. package/dist/utils/zod-to-json-schema/parsers/default.d.ts +1 -3
  792. package/dist/utils/zod-to-json-schema/parsers/default.js +1 -2
  793. package/dist/utils/zod-to-json-schema/parsers/default.js.map +1 -1
  794. package/dist/utils/zod-to-json-schema/parsers/effects.cjs +3 -4
  795. package/dist/utils/zod-to-json-schema/parsers/effects.cjs.map +1 -1
  796. package/dist/utils/zod-to-json-schema/parsers/effects.d.ts +1 -3
  797. package/dist/utils/zod-to-json-schema/parsers/effects.js +1 -2
  798. package/dist/utils/zod-to-json-schema/parsers/effects.js.map +1 -1
  799. package/dist/utils/zod-to-json-schema/parsers/enum.cjs +1 -2
  800. package/dist/utils/zod-to-json-schema/parsers/enum.cjs.map +1 -1
  801. package/dist/utils/zod-to-json-schema/parsers/enum.d.ts +0 -2
  802. package/dist/utils/zod-to-json-schema/parsers/enum.d.ts.map +1 -1
  803. package/dist/utils/zod-to-json-schema/parsers/enum.js +1 -1
  804. package/dist/utils/zod-to-json-schema/parsers/intersection.cjs +2 -3
  805. package/dist/utils/zod-to-json-schema/parsers/intersection.cjs.map +1 -1
  806. package/dist/utils/zod-to-json-schema/parsers/intersection.d.ts +0 -3
  807. package/dist/utils/zod-to-json-schema/parsers/intersection.d.ts.map +1 -1
  808. package/dist/utils/zod-to-json-schema/parsers/intersection.js +1 -2
  809. package/dist/utils/zod-to-json-schema/parsers/intersection.js.map +1 -1
  810. package/dist/utils/zod-to-json-schema/parsers/literal.cjs +1 -2
  811. package/dist/utils/zod-to-json-schema/parsers/literal.cjs.map +1 -1
  812. package/dist/utils/zod-to-json-schema/parsers/literal.d.ts +0 -3
  813. package/dist/utils/zod-to-json-schema/parsers/literal.d.ts.map +1 -1
  814. package/dist/utils/zod-to-json-schema/parsers/literal.js +1 -1
  815. package/dist/utils/zod-to-json-schema/parsers/map.cjs +4 -5
  816. package/dist/utils/zod-to-json-schema/parsers/map.cjs.map +1 -1
  817. package/dist/utils/zod-to-json-schema/parsers/map.d.ts +0 -4
  818. package/dist/utils/zod-to-json-schema/parsers/map.d.ts.map +1 -1
  819. package/dist/utils/zod-to-json-schema/parsers/map.js +1 -2
  820. package/dist/utils/zod-to-json-schema/parsers/map.js.map +1 -1
  821. package/dist/utils/zod-to-json-schema/parsers/nativeEnum.cjs +1 -2
  822. package/dist/utils/zod-to-json-schema/parsers/nativeEnum.cjs.map +1 -1
  823. package/dist/utils/zod-to-json-schema/parsers/nativeEnum.d.ts +0 -2
  824. package/dist/utils/zod-to-json-schema/parsers/nativeEnum.d.ts.map +1 -1
  825. package/dist/utils/zod-to-json-schema/parsers/nativeEnum.js +1 -1
  826. package/dist/utils/zod-to-json-schema/parsers/never.cjs +2 -3
  827. package/dist/utils/zod-to-json-schema/parsers/never.cjs.map +1 -1
  828. package/dist/utils/zod-to-json-schema/parsers/never.d.ts +0 -2
  829. package/dist/utils/zod-to-json-schema/parsers/never.d.ts.map +1 -1
  830. package/dist/utils/zod-to-json-schema/parsers/never.js +1 -2
  831. package/dist/utils/zod-to-json-schema/parsers/never.js.map +1 -1
  832. package/dist/utils/zod-to-json-schema/parsers/null.cjs +1 -2
  833. package/dist/utils/zod-to-json-schema/parsers/null.cjs.map +1 -1
  834. package/dist/utils/zod-to-json-schema/parsers/null.d.ts +0 -2
  835. package/dist/utils/zod-to-json-schema/parsers/null.d.ts.map +1 -1
  836. package/dist/utils/zod-to-json-schema/parsers/null.js +1 -1
  837. package/dist/utils/zod-to-json-schema/parsers/nullable.cjs +3 -4
  838. package/dist/utils/zod-to-json-schema/parsers/nullable.cjs.map +1 -1
  839. package/dist/utils/zod-to-json-schema/parsers/nullable.d.ts +0 -3
  840. package/dist/utils/zod-to-json-schema/parsers/nullable.d.ts.map +1 -1
  841. package/dist/utils/zod-to-json-schema/parsers/nullable.js +1 -2
  842. package/dist/utils/zod-to-json-schema/parsers/nullable.js.map +1 -1
  843. package/dist/utils/zod-to-json-schema/parsers/number.cjs +2 -3
  844. package/dist/utils/zod-to-json-schema/parsers/number.cjs.map +1 -1
  845. package/dist/utils/zod-to-json-schema/parsers/number.d.ts +0 -3
  846. package/dist/utils/zod-to-json-schema/parsers/number.d.ts.map +1 -1
  847. package/dist/utils/zod-to-json-schema/parsers/number.js +1 -2
  848. package/dist/utils/zod-to-json-schema/parsers/number.js.map +1 -1
  849. package/dist/utils/zod-to-json-schema/parsers/object.cjs +2 -3
  850. package/dist/utils/zod-to-json-schema/parsers/object.cjs.map +1 -1
  851. package/dist/utils/zod-to-json-schema/parsers/object.d.ts +0 -3
  852. package/dist/utils/zod-to-json-schema/parsers/object.d.ts.map +1 -1
  853. package/dist/utils/zod-to-json-schema/parsers/object.js +1 -2
  854. package/dist/utils/zod-to-json-schema/parsers/object.js.map +1 -1
  855. package/dist/utils/zod-to-json-schema/parsers/optional.cjs +3 -4
  856. package/dist/utils/zod-to-json-schema/parsers/optional.cjs.map +1 -1
  857. package/dist/utils/zod-to-json-schema/parsers/optional.d.ts +1 -3
  858. package/dist/utils/zod-to-json-schema/parsers/optional.js +1 -2
  859. package/dist/utils/zod-to-json-schema/parsers/optional.js.map +1 -1
  860. package/dist/utils/zod-to-json-schema/parsers/pipeline.cjs +2 -3
  861. package/dist/utils/zod-to-json-schema/parsers/pipeline.cjs.map +1 -1
  862. package/dist/utils/zod-to-json-schema/parsers/pipeline.d.ts +1 -4
  863. package/dist/utils/zod-to-json-schema/parsers/pipeline.js +1 -2
  864. package/dist/utils/zod-to-json-schema/parsers/pipeline.js.map +1 -1
  865. package/dist/utils/zod-to-json-schema/parsers/promise.cjs +2 -3
  866. package/dist/utils/zod-to-json-schema/parsers/promise.cjs.map +1 -1
  867. package/dist/utils/zod-to-json-schema/parsers/promise.d.ts +1 -3
  868. package/dist/utils/zod-to-json-schema/parsers/promise.js +1 -2
  869. package/dist/utils/zod-to-json-schema/parsers/promise.js.map +1 -1
  870. package/dist/utils/zod-to-json-schema/parsers/readonly.cjs +2 -3
  871. package/dist/utils/zod-to-json-schema/parsers/readonly.cjs.map +1 -1
  872. package/dist/utils/zod-to-json-schema/parsers/readonly.d.ts +1 -3
  873. package/dist/utils/zod-to-json-schema/parsers/readonly.js +1 -2
  874. package/dist/utils/zod-to-json-schema/parsers/readonly.js.map +1 -1
  875. package/dist/utils/zod-to-json-schema/parsers/record.cjs +6 -7
  876. package/dist/utils/zod-to-json-schema/parsers/record.cjs.map +1 -1
  877. package/dist/utils/zod-to-json-schema/parsers/record.d.ts +0 -3
  878. package/dist/utils/zod-to-json-schema/parsers/record.d.ts.map +1 -1
  879. package/dist/utils/zod-to-json-schema/parsers/record.js +1 -2
  880. package/dist/utils/zod-to-json-schema/parsers/record.js.map +1 -1
  881. package/dist/utils/zod-to-json-schema/parsers/set.cjs +3 -4
  882. package/dist/utils/zod-to-json-schema/parsers/set.cjs.map +1 -1
  883. package/dist/utils/zod-to-json-schema/parsers/set.d.ts +0 -3
  884. package/dist/utils/zod-to-json-schema/parsers/set.d.ts.map +1 -1
  885. package/dist/utils/zod-to-json-schema/parsers/set.js +1 -2
  886. package/dist/utils/zod-to-json-schema/parsers/set.js.map +1 -1
  887. package/dist/utils/zod-to-json-schema/parsers/string.cjs +2 -3
  888. package/dist/utils/zod-to-json-schema/parsers/string.cjs.map +1 -1
  889. package/dist/utils/zod-to-json-schema/parsers/string.d.ts +0 -3
  890. package/dist/utils/zod-to-json-schema/parsers/string.d.ts.map +1 -1
  891. package/dist/utils/zod-to-json-schema/parsers/string.js +1 -2
  892. package/dist/utils/zod-to-json-schema/parsers/string.js.map +1 -1
  893. package/dist/utils/zod-to-json-schema/parsers/tuple.cjs +2 -3
  894. package/dist/utils/zod-to-json-schema/parsers/tuple.cjs.map +1 -1
  895. package/dist/utils/zod-to-json-schema/parsers/tuple.d.ts +0 -3
  896. package/dist/utils/zod-to-json-schema/parsers/tuple.d.ts.map +1 -1
  897. package/dist/utils/zod-to-json-schema/parsers/tuple.js +1 -2
  898. package/dist/utils/zod-to-json-schema/parsers/tuple.js.map +1 -1
  899. package/dist/utils/zod-to-json-schema/parsers/undefined.cjs +2 -3
  900. package/dist/utils/zod-to-json-schema/parsers/undefined.cjs.map +1 -1
  901. package/dist/utils/zod-to-json-schema/parsers/undefined.d.ts +0 -2
  902. package/dist/utils/zod-to-json-schema/parsers/undefined.d.ts.map +1 -1
  903. package/dist/utils/zod-to-json-schema/parsers/undefined.js +1 -2
  904. package/dist/utils/zod-to-json-schema/parsers/undefined.js.map +1 -1
  905. package/dist/utils/zod-to-json-schema/parsers/union.cjs +2 -3
  906. package/dist/utils/zod-to-json-schema/parsers/union.cjs.map +1 -1
  907. package/dist/utils/zod-to-json-schema/parsers/union.d.ts +0 -3
  908. package/dist/utils/zod-to-json-schema/parsers/union.d.ts.map +1 -1
  909. package/dist/utils/zod-to-json-schema/parsers/union.js +1 -2
  910. package/dist/utils/zod-to-json-schema/parsers/union.js.map +1 -1
  911. package/dist/utils/zod-to-json-schema/parsers/unknown.cjs +2 -3
  912. package/dist/utils/zod-to-json-schema/parsers/unknown.cjs.map +1 -1
  913. package/dist/utils/zod-to-json-schema/parsers/unknown.d.ts +0 -2
  914. package/dist/utils/zod-to-json-schema/parsers/unknown.d.ts.map +1 -1
  915. package/dist/utils/zod-to-json-schema/parsers/unknown.js +1 -2
  916. package/dist/utils/zod-to-json-schema/parsers/unknown.js.map +1 -1
  917. package/dist/utils/zod-to-json-schema/selectParser.cjs +32 -33
  918. package/dist/utils/zod-to-json-schema/selectParser.cjs.map +1 -1
  919. package/dist/utils/zod-to-json-schema/selectParser.d.ts +0 -2
  920. package/dist/utils/zod-to-json-schema/selectParser.js +1 -2
  921. package/dist/utils/zod-to-json-schema/selectParser.js.map +1 -1
  922. package/dist/utils/zod-to-json-schema/zodToJsonSchema.cjs +4 -5
  923. package/dist/utils/zod-to-json-schema/zodToJsonSchema.cjs.map +1 -1
  924. package/dist/utils/zod-to-json-schema/zodToJsonSchema.d.ts +1 -3
  925. package/dist/utils/zod-to-json-schema/zodToJsonSchema.js +1 -2
  926. package/dist/utils/zod-to-json-schema/zodToJsonSchema.js.map +1 -1
  927. package/dist/vectorstores.cjs +10 -11
  928. package/dist/vectorstores.cjs.map +1 -1
  929. package/dist/vectorstores.js +1 -2
  930. package/dist/vectorstores.js.map +1 -1
  931. package/package.json +1 -1
  932. package/agents.cjs +0 -1
  933. package/agents.d.cts +0 -1
  934. package/agents.d.ts +0 -1
  935. package/agents.js +0 -1
  936. package/caches.cjs +0 -1
  937. package/caches.d.cts +0 -1
  938. package/caches.d.ts +0 -1
  939. package/caches.js +0 -1
  940. package/callbacks/base.cjs +0 -1
  941. package/callbacks/base.d.cts +0 -1
  942. package/callbacks/base.d.ts +0 -1
  943. package/callbacks/base.js +0 -1
  944. package/callbacks/dispatch/web.cjs +0 -1
  945. package/callbacks/dispatch/web.d.cts +0 -1
  946. package/callbacks/dispatch/web.d.ts +0 -1
  947. package/callbacks/dispatch/web.js +0 -1
  948. package/callbacks/dispatch.cjs +0 -1
  949. package/callbacks/dispatch.d.cts +0 -1
  950. package/callbacks/dispatch.d.ts +0 -1
  951. package/callbacks/dispatch.js +0 -1
  952. package/callbacks/manager.cjs +0 -1
  953. package/callbacks/manager.d.cts +0 -1
  954. package/callbacks/manager.d.ts +0 -1
  955. package/callbacks/manager.js +0 -1
  956. package/callbacks/promises.cjs +0 -1
  957. package/callbacks/promises.d.cts +0 -1
  958. package/callbacks/promises.d.ts +0 -1
  959. package/callbacks/promises.js +0 -1
  960. package/chat_history.cjs +0 -1
  961. package/chat_history.d.cts +0 -1
  962. package/chat_history.d.ts +0 -1
  963. package/chat_history.js +0 -1
  964. package/context.cjs +0 -1
  965. package/context.d.cts +0 -1
  966. package/context.d.ts +0 -1
  967. package/context.js +0 -1
  968. package/document_loaders/base.cjs +0 -1
  969. package/document_loaders/base.d.cts +0 -1
  970. package/document_loaders/base.d.ts +0 -1
  971. package/document_loaders/base.js +0 -1
  972. package/document_loaders/langsmith.cjs +0 -1
  973. package/document_loaders/langsmith.d.cts +0 -1
  974. package/document_loaders/langsmith.d.ts +0 -1
  975. package/document_loaders/langsmith.js +0 -1
  976. package/documents.cjs +0 -1
  977. package/documents.d.cts +0 -1
  978. package/documents.d.ts +0 -1
  979. package/documents.js +0 -1
  980. package/embeddings.cjs +0 -1
  981. package/embeddings.d.cts +0 -1
  982. package/embeddings.d.ts +0 -1
  983. package/embeddings.js +0 -1
  984. package/errors.cjs +0 -1
  985. package/errors.d.cts +0 -1
  986. package/errors.d.ts +0 -1
  987. package/errors.js +0 -1
  988. package/example_selectors.cjs +0 -1
  989. package/example_selectors.d.cts +0 -1
  990. package/example_selectors.d.ts +0 -1
  991. package/example_selectors.js +0 -1
  992. package/indexing.cjs +0 -1
  993. package/indexing.d.cts +0 -1
  994. package/indexing.d.ts +0 -1
  995. package/indexing.js +0 -1
  996. package/language_models/base.cjs +0 -1
  997. package/language_models/base.d.cts +0 -1
  998. package/language_models/base.d.ts +0 -1
  999. package/language_models/base.js +0 -1
  1000. package/language_models/chat_models.cjs +0 -1
  1001. package/language_models/chat_models.d.cts +0 -1
  1002. package/language_models/chat_models.d.ts +0 -1
  1003. package/language_models/chat_models.js +0 -1
  1004. package/language_models/llms.cjs +0 -1
  1005. package/language_models/llms.d.cts +0 -1
  1006. package/language_models/llms.d.ts +0 -1
  1007. package/language_models/llms.js +0 -1
  1008. package/language_models/profile.cjs +0 -1
  1009. package/language_models/profile.d.cts +0 -1
  1010. package/language_models/profile.d.ts +0 -1
  1011. package/language_models/profile.js +0 -1
  1012. package/language_models/structured_output.cjs +0 -1
  1013. package/language_models/structured_output.d.cts +0 -1
  1014. package/language_models/structured_output.d.ts +0 -1
  1015. package/language_models/structured_output.js +0 -1
  1016. package/load/serializable.cjs +0 -1
  1017. package/load/serializable.d.cts +0 -1
  1018. package/load/serializable.d.ts +0 -1
  1019. package/load/serializable.js +0 -1
  1020. package/load.cjs +0 -1
  1021. package/load.d.cts +0 -1
  1022. package/load.d.ts +0 -1
  1023. package/load.js +0 -1
  1024. package/memory.cjs +0 -1
  1025. package/memory.d.cts +0 -1
  1026. package/memory.d.ts +0 -1
  1027. package/memory.js +0 -1
  1028. package/messages/tool.cjs +0 -1
  1029. package/messages/tool.d.cts +0 -1
  1030. package/messages/tool.d.ts +0 -1
  1031. package/messages/tool.js +0 -1
  1032. package/messages.cjs +0 -1
  1033. package/messages.d.cts +0 -1
  1034. package/messages.d.ts +0 -1
  1035. package/messages.js +0 -1
  1036. package/output_parsers/openai_functions.cjs +0 -1
  1037. package/output_parsers/openai_functions.d.cts +0 -1
  1038. package/output_parsers/openai_functions.d.ts +0 -1
  1039. package/output_parsers/openai_functions.js +0 -1
  1040. package/output_parsers/openai_tools.cjs +0 -1
  1041. package/output_parsers/openai_tools.d.cts +0 -1
  1042. package/output_parsers/openai_tools.d.ts +0 -1
  1043. package/output_parsers/openai_tools.js +0 -1
  1044. package/output_parsers.cjs +0 -1
  1045. package/output_parsers.d.cts +0 -1
  1046. package/output_parsers.d.ts +0 -1
  1047. package/output_parsers.js +0 -1
  1048. package/outputs.cjs +0 -1
  1049. package/outputs.d.cts +0 -1
  1050. package/outputs.d.ts +0 -1
  1051. package/outputs.js +0 -1
  1052. package/prompt_values.cjs +0 -1
  1053. package/prompt_values.d.cts +0 -1
  1054. package/prompt_values.d.ts +0 -1
  1055. package/prompt_values.js +0 -1
  1056. package/prompts.cjs +0 -1
  1057. package/prompts.d.cts +0 -1
  1058. package/prompts.d.ts +0 -1
  1059. package/prompts.js +0 -1
  1060. package/retrievers/document_compressors.cjs +0 -1
  1061. package/retrievers/document_compressors.d.cts +0 -1
  1062. package/retrievers/document_compressors.d.ts +0 -1
  1063. package/retrievers/document_compressors.js +0 -1
  1064. package/retrievers.cjs +0 -1
  1065. package/retrievers.d.cts +0 -1
  1066. package/retrievers.d.ts +0 -1
  1067. package/retrievers.js +0 -1
  1068. package/runnables/graph.cjs +0 -1
  1069. package/runnables/graph.d.cts +0 -1
  1070. package/runnables/graph.d.ts +0 -1
  1071. package/runnables/graph.js +0 -1
  1072. package/runnables.cjs +0 -1
  1073. package/runnables.d.cts +0 -1
  1074. package/runnables.d.ts +0 -1
  1075. package/runnables.js +0 -1
  1076. package/singletons.cjs +0 -1
  1077. package/singletons.d.cts +0 -1
  1078. package/singletons.d.ts +0 -1
  1079. package/singletons.js +0 -1
  1080. package/stores.cjs +0 -1
  1081. package/stores.d.cts +0 -1
  1082. package/stores.d.ts +0 -1
  1083. package/stores.js +0 -1
  1084. package/structured_query.cjs +0 -1
  1085. package/structured_query.d.cts +0 -1
  1086. package/structured_query.d.ts +0 -1
  1087. package/structured_query.js +0 -1
  1088. package/tools.cjs +0 -1
  1089. package/tools.d.cts +0 -1
  1090. package/tools.d.ts +0 -1
  1091. package/tools.js +0 -1
  1092. package/tracers/base.cjs +0 -1
  1093. package/tracers/base.d.cts +0 -1
  1094. package/tracers/base.d.ts +0 -1
  1095. package/tracers/base.js +0 -1
  1096. package/tracers/console.cjs +0 -1
  1097. package/tracers/console.d.cts +0 -1
  1098. package/tracers/console.d.ts +0 -1
  1099. package/tracers/console.js +0 -1
  1100. package/tracers/log_stream.cjs +0 -1
  1101. package/tracers/log_stream.d.cts +0 -1
  1102. package/tracers/log_stream.d.ts +0 -1
  1103. package/tracers/log_stream.js +0 -1
  1104. package/tracers/run_collector.cjs +0 -1
  1105. package/tracers/run_collector.d.cts +0 -1
  1106. package/tracers/run_collector.d.ts +0 -1
  1107. package/tracers/run_collector.js +0 -1
  1108. package/tracers/tracer_langchain.cjs +0 -1
  1109. package/tracers/tracer_langchain.d.cts +0 -1
  1110. package/tracers/tracer_langchain.d.ts +0 -1
  1111. package/tracers/tracer_langchain.js +0 -1
  1112. package/types/stream.cjs +0 -1
  1113. package/types/stream.d.cts +0 -1
  1114. package/types/stream.d.ts +0 -1
  1115. package/types/stream.js +0 -1
  1116. package/utils/async_caller.cjs +0 -1
  1117. package/utils/async_caller.d.cts +0 -1
  1118. package/utils/async_caller.d.ts +0 -1
  1119. package/utils/async_caller.js +0 -1
  1120. package/utils/chunk_array.cjs +0 -1
  1121. package/utils/chunk_array.d.cts +0 -1
  1122. package/utils/chunk_array.d.ts +0 -1
  1123. package/utils/chunk_array.js +0 -1
  1124. package/utils/context.cjs +0 -1
  1125. package/utils/context.d.cts +0 -1
  1126. package/utils/context.d.ts +0 -1
  1127. package/utils/context.js +0 -1
  1128. package/utils/env.cjs +0 -1
  1129. package/utils/env.d.cts +0 -1
  1130. package/utils/env.d.ts +0 -1
  1131. package/utils/env.js +0 -1
  1132. package/utils/event_source_parse.cjs +0 -1
  1133. package/utils/event_source_parse.d.cts +0 -1
  1134. package/utils/event_source_parse.d.ts +0 -1
  1135. package/utils/event_source_parse.js +0 -1
  1136. package/utils/format.cjs +0 -1
  1137. package/utils/format.d.cts +0 -1
  1138. package/utils/format.d.ts +0 -1
  1139. package/utils/format.js +0 -1
  1140. package/utils/function_calling.cjs +0 -1
  1141. package/utils/function_calling.d.cts +0 -1
  1142. package/utils/function_calling.d.ts +0 -1
  1143. package/utils/function_calling.js +0 -1
  1144. package/utils/hash.cjs +0 -1
  1145. package/utils/hash.d.cts +0 -1
  1146. package/utils/hash.d.ts +0 -1
  1147. package/utils/hash.js +0 -1
  1148. package/utils/json_patch.cjs +0 -1
  1149. package/utils/json_patch.d.cts +0 -1
  1150. package/utils/json_patch.d.ts +0 -1
  1151. package/utils/json_patch.js +0 -1
  1152. package/utils/json_schema.cjs +0 -1
  1153. package/utils/json_schema.d.cts +0 -1
  1154. package/utils/json_schema.d.ts +0 -1
  1155. package/utils/json_schema.js +0 -1
  1156. package/utils/math.cjs +0 -1
  1157. package/utils/math.d.cts +0 -1
  1158. package/utils/math.d.ts +0 -1
  1159. package/utils/math.js +0 -1
  1160. package/utils/ssrf.cjs +0 -1
  1161. package/utils/ssrf.d.cts +0 -1
  1162. package/utils/ssrf.d.ts +0 -1
  1163. package/utils/ssrf.js +0 -1
  1164. package/utils/standard_schema.cjs +0 -1
  1165. package/utils/standard_schema.d.cts +0 -1
  1166. package/utils/standard_schema.d.ts +0 -1
  1167. package/utils/standard_schema.js +0 -1
  1168. package/utils/stream.cjs +0 -1
  1169. package/utils/stream.d.cts +0 -1
  1170. package/utils/stream.d.ts +0 -1
  1171. package/utils/stream.js +0 -1
  1172. package/utils/testing.cjs +0 -1
  1173. package/utils/testing.d.cts +0 -1
  1174. package/utils/testing.d.ts +0 -1
  1175. package/utils/testing.js +0 -1
  1176. package/utils/tiktoken.cjs +0 -1
  1177. package/utils/tiktoken.d.cts +0 -1
  1178. package/utils/tiktoken.d.ts +0 -1
  1179. package/utils/tiktoken.js +0 -1
  1180. package/utils/types.cjs +0 -1
  1181. package/utils/types.d.cts +0 -1
  1182. package/utils/types.d.ts +0 -1
  1183. package/utils/types.js +0 -1
  1184. package/vectorstores.cjs +0 -1
  1185. package/vectorstores.d.cts +0 -1
  1186. package/vectorstores.d.ts +0 -1
  1187. package/vectorstores.js +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"graph_mermaid.cjs","names":["toBase64Url"],"sources":["../../src/runnables/graph_mermaid.ts"],"sourcesContent":["import { Edge, Node } from \"./types.js\";\nimport { toBase64Url } from \"./utils.js\";\n\nfunction _escapeNodeLabel(nodeLabel: string): string {\n // Escapes the node label for Mermaid syntax.\n return nodeLabel.replace(/[^a-zA-Z-_0-9]/g, \"_\");\n}\n\nconst MARKDOWN_SPECIAL_CHARS = [\"*\", \"_\", \"`\"];\n\nfunction _generateMermaidGraphStyles(\n nodeColors: Record<string, string>\n): string {\n let styles = \"\";\n for (const [className, color] of Object.entries(nodeColors)) {\n styles += `\\tclassDef ${className} ${color};\\n`;\n }\n return styles;\n}\n\n/**\n * Draws a Mermaid graph using the provided graph data\n */\nexport function drawMermaid(\n nodes: Record<string, Node>,\n edges: Edge[],\n config?: {\n firstNode?: string;\n lastNode?: string;\n curveStyle?: string;\n withStyles?: boolean;\n nodeColors?: Record<string, string>;\n wrapLabelNWords?: number;\n }\n): string {\n const {\n firstNode,\n lastNode,\n nodeColors,\n withStyles = true,\n curveStyle = \"linear\",\n wrapLabelNWords = 9,\n } = config ?? {};\n // Initialize Mermaid graph configuration\n let mermaidGraph = withStyles\n ? `%%{init: {'flowchart': {'curve': '${curveStyle}'}}}%%\\ngraph TD;\\n`\n : \"graph TD;\\n\";\n if (withStyles) {\n // Node formatting templates\n const defaultClassLabel = \"default\";\n const formatDict: Record<string, string> = {\n [defaultClassLabel]: \"{0}({1})\",\n };\n if (firstNode !== undefined) {\n formatDict[firstNode] = \"{0}([{1}]):::first\";\n }\n if (lastNode !== undefined) {\n formatDict[lastNode] = \"{0}([{1}]):::last\";\n }\n\n // Add nodes to the graph\n for (const [key, node] of Object.entries(nodes)) {\n const nodeName = node.name.split(\":\").pop() ?? \"\";\n const label = MARKDOWN_SPECIAL_CHARS.some(\n (char) => nodeName.startsWith(char) && nodeName.endsWith(char)\n )\n ? `<p>${nodeName}</p>`\n : nodeName;\n\n let finalLabel = label;\n if (Object.keys(node.metadata ?? {}).length) {\n finalLabel += `<hr/><small><em>${Object.entries(node.metadata ?? {})\n .map(([k, v]) => `${k} = ${v}`)\n .join(\"\\n\")}</em></small>`;\n }\n\n const nodeLabel = (formatDict[key] ?? formatDict[defaultClassLabel])\n .replace(\"{0}\", _escapeNodeLabel(key))\n .replace(\"{1}\", finalLabel);\n\n mermaidGraph += `\\t${nodeLabel}\\n`;\n }\n }\n\n // Group edges by their common prefixes\n const edgeGroups: Record<string, Edge[]> = {};\n for (const edge of edges) {\n const srcParts = edge.source.split(\":\");\n const tgtParts = edge.target.split(\":\");\n const commonPrefix = srcParts\n .filter((src, i) => src === tgtParts[i])\n .join(\":\");\n if (!edgeGroups[commonPrefix]) {\n edgeGroups[commonPrefix] = [];\n }\n edgeGroups[commonPrefix].push(edge);\n }\n\n const seenSubgraphs = new Set<string>();\n\n // sort prefixes by path length for correct nesting\n function sortPrefixesByDepth(prefixes: string[]): string[] {\n return [...prefixes].sort((a, b) => {\n return a.split(\":\").length - b.split(\":\").length;\n });\n }\n\n function addSubgraph(edges: Edge[], prefix: string): void {\n const selfLoop = edges.length === 1 && edges[0].source === edges[0].target;\n if (prefix && !selfLoop) {\n const subgraph = prefix.split(\":\").pop()!;\n\n if (seenSubgraphs.has(prefix)) {\n throw new Error(\n `Found duplicate subgraph '${subgraph}' at '${prefix} -- this likely means that ` +\n \"you're reusing a subgraph node with the same name. \" +\n \"Please adjust your graph to have subgraph nodes with unique names.\"\n );\n }\n\n seenSubgraphs.add(prefix);\n mermaidGraph += `\\tsubgraph ${subgraph}\\n`;\n }\n\n // all nested prefixes for this level, sorted by depth\n const nestedPrefixes = sortPrefixesByDepth(\n Object.keys(edgeGroups).filter(\n (nestedPrefix) =>\n nestedPrefix.startsWith(`${prefix}:`) &&\n nestedPrefix !== prefix &&\n nestedPrefix.split(\":\").length === prefix.split(\":\").length + 1\n )\n );\n\n for (const nestedPrefix of nestedPrefixes) {\n addSubgraph(edgeGroups[nestedPrefix], nestedPrefix);\n }\n\n for (const edge of edges) {\n const { source, target, data, conditional } = edge;\n\n let edgeLabel = \"\";\n if (data !== undefined) {\n let edgeData = data;\n const words = edgeData.split(\" \");\n if (words.length > wrapLabelNWords) {\n edgeData = Array.from(\n { length: Math.ceil(words.length / wrapLabelNWords) },\n (_, i) =>\n words\n .slice(i * wrapLabelNWords, (i + 1) * wrapLabelNWords)\n .join(\" \")\n ).join(\"&nbsp;<br>&nbsp;\");\n }\n edgeLabel = conditional\n ? ` -. &nbsp;${edgeData}&nbsp; .-> `\n : ` -- &nbsp;${edgeData}&nbsp; --> `;\n } else {\n edgeLabel = conditional ? \" -.-> \" : \" --> \";\n }\n\n mermaidGraph += `\\t${_escapeNodeLabel(\n source\n )}${edgeLabel}${_escapeNodeLabel(target)};\\n`;\n }\n\n if (prefix && !selfLoop) {\n mermaidGraph += \"\\tend\\n\";\n }\n }\n\n // Start with the top-level edges (no common prefix)\n addSubgraph(edgeGroups[\"\"] ?? [], \"\");\n\n // Add remaining top-level subgraphs\n for (const prefix in edgeGroups) {\n if (!prefix.includes(\":\") && prefix !== \"\") {\n addSubgraph(edgeGroups[prefix], prefix);\n }\n }\n\n // Add custom styles for nodes\n if (withStyles) {\n mermaidGraph += _generateMermaidGraphStyles(nodeColors ?? {});\n }\n\n return mermaidGraph;\n}\n\n/**\n * Renders Mermaid graph using the Mermaid.INK API.\n *\n * @example\n * ```javascript\n * const image = await drawMermaidImage(mermaidSyntax, {\n * backgroundColor: \"white\",\n * imageType: \"png\",\n * });\n * fs.writeFileSync(\"image.png\", image);\n * ```\n *\n * @param mermaidSyntax - The Mermaid syntax to render.\n * @param config - The configuration for the image.\n * @returns The image as a Blob.\n */\nexport async function drawMermaidImage(\n mermaidSyntax: string,\n config?: {\n /**\n * The type of image to render.\n * @default \"png\"\n */\n imageType?: \"png\" | \"jpeg\" | \"webp\";\n backgroundColor?: string;\n }\n) {\n let backgroundColor = config?.backgroundColor ?? \"white\";\n const imageType = config?.imageType ?? \"png\";\n\n const mermaidSyntaxEncoded = toBase64Url(mermaidSyntax);\n\n // Check if the background color is a hexadecimal color code using regex\n if (backgroundColor !== undefined) {\n const hexColorPattern = /^#(?:[0-9a-fA-F]{3}){1,2}$/;\n if (!hexColorPattern.test(backgroundColor)) {\n backgroundColor = `!${backgroundColor}`;\n }\n }\n const imageUrl = `https://mermaid.ink/img/${mermaidSyntaxEncoded}?bgColor=${backgroundColor}&type=${imageType}`;\n const res = await fetch(imageUrl);\n if (!res.ok) {\n throw new Error(\n [\n `Failed to render the graph using the Mermaid.INK API.`,\n `Status code: ${res.status}`,\n `Status text: ${res.statusText}`,\n ].join(\"\\n\")\n );\n }\n const content = await res.blob();\n return content;\n}\n"],"mappings":";;;AAGA,SAAS,iBAAiB,WAA2B;AAEnD,QAAO,UAAU,QAAQ,mBAAmB,IAAI;;AAGlD,MAAM,yBAAyB;CAAC;CAAK;CAAK;CAAI;AAE9C,SAAS,4BACP,YACQ;CACR,IAAI,SAAS;AACb,MAAK,MAAM,CAAC,WAAW,UAAU,OAAO,QAAQ,WAAW,CACzD,WAAU,cAAc,UAAU,GAAG,MAAM;AAE7C,QAAO;;;;;AAMT,SAAgB,YACd,OACA,OACA,QAQQ;CACR,MAAM,EACJ,WACA,UACA,YACA,aAAa,MACb,aAAa,UACb,kBAAkB,MAChB,UAAU,EAAE;CAEhB,IAAI,eAAe,aACf,qCAAqC,WAAW,uBAChD;AACJ,KAAI,YAAY;EAEd,MAAM,oBAAoB;EAC1B,MAAM,aAAqC,GACxC,oBAAoB,YACtB;AACD,MAAI,cAAc,OAChB,YAAW,aAAa;AAE1B,MAAI,aAAa,OACf,YAAW,YAAY;AAIzB,OAAK,MAAM,CAAC,KAAK,SAAS,OAAO,QAAQ,MAAM,EAAE;GAC/C,MAAM,WAAW,KAAK,KAAK,MAAM,IAAI,CAAC,KAAK,IAAI;GAO/C,IAAI,aANU,uBAAuB,MAClC,SAAS,SAAS,WAAW,KAAK,IAAI,SAAS,SAAS,KAAK,CAC/D,GACG,MAAM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,QAAQ;CACpG,MAAM,MAAM,MAAM,MAAM,SAAS;AACjC,KAAI,CAAC,IAAI,GACP,OAAM,IAAI,MACR;EACE;EACA,gBAAgB,IAAI;EACpB,gBAAgB,IAAI;EACrB,CAAC,KAAK,KAAK,CACb;AAGH,QADgB,MAAM,IAAI,MAAM"}
1
+ {"version":3,"file":"graph_mermaid.cjs","names":["toBase64Url"],"sources":["../../src/runnables/graph_mermaid.ts"],"sourcesContent":["import { Edge, Node } from \"./types.js\";\nimport { toBase64Url } from \"./utils.js\";\n\nfunction _escapeNodeLabel(nodeLabel: string): string {\n // Escapes the node label for Mermaid syntax.\n return nodeLabel.replace(/[^a-zA-Z-_0-9]/g, \"_\");\n}\n\nconst MARKDOWN_SPECIAL_CHARS = [\"*\", \"_\", \"`\"];\n\nfunction _generateMermaidGraphStyles(\n nodeColors: Record<string, string>\n): string {\n let styles = \"\";\n for (const [className, color] of Object.entries(nodeColors)) {\n styles += `\\tclassDef ${className} ${color};\\n`;\n }\n return styles;\n}\n\n/**\n * Draws a Mermaid graph using the provided graph data\n */\nexport function drawMermaid(\n nodes: Record<string, Node>,\n edges: Edge[],\n config?: {\n firstNode?: string;\n lastNode?: string;\n curveStyle?: string;\n withStyles?: boolean;\n nodeColors?: Record<string, string>;\n wrapLabelNWords?: number;\n }\n): string {\n const {\n firstNode,\n lastNode,\n nodeColors,\n withStyles = true,\n curveStyle = \"linear\",\n wrapLabelNWords = 9,\n } = config ?? {};\n // Initialize Mermaid graph configuration\n let mermaidGraph = withStyles\n ? `%%{init: {'flowchart': {'curve': '${curveStyle}'}}}%%\\ngraph TD;\\n`\n : \"graph TD;\\n\";\n if (withStyles) {\n // Node formatting templates\n const defaultClassLabel = \"default\";\n const formatDict: Record<string, string> = {\n [defaultClassLabel]: \"{0}({1})\",\n };\n if (firstNode !== undefined) {\n formatDict[firstNode] = \"{0}([{1}]):::first\";\n }\n if (lastNode !== undefined) {\n formatDict[lastNode] = \"{0}([{1}]):::last\";\n }\n\n // Add nodes to the graph\n for (const [key, node] of Object.entries(nodes)) {\n const nodeName = node.name.split(\":\").pop() ?? \"\";\n const label = MARKDOWN_SPECIAL_CHARS.some(\n (char) => nodeName.startsWith(char) && nodeName.endsWith(char)\n )\n ? `<p>${nodeName}</p>`\n : nodeName;\n\n let finalLabel = label;\n if (Object.keys(node.metadata ?? {}).length) {\n finalLabel += `<hr/><small><em>${Object.entries(node.metadata ?? {})\n .map(([k, v]) => `${k} = ${v}`)\n .join(\"\\n\")}</em></small>`;\n }\n\n const nodeLabel = (formatDict[key] ?? formatDict[defaultClassLabel])\n .replace(\"{0}\", _escapeNodeLabel(key))\n .replace(\"{1}\", finalLabel);\n\n mermaidGraph += `\\t${nodeLabel}\\n`;\n }\n }\n\n // Group edges by their common prefixes\n const edgeGroups: Record<string, Edge[]> = {};\n for (const edge of edges) {\n const srcParts = edge.source.split(\":\");\n const tgtParts = edge.target.split(\":\");\n const commonPrefix = srcParts\n .filter((src, i) => src === tgtParts[i])\n .join(\":\");\n if (!edgeGroups[commonPrefix]) {\n edgeGroups[commonPrefix] = [];\n }\n edgeGroups[commonPrefix].push(edge);\n }\n\n const seenSubgraphs = new Set<string>();\n\n // sort prefixes by path length for correct nesting\n function sortPrefixesByDepth(prefixes: string[]): string[] {\n return [...prefixes].sort((a, b) => {\n return a.split(\":\").length - b.split(\":\").length;\n });\n }\n\n function addSubgraph(edges: Edge[], prefix: string): void {\n const selfLoop = edges.length === 1 && edges[0].source === edges[0].target;\n if (prefix && !selfLoop) {\n const subgraph = prefix.split(\":\").pop()!;\n\n if (seenSubgraphs.has(prefix)) {\n throw new Error(\n `Found duplicate subgraph '${subgraph}' at '${prefix} -- this likely means that ` +\n \"you're reusing a subgraph node with the same name. \" +\n \"Please adjust your graph to have subgraph nodes with unique names.\"\n );\n }\n\n seenSubgraphs.add(prefix);\n mermaidGraph += `\\tsubgraph ${subgraph}\\n`;\n }\n\n // all nested prefixes for this level, sorted by depth\n const nestedPrefixes = sortPrefixesByDepth(\n Object.keys(edgeGroups).filter(\n (nestedPrefix) =>\n nestedPrefix.startsWith(`${prefix}:`) &&\n nestedPrefix !== prefix &&\n nestedPrefix.split(\":\").length === prefix.split(\":\").length + 1\n )\n );\n\n for (const nestedPrefix of nestedPrefixes) {\n addSubgraph(edgeGroups[nestedPrefix], nestedPrefix);\n }\n\n for (const edge of edges) {\n const { source, target, data, conditional } = edge;\n\n let edgeLabel = \"\";\n if (data !== undefined) {\n let edgeData = data;\n const words = edgeData.split(\" \");\n if (words.length > wrapLabelNWords) {\n edgeData = Array.from(\n { length: Math.ceil(words.length / wrapLabelNWords) },\n (_, i) =>\n words\n .slice(i * wrapLabelNWords, (i + 1) * wrapLabelNWords)\n .join(\" \")\n ).join(\"&nbsp;<br>&nbsp;\");\n }\n edgeLabel = conditional\n ? ` -. &nbsp;${edgeData}&nbsp; .-> `\n : ` -- &nbsp;${edgeData}&nbsp; --> `;\n } else {\n edgeLabel = conditional ? \" -.-> \" : \" --> \";\n }\n\n mermaidGraph += `\\t${_escapeNodeLabel(\n source\n )}${edgeLabel}${_escapeNodeLabel(target)};\\n`;\n }\n\n if (prefix && !selfLoop) {\n mermaidGraph += \"\\tend\\n\";\n }\n }\n\n // Start with the top-level edges (no common prefix)\n addSubgraph(edgeGroups[\"\"] ?? [], \"\");\n\n // Add remaining top-level subgraphs\n for (const prefix in edgeGroups) {\n if (!prefix.includes(\":\") && prefix !== \"\") {\n addSubgraph(edgeGroups[prefix], prefix);\n }\n }\n\n // Add custom styles for nodes\n if (withStyles) {\n mermaidGraph += _generateMermaidGraphStyles(nodeColors ?? {});\n }\n\n return mermaidGraph;\n}\n\n/**\n * Renders Mermaid graph using the Mermaid.INK API.\n *\n * @example\n * ```javascript\n * const image = await drawMermaidImage(mermaidSyntax, {\n * backgroundColor: \"white\",\n * imageType: \"png\",\n * });\n * fs.writeFileSync(\"image.png\", image);\n * ```\n *\n * @param mermaidSyntax - The Mermaid syntax to render.\n * @param config - The configuration for the image.\n * @returns The image as a Blob.\n */\nexport async function drawMermaidImage(\n mermaidSyntax: string,\n config?: {\n /**\n * The type of image to render.\n * @default \"png\"\n */\n imageType?: \"png\" | \"jpeg\" | \"webp\";\n backgroundColor?: string;\n }\n) {\n let backgroundColor = config?.backgroundColor ?? \"white\";\n const imageType = config?.imageType ?? \"png\";\n\n const mermaidSyntaxEncoded = toBase64Url(mermaidSyntax);\n\n // Check if the background color is a hexadecimal color code using regex\n if (backgroundColor !== undefined) {\n const hexColorPattern = /^#(?:[0-9a-fA-F]{3}){1,2}$/;\n if (!hexColorPattern.test(backgroundColor)) {\n backgroundColor = `!${backgroundColor}`;\n }\n }\n const imageUrl = `https://mermaid.ink/img/${mermaidSyntaxEncoded}?bgColor=${backgroundColor}&type=${imageType}`;\n const res = await fetch(imageUrl);\n if (!res.ok) {\n throw new Error(\n [\n `Failed to render the graph using the Mermaid.INK API.`,\n `Status code: ${res.status}`,\n `Status text: ${res.statusText}`,\n ].join(\"\\n\")\n );\n }\n const content = await res.blob();\n return content;\n}\n"],"mappings":";;AAGA,SAAS,iBAAiB,WAA2B;AAEnD,QAAO,UAAU,QAAQ,mBAAmB,IAAI;;AAGlD,MAAM,yBAAyB;CAAC;CAAK;CAAK;CAAI;AAE9C,SAAS,4BACP,YACQ;CACR,IAAI,SAAS;AACb,MAAK,MAAM,CAAC,WAAW,UAAU,OAAO,QAAQ,WAAW,CACzD,WAAU,cAAc,UAAU,GAAG,MAAM;AAE7C,QAAO;;;;;AAMT,SAAgB,YACd,OACA,OACA,QAQQ;CACR,MAAM,EACJ,WACA,UACA,YACA,aAAa,MACb,aAAa,UACb,kBAAkB,MAChB,UAAU,EAAE;CAEhB,IAAI,eAAe,aACf,qCAAqC,WAAW,uBAChD;AACJ,KAAI,YAAY;EAEd,MAAM,oBAAoB;EAC1B,MAAM,aAAqC,GACxC,oBAAoB,YACtB;AACD,MAAI,cAAc,KAAA,EAChB,YAAW,aAAa;AAE1B,MAAI,aAAa,KAAA,EACf,YAAW,YAAY;A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I,kBAAkB,QAAQ,mBAAmB;CACjD,MAAM,YAAY,QAAQ,aAAa;CAEvC,MAAM,uBAAuBA,cAAAA,YAAY,cAAc;AAGvD,KAAI,oBAAoB,KAAA;MAElB,CADoB,6BACH,KAAK,gBAAgB,CACxC,mBAAkB,IAAI;;CAG1B,MAAM,WAAW,2BAA2B,qBAAqB,WAAW,gBAAgB,QAAQ;CACpG,MAAM,MAAM,MAAM,MAAM,SAAS;AACjC,KAAI,CAAC,IAAI,GACP,OAAM,IAAI,MACR;EACE;EACA,gBAAgB,IAAI;EACpB,gBAAgB,IAAI;EACrB,CAAC,KAAK,KAAK,CACb;AAGH,QADgB,MAAM,IAAI,MAAM"}
@@ -1,5 +1,4 @@
1
1
  import { toBase64Url } from "./utils.js";
2
-
3
2
  //#region src/runnables/graph_mermaid.ts
4
3
  function _escapeNodeLabel(nodeLabel) {
5
4
  return nodeLabel.replace(/[^a-zA-Z-_0-9]/g, "_");
@@ -107,7 +106,7 @@ async function drawMermaidImage(mermaidSyntax, config) {
107
106
  ].join("\n"));
108
107
  return await res.blob();
109
108
  }
110
-
111
109
  //#endregion
112
110
  export { drawMermaid, drawMermaidImage };
111
+
113
112
  //# sourceMappingURL=graph_mermaid.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"graph_mermaid.js","names":[],"sources":["../../src/runnables/graph_mermaid.ts"],"sourcesContent":["import { Edge, Node } from \"./types.js\";\nimport { toBase64Url } from \"./utils.js\";\n\nfunction _escapeNodeLabel(nodeLabel: string): string {\n // Escapes the node label for Mermaid syntax.\n return nodeLabel.replace(/[^a-zA-Z-_0-9]/g, \"_\");\n}\n\nconst MARKDOWN_SPECIAL_CHARS = [\"*\", \"_\", \"`\"];\n\nfunction _generateMermaidGraphStyles(\n nodeColors: Record<string, string>\n): string {\n let styles = \"\";\n for (const [className, color] of Object.entries(nodeColors)) {\n styles += `\\tclassDef ${className} ${color};\\n`;\n }\n return styles;\n}\n\n/**\n * Draws a Mermaid graph using the provided graph data\n */\nexport function drawMermaid(\n nodes: Record<string, Node>,\n edges: Edge[],\n config?: {\n firstNode?: string;\n lastNode?: string;\n curveStyle?: string;\n withStyles?: boolean;\n nodeColors?: Record<string, string>;\n wrapLabelNWords?: number;\n }\n): string {\n const {\n firstNode,\n lastNode,\n nodeColors,\n withStyles = true,\n curveStyle = \"linear\",\n wrapLabelNWords = 9,\n } = config ?? {};\n // Initialize Mermaid graph configuration\n let mermaidGraph = withStyles\n ? `%%{init: {'flowchart': {'curve': '${curveStyle}'}}}%%\\ngraph TD;\\n`\n : \"graph TD;\\n\";\n if (withStyles) {\n // Node formatting templates\n const defaultClassLabel = \"default\";\n const formatDict: Record<string, string> = {\n [defaultClassLabel]: \"{0}({1})\",\n };\n if (firstNode !== undefined) {\n formatDict[firstNode] = \"{0}([{1}]):::first\";\n }\n if (lastNode !== undefined) {\n formatDict[lastNode] = \"{0}([{1}]):::last\";\n }\n\n // Add nodes to the graph\n for (const [key, node] of Object.entries(nodes)) {\n const nodeName = node.name.split(\":\").pop() ?? \"\";\n const label = MARKDOWN_SPECIAL_CHARS.some(\n (char) => nodeName.startsWith(char) && nodeName.endsWith(char)\n )\n ? `<p>${nodeName}</p>`\n : nodeName;\n\n let finalLabel = label;\n if (Object.keys(node.metadata ?? {}).length) {\n finalLabel += `<hr/><small><em>${Object.entries(node.metadata ?? {})\n .map(([k, v]) => `${k} = ${v}`)\n .join(\"\\n\")}</em></small>`;\n }\n\n const nodeLabel = (formatDict[key] ?? formatDict[defaultClassLabel])\n .replace(\"{0}\", _escapeNodeLabel(key))\n .replace(\"{1}\", finalLabel);\n\n mermaidGraph += `\\t${nodeLabel}\\n`;\n }\n }\n\n // Group edges by their common prefixes\n const edgeGroups: Record<string, Edge[]> = {};\n for (const edge of edges) {\n const srcParts = edge.source.split(\":\");\n const tgtParts = edge.target.split(\":\");\n const commonPrefix = srcParts\n .filter((src, i) => src === tgtParts[i])\n .join(\":\");\n if (!edgeGroups[commonPrefix]) {\n edgeGroups[commonPrefix] = [];\n }\n edgeGroups[commonPrefix].push(edge);\n }\n\n const seenSubgraphs = new Set<string>();\n\n // sort prefixes by path length for correct nesting\n function sortPrefixesByDepth(prefixes: string[]): string[] {\n return [...prefixes].sort((a, b) => {\n return a.split(\":\").length - b.split(\":\").length;\n });\n }\n\n function addSubgraph(edges: Edge[], prefix: string): void {\n const selfLoop = edges.length === 1 && edges[0].source === edges[0].target;\n if (prefix && !selfLoop) {\n const subgraph = prefix.split(\":\").pop()!;\n\n if (seenSubgraphs.has(prefix)) {\n throw new Error(\n `Found duplicate subgraph '${subgraph}' at '${prefix} -- this likely means that ` +\n \"you're reusing a subgraph node with the same name. \" +\n \"Please adjust your graph to have subgraph nodes with unique names.\"\n );\n }\n\n seenSubgraphs.add(prefix);\n mermaidGraph += `\\tsubgraph ${subgraph}\\n`;\n }\n\n // all nested prefixes for this level, sorted by depth\n const nestedPrefixes = sortPrefixesByDepth(\n Object.keys(edgeGroups).filter(\n (nestedPrefix) =>\n nestedPrefix.startsWith(`${prefix}:`) &&\n nestedPrefix !== prefix &&\n nestedPrefix.split(\":\").length === prefix.split(\":\").length + 1\n )\n );\n\n for (const nestedPrefix of nestedPrefixes) {\n addSubgraph(edgeGroups[nestedPrefix], nestedPrefix);\n }\n\n for (const edge of edges) {\n const { source, target, data, conditional } = edge;\n\n let edgeLabel = \"\";\n if (data !== undefined) {\n let edgeData = data;\n const words = edgeData.split(\" \");\n if (words.length > wrapLabelNWords) {\n edgeData = Array.from(\n { length: Math.ceil(words.length / wrapLabelNWords) },\n (_, i) =>\n words\n .slice(i * wrapLabelNWords, (i + 1) * wrapLabelNWords)\n .join(\" \")\n ).join(\"&nbsp;<br>&nbsp;\");\n }\n edgeLabel = conditional\n ? ` -. &nbsp;${edgeData}&nbsp; .-> `\n : ` -- &nbsp;${edgeData}&nbsp; --> `;\n } else {\n edgeLabel = conditional ? \" -.-> \" : \" --> \";\n }\n\n mermaidGraph += `\\t${_escapeNodeLabel(\n source\n )}${edgeLabel}${_escapeNodeLabel(target)};\\n`;\n }\n\n if (prefix && !selfLoop) {\n mermaidGraph += \"\\tend\\n\";\n }\n }\n\n // Start with the top-level edges (no common prefix)\n addSubgraph(edgeGroups[\"\"] ?? [], \"\");\n\n // Add remaining top-level subgraphs\n for (const prefix in edgeGroups) {\n if (!prefix.includes(\":\") && prefix !== \"\") {\n addSubgraph(edgeGroups[prefix], prefix);\n }\n }\n\n // Add custom styles for nodes\n if (withStyles) {\n mermaidGraph += _generateMermaidGraphStyles(nodeColors ?? {});\n }\n\n return mermaidGraph;\n}\n\n/**\n * Renders Mermaid graph using the Mermaid.INK API.\n *\n * @example\n * ```javascript\n * const image = await drawMermaidImage(mermaidSyntax, {\n * backgroundColor: \"white\",\n * imageType: \"png\",\n * });\n * fs.writeFileSync(\"image.png\", image);\n * ```\n *\n * @param mermaidSyntax - The Mermaid syntax to render.\n * @param config - The configuration for the image.\n * @returns The image as a Blob.\n */\nexport async function drawMermaidImage(\n mermaidSyntax: string,\n config?: {\n /**\n * The type of image to render.\n * @default \"png\"\n */\n imageType?: \"png\" | \"jpeg\" | \"webp\";\n backgroundColor?: string;\n }\n) {\n let backgroundColor = config?.backgroundColor ?? \"white\";\n const imageType = config?.imageType ?? \"png\";\n\n const mermaidSyntaxEncoded = toBase64Url(mermaidSyntax);\n\n // Check if the background color is a hexadecimal color code using regex\n if (backgroundColor !== undefined) {\n const hexColorPattern = /^#(?:[0-9a-fA-F]{3}){1,2}$/;\n if (!hexColorPattern.test(backgroundColor)) {\n backgroundColor = `!${backgroundColor}`;\n }\n }\n const imageUrl = `https://mermaid.ink/img/${mermaidSyntaxEncoded}?bgColor=${backgroundColor}&type=${imageType}`;\n const res = await fetch(imageUrl);\n if (!res.ok) {\n throw new Error(\n [\n `Failed to render the graph using the Mermaid.INK API.`,\n `Status code: ${res.status}`,\n `Status text: ${res.statusText}`,\n ].join(\"\\n\")\n );\n }\n const content = await res.blob();\n return content;\n}\n"],"mappings":";;;AAGA,SAAS,iBAAiB,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,MACF,MACG,MAAM,IAAI,kBAAkB,IAAI,KAAK,gBAAgB,CACrD,KAAK,IAAI,CACf,CAAC,KAAK,mBAAmB;AAE5B,gBAAY,cACR,aAAa,SAAS,eACtB,aAAa,SAAS;SAE1B,aAAY,cAAc,WAAW;AAGvC,mBAAgB,KAAK,iBACnB,OACD,GAAG,YAAY,iBAAiB,OAAO,CAAC;;AAG3C,MAAI,UAAU,CAAC,SACb,iBAAgB;;AAKpB,aAAY,WAAW,OAAO,EAAE,EAAE,GAAG;AAGrC,MAAK,MAAM,UAAU,WACnB,KAAI,CAAC,OAAO,SAAS,IAAI,IAAI,WAAW,GACtC,aAAY,WAAW,SAAS,OAAO;AAK3C,KAAI,WACF,iBAAgB,4BAA4B,cAAc,EAAE,CAAC;AAG/D,QAAO;;;;;;;;;;;;;;;;;;AAmBT,eAAsB,iBACpB,eACA,QAQA;CACA,IAAI,kBAAkB,QAAQ,mBAAmB;CACjD,MAAM,YAAY,QAAQ,aAAa;CAEvC,MAAM,uBAAuB,YAAY,cAAc;AAGvD,KAAI,oBAAoB,QAEtB;MAAI,CADoB,6BACH,KAAK,gBAAgB,CACxC,mBAAkB,IAAI;;CAG1B,MAAM,WAAW,2BAA2B,qBAAqB,WAAW,gBAAgB,QAAQ;CACpG,MAAM,MAAM,MAAM,MAAM,SAAS;AACjC,KAAI,CAAC,IAAI,GACP,OAAM,IAAI,MACR;EACE;EACA,gBAAgB,IAAI;EACpB,gBAAgB,IAAI;EACrB,CAAC,KAAK,KAAK,CACb;AAGH,QADgB,MAAM,IAAI,MAAM"}
1
+ {"version":3,"file":"graph_mermaid.js","names":[],"sources":["../../src/runnables/graph_mermaid.ts"],"sourcesContent":["import { Edge, Node } from \"./types.js\";\nimport { toBase64Url } from \"./utils.js\";\n\nfunction _escapeNodeLabel(nodeLabel: string): string {\n // Escapes the node label for Mermaid syntax.\n return nodeLabel.replace(/[^a-zA-Z-_0-9]/g, \"_\");\n}\n\nconst MARKDOWN_SPECIAL_CHARS = [\"*\", \"_\", \"`\"];\n\nfunction _generateMermaidGraphStyles(\n nodeColors: Record<string, string>\n): string {\n let styles = \"\";\n for (const [className, color] of Object.entries(nodeColors)) {\n styles += `\\tclassDef ${className} ${color};\\n`;\n }\n return styles;\n}\n\n/**\n * Draws a Mermaid graph using the provided graph data\n */\nexport function drawMermaid(\n nodes: Record<string, Node>,\n edges: Edge[],\n config?: {\n firstNode?: string;\n lastNode?: string;\n curveStyle?: string;\n withStyles?: boolean;\n nodeColors?: Record<string, string>;\n wrapLabelNWords?: number;\n }\n): string {\n const {\n firstNode,\n lastNode,\n nodeColors,\n withStyles = true,\n curveStyle = \"linear\",\n wrapLabelNWords = 9,\n } = config ?? {};\n // Initialize Mermaid graph configuration\n let mermaidGraph = withStyles\n ? `%%{init: {'flowchart': {'curve': '${curveStyle}'}}}%%\\ngraph TD;\\n`\n : \"graph TD;\\n\";\n if (withStyles) {\n // Node formatting templates\n const defaultClassLabel = \"default\";\n const formatDict: Record<string, string> = {\n [defaultClassLabel]: \"{0}({1})\",\n };\n if (firstNode !== undefined) {\n formatDict[firstNode] = \"{0}([{1}]):::first\";\n }\n if (lastNode !== undefined) {\n formatDict[lastNode] = \"{0}([{1}]):::last\";\n }\n\n // Add nodes to the graph\n for (const [key, node] of Object.entries(nodes)) {\n const nodeName = node.name.split(\":\").pop() ?? \"\";\n const label = MARKDOWN_SPECIAL_CHARS.some(\n (char) => nodeName.startsWith(char) && nodeName.endsWith(char)\n )\n ? `<p>${nodeName}</p>`\n : nodeName;\n\n let finalLabel = label;\n if (Object.keys(node.metadata ?? {}).length) {\n finalLabel += `<hr/><small><em>${Object.entries(node.metadata ?? {})\n .map(([k, v]) => `${k} = ${v}`)\n .join(\"\\n\")}</em></small>`;\n }\n\n const nodeLabel = (formatDict[key] ?? formatDict[defaultClassLabel])\n .replace(\"{0}\", _escapeNodeLabel(key))\n .replace(\"{1}\", finalLabel);\n\n mermaidGraph += `\\t${nodeLabel}\\n`;\n }\n }\n\n // Group edges by their common prefixes\n const edgeGroups: Record<string, Edge[]> = {};\n for (const edge of edges) {\n const srcParts = edge.source.split(\":\");\n const tgtParts = edge.target.split(\":\");\n const commonPrefix = srcParts\n .filter((src, i) => src === tgtParts[i])\n .join(\":\");\n if (!edgeGroups[commonPrefix]) {\n edgeGroups[commonPrefix] = [];\n }\n edgeGroups[commonPrefix].push(edge);\n }\n\n const seenSubgraphs = new Set<string>();\n\n // sort prefixes by path length for correct nesting\n function sortPrefixesByDepth(prefixes: string[]): string[] {\n return [...prefixes].sort((a, b) => {\n return a.split(\":\").length - b.split(\":\").length;\n });\n }\n\n function addSubgraph(edges: Edge[], prefix: string): void {\n const selfLoop = edges.length === 1 && edges[0].source === edges[0].target;\n if (prefix && !selfLoop) {\n const subgraph = prefix.split(\":\").pop()!;\n\n if (seenSubgraphs.has(prefix)) {\n throw new Error(\n `Found duplicate subgraph '${subgraph}' at '${prefix} -- this likely means that ` +\n \"you're reusing a subgraph node with the same name. \" +\n \"Please adjust your graph to have subgraph nodes with unique names.\"\n );\n }\n\n seenSubgraphs.add(prefix);\n mermaidGraph += `\\tsubgraph ${subgraph}\\n`;\n }\n\n // all nested prefixes for this level, sorted by depth\n const nestedPrefixes = sortPrefixesByDepth(\n Object.keys(edgeGroups).filter(\n (nestedPrefix) =>\n nestedPrefix.startsWith(`${prefix}:`) &&\n nestedPrefix !== prefix &&\n nestedPrefix.split(\":\").length === prefix.split(\":\").length + 1\n )\n );\n\n for (const nestedPrefix of nestedPrefixes) {\n addSubgraph(edgeGroups[nestedPrefix], nestedPrefix);\n }\n\n for (const edge of edges) {\n const { source, target, data, conditional } = edge;\n\n let edgeLabel = \"\";\n if (data !== undefined) {\n let edgeData = data;\n const words = edgeData.split(\" \");\n if (words.length > wrapLabelNWords) {\n edgeData = Array.from(\n { length: Math.ceil(words.length / wrapLabelNWords) },\n (_, i) =>\n words\n .slice(i * wrapLabelNWords, (i + 1) * wrapLabelNWords)\n .join(\" \")\n ).join(\"&nbsp;<br>&nbsp;\");\n }\n edgeLabel = conditional\n ? ` -. &nbsp;${edgeData}&nbsp; .-> `\n : ` -- &nbsp;${edgeData}&nbsp; --> `;\n } else {\n edgeLabel = conditional ? \" -.-> \" : \" --> \";\n }\n\n mermaidGraph += `\\t${_escapeNodeLabel(\n source\n )}${edgeLabel}${_escapeNodeLabel(target)};\\n`;\n }\n\n if (prefix && !selfLoop) {\n mermaidGraph += \"\\tend\\n\";\n }\n }\n\n // Start with the top-level edges (no common prefix)\n addSubgraph(edgeGroups[\"\"] ?? [], \"\");\n\n // Add remaining top-level subgraphs\n for (const prefix in edgeGroups) {\n if (!prefix.includes(\":\") && prefix !== \"\") {\n addSubgraph(edgeGroups[prefix], prefix);\n }\n }\n\n // Add custom styles for nodes\n if (withStyles) {\n mermaidGraph += _generateMermaidGraphStyles(nodeColors ?? {});\n }\n\n return mermaidGraph;\n}\n\n/**\n * Renders Mermaid graph using the Mermaid.INK API.\n *\n * @example\n * ```javascript\n * const image = await drawMermaidImage(mermaidSyntax, {\n * backgroundColor: \"white\",\n * imageType: \"png\",\n * });\n * fs.writeFileSync(\"image.png\", image);\n * ```\n *\n * @param mermaidSyntax - The Mermaid syntax to render.\n * @param config - The configuration for the image.\n * @returns The image as a Blob.\n */\nexport async function drawMermaidImage(\n mermaidSyntax: string,\n config?: {\n /**\n * The type of image to render.\n * @default \"png\"\n */\n imageType?: \"png\" | \"jpeg\" | \"webp\";\n backgroundColor?: string;\n }\n) {\n let backgroundColor = config?.backgroundColor ?? \"white\";\n const imageType = config?.imageType ?? \"png\";\n\n const mermaidSyntaxEncoded = toBase64Url(mermaidSyntax);\n\n // Check if the background color is a hexadecimal color code using regex\n if (backgroundColor !== undefined) {\n const hexColorPattern = /^#(?:[0-9a-fA-F]{3}){1,2}$/;\n if (!hexColorPattern.test(backgroundColor)) {\n backgroundColor = `!${backgroundColor}`;\n }\n }\n const imageUrl = `https://mermaid.ink/img/${mermaidSyntaxEncoded}?bgColor=${backgroundColor}&type=${imageType}`;\n const res = await fetch(imageUrl);\n if (!res.ok) {\n throw new Error(\n [\n `Failed to render the graph using the Mermaid.INK API.`,\n `Status code: ${res.status}`,\n `Status text: ${res.statusText}`,\n ].join(\"\\n\")\n );\n }\n const content = await res.blob();\n return content;\n}\n"],"mappings":";;AAGA,SAAS,iBAAiB,WAA2B;AAEnD,QAAO,UAAU,QAAQ,mBAAmB,IAAI;;AAGlD,MAAM,yBAAyB;CAAC;CAAK;CAAK;CAAI;AAE9C,SAAS,4BACP,YACQ;CACR,IAAI,SAAS;AACb,MAAK,MAAM,CAAC,WAAW,UAAU,OAAO,QAAQ,WAAW,CACzD,WAAU,cAAc,UAAU,GAAG,MAAM;AAE7C,QAAO;;;;;AAMT,SAAgB,YACd,OACA,OACA,QAQQ;CACR,MAAM,EACJ,WACA,UACA,YACA,aAAa,MACb,aAAa,UACb,kBAAkB,MAChB,UAAU,EAAE;CAEhB,IAAI,eAAe,aACf,qCAAqC,WAAW,uBAChD;AACJ,KAAI,YAAY;EAEd,MAAM,oBAAoB;EAC1B,MAAM,aAAqC,GACxC,oBAAoB,YACtB;AACD,MAAI,cAAc,KAAA,EAChB,YAAW,aAAa;AAE1B,MAAI,aAAa,KAAA,EACf,YAAW,YAAY;AAIzB,OAAK,MAAM,CAAC,KAAK,SAAS,OAAO,QAAQ,MAAM,EAAE;GAC/C,MAAM,WAAW,KAAK,KAAK,MAAM,IAAI,CAAC,KAAK,IAAI;GAO/C,IAAI,aANU,uBAAuB,MAClC,SAAS,SAAS,WAAW,KAAK,IAAI,SAAS,SAAS,KAAK,CAC/D,GACG,MAAM,SAAS,QACf;AAGJ,OAAI,OAAO,KAAK,KAAK,YAAY,EAAE,CAAC,CAAC,OACnC,eAAc,mBAAmB,OAAO,QAAQ,KAAK,YAAY,EAAE,CAAC,CACjE,KAAK,CAAC,GAAG,OAAO,GAAG,EAAE,KAAK,IAAI,CAC9B,KAAK,KAAK,CAAC;GAGhB,MAAM,aAAa,WAAW,QAAQ,WAAW,oBAC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require_ai = require('../messages/ai.cjs');
3
- const require_human = require('../messages/human.cjs');
4
- const require_base$1 = require('./base.cjs');
5
- require('../messages/index.cjs');
6
- const require_passthrough = require('./passthrough.cjs');
7
-
1
+ const require_base = require("../messages/base.cjs");
2
+ const require_ai = require("../messages/ai.cjs");
3
+ const require_human = require("../messages/human.cjs");
4
+ const require_base$1 = require("./base.cjs");
5
+ require("../messages/index.cjs");
6
+ const require_passthrough = require("./passthrough.cjs");
8
7
  //#region src/runnables/history.ts
9
8
  /**
10
9
  * Wraps a LCEL chain and manages history. It appends input messages
@@ -154,7 +153,7 @@ var RunnableWithMessageHistory = class extends require_base$1.RunnableBinding {
154
153
  return config;
155
154
  }
156
155
  };
157
-
158
156
  //#endregion
159
157
  exports.RunnableWithMessageHistory = RunnableWithMessageHistory;
158
+
160
159
  //# sourceMappingURL=history.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"history.cjs","names":["RunnableBinding","RunnableLambda","RunnablePassthrough","isBaseMessage","HumanMessage","AIMessage"],"sources":["../../src/runnables/history.ts"],"sourcesContent":["import {\n BaseChatMessageHistory,\n BaseListChatMessageHistory,\n} from \"../chat_history.js\";\nimport {\n AIMessage,\n BaseMessage,\n HumanMessage,\n isBaseMessage,\n} from \"../messages/index.js\";\nimport { Run } from \"../tracers/base.js\";\nimport {\n Runnable,\n RunnableBinding,\n type RunnableBindingArgs,\n RunnableLambda,\n} from \"./base.js\";\nimport { RunnableConfig } from \"./config.js\";\nimport { RunnablePassthrough } from \"./passthrough.js\";\n\ntype GetSessionHistoryCallable = (\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ...args: Array<any>\n) =>\n | Promise<BaseChatMessageHistory | BaseListChatMessageHistory>\n | BaseChatMessageHistory\n | BaseListChatMessageHistory;\n\nexport interface RunnableWithMessageHistoryInputs<\n RunInput,\n RunOutput,\n> extends Omit<RunnableBindingArgs<RunInput, RunOutput>, \"bound\" | \"config\"> {\n runnable: Runnable<RunInput, RunOutput>;\n getMessageHistory: GetSessionHistoryCallable;\n inputMessagesKey?: string;\n outputMessagesKey?: string;\n historyMessagesKey?: string;\n config?: RunnableConfig;\n}\n\n/**\n * Wraps a LCEL chain and manages history. It appends input messages\n * and chain outputs as history, and adds the current history messages to\n * the chain input.\n * @example\n * ```typescript\n * // pnpm install @langchain/anthropic @langchain/community @upstash/redis\n *\n * import {\n * ChatPromptTemplate,\n * MessagesPlaceholder,\n * } from \"@langchain/core/prompts\";\n * import { ChatAnthropic } from \"@langchain/anthropic\";\n * import { UpstashRedisChatMessageHistory } from \"@langchain/community/stores/message/upstash_redis\";\n * // For demos, you can also use an in-memory store:\n * // import { ChatMessageHistory } from \"@langchain/classic/stores/message/in_memory\";\n *\n * const prompt = ChatPromptTemplate.fromMessages([\n * [\"system\", \"You're an assistant who's good at {ability}\"],\n * new MessagesPlaceholder(\"history\"),\n * [\"human\", \"{question}\"],\n * ]);\n *\n * const chain = prompt.pipe(new ChatAnthropic({}));\n *\n * const chainWithHistory = new RunnableWithMessageHistory({\n * runnable: chain,\n * getMessageHistory: (sessionId) =>\n * new UpstashRedisChatMessageHistory({\n * sessionId,\n * config: {\n * url: process.env.UPSTASH_REDIS_REST_URL!,\n * token: process.env.UPSTASH_REDIS_REST_TOKEN!,\n * },\n * }),\n * inputMessagesKey: \"question\",\n * historyMessagesKey: \"history\",\n * });\n *\n * const result = await chainWithHistory.invoke(\n * {\n * ability: \"math\",\n * question: \"What does cosine mean?\",\n * },\n * {\n * configurable: {\n * sessionId: \"some_string_identifying_a_user\",\n * },\n * }\n * );\n *\n * const result2 = await chainWithHistory.invoke(\n * {\n * ability: \"math\",\n * question: \"What's its inverse?\",\n * },\n * {\n * configurable: {\n * sessionId: \"some_string_identifying_a_user\",\n * },\n * }\n * );\n * ```\n */\nexport class RunnableWithMessageHistory<\n RunInput,\n RunOutput,\n> extends RunnableBinding<RunInput, RunOutput> {\n runnable: Runnable<RunInput, RunOutput>;\n\n inputMessagesKey?: string;\n\n outputMessagesKey?: string;\n\n historyMessagesKey?: string;\n\n getMessageHistory: GetSessionHistoryCallable;\n\n constructor(fields: RunnableWithMessageHistoryInputs<RunInput, RunOutput>) {\n let historyChain: Runnable = RunnableLambda.from((input, options) =>\n this._enterHistory(input, options ?? {})\n ).withConfig({ runName: \"loadHistory\" });\n\n const messagesKey = fields.historyMessagesKey ?? fields.inputMessagesKey;\n if (messagesKey) {\n historyChain = RunnablePassthrough.assign({\n [messagesKey]: historyChain,\n }).withConfig({ runName: \"insertHistory\" });\n }\n\n const bound = historyChain\n .pipe(\n fields.runnable.withListeners({\n onEnd: (run, config) => this._exitHistory(run, config ?? {}),\n })\n )\n .withConfig({ runName: \"RunnableWithMessageHistory\" });\n\n const config = fields.config ?? {};\n\n super({\n ...fields,\n config,\n bound,\n });\n this.runnable = fields.runnable;\n this.getMessageHistory = fields.getMessageHistory;\n this.inputMessagesKey = fields.inputMessagesKey;\n this.outputMessagesKey = fields.outputMessagesKey;\n this.historyMessagesKey = fields.historyMessagesKey;\n }\n\n _getInputMessages(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n inputValue: string | BaseMessage | Array<BaseMessage> | Record<string, any>\n ): Array<BaseMessage> {\n let parsedInputValue;\n if (\n typeof inputValue === \"object\" &&\n !Array.isArray(inputValue) &&\n !isBaseMessage(inputValue)\n ) {\n let key;\n if (this.inputMessagesKey) {\n key = this.inputMessagesKey;\n } else if (Object.keys(inputValue).length === 1) {\n key = Object.keys(inputValue)[0];\n } else {\n key = \"input\";\n }\n if (Array.isArray(inputValue[key]) && Array.isArray(inputValue[key][0])) {\n parsedInputValue = inputValue[key][0];\n } else {\n parsedInputValue = inputValue[key];\n }\n } else {\n parsedInputValue = inputValue;\n }\n if (typeof parsedInputValue === \"string\") {\n return [new HumanMessage(parsedInputValue)];\n } else if (Array.isArray(parsedInputValue)) {\n return parsedInputValue;\n } else if (isBaseMessage(parsedInputValue)) {\n return [parsedInputValue];\n } else {\n throw new Error(\n `Expected a string, BaseMessage, or array of BaseMessages.\\nGot ${JSON.stringify(\n parsedInputValue,\n null,\n 2\n )}`\n );\n }\n }\n\n _getOutputMessages(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n outputValue: string | BaseMessage | Array<BaseMessage> | Record<string, any>\n ): Array<BaseMessage> {\n let parsedOutputValue;\n if (\n !Array.isArray(outputValue) &&\n !isBaseMessage(outputValue) &&\n typeof outputValue !== \"string\"\n ) {\n let key;\n if (this.outputMessagesKey !== undefined) {\n key = this.outputMessagesKey;\n } else if (Object.keys(outputValue).length === 1) {\n key = Object.keys(outputValue)[0];\n } else {\n key = \"output\";\n }\n // If you are wrapping a chat model directly\n // The output is actually this weird generations object\n if (outputValue.generations !== undefined) {\n parsedOutputValue = outputValue.generations[0][0].message;\n } else {\n parsedOutputValue = outputValue[key];\n }\n } else {\n parsedOutputValue = outputValue;\n }\n\n if (typeof parsedOutputValue === \"string\") {\n return [new AIMessage(parsedOutputValue)];\n } else if (Array.isArray(parsedOutputValue)) {\n return parsedOutputValue;\n } else if (isBaseMessage(parsedOutputValue)) {\n return [parsedOutputValue];\n } else {\n throw new Error(\n `Expected a string, BaseMessage, or array of BaseMessages. Received: ${JSON.stringify(\n parsedOutputValue,\n null,\n 2\n )}`\n );\n }\n }\n\n async _enterHistory(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n input: any,\n kwargs?: RunnableConfig\n ): Promise<BaseMessage[]> {\n const history = kwargs?.configurable?.messageHistory;\n const messages = await history.getMessages();\n if (this.historyMessagesKey === undefined) {\n return messages.concat(this._getInputMessages(input));\n }\n return messages;\n }\n\n async _exitHistory(run: Run, config: RunnableConfig): Promise<void> {\n const history = config.configurable?.messageHistory;\n\n // Get input messages\n let inputs;\n // Chat model inputs are nested arrays\n if (Array.isArray(run.inputs) && Array.isArray(run.inputs[0])) {\n inputs = run.inputs[0];\n } else {\n inputs = run.inputs;\n }\n let inputMessages = this._getInputMessages(inputs);\n // If historic messages were prepended to the input messages, remove them to\n // avoid adding duplicate messages to history.\n if (this.historyMessagesKey === undefined) {\n const existingMessages = await history.getMessages();\n inputMessages = inputMessages.slice(existingMessages.length);\n }\n // Get output messages\n const outputValue = run.outputs;\n if (!outputValue) {\n throw new Error(\n `Output values from 'Run' undefined. Run: ${JSON.stringify(\n run,\n null,\n 2\n )}`\n );\n }\n const outputMessages = this._getOutputMessages(outputValue);\n await history.addMessages([...inputMessages, ...outputMessages]);\n }\n\n async _mergeConfig(...configs: Array<RunnableConfig | undefined>) {\n const config = await super._mergeConfig(...configs);\n // Extract sessionId\n if (!config.configurable || !config.configurable.sessionId) {\n const exampleInput = {\n [this.inputMessagesKey ?? \"input\"]: \"foo\",\n };\n const exampleConfig = { configurable: { sessionId: \"123\" } };\n throw new Error(\n `sessionId is required. Pass it in as part of the config argument to .invoke() or .stream()\\n` +\n `eg. chain.invoke(${JSON.stringify(exampleInput)}, ${JSON.stringify(\n exampleConfig\n )})`\n );\n }\n // attach messageHistory\n const { sessionId } = config.configurable;\n config.configurable.messageHistory =\n await this.getMessageHistory(sessionId);\n return config;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwGA,IAAa,6BAAb,cAGUA,+BAAqC;CAC7C;CAEA;CAEA;CAEA;CAEA;CAEA,YAAY,QAA+D;EACzE,IAAI,eAAyBC,8BAAe,MAAM,OAAO,YACvD,KAAK,cAAc,OAAO,WAAW,EAAE,CAAC,CACzC,CAAC,WAAW,EAAE,SAAS,eAAe,CAAC;EAExC,MAAM,cAAc,OAAO,sBAAsB,OAAO;AACxD,MAAI,YACF,gBAAeC,wCAAoB,OAAO,GACvC,cAAc,cAChB,CAAC,CAAC,WAAW,EAAE,SAAS,iBAAiB,CAAC;EAG7C,MAAM,QAAQ,aACX,KACC,OAAO,SAAS,cAAc,EAC5B,QAAQ,KAAK,WAAW,KAAK,aAAa,KAAK,UAAU,EAAE,CAAC,EAC7D,CAAC,CACH,CACA,WA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,EAAE,WAAW,OAAO,EAAE,CAKvD,CAAC,GACL;;EAGH,MAAM,EAAE,cAAc,OAAO;AAC7B,SAAO,aAAa,iBAClB,MAAM,KAAK,kBAAkB,UAAU;AACzC,SAAO"}
1
+ {"version":3,"file":"history.cjs","names":["RunnableBinding","RunnableLambda","RunnablePassthrough","isBaseMessage","HumanMessage","AIMessage"],"sources":["../../src/runnables/history.ts"],"sourcesContent":["import {\n BaseChatMessageHistory,\n BaseListChatMessageHistory,\n} from \"../chat_history.js\";\nimport {\n AIMessage,\n BaseMessage,\n HumanMessage,\n isBaseMessage,\n} from \"../messages/index.js\";\nimport { Run } from \"../tracers/base.js\";\nimport {\n Runnable,\n RunnableBinding,\n type RunnableBindingArgs,\n RunnableLambda,\n} from \"./base.js\";\nimport { RunnableConfig } from \"./config.js\";\nimport { RunnablePassthrough } from \"./passthrough.js\";\n\ntype GetSessionHistoryCallable = (\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ...args: Array<any>\n) =>\n | Promise<BaseChatMessageHistory | BaseListChatMessageHistory>\n | BaseChatMessageHistory\n | BaseListChatMessageHistory;\n\nexport interface RunnableWithMessageHistoryInputs<\n RunInput,\n RunOutput,\n> extends Omit<RunnableBindingArgs<RunInput, RunOutput>, \"bound\" | \"config\"> {\n runnable: Runnable<RunInput, RunOutput>;\n getMessageHistory: GetSessionHistoryCallable;\n inputMessagesKey?: string;\n outputMessagesKey?: string;\n historyMessagesKey?: string;\n config?: RunnableConfig;\n}\n\n/**\n * Wraps a LCEL chain and manages history. It appends input messages\n * and chain outputs as history, and adds the current history messages to\n * the chain input.\n * @example\n * ```typescript\n * // pnpm install @langchain/anthropic @langchain/community @upstash/redis\n *\n * import {\n * ChatPromptTemplate,\n * MessagesPlaceholder,\n * } from \"@langchain/core/prompts\";\n * import { ChatAnthropic } from \"@langchain/anthropic\";\n * import { UpstashRedisChatMessageHistory } from \"@langchain/community/stores/message/upstash_redis\";\n * // For demos, you can also use an in-memory store:\n * // import { ChatMessageHistory } from \"@langchain/classic/stores/message/in_memory\";\n *\n * const prompt = ChatPromptTemplate.fromMessages([\n * [\"system\", \"You're an assistant who's good at {ability}\"],\n * new MessagesPlaceholder(\"history\"),\n * [\"human\", \"{question}\"],\n * ]);\n *\n * const chain = prompt.pipe(new ChatAnthropic({}));\n *\n * const chainWithHistory = new RunnableWithMessageHistory({\n * runnable: chain,\n * getMessageHistory: (sessionId) =>\n * new UpstashRedisChatMessageHistory({\n * sessionId,\n * config: {\n * url: process.env.UPSTASH_REDIS_REST_URL!,\n * token: process.env.UPSTASH_REDIS_REST_TOKEN!,\n * },\n * }),\n * inputMessagesKey: \"question\",\n * historyMessagesKey: \"history\",\n * });\n *\n * const result = await chainWithHistory.invoke(\n * {\n * ability: \"math\",\n * question: \"What does cosine mean?\",\n * },\n * {\n * configurable: {\n * sessionId: \"some_string_identifying_a_user\",\n * },\n * }\n * );\n *\n * const result2 = await chainWithHistory.invoke(\n * {\n * ability: \"math\",\n * question: \"What's its inverse?\",\n * },\n * {\n * configurable: {\n * sessionId: \"some_string_identifying_a_user\",\n * },\n * }\n * );\n * ```\n */\nexport class RunnableWithMessageHistory<\n RunInput,\n RunOutput,\n> extends RunnableBinding<RunInput, RunOutput> {\n runnable: Runnable<RunInput, RunOutput>;\n\n inputMessagesKey?: string;\n\n outputMessagesKey?: string;\n\n historyMessagesKey?: string;\n\n getMessageHistory: GetSessionHistoryCallable;\n\n constructor(fields: RunnableWithMessageHistoryInputs<RunInput, RunOutput>) {\n let historyChain: Runnable = RunnableLambda.from((input, options) =>\n this._enterHistory(input, options ?? {})\n ).withConfig({ runName: \"loadHistory\" });\n\n const messagesKey = fields.historyMessagesKey ?? fields.inputMessagesKey;\n if (messagesKey) {\n historyChain = RunnablePassthrough.assign({\n [messagesKey]: historyChain,\n }).withConfig({ runName: \"insertHistory\" });\n }\n\n const bound = historyChain\n .pipe(\n fields.runnable.withListeners({\n onEnd: (run, config) => this._exitHistory(run, config ?? {}),\n })\n )\n .withConfig({ runName: \"RunnableWithMessageHistory\" });\n\n const config = fields.config ?? {};\n\n super({\n ...fields,\n config,\n bound,\n });\n this.runnable = fields.runnable;\n this.getMessageHistory = fields.getMessageHistory;\n this.inputMessagesKey = fields.inputMessagesKey;\n this.outputMessagesKey = fields.outputMessagesKey;\n this.historyMessagesKey = fields.historyMessagesKey;\n }\n\n _getInputMessages(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n inputValue: string | BaseMessage | Array<BaseMessage> | Record<string, any>\n ): Array<BaseMessage> {\n let parsedInputValue;\n if (\n typeof inputValue === \"object\" &&\n !Array.isArray(inputValue) &&\n !isBaseMessage(inputValue)\n ) {\n let key;\n if (this.inputMessagesKey) {\n key = this.inputMessagesKey;\n } else if (Object.keys(inputValue).length === 1) {\n key = Object.keys(inputValue)[0];\n } else {\n key = \"input\";\n }\n if (Array.isArray(inputValue[key]) && Array.isArray(inputValue[key][0])) {\n parsedInputValue = inputValue[key][0];\n } else {\n parsedInputValue = inputValue[key];\n }\n } else {\n parsedInputValue = inputValue;\n }\n if (typeof parsedInputValue === \"string\") {\n return [new HumanMessage(parsedInputValue)];\n } else if (Array.isArray(parsedInputValue)) {\n return parsedInputValue;\n } else if (isBaseMessage(parsedInputValue)) {\n return [parsedInputValue];\n } else {\n throw new Error(\n `Expected a string, BaseMessage, or array of BaseMessages.\\nGot ${JSON.stringify(\n parsedInputValue,\n null,\n 2\n )}`\n );\n }\n }\n\n _getOutputMessages(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n outputValue: string | BaseMessage | Array<BaseMessage> | Record<string, any>\n ): Array<BaseMessage> {\n let parsedOutputValue;\n if (\n !Array.isArray(outputValue) &&\n !isBaseMessage(outputValue) &&\n typeof outputValue !== \"string\"\n ) {\n let key;\n if (this.outputMessagesKey !== undefined) {\n key = this.outputMessagesKey;\n } else if (Object.keys(outputValue).length === 1) {\n key = Object.keys(outputValue)[0];\n } else {\n key = \"output\";\n }\n // If you are wrapping a chat model directly\n // The output is actually this weird generations object\n if (outputValue.generations !== undefined) {\n parsedOutputValue = outputValue.generations[0][0].message;\n } else {\n parsedOutputValue = outputValue[key];\n }\n } else {\n parsedOutputValue = outputValue;\n }\n\n if (typeof parsedOutputValue === \"string\") {\n return [new AIMessage(parsedOutputValue)];\n } else if (Array.isArray(parsedOutputValue)) {\n return parsedOutputValue;\n } else if (isBaseMessage(parsedOutputValue)) {\n return [parsedOutputValue];\n } else {\n throw new Error(\n `Expected a string, BaseMessage, or array of BaseMessages. Received: ${JSON.stringify(\n parsedOutputValue,\n null,\n 2\n )}`\n );\n }\n }\n\n async _enterHistory(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n input: any,\n kwargs?: RunnableConfig\n ): Promise<BaseMessage[]> {\n const history = kwargs?.configurable?.messageHistory;\n const messages = await history.getMessages();\n if (this.historyMessagesKey === undefined) {\n return messages.concat(this._getInputMessages(input));\n }\n return messages;\n }\n\n async _exitHistory(run: Run, config: RunnableConfig): Promise<void> {\n const history = config.configurable?.messageHistory;\n\n // Get input messages\n let inputs;\n // Chat model inputs are nested arrays\n if (Array.isArray(run.inputs) && Array.isArray(run.inputs[0])) {\n inputs = run.inputs[0];\n } else {\n inputs = run.inputs;\n }\n let inputMessages = this._getInputMessages(inputs);\n // If historic messages were prepended to the input messages, remove them to\n // avoid adding duplicate messages to history.\n if (this.historyMessagesKey === undefined) {\n const existingMessages = await history.getMessages();\n inputMessages = inputMessages.slice(existingMessages.length);\n }\n // Get output messages\n const outputValue = run.outputs;\n if (!outputValue) {\n throw new Error(\n `Output values from 'Run' undefined. Run: ${JSON.stringify(\n run,\n null,\n 2\n )}`\n );\n }\n const outputMessages = this._getOutputMessages(outputValue);\n await history.addMessages([...inputMessages, ...outputMessages]);\n }\n\n async _mergeConfig(...configs: Array<RunnableConfig | undefined>) {\n const config = await super._mergeConfig(...configs);\n // Extract sessionId\n if (!config.configurable || !config.configurable.sessionId) {\n const exampleInput = {\n [this.inputMessagesKey ?? \"input\"]: \"foo\",\n };\n const exampleConfig = { configurable: { sessionId: \"123\" } };\n throw new Error(\n `sessionId is required. Pass it in as part of the config argument to .invoke() or .stream()\\n` +\n `eg. chain.invoke(${JSON.stringify(exampleInput)}, ${JSON.stringify(\n exampleConfig\n )})`\n );\n }\n // attach messageHistory\n const { sessionId } = config.configurable;\n config.configurable.messageHistory =\n await this.getMessageHistory(sessionId);\n return config;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwGA,IAAa,6BAAb,cAGUA,eAAAA,gBAAqC;CAC7C;CAEA;CAEA;CAEA;CAEA;CAEA,YAAY,QAA+D;EACzE,IAAI,eAAyBC,eAAAA,eAAe,MAAM,OAAO,YACvD,KAAK,cAAc,OAAO,WAAW,EAAE,CAAC,CACzC,CAAC,WAAW,EAAE,SAAS,eAAe,CAAC;EAExC,MAAM,cAAc,OAAO,sBAAsB,OAAO;AACxD,MAAI,YACF,gBAAeC,oBAAAA,oBAAoB,OAAO,GACvC,cAAc,cAChB,CAAC,CAAC,WAAW,EAAE,SAAS,iBAAiB,CAAC;EAG7C,MAAM,QAAQ,aACX,KACC,OAAO,SAAS,cAAc,EAC5B,QAAQ,KAAK,WAAW,KAAK,aAAa,KAAK,UAAU,EAAE,CAAC,EAC7D,CAAC,CACH,CACA,WAAW,EAAE,SAAS,8BAA8B,CAAC;EAExD,MAAM,SAAS,OAAO,UAAU,EAAE;AAElC,QAAM;GACJ,GAAG;GACH;GACA;GACD,CAAC;AACF,OAAK,WAAW,OAAO;AACvB,OAAK,oBAAoB,OAAO;AAChC,OAAK,mBAAmB,OAAO;AAC/B,OAAK,oBAAoB,OAAO;AAChC,OAAK,qBAAqB,OAAO;;CAGnC,kBAEE,YACoB;EACpB,IAAI;AACJ,MACE,OAAO,eAAe,YACtB,CAAC,MAAM,QAAQ,WAAW,IAC1B,CAACC,aAAAA,cAAc,WAAW,EAC1B;GACA,IAAI;AACJ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,EAC9B,QAAO,SAAS,OAAO,KAAK,kBAAkB,MAAM,CAAC;AAEvD,SAAO;;CAGT,MAAM,aAAa,KAAU,QAAuC;EAClE,MAAM,UAAU,OAAO,cAAc;EAGrC,IAAI;AAEJ,MAAI,MAAM,QAAQ,IAAI,OAAO,IAAI,MAAM,QAAQ,IAAI,OAAO,GAAG,CAC3D,UAAS,IAAI,OAAO;MAEpB,UAAS,IAAI;EAEf,IAAI,gBAAgB,KAAK,kBAAkB,OAAO;AAGlD,MAAI,KAAK,uBAAuB,KAAA,GAAW;GACzC,MAAM,mBAAmB,MAAM,QAAQ,aAAa;AACpD,mBAAgB,cAAc,MAAM,iBAAiB,OAAO;;EAG9D,MAAM,cAAc,IAAI;AACxB,MAAI,CAAC,YACH,OAAM,IAAI,MACR,4CAA4C,KAAK,UAC/C,KACA,MACA,EACD,GACF;EAEH,MAAM,iBAAiB,KAAK,mBAAmB,YAAY;AAC3D,QAAM,QAAQ,YAAY,CAAC,GAAG,eAAe,GAAG,eAAe,CAAC;;CAGlE,MAAM,aAAa,GAAG,SAA4C;EAChE,MAAM,SAAS,MAAM,MAAM,aAAa,GAAG,QAAQ;AAEnD,MAAI,CAAC,OAAO,gBAAgB,CAAC,OAAO,aAAa,WAAW;GAC1D,MAAM,eAAe,GAClB,KAAK,oBAAoB,UAAU,OACrC;AAED,SAAM,IAAI,MACR,gHACsB,KAAK,UAAU,aAAa,CAAC,IAAI,KAAK,UAHxC,EAAE,cAAc,EAAE,WAAW,OAAO,EAAE,CAKvD,CAAC,GACL;;EAGH,MAAM,EAAE,cAAc,OAAO;AAC7B,SAAO,aAAa,iBAClB,MAAM,KAAK,kBAAkB,UAAU;AACzC,SAAO"}
@@ -1,9 +1,7 @@
1
1
  import { BaseMessage } from "../messages/base.js";
2
2
  import { RunnableConfig } from "./types.js";
3
- import "./config.js";
4
3
  import { Run } from "../tracers/base.js";
5
4
  import { Runnable, RunnableBinding, RunnableBindingArgs } from "./base.js";
6
- import "../messages/index.js";
7
5
  import { BaseChatMessageHistory, BaseListChatMessageHistory } from "../chat_history.js";
8
6
 
9
7
  //#region src/runnables/history.d.ts
@@ -1 +1 @@
1
- {"version":3,"file":"history.d.ts","names":[],"sources":["../../src/runnables/history.ts"],"mappings":";;;;;;;;;KAoBK,yBAAA,OAEA,IAAA,EAAM,KAAA,UAEP,OAAA,CAAQ,sBAAA,GAAyB,0BAAA,IACjC,sBAAA,GACA,0BAAA;AAAA,UAEa,gCAAA,8BAGP,IAAA,CAAK,mBAAA,CAAoB,QAAA,EAAU,SAAA;EAC3C,QAAA,EAAU,QAAA,CAAS,QAAA,EAAU,SAAA;EAC7B,iBAAA,EAAmB,yBAAA;EACnB,gBAAA;EACA,iBAAA;EACA,kBAAA;EACA,MAAA,GAAS,cAAA;AAAA;;;;;;;;;;;;;;;;AATX;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4EA;;;;;;;;;;;;;;;;cAAa,0BAAA,8BAGH,eAAA,CAAgB,QAAA,EAAU,SAAA;EAClC,QAAA,EAAU,QAAA,CAAS,QAAA,EAAU,SAAA;EAE7B,gBAAA;EAEA,iBAAA;EAEA,kBAAA;EAEA,iBAAA,EAAmB,yBAAA;EAEnB,WAAA,CAAY,MAAA,EAAQ,gCAAA,CAAiC,QAAA,EAAU,SAAA;EAkC/D,iBAAA,CAEE,UAAA,WAAqB,WAAA,GAAc,KAAA,CAAM,WAAA,IAAe,MAAA,gBACvD,KAAA,CAAM,WAAA;EAwCT,kBAAA,CAEE,WAAA,WAAsB,WAAA,GAAc,KAAA,CAAM,WAAA,IAAe,MAAA,gBACxD,KAAA,CAAM,WAAA;EA2CH,aAAA,CAEJ,KAAA,OACA,MAAA,GAAS,cAAA,GACR,OAAA,CAAQ,WAAA;EASL,YAAA,CAAa,GAAA,EAAK,GAAA,EAAK,MAAA,EAAQ,cAAA,GAAiB,OAAA;EAiChD,YAAA,CAAA,GAAgB,OAAA,EAAS,KAAA,CAAM,cAAA,gBAA2B,OAAA,CAA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 import { HumanMessage } from "../messages/human.js";
4
4
  import { RunnableBinding, RunnableLambda } from "./base.js";
5
5
  import "../messages/index.js";
6
6
  import { RunnablePassthrough } from "./passthrough.js";
7
-
8
7
  //#region src/runnables/history.ts
9
8
  /**
10
9
  * Wraps a LCEL chain and manages history. It appends input messages
@@ -154,7 +153,7 @@ var RunnableWithMessageHistory = class extends RunnableBinding {
154
153
  return config;
155
154
  }
156
155
  };
157
-
158
156
  //#endregion
159
157
  export { RunnableWithMessageHistory };
158
+
160
159
  //# sourceMappingURL=history.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"history.js","names":[],"sources":["../../src/runnables/history.ts"],"sourcesContent":["import {\n BaseChatMessageHistory,\n BaseListChatMessageHistory,\n} from \"../chat_history.js\";\nimport {\n AIMessage,\n BaseMessage,\n HumanMessage,\n isBaseMessage,\n} from \"../messages/index.js\";\nimport { Run } from \"../tracers/base.js\";\nimport {\n Runnable,\n RunnableBinding,\n type RunnableBindingArgs,\n RunnableLambda,\n} from \"./base.js\";\nimport { RunnableConfig } from \"./config.js\";\nimport { RunnablePassthrough } from \"./passthrough.js\";\n\ntype GetSessionHistoryCallable = (\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ...args: Array<any>\n) =>\n | Promise<BaseChatMessageHistory | BaseListChatMessageHistory>\n | BaseChatMessageHistory\n | BaseListChatMessageHistory;\n\nexport interface RunnableWithMessageHistoryInputs<\n RunInput,\n RunOutput,\n> extends Omit<RunnableBindingArgs<RunInput, RunOutput>, \"bound\" | \"config\"> {\n runnable: Runnable<RunInput, RunOutput>;\n getMessageHistory: GetSessionHistoryCallable;\n inputMessagesKey?: string;\n outputMessagesKey?: string;\n historyMessagesKey?: string;\n config?: RunnableConfig;\n}\n\n/**\n * Wraps a LCEL chain and manages history. It appends input messages\n * and chain outputs as history, and adds the current history messages to\n * the chain input.\n * @example\n * ```typescript\n * // pnpm install @langchain/anthropic @langchain/community @upstash/redis\n *\n * import {\n * ChatPromptTemplate,\n * MessagesPlaceholder,\n * } from \"@langchain/core/prompts\";\n * import { ChatAnthropic } from \"@langchain/anthropic\";\n * import { UpstashRedisChatMessageHistory } from \"@langchain/community/stores/message/upstash_redis\";\n * // For demos, you can also use an in-memory store:\n * // import { ChatMessageHistory } from \"@langchain/classic/stores/message/in_memory\";\n *\n * const prompt = ChatPromptTemplate.fromMessages([\n * [\"system\", \"You're an assistant who's good at {ability}\"],\n * new MessagesPlaceholder(\"history\"),\n * [\"human\", \"{question}\"],\n * ]);\n *\n * const chain = prompt.pipe(new ChatAnthropic({}));\n *\n * const chainWithHistory = new RunnableWithMessageHistory({\n * runnable: chain,\n * getMessageHistory: (sessionId) =>\n * new UpstashRedisChatMessageHistory({\n * sessionId,\n * config: {\n * url: process.env.UPSTASH_REDIS_REST_URL!,\n * token: process.env.UPSTASH_REDIS_REST_TOKEN!,\n * },\n * }),\n * inputMessagesKey: \"question\",\n * historyMessagesKey: \"history\",\n * });\n *\n * const result = await chainWithHistory.invoke(\n * {\n * ability: \"math\",\n * question: \"What does cosine mean?\",\n * },\n * {\n * configurable: {\n * sessionId: \"some_string_identifying_a_user\",\n * },\n * }\n * );\n *\n * const result2 = await chainWithHistory.invoke(\n * {\n * ability: \"math\",\n * question: \"What's its inverse?\",\n * },\n * {\n * configurable: {\n * sessionId: \"some_string_identifying_a_user\",\n * },\n * }\n * );\n * ```\n */\nexport class RunnableWithMessageHistory<\n RunInput,\n RunOutput,\n> extends RunnableBinding<RunInput, RunOutput> {\n runnable: Runnable<RunInput, RunOutput>;\n\n inputMessagesKey?: string;\n\n outputMessagesKey?: string;\n\n historyMessagesKey?: string;\n\n getMessageHistory: GetSessionHistoryCallable;\n\n constructor(fields: RunnableWithMessageHistoryInputs<RunInput, RunOutput>) {\n let historyChain: Runnable = RunnableLambda.from((input, options) =>\n this._enterHistory(input, options ?? {})\n ).withConfig({ runName: \"loadHistory\" });\n\n const messagesKey = fields.historyMessagesKey ?? fields.inputMessagesKey;\n if (messagesKey) {\n historyChain = RunnablePassthrough.assign({\n [messagesKey]: historyChain,\n }).withConfig({ runName: \"insertHistory\" });\n }\n\n const bound = historyChain\n .pipe(\n fields.runnable.withListeners({\n onEnd: (run, config) => this._exitHistory(run, config ?? {}),\n })\n )\n .withConfig({ runName: \"RunnableWithMessageHistory\" });\n\n const config = fields.config ?? {};\n\n super({\n ...fields,\n config,\n bound,\n });\n this.runnable = fields.runnable;\n this.getMessageHistory = fields.getMessageHistory;\n this.inputMessagesKey = fields.inputMessagesKey;\n this.outputMessagesKey = fields.outputMessagesKey;\n this.historyMessagesKey = fields.historyMessagesKey;\n }\n\n _getInputMessages(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n inputValue: string | BaseMessage | Array<BaseMessage> | Record<string, any>\n ): Array<BaseMessage> {\n let parsedInputValue;\n if (\n typeof inputValue === \"object\" &&\n !Array.isArray(inputValue) &&\n !isBaseMessage(inputValue)\n ) {\n let key;\n if (this.inputMessagesKey) {\n key = this.inputMessagesKey;\n } else if (Object.keys(inputValue).length === 1) {\n key = Object.keys(inputValue)[0];\n } else {\n key = \"input\";\n }\n if (Array.isArray(inputValue[key]) && Array.isArray(inputValue[key][0])) {\n parsedInputValue = inputValue[key][0];\n } else {\n parsedInputValue = inputValue[key];\n }\n } else {\n parsedInputValue = inputValue;\n }\n if (typeof parsedInputValue === \"string\") {\n return [new HumanMessage(parsedInputValue)];\n } else if (Array.isArray(parsedInputValue)) {\n return parsedInputValue;\n } else if (isBaseMessage(parsedInputValue)) {\n return [parsedInputValue];\n } else {\n throw new Error(\n `Expected a string, BaseMessage, or array of BaseMessages.\\nGot ${JSON.stringify(\n parsedInputValue,\n null,\n 2\n )}`\n );\n }\n }\n\n _getOutputMessages(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n outputValue: string | BaseMessage | Array<BaseMessage> | Record<string, any>\n ): Array<BaseMessage> {\n let parsedOutputValue;\n if (\n !Array.isArray(outputValue) &&\n !isBaseMessage(outputValue) &&\n typeof outputValue !== \"string\"\n ) {\n let key;\n if (this.outputMessagesKey !== undefined) {\n key = this.outputMessagesKey;\n } else if (Object.keys(outputValue).length === 1) {\n key = Object.keys(outputValue)[0];\n } else {\n key = \"output\";\n }\n // If you are wrapping a chat model directly\n // The output is actually this weird generations object\n if (outputValue.generations !== undefined) {\n parsedOutputValue = outputValue.generations[0][0].message;\n } else {\n parsedOutputValue = outputValue[key];\n }\n } else {\n parsedOutputValue = outputValue;\n }\n\n if (typeof parsedOutputValue === \"string\") {\n return [new AIMessage(parsedOutputValue)];\n } else if (Array.isArray(parsedOutputValue)) {\n return parsedOutputValue;\n } else if (isBaseMessage(parsedOutputValue)) {\n return [parsedOutputValue];\n } else {\n throw new Error(\n `Expected a string, BaseMessage, or array of BaseMessages. Received: ${JSON.stringify(\n parsedOutputValue,\n null,\n 2\n )}`\n );\n }\n }\n\n async _enterHistory(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n input: any,\n kwargs?: RunnableConfig\n ): Promise<BaseMessage[]> {\n const history = kwargs?.configurable?.messageHistory;\n const messages = await history.getMessages();\n if (this.historyMessagesKey === undefined) {\n return messages.concat(this._getInputMessages(input));\n }\n return messages;\n }\n\n async _exitHistory(run: Run, config: RunnableConfig): Promise<void> {\n const history = config.configurable?.messageHistory;\n\n // Get input messages\n let inputs;\n // Chat model inputs are nested arrays\n if (Array.isArray(run.inputs) && Array.isArray(run.inputs[0])) {\n inputs = run.inputs[0];\n } else {\n inputs = run.inputs;\n }\n let inputMessages = this._getInputMessages(inputs);\n // If historic messages were prepended to the input messages, remove them to\n // avoid adding duplicate messages to history.\n if (this.historyMessagesKey === undefined) {\n const existingMessages = await history.getMessages();\n inputMessages = inputMessages.slice(existingMessages.length);\n }\n // Get output messages\n const outputValue = run.outputs;\n if (!outputValue) {\n throw new Error(\n `Output values from 'Run' undefined. Run: ${JSON.stringify(\n run,\n null,\n 2\n )}`\n );\n }\n const outputMessages = this._getOutputMessages(outputValue);\n await history.addMessages([...inputMessages, ...outputMessages]);\n }\n\n async _mergeConfig(...configs: Array<RunnableConfig | undefined>) {\n const config = await super._mergeConfig(...configs);\n // Extract sessionId\n if (!config.configurable || !config.configurable.sessionId) {\n const exampleInput = {\n [this.inputMessagesKey ?? \"input\"]: \"foo\",\n };\n const exampleConfig = { configurable: { sessionId: \"123\" } };\n throw new Error(\n `sessionId is required. Pass it in as part of the config argument to .invoke() or .stream()\\n` +\n `eg. chain.invoke(${JSON.stringify(exampleInput)}, ${JSON.stringify(\n exampleConfig\n )})`\n );\n }\n // attach messageHistory\n const { sessionId } = config.configurable;\n config.configurable.messageHistory =\n await this.getMessageHistory(sessionId);\n return config;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwGA,IAAa,6BAAb,cAGU,gBAAqC;CAC7C;CAEA;CAEA;CAEA;CAEA;CAEA,YAAY,QAA+D;EACzE,IAAI,eAAyB,eAAe,MAAM,OAAO,YACvD,KAAK,cAAc,OAAO,WAAW,EAAE,CAAC,CACzC,CAAC,WAAW,EAAE,SAAS,eAAe,CAAC;EAExC,MAAM,cAAc,OAAO,sBAAsB,OAAO;AACxD,MAAI,YACF,gBAAe,oBAAoB,OAAO,GACvC,cAAc,cAChB,CAAC,CAAC,WAAW,EAAE,SAAS,iBAAiB,CAAC;EAG7C,MAAM,QAAQ,aACX,KACC,OAAO,SAAS,cAAc,EAC5B,QAAQ,KAAK,WAAW,KAAK,aAAa,KAAK,UAAU,EAAE,CAAC,EAC7D,CAAC,CACH,CACA,WAAW,EAAE,SAAS,8BAA8B,CAAC;EAExD,MAAM,SAAS,OAAO,UAAU,EAAE;AAElC,QAAM;GACJ,GAAG;GACH;GACA;GACD,CAAC;AACF,OAAK,WAAW,OAAO;AACvB,OAAK,oBAAoB,OAAO;AAChC,OAAK,mBAAmB,OAAO;AAC/B,OAAK,oBAAoB,OAAO;AAChC,OAAK,qBAAqB,OAAO;;CAGnC,kBAEE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WAAW,OADD,QAAQ,cAAc,gBACP,aAAa;AAC5C,MAAI,KAAK,uBAAuB,OAC9B,QAAO,SAAS,OAAO,KAAK,kBAAkB,MAAM,CAAC;AAEvD,SAAO;;CAGT,MAAM,aAAa,KAAU,QAAuC;EAClE,MAAM,UAAU,OAAO,cAAc;EAGrC,IAAI;AAEJ,MAAI,MAAM,QAAQ,IAAI,OAAO,IAAI,MAAM,QAAQ,IAAI,OAAO,GAAG,CAC3D,UAAS,IAAI,OAAO;MAEpB,UAAS,IAAI;EAEf,IAAI,gBAAgB,KAAK,kBAAkB,OAAO;AAGlD,MAAI,KAAK,uBAAuB,QAAW;GACzC,MAAM,mBAAmB,MAAM,QAAQ,aAAa;AACpD,mBAAgB,cAAc,MAAM,iBAAiB,OAAO;;EAG9D,MAAM,cAAc,IAAI;AACxB,MAAI,CAAC,YACH,OAAM,IAAI,MACR,4CAA4C,KAAK,UAC/C,KACA,MACA,EACD,GACF;EAEH,MAAM,iBAAiB,KAAK,mBAAmB,YAAY;AAC3D,QAAM,QAAQ,YAAY,CAAC,GAAG,eAAe,GAAG,eAAe,CAAC;;CAGlE,MAAM,aAAa,GAAG,SAA4C;EAChE,MAAM,SAAS,MAAM,MAAM,aAAa,GAAG,QAAQ;AAEnD,MAAI,CAAC,OAAO,gBAAgB,CAAC,OAAO,aAAa,WAAW;GAC1D,MAAM,eAAe,GAClB,KAAK,oBAAoB,UAAU,OACrC;AAED,SAAM,IAAI,MACR,gHACsB,KAAK,UAAU,aAAa,CAAC,IAAI,KAAK,UAHxC,EAAE,cAAc,EAAE,WAAW,OAAO,EAAE,CAKvD,CAAC,GACL;;EAGH,MAAM,EAAE,cAAc,OAAO;AAC7B,SAAO,aAAa,iBAClB,MAAM,KAAK,kBAAkB,UAAU;AACzC,SAAO"}
1
+ {"version":3,"file":"history.js","names":[],"sources":["../../src/runnables/history.ts"],"sourcesContent":["import {\n BaseChatMessageHistory,\n BaseListChatMessageHistory,\n} from \"../chat_history.js\";\nimport {\n AIMessage,\n BaseMessage,\n HumanMessage,\n isBaseMessage,\n} from \"../messages/index.js\";\nimport { Run } from \"../tracers/base.js\";\nimport {\n Runnable,\n RunnableBinding,\n type RunnableBindingArgs,\n RunnableLambda,\n} from \"./base.js\";\nimport { RunnableConfig } from \"./config.js\";\nimport { RunnablePassthrough } from \"./passthrough.js\";\n\ntype GetSessionHistoryCallable = (\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ...args: Array<any>\n) =>\n | Promise<BaseChatMessageHistory | BaseListChatMessageHistory>\n | BaseChatMessageHistory\n | BaseListChatMessageHistory;\n\nexport interface RunnableWithMessageHistoryInputs<\n RunInput,\n RunOutput,\n> extends Omit<RunnableBindingArgs<RunInput, RunOutput>, \"bound\" | \"config\"> {\n runnable: Runnable<RunInput, RunOutput>;\n getMessageHistory: GetSessionHistoryCallable;\n inputMessagesKey?: string;\n outputMessagesKey?: string;\n historyMessagesKey?: string;\n config?: RunnableConfig;\n}\n\n/**\n * Wraps a LCEL chain and manages history. It appends input messages\n * and chain outputs as history, and adds the current history messages to\n * the chain input.\n * @example\n * ```typescript\n * // pnpm install @langchain/anthropic @langchain/community @upstash/redis\n *\n * import {\n * ChatPromptTemplate,\n * MessagesPlaceholder,\n * } from \"@langchain/core/prompts\";\n * import { ChatAnthropic } from \"@langchain/anthropic\";\n * import { UpstashRedisChatMessageHistory } from \"@langchain/community/stores/message/upstash_redis\";\n * // For demos, you can also use an in-memory store:\n * // import { ChatMessageHistory } from \"@langchain/classic/stores/message/in_memory\";\n *\n * const prompt = ChatPromptTemplate.fromMessages([\n * [\"system\", \"You're an assistant who's good at {ability}\"],\n * new MessagesPlaceholder(\"history\"),\n * [\"human\", \"{question}\"],\n * ]);\n *\n * const chain = prompt.pipe(new ChatAnthropic({}));\n *\n * const chainWithHistory = new RunnableWithMessageHistory({\n * runnable: chain,\n * getMessageHistory: (sessionId) =>\n * new UpstashRedisChatMessageHistory({\n * sessionId,\n * config: {\n * url: process.env.UPSTASH_REDIS_REST_URL!,\n * token: process.env.UPSTASH_REDIS_REST_TOKEN!,\n * },\n * }),\n * inputMessagesKey: \"question\",\n * historyMessagesKey: \"history\",\n * });\n *\n * const result = await chainWithHistory.invoke(\n * {\n * ability: \"math\",\n * question: \"What does cosine mean?\",\n * },\n * {\n * configurable: {\n * sessionId: \"some_string_identifying_a_user\",\n * },\n * }\n * );\n *\n * const result2 = await chainWithHistory.invoke(\n * {\n * ability: \"math\",\n * question: \"What's its inverse?\",\n * },\n * {\n * configurable: {\n * sessionId: \"some_string_identifying_a_user\",\n * },\n * }\n * );\n * ```\n */\nexport class RunnableWithMessageHistory<\n RunInput,\n RunOutput,\n> extends RunnableBinding<RunInput, RunOutput> {\n runnable: Runnable<RunInput, RunOutput>;\n\n inputMessagesKey?: string;\n\n outputMessagesKey?: string;\n\n historyMessagesKey?: string;\n\n getMessageHistory: GetSessionHistoryCallable;\n\n constructor(fields: RunnableWithMessageHistoryInputs<RunInput, RunOutput>) {\n let historyChain: Runnable = RunnableLambda.from((input, options) =>\n this._enterHistory(input, options ?? {})\n ).withConfig({ runName: \"loadHistory\" });\n\n const messagesKey = fields.historyMessagesKey ?? fields.inputMessagesKey;\n if (messagesKey) {\n historyChain = RunnablePassthrough.assign({\n [messagesKey]: historyChain,\n }).withConfig({ runName: \"insertHistory\" });\n }\n\n const bound = historyChain\n .pipe(\n fields.runnable.withListeners({\n onEnd: (run, config) => this._exitHistory(run, config ?? {}),\n })\n )\n .withConfig({ runName: \"RunnableWithMessageHistory\" });\n\n const config = fields.config ?? {};\n\n super({\n ...fields,\n config,\n bound,\n });\n this.runnable = fields.runnable;\n this.getMessageHistory = fields.getMessageHistory;\n this.inputMessagesKey = fields.inputMessagesKey;\n this.outputMessagesKey = fields.outputMessagesKey;\n this.historyMessagesKey = fields.historyMessagesKey;\n }\n\n _getInputMessages(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n inputValue: string | BaseMessage | Array<BaseMessage> | Record<string, any>\n ): Array<BaseMessage> {\n let parsedInputValue;\n if (\n typeof inputValue === \"object\" &&\n !Array.isArray(inputValue) &&\n !isBaseMessage(inputValue)\n ) {\n let key;\n if (this.inputMessagesKey) {\n key = this.inputMessagesKey;\n } else if (Object.keys(inputValue).length === 1) {\n key = Object.keys(inputValue)[0];\n } else {\n key = \"input\";\n }\n if (Array.isArray(inputValue[key]) && Array.isArray(inputValue[key][0])) {\n parsedInputValue = inputValue[key][0];\n } else {\n parsedInputValue = inputValue[key];\n }\n } else {\n parsedInputValue = inputValue;\n }\n if (typeof parsedInputValue === \"string\") {\n return [new HumanMessage(parsedInputValue)];\n } else if (Array.isArray(parsedInputValue)) {\n return parsedInputValue;\n } else if (isBaseMessage(parsedInputValue)) {\n return [parsedInputValue];\n } else {\n throw new Error(\n `Expected a string, BaseMessage, or array of BaseMessages.\\nGot ${JSON.stringify(\n parsedInputValue,\n null,\n 2\n )}`\n );\n }\n }\n\n _getOutputMessages(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n outputValue: string | BaseMessage | Array<BaseMessage> | Record<string, any>\n ): Array<BaseMessage> {\n let parsedOutputValue;\n if (\n !Array.isArray(outputValue) &&\n !isBaseMessage(outputValue) &&\n typeof outputValue !== \"string\"\n ) {\n let key;\n if (this.outputMessagesKey !== undefined) {\n key = this.outputMessagesKey;\n } else if (Object.keys(outputValue).length === 1) {\n key = Object.keys(outputValue)[0];\n } else {\n key = \"output\";\n }\n // If you are wrapping a chat model directly\n // The output is actually this weird generations object\n if (outputValue.generations !== undefined) {\n parsedOutputValue = outputValue.generations[0][0].message;\n } else {\n parsedOutputValue = outputValue[key];\n }\n } else {\n parsedOutputValue = outputValue;\n }\n\n if (typeof parsedOutputValue === \"string\") {\n return [new AIMessage(parsedOutputValue)];\n } else if (Array.isArray(parsedOutputValue)) {\n return parsedOutputValue;\n } else if (isBaseMessage(parsedOutputValue)) {\n return [parsedOutputValue];\n } else {\n throw new Error(\n `Expected a string, BaseMessage, or array of BaseMessages. Received: ${JSON.stringify(\n parsedOutputValue,\n null,\n 2\n )}`\n );\n }\n }\n\n async _enterHistory(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n input: any,\n kwargs?: RunnableConfig\n ): Promise<BaseMessage[]> {\n const history = kwargs?.configurable?.messageHistory;\n const messages = await history.getMessages();\n if (this.historyMessagesKey === undefined) {\n return messages.concat(this._getInputMessages(input));\n }\n return messages;\n }\n\n async _exitHistory(run: Run, config: RunnableConfig): Promise<void> {\n const history = config.configurable?.messageHistory;\n\n // Get input messages\n let inputs;\n // Chat model inputs are nested arrays\n if (Array.isArray(run.inputs) && Array.isArray(run.inputs[0])) {\n inputs = run.inputs[0];\n } else {\n inputs = run.inputs;\n }\n let inputMessages = this._getInputMessages(inputs);\n // If historic messages were prepended to the input messages, remove them to\n // avoid adding duplicate messages to history.\n if (this.historyMessagesKey === undefined) {\n const existingMessages = await history.getMessages();\n inputMessages = inputMessages.slice(existingMessages.length);\n }\n // Get output messages\n const outputValue = run.outputs;\n if (!outputValue) {\n throw new Error(\n `Output values from 'Run' undefined. Run: ${JSON.stringify(\n run,\n null,\n 2\n )}`\n );\n }\n const outputMessages = this._getOutputMessages(outputValue);\n await history.addMessages([...inputMessages, ...outputMessages]);\n }\n\n async _mergeConfig(...configs: Array<RunnableConfig | undefined>) {\n const config = await super._mergeConfig(...configs);\n // Extract sessionId\n if (!config.configurable || !config.configurable.sessionId) {\n const exampleInput = {\n [this.inputMessagesKey ?? \"input\"]: \"foo\",\n };\n const exampleConfig = { configurable: { sessionId: \"123\" } };\n throw new Error(\n `sessionId is required. Pass it in as part of the config argument to .invoke() or .stream()\\n` +\n `eg. chain.invoke(${JSON.stringify(exampleInput)}, ${JSON.stringify(\n exampleConfig\n )})`\n );\n }\n // attach messageHistory\n const { sessionId } = config.configurable;\n config.configurable.messageHistory =\n await this.getMessageHistory(sessionId);\n return config;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AAc,MAAM,iBAAiB,OAAO;;EAG9D,MAAM,cAAc,IAAI;AACxB,MAAI,CAAC,YACH,OAAM,IAAI,MACR,4CAA4C,KAAK,UAC/C,KACA,MACA,EACD,GACF;EAEH,MAAM,iBAAiB,KAAK,mBAAmB,YAAY;AAC3D,QAAM,QAAQ,YAAY,CAAC,GAAG,eAAe,GAAG,eAAe,CAAC;;CAGlE,MAAM,aAAa,GAAG,SAA4C;EAChE,MAAM,SAAS,MAAM,MAAM,aAAa,GAAG,QAAQ;AAEnD,MAAI,CAAC,OAAO,gBAAgB,CAAC,OAAO,aAAa,WAAW;GAC1D,MAAM,eAAe,GAClB,KAAK,oBAAoB,UAAU,OACrC;AAED,SAAM,IAAI,MACR,gHACsB,KAAK,UAAU,aAAa,CAAC,IAAI,KAAK,UAHxC,EAAE,cAAc,EAAE,WAAW,OAAO,EAAE,CAKvD,CAAC,GACL;;EAGH,MAAM,EAAE,cAAc,OAAO;AAC7B,SAAO,aAAa,iBAClB,MAAM,KAAK,kBAAkB,UAAU;AACzC,SAAO"}
@@ -1,13 +1,12 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
3
- const require_config = require('./config.cjs');
4
- const require_signal = require('../utils/signal.cjs');
5
- const require_base = require('./base.cjs');
6
- const require_passthrough = require('./passthrough.cjs');
7
- const require_router = require('./router.cjs');
8
- const require_branch = require('./branch.cjs');
9
- const require_history = require('./history.cjs');
10
-
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_runtime = require("../_virtual/_rolldown/runtime.cjs");
3
+ const require_config = require("./config.cjs");
4
+ const require_signal = require("../utils/signal.cjs");
5
+ const require_base = require("./base.cjs");
6
+ const require_passthrough = require("./passthrough.cjs");
7
+ const require_router = require("./router.cjs");
8
+ const require_branch = require("./branch.cjs");
9
+ const require_history = require("./history.cjs");
11
10
  //#region src/runnables/index.ts
12
11
  var runnables_exports = /* @__PURE__ */ require_runtime.__exportAll({
13
12
  RouterRunnable: () => require_router.RouterRunnable,
@@ -34,7 +33,6 @@ var runnables_exports = /* @__PURE__ */ require_runtime.__exportAll({
34
33
  pickRunnableConfigKeys: () => require_config.pickRunnableConfigKeys,
35
34
  raceWithSignal: () => require_signal.raceWithSignal
36
35
  });
37
-
38
36
  //#endregion
39
37
  exports.RouterRunnable = require_router.RouterRunnable;
40
38
  exports.Runnable = require_base.Runnable;
@@ -59,10 +57,11 @@ exports.mergeConfigs = require_config.mergeConfigs;
59
57
  exports.patchConfig = require_config.patchConfig;
60
58
  exports.pickRunnableConfigKeys = require_config.pickRunnableConfigKeys;
61
59
  exports.raceWithSignal = require_signal.raceWithSignal;
62
- Object.defineProperty(exports, 'runnables_exports', {
63
- enumerable: true,
64
- get: function () {
65
- return runnables_exports;
66
- }
60
+ Object.defineProperty(exports, "runnables_exports", {
61
+ enumerable: true,
62
+ get: function() {
63
+ return runnables_exports;
64
+ }
67
65
  });
66
+
68
67
  //# sourceMappingURL=index.cjs.map
@@ -6,7 +6,6 @@ import { RunnablePassthrough } from "./passthrough.js";
6
6
  import { RouterRunnable } from "./router.js";
7
7
  import { RunnableBranch } from "./branch.js";
8
8
  import { RunnableWithMessageHistory } from "./history.js";
9
-
10
9
  //#region src/runnables/index.ts
11
10
  var runnables_exports = /* @__PURE__ */ __exportAll({
12
11
  RouterRunnable: () => RouterRunnable,
@@ -33,7 +32,7 @@ var runnables_exports = /* @__PURE__ */ __exportAll({
33
32
  pickRunnableConfigKeys: () => pickRunnableConfigKeys,
34
33
  raceWithSignal: () => raceWithSignal
35
34
  });
36
-
37
35
  //#endregion
38
36
  export { RouterRunnable, Runnable, RunnableAssign, RunnableBinding, RunnableBranch, RunnableEach, RunnableLambda, RunnableMap, RunnableParallel, RunnablePassthrough, RunnablePick, RunnableRetry, RunnableSequence, RunnableToolLike, RunnableWithFallbacks, RunnableWithMessageHistory, _coerceToRunnable, ensureConfig, getCallbackManagerForConfig, mergeConfigs, patchConfig, pickRunnableConfigKeys, raceWithSignal, runnables_exports };
37
+
39
38
  //# sourceMappingURL=index.js.map
@@ -1,7 +1,6 @@
1
- const require_index = require('../singletons/async_local_storage/index.cjs');
2
- require('../singletons/index.cjs');
3
- const require_config = require('./config.cjs');
4
-
1
+ const require_index = require("../singletons/async_local_storage/index.cjs");
2
+ require("../singletons/index.cjs");
3
+ const require_config = require("./config.cjs");
5
4
  //#region src/runnables/iter.ts
6
5
  function isIterableIterator(thing) {
7
6
  return typeof thing === "object" && thing !== null && typeof thing[Symbol.iterator] === "function" && typeof thing.next === "function";
@@ -40,7 +39,6 @@ async function* consumeAsyncIterableInContext(context, iter) {
40
39
  else yield value;
41
40
  }
42
41
  }
43
-
44
42
  //#endregion
45
43
  exports.consumeAsyncGenerator = consumeAsyncGenerator;
46
44
  exports.consumeAsyncIterableInContext = consumeAsyncIterableInContext;
@@ -49,4 +47,5 @@ exports.isAsyncGenerator = isAsyncGenerator;
49
47
  exports.isAsyncIterable = isAsyncIterable;
50
48
  exports.isIterableIterator = isIterableIterator;
51
49
  exports.isIterator = isIterator;
50
+
52
51
  //# sourceMappingURL=iter.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"iter.cjs","names":["AsyncLocalStorageProviderSingleton","pickRunnableConfigKeys"],"sources":["../../src/runnables/iter.ts"],"sourcesContent":["import type { RunnableConfig } from \"../runnables/types.js\";\nimport { AsyncLocalStorageProviderSingleton } from \"../singletons/index.js\";\nimport { pickRunnableConfigKeys } from \"./config.js\";\n\nexport function isIterableIterator(\n thing: unknown\n): thing is IterableIterator<unknown> {\n return (\n typeof thing === \"object\" &&\n thing !== null &&\n typeof (thing as Generator)[Symbol.iterator] === \"function\" &&\n // avoid detecting array/set as iterator\n typeof (thing as Generator).next === \"function\"\n );\n}\n\nexport const isIterator = (x: unknown): x is Iterator<unknown> =>\n x != null &&\n typeof x === \"object\" &&\n \"next\" in x &&\n typeof x.next === \"function\";\n\nexport function isAsyncIterable(\n thing: unknown\n): thing is AsyncIterable<unknown> {\n return (\n typeof thing === \"object\" &&\n thing !== null &&\n typeof (thing as AsyncIterable<unknown>)[Symbol.asyncIterator] ===\n \"function\"\n );\n}\n\nexport function isAsyncGenerator(x: unknown): x is AsyncGenerator {\n return (\n x != null &&\n typeof x === \"object\" &&\n typeof (x as AsyncGenerator).next === \"function\"\n );\n}\n\nexport async function consumeAsyncGenerator<T, TReturn>(\n generator: AsyncGenerator<T, TReturn>,\n onYield?: (value: T) => Promise<void> | void\n): Promise<TReturn> {\n try {\n let iterResult = await generator.next();\n while (!iterResult.done) {\n await onYield?.(iterResult.value);\n iterResult = await generator.next();\n }\n return iterResult.value;\n } finally {\n await generator.return?.(undefined as TReturn);\n }\n}\n\nexport function* consumeIteratorInContext<T>(\n context: Partial<RunnableConfig> | undefined,\n iter: IterableIterator<T>\n): IterableIterator<T> {\n while (true) {\n const { value, done } = AsyncLocalStorageProviderSingleton.runWithConfig(\n pickRunnableConfigKeys(context),\n iter.next.bind(iter),\n true\n );\n if (done) {\n break;\n } else {\n yield value;\n }\n }\n}\n\nexport async function* consumeAsyncIterableInContext<T>(\n context: Partial<RunnableConfig> | undefined,\n iter: AsyncIterable<T>\n): AsyncIterableIterator<T> {\n const iterator = iter[Symbol.asyncIterator]();\n while (true) {\n const { value, done } =\n await AsyncLocalStorageProviderSingleton.runWithConfig(\n pickRunnableConfigKeys(context),\n iterator.next.bind(iter),\n true\n );\n if (done) {\n break;\n } else {\n yield value;\n }\n }\n}\n"],"mappings":";;;;;AAIA,SAAgB,mBACd,OACoC;AACpC,QACE,OAAO,UAAU,YACjB,UAAU,QACV,OAAQ,MAAoB,OAAO,cAAc,cAEjD,OAAQ,MAAoB,SAAS;;AAIzC,MAAa,cAAc,MACzB,KAAK,QACL,OAAO,MAAM,YACb,UAAU,KACV,OAAO,EAAE,SAAS;AAEpB,SAAgB,gBACd,OACiC;AACjC,QACE,OAAO,UAAU,YACjB,UAAU,QACV,OAAQ,MAAiC,OAAO,mBAC9C;;AAIN,SAAgB,iBAAiB,GAAiC;AAChE,QACE,KAAK,QACL,OAAO,MAAM,YACb,OAAQ,EAAqB,SAAS;;AAI1C,eAAsB,sBACpB,WACA,SACkB;AAClB,KAAI;EACF,IAAI,aAAa,MAAM,UAAU,MAAM;AACvC,SAAO,CAAC,WAAW,MAAM;AACvB,SAAM,UAAU,WAAW,MAAM;AACjC,gBAAa,MAAM,UAAU,MAAM;;AAErC,SAAO,WAAW;WACV;AACR,QAAM,UAAU,SAAS,OAAqB;;;AAIlD,UAAiB,yBACf,SACA,MACqB;AACrB,QAAO,MAAM;EACX,MAAM,EAAE,OAAO,SAASA,iDAAmC,cACzDC,sCAAuB,QAAQ,EAC/B,KAAK,KAAK,KAAK,KAAK,EACpB,KACD;AACD,MAAI,KACF;MAEA,OAAM;;;AAKZ,gBAAuB,8BACrB,SACA,MAC0B;CAC1B,MAAM,WAAW,KAAK,OAAO,gBAAgB;AAC7C,QAAO,MAAM;EACX,MAAM,EAAE,OAAO,SACb,MAAMD,iDAAmC,cACvCC,sCAAuB,QAAQ,EAC/B,SAAS,KAAK,KAAK,KAAK,EACxB,KACD;AACH,MAAI,KACF;MAEA,OAAM"}
1
+ {"version":3,"file":"iter.cjs","names":["AsyncLocalStorageProviderSingleton","pickRunnableConfigKeys"],"sources":["../../src/runnables/iter.ts"],"sourcesContent":["import type { RunnableConfig } from \"../runnables/types.js\";\nimport { AsyncLocalStorageProviderSingleton } from \"../singletons/index.js\";\nimport { pickRunnableConfigKeys } from \"./config.js\";\n\nexport function isIterableIterator(\n thing: unknown\n): thing is IterableIterator<unknown> {\n return (\n typeof thing === \"object\" &&\n thing !== null &&\n typeof (thing as Generator)[Symbol.iterator] === \"function\" &&\n // avoid detecting array/set as iterator\n typeof (thing as Generator).next === \"function\"\n );\n}\n\nexport const isIterator = (x: unknown): x is Iterator<unknown> =>\n x != null &&\n typeof x === \"object\" &&\n \"next\" in x &&\n typeof x.next === \"function\";\n\nexport function isAsyncIterable(\n thing: unknown\n): thing is AsyncIterable<unknown> {\n return (\n typeof thing === \"object\" &&\n thing !== null &&\n typeof (thing as AsyncIterable<unknown>)[Symbol.asyncIterator] ===\n \"function\"\n );\n}\n\nexport function isAsyncGenerator(x: unknown): x is AsyncGenerator {\n return (\n x != null &&\n typeof x === \"object\" &&\n typeof (x as AsyncGenerator).next === \"function\"\n );\n}\n\nexport async function consumeAsyncGenerator<T, TReturn>(\n generator: AsyncGenerator<T, TReturn>,\n onYield?: (value: T) => Promise<void> | void\n): Promise<TReturn> {\n try {\n let iterResult = await generator.next();\n while (!iterResult.done) {\n await onYield?.(iterResult.value);\n iterResult = await generator.next();\n }\n return iterResult.value;\n } finally {\n await generator.return?.(undefined as TReturn);\n }\n}\n\nexport function* consumeIteratorInContext<T>(\n context: Partial<RunnableConfig> | undefined,\n iter: IterableIterator<T>\n): IterableIterator<T> {\n while (true) {\n const { value, done } = AsyncLocalStorageProviderSingleton.runWithConfig(\n pickRunnableConfigKeys(context),\n iter.next.bind(iter),\n true\n );\n if (done) {\n break;\n } else {\n yield value;\n }\n }\n}\n\nexport async function* consumeAsyncIterableInContext<T>(\n context: Partial<RunnableConfig> | undefined,\n iter: AsyncIterable<T>\n): AsyncIterableIterator<T> {\n const iterator = iter[Symbol.asyncIterator]();\n while (true) {\n const { value, done } =\n await AsyncLocalStorageProviderSingleton.runWithConfig(\n pickRunnableConfigKeys(context),\n iterator.next.bind(iter),\n true\n );\n if (done) {\n break;\n } else {\n yield value;\n }\n }\n}\n"],"mappings":";;;;AAIA,SAAgB,mBACd,OACoC;AACpC,QACE,OAAO,UAAU,YACjB,UAAU,QACV,OAAQ,MAAoB,OAAO,cAAc,cAEjD,OAAQ,MAAoB,SAAS;;AAIzC,MAAa,cAAc,MACzB,KAAK,QACL,OAAO,MAAM,YACb,UAAU,KACV,OAAO,EAAE,SAAS;AAEpB,SAAgB,gBACd,OACiC;AACjC,QACE,OAAO,UAAU,YACjB,UAAU,QACV,OAAQ,MAAiC,OAAO,mBAC9C;;AAIN,SAAgB,iBAAiB,GAAiC;AAChE,QACE,KAAK,QACL,OAAO,MAAM,YACb,OAAQ,EAAqB,SAAS;;AAI1C,eAAsB,sBACpB,WACA,SACkB;AAClB,KAAI;EACF,IAAI,aAAa,MAAM,UAAU,MAAM;AACvC,SAAO,CAAC,WAAW,MAAM;AACvB,SAAM,UAAU,WAAW,MAAM;AACjC,gBAAa,MAAM,UAAU,MAAM;;AAErC,SAAO,WAAW;WACV;AACR,QAAM,UAAU,SAAS,KAAA,EAAqB;;;AAIlD,UAAiB,yBACf,SACA,MACqB;AACrB,QAAO,MAAM;EACX,MAAM,EAAE,OAAO,SAASA,cAAAA,mCAAmC,cACzDC,eAAAA,uBAAuB,QAAQ,EAC/B,KAAK,KAAK,KAAK,KAAK,EACpB,KACD;AACD,MAAI,KACF;MAEA,OAAM;;;AAKZ,gBAAuB,8BACrB,SACA,MAC0B;CAC1B,MAAM,WAAW,KAAK,OAAO,gBAAgB;AAC7C,QAAO,MAAM;EACX,MAAM,EAAE,OAAO,SACb,MAAMD,cAAAA,mCAAmC,cACvCC,eAAAA,uBAAuB,QAAQ,EAC/B,SAAS,KAAK,KAAK,KAAK,EACxB,KACD;AACH,MAAI,KACF;MAEA,OAAM"}
@@ -1,7 +1,6 @@
1
1
  import { AsyncLocalStorageProviderSingleton } from "../singletons/async_local_storage/index.js";
2
2
  import "../singletons/index.js";
3
3
  import { pickRunnableConfigKeys } from "./config.js";
4
-
5
4
  //#region src/runnables/iter.ts
6
5
  function isIterableIterator(thing) {
7
6
  return typeof thing === "object" && thing !== null && typeof thing[Symbol.iterator] === "function" && typeof thing.next === "function";
@@ -40,7 +39,7 @@ async function* consumeAsyncIterableInContext(context, iter) {
40
39
  else yield value;
41
40
  }
42
41
  }
43
-
44
42
  //#endregion
45
43
  export { consumeAsyncGenerator, consumeAsyncIterableInContext, consumeIteratorInContext, isAsyncGenerator, isAsyncIterable, isIterableIterator, isIterator };
44
+
46
45
  //# sourceMappingURL=iter.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"iter.js","names":[],"sources":["../../src/runnables/iter.ts"],"sourcesContent":["import type { RunnableConfig } from \"../runnables/types.js\";\nimport { AsyncLocalStorageProviderSingleton } from \"../singletons/index.js\";\nimport { pickRunnableConfigKeys } from \"./config.js\";\n\nexport function isIterableIterator(\n thing: unknown\n): thing is IterableIterator<unknown> {\n return (\n typeof thing === \"object\" &&\n thing !== null &&\n typeof (thing as Generator)[Symbol.iterator] === \"function\" &&\n // avoid detecting array/set as iterator\n typeof (thing as Generator).next === \"function\"\n );\n}\n\nexport const isIterator = (x: unknown): x is Iterator<unknown> =>\n x != null &&\n typeof x === \"object\" &&\n \"next\" in x &&\n typeof x.next === \"function\";\n\nexport function isAsyncIterable(\n thing: unknown\n): thing is AsyncIterable<unknown> {\n return (\n typeof thing === \"object\" &&\n thing !== null &&\n typeof (thing as AsyncIterable<unknown>)[Symbol.asyncIterator] ===\n \"function\"\n );\n}\n\nexport function isAsyncGenerator(x: unknown): x is AsyncGenerator {\n return (\n x != null &&\n typeof x === \"object\" &&\n typeof (x as AsyncGenerator).next === \"function\"\n );\n}\n\nexport async function consumeAsyncGenerator<T, TReturn>(\n generator: AsyncGenerator<T, TReturn>,\n onYield?: (value: T) => Promise<void> | void\n): Promise<TReturn> {\n try {\n let iterResult = await generator.next();\n while (!iterResult.done) {\n await onYield?.(iterResult.value);\n iterResult = await generator.next();\n }\n return iterResult.value;\n } finally {\n await generator.return?.(undefined as TReturn);\n }\n}\n\nexport function* consumeIteratorInContext<T>(\n context: Partial<RunnableConfig> | undefined,\n iter: IterableIterator<T>\n): IterableIterator<T> {\n while (true) {\n const { value, done } = AsyncLocalStorageProviderSingleton.runWithConfig(\n pickRunnableConfigKeys(context),\n iter.next.bind(iter),\n true\n );\n if (done) {\n break;\n } else {\n yield value;\n }\n }\n}\n\nexport async function* consumeAsyncIterableInContext<T>(\n context: Partial<RunnableConfig> | undefined,\n iter: AsyncIterable<T>\n): AsyncIterableIterator<T> {\n const iterator = iter[Symbol.asyncIterator]();\n while (true) {\n const { value, done } =\n await AsyncLocalStorageProviderSingleton.runWithConfig(\n pickRunnableConfigKeys(context),\n iterator.next.bind(iter),\n true\n );\n if (done) {\n break;\n } else {\n yield value;\n }\n }\n}\n"],"mappings":";;;;;AAIA,SAAgB,mBACd,OACoC;AACpC,QACE,OAAO,UAAU,YACjB,UAAU,QACV,OAAQ,MAAoB,OAAO,cAAc,cAEjD,OAAQ,MAAoB,SAAS;;AAIzC,MAAa,cAAc,MACzB,KAAK,QACL,OAAO,MAAM,YACb,UAAU,KACV,OAAO,EAAE,SAAS;AAEpB,SAAgB,gBACd,OACiC;AACjC,QACE,OAAO,UAAU,YACjB,UAAU,QACV,OAAQ,MAAiC,OAAO,mBAC9C;;AAIN,SAAgB,iBAAiB,GAAiC;AAChE,QACE,KAAK,QACL,OAAO,MAAM,YACb,OAAQ,EAAqB,SAAS;;AAI1C,eAAsB,sBACpB,WACA,SACkB;AAClB,KAAI;EACF,IAAI,aAAa,MAAM,UAAU,MAAM;AACvC,SAAO,CAAC,WAAW,MAAM;AACvB,SAAM,UAAU,WAAW,MAAM;AACjC,gBAAa,MAAM,UAAU,MAAM;;AAErC,SAAO,WAAW;WACV;AACR,QAAM,UAAU,SAAS,OAAqB;;;AAIlD,UAAiB,yBACf,SACA,MACqB;AACrB,QAAO,MAAM;EACX,MAAM,EAAE,OAAO,SAAS,mCAAmC,cACzD,uBAAuB,QAAQ,EAC/B,KAAK,KAAK,KAAK,KAAK,EACpB,KACD;AACD,MAAI,KACF;MAEA,OAAM;;;AAKZ,gBAAuB,8BACrB,SACA,MAC0B;CAC1B,MAAM,WAAW,KAAK,OAAO,gBAAgB;AAC7C,QAAO,MAAM;EACX,MAAM,EAAE,OAAO,SACb,MAAM,mCAAmC,cACvC,uBAAuB,QAAQ,EAC/B,SAAS,KAAK,KAAK,KAAK,EACxB,KACD;AACH,MAAI,KACF;MAEA,OAAM"}
1
+ {"version":3,"file":"iter.js","names":[],"sources":["../../src/runnables/iter.ts"],"sourcesContent":["import type { RunnableConfig } from \"../runnables/types.js\";\nimport { AsyncLocalStorageProviderSingleton } from \"../singletons/index.js\";\nimport { pickRunnableConfigKeys } from \"./config.js\";\n\nexport function isIterableIterator(\n thing: unknown\n): thing is IterableIterator<unknown> {\n return (\n typeof thing === \"object\" &&\n thing !== null &&\n typeof (thing as Generator)[Symbol.iterator] === \"function\" &&\n // avoid detecting array/set as iterator\n typeof (thing as Generator).next === \"function\"\n );\n}\n\nexport const isIterator = (x: unknown): x is Iterator<unknown> =>\n x != null &&\n typeof x === \"object\" &&\n \"next\" in x &&\n typeof x.next === \"function\";\n\nexport function isAsyncIterable(\n thing: unknown\n): thing is AsyncIterable<unknown> {\n return (\n typeof thing === \"object\" &&\n thing !== null &&\n typeof (thing as AsyncIterable<unknown>)[Symbol.asyncIterator] ===\n \"function\"\n );\n}\n\nexport function isAsyncGenerator(x: unknown): x is AsyncGenerator {\n return (\n x != null &&\n typeof x === \"object\" &&\n typeof (x as AsyncGenerator).next === \"function\"\n );\n}\n\nexport async function consumeAsyncGenerator<T, TReturn>(\n generator: AsyncGenerator<T, TReturn>,\n onYield?: (value: T) => Promise<void> | void\n): Promise<TReturn> {\n try {\n let iterResult = await generator.next();\n while (!iterResult.done) {\n await onYield?.(iterResult.value);\n iterResult = await generator.next();\n }\n return iterResult.value;\n } finally {\n await generator.return?.(undefined as TReturn);\n }\n}\n\nexport function* consumeIteratorInContext<T>(\n context: Partial<RunnableConfig> | undefined,\n iter: IterableIterator<T>\n): IterableIterator<T> {\n while (true) {\n const { value, done } = AsyncLocalStorageProviderSingleton.runWithConfig(\n pickRunnableConfigKeys(context),\n iter.next.bind(iter),\n true\n );\n if (done) {\n break;\n } else {\n yield value;\n }\n }\n}\n\nexport async function* consumeAsyncIterableInContext<T>(\n context: Partial<RunnableConfig> | undefined,\n iter: AsyncIterable<T>\n): AsyncIterableIterator<T> {\n const iterator = iter[Symbol.asyncIterator]();\n while (true) {\n const { value, done } =\n await AsyncLocalStorageProviderSingleton.runWithConfig(\n pickRunnableConfigKeys(context),\n iterator.next.bind(iter),\n true\n );\n if (done) {\n break;\n } else {\n yield value;\n }\n }\n}\n"],"mappings":";;;;AAIA,SAAgB,mBACd,OACoC;AACpC,QACE,OAAO,UAAU,YACjB,UAAU,QACV,OAAQ,MAAoB,OAAO,cAAc,cAEjD,OAAQ,MAAoB,SAAS;;AAIzC,MAAa,cAAc,MACzB,KAAK,QACL,OAAO,MAAM,YACb,UAAU,KACV,OAAO,EAAE,SAAS;AAEpB,SAAgB,gBACd,OACiC;AACjC,QACE,OAAO,UAAU,YACjB,UAAU,QACV,OAAQ,MAAiC,OAAO,mBAC9C;;AAIN,SAAgB,iBAAiB,GAAiC;AAChE,QACE,KAAK,QACL,OAAO,MAAM,YACb,OAAQ,EAAqB,SAAS;;AAI1C,eAAsB,sBACpB,WACA,SACkB;AAClB,KAAI;EACF,IAAI,aAAa,MAAM,UAAU,MAAM;AACvC,SAAO,CAAC,WAAW,MAAM;AACvB,SAAM,UAAU,WAAW,MAAM;AACjC,gBAAa,MAAM,UAAU,MAAM;;AAErC,SAAO,WAAW;WACV;AACR,QAAM,UAAU,SAAS,KAAA,EAAqB;;;AAIlD,UAAiB,yBACf,SACA,MACqB;AACrB,QAAO,MAAM;EACX,MAAM,EAAE,OAAO,SAAS,mCAAmC,cACzD,uBAAuB,QAAQ,EAC/B,KAAK,KAAK,KAAK,KAAK,EACpB,KACD;AACD,MAAI,KACF;MAEA,OAAM;;;AAKZ,gBAAuB,8BACrB,SACA,MAC0B;CAC1B,MAAM,WAAW,KAAK,OAAO,gBAAgB;AAC7C,QAAO,MAAM;EACX,MAAM,EAAE,OAAO,SACb,MAAM,mCAAmC,cACvC,uBAAuB,QAAQ,EAC/B,SAAS,KAAK,KAAK,KAAK,EACxB,KACD;AACH,MAAI,KACF;MAEA,OAAM"}
@@ -1,7 +1,6 @@
1
- const require_config = require('./config.cjs');
2
- const require_utils_stream = require('../utils/stream.cjs');
3
- const require_base = require('./base.cjs');
4
-
1
+ const require_config = require("./config.cjs");
2
+ const require_utils_stream = require("../utils/stream.cjs");
3
+ const require_base = require("./base.cjs");
5
4
  //#region src/runnables/passthrough.ts
6
5
  /**
7
6
  * A runnable to passthrough inputs unchanged or with additional keys.
@@ -93,7 +92,7 @@ var RunnablePassthrough = class extends require_base.Runnable {
93
92
  return new require_base.RunnableAssign(new require_base.RunnableMap({ steps: mapping }));
94
93
  }
95
94
  };
96
-
97
95
  //#endregion
98
96
  exports.RunnablePassthrough = RunnablePassthrough;
97
+
99
98
  //# sourceMappingURL=passthrough.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"passthrough.cjs","names":["Runnable","ensureConfig","concat","RunnableAssign","RunnableMap"],"sources":["../../src/runnables/passthrough.ts"],"sourcesContent":["import { concat } from \"../utils/stream.js\";\nimport {\n Runnable,\n RunnableAssign,\n RunnableMap,\n RunnableMapLike,\n} from \"./base.js\";\nimport { ensureConfig, type RunnableConfig } from \"./config.js\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype RunnablePassthroughFunc<RunInput = any> =\n | ((input: RunInput) => void)\n | ((input: RunInput, config?: RunnableConfig) => void)\n | ((input: RunInput) => Promise<void>)\n | ((input: RunInput, config?: RunnableConfig) => Promise<void>);\n\n/**\n * A runnable to passthrough inputs unchanged or with additional keys.\n *\n * This runnable behaves almost like the identity function, except that it\n * can be configured to add additional keys to the output, if the input is\n * an object.\n *\n * The example below demonstrates how to use `RunnablePassthrough to\n * passthrough the input from the `.invoke()`\n *\n * @example\n * ```typescript\n * const chain = RunnableSequence.from([\n * {\n * question: new RunnablePassthrough(),\n * context: async () => loadContextFromStore(),\n * },\n * prompt,\n * llm,\n * outputParser,\n * ]);\n * const response = await chain.invoke(\n * \"I can pass a single string instead of an object since I'm using `RunnablePassthrough`.\"\n * );\n * ```\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport class RunnablePassthrough<RunInput = any> extends Runnable<\n RunInput,\n RunInput\n> {\n static lc_name() {\n return \"RunnablePassthrough\";\n }\n\n lc_namespace = [\"langchain_core\", \"runnables\"];\n\n lc_serializable = true;\n\n func?: RunnablePassthroughFunc<RunInput>;\n\n constructor(fields?: { func?: RunnablePassthroughFunc<RunInput> }) {\n super(fields);\n if (fields) {\n this.func = fields.func;\n }\n }\n\n async invoke(\n input: RunInput,\n options?: Partial<RunnableConfig>\n ): Promise<RunInput> {\n const config = ensureConfig(options);\n if (this.func) {\n await this.func(input, config);\n }\n\n return this._callWithConfig(\n (input: RunInput) => Promise.resolve(input),\n input,\n config\n );\n }\n\n async *transform(\n generator: AsyncGenerator<RunInput>,\n options: Partial<RunnableConfig>\n ): AsyncGenerator<RunInput> {\n const config = ensureConfig(options);\n let finalOutput: RunInput | undefined;\n let finalOutputSupported = true;\n\n for await (const chunk of this._transformStreamWithConfig(\n generator,\n (input: AsyncGenerator<RunInput>) => input,\n config\n )) {\n yield chunk;\n if (finalOutputSupported) {\n if (finalOutput === undefined) {\n finalOutput = chunk;\n } else {\n try {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n finalOutput = concat(finalOutput, chunk as any);\n } catch {\n finalOutput = undefined;\n finalOutputSupported = false;\n }\n }\n }\n }\n\n if (this.func && finalOutput !== undefined) {\n await this.func(finalOutput, config);\n }\n }\n\n /**\n * A runnable that assigns key-value pairs to the input.\n *\n * The example below shows how you could use it with an inline function.\n *\n * @example\n * ```typescript\n * const prompt =\n * PromptTemplate.fromTemplate(`Write a SQL query to answer the question using the following schema: {schema}\n * Question: {question}\n * SQL Query:`);\n *\n * // The `RunnablePassthrough.assign()` is used here to passthrough the input from the `.invoke()`\n * // call (in this example it's the question), along with any inputs passed to the `.assign()` method.\n * // In this case, we're passing the schema.\n * const sqlQueryGeneratorChain = RunnableSequence.from([\n * RunnablePassthrough.assign({\n * schema: async () => db.getTableInfo(),\n * }),\n * prompt,\n * new ChatOpenAI({ model: \"gpt-4o-mini\" }).withConfig({ stop: [\"\\nSQLResult:\"] }),\n * new StringOutputParser(),\n * ]);\n * const result = await sqlQueryGeneratorChain.invoke({\n * question: \"How many employees are there?\",\n * });\n * ```\n */\n static assign<\n RunInput extends Record<string, unknown> = Record<string, unknown>,\n RunOutput extends Record<string, unknown> = Record<string, unknown>,\n >(\n mapping: RunnableMapLike<RunInput, RunOutput>\n ): RunnableAssign<RunInput, RunInput & RunOutput> {\n return new RunnableAssign(new RunnableMap({ steps: mapping }));\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2CA,IAAa,sBAAb,cAAyDA,sBAGvD;CACA,OAAO,UAAU;AACf,SAAO;;CAGT,eAAe,CAAC,kBAAkB,YAAY;CAE9C,kBAAkB;CAElB;CAEA,YAAY,QAAuD;AACjE,QAAM,OAAO;AACb,MAAI,OACF,MAAK,OAAO,OAAO;;CAIvB,MAAM,OACJ,OACA,SACmB;EACnB,MAAM,SAASC,4BAAa,QAAQ;AACpC,MAAI,KAAK,KACP,OAAM,KAAK,KAAK,OAAO,OAAO;AAGhC,SAAO,KAAK,iBACT,UAAoB,QAAQ,QAAQ,MAAM,EAC3C,OACA,OACD;;CAGH,OAAO,UACL,WACA,SAC0B;EAC1B,MAAM,SAASA,4BAAa,QAAQ;EACpC,IAAI;EACJ,IAAI,uBAAuB;AAE3B,aAAW,MAAM,SAAS,KAAK,2BAC7B,YACC,UAAoC,OACrC,OACD,EAAE;AACD,SAAM;AACN,OAAI,qBACF,KAAI,gBAAgB,OAClB,eAAc;OAEd,KAAI;AAEF,kBAAcC,4BAAO,aAAa,MAAa;WACzC;AACN,kBAAc;AACd,2BAAuB;;;AAM/B,MAAI,KAAK,QAAQ,gBAAgB,OAC/B,OAAM,KAAK,KAAK,aAAa,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgCxC,OAAO,OAIL,SACgD;AAChD,SAAO,IAAIC,4BAAe,IAAIC,yBAAY,EAAE,OAAO,SAAS,CAAC,CAAC"}
1
+ {"version":3,"file":"passthrough.cjs","names":["Runnable","ensureConfig","concat","RunnableAssign","RunnableMap"],"sources":["../../src/runnables/passthrough.ts"],"sourcesContent":["import { concat } from \"../utils/stream.js\";\nimport {\n Runnable,\n RunnableAssign,\n RunnableMap,\n RunnableMapLike,\n} from \"./base.js\";\nimport { ensureConfig, type RunnableConfig } from \"./config.js\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype RunnablePassthroughFunc<RunInput = any> =\n | ((input: RunInput) => void)\n | ((input: RunInput, config?: RunnableConfig) => void)\n | ((input: RunInput) => Promise<void>)\n | ((input: RunInput, config?: RunnableConfig) => Promise<void>);\n\n/**\n * A runnable to passthrough inputs unchanged or with additional keys.\n *\n * This runnable behaves almost like the identity function, except that it\n * can be configured to add additional keys to the output, if the input is\n * an object.\n *\n * The example below demonstrates how to use `RunnablePassthrough to\n * passthrough the input from the `.invoke()`\n *\n * @example\n * ```typescript\n * const chain = RunnableSequence.from([\n * {\n * question: new RunnablePassthrough(),\n * context: async () => loadContextFromStore(),\n * },\n * prompt,\n * llm,\n * outputParser,\n * ]);\n * const response = await chain.invoke(\n * \"I can pass a single string instead of an object since I'm using `RunnablePassthrough`.\"\n * );\n * ```\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport class RunnablePassthrough<RunInput = any> extends Runnable<\n RunInput,\n RunInput\n> {\n static lc_name() {\n return \"RunnablePassthrough\";\n }\n\n lc_namespace = [\"langchain_core\", \"runnables\"];\n\n lc_serializable = true;\n\n func?: RunnablePassthroughFunc<RunInput>;\n\n constructor(fields?: { func?: RunnablePassthroughFunc<RunInput> }) {\n super(fields);\n if (fields) {\n this.func = fields.func;\n }\n }\n\n async invoke(\n input: RunInput,\n options?: Partial<RunnableConfig>\n ): Promise<RunInput> {\n const config = ensureConfig(options);\n if (this.func) {\n await this.func(input, config);\n }\n\n return this._callWithConfig(\n (input: RunInput) => Promise.resolve(input),\n input,\n config\n );\n }\n\n async *transform(\n generator: AsyncGenerator<RunInput>,\n options: Partial<RunnableConfig>\n ): AsyncGenerator<RunInput> {\n const config = ensureConfig(options);\n let finalOutput: RunInput | undefined;\n let finalOutputSupported = true;\n\n for await (const chunk of this._transformStreamWithConfig(\n generator,\n (input: AsyncGenerator<RunInput>) => input,\n config\n )) {\n yield chunk;\n if (finalOutputSupported) {\n if (finalOutput === undefined) {\n finalOutput = chunk;\n } else {\n try {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n finalOutput = concat(finalOutput, chunk as any);\n } catch {\n finalOutput = undefined;\n finalOutputSupported = false;\n }\n }\n }\n }\n\n if (this.func && finalOutput !== undefined) {\n await this.func(finalOutput, config);\n }\n }\n\n /**\n * A runnable that assigns key-value pairs to the input.\n *\n * The example below shows how you could use it with an inline function.\n *\n * @example\n * ```typescript\n * const prompt =\n * PromptTemplate.fromTemplate(`Write a SQL query to answer the question using the following schema: {schema}\n * Question: {question}\n * SQL Query:`);\n *\n * // The `RunnablePassthrough.assign()` is used here to passthrough the input from the `.invoke()`\n * // call (in this example it's the question), along with any inputs passed to the `.assign()` method.\n * // In this case, we're passing the schema.\n * const sqlQueryGeneratorChain = RunnableSequence.from([\n * RunnablePassthrough.assign({\n * schema: async () => db.getTableInfo(),\n * }),\n * prompt,\n * new ChatOpenAI({ model: \"gpt-4o-mini\" }).withConfig({ stop: [\"\\nSQLResult:\"] }),\n * new StringOutputParser(),\n * ]);\n * const result = await sqlQueryGeneratorChain.invoke({\n * question: \"How many employees are there?\",\n * });\n * ```\n */\n static assign<\n RunInput extends Record<string, unknown> = Record<string, unknown>,\n RunOutput extends Record<string, unknown> = Record<string, unknown>,\n >(\n mapping: RunnableMapLike<RunInput, RunOutput>\n ): RunnableAssign<RunInput, RunInput & RunOutput> {\n return new RunnableAssign(new RunnableMap({ steps: mapping }));\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2CA,IAAa,sBAAb,cAAyDA,aAAAA,SAGvD;CACA,OAAO,UAAU;AACf,SAAO;;CAGT,eAAe,CAAC,kBAAkB,YAAY;CAE9C,kBAAkB;CAElB;CAEA,YAAY,QAAuD;AACjE,QAAM,OAAO;AACb,MAAI,OACF,MAAK,OAAO,OAAO;;CAIvB,MAAM,OACJ,OACA,SACmB;EACnB,MAAM,SAASC,eAAAA,aAAa,QAAQ;AACpC,MAAI,KAAK,KACP,OAAM,KAAK,KAAK,OAAO,OAAO;AAGhC,SAAO,KAAK,iBACT,UAAoB,QAAQ,QAAQ,MAAM,EAC3C,OACA,OACD;;CAGH,OAAO,UACL,WACA,SAC0B;EAC1B,MAAM,SAASA,eAAAA,aAAa,QAAQ;EACpC,IAAI;EACJ,IAAI,uBAAuB;AAE3B,aAAW,MAAM,SAAS,KAAK,2BAC7B,YACC,UAAoC,OACrC,OACD,EAAE;AACD,SAAM;AACN,OAAI,qBACF,KAAI,gBAAgB,KAAA,EAClB,eAAc;OAEd,KAAI;AAEF,kBAAcC,qBAAAA,OAAO,aAAa,MAAa;WACzC;AACN,kBAAc,KAAA;AACd,2BAAuB;;;AAM/B,MAAI,KAAK,QAAQ,gBAAgB,KAAA,EAC/B,OAAM,KAAK,KAAK,aAAa,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgCxC,OAAO,OAIL,SACgD;AAChD,SAAO,IAAIC,aAAAA,eAAe,IAAIC,aAAAA,YAAY,EAAE,OAAO,SAAS,CAAC,CAAC"}
@@ -1,5 +1,4 @@
1
1
  import { RunnableConfig } from "./types.js";
2
- import "./config.js";
3
2
  import { Runnable, RunnableAssign, RunnableMapLike } from "./base.js";
4
3
 
5
4
  //#region src/runnables/passthrough.d.ts
@@ -1 +1 @@
1
- {"version":3,"file":"passthrough.d.ts","names":[],"sources":["../../src/runnables/passthrough.ts"],"mappings":";;;;;KAUK,uBAAA,qBACC,KAAA,EAAO,QAAA,eACP,KAAA,EAAO,QAAA,EAAU,MAAA,GAAS,cAAA,eAC1B,KAAA,EAAO,QAAA,KAAa,OAAA,YACpB,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AAA;EAOhD,MAAA,CACJ,KAAA,EAAO,QAAA,EACP,OAAA,GAAU,OAAA,CAAQ,cAAA,IACjB,OAAA,CAAQ,QAAA;EAaJ,SAAA,CACL,SAAA,EAAW,cAAA,CAAe,QAAA,GAC1B,OAAA,EAAS,OAAA,CAAQ,cAAA,IAChB,cAAA,CAAe,QAAA;EAtClB;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAAA,OAiGO,MAAA,kBACY,MAAA,oBAA0B,MAAA,qCACzB,MAAA,oBAA0B,MAAA,kBAAA,CAE5C,OAAA,EAAS,eAAA,CAAgB,QAAA,EAAU,SAAA,IAClC,cAAA,CAAe,QAAA,EAAU,QAAA,GAAW,SAAA;AAAA"}
@@ -1,7 +1,6 @@
1
1
  import { ensureConfig } from "./config.js";
2
2
  import { concat } from "../utils/stream.js";
3
3
  import { Runnable, RunnableAssign, RunnableMap } from "./base.js";
4
-
5
4
  //#region src/runnables/passthrough.ts
6
5
  /**
7
6
  * A runnable to passthrough inputs unchanged or with additional keys.
@@ -93,7 +92,7 @@ var RunnablePassthrough = class extends Runnable {
93
92
  return new RunnableAssign(new RunnableMap({ steps: mapping }));
94
93
  }
95
94
  };
96
-
97
95
  //#endregion
98
96
  export { RunnablePassthrough };
97
+
99
98
  //# sourceMappingURL=passthrough.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"passthrough.js","names":[],"sources":["../../src/runnables/passthrough.ts"],"sourcesContent":["import { concat } from \"../utils/stream.js\";\nimport {\n Runnable,\n RunnableAssign,\n RunnableMap,\n RunnableMapLike,\n} from \"./base.js\";\nimport { ensureConfig, type RunnableConfig } from \"./config.js\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype RunnablePassthroughFunc<RunInput = any> =\n | ((input: RunInput) => void)\n | ((input: RunInput, config?: RunnableConfig) => void)\n | ((input: RunInput) => Promise<void>)\n | ((input: RunInput, config?: RunnableConfig) => Promise<void>);\n\n/**\n * A runnable to passthrough inputs unchanged or with additional keys.\n *\n * This runnable behaves almost like the identity function, except that it\n * can be configured to add additional keys to the output, if the input is\n * an object.\n *\n * The example below demonstrates how to use `RunnablePassthrough to\n * passthrough the input from the `.invoke()`\n *\n * @example\n * ```typescript\n * const chain = RunnableSequence.from([\n * {\n * question: new RunnablePassthrough(),\n * context: async () => loadContextFromStore(),\n * },\n * prompt,\n * llm,\n * outputParser,\n * ]);\n * const response = await chain.invoke(\n * \"I can pass a single string instead of an object since I'm using `RunnablePassthrough`.\"\n * );\n * ```\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport class RunnablePassthrough<RunInput = any> extends Runnable<\n RunInput,\n RunInput\n> {\n static lc_name() {\n return \"RunnablePassthrough\";\n }\n\n lc_namespace = [\"langchain_core\", \"runnables\"];\n\n lc_serializable = true;\n\n func?: RunnablePassthroughFunc<RunInput>;\n\n constructor(fields?: { func?: RunnablePassthroughFunc<RunInput> }) {\n super(fields);\n if (fields) {\n this.func = fields.func;\n }\n }\n\n async invoke(\n input: RunInput,\n options?: Partial<RunnableConfig>\n ): Promise<RunInput> {\n const config = ensureConfig(options);\n if (this.func) {\n await this.func(input, config);\n }\n\n return this._callWithConfig(\n (input: RunInput) => Promise.resolve(input),\n input,\n config\n );\n }\n\n async *transform(\n generator: AsyncGenerator<RunInput>,\n options: Partial<RunnableConfig>\n ): AsyncGenerator<RunInput> {\n const config = ensureConfig(options);\n let finalOutput: RunInput | undefined;\n let finalOutputSupported = true;\n\n for await (const chunk of this._transformStreamWithConfig(\n generator,\n (input: AsyncGenerator<RunInput>) => input,\n config\n )) {\n yield chunk;\n if (finalOutputSupported) {\n if (finalOutput === undefined) {\n finalOutput = chunk;\n } else {\n try {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n finalOutput = concat(finalOutput, chunk as any);\n } catch {\n finalOutput = undefined;\n finalOutputSupported = false;\n }\n }\n }\n }\n\n if (this.func && finalOutput !== undefined) {\n await this.func(finalOutput, config);\n }\n }\n\n /**\n * A runnable that assigns key-value pairs to the input.\n *\n * The example below shows how you could use it with an inline function.\n *\n * @example\n * ```typescript\n * const prompt =\n * PromptTemplate.fromTemplate(`Write a SQL query to answer the question using the following schema: {schema}\n * Question: {question}\n * SQL Query:`);\n *\n * // The `RunnablePassthrough.assign()` is used here to passthrough the input from the `.invoke()`\n * // call (in this example it's the question), along with any inputs passed to the `.assign()` method.\n * // In this case, we're passing the schema.\n * const sqlQueryGeneratorChain = RunnableSequence.from([\n * RunnablePassthrough.assign({\n * schema: async () => db.getTableInfo(),\n * }),\n * prompt,\n * new ChatOpenAI({ model: \"gpt-4o-mini\" }).withConfig({ stop: [\"\\nSQLResult:\"] }),\n * new StringOutputParser(),\n * ]);\n * const result = await sqlQueryGeneratorChain.invoke({\n * question: \"How many employees are there?\",\n * });\n * ```\n */\n static assign<\n RunInput extends Record<string, unknown> = Record<string, unknown>,\n RunOutput extends Record<string, unknown> = Record<string, unknown>,\n >(\n mapping: RunnableMapLike<RunInput, RunOutput>\n ): RunnableAssign<RunInput, RunInput & RunOutput> {\n return new RunnableAssign(new RunnableMap({ steps: mapping }));\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2CA,IAAa,sBAAb,cAAyD,SAGvD;CACA,OAAO,UAAU;AACf,SAAO;;CAGT,eAAe,CAAC,kBAAkB,YAAY;CAE9C,kBAAkB;CAElB;CAEA,YAAY,QAAuD;AACjE,QAAM,OAAO;AACb,MAAI,OACF,MAAK,OAAO,OAAO;;CAIvB,MAAM,OACJ,OACA,SACmB;EACnB,MAAM,SAAS,aAAa,QAAQ;AACpC,MAAI,KAAK,KACP,OAAM,KAAK,KAAK,OAAO,OAAO;AAGhC,SAAO,KAAK,iBACT,UAAoB,QAAQ,QAAQ,MAAM,EAC3C,OACA,OACD;;CAGH,OAAO,UACL,WACA,SAC0B;EAC1B,MAAM,SAAS,aAAa,QAAQ;EACpC,IAAI;EACJ,IAAI,uBAAuB;AAE3B,aAAW,MAAM,SAAS,KAAK,2BAC7B,YACC,UAAoC,OACrC,OACD,EAAE;AACD,SAAM;AACN,OAAI,qBACF,KAAI,gBAAgB,OAClB,eAAc;OAEd,KAAI;AAEF,kBAAc,OAAO,aAAa,MAAa;WACzC;AACN,kBAAc;AACd,2BAAuB;;;AAM/B,MAAI,KAAK,QAAQ,gBAAgB,OAC/B,OAAM,KAAK,KAAK,aAAa,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgCxC,OAAO,OAIL,SACgD;AAChD,SAAO,IAAI,eAAe,IAAI,YAAY,EAAE,OAAO,SAAS,CAAC,CAAC"}
1
+ {"version":3,"file":"passthrough.js","names":[],"sources":["../../src/runnables/passthrough.ts"],"sourcesContent":["import { concat } from \"../utils/stream.js\";\nimport {\n Runnable,\n RunnableAssign,\n RunnableMap,\n RunnableMapLike,\n} from \"./base.js\";\nimport { ensureConfig, type RunnableConfig } from \"./config.js\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype RunnablePassthroughFunc<RunInput = any> =\n | ((input: RunInput) => void)\n | ((input: RunInput, config?: RunnableConfig) => void)\n | ((input: RunInput) => Promise<void>)\n | ((input: RunInput, config?: RunnableConfig) => Promise<void>);\n\n/**\n * A runnable to passthrough inputs unchanged or with additional keys.\n *\n * This runnable behaves almost like the identity function, except that it\n * can be configured to add additional keys to the output, if the input is\n * an object.\n *\n * The example below demonstrates how to use `RunnablePassthrough to\n * passthrough the input from the `.invoke()`\n *\n * @example\n * ```typescript\n * const chain = RunnableSequence.from([\n * {\n * question: new RunnablePassthrough(),\n * context: async () => loadContextFromStore(),\n * },\n * prompt,\n * llm,\n * outputParser,\n * ]);\n * const response = await chain.invoke(\n * \"I can pass a single string instead of an object since I'm using `RunnablePassthrough`.\"\n * );\n * ```\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport class RunnablePassthrough<RunInput = any> extends Runnable<\n RunInput,\n RunInput\n> {\n static lc_name() {\n return \"RunnablePassthrough\";\n }\n\n lc_namespace = [\"langchain_core\", \"runnables\"];\n\n lc_serializable = true;\n\n func?: RunnablePassthroughFunc<RunInput>;\n\n constructor(fields?: { func?: RunnablePassthroughFunc<RunInput> }) {\n super(fields);\n if (fields) {\n this.func = fields.func;\n }\n }\n\n async invoke(\n input: RunInput,\n options?: Partial<RunnableConfig>\n ): Promise<RunInput> {\n const config = ensureConfig(options);\n if (this.func) {\n await this.func(input, config);\n }\n\n return this._callWithConfig(\n (input: RunInput) => Promise.resolve(input),\n input,\n config\n );\n }\n\n async *transform(\n generator: AsyncGenerator<RunInput>,\n options: Partial<RunnableConfig>\n ): AsyncGenerator<RunInput> {\n const config = ensureConfig(options);\n let finalOutput: RunInput | undefined;\n let finalOutputSupported = true;\n\n for await (const chunk of this._transformStreamWithConfig(\n generator,\n (input: AsyncGenerator<RunInput>) => input,\n config\n )) {\n yield chunk;\n if (finalOutputSupported) {\n if (finalOutput === undefined) {\n finalOutput = chunk;\n } else {\n try {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n finalOutput = concat(finalOutput, chunk as any);\n } catch {\n finalOutput = undefined;\n finalOutputSupported = false;\n }\n }\n }\n }\n\n if (this.func && finalOutput !== undefined) {\n await this.func(finalOutput, config);\n }\n }\n\n /**\n * A runnable that assigns key-value pairs to the input.\n *\n * The example below shows how you could use it with an inline function.\n *\n * @example\n * ```typescript\n * const prompt =\n * PromptTemplate.fromTemplate(`Write a SQL query to answer the question using the following schema: {schema}\n * Question: {question}\n * SQL Query:`);\n *\n * // The `RunnablePassthrough.assign()` is used here to passthrough the input from the `.invoke()`\n * // call (in this example it's the question), along with any inputs passed to the `.assign()` method.\n * // In this case, we're passing the schema.\n * const sqlQueryGeneratorChain = RunnableSequence.from([\n * RunnablePassthrough.assign({\n * schema: async () => db.getTableInfo(),\n * }),\n * prompt,\n * new ChatOpenAI({ model: \"gpt-4o-mini\" }).withConfig({ stop: [\"\\nSQLResult:\"] }),\n * new StringOutputParser(),\n * ]);\n * const result = await sqlQueryGeneratorChain.invoke({\n * question: \"How many employees are there?\",\n * });\n * ```\n */\n static assign<\n RunInput extends Record<string, unknown> = Record<string, unknown>,\n RunOutput extends Record<string, unknown> = Record<string, unknown>,\n >(\n mapping: RunnableMapLike<RunInput, RunOutput>\n ): RunnableAssign<RunInput, RunInput & RunOutput> {\n return new RunnableAssign(new RunnableMap({ steps: mapping }));\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2CA,IAAa,sBAAb,cAAyD,SAGvD;CACA,OAAO,UAAU;AACf,SAAO;;CAGT,eAAe,CAAC,kBAAkB,YAAY;CAE9C,kBAAkB;CAElB;CAEA,YAAY,QAAuD;AACjE,QAAM,OAAO;AACb,MAAI,OACF,MAAK,OAAO,OAAO;;CAIvB,MAAM,OACJ,OACA,SACmB;EACnB,MAAM,SAAS,aAAa,QAAQ;AACpC,MAAI,KAAK,KACP,OAAM,KAAK,KAAK,OAAO,OAAO;AAGhC,SAAO,KAAK,iBACT,UAAoB,QAAQ,QAAQ,MAAM,EAC3C,OACA,OACD;;CAGH,OAAO,UACL,WACA,SAC0B;EAC1B,MAAM,SAAS,aAAa,QAAQ;EACpC,IAAI;EACJ,IAAI,uBAAuB;AAE3B,aAAW,MAAM,SAAS,KAAK,2BAC7B,YACC,UAAoC,OACrC,OACD,EAAE;AACD,SAAM;AACN,OAAI,qBACF,KAAI,gBAAgB,KAAA,EAClB,eAAc;OAEd,KAAI;AAEF,kBAAc,OAAO,aAAa,MAAa;WACzC;AACN,kBAAc,KAAA;AACd,2BAAuB;;;AAM/B,MAAI,KAAK,QAAQ,gBAAgB,KAAA,EAC/B,OAAM,KAAK,KAAK,aAAa,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgCxC,OAAO,OAIL,SACgD;AAChD,SAAO,IAAI,eAAe,IAAI,YAAY,EAAE,OAAO,SAAS,CAAC,CAAC"}