langchain 1.0.0-alpha.5 → 1.0.0-alpha.6

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 (351) hide show
  1. package/dist/agents/ReactAgent.cjs +5 -5
  2. package/dist/agents/ReactAgent.cjs.map +1 -1
  3. package/dist/agents/ReactAgent.d.cts +1 -3
  4. package/dist/agents/ReactAgent.d.cts.map +1 -1
  5. package/dist/agents/ReactAgent.d.ts +1 -3
  6. package/dist/agents/ReactAgent.d.ts.map +1 -1
  7. package/dist/agents/ReactAgent.js +6 -6
  8. package/dist/agents/ReactAgent.js.map +1 -1
  9. package/dist/agents/annotation.cjs.map +1 -1
  10. package/dist/agents/annotation.d.cts +4 -6
  11. package/dist/agents/annotation.d.cts.map +1 -1
  12. package/dist/agents/annotation.d.ts +4 -6
  13. package/dist/agents/annotation.d.ts.map +1 -1
  14. package/dist/agents/annotation.js.map +1 -1
  15. package/dist/agents/createAgent.cjs.map +1 -1
  16. package/dist/agents/createAgent.js.map +1 -1
  17. package/dist/agents/index.cjs +2 -2
  18. package/dist/agents/index.cjs.map +1 -1
  19. package/dist/agents/index.d.cts +47 -47
  20. package/dist/agents/index.d.cts.map +1 -1
  21. package/dist/agents/index.d.ts +47 -47
  22. package/dist/agents/index.d.ts.map +1 -1
  23. package/dist/agents/index.js +2 -2
  24. package/dist/agents/index.js.map +1 -1
  25. package/dist/agents/middlewareAgent/ReactAgent.cjs +18 -18
  26. package/dist/agents/middlewareAgent/ReactAgent.cjs.map +1 -1
  27. package/dist/agents/middlewareAgent/ReactAgent.d.cts +8 -9
  28. package/dist/agents/middlewareAgent/ReactAgent.d.cts.map +1 -1
  29. package/dist/agents/middlewareAgent/ReactAgent.d.ts +8 -9
  30. package/dist/agents/middlewareAgent/ReactAgent.d.ts.map +1 -1
  31. package/dist/agents/middlewareAgent/ReactAgent.js +18 -18
  32. package/dist/agents/middlewareAgent/ReactAgent.js.map +1 -1
  33. package/dist/agents/middlewareAgent/annotation.cjs +2 -2
  34. package/dist/agents/middlewareAgent/annotation.cjs.map +1 -1
  35. package/dist/agents/middlewareAgent/annotation.js +2 -2
  36. package/dist/agents/middlewareAgent/annotation.js.map +1 -1
  37. package/dist/agents/middlewareAgent/index.cjs.map +1 -1
  38. package/dist/agents/middlewareAgent/index.js.map +1 -1
  39. package/dist/agents/middlewareAgent/{middlewares → middleware}/hitl.cjs +8 -8
  40. package/dist/agents/middlewareAgent/middleware/hitl.cjs.map +1 -0
  41. package/dist/agents/middlewareAgent/{middlewares → middleware}/hitl.d.cts +3 -3
  42. package/dist/agents/middlewareAgent/middleware/hitl.d.cts.map +1 -0
  43. package/dist/agents/middlewareAgent/{middlewares → middleware}/hitl.d.ts +3 -3
  44. package/dist/agents/middlewareAgent/middleware/hitl.d.ts.map +1 -0
  45. package/dist/agents/middlewareAgent/{middlewares → middleware}/hitl.js +3 -3
  46. package/dist/agents/middlewareAgent/middleware/hitl.js.map +1 -0
  47. package/dist/agents/middlewareAgent/middleware/index.cjs +26 -0
  48. package/dist/agents/middlewareAgent/middleware/index.cjs.map +1 -0
  49. package/dist/agents/middlewareAgent/middleware/index.js +17 -0
  50. package/dist/agents/middlewareAgent/middleware/index.js.map +1 -0
  51. package/dist/agents/middlewareAgent/{middlewares → middleware}/promptCaching.cjs +51 -22
  52. package/dist/agents/middlewareAgent/middleware/promptCaching.cjs.map +1 -0
  53. package/dist/agents/middlewareAgent/{middlewares → middleware}/promptCaching.d.cts +9 -9
  54. package/dist/agents/middlewareAgent/middleware/promptCaching.d.cts.map +1 -0
  55. package/dist/agents/middlewareAgent/{middlewares → middleware}/promptCaching.d.ts +9 -9
  56. package/dist/agents/middlewareAgent/middleware/promptCaching.d.ts.map +1 -0
  57. package/dist/agents/middlewareAgent/{middlewares → middleware}/promptCaching.js +50 -21
  58. package/dist/agents/middlewareAgent/middleware/promptCaching.js.map +1 -0
  59. package/dist/agents/middlewareAgent/{middlewares → middleware}/summarization.cjs +11 -11
  60. package/dist/agents/middlewareAgent/middleware/summarization.cjs.map +1 -0
  61. package/dist/agents/middlewareAgent/{middlewares → middleware}/summarization.d.cts +3 -3
  62. package/dist/agents/middlewareAgent/middleware/summarization.d.cts.map +1 -0
  63. package/dist/agents/middlewareAgent/{middlewares → middleware}/summarization.d.ts +10 -10
  64. package/dist/agents/middlewareAgent/{middlewares/summarization.d.cts.map → middleware/summarization.d.ts.map} +1 -1
  65. package/dist/agents/middlewareAgent/{middlewares → middleware}/summarization.js +4 -4
  66. package/dist/agents/middlewareAgent/middleware/summarization.js.map +1 -0
  67. package/dist/agents/middlewareAgent/middleware.cjs.map +1 -1
  68. package/dist/agents/middlewareAgent/middleware.d.cts +1 -1
  69. package/dist/agents/middlewareAgent/middleware.d.cts.map +1 -1
  70. package/dist/agents/middlewareAgent/middleware.d.ts +1 -1
  71. package/dist/agents/middlewareAgent/middleware.d.ts.map +1 -1
  72. package/dist/agents/middlewareAgent/middleware.js.map +1 -1
  73. package/dist/agents/middlewareAgent/nodes/AfterModalNode.cjs.map +1 -1
  74. package/dist/agents/middlewareAgent/nodes/AfterModalNode.js.map +1 -1
  75. package/dist/agents/middlewareAgent/nodes/AgentNode.cjs +12 -19
  76. package/dist/agents/middlewareAgent/nodes/AgentNode.cjs.map +1 -1
  77. package/dist/agents/middlewareAgent/nodes/AgentNode.js +12 -19
  78. package/dist/agents/middlewareAgent/nodes/AgentNode.js.map +1 -1
  79. package/dist/agents/middlewareAgent/nodes/BeforeModalNode.cjs.map +1 -1
  80. package/dist/agents/middlewareAgent/nodes/BeforeModalNode.js.map +1 -1
  81. package/dist/agents/middlewareAgent/nodes/middleware.cjs.map +1 -1
  82. package/dist/agents/middlewareAgent/nodes/middleware.js.map +1 -1
  83. package/dist/agents/middlewareAgent/nodes/utils.cjs +7 -7
  84. package/dist/agents/middlewareAgent/nodes/utils.cjs.map +1 -1
  85. package/dist/agents/middlewareAgent/nodes/utils.js +3 -3
  86. package/dist/agents/middlewareAgent/nodes/utils.js.map +1 -1
  87. package/dist/agents/middlewareAgent/types.d.cts +10 -23
  88. package/dist/agents/middlewareAgent/types.d.cts.map +1 -1
  89. package/dist/agents/middlewareAgent/types.d.ts +10 -23
  90. package/dist/agents/middlewareAgent/types.d.ts.map +1 -1
  91. package/dist/agents/nodes/AgentNode.cjs +4 -4
  92. package/dist/agents/nodes/AgentNode.cjs.map +1 -1
  93. package/dist/agents/nodes/AgentNode.js +4 -4
  94. package/dist/agents/nodes/AgentNode.js.map +1 -1
  95. package/dist/agents/nodes/ToolNode.cjs +3 -3
  96. package/dist/agents/nodes/ToolNode.cjs.map +1 -1
  97. package/dist/agents/nodes/ToolNode.d.cts +1 -2
  98. package/dist/agents/nodes/ToolNode.d.cts.map +1 -1
  99. package/dist/agents/nodes/ToolNode.d.ts +1 -2
  100. package/dist/agents/nodes/ToolNode.d.ts.map +1 -1
  101. package/dist/agents/nodes/ToolNode.js +4 -4
  102. package/dist/agents/nodes/ToolNode.js.map +1 -1
  103. package/dist/agents/responses.cjs +1 -1
  104. package/dist/agents/responses.cjs.map +1 -1
  105. package/dist/agents/responses.d.cts.map +1 -1
  106. package/dist/agents/responses.d.ts.map +1 -1
  107. package/dist/agents/responses.js +1 -1
  108. package/dist/agents/responses.js.map +1 -1
  109. package/dist/agents/types.d.cts +1 -3
  110. package/dist/agents/types.d.cts.map +1 -1
  111. package/dist/agents/types.d.ts +1 -3
  112. package/dist/agents/types.d.ts.map +1 -1
  113. package/dist/agents/utils.cjs +6 -6
  114. package/dist/agents/utils.cjs.map +1 -1
  115. package/dist/agents/utils.js +7 -7
  116. package/dist/agents/utils.js.map +1 -1
  117. package/dist/agents/withAgentName.cjs.map +1 -1
  118. package/dist/agents/withAgentName.js.map +1 -1
  119. package/dist/chains/api/prompts.cjs.map +1 -1
  120. package/dist/chains/api/prompts.js.map +1 -1
  121. package/dist/chains/constitutional_ai/constitutional_chain.cjs.map +1 -1
  122. package/dist/chains/constitutional_ai/constitutional_chain.js.map +1 -1
  123. package/dist/chains/index.cjs +0 -3
  124. package/dist/chains/index.cjs.map +1 -1
  125. package/dist/chains/index.d.cts +1 -2
  126. package/dist/chains/index.d.ts +1 -2
  127. package/dist/chains/index.js +1 -3
  128. package/dist/chains/index.js.map +1 -1
  129. package/dist/chains/openai_functions/extraction.cjs.map +1 -1
  130. package/dist/chains/openai_functions/extraction.d.cts +1 -3
  131. package/dist/chains/openai_functions/extraction.d.cts.map +1 -1
  132. package/dist/chains/openai_functions/extraction.d.ts +1 -3
  133. package/dist/chains/openai_functions/extraction.d.ts.map +1 -1
  134. package/dist/chains/openai_functions/extraction.js.map +1 -1
  135. package/dist/chains/openai_functions/index.cjs +0 -5
  136. package/dist/chains/openai_functions/index.cjs.map +1 -1
  137. package/dist/chains/openai_functions/index.d.cts +1 -2
  138. package/dist/chains/openai_functions/index.d.ts +1 -2
  139. package/dist/chains/openai_functions/index.js +1 -4
  140. package/dist/chains/openai_functions/index.js.map +1 -1
  141. package/dist/chains/openai_functions/openapi.cjs +4 -4
  142. package/dist/chains/openai_functions/openapi.cjs.map +1 -1
  143. package/dist/chains/openai_functions/openapi.d.cts +1 -1
  144. package/dist/chains/openai_functions/openapi.js +4 -4
  145. package/dist/chains/openai_functions/openapi.js.map +1 -1
  146. package/dist/chains/openai_functions/tagging.cjs.map +1 -1
  147. package/dist/chains/openai_functions/tagging.d.cts +1 -3
  148. package/dist/chains/openai_functions/tagging.d.cts.map +1 -1
  149. package/dist/chains/openai_functions/tagging.d.ts +1 -3
  150. package/dist/chains/openai_functions/tagging.d.ts.map +1 -1
  151. package/dist/chains/openai_functions/tagging.js.map +1 -1
  152. package/dist/chains/query_constructor/index.cjs +4 -4
  153. package/dist/chains/query_constructor/index.cjs.map +1 -1
  154. package/dist/chains/query_constructor/index.d.cts +4 -2
  155. package/dist/chains/query_constructor/index.d.cts.map +1 -1
  156. package/dist/chains/query_constructor/index.d.ts +4 -2
  157. package/dist/chains/query_constructor/index.d.ts.map +1 -1
  158. package/dist/chains/query_constructor/index.js +1 -1
  159. package/dist/chains/query_constructor/index.js.map +1 -1
  160. package/dist/chains/question_answering/load.d.ts +2 -2
  161. package/dist/chains/question_answering/load.d.ts.map +1 -1
  162. package/dist/chains/question_answering/map_reduce_prompts.cjs.map +1 -1
  163. package/dist/chains/question_answering/map_reduce_prompts.js.map +1 -1
  164. package/dist/chains/question_answering/refine_prompts.cjs.map +1 -1
  165. package/dist/chains/question_answering/refine_prompts.js.map +1 -1
  166. package/dist/chains/question_answering/stuff_prompts.cjs.map +1 -1
  167. package/dist/chains/question_answering/stuff_prompts.js.map +1 -1
  168. package/dist/chains/router/multi_prompt.cjs +4 -4
  169. package/dist/chains/router/multi_prompt.cjs.map +1 -1
  170. package/dist/chains/router/multi_prompt.js +1 -1
  171. package/dist/chains/router/multi_prompt.js.map +1 -1
  172. package/dist/chains/router/multi_retrieval_qa.cjs +4 -4
  173. package/dist/chains/router/multi_retrieval_qa.cjs.map +1 -1
  174. package/dist/chains/router/multi_retrieval_qa.js +1 -1
  175. package/dist/chains/router/multi_retrieval_qa.js.map +1 -1
  176. package/dist/chains/sql_db/sql_db_prompt.cjs.map +1 -1
  177. package/dist/chains/sql_db/sql_db_prompt.d.cts.map +1 -1
  178. package/dist/chains/sql_db/sql_db_prompt.d.ts.map +1 -1
  179. package/dist/chains/sql_db/sql_db_prompt.js.map +1 -1
  180. package/dist/chains/summarization/load.d.ts +2 -2
  181. package/dist/chains/summarization/load.d.ts.map +1 -1
  182. package/dist/chains/summarization/stuff_prompts.cjs.map +1 -1
  183. package/dist/chains/summarization/stuff_prompts.js.map +1 -1
  184. package/dist/chat_models/universal.cjs +8 -5
  185. package/dist/chat_models/universal.cjs.map +1 -1
  186. package/dist/chat_models/universal.d.cts +2 -2
  187. package/dist/chat_models/universal.d.cts.map +1 -1
  188. package/dist/chat_models/universal.d.ts +2 -2
  189. package/dist/chat_models/universal.d.ts.map +1 -1
  190. package/dist/chat_models/universal.js +8 -5
  191. package/dist/chat_models/universal.js.map +1 -1
  192. package/dist/document_loaders/fs/directory.cjs.map +1 -1
  193. package/dist/document_loaders/fs/directory.d.cts +0 -1
  194. package/dist/document_loaders/fs/directory.d.cts.map +1 -1
  195. package/dist/document_loaders/fs/directory.d.ts +0 -1
  196. package/dist/document_loaders/fs/directory.d.ts.map +1 -1
  197. package/dist/document_loaders/fs/directory.js.map +1 -1
  198. package/dist/document_loaders/fs/json.cjs +7 -1
  199. package/dist/document_loaders/fs/json.cjs.map +1 -1
  200. package/dist/document_loaders/fs/json.js +7 -1
  201. package/dist/document_loaders/fs/json.js.map +1 -1
  202. package/dist/embeddings/cache_backed.cjs +1 -1
  203. package/dist/embeddings/cache_backed.cjs.map +1 -1
  204. package/dist/embeddings/cache_backed.d.cts +1 -1
  205. package/dist/embeddings/cache_backed.d.ts +1 -1
  206. package/dist/embeddings/cache_backed.js +2 -2
  207. package/dist/embeddings/cache_backed.js.map +1 -1
  208. package/dist/evaluation/agents/trajectory.d.cts.map +1 -1
  209. package/dist/evaluation/comparison/pairwise.d.ts.map +1 -1
  210. package/dist/evaluation/criteria/criteria.d.ts.map +1 -1
  211. package/dist/evaluation/embedding_distance/base.cjs +2 -4
  212. package/dist/evaluation/embedding_distance/base.cjs.map +1 -1
  213. package/dist/evaluation/embedding_distance/base.js +2 -3
  214. package/dist/evaluation/embedding_distance/base.js.map +1 -1
  215. package/dist/evaluation/loader.cjs +7 -12
  216. package/dist/evaluation/loader.cjs.map +1 -1
  217. package/dist/evaluation/loader.d.cts +8 -2
  218. package/dist/evaluation/loader.d.cts.map +1 -1
  219. package/dist/evaluation/loader.d.ts +8 -2
  220. package/dist/evaluation/loader.d.ts.map +1 -1
  221. package/dist/evaluation/loader.js +7 -12
  222. package/dist/evaluation/loader.js.map +1 -1
  223. package/dist/hub/base.cjs.map +1 -1
  224. package/dist/hub/base.js.map +1 -1
  225. package/dist/langchain-core/dist/load/serializable.d.cts.map +1 -1
  226. package/dist/langchain-core/dist/messages/base.d.cts +24 -33
  227. package/dist/langchain-core/dist/messages/base.d.cts.map +1 -1
  228. package/dist/langchain-core/dist/messages/content/index.d.cts +1 -1
  229. package/dist/langchain-core/dist/messages/content/index.d.cts.map +1 -1
  230. package/dist/langchain-core/dist/messages/message.d.cts +598 -0
  231. package/dist/langchain-core/dist/messages/message.d.cts.map +1 -0
  232. package/dist/langchain-core/dist/messages/metadata.d.cts +97 -0
  233. package/dist/langchain-core/dist/messages/metadata.d.cts.map +1 -0
  234. package/dist/langchain-core/dist/messages/utils.d.cts +75 -0
  235. package/dist/langchain-core/dist/messages/utils.d.cts.map +1 -0
  236. package/dist/langchain-core/dist/prompt_values.d.cts.map +1 -1
  237. package/dist/libs/langchain-core/dist/load/serializable.d.ts.map +1 -1
  238. package/dist/libs/langchain-core/dist/messages/base.d.ts +24 -33
  239. package/dist/libs/langchain-core/dist/messages/base.d.ts.map +1 -1
  240. package/dist/libs/langchain-core/dist/messages/content/index.d.ts +1 -1
  241. package/dist/libs/langchain-core/dist/messages/content/index.d.ts.map +1 -1
  242. package/dist/libs/langchain-core/dist/messages/message.d.ts +598 -0
  243. package/dist/libs/langchain-core/dist/messages/message.d.ts.map +1 -0
  244. package/dist/libs/langchain-core/dist/messages/metadata.d.ts +97 -0
  245. package/dist/libs/langchain-core/dist/messages/metadata.d.ts.map +1 -0
  246. package/dist/libs/langchain-core/dist/messages/utils.d.ts +75 -0
  247. package/dist/libs/langchain-core/dist/messages/utils.d.ts.map +1 -0
  248. package/dist/libs/langchain-core/dist/prompt_values.d.ts.map +1 -1
  249. package/dist/libs/langchain-core/dist/utils/types/index.d.ts +2 -0
  250. package/dist/libs/langchain-core/dist/utils/types/index.d.ts.map +1 -1
  251. package/dist/libs/langchain-core/dist/utils/types/zod.d.ts +1 -0
  252. package/dist/load/import_map.cjs +3 -14
  253. package/dist/load/import_map.cjs.map +1 -1
  254. package/dist/load/import_map.js +3 -14
  255. package/dist/load/import_map.js.map +1 -1
  256. package/dist/memory/prompt.cjs.map +1 -1
  257. package/dist/memory/prompt.d.cts.map +1 -1
  258. package/dist/memory/prompt.d.ts.map +1 -1
  259. package/dist/memory/prompt.js.map +1 -1
  260. package/dist/output_parsers/combining.cjs +1 -1
  261. package/dist/output_parsers/combining.cjs.map +1 -1
  262. package/dist/output_parsers/combining.js +1 -1
  263. package/dist/output_parsers/combining.js.map +1 -1
  264. package/dist/output_parsers/expression_type_handlers/array_literal_expression_handler.cjs.map +1 -1
  265. package/dist/output_parsers/expression_type_handlers/array_literal_expression_handler.js.map +1 -1
  266. package/dist/output_parsers/expression_type_handlers/base.cjs +1 -1
  267. package/dist/output_parsers/expression_type_handlers/base.cjs.map +1 -1
  268. package/dist/output_parsers/expression_type_handlers/base.js +1 -1
  269. package/dist/output_parsers/expression_type_handlers/base.js.map +1 -1
  270. package/dist/output_parsers/regex.cjs.map +1 -1
  271. package/dist/output_parsers/regex.js.map +1 -1
  272. package/dist/output_parsers/structured.cjs +4 -4
  273. package/dist/output_parsers/structured.cjs.map +1 -1
  274. package/dist/output_parsers/structured.d.cts +1 -1
  275. package/dist/output_parsers/structured.d.cts.map +1 -1
  276. package/dist/output_parsers/structured.d.ts +1 -1
  277. package/dist/output_parsers/structured.d.ts.map +1 -1
  278. package/dist/output_parsers/structured.js +2 -2
  279. package/dist/output_parsers/structured.js.map +1 -1
  280. package/dist/retrievers/ensemble.cjs.map +1 -1
  281. package/dist/retrievers/ensemble.js.map +1 -1
  282. package/dist/storage/file_system.cjs +1 -1
  283. package/dist/storage/file_system.cjs.map +1 -1
  284. package/dist/storage/file_system.js +1 -1
  285. package/dist/storage/file_system.js.map +1 -1
  286. package/dist/tools/fs.cjs +5 -5
  287. package/dist/tools/fs.cjs.map +1 -1
  288. package/dist/tools/fs.d.cts +1 -1
  289. package/dist/tools/fs.d.cts.map +1 -1
  290. package/dist/tools/fs.d.ts +1 -1
  291. package/dist/tools/fs.d.ts.map +1 -1
  292. package/dist/tools/fs.js +1 -1
  293. package/dist/tools/fs.js.map +1 -1
  294. package/dist/tools/retriever.cjs +2 -2
  295. package/dist/tools/retriever.cjs.map +1 -1
  296. package/dist/tools/retriever.d.cts +1 -1
  297. package/dist/tools/retriever.d.cts.map +1 -1
  298. package/dist/tools/retriever.d.ts +1 -1
  299. package/dist/tools/retriever.d.ts.map +1 -1
  300. package/dist/tools/retriever.js +1 -1
  301. package/dist/tools/retriever.js.map +1 -1
  302. package/dist/tools/sql.cjs +1 -2
  303. package/dist/tools/sql.cjs.map +1 -1
  304. package/dist/tools/sql.d.cts +1 -1
  305. package/dist/tools/sql.d.cts.map +1 -1
  306. package/dist/tools/sql.d.ts +1 -1
  307. package/dist/tools/sql.d.ts.map +1 -1
  308. package/dist/tools/sql.js +1 -2
  309. package/dist/tools/sql.js.map +1 -1
  310. package/dist/types/expression-parser.d.cts +2 -0
  311. package/dist/types/expression-parser.d.cts.map +1 -1
  312. package/dist/types/expression-parser.d.ts +2 -0
  313. package/dist/types/expression-parser.d.ts.map +1 -1
  314. package/dist/util/hub.cjs +1 -1
  315. package/dist/util/hub.js +1 -1
  316. package/dist/util/openapi.cjs +1 -1
  317. package/dist/util/openapi.cjs.map +1 -1
  318. package/dist/util/openapi.js +1 -1
  319. package/dist/util/openapi.js.map +1 -1
  320. package/package.json +15 -21
  321. package/dist/agents/middlewareAgent/middlewares/hitl.cjs.map +0 -1
  322. package/dist/agents/middlewareAgent/middlewares/hitl.d.cts.map +0 -1
  323. package/dist/agents/middlewareAgent/middlewares/hitl.d.ts.map +0 -1
  324. package/dist/agents/middlewareAgent/middlewares/hitl.js.map +0 -1
  325. package/dist/agents/middlewareAgent/middlewares/index.cjs +0 -8
  326. package/dist/agents/middlewareAgent/middlewares/index.js +0 -5
  327. package/dist/agents/middlewareAgent/middlewares/promptCaching.cjs.map +0 -1
  328. package/dist/agents/middlewareAgent/middlewares/promptCaching.d.cts.map +0 -1
  329. package/dist/agents/middlewareAgent/middlewares/promptCaching.d.ts.map +0 -1
  330. package/dist/agents/middlewareAgent/middlewares/promptCaching.js.map +0 -1
  331. package/dist/agents/middlewareAgent/middlewares/summarization.cjs.map +0 -1
  332. package/dist/agents/middlewareAgent/middlewares/summarization.d.ts.map +0 -1
  333. package/dist/agents/middlewareAgent/middlewares/summarization.js.map +0 -1
  334. package/dist/chains/openai_functions/structured_output.cjs +0 -107
  335. package/dist/chains/openai_functions/structured_output.cjs.map +0 -1
  336. package/dist/chains/openai_functions/structured_output.d.cts +0 -38
  337. package/dist/chains/openai_functions/structured_output.d.cts.map +0 -1
  338. package/dist/chains/openai_functions/structured_output.d.ts +0 -38
  339. package/dist/chains/openai_functions/structured_output.d.ts.map +0 -1
  340. package/dist/chains/openai_functions/structured_output.js +0 -105
  341. package/dist/chains/openai_functions/structured_output.js.map +0 -1
  342. package/dist/chains/openai_moderation.cjs +0 -107
  343. package/dist/chains/openai_moderation.cjs.map +0 -1
  344. package/dist/chains/openai_moderation.d.cts +0 -74
  345. package/dist/chains/openai_moderation.d.cts.map +0 -1
  346. package/dist/chains/openai_moderation.d.ts +0 -74
  347. package/dist/chains/openai_moderation.d.ts.map +0 -1
  348. package/dist/chains/openai_moderation.js +0 -106
  349. package/dist/chains/openai_moderation.js.map +0 -1
  350. /package/dist/agents/middlewareAgent/{middlewares → middleware}/index.d.cts +0 -0
  351. /package/dist/agents/middlewareAgent/{middlewares → middleware}/index.d.ts +0 -0
@@ -5,26 +5,25 @@ import { InteropZodObject } from "@langchain/core/utils/types";
5
5
  import { Command, CompiledStateGraph, LangGraphRunnableConfig } from "@langchain/langgraph";
6
6
 
7
7
  //#region src/agents/middlewareAgent/ReactAgent.d.ts
8
+
8
9
  // Helper type to get the state definition with middleware states
9
- type MergedAgentState<StructuredResponseFormat extends Record<string, any> | ResponseFormatUndefined, TMiddlewares extends readonly AgentMiddleware<any, any, any>[]> = (StructuredResponseFormat extends ResponseFormatUndefined ? BuiltInState : BuiltInState & {
10
+ type MergedAgentState<StructuredResponseFormat extends Record<string, any> | ResponseFormatUndefined, TMiddleware extends readonly AgentMiddleware<any, any, any>[]> = (StructuredResponseFormat extends ResponseFormatUndefined ? BuiltInState : BuiltInState & {
10
11
  structuredResponse: StructuredResponseFormat;
11
- }) & InferMiddlewareStates<TMiddlewares>;
12
- type InvokeStateParameter<TMiddlewares extends readonly AgentMiddleware<any, any, any>[]> = (BuiltInState & InferMiddlewareInputStates<TMiddlewares>) | Command<any, any, any> | null;
13
- type AgentGraph<StructuredResponseFormat extends Record<string, any> | ResponseFormatUndefined = Record<string, any>, ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot, TMiddlewares extends readonly AgentMiddleware<any, any, any>[] = []> = CompiledStateGraph<any, any,
14
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
15
- any, any, MergedAgentState<StructuredResponseFormat, TMiddlewares>, ToAnnotationRoot<ContextSchema>["spec"], unknown>;
16
- declare class ReactAgent<StructuredResponseFormat extends Record<string, any> | ResponseFormatUndefined = Record<string, any>, ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot, TMiddlewares extends readonly AgentMiddleware<any, any, any>[] = []> {
12
+ }) & InferMiddlewareStates<TMiddleware>;
13
+ type InvokeStateParameter<TMiddleware extends readonly AgentMiddleware<any, any, any>[]> = (BuiltInState & InferMiddlewareInputStates<TMiddleware>) | Command<any, any, any> | null;
14
+ type AgentGraph<StructuredResponseFormat extends Record<string, any> | ResponseFormatUndefined = Record<string, any>, ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot, TMiddleware extends readonly AgentMiddleware<any, any, any>[] = []> = CompiledStateGraph<any, any, any, any, MergedAgentState<StructuredResponseFormat, TMiddleware>, ToAnnotationRoot<ContextSchema>["spec"], unknown>;
15
+ declare class ReactAgent<StructuredResponseFormat extends Record<string, any> | ResponseFormatUndefined = Record<string, any>, ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot, TMiddleware extends readonly AgentMiddleware<any, any, any>[] = []> {
17
16
  #private;
18
17
  options: CreateAgentParams<StructuredResponseFormat, ContextSchema>;
19
18
  constructor(options: CreateAgentParams<StructuredResponseFormat, ContextSchema>);
20
19
  /**
21
20
  * Get the compiled graph.
22
21
  */
23
- get graph(): AgentGraph<StructuredResponseFormat, ContextSchema, TMiddlewares>;
22
+ get graph(): AgentGraph<StructuredResponseFormat, ContextSchema, TMiddleware>;
24
23
  /**
25
24
  * @inheritdoc
26
25
  */
27
- get invoke(): IsAllOptional<InferContextInput<ContextSchema> & InferMiddlewareContextInputs<TMiddlewares>> extends true ? (state: InvokeStateParameter<TMiddlewares>, config?: LangGraphRunnableConfig<InferContextInput<ContextSchema> & InferMiddlewareContextInputs<TMiddlewares>> | undefined) => Promise<MergedAgentState<StructuredResponseFormat, TMiddlewares>> : (state: InvokeStateParameter<TMiddlewares>, config?: LangGraphRunnableConfig<InferContextInput<ContextSchema> & InferMiddlewareContextInputs<TMiddlewares>> | undefined) => Promise<MergedAgentState<StructuredResponseFormat, TMiddlewares>>;
26
+ get invoke(): IsAllOptional<InferContextInput<ContextSchema> & InferMiddlewareContextInputs<TMiddleware>> extends true ? (state: InvokeStateParameter<TMiddleware>, config?: LangGraphRunnableConfig<InferContextInput<ContextSchema> & InferMiddlewareContextInputs<TMiddleware>> | undefined) => Promise<MergedAgentState<StructuredResponseFormat, TMiddleware>> : (state: InvokeStateParameter<TMiddleware>, config?: LangGraphRunnableConfig<InferContextInput<ContextSchema> & InferMiddlewareContextInputs<TMiddleware>> | undefined) => Promise<MergedAgentState<StructuredResponseFormat, TMiddleware>>;
28
27
  /**
29
28
  * ToDo(@christian-bromann): Add stream and streamEvents methods
30
29
  */
@@ -1 +1 @@
1
- {"version":3,"file":"ReactAgent.d.cts","names":["InteropZodObject","Command","CompiledStateGraph","LangGraphRunnableConfig","CreateAgentParams","AgentMiddleware","InferMiddlewareStates","InferMiddlewareInputStates","BuiltInState","InferMiddlewareContextInputs","IsAllOptional","InferContextInput","AnyAnnotationRoot","ToAnnotationRoot","ResponseFormatUndefined","MergedAgentState","Record","StructuredResponseFormat","TMiddlewares","InvokeStateParameter","AgentGraph","ContextSchema","ReactAgent","Promise","ArrayBuffer","Uint8Array"],"sources":["../../../src/agents/middlewareAgent/ReactAgent.d.ts"],"sourcesContent":["/* eslint-disable prefer-destructuring, no-instanceof/no-instanceof, @typescript-eslint/ban-types */\nimport { InteropZodObject } from \"@langchain/core/utils/types\";\nimport { Command, CompiledStateGraph, type LangGraphRunnableConfig } from \"@langchain/langgraph\";\nimport { CreateAgentParams, AgentMiddleware, InferMiddlewareStates, InferMiddlewareInputStates, BuiltInState, InferMiddlewareContextInputs, IsAllOptional, InferContextInput } from \"./types.js\";\nimport { type AnyAnnotationRoot, type ToAnnotationRoot } from \"../annotation.js\";\nimport type { ResponseFormatUndefined } from \"../responses.js\";\n// Helper type to get the state definition with middleware states\ntype MergedAgentState<StructuredResponseFormat extends Record<string, any> | ResponseFormatUndefined, TMiddlewares extends readonly AgentMiddleware<any, any, any>[]> = (StructuredResponseFormat extends ResponseFormatUndefined ? BuiltInState : BuiltInState & {\n structuredResponse: StructuredResponseFormat;\n}) & InferMiddlewareStates<TMiddlewares>;\ntype InvokeStateParameter<TMiddlewares extends readonly AgentMiddleware<any, any, any>[]> = (BuiltInState & InferMiddlewareInputStates<TMiddlewares>) | Command<any, any, any> | null;\ntype AgentGraph<StructuredResponseFormat extends Record<string, any> | ResponseFormatUndefined = Record<string, any>, ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot, TMiddlewares extends readonly AgentMiddleware<any, any, any>[] = []> = CompiledStateGraph<any, any, \n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nany, any, MergedAgentState<StructuredResponseFormat, TMiddlewares>, ToAnnotationRoot<ContextSchema>[\"spec\"], unknown>;\nexport declare class ReactAgent<StructuredResponseFormat extends Record<string, any> | ResponseFormatUndefined = Record<string, any>, ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot, TMiddlewares extends readonly AgentMiddleware<any, any, any>[] = []> {\n #private;\n options: CreateAgentParams<StructuredResponseFormat, ContextSchema>;\n constructor(options: CreateAgentParams<StructuredResponseFormat, ContextSchema>);\n /**\n * Get the compiled graph.\n */\n get graph(): AgentGraph<StructuredResponseFormat, ContextSchema, TMiddlewares>;\n /**\n * @inheritdoc\n */\n get invoke(): IsAllOptional<InferContextInput<ContextSchema> & InferMiddlewareContextInputs<TMiddlewares>> extends true ? (state: InvokeStateParameter<TMiddlewares>, config?: LangGraphRunnableConfig<InferContextInput<ContextSchema> & InferMiddlewareContextInputs<TMiddlewares>> | undefined) => Promise<MergedAgentState<StructuredResponseFormat, TMiddlewares>> : (state: InvokeStateParameter<TMiddlewares>, config?: LangGraphRunnableConfig<InferContextInput<ContextSchema> & InferMiddlewareContextInputs<TMiddlewares>> | undefined) => Promise<MergedAgentState<StructuredResponseFormat, TMiddlewares>>;\n /**\n * ToDo(@christian-bromann): Add stream and streamEvents methods\n */\n /**\n * Visualize the graph as a PNG image.\n * @param params - Parameters for the drawMermaidPng method.\n * @param params.withStyles - Whether to include styles in the graph.\n * @param params.curveStyle - The style of the graph's curves.\n * @param params.nodeColors - The colors of the graph's nodes.\n * @param params.wrapLabelNWords - The maximum number of words to wrap in a node's label.\n * @param params.backgroundColor - The background color of the graph.\n * @returns PNG image as a buffer\n */\n drawMermaidPng(params?: {\n withStyles?: boolean;\n curveStyle?: string;\n nodeColors?: Record<string, string>;\n wrapLabelNWords?: number;\n backgroundColor?: string;\n }): Promise<Uint8Array<ArrayBuffer>>;\n /**\n * Draw the graph as a Mermaid string.\n * @param params - Parameters for the drawMermaid method.\n * @param params.withStyles - Whether to include styles in the graph.\n * @param params.curveStyle - The style of the graph's curves.\n * @param params.nodeColors - The colors of the graph's nodes.\n * @param params.wrapLabelNWords - The maximum number of words to wrap in a node's label.\n * @param params.backgroundColor - The background color of the graph.\n * @returns Mermaid string\n */\n drawMermaid(params?: {\n withStyles?: boolean;\n curveStyle?: string;\n nodeColors?: Record<string, string>;\n wrapLabelNWords?: number;\n backgroundColor?: string;\n }): Promise<string>;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AAA,GAAAA,SAAAA,EAAAA,GAe8agB,OAf9ahB,CAesbQ,gBAftbR,CAeucU,wBAfvcV,EAeieW,YAfjeX,CAAAA,CAAAA;EAA0B;AAAyB;AAAA;EAChJ;;;;;;;;;;EAEkD,cAAvDQ,CAAAA,MACqB,CADrBA,EAAAA;IAA2EM,UAAAA,CAAAA,EAAAA,OAAAA;IAAjBR,UAAAA,CAAAA,EAAAA,MAAAA;IAFyMX,UAAAA,CAAAA,EA+BxPc,MA/BwPd,CAAAA,MAAAA,EAAAA,MAAAA,CAAAA;IAAkB,eAAA,CAAA,EAAA,MAAA;IAG1QoB,eAAU,CAAA,EAAA,MAAA;EAAA,CAAA,CAAA,EA+BvBC,OA/BuB,CA+BfE,UA/Be,CA+BJD,WA/BI,CAAA,CAAA;EAAA;;;;;;;;;;EAED,WACaP,CAAAA,MAIsC,CAJtCA,EAAAA;IAA0BI,UAAAA,CAAAA,EAAAA,OAAAA;IAA5CjB,UAAAA,CAAAA,EAAAA,MAAAA;IAIGa,UAAAA,CAAAA,EAsCPD,MAtCOC,CAAAA,MAAAA,EAAAA,MAAAA,CAAAA;IAA0BI,eAAAA,CAAAA,EAAAA,MAAAA;IAAeH,eAAAA,CAAAA,EAAAA,MAAAA;EAAY,CAAA,CAAA,EAyCzEK,OAzCSH,CAAAA,MAAAA,CAAAA"}
1
+ {"version":3,"file":"ReactAgent.d.cts","names":["InteropZodObject","Command","CompiledStateGraph","LangGraphRunnableConfig","CreateAgentParams","AgentMiddleware","InferMiddlewareStates","InferMiddlewareInputStates","BuiltInState","InferMiddlewareContextInputs","IsAllOptional","InferContextInput","AnyAnnotationRoot","ToAnnotationRoot","ResponseFormatUndefined","MergedAgentState","Record","StructuredResponseFormat","TMiddleware","InvokeStateParameter","AgentGraph","ContextSchema","ReactAgent","Promise","ArrayBuffer","Uint8Array"],"sources":["../../../src/agents/middlewareAgent/ReactAgent.d.ts"],"sourcesContent":["/* eslint-disable no-instanceof/no-instanceof */\n/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { InteropZodObject } from \"@langchain/core/utils/types\";\nimport { Command, CompiledStateGraph, type LangGraphRunnableConfig } from \"@langchain/langgraph\";\nimport { CreateAgentParams, AgentMiddleware, InferMiddlewareStates, InferMiddlewareInputStates, BuiltInState, InferMiddlewareContextInputs, IsAllOptional, InferContextInput } from \"./types.js\";\nimport { type AnyAnnotationRoot, type ToAnnotationRoot } from \"../annotation.js\";\nimport type { ResponseFormatUndefined } from \"../responses.js\";\n// Helper type to get the state definition with middleware states\ntype MergedAgentState<StructuredResponseFormat extends Record<string, any> | ResponseFormatUndefined, TMiddleware extends readonly AgentMiddleware<any, any, any>[]> = (StructuredResponseFormat extends ResponseFormatUndefined ? BuiltInState : BuiltInState & {\n structuredResponse: StructuredResponseFormat;\n}) & InferMiddlewareStates<TMiddleware>;\ntype InvokeStateParameter<TMiddleware extends readonly AgentMiddleware<any, any, any>[]> = (BuiltInState & InferMiddlewareInputStates<TMiddleware>) | Command<any, any, any> | null;\ntype AgentGraph<StructuredResponseFormat extends Record<string, any> | ResponseFormatUndefined = Record<string, any>, ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot, TMiddleware extends readonly AgentMiddleware<any, any, any>[] = []> = CompiledStateGraph<any, any, any, any, MergedAgentState<StructuredResponseFormat, TMiddleware>, ToAnnotationRoot<ContextSchema>[\"spec\"], unknown>;\nexport declare class ReactAgent<StructuredResponseFormat extends Record<string, any> | ResponseFormatUndefined = Record<string, any>, ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot, TMiddleware extends readonly AgentMiddleware<any, any, any>[] = []> {\n #private;\n options: CreateAgentParams<StructuredResponseFormat, ContextSchema>;\n constructor(options: CreateAgentParams<StructuredResponseFormat, ContextSchema>);\n /**\n * Get the compiled graph.\n */\n get graph(): AgentGraph<StructuredResponseFormat, ContextSchema, TMiddleware>;\n /**\n * @inheritdoc\n */\n get invoke(): IsAllOptional<InferContextInput<ContextSchema> & InferMiddlewareContextInputs<TMiddleware>> extends true ? (state: InvokeStateParameter<TMiddleware>, config?: LangGraphRunnableConfig<InferContextInput<ContextSchema> & InferMiddlewareContextInputs<TMiddleware>> | undefined) => Promise<MergedAgentState<StructuredResponseFormat, TMiddleware>> : (state: InvokeStateParameter<TMiddleware>, config?: LangGraphRunnableConfig<InferContextInput<ContextSchema> & InferMiddlewareContextInputs<TMiddleware>> | undefined) => Promise<MergedAgentState<StructuredResponseFormat, TMiddleware>>;\n /**\n * ToDo(@christian-bromann): Add stream and streamEvents methods\n */\n /**\n * Visualize the graph as a PNG image.\n * @param params - Parameters for the drawMermaidPng method.\n * @param params.withStyles - Whether to include styles in the graph.\n * @param params.curveStyle - The style of the graph's curves.\n * @param params.nodeColors - The colors of the graph's nodes.\n * @param params.wrapLabelNWords - The maximum number of words to wrap in a node's label.\n * @param params.backgroundColor - The background color of the graph.\n * @returns PNG image as a buffer\n */\n drawMermaidPng(params?: {\n withStyles?: boolean;\n curveStyle?: string;\n nodeColors?: Record<string, string>;\n wrapLabelNWords?: number;\n backgroundColor?: string;\n }): Promise<Uint8Array<ArrayBuffer>>;\n /**\n * Draw the graph as a Mermaid string.\n * @param params - Parameters for the drawMermaid method.\n * @param params.withStyles - Whether to include styles in the graph.\n * @param params.curveStyle - The style of the graph's curves.\n * @param params.nodeColors - The colors of the graph's nodes.\n * @param params.wrapLabelNWords - The maximum number of words to wrap in a node's label.\n * @param params.backgroundColor - The background color of the graph.\n * @returns Mermaid string\n */\n drawMermaid(params?: {\n withStyles?: boolean;\n curveStyle?: string;\n nodeColors?: Record<string, string>;\n wrapLabelNWords?: number;\n backgroundColor?: string;\n }): Promise<string>;\n}\nexport {};\n"],"mappings":";;;;;;;;AAM+D;KAE1De,gBAAgB,CAAA,iCAAkCC,MAAlC,CAAA,MAAA,EAAA,GAAA,CAAA,GAAwDF,uBAAxD,EAAA,oBAAA,SAA8GT,eAA9G,CAAA,GAAA,EAAA,GAAA,EAAA,GAAA,CAAA,EAAA,C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OAAAA;IAA0EM,UAAAA,CAAAA,EAAAA,MAAAA;IAAjBR,UAAAA,CAAAA,EA6BvVG,MA7BuVH,CAAAA,MAAAA,EAAAA,MAAAA,CAAAA;IAAhGX,eAAAA,CAAAA,EAAAA,MAAAA;IAAkB,eAAA,CAAA,EAAA,MAAA;EACzQoB,CAAAA,CAAAA,EA+BbC,OA/BaD,CA+BLG,UA/Be,CA+BJD,WA/BI,CAAA,CAAA;EAAA;;;;;;;;;;EAEuC,WAAzDpB,CAAAA,MAKsD,CALtDA,EAAAA;IAC8Ba,UAAAA,CAAAA,EAAAA,OAAAA;IAA0BI,UAAAA,CAAAA,EAAAA,MAAAA;IAA5CjB,UAAAA,CAAAA,EA0CJY,MA1CIZ,CAAAA,MAAAA,EAAAA,MAAAA,CAAAA;IAIGa,eAAAA,CAAAA,EAAAA,MAAAA;IAA0BI,eAAAA,CAAAA,EAAAA,MAAAA;EAAa,CAAA,CAAA,EAyC3DE,OAzC6DL,CAAAA,MAAAA,CAAAA"}
@@ -5,26 +5,25 @@ import { Command, CompiledStateGraph, LangGraphRunnableConfig } from "@langchain
5
5
  import { InteropZodObject } from "@langchain/core/utils/types";
6
6
 
7
7
  //#region src/agents/middlewareAgent/ReactAgent.d.ts
8
+
8
9
  // Helper type to get the state definition with middleware states
9
- type MergedAgentState<StructuredResponseFormat extends Record<string, any> | ResponseFormatUndefined, TMiddlewares extends readonly AgentMiddleware<any, any, any>[]> = (StructuredResponseFormat extends ResponseFormatUndefined ? BuiltInState : BuiltInState & {
10
+ type MergedAgentState<StructuredResponseFormat extends Record<string, any> | ResponseFormatUndefined, TMiddleware extends readonly AgentMiddleware<any, any, any>[]> = (StructuredResponseFormat extends ResponseFormatUndefined ? BuiltInState : BuiltInState & {
10
11
  structuredResponse: StructuredResponseFormat;
11
- }) & InferMiddlewareStates<TMiddlewares>;
12
- type InvokeStateParameter<TMiddlewares extends readonly AgentMiddleware<any, any, any>[]> = (BuiltInState & InferMiddlewareInputStates<TMiddlewares>) | Command<any, any, any> | null;
13
- type AgentGraph<StructuredResponseFormat extends Record<string, any> | ResponseFormatUndefined = Record<string, any>, ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot, TMiddlewares extends readonly AgentMiddleware<any, any, any>[] = []> = CompiledStateGraph<any, any,
14
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
15
- any, any, MergedAgentState<StructuredResponseFormat, TMiddlewares>, ToAnnotationRoot<ContextSchema>["spec"], unknown>;
16
- declare class ReactAgent<StructuredResponseFormat extends Record<string, any> | ResponseFormatUndefined = Record<string, any>, ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot, TMiddlewares extends readonly AgentMiddleware<any, any, any>[] = []> {
12
+ }) & InferMiddlewareStates<TMiddleware>;
13
+ type InvokeStateParameter<TMiddleware extends readonly AgentMiddleware<any, any, any>[]> = (BuiltInState & InferMiddlewareInputStates<TMiddleware>) | Command<any, any, any> | null;
14
+ type AgentGraph<StructuredResponseFormat extends Record<string, any> | ResponseFormatUndefined = Record<string, any>, ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot, TMiddleware extends readonly AgentMiddleware<any, any, any>[] = []> = CompiledStateGraph<any, any, any, any, MergedAgentState<StructuredResponseFormat, TMiddleware>, ToAnnotationRoot<ContextSchema>["spec"], unknown>;
15
+ declare class ReactAgent<StructuredResponseFormat extends Record<string, any> | ResponseFormatUndefined = Record<string, any>, ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot, TMiddleware extends readonly AgentMiddleware<any, any, any>[] = []> {
17
16
  #private;
18
17
  options: CreateAgentParams<StructuredResponseFormat, ContextSchema>;
19
18
  constructor(options: CreateAgentParams<StructuredResponseFormat, ContextSchema>);
20
19
  /**
21
20
  * Get the compiled graph.
22
21
  */
23
- get graph(): AgentGraph<StructuredResponseFormat, ContextSchema, TMiddlewares>;
22
+ get graph(): AgentGraph<StructuredResponseFormat, ContextSchema, TMiddleware>;
24
23
  /**
25
24
  * @inheritdoc
26
25
  */
27
- get invoke(): IsAllOptional<InferContextInput<ContextSchema> & InferMiddlewareContextInputs<TMiddlewares>> extends true ? (state: InvokeStateParameter<TMiddlewares>, config?: LangGraphRunnableConfig<InferContextInput<ContextSchema> & InferMiddlewareContextInputs<TMiddlewares>> | undefined) => Promise<MergedAgentState<StructuredResponseFormat, TMiddlewares>> : (state: InvokeStateParameter<TMiddlewares>, config?: LangGraphRunnableConfig<InferContextInput<ContextSchema> & InferMiddlewareContextInputs<TMiddlewares>> | undefined) => Promise<MergedAgentState<StructuredResponseFormat, TMiddlewares>>;
26
+ get invoke(): IsAllOptional<InferContextInput<ContextSchema> & InferMiddlewareContextInputs<TMiddleware>> extends true ? (state: InvokeStateParameter<TMiddleware>, config?: LangGraphRunnableConfig<InferContextInput<ContextSchema> & InferMiddlewareContextInputs<TMiddleware>> | undefined) => Promise<MergedAgentState<StructuredResponseFormat, TMiddleware>> : (state: InvokeStateParameter<TMiddleware>, config?: LangGraphRunnableConfig<InferContextInput<ContextSchema> & InferMiddlewareContextInputs<TMiddleware>> | undefined) => Promise<MergedAgentState<StructuredResponseFormat, TMiddleware>>;
28
27
  /**
29
28
  * ToDo(@christian-bromann): Add stream and streamEvents methods
30
29
  */
@@ -1 +1 @@
1
- {"version":3,"file":"ReactAgent.d.ts","names":["InteropZodObject","Command","CompiledStateGraph","LangGraphRunnableConfig","CreateAgentParams","AgentMiddleware","InferMiddlewareStates","InferMiddlewareInputStates","BuiltInState","InferMiddlewareContextInputs","IsAllOptional","InferContextInput","AnyAnnotationRoot","ToAnnotationRoot","ResponseFormatUndefined","MergedAgentState","Record","StructuredResponseFormat","TMiddlewares","InvokeStateParameter","AgentGraph","ContextSchema","ReactAgent","Promise","ArrayBuffer","Uint8Array"],"sources":["../../../src/agents/middlewareAgent/ReactAgent.d.ts"],"sourcesContent":["/* eslint-disable prefer-destructuring, no-instanceof/no-instanceof, @typescript-eslint/ban-types */\nimport { InteropZodObject } from \"@langchain/core/utils/types\";\nimport { Command, CompiledStateGraph, type LangGraphRunnableConfig } from \"@langchain/langgraph\";\nimport { CreateAgentParams, AgentMiddleware, InferMiddlewareStates, InferMiddlewareInputStates, BuiltInState, InferMiddlewareContextInputs, IsAllOptional, InferContextInput } from \"./types.js\";\nimport { type AnyAnnotationRoot, type ToAnnotationRoot } from \"../annotation.js\";\nimport type { ResponseFormatUndefined } from \"../responses.js\";\n// Helper type to get the state definition with middleware states\ntype MergedAgentState<StructuredResponseFormat extends Record<string, any> | ResponseFormatUndefined, TMiddlewares extends readonly AgentMiddleware<any, any, any>[]> = (StructuredResponseFormat extends ResponseFormatUndefined ? BuiltInState : BuiltInState & {\n structuredResponse: StructuredResponseFormat;\n}) & InferMiddlewareStates<TMiddlewares>;\ntype InvokeStateParameter<TMiddlewares extends readonly AgentMiddleware<any, any, any>[]> = (BuiltInState & InferMiddlewareInputStates<TMiddlewares>) | Command<any, any, any> | null;\ntype AgentGraph<StructuredResponseFormat extends Record<string, any> | ResponseFormatUndefined = Record<string, any>, ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot, TMiddlewares extends readonly AgentMiddleware<any, any, any>[] = []> = CompiledStateGraph<any, any, \n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nany, any, MergedAgentState<StructuredResponseFormat, TMiddlewares>, ToAnnotationRoot<ContextSchema>[\"spec\"], unknown>;\nexport declare class ReactAgent<StructuredResponseFormat extends Record<string, any> | ResponseFormatUndefined = Record<string, any>, ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot, TMiddlewares extends readonly AgentMiddleware<any, any, any>[] = []> {\n #private;\n options: CreateAgentParams<StructuredResponseFormat, ContextSchema>;\n constructor(options: CreateAgentParams<StructuredResponseFormat, ContextSchema>);\n /**\n * Get the compiled graph.\n */\n get graph(): AgentGraph<StructuredResponseFormat, ContextSchema, TMiddlewares>;\n /**\n * @inheritdoc\n */\n get invoke(): IsAllOptional<InferContextInput<ContextSchema> & InferMiddlewareContextInputs<TMiddlewares>> extends true ? (state: InvokeStateParameter<TMiddlewares>, config?: LangGraphRunnableConfig<InferContextInput<ContextSchema> & InferMiddlewareContextInputs<TMiddlewares>> | undefined) => Promise<MergedAgentState<StructuredResponseFormat, TMiddlewares>> : (state: InvokeStateParameter<TMiddlewares>, config?: LangGraphRunnableConfig<InferContextInput<ContextSchema> & InferMiddlewareContextInputs<TMiddlewares>> | undefined) => Promise<MergedAgentState<StructuredResponseFormat, TMiddlewares>>;\n /**\n * ToDo(@christian-bromann): Add stream and streamEvents methods\n */\n /**\n * Visualize the graph as a PNG image.\n * @param params - Parameters for the drawMermaidPng method.\n * @param params.withStyles - Whether to include styles in the graph.\n * @param params.curveStyle - The style of the graph's curves.\n * @param params.nodeColors - The colors of the graph's nodes.\n * @param params.wrapLabelNWords - The maximum number of words to wrap in a node's label.\n * @param params.backgroundColor - The background color of the graph.\n * @returns PNG image as a buffer\n */\n drawMermaidPng(params?: {\n withStyles?: boolean;\n curveStyle?: string;\n nodeColors?: Record<string, string>;\n wrapLabelNWords?: number;\n backgroundColor?: string;\n }): Promise<Uint8Array<ArrayBuffer>>;\n /**\n * Draw the graph as a Mermaid string.\n * @param params - Parameters for the drawMermaid method.\n * @param params.withStyles - Whether to include styles in the graph.\n * @param params.curveStyle - The style of the graph's curves.\n * @param params.nodeColors - The colors of the graph's nodes.\n * @param params.wrapLabelNWords - The maximum number of words to wrap in a node's label.\n * @param params.backgroundColor - The background color of the graph.\n * @returns Mermaid string\n */\n drawMermaid(params?: {\n withStyles?: boolean;\n curveStyle?: string;\n nodeColors?: Record<string, string>;\n wrapLabelNWords?: number;\n backgroundColor?: string;\n }): Promise<string>;\n}\nexport {};\n"],"mappings":";;;;;;;;AAK+D,KAE1De,gBAAAA,CAAAA,iCAAkDC,MAAlC,CAAA,MAAA,EAAA,GAAA,CAAA,GAAwDF,uBAAxD,EAAA,qBAAA,SAA+GT,eAA/G,CAAA,GAAA,EAAA,GAAA,EAAA,GAAA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A;IAA2EM,UAAAA,CAAAA,EAAAA,OAAAA;IAAjBR,UAAAA,CAAAA,EAAAA,MAAAA;IAFyMX,UAAAA,CAAAA,EA+BxPc,MA/BwPd,CAAAA,MAAAA,EAAAA,MAAAA,CAAAA;IAAkB,eAAA,CAAA,EAAA,MAAA;IAG1QoB,eAAU,CAAA,EAAA,MAAA;EAAA,CAAA,CAAA,EA+BvBC,OA/BuB,CA+BfE,UA/Be,CA+BJD,WA/BI,CAAA,CAAA;EAAA;;;;;;;;;;EAED,WACaP,CAAAA,MAIsC,CAJtCA,EAAAA;IAA0BI,UAAAA,CAAAA,EAAAA,OAAAA;IAA5CjB,UAAAA,CAAAA,EAAAA,MAAAA;IAIGa,UAAAA,CAAAA,EAsCPD,MAtCOC,CAAAA,MAAAA,EAAAA,MAAAA,CAAAA;IAA0BI,eAAAA,CAAAA,EAAAA,MAAAA;IAAeH,eAAAA,CAAAA,EAAAA,MAAAA;EAAY,CAAA,CAAA,EAyCzEK,OAzCSH,CAAAA,MAAAA,CAAAA"}
1
+ {"version":3,"file":"ReactAgent.d.ts","names":["InteropZodObject","Command","CompiledStateGraph","LangGraphRunnableConfig","CreateAgentParams","AgentMiddleware","InferMiddlewareStates","InferMiddlewareInputStates","BuiltInState","InferMiddlewareContextInputs","IsAllOptional","InferContextInput","AnyAnnotationRoot","ToAnnotationRoot","ResponseFormatUndefined","MergedAgentState","Record","StructuredResponseFormat","TMiddleware","InvokeStateParameter","AgentGraph","ContextSchema","ReactAgent","Promise","ArrayBuffer","Uint8Array"],"sources":["../../../src/agents/middlewareAgent/ReactAgent.d.ts"],"sourcesContent":["/* eslint-disable no-instanceof/no-instanceof */\n/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { InteropZodObject } from \"@langchain/core/utils/types\";\nimport { Command, CompiledStateGraph, type LangGraphRunnableConfig } from \"@langchain/langgraph\";\nimport { CreateAgentParams, AgentMiddleware, InferMiddlewareStates, InferMiddlewareInputStates, BuiltInState, InferMiddlewareContextInputs, IsAllOptional, InferContextInput } from \"./types.js\";\nimport { type AnyAnnotationRoot, type ToAnnotationRoot } from \"../annotation.js\";\nimport type { ResponseFormatUndefined } from \"../responses.js\";\n// Helper type to get the state definition with middleware states\ntype MergedAgentState<StructuredResponseFormat extends Record<string, any> | ResponseFormatUndefined, TMiddleware extends readonly AgentMiddleware<any, any, any>[]> = (StructuredResponseFormat extends ResponseFormatUndefined ? BuiltInState : BuiltInState & {\n structuredResponse: StructuredResponseFormat;\n}) & InferMiddlewareStates<TMiddleware>;\ntype InvokeStateParameter<TMiddleware extends readonly AgentMiddleware<any, any, any>[]> = (BuiltInState & InferMiddlewareInputStates<TMiddleware>) | Command<any, any, any> | null;\ntype AgentGraph<StructuredResponseFormat extends Record<string, any> | ResponseFormatUndefined = Record<string, any>, ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot, TMiddleware extends readonly AgentMiddleware<any, any, any>[] = []> = CompiledStateGraph<any, any, any, any, MergedAgentState<StructuredResponseFormat, TMiddleware>, ToAnnotationRoot<ContextSchema>[\"spec\"], unknown>;\nexport declare class ReactAgent<StructuredResponseFormat extends Record<string, any> | ResponseFormatUndefined = Record<string, any>, ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot, TMiddleware extends readonly AgentMiddleware<any, any, any>[] = []> {\n #private;\n options: CreateAgentParams<StructuredResponseFormat, ContextSchema>;\n constructor(options: CreateAgentParams<StructuredResponseFormat, ContextSchema>);\n /**\n * Get the compiled graph.\n */\n get graph(): AgentGraph<StructuredResponseFormat, ContextSchema, TMiddleware>;\n /**\n * @inheritdoc\n */\n get invoke(): IsAllOptional<InferContextInput<ContextSchema> & InferMiddlewareContextInputs<TMiddleware>> extends true ? (state: InvokeStateParameter<TMiddleware>, config?: LangGraphRunnableConfig<InferContextInput<ContextSchema> & InferMiddlewareContextInputs<TMiddleware>> | undefined) => Promise<MergedAgentState<StructuredResponseFormat, TMiddleware>> : (state: InvokeStateParameter<TMiddleware>, config?: LangGraphRunnableConfig<InferContextInput<ContextSchema> & InferMiddlewareContextInputs<TMiddleware>> | undefined) => Promise<MergedAgentState<StructuredResponseFormat, TMiddleware>>;\n /**\n * ToDo(@christian-bromann): Add stream and streamEvents methods\n */\n /**\n * Visualize the graph as a PNG image.\n * @param params - Parameters for the drawMermaidPng method.\n * @param params.withStyles - Whether to include styles in the graph.\n * @param params.curveStyle - The style of the graph's curves.\n * @param params.nodeColors - The colors of the graph's nodes.\n * @param params.wrapLabelNWords - The maximum number of words to wrap in a node's label.\n * @param params.backgroundColor - The background color of the graph.\n * @returns PNG image as a buffer\n */\n drawMermaidPng(params?: {\n withStyles?: boolean;\n curveStyle?: string;\n nodeColors?: Record<string, string>;\n wrapLabelNWords?: number;\n backgroundColor?: string;\n }): Promise<Uint8Array<ArrayBuffer>>;\n /**\n * Draw the graph as a Mermaid string.\n * @param params - Parameters for the drawMermaid method.\n * @param params.withStyles - Whether to include styles in the graph.\n * @param params.curveStyle - The style of the graph's curves.\n * @param params.nodeColors - The colors of the graph's nodes.\n * @param params.wrapLabelNWords - The maximum number of words to wrap in a node's label.\n * @param params.backgroundColor - The background color of the graph.\n * @returns Mermaid string\n */\n drawMermaid(params?: {\n withStyles?: boolean;\n curveStyle?: string;\n nodeColors?: Record<string, string>;\n wrapLabelNWords?: number;\n backgroundColor?: string;\n }): Promise<string>;\n}\nexport {};\n"],"mappings":";;;;;;;;AAM+D;KAE1De,gBAAgB,CAAA,iCAAkCC,MAAlC,CAAA,MAAA,EAAA,GAAA,CAAA,GAAwDF,uBAAxD,EAAA,oBAAA,SAA8GT,eAA9G,CAAA,GAAA,EAAA,GAAA,EAAA,GAAA,CAAA,EAAA,CAAA,GAAA,CAAmJY,wBAAnJ,SAAoLH,uBAApL,GAA8MN,YAA9M,GAA6NA,YAA7N,GAAA;EAAA,kBAAkCQ,EAC/BC,wBAD+BD;CAAM,CAAA,GAExDV,qBAFwEQ,CAElDI,WAFkDJ,CAAAA;KAGxEK,oBAH8Hd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A;EACzQoB,CAAAA,CAAAA,EA+BbC,OA/BaD,CA+BLG,UA/Be,CA+BJD,WA/BI,CAAA,CAAA;EAAA;;;;;;;;;;EAEuC,WAAzDpB,CAAAA,MAKsD,CALtDA,EAAAA;IAC8Ba,UAAAA,CAAAA,EAAAA,OAAAA;IAA0BI,UAAAA,CAAAA,EAAAA,MAAAA;IAA5CjB,UAAAA,CAAAA,EA0CJY,MA1CIZ,CAAAA,MAAAA,EAAAA,MAAAA,CAAAA;IAIGa,eAAAA,CAAAA,EAAAA,MAAAA;IAA0BI,eAAAA,CAAAA,EAAAA,MAAAA;EAAa,CAAA,CAAA,EAyC3DE,OAzC6DL,CAAAA,MAAAA,CAAAA"}
@@ -33,36 +33,36 @@ var ReactAgent = class {
33
33
  * our graph needs to check if these were called
34
34
  */
35
35
  const shouldReturnDirect = new Set(toolClasses.filter(isClientTool).filter((tool) => "returnDirect" in tool && tool.returnDirect).map((tool) => tool.name));
36
- const schema = createAgentAnnotationConditional(this.options.responseFormat !== void 0, this.options.middlewares);
36
+ const schema = createAgentAnnotationConditional(this.options.responseFormat !== void 0, this.options.middleware);
37
37
  const workflow = new StateGraph(schema, this.options.contextSchema);
38
38
  const allNodeWorkflows = workflow;
39
39
  const beforeModelNodes = [];
40
40
  const afterModelNodes = [];
41
- const prepareModelRequestHookMiddlewares = [];
42
- const middlewares = this.options.middlewares ?? [];
43
- for (let i = 0; i < middlewares.length; i++) {
41
+ const prepareModelRequestHookMiddleware = [];
42
+ const middleware = this.options.middleware ?? [];
43
+ for (let i = 0; i < middleware.length; i++) {
44
44
  let beforeModelNode;
45
45
  let afterModelNode;
46
- const middleware = middlewares[i];
47
- if (middleware.beforeModel) {
48
- beforeModelNode = new BeforeModelNode(middleware);
49
- const name = `before_model_${middleware.name}_${i}`;
46
+ const m = middleware[i];
47
+ if (m.beforeModel) {
48
+ beforeModelNode = new BeforeModelNode(m);
49
+ const name = `before_model_${m.name}_${i}`;
50
50
  beforeModelNodes.push({
51
51
  index: i,
52
52
  name
53
53
  });
54
54
  allNodeWorkflows.addNode(name, beforeModelNode, beforeModelNode.nodeOptions);
55
55
  }
56
- if (middleware.afterModel) {
57
- afterModelNode = new AfterModelNode(middleware);
58
- const name = `after_model_${middleware.name}_${i}`;
56
+ if (m.afterModel) {
57
+ afterModelNode = new AfterModelNode(m);
58
+ const name = `after_model_${m.name}_${i}`;
59
59
  afterModelNodes.push({
60
60
  index: i,
61
61
  name
62
62
  });
63
63
  allNodeWorkflows.addNode(name, afterModelNode, afterModelNode.nodeOptions);
64
64
  }
65
- if (middleware.prepareModelRequest) prepareModelRequestHookMiddlewares.push([middleware, () => ({
65
+ if (m.prepareModelRequest) prepareModelRequestHookMiddleware.push([m, () => ({
66
66
  ...beforeModelNode?.getState(),
67
67
  ...afterModelNode?.getState()
68
68
  })]);
@@ -77,11 +77,11 @@ var ReactAgent = class {
77
77
  includeAgentName: this.options.includeAgentName,
78
78
  name: this.options.name,
79
79
  responseFormat: this.options.responseFormat,
80
- middlewares: this.options.middlewares,
80
+ middleware: this.options.middleware,
81
81
  toolClasses,
82
82
  shouldReturnDirect,
83
83
  signal: this.options.signal,
84
- prepareModelRequestHookMiddlewares
84
+ prepareModelRequestHookMiddleware
85
85
  }), AgentNode.nodeOptions);
86
86
  /**
87
87
  * add single tool node for all tools
@@ -164,7 +164,7 @@ var ReactAgent = class {
164
164
  return (state) => {
165
165
  const messages = state.messages;
166
166
  const lastMessage = messages.at(-1);
167
- if (!(lastMessage instanceof AIMessage) || !lastMessage.tool_calls || lastMessage.tool_calls.length === 0) return END;
167
+ if (!AIMessage.isInstance(lastMessage) || !lastMessage.tool_calls || lastMessage.tool_calls.length === 0) return END;
168
168
  /**
169
169
  * The tool node processes a single message.
170
170
  */
@@ -188,7 +188,7 @@ var ReactAgent = class {
188
188
  return (state) => {
189
189
  const messages = state.messages;
190
190
  const lastMessage = messages[messages.length - 1];
191
- if (lastMessage instanceof ToolMessage && lastMessage.name && shouldReturnDirect.has(lastMessage.name)) return this.options.responseFormat ? "model_request" : END;
191
+ if (ToolMessage.isInstance(lastMessage) && lastMessage.name && shouldReturnDirect.has(lastMessage.name)) return this.options.responseFormat ? "model_request" : END;
192
192
  return "model_request";
193
193
  };
194
194
  }
@@ -196,8 +196,8 @@ var ReactAgent = class {
196
196
  * Initialize middleware states if not already present in the input state.
197
197
  */
198
198
  #initializeMiddlewareStates(state) {
199
- if (!this.options.middlewares || this.options.middlewares.length === 0 || state instanceof Command || !state) return state;
200
- const defaultStates = initializeMiddlewareStates(this.options.middlewares, state);
199
+ if (!this.options.middleware || this.options.middleware.length === 0 || state instanceof Command || !state) return state;
200
+ const defaultStates = initializeMiddlewareStates(this.options.middleware, state);
201
201
  const updatedState = { ...state };
202
202
  if (!updatedState) return updatedState;
203
203
  for (const [key, value] of Object.entries(defaultStates)) if (!(key in updatedState)) updatedState[key] = value;
@@ -1 +1 @@
1
- {"version":3,"file":"ReactAgent.js","names":["options: CreateAgentParams<StructuredResponseFormat, ContextSchema>","#toolBehaviorVersion","beforeModelNodes: { index: number; name: string }[]","afterModelNodes: { index: number; name: string }[]","prepareModelRequestHookMiddlewares: [\n AgentMiddleware,\n /**\n * ToDo: better type to get the state of middleware\n */\n () => any\n ][]","beforeModelNode: BeforeModelNode | undefined","afterModelNode: AfterModelNode | undefined","#getModelPaths","#createModelRouter","toolReturnTarget: string","#createToolsRouter","#graph","toolClasses: (ClientTool | ServerTool)[]","paths: (\"tools\" | typeof END)[]","state: any","shouldReturnDirect: Set<string>","state: InvokeStateParameter<TMiddlewares>","invokeFunc: InvokeFunction","config?: LangGraphRunnableConfig<FullContext>","#initializeMiddlewareStates","params?: {\n withStyles?: boolean;\n curveStyle?: string;\n nodeColors?: Record<string, string>;\n wrapLabelNWords?: number;\n backgroundColor?: string;\n }"],"sources":["../../../src/agents/middlewareAgent/ReactAgent.ts"],"sourcesContent":["/* eslint-disable prefer-destructuring, no-instanceof/no-instanceof, @typescript-eslint/ban-types */\nimport { InteropZodObject } from \"@langchain/core/utils/types\";\n\nimport {\n AnnotationRoot,\n StateGraph,\n END,\n START,\n Send,\n Command,\n CompiledStateGraph,\n type LangGraphRunnableConfig,\n} from \"@langchain/langgraph\";\nimport { ToolMessage, AIMessage } from \"@langchain/core/messages\";\n\nimport { createAgentAnnotationConditional } from \"./annotation.js\";\nimport { isClientTool, validateLLMHasNoBoundTools } from \"../utils.js\";\n\nimport { AgentNode } from \"./nodes/AgentNode.js\";\nimport { ToolNode } from \"../nodes/ToolNode.js\";\nimport { BeforeModelNode } from \"./nodes/BeforeModalNode.js\";\nimport { AfterModelNode } from \"./nodes/AfterModalNode.js\";\nimport { initializeMiddlewareStates } from \"./nodes/utils.js\";\n\nimport type { ClientTool, ServerTool, WithStateGraphNodes } from \"../types.js\";\n\nimport {\n CreateAgentParams,\n AgentMiddleware,\n InferMiddlewareStates,\n InferMiddlewareInputStates,\n BuiltInState,\n InferMiddlewareContextInputs,\n IsAllOptional,\n InferContextInput,\n} from \"./types.js\";\n\nimport {\n type AnyAnnotationRoot,\n type ToAnnotationRoot,\n} from \"../annotation.js\";\nimport type { ResponseFormatUndefined } from \"../responses.js\";\n\n// Helper type to get the state definition with middleware states\ntype MergedAgentState<\n StructuredResponseFormat extends\n | Record<string, any>\n | ResponseFormatUndefined,\n TMiddlewares extends readonly AgentMiddleware<any, any, any>[]\n> = (StructuredResponseFormat extends ResponseFormatUndefined\n ? BuiltInState\n : BuiltInState & { structuredResponse: StructuredResponseFormat }) &\n InferMiddlewareStates<TMiddlewares>;\n\ntype InvokeStateParameter<\n TMiddlewares extends readonly AgentMiddleware<any, any, any>[]\n> =\n | (BuiltInState & InferMiddlewareInputStates<TMiddlewares>)\n | Command<any, any, any>\n | null;\n\ntype AgentGraph<\n StructuredResponseFormat extends\n | Record<string, any>\n | ResponseFormatUndefined = Record<string, any>,\n ContextSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = AnyAnnotationRoot,\n TMiddlewares extends readonly AgentMiddleware<any, any, any>[] = []\n> = CompiledStateGraph<\n any,\n any,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n any,\n any,\n MergedAgentState<StructuredResponseFormat, TMiddlewares>,\n ToAnnotationRoot<ContextSchema>[\"spec\"],\n unknown\n>;\n\nexport class ReactAgent<\n StructuredResponseFormat extends\n | Record<string, any>\n | ResponseFormatUndefined = Record<string, any>,\n ContextSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = AnyAnnotationRoot,\n TMiddlewares extends readonly AgentMiddleware<any, any, any>[] = []\n> {\n #graph: AgentGraph<StructuredResponseFormat, ContextSchema, TMiddlewares>;\n\n #toolBehaviorVersion: \"v1\" | \"v2\" = \"v2\";\n\n constructor(\n public options: CreateAgentParams<StructuredResponseFormat, ContextSchema>\n ) {\n this.#toolBehaviorVersion = options.version ?? this.#toolBehaviorVersion;\n\n /**\n * Check if the LLM already has bound tools and throw if it does.\n */\n if (options.llm && typeof options.llm !== \"function\") {\n validateLLMHasNoBoundTools(options.llm);\n }\n\n /**\n * validate that model and llm options are not provided together\n */\n if (options.llm && options.model) {\n throw new Error(\"Cannot provide both `model` and `llm` options.\");\n }\n\n /**\n * validate that either model or llm option is provided\n */\n if (!options.llm && !options.model) {\n throw new Error(\n \"Either `model` or `llm` option must be provided to create an agent.\"\n );\n }\n\n const toolClasses =\n (Array.isArray(options.tools) ? options.tools : options.tools?.tools) ??\n [];\n\n /**\n * If any of the tools are configured to return_directly after running,\n * our graph needs to check if these were called\n */\n const shouldReturnDirect = new Set(\n toolClasses\n .filter(isClientTool)\n .filter((tool) => \"returnDirect\" in tool && tool.returnDirect)\n .map((tool) => tool.name)\n );\n\n // Create a schema that merges agent base schema with middleware state schemas\n const schema = createAgentAnnotationConditional<\n StructuredResponseFormat,\n TMiddlewares\n >(\n this.options.responseFormat !== undefined,\n this.options.middlewares as TMiddlewares\n );\n\n const workflow = new StateGraph(\n schema as AnnotationRoot<any>,\n this.options.contextSchema\n );\n\n const allNodeWorkflows = workflow as WithStateGraphNodes<\n \"tools\" | \"model_request\" | string,\n typeof workflow\n >;\n\n // Generate node names for middleware nodes that have hooks\n const beforeModelNodes: { index: number; name: string }[] = [];\n const afterModelNodes: { index: number; name: string }[] = [];\n const prepareModelRequestHookMiddlewares: [\n AgentMiddleware,\n /**\n * ToDo: better type to get the state of middleware\n */\n () => any\n ][] = [];\n\n const middlewares = this.options.middlewares ?? [];\n for (let i = 0; i < middlewares.length; i++) {\n let beforeModelNode: BeforeModelNode | undefined;\n let afterModelNode: AfterModelNode | undefined;\n const middleware = middlewares[i];\n if (middleware.beforeModel) {\n beforeModelNode = new BeforeModelNode(middleware);\n const name = `before_model_${middleware.name}_${i}`;\n beforeModelNodes.push({\n index: i,\n name,\n });\n allNodeWorkflows.addNode(\n name,\n beforeModelNode,\n beforeModelNode.nodeOptions\n );\n }\n if (middleware.afterModel) {\n afterModelNode = new AfterModelNode(middleware);\n const name = `after_model_${middleware.name}_${i}`;\n afterModelNodes.push({\n index: i,\n name,\n });\n allNodeWorkflows.addNode(\n name,\n afterModelNode,\n afterModelNode.nodeOptions\n );\n }\n\n if (middleware.prepareModelRequest) {\n prepareModelRequestHookMiddlewares.push([\n middleware,\n () => ({\n ...beforeModelNode?.getState(),\n ...afterModelNode?.getState(),\n }),\n ]);\n }\n }\n\n /**\n * Add Nodes\n */\n allNodeWorkflows.addNode(\n \"model_request\",\n new AgentNode({\n llm: this.options.llm,\n model: this.options.model,\n prompt: this.options.prompt,\n includeAgentName: this.options.includeAgentName,\n name: this.options.name,\n responseFormat: this.options.responseFormat,\n middlewares: this.options.middlewares,\n toolClasses,\n shouldReturnDirect,\n signal: this.options.signal,\n prepareModelRequestHookMiddlewares,\n }),\n AgentNode.nodeOptions\n );\n\n /**\n * add single tool node for all tools\n */\n if (toolClasses.length > 0) {\n const toolNode = new ToolNode(toolClasses.filter(isClientTool), {\n signal: this.options.signal,\n });\n allNodeWorkflows.addNode(\"tools\", toolNode);\n }\n\n /**\n * Add Edges\n */\n // Determine starting point based on what nodes exist\n if (beforeModelNodes.length > 0) {\n // If we have beforeModel nodes, start with the first one\n allNodeWorkflows.addEdge(START, beforeModelNodes[0].name);\n } else {\n // If no beforeModel nodes, go directly to agent\n allNodeWorkflows.addEdge(START, \"model_request\");\n }\n\n // Connect beforeModel nodes in sequence\n for (let i = 0; i < beforeModelNodes.length - 1; i++) {\n allNodeWorkflows.addEdge(\n beforeModelNodes[i].name,\n beforeModelNodes[i + 1].name\n );\n }\n\n // Connect last beforeModel node to agent\n const lastBeforeModelNode = beforeModelNodes.at(-1);\n if (beforeModelNodes.length > 0 && lastBeforeModelNode) {\n allNodeWorkflows.addEdge(lastBeforeModelNode.name, \"model_request\");\n }\n\n // Connect agent to last afterModel node (for reverse order execution)\n const lastAfterModelNode = afterModelNodes.at(-1);\n if (afterModelNodes.length > 0 && lastAfterModelNode) {\n allNodeWorkflows.addEdge(\"model_request\", lastAfterModelNode.name);\n } else {\n const modelPaths = this.#getModelPaths(toolClasses.filter(isClientTool));\n if (modelPaths.length === 1) {\n allNodeWorkflows.addEdge(\"model_request\", modelPaths[0]);\n } else {\n allNodeWorkflows.addConditionalEdges(\n \"model_request\",\n this.#createModelRouter(),\n modelPaths\n );\n }\n }\n\n // Connect afterModel nodes in reverse sequence\n for (let i = afterModelNodes.length - 1; i > 0; i--) {\n allNodeWorkflows.addEdge(\n afterModelNodes[i].name,\n afterModelNodes[i - 1].name\n );\n }\n\n // Connect first afterModel node (last to execute) to model paths\n if (afterModelNodes.length > 0) {\n const firstAfterModelNode = afterModelNodes[0].name;\n const modelPaths = this.#getModelPaths(toolClasses.filter(isClientTool));\n if (modelPaths.length === 1) {\n allNodeWorkflows.addEdge(firstAfterModelNode, modelPaths[0]);\n } else {\n allNodeWorkflows.addConditionalEdges(\n firstAfterModelNode,\n this.#createModelRouter(),\n modelPaths\n );\n }\n }\n\n /**\n * add edges for tools node\n */\n if (toolClasses.length > 0) {\n // Tools should return to first beforeModel node or agent\n let toolReturnTarget: string;\n if (beforeModelNodes.length > 0) {\n toolReturnTarget = beforeModelNodes[0].name;\n } else {\n toolReturnTarget = \"model_request\";\n }\n\n if (shouldReturnDirect.size > 0) {\n allNodeWorkflows.addConditionalEdges(\n \"tools\",\n this.#createToolsRouter(shouldReturnDirect),\n [toolReturnTarget, END]\n );\n } else {\n allNodeWorkflows.addEdge(\"tools\", toolReturnTarget);\n }\n }\n\n /**\n * compile the graph\n */\n this.#graph = allNodeWorkflows.compile({\n checkpointer: this.options.checkpointer ?? this.options.checkpointSaver,\n interruptBefore: this.options.interruptBefore,\n interruptAfter: this.options.interruptAfter,\n store: this.options.store,\n name: this.options.name,\n description: this.options.description,\n }) as AgentGraph<StructuredResponseFormat, ContextSchema, TMiddlewares>;\n }\n\n /**\n * Get the compiled graph.\n */\n get graph(): AgentGraph<\n StructuredResponseFormat,\n ContextSchema,\n TMiddlewares\n > {\n return this.#graph;\n }\n\n /**\n * Get possible edge destinations from model node.\n * @param toolClasses names of tools to call\n * @returns list of possible edge destinations\n */\n #getModelPaths(\n toolClasses: (ClientTool | ServerTool)[]\n ): (\"tools\" | typeof END)[] {\n const paths: (\"tools\" | typeof END)[] = [];\n if (toolClasses.length > 0) {\n paths.push(\"tools\");\n }\n\n paths.push(END);\n\n return paths;\n }\n\n /**\n * Create routing function for model node conditional edges.\n */\n #createModelRouter() {\n /**\n * determine if the agent should continue or not\n */\n /**\n * ToDo: fix type\n */\n return (state: any) => {\n const messages = state.messages;\n const lastMessage = messages.at(-1);\n\n if (\n !(lastMessage instanceof AIMessage) ||\n !lastMessage.tool_calls ||\n lastMessage.tool_calls.length === 0\n ) {\n return END;\n }\n\n /**\n * The tool node processes a single message.\n */\n if (this.#toolBehaviorVersion === \"v1\") {\n return \"tools\";\n }\n\n /**\n * Route to tools node\n */\n return lastMessage.tool_calls.map(\n (toolCall) => new Send(\"tools\", { ...state, lg_tool_call: toolCall })\n );\n };\n }\n\n /**\n * Create routing function for tools node conditional edges.\n */\n #createToolsRouter(shouldReturnDirect: Set<string>) {\n /**\n * ToDo: fix type\n */\n return (state: any) => {\n const messages = state.messages;\n const lastMessage = messages[messages.length - 1];\n\n // Check if we just executed a returnDirect tool\n if (\n lastMessage instanceof ToolMessage &&\n lastMessage.name &&\n shouldReturnDirect.has(lastMessage.name)\n ) {\n // If we have a response format, route to agent to generate structured response\n // Otherwise, return directly\n return this.options.responseFormat ? \"model_request\" : END;\n }\n\n // For non-returnDirect tools, always route back to agent\n return \"model_request\";\n };\n }\n\n /**\n * Initialize middleware states if not already present in the input state.\n */\n #initializeMiddlewareStates(\n state: InvokeStateParameter<TMiddlewares>\n ): InvokeStateParameter<TMiddlewares> {\n if (\n !this.options.middlewares ||\n this.options.middlewares.length === 0 ||\n state instanceof Command ||\n !state\n ) {\n return state;\n }\n\n const defaultStates = initializeMiddlewareStates(\n this.options.middlewares,\n state\n );\n const updatedState = { ...state } as InvokeStateParameter<TMiddlewares>;\n if (!updatedState) {\n return updatedState;\n }\n\n // Only add defaults for keys that don't exist in current state\n for (const [key, value] of Object.entries(defaultStates)) {\n if (!(key in updatedState)) {\n // @ts-expect-error - ToDo: fix type\n updatedState[key as keyof InvokeStateParameter<TMiddlewares>] = value;\n }\n }\n\n return updatedState;\n }\n\n /**\n * @inheritdoc\n */\n get invoke() {\n type FullState = MergedAgentState<StructuredResponseFormat, TMiddlewares>;\n type FullContext = InferContextInput<ContextSchema> &\n InferMiddlewareContextInputs<TMiddlewares>;\n\n // Create overloaded function type based on whether context has required fields\n type InvokeFunction = IsAllOptional<FullContext> extends true\n ? (\n state: InvokeStateParameter<TMiddlewares>,\n config?: LangGraphRunnableConfig<FullContext>\n ) => Promise<FullState>\n : (\n state: InvokeStateParameter<TMiddlewares>,\n config?: LangGraphRunnableConfig<FullContext>\n ) => Promise<FullState>;\n\n const invokeFunc: InvokeFunction = async (\n state: InvokeStateParameter<TMiddlewares>,\n config?: LangGraphRunnableConfig<FullContext>\n ): Promise<FullState> => {\n const initializedState = this.#initializeMiddlewareStates(state);\n return this.#graph.invoke(\n initializedState,\n config as any\n ) as Promise<FullState>;\n };\n\n return invokeFunc;\n }\n\n /**\n * ToDo(@christian-bromann): Add stream and streamEvents methods\n */\n\n /**\n * Visualize the graph as a PNG image.\n * @param params - Parameters for the drawMermaidPng method.\n * @param params.withStyles - Whether to include styles in the graph.\n * @param params.curveStyle - The style of the graph's curves.\n * @param params.nodeColors - The colors of the graph's nodes.\n * @param params.wrapLabelNWords - The maximum number of words to wrap in a node's label.\n * @param params.backgroundColor - The background color of the graph.\n * @returns PNG image as a buffer\n */\n async drawMermaidPng(params?: {\n withStyles?: boolean;\n curveStyle?: string;\n nodeColors?: Record<string, string>;\n wrapLabelNWords?: number;\n backgroundColor?: string;\n }) {\n const representation = await this.#graph.getGraphAsync();\n const image = await representation.drawMermaidPng(params);\n const arrayBuffer = await image.arrayBuffer();\n const buffer = new Uint8Array(arrayBuffer);\n return buffer;\n }\n\n /**\n * Draw the graph as a Mermaid string.\n * @param params - Parameters for the drawMermaid method.\n * @param params.withStyles - Whether to include styles in the graph.\n * @param params.curveStyle - The style of the graph's curves.\n * @param params.nodeColors - The colors of the graph's nodes.\n * @param params.wrapLabelNWords - The maximum number of words to wrap in a node's label.\n * @param params.backgroundColor - The background color of the graph.\n * @returns Mermaid string\n */\n async drawMermaid(params?: {\n withStyles?: boolean;\n curveStyle?: string;\n nodeColors?: Record<string, string>;\n wrapLabelNWords?: number;\n backgroundColor?: string;\n }) {\n const representation = await this.#graph.getGraphAsync();\n return representation.drawMermaid(params);\n }\n}\n"],"mappings":";;;;;;;;;;;AAgFA,IAAa,aAAb,MAQE;CACA;CAEA,uBAAoC;CAEpC,YACSA,SACP;EADO;EAEP,KAAKC,uBAAuB,QAAQ,WAAW,KAAKA;;;;AAKpD,MAAI,QAAQ,OAAO,OAAO,QAAQ,QAAQ,YACxC,2BAA2B,QAAQ,IAAI;;;;AAMzC,MAAI,QAAQ,OAAO,QAAQ,MACzB,OAAM,IAAI,MAAM;;;;AAMlB,MAAI,CAAC,QAAQ,OAA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extSchema>","#toolBehaviorVersion","beforeModelNodes: { index: number; name: string }[]","afterModelNodes: { index: number; name: string }[]","prepareModelRequestHookMiddleware: [\n AgentMiddleware,\n /**\n * ToDo: better type to get the state of middleware\n */\n () => any\n ][]","beforeModelNode: BeforeModelNode | undefined","afterModelNode: AfterModelNode | undefined","#getModelPaths","#createModelRouter","toolReturnTarget: string","#createToolsRouter","#graph","toolClasses: (ClientTool | ServerTool)[]","paths: (\"tools\" | typeof END)[]","state: any","shouldReturnDirect: Set<string>","state: InvokeStateParameter<TMiddleware>","invokeFunc: InvokeFunction","config?: LangGraphRunnableConfig<FullContext>","#initializeMiddlewareStates","params?: {\n withStyles?: boolean;\n curveStyle?: string;\n nodeColors?: Record<string, string>;\n wrapLabelNWords?: number;\n backgroundColor?: string;\n }"],"sources":["../../../src/agents/middlewareAgent/ReactAgent.ts"],"sourcesContent":["/* eslint-disable no-instanceof/no-instanceof */\n/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { InteropZodObject } from \"@langchain/core/utils/types\";\n\nimport {\n AnnotationRoot,\n StateGraph,\n END,\n START,\n Send,\n Command,\n CompiledStateGraph,\n type LangGraphRunnableConfig,\n} from \"@langchain/langgraph\";\nimport { ToolMessage, AIMessage } from \"@langchain/core/messages\";\n\nimport { createAgentAnnotationConditional } from \"./annotation.js\";\nimport { isClientTool, validateLLMHasNoBoundTools } from \"../utils.js\";\n\nimport { AgentNode } from \"./nodes/AgentNode.js\";\nimport { ToolNode } from \"../nodes/ToolNode.js\";\nimport { BeforeModelNode } from \"./nodes/BeforeModalNode.js\";\nimport { AfterModelNode } from \"./nodes/AfterModalNode.js\";\nimport { initializeMiddlewareStates } from \"./nodes/utils.js\";\n\nimport type { ClientTool, ServerTool, WithStateGraphNodes } from \"../types.js\";\n\nimport {\n CreateAgentParams,\n AgentMiddleware,\n InferMiddlewareStates,\n InferMiddlewareInputStates,\n BuiltInState,\n InferMiddlewareContextInputs,\n IsAllOptional,\n InferContextInput,\n} from \"./types.js\";\n\nimport {\n type AnyAnnotationRoot,\n type ToAnnotationRoot,\n} from \"../annotation.js\";\nimport type { ResponseFormatUndefined } from \"../responses.js\";\n\n// Helper type to get the state definition with middleware states\ntype MergedAgentState<\n StructuredResponseFormat extends\n | Record<string, any>\n | ResponseFormatUndefined,\n TMiddleware extends readonly AgentMiddleware<any, any, any>[]\n> = (StructuredResponseFormat extends ResponseFormatUndefined\n ? BuiltInState\n : BuiltInState & { structuredResponse: StructuredResponseFormat }) &\n InferMiddlewareStates<TMiddleware>;\n\ntype InvokeStateParameter<\n TMiddleware extends readonly AgentMiddleware<any, any, any>[]\n> =\n | (BuiltInState & InferMiddlewareInputStates<TMiddleware>)\n | Command<any, any, any>\n | null;\n\ntype AgentGraph<\n StructuredResponseFormat extends\n | Record<string, any>\n | ResponseFormatUndefined = Record<string, any>,\n ContextSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = AnyAnnotationRoot,\n TMiddleware extends readonly AgentMiddleware<any, any, any>[] = []\n> = CompiledStateGraph<\n any,\n any,\n any,\n any,\n MergedAgentState<StructuredResponseFormat, TMiddleware>,\n ToAnnotationRoot<ContextSchema>[\"spec\"],\n unknown\n>;\n\nexport class ReactAgent<\n StructuredResponseFormat extends\n | Record<string, any>\n | ResponseFormatUndefined = Record<string, any>,\n ContextSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = AnyAnnotationRoot,\n TMiddleware extends readonly AgentMiddleware<any, any, any>[] = []\n> {\n #graph: AgentGraph<StructuredResponseFormat, ContextSchema, TMiddleware>;\n\n #toolBehaviorVersion: \"v1\" | \"v2\" = \"v2\";\n\n constructor(\n public options: CreateAgentParams<StructuredResponseFormat, ContextSchema>\n ) {\n this.#toolBehaviorVersion = options.version ?? this.#toolBehaviorVersion;\n\n /**\n * Check if the LLM already has bound tools and throw if it does.\n */\n if (options.llm && typeof options.llm !== \"function\") {\n validateLLMHasNoBoundTools(options.llm);\n }\n\n /**\n * validate that model and llm options are not provided together\n */\n if (options.llm && options.model) {\n throw new Error(\"Cannot provide both `model` and `llm` options.\");\n }\n\n /**\n * validate that either model or llm option is provided\n */\n if (!options.llm && !options.model) {\n throw new Error(\n \"Either `model` or `llm` option must be provided to create an agent.\"\n );\n }\n\n const toolClasses =\n (Array.isArray(options.tools) ? options.tools : options.tools?.tools) ??\n [];\n\n /**\n * If any of the tools are configured to return_directly after running,\n * our graph needs to check if these were called\n */\n const shouldReturnDirect = new Set(\n toolClasses\n .filter(isClientTool)\n .filter((tool) => \"returnDirect\" in tool && tool.returnDirect)\n .map((tool) => tool.name)\n );\n\n // Create a schema that merges agent base schema with middleware state schemas\n const schema = createAgentAnnotationConditional<\n StructuredResponseFormat,\n TMiddleware\n >(\n this.options.responseFormat !== undefined,\n this.options.middleware as TMiddleware\n );\n\n const workflow = new StateGraph(\n schema as AnnotationRoot<any>,\n this.options.contextSchema\n );\n\n const allNodeWorkflows = workflow as WithStateGraphNodes<\n \"tools\" | \"model_request\" | string,\n typeof workflow\n >;\n\n // Generate node names for middleware nodes that have hooks\n const beforeModelNodes: { index: number; name: string }[] = [];\n const afterModelNodes: { index: number; name: string }[] = [];\n const prepareModelRequestHookMiddleware: [\n AgentMiddleware,\n /**\n * ToDo: better type to get the state of middleware\n */\n () => any\n ][] = [];\n\n const middleware = this.options.middleware ?? [];\n for (let i = 0; i < middleware.length; i++) {\n let beforeModelNode: BeforeModelNode | undefined;\n let afterModelNode: AfterModelNode | undefined;\n const m = middleware[i];\n if (m.beforeModel) {\n beforeModelNode = new BeforeModelNode(m);\n const name = `before_model_${m.name}_${i}`;\n beforeModelNodes.push({\n index: i,\n name,\n });\n allNodeWorkflows.addNode(\n name,\n beforeModelNode,\n beforeModelNode.nodeOptions\n );\n }\n if (m.afterModel) {\n afterModelNode = new AfterModelNode(m);\n const name = `after_model_${m.name}_${i}`;\n afterModelNodes.push({\n index: i,\n name,\n });\n allNodeWorkflows.addNode(\n name,\n afterModelNode,\n afterModelNode.nodeOptions\n );\n }\n\n if (m.prepareModelRequest) {\n prepareModelRequestHookMiddleware.push([\n m,\n () => ({\n ...beforeModelNode?.getState(),\n ...afterModelNode?.getState(),\n }),\n ]);\n }\n }\n\n /**\n * Add Nodes\n */\n allNodeWorkflows.addNode(\n \"model_request\",\n new AgentNode({\n llm: this.options.llm,\n model: this.options.model,\n prompt: this.options.prompt,\n includeAgentName: this.options.includeAgentName,\n name: this.options.name,\n responseFormat: this.options.responseFormat,\n middleware: this.options.middleware,\n toolClasses,\n shouldReturnDirect,\n signal: this.options.signal,\n prepareModelRequestHookMiddleware,\n }),\n AgentNode.nodeOptions\n );\n\n /**\n * add single tool node for all tools\n */\n if (toolClasses.length > 0) {\n const toolNode = new ToolNode(toolClasses.filter(isClientTool), {\n signal: this.options.signal,\n });\n allNodeWorkflows.addNode(\"tools\", toolNode);\n }\n\n /**\n * Add Edges\n */\n // Determine starting point based on what nodes exist\n if (beforeModelNodes.length > 0) {\n // If we have beforeModel nodes, start with the first one\n allNodeWorkflows.addEdge(START, beforeModelNodes[0].name);\n } else {\n // If no beforeModel nodes, go directly to agent\n allNodeWorkflows.addEdge(START, \"model_request\");\n }\n\n // Connect beforeModel nodes in sequence\n for (let i = 0; i < beforeModelNodes.length - 1; i++) {\n allNodeWorkflows.addEdge(\n beforeModelNodes[i].name,\n beforeModelNodes[i + 1].name\n );\n }\n\n // Connect last beforeModel node to agent\n const lastBeforeModelNode = beforeModelNodes.at(-1);\n if (beforeModelNodes.length > 0 && lastBeforeModelNode) {\n allNodeWorkflows.addEdge(lastBeforeModelNode.name, \"model_request\");\n }\n\n // Connect agent to last afterModel node (for reverse order execution)\n const lastAfterModelNode = afterModelNodes.at(-1);\n if (afterModelNodes.length > 0 && lastAfterModelNode) {\n allNodeWorkflows.addEdge(\"model_request\", lastAfterModelNode.name);\n } else {\n const modelPaths = this.#getModelPaths(toolClasses.filter(isClientTool));\n if (modelPaths.length === 1) {\n allNodeWorkflows.addEdge(\"model_request\", modelPaths[0]);\n } else {\n allNodeWorkflows.addConditionalEdges(\n \"model_request\",\n this.#createModelRouter(),\n modelPaths\n );\n }\n }\n\n // Connect afterModel nodes in reverse sequence\n for (let i = afterModelNodes.length - 1; i > 0; i--) {\n allNodeWorkflows.addEdge(\n afterModelNodes[i].name,\n afterModelNodes[i - 1].name\n );\n }\n\n // Connect first afterModel node (last to execute) to model paths\n if (afterModelNodes.length > 0) {\n const firstAfterModelNode = afterModelNodes[0].name;\n const modelPaths = this.#getModelPaths(toolClasses.filter(isClientTool));\n if (modelPaths.length === 1) {\n allNodeWorkflows.addEdge(firstAfterModelNode, modelPaths[0]);\n } else {\n allNodeWorkflows.addConditionalEdges(\n firstAfterModelNode,\n this.#createModelRouter(),\n modelPaths\n );\n }\n }\n\n /**\n * add edges for tools node\n */\n if (toolClasses.length > 0) {\n // Tools should return to first beforeModel node or agent\n let toolReturnTarget: string;\n if (beforeModelNodes.length > 0) {\n toolReturnTarget = beforeModelNodes[0].name;\n } else {\n toolReturnTarget = \"model_request\";\n }\n\n if (shouldReturnDirect.size > 0) {\n allNodeWorkflows.addConditionalEdges(\n \"tools\",\n this.#createToolsRouter(shouldReturnDirect),\n [toolReturnTarget, END]\n );\n } else {\n allNodeWorkflows.addEdge(\"tools\", toolReturnTarget);\n }\n }\n\n /**\n * compile the graph\n */\n this.#graph = allNodeWorkflows.compile({\n checkpointer: this.options.checkpointer ?? this.options.checkpointSaver,\n interruptBefore: this.options.interruptBefore,\n interruptAfter: this.options.interruptAfter,\n store: this.options.store,\n name: this.options.name,\n description: this.options.description,\n }) as AgentGraph<StructuredResponseFormat, ContextSchema, TMiddleware>;\n }\n\n /**\n * Get the compiled graph.\n */\n get graph(): AgentGraph<\n StructuredResponseFormat,\n ContextSchema,\n TMiddleware\n > {\n return this.#graph;\n }\n\n /**\n * Get possible edge destinations from model node.\n * @param toolClasses names of tools to call\n * @returns list of possible edge destinations\n */\n #getModelPaths(\n toolClasses: (ClientTool | ServerTool)[]\n ): (\"tools\" | typeof END)[] {\n const paths: (\"tools\" | typeof END)[] = [];\n if (toolClasses.length > 0) {\n paths.push(\"tools\");\n }\n\n paths.push(END);\n\n return paths;\n }\n\n /**\n * Create routing function for model node conditional edges.\n */\n #createModelRouter() {\n /**\n * determine if the agent should continue or not\n */\n /**\n * ToDo: fix type\n */\n return (state: any) => {\n const messages = state.messages;\n const lastMessage = messages.at(-1);\n\n if (\n !AIMessage.isInstance(lastMessage) ||\n !lastMessage.tool_calls ||\n lastMessage.tool_calls.length === 0\n ) {\n return END;\n }\n\n /**\n * The tool node processes a single message.\n */\n if (this.#toolBehaviorVersion === \"v1\") {\n return \"tools\";\n }\n\n /**\n * Route to tools node\n */\n return lastMessage.tool_calls.map(\n (toolCall) => new Send(\"tools\", { ...state, lg_tool_call: toolCall })\n );\n };\n }\n\n /**\n * Create routing function for tools node conditional edges.\n */\n #createToolsRouter(shouldReturnDirect: Set<string>) {\n /**\n * ToDo: fix type\n */\n return (state: any) => {\n const messages = state.messages;\n const lastMessage = messages[messages.length - 1];\n\n // Check if we just executed a returnDirect tool\n if (\n ToolMessage.isInstance(lastMessage) &&\n lastMessage.name &&\n shouldReturnDirect.has(lastMessage.name)\n ) {\n // If we have a response format, route to agent to generate structured response\n // Otherwise, return directly\n return this.options.responseFormat ? \"model_request\" : END;\n }\n\n // For non-returnDirect tools, always route back to agent\n return \"model_request\";\n };\n }\n\n /**\n * Initialize middleware states if not already present in the input state.\n */\n #initializeMiddlewareStates(\n state: InvokeStateParameter<TMiddleware>\n ): InvokeStateParameter<TMiddleware> {\n if (\n !this.options.middleware ||\n this.options.middleware.length === 0 ||\n state instanceof Command ||\n !state\n ) {\n return state;\n }\n\n const defaultStates = initializeMiddlewareStates(\n this.options.middleware,\n state\n );\n const updatedState = { ...state } as InvokeStateParameter<TMiddleware>;\n if (!updatedState) {\n return updatedState;\n }\n\n // Only add defaults for keys that don't exist in current state\n for (const [key, value] of Object.entries(defaultStates)) {\n if (!(key in updatedState)) {\n // @ts-expect-error - ToDo: fix type\n updatedState[key as keyof InvokeStateParameter<TMiddleware>] = value;\n }\n }\n\n return updatedState;\n }\n\n /**\n * @inheritdoc\n */\n get invoke() {\n type FullState = MergedAgentState<StructuredResponseFormat, TMiddleware>;\n type FullContext = InferContextInput<ContextSchema> &\n InferMiddlewareContextInputs<TMiddleware>;\n\n // Create overloaded function type based on whether context has required fields\n type InvokeFunction = IsAllOptional<FullContext> extends true\n ? (\n state: InvokeStateParameter<TMiddleware>,\n config?: LangGraphRunnableConfig<FullContext>\n ) => Promise<FullState>\n : (\n state: InvokeStateParameter<TMiddleware>,\n config?: LangGraphRunnableConfig<FullContext>\n ) => Promise<FullState>;\n\n const invokeFunc: InvokeFunction = async (\n state: InvokeStateParameter<TMiddleware>,\n config?: LangGraphRunnableConfig<FullContext>\n ): Promise<FullState> => {\n const initializedState = this.#initializeMiddlewareStates(state);\n return this.#graph.invoke(\n initializedState,\n config as any\n ) as Promise<FullState>;\n };\n\n return invokeFunc;\n }\n\n /**\n * ToDo(@christian-bromann): Add stream and streamEvents methods\n */\n\n /**\n * Visualize the graph as a PNG image.\n * @param params - Parameters for the drawMermaidPng method.\n * @param params.withStyles - Whether to include styles in the graph.\n * @param params.curveStyle - The style of the graph's curves.\n * @param params.nodeColors - The colors of the graph's nodes.\n * @param params.wrapLabelNWords - The maximum number of words to wrap in a node's label.\n * @param params.backgroundColor - The background color of the graph.\n * @returns PNG image as a buffer\n */\n async drawMermaidPng(params?: {\n withStyles?: boolean;\n curveStyle?: string;\n nodeColors?: Record<string, string>;\n wrapLabelNWords?: number;\n backgroundColor?: string;\n }) {\n const representation = await this.#graph.getGraphAsync();\n const image = await representation.drawMermaidPng(params);\n const arrayBuffer = await image.arrayBuffer();\n const buffer = new Uint8Array(arrayBuffer);\n return buffer;\n }\n\n /**\n * Draw the graph as a Mermaid string.\n * @param params - Parameters for the drawMermaid method.\n * @param params.withStyles - Whether to include styles in the graph.\n * @param params.curveStyle - The style of the graph's curves.\n * @param params.nodeColors - The colors of the graph's nodes.\n * @param params.wrapLabelNWords - The maximum number of words to wrap in a node's label.\n * @param params.backgroundColor - The background color of the graph.\n * @returns Mermaid string\n */\n async drawMermaid(params?: {\n withStyles?: boolean;\n curveStyle?: string;\n nodeColors?: Record<string, string>;\n wrapLabelNWords?: number;\n backgroundColor?: string;\n }) {\n const representation = await this.#graph.getGraphAsync();\n return representation.drawMermaid(params);\n }\n}\n"],"mappings":";;;;;;;;;;;AAgFA,IAAa,aAAb,MAQE;CACA;CAEA,uBAAoC;CAEpC,YACSA,SACP;EADO;EAEP,KAAKC,uBAAuB,QAAQ,WAAW,KAAKA;;;;AAKpD,MAAI,QAAQ,OAAO,OAAO,QAAQ,QAAQ,YACxC,2BAA2B,QAAQ,IAAI;;;;AAMzC,MAAI,QAAQ,OAAO,QAAQ,MACzB,OAAM,IAAI,MAAM;;;;AAMlB,MAAI,CAAC,QAAQ,OAAO,CAAC,QAAQ,MAC3B,OAAM,IAAI,MACR;EAIJ,MAAM,eACH,MAAM,QAAQ,QAAQ,MAAM,GAAG,QAAQ,QAAQ,QAAQ,OAAO,UAC/D,CAAE;;;;;EAMJ,MAAM,qBAAqB,IAAI,IAC7B,YACG,OAAO,aAAa,CACpB,OAAO,CAAC,SAAS,kBAAkB,QAAQ,KAAK,aAAa,CAC7D,IAAI,CAAC,SAAS,KAAK,KAAK;EAI7B,MAAM,SAAS,iCAIb,KAAK,QAAQ,mBAAmB,QAChC,KAAK,QAAQ,WACd;EAED,MAAM,WAAW,IAAI,WACnB,QACA,KAAK,QAAQ;EAGf,MAAM,mBAAmB;EAMzB,MAAMC,mBAAsD,CAAE;EAC9D,MAAMC,kBAAqD,CAAE;EAC7D,MAAMC,oCAMA,CAAE;EAER,MAAM,aAAa,KAAK,QAAQ,cAAc,CAAE;AAChD,OAAK,IAAI,IAAI,GAAG,IAAI,WAAW,QAAQ,KAAK;GAC1C,IAAIC;GACJ,IAAIC;GACJ,MAAM,IAAI,WAAW;AACrB,OAAI,EAAE,aAAa;IACjB,kBAAkB,IAAI,gBAAgB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gBX,MAAMC,aAA6B,OACjCD,OACAE,WACuB;GACvB,MAAM,mBAAmB,KAAKC,4BAA4B,MAAM;AAChE,UAAO,KAAKR,OAAO,OACjB,kBACA,OACD;EACF;AAED,SAAO;CACR;;;;;;;;;;;;;;CAgBD,MAAM,eAAeS,QAMlB;EACD,MAAM,iBAAiB,MAAM,KAAKT,OAAO,eAAe;EACxD,MAAM,QAAQ,MAAM,eAAe,eAAe,OAAO;EACzD,MAAM,cAAc,MAAM,MAAM,aAAa;EAC7C,MAAM,SAAS,IAAI,WAAW;AAC9B,SAAO;CACR;;;;;;;;;;;CAYD,MAAM,YAAYS,QAMf;EACD,MAAM,iBAAiB,MAAM,KAAKT,OAAO,eAAe;AACxD,SAAO,eAAe,YAAY,OAAO;CAC1C;AACF"}
@@ -2,12 +2,12 @@ const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
2
2
  const __langchain_langgraph = require_rolldown_runtime.__toESM(require("@langchain/langgraph"));
3
3
 
4
4
  //#region src/agents/middlewareAgent/annotation.ts
5
- function createAgentAnnotationConditional(hasStructuredResponse = true, middlewares = []) {
5
+ function createAgentAnnotationConditional(hasStructuredResponse = true, middlewareList = []) {
6
6
  const baseAnnotation = { messages: (0, __langchain_langgraph.Annotation)({
7
7
  reducer: __langchain_langgraph.messagesStateReducer,
8
8
  default: () => []
9
9
  }) };
10
- for (const middleware of middlewares) if (middleware.stateSchema) {
10
+ for (const middleware of middlewareList) if (middleware.stateSchema) {
11
11
  let parsedDefaults = {};
12
12
  try {
13
13
  parsedDefaults = middleware.stateSchema.parse({});
@@ -1 +1 @@
1
- {"version":3,"file":"annotation.cjs","names":["middlewares: TMiddlewares","baseAnnotation: Record<string, any>","messagesStateReducer","parsedDefaults: Record<string, any>","x: any","y: any","Annotation"],"sources":["../../../src/agents/middlewareAgent/annotation.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/ban-types */\nimport { BaseMessage } from \"@langchain/core/messages\";\nimport {\n Annotation,\n Messages,\n AnnotationRoot,\n messagesStateReducer,\n type BinaryOperatorAggregate,\n type LastValue,\n} from \"@langchain/langgraph\";\nimport type { ResponseFormatUndefined } from \"../responses.js\";\nimport type { AgentMiddleware, InferMiddlewareStates } from \"./types.js\";\n\n// Create annotation conditionally - for ResponseFormatUndefined, don't include structuredResponse\n// Helper type for the merged annotation\ntype MergedAnnotationSpec<\n T extends Record<string, any> | ResponseFormatUndefined,\n TMiddlewares extends readonly AgentMiddleware<any, any, any>[]\n> = {\n messages: BinaryOperatorAggregate<BaseMessage[], Messages>;\n} & (T extends ResponseFormatUndefined\n ? {}\n : { structuredResponse: LastValue<T> }) &\n InferMiddlewareStates<TMiddlewares>;\n\nexport function createAgentAnnotationConditional<\n T extends Record<string, any> | ResponseFormatUndefined,\n TMiddlewares extends readonly AgentMiddleware<any, any, any>[] = []\n>(\n hasStructuredResponse = true,\n middlewares: TMiddlewares = [] as unknown as TMiddlewares\n): AnnotationRoot<MergedAnnotationSpec<T, TMiddlewares>> {\n const baseAnnotation: Record<string, any> = {\n messages: Annotation<BaseMessage[], Messages>({\n reducer: messagesStateReducer,\n default: () => [],\n }),\n };\n\n // Add middleware state properties to the annotation\n for (const middleware of middlewares) {\n if (middleware.stateSchema) {\n // Parse empty object to get default values\n let parsedDefaults: Record<string, any> = {};\n try {\n parsedDefaults = middleware.stateSchema.parse({});\n } catch {\n // If parsing fails, we'll use undefined as defaults\n }\n\n const { shape } = middleware.stateSchema;\n for (const [key] of Object.entries(shape)) {\n /**\n * Skip private state properties\n */\n if (key.startsWith(\"_\")) {\n continue;\n }\n\n if (!(key in baseAnnotation)) {\n const defaultValue = parsedDefaults[key] ?? undefined;\n baseAnnotation[key] = Annotation({\n reducer: (x: any, y: any) => y ?? x,\n default: () => defaultValue,\n });\n }\n }\n }\n }\n\n if (!hasStructuredResponse) {\n return Annotation.Root(baseAnnotation) as AnnotationRoot<\n MergedAnnotationSpec<T, TMiddlewares>\n >;\n }\n\n return Annotation.Root({\n ...baseAnnotation,\n structuredResponse:\n Annotation<T extends ResponseFormatUndefined ? never : T>(),\n }) as unknown as AnnotationRoot<MergedAnnotationSpec<T, TMiddlewares>>;\n}\n"],"mappings":";;;;AAyBA,SAAgB,iCAId,wBAAwB,MACxBA,cAA4B,CAAE,GACyB;CACvD,MAAMC,iBAAsC,EAC1C,gDAA8C;EAC5C,SAASC;EACT,SAAS,MAAM,CAAE;CAClB,EAAC,CACH;AAGD,MAAK,MAAM,cAAc,YACvB,KAAI,WAAW,aAAa;EAE1B,IAAIC,iBAAsC,CAAE;AAC5C,MAAI;GACF,iBAAiB,WAAW,YAAY,MAAM,CAAE,EAAC;EAClD,QAAO,CAEP;EAED,MAAM,EAAE,OAAO,GAAG,WAAW;AAC7B,OAAK,MAAM,CAAC,IAAI,IAAI,OAAO,QAAQ,MAAM,EAAE;;;;AAIzC,OAAI,IAAI,WAAW,IAAI,CACrB;AAGF,OAAI,EAAE,OAAO,iBAAiB;IAC5B,MAAM,eAAe,eAAe,QAAQ;IAC5C,eAAe,6CAAkB;KAC/B,SAAS,CAACC,GAAQC,MAAW,KAAK;KAClC,SAAS,MAAM;IAChB,EAAC;GACH;EACF;CACF;AAGH,KAAI,CAAC,sBACH,QAAOC,iCAAW,KAAK,eAAe;AAKxC,QAAOA,iCAAW,KAAK;EACrB,GAAG;EACH,2DAC6D;CAC9D,EAAC;AACH"}
1
+ {"version":3,"file":"annotation.cjs","names":["middlewareList: TMiddleware","baseAnnotation: Record<string, any>","messagesStateReducer","parsedDefaults: Record<string, any>","x: any","y: any","Annotation"],"sources":["../../../src/agents/middlewareAgent/annotation.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { BaseMessage } from \"@langchain/core/messages\";\nimport {\n Annotation,\n Messages,\n AnnotationRoot,\n messagesStateReducer,\n type BinaryOperatorAggregate,\n type LastValue,\n} from \"@langchain/langgraph\";\nimport type { ResponseFormatUndefined } from \"../responses.js\";\nimport type { AgentMiddleware, InferMiddlewareStates } from \"./types.js\";\n\n// Create annotation conditionally - for ResponseFormatUndefined, don't include structuredResponse\n// Helper type for the merged annotation\ntype MergedAnnotationSpec<\n T extends Record<string, any> | ResponseFormatUndefined,\n TMiddleware extends readonly AgentMiddleware<any, any, any>[]\n> = {\n messages: BinaryOperatorAggregate<BaseMessage[], Messages>;\n} & (T extends ResponseFormatUndefined\n ? {}\n : { structuredResponse: LastValue<T> }) &\n InferMiddlewareStates<TMiddleware>;\n\nexport function createAgentAnnotationConditional<\n T extends Record<string, any> | ResponseFormatUndefined,\n TMiddleware extends readonly AgentMiddleware<any, any, any>[] = []\n>(\n hasStructuredResponse = true,\n middlewareList: TMiddleware = [] as unknown as TMiddleware\n): AnnotationRoot<MergedAnnotationSpec<T, TMiddleware>> {\n const baseAnnotation: Record<string, any> = {\n messages: Annotation<BaseMessage[], Messages>({\n reducer: messagesStateReducer,\n default: () => [],\n }),\n };\n\n // Add middleware state properties to the annotation\n for (const middleware of middlewareList) {\n if (middleware.stateSchema) {\n // Parse empty object to get default values\n let parsedDefaults: Record<string, any> = {};\n try {\n parsedDefaults = middleware.stateSchema.parse({});\n } catch {\n // If parsing fails, we'll use undefined as defaults\n }\n\n const { shape } = middleware.stateSchema;\n for (const [key] of Object.entries(shape)) {\n /**\n * Skip private state properties\n */\n if (key.startsWith(\"_\")) {\n continue;\n }\n\n if (!(key in baseAnnotation)) {\n const defaultValue = parsedDefaults[key] ?? undefined;\n baseAnnotation[key] = Annotation({\n reducer: (x: any, y: any) => y ?? x,\n default: () => defaultValue,\n });\n }\n }\n }\n }\n\n if (!hasStructuredResponse) {\n return Annotation.Root(baseAnnotation) as AnnotationRoot<\n MergedAnnotationSpec<T, TMiddleware>\n >;\n }\n\n return Annotation.Root({\n ...baseAnnotation,\n structuredResponse:\n Annotation<T extends ResponseFormatUndefined ? never : T>(),\n }) as unknown as AnnotationRoot<MergedAnnotationSpec<T, TMiddleware>>;\n}\n"],"mappings":";;;;AAyBA,SAAgB,iCAId,wBAAwB,MACxBA,iBAA8B,CAAE,GACsB;CACtD,MAAMC,iBAAsC,EAC1C,gDAA8C;EAC5C,SAASC;EACT,SAAS,MAAM,CAAE;CAClB,EAAC,CACH;AAGD,MAAK,MAAM,cAAc,eACvB,KAAI,WAAW,aAAa;EAE1B,IAAIC,iBAAsC,CAAE;AAC5C,MAAI;GACF,iBAAiB,WAAW,YAAY,MAAM,CAAE,EAAC;EAClD,QAAO,CAEP;EAED,MAAM,EAAE,OAAO,GAAG,WAAW;AAC7B,OAAK,MAAM,CAAC,IAAI,IAAI,OAAO,QAAQ,MAAM,EAAE;;;;AAIzC,OAAI,IAAI,WAAW,IAAI,CACrB;AAGF,OAAI,EAAE,OAAO,iBAAiB;IAC5B,MAAM,eAAe,eAAe,QAAQ;IAC5C,eAAe,6CAAkB;KAC/B,SAAS,CAACC,GAAQC,MAAW,KAAK;KAClC,SAAS,MAAM;IAChB,EAAC;GACH;EACF;CACF;AAGH,KAAI,CAAC,sBACH,QAAOC,iCAAW,KAAK,eAAe;AAKxC,QAAOA,iCAAW,KAAK;EACrB,GAAG;EACH,2DAC6D;CAC9D,EAAC;AACH"}
@@ -1,12 +1,12 @@
1
1
  import { Annotation, messagesStateReducer } from "@langchain/langgraph";
2
2
 
3
3
  //#region src/agents/middlewareAgent/annotation.ts
4
- function createAgentAnnotationConditional(hasStructuredResponse = true, middlewares = []) {
4
+ function createAgentAnnotationConditional(hasStructuredResponse = true, middlewareList = []) {
5
5
  const baseAnnotation = { messages: Annotation({
6
6
  reducer: messagesStateReducer,
7
7
  default: () => []
8
8
  }) };
9
- for (const middleware of middlewares) if (middleware.stateSchema) {
9
+ for (const middleware of middlewareList) if (middleware.stateSchema) {
10
10
  let parsedDefaults = {};
11
11
  try {
12
12
  parsedDefaults = middleware.stateSchema.parse({});
@@ -1 +1 @@
1
- {"version":3,"file":"annotation.js","names":["middlewares: TMiddlewares","baseAnnotation: Record<string, any>","parsedDefaults: Record<string, any>","x: any","y: any"],"sources":["../../../src/agents/middlewareAgent/annotation.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/ban-types */\nimport { BaseMessage } from \"@langchain/core/messages\";\nimport {\n Annotation,\n Messages,\n AnnotationRoot,\n messagesStateReducer,\n type BinaryOperatorAggregate,\n type LastValue,\n} from \"@langchain/langgraph\";\nimport type { ResponseFormatUndefined } from \"../responses.js\";\nimport type { AgentMiddleware, InferMiddlewareStates } from \"./types.js\";\n\n// Create annotation conditionally - for ResponseFormatUndefined, don't include structuredResponse\n// Helper type for the merged annotation\ntype MergedAnnotationSpec<\n T extends Record<string, any> | ResponseFormatUndefined,\n TMiddlewares extends readonly AgentMiddleware<any, any, any>[]\n> = {\n messages: BinaryOperatorAggregate<BaseMessage[], Messages>;\n} & (T extends ResponseFormatUndefined\n ? {}\n : { structuredResponse: LastValue<T> }) &\n InferMiddlewareStates<TMiddlewares>;\n\nexport function createAgentAnnotationConditional<\n T extends Record<string, any> | ResponseFormatUndefined,\n TMiddlewares extends readonly AgentMiddleware<any, any, any>[] = []\n>(\n hasStructuredResponse = true,\n middlewares: TMiddlewares = [] as unknown as TMiddlewares\n): AnnotationRoot<MergedAnnotationSpec<T, TMiddlewares>> {\n const baseAnnotation: Record<string, any> = {\n messages: Annotation<BaseMessage[], Messages>({\n reducer: messagesStateReducer,\n default: () => [],\n }),\n };\n\n // Add middleware state properties to the annotation\n for (const middleware of middlewares) {\n if (middleware.stateSchema) {\n // Parse empty object to get default values\n let parsedDefaults: Record<string, any> = {};\n try {\n parsedDefaults = middleware.stateSchema.parse({});\n } catch {\n // If parsing fails, we'll use undefined as defaults\n }\n\n const { shape } = middleware.stateSchema;\n for (const [key] of Object.entries(shape)) {\n /**\n * Skip private state properties\n */\n if (key.startsWith(\"_\")) {\n continue;\n }\n\n if (!(key in baseAnnotation)) {\n const defaultValue = parsedDefaults[key] ?? undefined;\n baseAnnotation[key] = Annotation({\n reducer: (x: any, y: any) => y ?? x,\n default: () => defaultValue,\n });\n }\n }\n }\n }\n\n if (!hasStructuredResponse) {\n return Annotation.Root(baseAnnotation) as AnnotationRoot<\n MergedAnnotationSpec<T, TMiddlewares>\n >;\n }\n\n return Annotation.Root({\n ...baseAnnotation,\n structuredResponse:\n Annotation<T extends ResponseFormatUndefined ? never : T>(),\n }) as unknown as AnnotationRoot<MergedAnnotationSpec<T, TMiddlewares>>;\n}\n"],"mappings":";;;AAyBA,SAAgB,iCAId,wBAAwB,MACxBA,cAA4B,CAAE,GACyB;CACvD,MAAMC,iBAAsC,EAC1C,UAAU,WAAoC;EAC5C,SAAS;EACT,SAAS,MAAM,CAAE;CAClB,EAAC,CACH;AAGD,MAAK,MAAM,cAAc,YACvB,KAAI,WAAW,aAAa;EAE1B,IAAIC,iBAAsC,CAAE;AAC5C,MAAI;GACF,iBAAiB,WAAW,YAAY,MAAM,CAAE,EAAC;EAClD,QAAO,CAEP;EAED,MAAM,EAAE,OAAO,GAAG,WAAW;AAC7B,OAAK,MAAM,CAAC,IAAI,IAAI,OAAO,QAAQ,MAAM,EAAE;;;;AAIzC,OAAI,IAAI,WAAW,IAAI,CACrB;AAGF,OAAI,EAAE,OAAO,iBAAiB;IAC5B,MAAM,eAAe,eAAe,QAAQ;IAC5C,eAAe,OAAO,WAAW;KAC/B,SAAS,CAACC,GAAQC,MAAW,KAAK;KAClC,SAAS,MAAM;IAChB,EAAC;GACH;EACF;CACF;AAGH,KAAI,CAAC,sBACH,QAAO,WAAW,KAAK,eAAe;AAKxC,QAAO,WAAW,KAAK;EACrB,GAAG;EACH,oBACE,YAA2D;CAC9D,EAAC;AACH"}
1
+ {"version":3,"file":"annotation.js","names":["middlewareList: TMiddleware","baseAnnotation: Record<string, any>","parsedDefaults: Record<string, any>","x: any","y: any"],"sources":["../../../src/agents/middlewareAgent/annotation.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { BaseMessage } from \"@langchain/core/messages\";\nimport {\n Annotation,\n Messages,\n AnnotationRoot,\n messagesStateReducer,\n type BinaryOperatorAggregate,\n type LastValue,\n} from \"@langchain/langgraph\";\nimport type { ResponseFormatUndefined } from \"../responses.js\";\nimport type { AgentMiddleware, InferMiddlewareStates } from \"./types.js\";\n\n// Create annotation conditionally - for ResponseFormatUndefined, don't include structuredResponse\n// Helper type for the merged annotation\ntype MergedAnnotationSpec<\n T extends Record<string, any> | ResponseFormatUndefined,\n TMiddleware extends readonly AgentMiddleware<any, any, any>[]\n> = {\n messages: BinaryOperatorAggregate<BaseMessage[], Messages>;\n} & (T extends ResponseFormatUndefined\n ? {}\n : { structuredResponse: LastValue<T> }) &\n InferMiddlewareStates<TMiddleware>;\n\nexport function createAgentAnnotationConditional<\n T extends Record<string, any> | ResponseFormatUndefined,\n TMiddleware extends readonly AgentMiddleware<any, any, any>[] = []\n>(\n hasStructuredResponse = true,\n middlewareList: TMiddleware = [] as unknown as TMiddleware\n): AnnotationRoot<MergedAnnotationSpec<T, TMiddleware>> {\n const baseAnnotation: Record<string, any> = {\n messages: Annotation<BaseMessage[], Messages>({\n reducer: messagesStateReducer,\n default: () => [],\n }),\n };\n\n // Add middleware state properties to the annotation\n for (const middleware of middlewareList) {\n if (middleware.stateSchema) {\n // Parse empty object to get default values\n let parsedDefaults: Record<string, any> = {};\n try {\n parsedDefaults = middleware.stateSchema.parse({});\n } catch {\n // If parsing fails, we'll use undefined as defaults\n }\n\n const { shape } = middleware.stateSchema;\n for (const [key] of Object.entries(shape)) {\n /**\n * Skip private state properties\n */\n if (key.startsWith(\"_\")) {\n continue;\n }\n\n if (!(key in baseAnnotation)) {\n const defaultValue = parsedDefaults[key] ?? undefined;\n baseAnnotation[key] = Annotation({\n reducer: (x: any, y: any) => y ?? x,\n default: () => defaultValue,\n });\n }\n }\n }\n }\n\n if (!hasStructuredResponse) {\n return Annotation.Root(baseAnnotation) as AnnotationRoot<\n MergedAnnotationSpec<T, TMiddleware>\n >;\n }\n\n return Annotation.Root({\n ...baseAnnotation,\n structuredResponse:\n Annotation<T extends ResponseFormatUndefined ? never : T>(),\n }) as unknown as AnnotationRoot<MergedAnnotationSpec<T, TMiddleware>>;\n}\n"],"mappings":";;;AAyBA,SAAgB,iCAId,wBAAwB,MACxBA,iBAA8B,CAAE,GACsB;CACtD,MAAMC,iBAAsC,EAC1C,UAAU,WAAoC;EAC5C,SAAS;EACT,SAAS,MAAM,CAAE;CAClB,EAAC,CACH;AAGD,MAAK,MAAM,cAAc,eACvB,KAAI,WAAW,aAAa;EAE1B,IAAIC,iBAAsC,CAAE;AAC5C,MAAI;GACF,iBAAiB,WAAW,YAAY,MAAM,CAAE,EAAC;EAClD,QAAO,CAEP;EAED,MAAM,EAAE,OAAO,GAAG,WAAW;AAC7B,OAAK,MAAM,CAAC,IAAI,IAAI,OAAO,QAAQ,MAAM,EAAE;;;;AAIzC,OAAI,IAAI,WAAW,IAAI,CACrB;AAGF,OAAI,EAAE,OAAO,iBAAiB;IAC5B,MAAM,eAAe,eAAe,QAAQ;IAC5C,eAAe,OAAO,WAAW;KAC/B,SAAS,CAACC,GAAQC,MAAW,KAAK;KAClC,SAAS,MAAM;IAChB,EAAC;GACH;EACF;CACF;AAGH,KAAI,CAAC,sBACH,QAAO,WAAW,KAAK,eAAe;AAKxC,QAAO,WAAW,KAAK;EACrB,GAAG;EACH,oBACE,YAA2D;CAC9D,EAAC;AACH"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["params: CreateAgentParams<StructuredResponseFormat, ContextSchema, any>","ReactAgent"],"sources":["../../../src/agents/middlewareAgent/index.ts"],"sourcesContent":["import type {\n InteropZodObject,\n InteropZodType,\n} from \"@langchain/core/utils/types\";\n\nimport { type AnyAnnotationRoot } from \"../annotation.js\";\nimport type { CreateAgentParams, AgentMiddleware } from \"./types.js\";\nimport type { ExtractZodArrayTypes } from \"../types.js\";\nimport type {\n ToolStrategy,\n TypedToolStrategy,\n ProviderStrategy,\n ResponseFormat,\n ResponseFormatUndefined,\n JsonSchemaFormat,\n} from \"../responses.js\";\nimport { ReactAgent } from \"./ReactAgent.js\";\n\n/**\n * Creates a StateGraph agent that relies on a chat model utilizing tool calling.\n *\n * @example\n * ```ts\n * import { ChatOpenAI } from \"@langchain/openai\";\n * import { createAgent, tool } from \"langchain\";\n * import { z } from \"zod\";\n *\n * const model = new ChatOpenAI({\n * model: \"gpt-4o\",\n * });\n *\n * const getWeather = tool((input) => {\n * if ([\"sf\", \"san francisco\"].includes(input.location.toLowerCase())) {\n * return \"It's 60 degrees and foggy.\";\n * } else {\n * return \"It's 90 degrees and sunny.\";\n * }\n * }, {\n * name: \"get_weather\",\n * description: \"Call to get the current weather.\",\n * schema: z.object({\n * location: z.string().describe(\"Location to get the weather for.\"),\n * })\n * })\n *\n * const agent = createAgent({ llm: model, tools: [getWeather] });\n *\n * const inputs = {\n * messages: [{ role: \"user\", content: \"what is the weather in SF?\" }],\n * };\n *\n * const stream = await agent.stream(inputs, { streamMode: \"values\" });\n *\n * for await (const { messages } of stream) {\n * console.log(messages);\n * }\n * // Returns the messages in the state at each step of execution\n * ```\n */\n// Overload 1: With responseFormat as single InteropZodType\nexport function createAgent<\n T extends Record<string, any> = Record<string, any>,\n ContextSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = AnyAnnotationRoot,\n TMiddlewares extends readonly AgentMiddleware<\n any,\n any,\n any\n >[] = readonly AgentMiddleware<any, any, any>[]\n>(\n params: CreateAgentParams<T, ContextSchema, InteropZodType<T>> & {\n responseFormat: InteropZodType<T>;\n middlewares?: TMiddlewares;\n }\n): ReactAgent<T, ContextSchema, TMiddlewares>;\n\n// Overload 2: With responseFormat as array of InteropZodTypes (infers union type)\nexport function createAgent<\n T extends readonly InteropZodType<any>[],\n ContextSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = AnyAnnotationRoot,\n TMiddlewares extends readonly AgentMiddleware<\n any,\n any,\n any\n >[] = readonly AgentMiddleware<any, any, any>[]\n>(\n params: CreateAgentParams<\n ExtractZodArrayTypes<T> extends Record<string, any>\n ? ExtractZodArrayTypes<T>\n : Record<string, any>,\n ContextSchema,\n T\n > & {\n responseFormat: T;\n middlewares?: TMiddlewares;\n }\n): ReactAgent<\n ExtractZodArrayTypes<T> extends Record<string, any>\n ? ExtractZodArrayTypes<T>\n : Record<string, any>,\n ContextSchema,\n TMiddlewares\n>;\n\n// Overload 3: With responseFormat as JsonSchemaFormat (JSON schema object)\nexport function createAgent<\n ContextSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = AnyAnnotationRoot,\n TMiddlewares extends readonly AgentMiddleware<\n any,\n any,\n any\n >[] = readonly AgentMiddleware<any, any, any>[]\n>(\n params: CreateAgentParams<\n Record<string, unknown>,\n ContextSchema,\n JsonSchemaFormat\n > & {\n responseFormat: JsonSchemaFormat;\n middlewares?: TMiddlewares;\n }\n): ReactAgent<Record<string, unknown>, ContextSchema, TMiddlewares>;\n\n// Overload 4: With responseFormat as array of JsonSchemaFormat (JSON schema objects)\nexport function createAgent<\n ContextSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = AnyAnnotationRoot,\n TMiddlewares extends readonly AgentMiddleware<\n any,\n any,\n any\n >[] = readonly AgentMiddleware<any, any, any>[]\n>(\n params: CreateAgentParams<\n Record<string, unknown>,\n ContextSchema,\n JsonSchemaFormat[]\n > & {\n responseFormat: JsonSchemaFormat[];\n middlewares?: TMiddlewares;\n }\n): ReactAgent<Record<string, unknown>, ContextSchema, TMiddlewares>;\n\n// Overload 4.5: With responseFormat as union of JsonSchemaFormat | JsonSchemaFormat[]\nexport function createAgent<\n ContextSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = AnyAnnotationRoot,\n TMiddlewares extends readonly AgentMiddleware<\n any,\n any,\n any\n >[] = readonly AgentMiddleware<any, any, any>[]\n>(\n params: CreateAgentParams<\n Record<string, unknown>,\n ContextSchema,\n JsonSchemaFormat | JsonSchemaFormat[]\n > & {\n responseFormat: JsonSchemaFormat | JsonSchemaFormat[];\n middlewares?: TMiddlewares;\n }\n): ReactAgent<Record<string, unknown>, ContextSchema, TMiddlewares>;\n\n// Overload 5: With responseFormat as TypedToolStrategy (for union types from toolStrategy)\nexport function createAgent<\n T extends Record<string, any> = Record<string, any>,\n ContextSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = AnyAnnotationRoot,\n TMiddlewares extends readonly AgentMiddleware<\n any,\n any,\n any\n >[] = readonly AgentMiddleware<any, any, any>[]\n>(\n params: CreateAgentParams<T, ContextSchema, TypedToolStrategy<T>> & {\n responseFormat: TypedToolStrategy<T>;\n middlewares?: TMiddlewares;\n }\n): ReactAgent<T, ContextSchema, TMiddlewares>;\n\n// Overload 6: With responseFormat as single ToolStrategy instance\nexport function createAgent<\n T extends Record<string, any> = Record<string, any>,\n ContextSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = AnyAnnotationRoot,\n TMiddlewares extends readonly AgentMiddleware<\n any,\n any,\n any\n >[] = readonly AgentMiddleware<any, any, any>[]\n>(\n params: CreateAgentParams<T, ContextSchema, ToolStrategy<T>> & {\n responseFormat: ToolStrategy<T>;\n middlewares?: TMiddlewares;\n }\n): ReactAgent<T, ContextSchema, TMiddlewares>;\n\n// Overload 7: With responseFormat as ProviderStrategy\nexport function createAgent<\n T extends Record<string, any> = Record<string, any>,\n ContextSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = AnyAnnotationRoot,\n TMiddlewares extends readonly AgentMiddleware<\n any,\n any,\n any\n >[] = readonly AgentMiddleware<any, any, any>[]\n>(\n params: CreateAgentParams<T, ContextSchema, ProviderStrategy<T>> & {\n responseFormat: ProviderStrategy<T>;\n middlewares?: TMiddlewares;\n }\n): ReactAgent<T, ContextSchema, TMiddlewares>;\n\n// Overload 8: Without responseFormat property at all - with proper middleware state typing\nexport function createAgent<\n ContextSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = AnyAnnotationRoot,\n TMiddlewares extends readonly AgentMiddleware<\n any,\n any,\n any\n >[] = readonly AgentMiddleware<any, any, any>[]\n>(\n params: Omit<\n CreateAgentParams<ResponseFormatUndefined, ContextSchema, never>,\n \"responseFormat\"\n > & { middlewares?: TMiddlewares }\n): ReactAgent<ResponseFormatUndefined, ContextSchema, TMiddlewares>;\n\n// Overload 9: With responseFormat explicitly undefined\nexport function createAgent<\n ContextSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = AnyAnnotationRoot,\n TMiddlewares extends readonly AgentMiddleware<\n any,\n any,\n any\n >[] = readonly AgentMiddleware<any, any, any>[]\n>(\n params: Omit<\n CreateAgentParams<ResponseFormatUndefined, ContextSchema, never>,\n \"responseFormat\"\n > & {\n responseFormat?: undefined;\n middlewares?: TMiddlewares;\n }\n): ReactAgent<ResponseFormatUndefined, ContextSchema, TMiddlewares>;\n\n// Overload 10: For other ResponseFormat values (failsafe)\nexport function createAgent<\n StructuredResponseFormat extends Record<string, any> = Record<string, any>,\n ContextSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = AnyAnnotationRoot,\n TMiddlewares extends readonly AgentMiddleware<\n any,\n any,\n any\n >[] = readonly AgentMiddleware<any, any, any>[]\n>(\n params: CreateAgentParams<\n StructuredResponseFormat,\n ContextSchema,\n ResponseFormat\n > & {\n responseFormat: ResponseFormat;\n middlewares?: TMiddlewares;\n }\n): ReactAgent<StructuredResponseFormat, ContextSchema, TMiddlewares>;\n\n// Implementation\nexport function createAgent<\n StructuredResponseFormat extends Record<string, any>,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject,\n TMiddlewares extends readonly AgentMiddleware<any, any, any>[] = []\n>(\n params: CreateAgentParams<StructuredResponseFormat, ContextSchema, any>\n): ReactAgent<StructuredResponseFormat, ContextSchema, TMiddlewares> {\n return new ReactAgent(params);\n}\n\nexport { createMiddleware } from \"./middleware.js\";\n"],"mappings":";;;;AA4RA,SAAgB,YAKdA,QACmE;AACnE,QAAO,IAAIC,8BAAW;AACvB"}
1
+ {"version":3,"file":"index.cjs","names":["params: CreateAgentParams<StructuredResponseFormat, ContextSchema, any>","ReactAgent"],"sources":["../../../src/agents/middlewareAgent/index.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport type {\n InteropZodObject,\n InteropZodType,\n} from \"@langchain/core/utils/types\";\n\nimport { type AnyAnnotationRoot } from \"../annotation.js\";\nimport type { CreateAgentParams, AgentMiddleware } from \"./types.js\";\nimport type { ExtractZodArrayTypes } from \"../types.js\";\nimport type {\n ToolStrategy,\n TypedToolStrategy,\n ProviderStrategy,\n ResponseFormat,\n ResponseFormatUndefined,\n JsonSchemaFormat,\n} from \"../responses.js\";\nimport { ReactAgent } from \"./ReactAgent.js\";\n\n/**\n * Creates a StateGraph agent that relies on a chat model utilizing tool calling.\n *\n * @example\n * ```ts\n * import { ChatOpenAI } from \"@langchain/openai\";\n * import { createAgent, tool } from \"langchain\";\n * import { z } from \"zod/v3\";\n *\n * const model = new ChatOpenAI({\n * model: \"gpt-4o\",\n * });\n *\n * const getWeather = tool((input) => {\n * if ([\"sf\", \"san francisco\"].includes(input.location.toLowerCase())) {\n * return \"It's 60 degrees and foggy.\";\n * } else {\n * return \"It's 90 degrees and sunny.\";\n * }\n * }, {\n * name: \"get_weather\",\n * description: \"Call to get the current weather.\",\n * schema: z.object({\n * location: z.string().describe(\"Location to get the weather for.\"),\n * })\n * })\n *\n * const agent = createAgent({ llm: model, tools: [getWeather] });\n *\n * const inputs = {\n * messages: [{ role: \"user\", content: \"what is the weather in SF?\" }],\n * };\n *\n * const stream = await agent.stream(inputs, { streamMode: \"values\" });\n *\n * for await (const { messages } of stream) {\n * console.log(messages);\n * }\n * // Returns the messages in the state at each step of execution\n * ```\n */\n// Overload 1: With responseFormat as single InteropZodType\nexport function createAgent<\n T extends Record<string, any> = Record<string, any>,\n ContextSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = AnyAnnotationRoot,\n TMiddleware extends readonly AgentMiddleware<\n any,\n any,\n any\n >[] = readonly AgentMiddleware<any, any, any>[]\n>(\n params: CreateAgentParams<T, ContextSchema, InteropZodType<T>> & {\n responseFormat: InteropZodType<T>;\n middleware?: TMiddleware;\n }\n): ReactAgent<T, ContextSchema, TMiddleware>;\n\n// Overload 2: With responseFormat as array of InteropZodTypes (infers union type)\nexport function createAgent<\n T extends readonly InteropZodType<any>[],\n ContextSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = AnyAnnotationRoot,\n TMiddleware extends readonly AgentMiddleware<\n any,\n any,\n any\n >[] = readonly AgentMiddleware<any, any, any>[]\n>(\n params: CreateAgentParams<\n ExtractZodArrayTypes<T> extends Record<string, any>\n ? ExtractZodArrayTypes<T>\n : Record<string, any>,\n ContextSchema,\n T\n > & {\n responseFormat: T;\n middleware?: TMiddleware;\n }\n): ReactAgent<\n ExtractZodArrayTypes<T> extends Record<string, any>\n ? ExtractZodArrayTypes<T>\n : Record<string, any>,\n ContextSchema,\n TMiddleware\n>;\n\n// Overload 3: With responseFormat as JsonSchemaFormat (JSON schema object)\nexport function createAgent<\n ContextSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = AnyAnnotationRoot,\n TMiddleware extends readonly AgentMiddleware<\n any,\n any,\n any\n >[] = readonly AgentMiddleware<any, any, any>[]\n>(\n params: CreateAgentParams<\n Record<string, unknown>,\n ContextSchema,\n JsonSchemaFormat\n > & {\n responseFormat: JsonSchemaFormat;\n middleware?: TMiddleware;\n }\n): ReactAgent<Record<string, unknown>, ContextSchema, TMiddleware>;\n\n// Overload 4: With responseFormat as array of JsonSchemaFormat (JSON schema objects)\nexport function createAgent<\n ContextSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = AnyAnnotationRoot,\n TMiddleware extends readonly AgentMiddleware<\n any,\n any,\n any\n >[] = readonly AgentMiddleware<any, any, any>[]\n>(\n params: CreateAgentParams<\n Record<string, unknown>,\n ContextSchema,\n JsonSchemaFormat[]\n > & {\n responseFormat: JsonSchemaFormat[];\n middleware?: TMiddleware;\n }\n): ReactAgent<Record<string, unknown>, ContextSchema, TMiddleware>;\n\n// Overload 4.5: With responseFormat as union of JsonSchemaFormat | JsonSchemaFormat[]\nexport function createAgent<\n ContextSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = AnyAnnotationRoot,\n TMiddleware extends readonly AgentMiddleware<\n any,\n any,\n any\n >[] = readonly AgentMiddleware<any, any, any>[]\n>(\n params: CreateAgentParams<\n Record<string, unknown>,\n ContextSchema,\n JsonSchemaFormat | JsonSchemaFormat[]\n > & {\n responseFormat: JsonSchemaFormat | JsonSchemaFormat[];\n middleware?: TMiddleware;\n }\n): ReactAgent<Record<string, unknown>, ContextSchema, TMiddleware>;\n\n// Overload 5: With responseFormat as TypedToolStrategy (for union types from toolStrategy)\nexport function createAgent<\n T extends Record<string, any> = Record<string, any>,\n ContextSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = AnyAnnotationRoot,\n TMiddleware extends readonly AgentMiddleware<\n any,\n any,\n any\n >[] = readonly AgentMiddleware<any, any, any>[]\n>(\n params: CreateAgentParams<T, ContextSchema, TypedToolStrategy<T>> & {\n responseFormat: TypedToolStrategy<T>;\n middleware?: TMiddleware;\n }\n): ReactAgent<T, ContextSchema, TMiddleware>;\n\n// Overload 6: With responseFormat as single ToolStrategy instance\nexport function createAgent<\n T extends Record<string, any> = Record<string, any>,\n ContextSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = AnyAnnotationRoot,\n TMiddleware extends readonly AgentMiddleware<\n any,\n any,\n any\n >[] = readonly AgentMiddleware<any, any, any>[]\n>(\n params: CreateAgentParams<T, ContextSchema, ToolStrategy<T>> & {\n responseFormat: ToolStrategy<T>;\n middleware?: TMiddleware;\n }\n): ReactAgent<T, ContextSchema, TMiddleware>;\n\n// Overload 7: With responseFormat as ProviderStrategy\nexport function createAgent<\n T extends Record<string, any> = Record<string, any>,\n ContextSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = AnyAnnotationRoot,\n TMiddleware extends readonly AgentMiddleware<\n any,\n any,\n any\n >[] = readonly AgentMiddleware<any, any, any>[]\n>(\n params: CreateAgentParams<T, ContextSchema, ProviderStrategy<T>> & {\n responseFormat: ProviderStrategy<T>;\n middleware?: TMiddleware;\n }\n): ReactAgent<T, ContextSchema, TMiddleware>;\n\n// Overload 8: Without responseFormat property at all - with proper middleware state typing\nexport function createAgent<\n ContextSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = AnyAnnotationRoot,\n TMiddleware extends readonly AgentMiddleware<\n any,\n any,\n any\n >[] = readonly AgentMiddleware<any, any, any>[]\n>(\n params: Omit<\n CreateAgentParams<ResponseFormatUndefined, ContextSchema, never>,\n \"responseFormat\"\n > & { middleware?: TMiddleware }\n): ReactAgent<ResponseFormatUndefined, ContextSchema, TMiddleware>;\n\n// Overload 9: With responseFormat explicitly undefined\nexport function createAgent<\n ContextSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = AnyAnnotationRoot,\n TMiddleware extends readonly AgentMiddleware<\n any,\n any,\n any\n >[] = readonly AgentMiddleware<any, any, any>[]\n>(\n params: Omit<\n CreateAgentParams<ResponseFormatUndefined, ContextSchema, never>,\n \"responseFormat\"\n > & {\n responseFormat?: undefined;\n middleware?: TMiddleware;\n }\n): ReactAgent<ResponseFormatUndefined, ContextSchema, TMiddleware>;\n\n// Overload 10: For other ResponseFormat values (failsafe)\nexport function createAgent<\n StructuredResponseFormat extends Record<string, any> = Record<string, any>,\n ContextSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = AnyAnnotationRoot,\n TMiddleware extends readonly AgentMiddleware<\n any,\n any,\n any\n >[] = readonly AgentMiddleware<any, any, any>[]\n>(\n params: CreateAgentParams<\n StructuredResponseFormat,\n ContextSchema,\n ResponseFormat\n > & {\n responseFormat: ResponseFormat;\n middleware?: TMiddleware;\n }\n): ReactAgent<StructuredResponseFormat, ContextSchema, TMiddleware>;\n\n// Implementation\nexport function createAgent<\n StructuredResponseFormat extends Record<string, any>,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject,\n TMiddleware extends readonly AgentMiddleware<any, any, any>[] = []\n>(\n params: CreateAgentParams<StructuredResponseFormat, ContextSchema, any>\n): ReactAgent<StructuredResponseFormat, ContextSchema, TMiddleware> {\n return new ReactAgent(params);\n}\n\nexport { createMiddleware } from \"./middleware.js\";\n"],"mappings":";;;;AA6RA,SAAgB,YAKdA,QACkE;AAClE,QAAO,IAAIC,8BAAW;AACvB"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["params: CreateAgentParams<StructuredResponseFormat, ContextSchema, any>"],"sources":["../../../src/agents/middlewareAgent/index.ts"],"sourcesContent":["import type {\n InteropZodObject,\n InteropZodType,\n} from \"@langchain/core/utils/types\";\n\nimport { type AnyAnnotationRoot } from \"../annotation.js\";\nimport type { CreateAgentParams, AgentMiddleware } from \"./types.js\";\nimport type { ExtractZodArrayTypes } from \"../types.js\";\nimport type {\n ToolStrategy,\n TypedToolStrategy,\n ProviderStrategy,\n ResponseFormat,\n ResponseFormatUndefined,\n JsonSchemaFormat,\n} from \"../responses.js\";\nimport { ReactAgent } from \"./ReactAgent.js\";\n\n/**\n * Creates a StateGraph agent that relies on a chat model utilizing tool calling.\n *\n * @example\n * ```ts\n * import { ChatOpenAI } from \"@langchain/openai\";\n * import { createAgent, tool } from \"langchain\";\n * import { z } from \"zod\";\n *\n * const model = new ChatOpenAI({\n * model: \"gpt-4o\",\n * });\n *\n * const getWeather = tool((input) => {\n * if ([\"sf\", \"san francisco\"].includes(input.location.toLowerCase())) {\n * return \"It's 60 degrees and foggy.\";\n * } else {\n * return \"It's 90 degrees and sunny.\";\n * }\n * }, {\n * name: \"get_weather\",\n * description: \"Call to get the current weather.\",\n * schema: z.object({\n * location: z.string().describe(\"Location to get the weather for.\"),\n * })\n * })\n *\n * const agent = createAgent({ llm: model, tools: [getWeather] });\n *\n * const inputs = {\n * messages: [{ role: \"user\", content: \"what is the weather in SF?\" }],\n * };\n *\n * const stream = await agent.stream(inputs, { streamMode: \"values\" });\n *\n * for await (const { messages } of stream) {\n * console.log(messages);\n * }\n * // Returns the messages in the state at each step of execution\n * ```\n */\n// Overload 1: With responseFormat as single InteropZodType\nexport function createAgent<\n T extends Record<string, any> = Record<string, any>,\n ContextSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = AnyAnnotationRoot,\n TMiddlewares extends readonly AgentMiddleware<\n any,\n any,\n any\n >[] = readonly AgentMiddleware<any, any, any>[]\n>(\n params: CreateAgentParams<T, ContextSchema, InteropZodType<T>> & {\n responseFormat: InteropZodType<T>;\n middlewares?: TMiddlewares;\n }\n): ReactAgent<T, ContextSchema, TMiddlewares>;\n\n// Overload 2: With responseFormat as array of InteropZodTypes (infers union type)\nexport function createAgent<\n T extends readonly InteropZodType<any>[],\n ContextSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = AnyAnnotationRoot,\n TMiddlewares extends readonly AgentMiddleware<\n any,\n any,\n any\n >[] = readonly AgentMiddleware<any, any, any>[]\n>(\n params: CreateAgentParams<\n ExtractZodArrayTypes<T> extends Record<string, any>\n ? ExtractZodArrayTypes<T>\n : Record<string, any>,\n ContextSchema,\n T\n > & {\n responseFormat: T;\n middlewares?: TMiddlewares;\n }\n): ReactAgent<\n ExtractZodArrayTypes<T> extends Record<string, any>\n ? ExtractZodArrayTypes<T>\n : Record<string, any>,\n ContextSchema,\n TMiddlewares\n>;\n\n// Overload 3: With responseFormat as JsonSchemaFormat (JSON schema object)\nexport function createAgent<\n ContextSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = AnyAnnotationRoot,\n TMiddlewares extends readonly AgentMiddleware<\n any,\n any,\n any\n >[] = readonly AgentMiddleware<any, any, any>[]\n>(\n params: CreateAgentParams<\n Record<string, unknown>,\n ContextSchema,\n JsonSchemaFormat\n > & {\n responseFormat: JsonSchemaFormat;\n middlewares?: TMiddlewares;\n }\n): ReactAgent<Record<string, unknown>, ContextSchema, TMiddlewares>;\n\n// Overload 4: With responseFormat as array of JsonSchemaFormat (JSON schema objects)\nexport function createAgent<\n ContextSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = AnyAnnotationRoot,\n TMiddlewares extends readonly AgentMiddleware<\n any,\n any,\n any\n >[] = readonly AgentMiddleware<any, any, any>[]\n>(\n params: CreateAgentParams<\n Record<string, unknown>,\n ContextSchema,\n JsonSchemaFormat[]\n > & {\n responseFormat: JsonSchemaFormat[];\n middlewares?: TMiddlewares;\n }\n): ReactAgent<Record<string, unknown>, ContextSchema, TMiddlewares>;\n\n// Overload 4.5: With responseFormat as union of JsonSchemaFormat | JsonSchemaFormat[]\nexport function createAgent<\n ContextSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = AnyAnnotationRoot,\n TMiddlewares extends readonly AgentMiddleware<\n any,\n any,\n any\n >[] = readonly AgentMiddleware<any, any, any>[]\n>(\n params: CreateAgentParams<\n Record<string, unknown>,\n ContextSchema,\n JsonSchemaFormat | JsonSchemaFormat[]\n > & {\n responseFormat: JsonSchemaFormat | JsonSchemaFormat[];\n middlewares?: TMiddlewares;\n }\n): ReactAgent<Record<string, unknown>, ContextSchema, TMiddlewares>;\n\n// Overload 5: With responseFormat as TypedToolStrategy (for union types from toolStrategy)\nexport function createAgent<\n T extends Record<string, any> = Record<string, any>,\n ContextSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = AnyAnnotationRoot,\n TMiddlewares extends readonly AgentMiddleware<\n any,\n any,\n any\n >[] = readonly AgentMiddleware<any, any, any>[]\n>(\n params: CreateAgentParams<T, ContextSchema, TypedToolStrategy<T>> & {\n responseFormat: TypedToolStrategy<T>;\n middlewares?: TMiddlewares;\n }\n): ReactAgent<T, ContextSchema, TMiddlewares>;\n\n// Overload 6: With responseFormat as single ToolStrategy instance\nexport function createAgent<\n T extends Record<string, any> = Record<string, any>,\n ContextSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = AnyAnnotationRoot,\n TMiddlewares extends readonly AgentMiddleware<\n any,\n any,\n any\n >[] = readonly AgentMiddleware<any, any, any>[]\n>(\n params: CreateAgentParams<T, ContextSchema, ToolStrategy<T>> & {\n responseFormat: ToolStrategy<T>;\n middlewares?: TMiddlewares;\n }\n): ReactAgent<T, ContextSchema, TMiddlewares>;\n\n// Overload 7: With responseFormat as ProviderStrategy\nexport function createAgent<\n T extends Record<string, any> = Record<string, any>,\n ContextSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = AnyAnnotationRoot,\n TMiddlewares extends readonly AgentMiddleware<\n any,\n any,\n any\n >[] = readonly AgentMiddleware<any, any, any>[]\n>(\n params: CreateAgentParams<T, ContextSchema, ProviderStrategy<T>> & {\n responseFormat: ProviderStrategy<T>;\n middlewares?: TMiddlewares;\n }\n): ReactAgent<T, ContextSchema, TMiddlewares>;\n\n// Overload 8: Without responseFormat property at all - with proper middleware state typing\nexport function createAgent<\n ContextSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = AnyAnnotationRoot,\n TMiddlewares extends readonly AgentMiddleware<\n any,\n any,\n any\n >[] = readonly AgentMiddleware<any, any, any>[]\n>(\n params: Omit<\n CreateAgentParams<ResponseFormatUndefined, ContextSchema, never>,\n \"responseFormat\"\n > & { middlewares?: TMiddlewares }\n): ReactAgent<ResponseFormatUndefined, ContextSchema, TMiddlewares>;\n\n// Overload 9: With responseFormat explicitly undefined\nexport function createAgent<\n ContextSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = AnyAnnotationRoot,\n TMiddlewares extends readonly AgentMiddleware<\n any,\n any,\n any\n >[] = readonly AgentMiddleware<any, any, any>[]\n>(\n params: Omit<\n CreateAgentParams<ResponseFormatUndefined, ContextSchema, never>,\n \"responseFormat\"\n > & {\n responseFormat?: undefined;\n middlewares?: TMiddlewares;\n }\n): ReactAgent<ResponseFormatUndefined, ContextSchema, TMiddlewares>;\n\n// Overload 10: For other ResponseFormat values (failsafe)\nexport function createAgent<\n StructuredResponseFormat extends Record<string, any> = Record<string, any>,\n ContextSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = AnyAnnotationRoot,\n TMiddlewares extends readonly AgentMiddleware<\n any,\n any,\n any\n >[] = readonly AgentMiddleware<any, any, any>[]\n>(\n params: CreateAgentParams<\n StructuredResponseFormat,\n ContextSchema,\n ResponseFormat\n > & {\n responseFormat: ResponseFormat;\n middlewares?: TMiddlewares;\n }\n): ReactAgent<StructuredResponseFormat, ContextSchema, TMiddlewares>;\n\n// Implementation\nexport function createAgent<\n StructuredResponseFormat extends Record<string, any>,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject,\n TMiddlewares extends readonly AgentMiddleware<any, any, any>[] = []\n>(\n params: CreateAgentParams<StructuredResponseFormat, ContextSchema, any>\n): ReactAgent<StructuredResponseFormat, ContextSchema, TMiddlewares> {\n return new ReactAgent(params);\n}\n\nexport { createMiddleware } from \"./middleware.js\";\n"],"mappings":";;;;AA4RA,SAAgB,YAKdA,QACmE;AACnE,QAAO,IAAI,WAAW;AACvB"}
1
+ {"version":3,"file":"index.js","names":["params: CreateAgentParams<StructuredResponseFormat, ContextSchema, any>"],"sources":["../../../src/agents/middlewareAgent/index.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport type {\n InteropZodObject,\n InteropZodType,\n} from \"@langchain/core/utils/types\";\n\nimport { type AnyAnnotationRoot } from \"../annotation.js\";\nimport type { CreateAgentParams, AgentMiddleware } from \"./types.js\";\nimport type { ExtractZodArrayTypes } from \"../types.js\";\nimport type {\n ToolStrategy,\n TypedToolStrategy,\n ProviderStrategy,\n ResponseFormat,\n ResponseFormatUndefined,\n JsonSchemaFormat,\n} from \"../responses.js\";\nimport { ReactAgent } from \"./ReactAgent.js\";\n\n/**\n * Creates a StateGraph agent that relies on a chat model utilizing tool calling.\n *\n * @example\n * ```ts\n * import { ChatOpenAI } from \"@langchain/openai\";\n * import { createAgent, tool } from \"langchain\";\n * import { z } from \"zod/v3\";\n *\n * const model = new ChatOpenAI({\n * model: \"gpt-4o\",\n * });\n *\n * const getWeather = tool((input) => {\n * if ([\"sf\", \"san francisco\"].includes(input.location.toLowerCase())) {\n * return \"It's 60 degrees and foggy.\";\n * } else {\n * return \"It's 90 degrees and sunny.\";\n * }\n * }, {\n * name: \"get_weather\",\n * description: \"Call to get the current weather.\",\n * schema: z.object({\n * location: z.string().describe(\"Location to get the weather for.\"),\n * })\n * })\n *\n * const agent = createAgent({ llm: model, tools: [getWeather] });\n *\n * const inputs = {\n * messages: [{ role: \"user\", content: \"what is the weather in SF?\" }],\n * };\n *\n * const stream = await agent.stream(inputs, { streamMode: \"values\" });\n *\n * for await (const { messages } of stream) {\n * console.log(messages);\n * }\n * // Returns the messages in the state at each step of execution\n * ```\n */\n// Overload 1: With responseFormat as single InteropZodType\nexport function createAgent<\n T extends Record<string, any> = Record<string, any>,\n ContextSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = AnyAnnotationRoot,\n TMiddleware extends readonly AgentMiddleware<\n any,\n any,\n any\n >[] = readonly AgentMiddleware<any, any, any>[]\n>(\n params: CreateAgentParams<T, ContextSchema, InteropZodType<T>> & {\n responseFormat: InteropZodType<T>;\n middleware?: TMiddleware;\n }\n): ReactAgent<T, ContextSchema, TMiddleware>;\n\n// Overload 2: With responseFormat as array of InteropZodTypes (infers union type)\nexport function createAgent<\n T extends readonly InteropZodType<any>[],\n ContextSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = AnyAnnotationRoot,\n TMiddleware extends readonly AgentMiddleware<\n any,\n any,\n any\n >[] = readonly AgentMiddleware<any, any, any>[]\n>(\n params: CreateAgentParams<\n ExtractZodArrayTypes<T> extends Record<string, any>\n ? ExtractZodArrayTypes<T>\n : Record<string, any>,\n ContextSchema,\n T\n > & {\n responseFormat: T;\n middleware?: TMiddleware;\n }\n): ReactAgent<\n ExtractZodArrayTypes<T> extends Record<string, any>\n ? ExtractZodArrayTypes<T>\n : Record<string, any>,\n ContextSchema,\n TMiddleware\n>;\n\n// Overload 3: With responseFormat as JsonSchemaFormat (JSON schema object)\nexport function createAgent<\n ContextSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = AnyAnnotationRoot,\n TMiddleware extends readonly AgentMiddleware<\n any,\n any,\n any\n >[] = readonly AgentMiddleware<any, any, any>[]\n>(\n params: CreateAgentParams<\n Record<string, unknown>,\n ContextSchema,\n JsonSchemaFormat\n > & {\n responseFormat: JsonSchemaFormat;\n middleware?: TMiddleware;\n }\n): ReactAgent<Record<string, unknown>, ContextSchema, TMiddleware>;\n\n// Overload 4: With responseFormat as array of JsonSchemaFormat (JSON schema objects)\nexport function createAgent<\n ContextSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = AnyAnnotationRoot,\n TMiddleware extends readonly AgentMiddleware<\n any,\n any,\n any\n >[] = readonly AgentMiddleware<any, any, any>[]\n>(\n params: CreateAgentParams<\n Record<string, unknown>,\n ContextSchema,\n JsonSchemaFormat[]\n > & {\n responseFormat: JsonSchemaFormat[];\n middleware?: TMiddleware;\n }\n): ReactAgent<Record<string, unknown>, ContextSchema, TMiddleware>;\n\n// Overload 4.5: With responseFormat as union of JsonSchemaFormat | JsonSchemaFormat[]\nexport function createAgent<\n ContextSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = AnyAnnotationRoot,\n TMiddleware extends readonly AgentMiddleware<\n any,\n any,\n any\n >[] = readonly AgentMiddleware<any, any, any>[]\n>(\n params: CreateAgentParams<\n Record<string, unknown>,\n ContextSchema,\n JsonSchemaFormat | JsonSchemaFormat[]\n > & {\n responseFormat: JsonSchemaFormat | JsonSchemaFormat[];\n middleware?: TMiddleware;\n }\n): ReactAgent<Record<string, unknown>, ContextSchema, TMiddleware>;\n\n// Overload 5: With responseFormat as TypedToolStrategy (for union types from toolStrategy)\nexport function createAgent<\n T extends Record<string, any> = Record<string, any>,\n ContextSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = AnyAnnotationRoot,\n TMiddleware extends readonly AgentMiddleware<\n any,\n any,\n any\n >[] = readonly AgentMiddleware<any, any, any>[]\n>(\n params: CreateAgentParams<T, ContextSchema, TypedToolStrategy<T>> & {\n responseFormat: TypedToolStrategy<T>;\n middleware?: TMiddleware;\n }\n): ReactAgent<T, ContextSchema, TMiddleware>;\n\n// Overload 6: With responseFormat as single ToolStrategy instance\nexport function createAgent<\n T extends Record<string, any> = Record<string, any>,\n ContextSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = AnyAnnotationRoot,\n TMiddleware extends readonly AgentMiddleware<\n any,\n any,\n any\n >[] = readonly AgentMiddleware<any, any, any>[]\n>(\n params: CreateAgentParams<T, ContextSchema, ToolStrategy<T>> & {\n responseFormat: ToolStrategy<T>;\n middleware?: TMiddleware;\n }\n): ReactAgent<T, ContextSchema, TMiddleware>;\n\n// Overload 7: With responseFormat as ProviderStrategy\nexport function createAgent<\n T extends Record<string, any> = Record<string, any>,\n ContextSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = AnyAnnotationRoot,\n TMiddleware extends readonly AgentMiddleware<\n any,\n any,\n any\n >[] = readonly AgentMiddleware<any, any, any>[]\n>(\n params: CreateAgentParams<T, ContextSchema, ProviderStrategy<T>> & {\n responseFormat: ProviderStrategy<T>;\n middleware?: TMiddleware;\n }\n): ReactAgent<T, ContextSchema, TMiddleware>;\n\n// Overload 8: Without responseFormat property at all - with proper middleware state typing\nexport function createAgent<\n ContextSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = AnyAnnotationRoot,\n TMiddleware extends readonly AgentMiddleware<\n any,\n any,\n any\n >[] = readonly AgentMiddleware<any, any, any>[]\n>(\n params: Omit<\n CreateAgentParams<ResponseFormatUndefined, ContextSchema, never>,\n \"responseFormat\"\n > & { middleware?: TMiddleware }\n): ReactAgent<ResponseFormatUndefined, ContextSchema, TMiddleware>;\n\n// Overload 9: With responseFormat explicitly undefined\nexport function createAgent<\n ContextSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = AnyAnnotationRoot,\n TMiddleware extends readonly AgentMiddleware<\n any,\n any,\n any\n >[] = readonly AgentMiddleware<any, any, any>[]\n>(\n params: Omit<\n CreateAgentParams<ResponseFormatUndefined, ContextSchema, never>,\n \"responseFormat\"\n > & {\n responseFormat?: undefined;\n middleware?: TMiddleware;\n }\n): ReactAgent<ResponseFormatUndefined, ContextSchema, TMiddleware>;\n\n// Overload 10: For other ResponseFormat values (failsafe)\nexport function createAgent<\n StructuredResponseFormat extends Record<string, any> = Record<string, any>,\n ContextSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = AnyAnnotationRoot,\n TMiddleware extends readonly AgentMiddleware<\n any,\n any,\n any\n >[] = readonly AgentMiddleware<any, any, any>[]\n>(\n params: CreateAgentParams<\n StructuredResponseFormat,\n ContextSchema,\n ResponseFormat\n > & {\n responseFormat: ResponseFormat;\n middleware?: TMiddleware;\n }\n): ReactAgent<StructuredResponseFormat, ContextSchema, TMiddleware>;\n\n// Implementation\nexport function createAgent<\n StructuredResponseFormat extends Record<string, any>,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject,\n TMiddleware extends readonly AgentMiddleware<any, any, any>[] = []\n>(\n params: CreateAgentParams<StructuredResponseFormat, ContextSchema, any>\n): ReactAgent<StructuredResponseFormat, ContextSchema, TMiddleware> {\n return new ReactAgent(params);\n}\n\nexport { createMiddleware } from \"./middleware.js\";\n"],"mappings":";;;;AA6RA,SAAgB,YAKdA,QACkE;AAClE,QAAO,IAAI,WAAW;AACvB"}