langchain 1.0.0-alpha.5 → 1.0.0-alpha.7

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 (405) 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 +2 -5
  4. package/dist/agents/ReactAgent.d.cts.map +1 -1
  5. package/dist/agents/ReactAgent.d.ts +2 -5
  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 +13 -8
  11. package/dist/agents/annotation.d.cts.map +1 -1
  12. package/dist/agents/annotation.d.ts +13 -8
  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 +50 -50
  20. package/dist/agents/index.d.cts.map +1 -1
  21. package/dist/agents/index.d.ts +50 -50
  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/interrupt.d.cts +14 -1
  26. package/dist/agents/interrupt.d.cts.map +1 -1
  27. package/dist/agents/interrupt.d.ts +14 -1
  28. package/dist/agents/interrupt.d.ts.map +1 -1
  29. package/dist/agents/middlewareAgent/ReactAgent.cjs +273 -66
  30. package/dist/agents/middlewareAgent/ReactAgent.cjs.map +1 -1
  31. package/dist/agents/middlewareAgent/ReactAgent.d.cts +102 -16
  32. package/dist/agents/middlewareAgent/ReactAgent.d.cts.map +1 -1
  33. package/dist/agents/middlewareAgent/ReactAgent.d.ts +102 -16
  34. package/dist/agents/middlewareAgent/ReactAgent.d.ts.map +1 -1
  35. package/dist/agents/middlewareAgent/ReactAgent.js +275 -68
  36. package/dist/agents/middlewareAgent/ReactAgent.js.map +1 -1
  37. package/dist/agents/middlewareAgent/annotation.cjs +12 -6
  38. package/dist/agents/middlewareAgent/annotation.cjs.map +1 -1
  39. package/dist/agents/middlewareAgent/annotation.js +12 -6
  40. package/dist/agents/middlewareAgent/annotation.js.map +1 -1
  41. package/dist/agents/middlewareAgent/constants.d.cts +5 -0
  42. package/dist/agents/middlewareAgent/constants.d.cts.map +1 -0
  43. package/dist/agents/middlewareAgent/constants.d.ts +5 -0
  44. package/dist/agents/middlewareAgent/constants.d.ts.map +1 -0
  45. package/dist/agents/middlewareAgent/index.cjs.map +1 -1
  46. package/dist/agents/middlewareAgent/index.js.map +1 -1
  47. package/dist/agents/middlewareAgent/middleware/bigTool.cjs +162 -0
  48. package/dist/agents/middlewareAgent/middleware/bigTool.cjs.map +1 -0
  49. package/dist/agents/middlewareAgent/middleware/bigTool.d.cts +113 -0
  50. package/dist/agents/middlewareAgent/middleware/bigTool.d.cts.map +1 -0
  51. package/dist/agents/middlewareAgent/middleware/bigTool.d.ts +113 -0
  52. package/dist/agents/middlewareAgent/middleware/bigTool.d.ts.map +1 -0
  53. package/dist/agents/middlewareAgent/middleware/bigTool.js +161 -0
  54. package/dist/agents/middlewareAgent/middleware/bigTool.js.map +1 -0
  55. package/dist/agents/middlewareAgent/middleware/dynamicSystemPrompt.cjs +58 -0
  56. package/dist/agents/middlewareAgent/middleware/dynamicSystemPrompt.cjs.map +1 -0
  57. package/dist/agents/middlewareAgent/middleware/dynamicSystemPrompt.d.cts +46 -0
  58. package/dist/agents/middlewareAgent/middleware/dynamicSystemPrompt.d.cts.map +1 -0
  59. package/dist/agents/middlewareAgent/middleware/dynamicSystemPrompt.d.ts +46 -0
  60. package/dist/agents/middlewareAgent/middleware/dynamicSystemPrompt.d.ts.map +1 -0
  61. package/dist/agents/middlewareAgent/middleware/dynamicSystemPrompt.js +58 -0
  62. package/dist/agents/middlewareAgent/middleware/dynamicSystemPrompt.js.map +1 -0
  63. package/dist/agents/middlewareAgent/middleware/hitl.cjs +311 -0
  64. package/dist/agents/middlewareAgent/middleware/hitl.cjs.map +1 -0
  65. package/dist/agents/middlewareAgent/middleware/hitl.d.cts +419 -0
  66. package/dist/agents/middlewareAgent/middleware/hitl.d.cts.map +1 -0
  67. package/dist/agents/middlewareAgent/middleware/hitl.d.ts +419 -0
  68. package/dist/agents/middlewareAgent/middleware/hitl.d.ts.map +1 -0
  69. package/dist/agents/middlewareAgent/middleware/hitl.js +310 -0
  70. package/dist/agents/middlewareAgent/middleware/hitl.js.map +1 -0
  71. package/dist/agents/middlewareAgent/middleware/index.cjs +32 -0
  72. package/dist/agents/middlewareAgent/middleware/index.cjs.map +1 -0
  73. package/dist/agents/middlewareAgent/middleware/index.d.cts +6 -0
  74. package/dist/agents/middlewareAgent/middleware/index.d.ts +6 -0
  75. package/dist/agents/middlewareAgent/middleware/index.js +21 -0
  76. package/dist/agents/middlewareAgent/middleware/index.js.map +1 -0
  77. package/dist/agents/middlewareAgent/{middlewares → middleware}/promptCaching.cjs +72 -27
  78. package/dist/agents/middlewareAgent/middleware/promptCaching.cjs.map +1 -0
  79. package/dist/agents/middlewareAgent/{middlewares → middleware}/promptCaching.d.cts +60 -15
  80. package/dist/agents/middlewareAgent/middleware/promptCaching.d.cts.map +1 -0
  81. package/dist/agents/middlewareAgent/{middlewares → middleware}/promptCaching.d.ts +60 -15
  82. package/dist/agents/middlewareAgent/middleware/promptCaching.d.ts.map +1 -0
  83. package/dist/agents/middlewareAgent/{middlewares → middleware}/promptCaching.js +71 -26
  84. package/dist/agents/middlewareAgent/middleware/promptCaching.js.map +1 -0
  85. package/dist/agents/middlewareAgent/{middlewares → middleware}/summarization.cjs +35 -23
  86. package/dist/agents/middlewareAgent/middleware/summarization.cjs.map +1 -0
  87. package/dist/agents/middlewareAgent/{middlewares → middleware}/summarization.d.cts +7 -5
  88. package/dist/agents/middlewareAgent/middleware/summarization.d.cts.map +1 -0
  89. package/dist/agents/middlewareAgent/{middlewares → middleware}/summarization.d.ts +7 -5
  90. package/dist/agents/middlewareAgent/middleware/summarization.d.ts.map +1 -0
  91. package/dist/agents/middlewareAgent/{middlewares → middleware}/summarization.js +29 -17
  92. package/dist/agents/middlewareAgent/middleware/summarization.js.map +1 -0
  93. package/dist/agents/middlewareAgent/middleware.cjs +8 -5
  94. package/dist/agents/middlewareAgent/middleware.cjs.map +1 -1
  95. package/dist/agents/middlewareAgent/middleware.d.cts +67 -7
  96. package/dist/agents/middlewareAgent/middleware.d.cts.map +1 -1
  97. package/dist/agents/middlewareAgent/middleware.d.ts +67 -7
  98. package/dist/agents/middlewareAgent/middleware.d.ts.map +1 -1
  99. package/dist/agents/middlewareAgent/middleware.js +8 -5
  100. package/dist/agents/middlewareAgent/middleware.js.map +1 -1
  101. package/dist/agents/middlewareAgent/nodes/AfterModalNode.cjs +2 -2
  102. package/dist/agents/middlewareAgent/nodes/AfterModalNode.cjs.map +1 -1
  103. package/dist/agents/middlewareAgent/nodes/AfterModalNode.js +2 -2
  104. package/dist/agents/middlewareAgent/nodes/AfterModalNode.js.map +1 -1
  105. package/dist/agents/middlewareAgent/nodes/AgentNode.cjs +125 -83
  106. package/dist/agents/middlewareAgent/nodes/AgentNode.cjs.map +1 -1
  107. package/dist/agents/middlewareAgent/nodes/AgentNode.js +128 -86
  108. package/dist/agents/middlewareAgent/nodes/AgentNode.js.map +1 -1
  109. package/dist/agents/middlewareAgent/nodes/BeforeModalNode.cjs +2 -2
  110. package/dist/agents/middlewareAgent/nodes/BeforeModalNode.cjs.map +1 -1
  111. package/dist/agents/middlewareAgent/nodes/BeforeModalNode.js +2 -2
  112. package/dist/agents/middlewareAgent/nodes/BeforeModalNode.js.map +1 -1
  113. package/dist/agents/middlewareAgent/nodes/middleware.cjs +42 -17
  114. package/dist/agents/middlewareAgent/nodes/middleware.cjs.map +1 -1
  115. package/dist/agents/middlewareAgent/nodes/middleware.js +42 -18
  116. package/dist/agents/middlewareAgent/nodes/middleware.js.map +1 -1
  117. package/dist/agents/middlewareAgent/nodes/utils.cjs +30 -16
  118. package/dist/agents/middlewareAgent/nodes/utils.cjs.map +1 -1
  119. package/dist/agents/middlewareAgent/nodes/utils.js +28 -14
  120. package/dist/agents/middlewareAgent/nodes/utils.js.map +1 -1
  121. package/dist/agents/middlewareAgent/types.d.cts +162 -88
  122. package/dist/agents/middlewareAgent/types.d.cts.map +1 -1
  123. package/dist/agents/middlewareAgent/types.d.ts +162 -88
  124. package/dist/agents/middlewareAgent/types.d.ts.map +1 -1
  125. package/dist/agents/model.cjs +13 -0
  126. package/dist/agents/model.cjs.map +1 -0
  127. package/dist/agents/model.js +11 -0
  128. package/dist/agents/model.js.map +1 -0
  129. package/dist/agents/nodes/AgentNode.cjs +60 -32
  130. package/dist/agents/nodes/AgentNode.cjs.map +1 -1
  131. package/dist/agents/nodes/AgentNode.js +61 -33
  132. package/dist/agents/nodes/AgentNode.js.map +1 -1
  133. package/dist/agents/nodes/ToolNode.cjs +4 -4
  134. package/dist/agents/nodes/ToolNode.cjs.map +1 -1
  135. package/dist/agents/nodes/ToolNode.d.cts +2 -3
  136. package/dist/agents/nodes/ToolNode.d.cts.map +1 -1
  137. package/dist/agents/nodes/ToolNode.d.ts +1 -2
  138. package/dist/agents/nodes/ToolNode.d.ts.map +1 -1
  139. package/dist/agents/nodes/ToolNode.js +5 -5
  140. package/dist/agents/nodes/ToolNode.js.map +1 -1
  141. package/dist/agents/responses.cjs +53 -11
  142. package/dist/agents/responses.cjs.map +1 -1
  143. package/dist/agents/responses.d.cts +12 -20
  144. package/dist/agents/responses.d.cts.map +1 -1
  145. package/dist/agents/responses.d.ts +12 -20
  146. package/dist/agents/responses.d.ts.map +1 -1
  147. package/dist/agents/responses.js +53 -12
  148. package/dist/agents/responses.js.map +1 -1
  149. package/dist/agents/types.d.cts +3 -6
  150. package/dist/agents/types.d.cts.map +1 -1
  151. package/dist/agents/types.d.ts +3 -6
  152. package/dist/agents/types.d.ts.map +1 -1
  153. package/dist/agents/utils.cjs +11 -29
  154. package/dist/agents/utils.cjs.map +1 -1
  155. package/dist/agents/utils.js +9 -26
  156. package/dist/agents/utils.js.map +1 -1
  157. package/dist/agents/withAgentName.cjs.map +1 -1
  158. package/dist/agents/withAgentName.js.map +1 -1
  159. package/dist/chains/api/prompts.cjs.map +1 -1
  160. package/dist/chains/api/prompts.js.map +1 -1
  161. package/dist/chains/constitutional_ai/constitutional_chain.cjs.map +1 -1
  162. package/dist/chains/constitutional_ai/constitutional_chain.js.map +1 -1
  163. package/dist/chains/index.cjs +0 -3
  164. package/dist/chains/index.cjs.map +1 -1
  165. package/dist/chains/index.d.cts +1 -2
  166. package/dist/chains/index.d.ts +1 -2
  167. package/dist/chains/index.js +1 -3
  168. package/dist/chains/index.js.map +1 -1
  169. package/dist/chains/openai_functions/extraction.cjs.map +1 -1
  170. package/dist/chains/openai_functions/extraction.d.cts +1 -3
  171. package/dist/chains/openai_functions/extraction.d.cts.map +1 -1
  172. package/dist/chains/openai_functions/extraction.d.ts +1 -3
  173. package/dist/chains/openai_functions/extraction.d.ts.map +1 -1
  174. package/dist/chains/openai_functions/extraction.js.map +1 -1
  175. package/dist/chains/openai_functions/index.cjs +0 -5
  176. package/dist/chains/openai_functions/index.cjs.map +1 -1
  177. package/dist/chains/openai_functions/index.d.cts +1 -2
  178. package/dist/chains/openai_functions/index.d.ts +1 -2
  179. package/dist/chains/openai_functions/index.js +1 -4
  180. package/dist/chains/openai_functions/index.js.map +1 -1
  181. package/dist/chains/openai_functions/openapi.cjs +4 -4
  182. package/dist/chains/openai_functions/openapi.cjs.map +1 -1
  183. package/dist/chains/openai_functions/openapi.d.cts +1 -1
  184. package/dist/chains/openai_functions/openapi.js +4 -4
  185. package/dist/chains/openai_functions/openapi.js.map +1 -1
  186. package/dist/chains/openai_functions/tagging.cjs.map +1 -1
  187. package/dist/chains/openai_functions/tagging.d.cts +1 -3
  188. package/dist/chains/openai_functions/tagging.d.cts.map +1 -1
  189. package/dist/chains/openai_functions/tagging.d.ts +1 -3
  190. package/dist/chains/openai_functions/tagging.d.ts.map +1 -1
  191. package/dist/chains/openai_functions/tagging.js.map +1 -1
  192. package/dist/chains/query_constructor/index.cjs +4 -4
  193. package/dist/chains/query_constructor/index.cjs.map +1 -1
  194. package/dist/chains/query_constructor/index.d.cts +4 -2
  195. package/dist/chains/query_constructor/index.d.cts.map +1 -1
  196. package/dist/chains/query_constructor/index.d.ts +4 -2
  197. package/dist/chains/query_constructor/index.d.ts.map +1 -1
  198. package/dist/chains/query_constructor/index.js +1 -1
  199. package/dist/chains/query_constructor/index.js.map +1 -1
  200. package/dist/chains/question_answering/load.d.ts +2 -2
  201. package/dist/chains/question_answering/load.d.ts.map +1 -1
  202. package/dist/chains/question_answering/map_reduce_prompts.cjs.map +1 -1
  203. package/dist/chains/question_answering/map_reduce_prompts.js.map +1 -1
  204. package/dist/chains/question_answering/refine_prompts.cjs.map +1 -1
  205. package/dist/chains/question_answering/refine_prompts.js.map +1 -1
  206. package/dist/chains/question_answering/stuff_prompts.cjs.map +1 -1
  207. package/dist/chains/question_answering/stuff_prompts.js.map +1 -1
  208. package/dist/chains/router/multi_prompt.cjs +4 -4
  209. package/dist/chains/router/multi_prompt.cjs.map +1 -1
  210. package/dist/chains/router/multi_prompt.js +1 -1
  211. package/dist/chains/router/multi_prompt.js.map +1 -1
  212. package/dist/chains/router/multi_retrieval_qa.cjs +4 -4
  213. package/dist/chains/router/multi_retrieval_qa.cjs.map +1 -1
  214. package/dist/chains/router/multi_retrieval_qa.js +1 -1
  215. package/dist/chains/router/multi_retrieval_qa.js.map +1 -1
  216. package/dist/chains/sql_db/sql_db_prompt.cjs.map +1 -1
  217. package/dist/chains/sql_db/sql_db_prompt.d.cts.map +1 -1
  218. package/dist/chains/sql_db/sql_db_prompt.d.ts.map +1 -1
  219. package/dist/chains/sql_db/sql_db_prompt.js.map +1 -1
  220. package/dist/chains/summarization/stuff_prompts.cjs.map +1 -1
  221. package/dist/chains/summarization/stuff_prompts.js.map +1 -1
  222. package/dist/chat_models/universal.cjs +8 -5
  223. package/dist/chat_models/universal.cjs.map +1 -1
  224. package/dist/chat_models/universal.d.cts +2 -2
  225. package/dist/chat_models/universal.d.cts.map +1 -1
  226. package/dist/chat_models/universal.d.ts +2 -2
  227. package/dist/chat_models/universal.d.ts.map +1 -1
  228. package/dist/chat_models/universal.js +8 -5
  229. package/dist/chat_models/universal.js.map +1 -1
  230. package/dist/document_loaders/fs/directory.cjs.map +1 -1
  231. package/dist/document_loaders/fs/directory.d.cts +0 -1
  232. package/dist/document_loaders/fs/directory.d.cts.map +1 -1
  233. package/dist/document_loaders/fs/directory.d.ts +0 -1
  234. package/dist/document_loaders/fs/directory.d.ts.map +1 -1
  235. package/dist/document_loaders/fs/directory.js.map +1 -1
  236. package/dist/document_loaders/fs/json.cjs +7 -1
  237. package/dist/document_loaders/fs/json.cjs.map +1 -1
  238. package/dist/document_loaders/fs/json.js +7 -1
  239. package/dist/document_loaders/fs/json.js.map +1 -1
  240. package/dist/embeddings/cache_backed.cjs +1 -1
  241. package/dist/embeddings/cache_backed.cjs.map +1 -1
  242. package/dist/embeddings/cache_backed.d.cts +1 -1
  243. package/dist/embeddings/cache_backed.d.ts +2 -2
  244. package/dist/embeddings/cache_backed.js +2 -2
  245. package/dist/embeddings/cache_backed.js.map +1 -1
  246. package/dist/evaluation/agents/trajectory.d.cts.map +1 -1
  247. package/dist/evaluation/comparison/pairwise.d.cts.map +1 -1
  248. package/dist/evaluation/criteria/criteria.d.cts.map +1 -1
  249. package/dist/evaluation/embedding_distance/base.cjs +2 -4
  250. package/dist/evaluation/embedding_distance/base.cjs.map +1 -1
  251. package/dist/evaluation/embedding_distance/base.js +2 -3
  252. package/dist/evaluation/embedding_distance/base.js.map +1 -1
  253. package/dist/evaluation/loader.cjs +7 -12
  254. package/dist/evaluation/loader.cjs.map +1 -1
  255. package/dist/evaluation/loader.d.cts +8 -2
  256. package/dist/evaluation/loader.d.cts.map +1 -1
  257. package/dist/evaluation/loader.d.ts +8 -2
  258. package/dist/evaluation/loader.d.ts.map +1 -1
  259. package/dist/evaluation/loader.js +7 -12
  260. package/dist/evaluation/loader.js.map +1 -1
  261. package/dist/hub/base.cjs.map +1 -1
  262. package/dist/hub/base.js.map +1 -1
  263. package/dist/index.cjs +38 -6
  264. package/dist/index.cjs.map +1 -1
  265. package/dist/index.d.cts +11 -4
  266. package/dist/index.d.ts +11 -4
  267. package/dist/index.js +18 -4
  268. package/dist/index.js.map +1 -1
  269. package/dist/langchain-core/dist/load/serializable.d.cts.map +1 -1
  270. package/dist/langchain-core/dist/messages/base.d.cts +24 -33
  271. package/dist/langchain-core/dist/messages/base.d.cts.map +1 -1
  272. package/dist/langchain-core/dist/messages/content/index.d.cts +21 -2
  273. package/dist/langchain-core/dist/messages/content/index.d.cts.map +1 -1
  274. package/dist/langchain-core/dist/messages/content/tools.d.cts +67 -6
  275. package/dist/langchain-core/dist/messages/content/tools.d.cts.map +1 -1
  276. package/dist/langchain-core/dist/messages/message.d.cts +598 -0
  277. package/dist/langchain-core/dist/messages/message.d.cts.map +1 -0
  278. package/dist/langchain-core/dist/messages/metadata.d.cts +97 -0
  279. package/dist/langchain-core/dist/messages/metadata.d.cts.map +1 -0
  280. package/dist/langchain-core/dist/messages/utils.d.cts +75 -0
  281. package/dist/langchain-core/dist/messages/utils.d.cts.map +1 -0
  282. package/dist/langchain-core/dist/prompt_values.d.cts.map +1 -1
  283. package/dist/langchain-core/dist/utils/types/index.d.cts.map +1 -1
  284. package/dist/libs/langchain-core/dist/load/serializable.d.ts.map +1 -1
  285. package/dist/libs/langchain-core/dist/messages/base.d.ts +24 -33
  286. package/dist/libs/langchain-core/dist/messages/base.d.ts.map +1 -1
  287. package/dist/libs/langchain-core/dist/messages/content/index.d.ts +21 -2
  288. package/dist/libs/langchain-core/dist/messages/content/index.d.ts.map +1 -1
  289. package/dist/libs/langchain-core/dist/messages/content/tools.d.ts +67 -6
  290. package/dist/libs/langchain-core/dist/messages/content/tools.d.ts.map +1 -1
  291. package/dist/libs/langchain-core/dist/messages/message.d.ts +598 -0
  292. package/dist/libs/langchain-core/dist/messages/message.d.ts.map +1 -0
  293. package/dist/libs/langchain-core/dist/messages/metadata.d.ts +97 -0
  294. package/dist/libs/langchain-core/dist/messages/metadata.d.ts.map +1 -0
  295. package/dist/libs/langchain-core/dist/messages/utils.d.ts +75 -0
  296. package/dist/libs/langchain-core/dist/messages/utils.d.ts.map +1 -0
  297. package/dist/libs/langchain-core/dist/prompt_values.d.ts.map +1 -1
  298. package/dist/libs/langchain-core/dist/utils/types/index.d.ts +2 -0
  299. package/dist/libs/langchain-core/dist/utils/types/index.d.ts.map +1 -1
  300. package/dist/libs/langchain-core/dist/utils/types/zod.d.ts +1 -0
  301. package/dist/load/import_map.cjs +3 -14
  302. package/dist/load/import_map.cjs.map +1 -1
  303. package/dist/load/import_map.js +3 -14
  304. package/dist/load/import_map.js.map +1 -1
  305. package/dist/memory/prompt.cjs.map +1 -1
  306. package/dist/memory/prompt.d.cts.map +1 -1
  307. package/dist/memory/prompt.d.ts.map +1 -1
  308. package/dist/memory/prompt.js.map +1 -1
  309. package/dist/output_parsers/combining.cjs +1 -1
  310. package/dist/output_parsers/combining.cjs.map +1 -1
  311. package/dist/output_parsers/combining.js +1 -1
  312. package/dist/output_parsers/combining.js.map +1 -1
  313. package/dist/output_parsers/expression_type_handlers/array_literal_expression_handler.cjs.map +1 -1
  314. package/dist/output_parsers/expression_type_handlers/array_literal_expression_handler.js.map +1 -1
  315. package/dist/output_parsers/expression_type_handlers/base.cjs +1 -1
  316. package/dist/output_parsers/expression_type_handlers/base.cjs.map +1 -1
  317. package/dist/output_parsers/expression_type_handlers/base.js +1 -1
  318. package/dist/output_parsers/expression_type_handlers/base.js.map +1 -1
  319. package/dist/output_parsers/regex.cjs.map +1 -1
  320. package/dist/output_parsers/regex.js.map +1 -1
  321. package/dist/output_parsers/structured.cjs +4 -4
  322. package/dist/output_parsers/structured.cjs.map +1 -1
  323. package/dist/output_parsers/structured.d.cts +1 -1
  324. package/dist/output_parsers/structured.d.cts.map +1 -1
  325. package/dist/output_parsers/structured.d.ts +1 -1
  326. package/dist/output_parsers/structured.d.ts.map +1 -1
  327. package/dist/output_parsers/structured.js +2 -2
  328. package/dist/output_parsers/structured.js.map +1 -1
  329. package/dist/retrievers/ensemble.cjs.map +1 -1
  330. package/dist/retrievers/ensemble.js.map +1 -1
  331. package/dist/storage/file_system.cjs +1 -1
  332. package/dist/storage/file_system.cjs.map +1 -1
  333. package/dist/storage/file_system.js +1 -1
  334. package/dist/storage/file_system.js.map +1 -1
  335. package/dist/tools/fs.cjs +5 -5
  336. package/dist/tools/fs.cjs.map +1 -1
  337. package/dist/tools/fs.d.cts +1 -1
  338. package/dist/tools/fs.d.cts.map +1 -1
  339. package/dist/tools/fs.d.ts +1 -1
  340. package/dist/tools/fs.d.ts.map +1 -1
  341. package/dist/tools/fs.js +1 -1
  342. package/dist/tools/fs.js.map +1 -1
  343. package/dist/tools/retriever.cjs +2 -2
  344. package/dist/tools/retriever.cjs.map +1 -1
  345. package/dist/tools/retriever.d.cts +1 -1
  346. package/dist/tools/retriever.d.cts.map +1 -1
  347. package/dist/tools/retriever.d.ts +1 -1
  348. package/dist/tools/retriever.d.ts.map +1 -1
  349. package/dist/tools/retriever.js +1 -1
  350. package/dist/tools/retriever.js.map +1 -1
  351. package/dist/tools/sql.cjs +1 -2
  352. package/dist/tools/sql.cjs.map +1 -1
  353. package/dist/tools/sql.d.cts +1 -1
  354. package/dist/tools/sql.d.cts.map +1 -1
  355. package/dist/tools/sql.d.ts +1 -1
  356. package/dist/tools/sql.d.ts.map +1 -1
  357. package/dist/tools/sql.js +1 -2
  358. package/dist/tools/sql.js.map +1 -1
  359. package/dist/types/expression-parser.d.cts +2 -0
  360. package/dist/types/expression-parser.d.cts.map +1 -1
  361. package/dist/types/expression-parser.d.ts +2 -0
  362. package/dist/types/expression-parser.d.ts.map +1 -1
  363. package/dist/util/hub.cjs +1 -1
  364. package/dist/util/hub.js +1 -1
  365. package/dist/util/openapi.cjs +1 -1
  366. package/dist/util/openapi.cjs.map +1 -1
  367. package/dist/util/openapi.js +1 -1
  368. package/dist/util/openapi.js.map +1 -1
  369. package/package.json +15 -21
  370. package/dist/agents/middlewareAgent/middlewares/hitl.cjs +0 -235
  371. package/dist/agents/middlewareAgent/middlewares/hitl.cjs.map +0 -1
  372. package/dist/agents/middlewareAgent/middlewares/hitl.d.cts +0 -199
  373. package/dist/agents/middlewareAgent/middlewares/hitl.d.cts.map +0 -1
  374. package/dist/agents/middlewareAgent/middlewares/hitl.d.ts +0 -199
  375. package/dist/agents/middlewareAgent/middlewares/hitl.d.ts.map +0 -1
  376. package/dist/agents/middlewareAgent/middlewares/hitl.js +0 -234
  377. package/dist/agents/middlewareAgent/middlewares/hitl.js.map +0 -1
  378. package/dist/agents/middlewareAgent/middlewares/index.cjs +0 -8
  379. package/dist/agents/middlewareAgent/middlewares/index.d.cts +0 -4
  380. package/dist/agents/middlewareAgent/middlewares/index.d.ts +0 -4
  381. package/dist/agents/middlewareAgent/middlewares/index.js +0 -5
  382. package/dist/agents/middlewareAgent/middlewares/promptCaching.cjs.map +0 -1
  383. package/dist/agents/middlewareAgent/middlewares/promptCaching.d.cts.map +0 -1
  384. package/dist/agents/middlewareAgent/middlewares/promptCaching.d.ts.map +0 -1
  385. package/dist/agents/middlewareAgent/middlewares/promptCaching.js.map +0 -1
  386. package/dist/agents/middlewareAgent/middlewares/summarization.cjs.map +0 -1
  387. package/dist/agents/middlewareAgent/middlewares/summarization.d.cts.map +0 -1
  388. package/dist/agents/middlewareAgent/middlewares/summarization.d.ts.map +0 -1
  389. package/dist/agents/middlewareAgent/middlewares/summarization.js.map +0 -1
  390. package/dist/chains/openai_functions/structured_output.cjs +0 -107
  391. package/dist/chains/openai_functions/structured_output.cjs.map +0 -1
  392. package/dist/chains/openai_functions/structured_output.d.cts +0 -38
  393. package/dist/chains/openai_functions/structured_output.d.cts.map +0 -1
  394. package/dist/chains/openai_functions/structured_output.d.ts +0 -38
  395. package/dist/chains/openai_functions/structured_output.d.ts.map +0 -1
  396. package/dist/chains/openai_functions/structured_output.js +0 -105
  397. package/dist/chains/openai_functions/structured_output.js.map +0 -1
  398. package/dist/chains/openai_moderation.cjs +0 -107
  399. package/dist/chains/openai_moderation.cjs.map +0 -1
  400. package/dist/chains/openai_moderation.d.cts +0 -74
  401. package/dist/chains/openai_moderation.d.cts.map +0 -1
  402. package/dist/chains/openai_moderation.d.ts +0 -74
  403. package/dist/chains/openai_moderation.d.ts.map +0 -1
  404. package/dist/chains/openai_moderation.js +0 -106
  405. package/dist/chains/openai_moderation.js.map +0 -1
@@ -1,5 +1,6 @@
1
- import { AgentBuiltInState, AgentMiddleware, Controls, MiddlewareResult, ModelRequest, Runtime } from "./types.cjs";
2
- import { z } from "zod";
1
+ import { ClientTool, ServerTool } from "../types.cjs";
2
+ import { AgentBuiltInState, AgentMiddleware, JumpToTarget, MiddlewareResult, ModelRequest, Runtime } from "./types.cjs";
3
+ import { InferInteropZodInput, InferInteropZodOutput, InteropZodDefault, InteropZodObject, InteropZodOptional } from "@langchain/core/utils/types";
3
4
 
4
5
  //#region src/agents/middlewareAgent/middleware.d.ts
5
6
 
@@ -10,7 +11,7 @@ import { z } from "zod";
10
11
  * @param config.name - The name of the middleware
11
12
  * @param config.stateSchema - The schema of the middleware state
12
13
  * @param config.contextSchema - The schema of the middleware context
13
- * @param config.prepareModelRequest - The function to prepare the model request
14
+ * @param config.modifyModelRequest - The function to prepare the model request
14
15
  * @param config.beforeModel - The function to run before the model call
15
16
  * @param config.afterModel - The function to run after the model call
16
17
  * @returns A middleware instance
@@ -33,13 +34,72 @@ import { z } from "zod";
33
34
  * });
34
35
  * ```
35
36
  */
36
- declare function createMiddleware<TSchema extends z.ZodObject<any> | undefined = undefined, TContextSchema extends z.ZodObject<any> | undefined = undefined>(config: {
37
+ declare function createMiddleware<TSchema extends InteropZodObject | undefined = undefined, TContextSchema extends InteropZodObject | InteropZodOptional<InteropZodObject> | InteropZodDefault<InteropZodObject> | undefined = undefined>(config: {
38
+ /**
39
+ * The name of the middleware
40
+ */
37
41
  name: string;
42
+ /**
43
+ * The schema of the middleware state. Middleware state is persisted between multiple invocations. It can be either:
44
+ * - A Zod object
45
+ * - A Zod optional object
46
+ * - A Zod default object
47
+ * - Undefined
48
+ */
38
49
  stateSchema?: TSchema;
50
+ /**
51
+ * The schema of the middleware context. Middleware context is read-only and not persisted between multiple invocations. It can be either:
52
+ * - A Zod object
53
+ * - A Zod optional object
54
+ * - A Zod default object
55
+ * - Undefined
56
+ */
39
57
  contextSchema?: TContextSchema;
40
- prepareModelRequest?: (options: ModelRequest, state: (TSchema extends z.ZodObject<any> ? z.infer<TSchema> : {}) & AgentBuiltInState, runtime: Runtime<TContextSchema extends z.ZodObject<any> ? z.infer<TContextSchema> : {}>) => Promise<ModelRequest | void> | ModelRequest | void;
41
- beforeModel?: (state: (TSchema extends z.ZodObject<any> ? z.infer<TSchema> : {}) & AgentBuiltInState, runtime: Runtime<TContextSchema extends z.ZodObject<any> ? z.infer<TContextSchema> : {}>, controls: Controls<(TSchema extends z.ZodObject<any> ? z.infer<TSchema> : {}) & AgentBuiltInState>) => Promise<MiddlewareResult<Partial<TSchema extends z.ZodObject<any> ? z.infer<TSchema> : {}>>> | MiddlewareResult<Partial<TSchema extends z.ZodObject<any> ? z.infer<TSchema> : {}>>;
42
- afterModel?: (state: (TSchema extends z.ZodObject<any> ? z.infer<TSchema> : {}) & AgentBuiltInState, runtime: Runtime<TContextSchema extends z.ZodObject<any> ? z.infer<TContextSchema> : {}>, controls: Controls<(TSchema extends z.ZodObject<any> ? z.infer<TSchema> : {}) & AgentBuiltInState>) => Promise<MiddlewareResult<Partial<TSchema extends z.ZodObject<any> ? z.infer<TSchema> : {}>>> | MiddlewareResult<Partial<TSchema extends z.ZodObject<any> ? z.infer<TSchema> : {}>>;
58
+ /**
59
+ * Explitictly defines which targets are allowed to be jumped to from the `beforeModel` hook.
60
+ */
61
+ beforeModelJumpTo?: JumpToTarget[];
62
+ /**
63
+ * Explitictly defines which targets are allowed to be jumped to from the `afterModel` hook.
64
+ */
65
+ afterModelJumpTo?: JumpToTarget[];
66
+ /**
67
+ * Additional tools registered by the middleware.
68
+ */
69
+ tools?: (ClientTool | ServerTool)[];
70
+ /**
71
+ * The function to modify the model request. This function is called after the `beforeModel` hook of this middleware and before the model is invoked.
72
+ * It allows to modify the model request before it is passed to the model.
73
+ *
74
+ * @param request - The model request
75
+ * @param request.model - The model to use for this step.
76
+ * @param request.messages - The messages to send to the model.
77
+ * @param request.systemPrompt - The system message for this step.
78
+ * @param request.toolChoice - The tool choice configuration for this step.
79
+ * @param request.tools - The tools to make available for this step.
80
+ * @param state - The middleware state
81
+ * @param runtime - The middleware runtime
82
+ * @returns The modified model request or undefined to pass through
83
+ */
84
+ modifyModelRequest?: (options: ModelRequest, state: (TSchema extends InteropZodObject ? InferInteropZodInput<TSchema> : {}) & AgentBuiltInState, runtime: Runtime<(TSchema extends InteropZodObject ? InferInteropZodInput<TSchema> : {}) & AgentBuiltInState, TContextSchema extends InteropZodObject ? InferInteropZodOutput<TContextSchema> : TContextSchema extends InteropZodDefault<any> ? InferInteropZodOutput<TContextSchema> : TContextSchema extends InteropZodOptional<any> ? Partial<InferInteropZodOutput<TContextSchema>> : never>) => Promise<ModelRequest | void> | ModelRequest | void;
85
+ /**
86
+ * The function to run before the model call. This function is called before the model is invoked and before the `modifyModelRequest` hook.
87
+ * It allows to modify the state of the agent.
88
+ *
89
+ * @param state - The middleware state
90
+ * @param runtime - The middleware runtime
91
+ * @returns The modified middleware state or undefined to pass through
92
+ */
93
+ beforeModel?: (state: (TSchema extends InteropZodObject ? InferInteropZodInput<TSchema> : {}) & AgentBuiltInState, runtime: Runtime<(TSchema extends InteropZodObject ? InferInteropZodInput<TSchema> : {}) & AgentBuiltInState, TContextSchema extends InteropZodObject ? InferInteropZodOutput<TContextSchema> : TContextSchema extends InteropZodDefault<any> ? InferInteropZodOutput<TContextSchema> : TContextSchema extends InteropZodOptional<any> ? Partial<InferInteropZodOutput<TContextSchema>> : never>) => Promise<MiddlewareResult<Partial<TSchema extends InteropZodObject ? InferInteropZodInput<TSchema> : {}>>> | MiddlewareResult<Partial<TSchema extends InteropZodObject ? InferInteropZodInput<TSchema> : {}>>;
94
+ /**
95
+ * The function to run after the model call. This function is called after the model is invoked and before any tools are called.
96
+ * It allows to modify the state of the agent after the model is invoked, e.g. to update tool call parameters.
97
+ *
98
+ * @param state - The middleware state
99
+ * @param runtime - The middleware runtime
100
+ * @returns The modified middleware state or undefined to pass through
101
+ */
102
+ afterModel?: (state: (TSchema extends InteropZodObject ? InferInteropZodInput<TSchema> : {}) & AgentBuiltInState, runtime: Runtime<(TSchema extends InteropZodObject ? InferInteropZodInput<TSchema> : {}) & AgentBuiltInState, TContextSchema extends InteropZodObject ? InferInteropZodOutput<TContextSchema> : TContextSchema extends InteropZodDefault<any> ? InferInteropZodOutput<TContextSchema> : TContextSchema extends InteropZodOptional<any> ? Partial<InferInteropZodOutput<TContextSchema>> : never>) => Promise<MiddlewareResult<Partial<TSchema extends InteropZodObject ? InferInteropZodInput<TSchema> : {}>>> | MiddlewareResult<Partial<TSchema extends InteropZodObject ? InferInteropZodInput<TSchema> : {}>>;
43
103
  }): AgentMiddleware<TSchema, TContextSchema, any>;
44
104
  //#endregion
45
105
  export { createMiddleware };
@@ -1 +1 @@
1
- {"version":3,"file":"middleware.d.cts","names":["z","AgentMiddleware","Runtime","Controls","MiddlewareResult","AgentBuiltInState","ModelRequest","createMiddleware","ZodObject","TSchema","TContextSchema","infer","Promise","Partial"],"sources":["../../../src/agents/middlewareAgent/middleware.d.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/ban-types */\nimport { z } from \"zod\";\nimport type { AgentMiddleware, Runtime, Controls, MiddlewareResult, AgentBuiltInState, ModelRequest } from \"./types.js\";\n/**\n * Creates a middleware instance with automatic schema inference.\n *\n * @param config - Middleware configuration\n * @param config.name - The name of the middleware\n * @param config.stateSchema - The schema of the middleware state\n * @param config.contextSchema - The schema of the middleware context\n * @param config.prepareModelRequest - The function to prepare the model request\n * @param config.beforeModel - The function to run before the model call\n * @param config.afterModel - The function to run after the model call\n * @returns A middleware instance\n *\n * @example\n * ```ts\n * const authMiddleware = createMiddleware({\n * name: \"AuthMiddleware\",\n * stateSchema: z.object({\n * isAuthenticated: z.boolean().default(false),\n * }),\n * contextSchema: z.object({\n * userId: z.string(),\n * }),\n * beforeModel: async (state, runtime, controls) => {\n * if (!state.isAuthenticated) {\n * return controls.terminate(new Error(\"Not authenticated\"));\n * }\n * },\n * });\n * ```\n */\nexport declare function createMiddleware<TSchema extends z.ZodObject<any> | undefined = undefined, TContextSchema extends z.ZodObject<any> | undefined = undefined>(config: {\n name: string;\n stateSchema?: TSchema;\n contextSchema?: TContextSchema;\n prepareModelRequest?: (options: ModelRequest, state: (TSchema extends z.ZodObject<any> ? z.infer<TSchema> : {}) & AgentBuiltInState, runtime: Runtime<TContextSchema extends z.ZodObject<any> ? z.infer<TContextSchema> : {}>) => Promise<ModelRequest | void> | ModelRequest | void;\n beforeModel?: (state: (TSchema extends z.ZodObject<any> ? z.infer<TSchema> : {}) & AgentBuiltInState, runtime: Runtime<TContextSchema extends z.ZodObject<any> ? z.infer<TContextSchema> : {}>, controls: Controls<(TSchema extends z.ZodObject<any> ? z.infer<TSchema> : {}) & AgentBuiltInState>) => Promise<MiddlewareResult<Partial<TSchema extends z.ZodObject<any> ? z.infer<TSchema> : {}>>> | MiddlewareResult<Partial<TSchema extends z.ZodObject<any> ? z.infer<TSchema> : {}>>;\n afterModel?: (state: (TSchema extends z.ZodObject<any> ? z.infer<TSchema> : {}) & AgentBuiltInState, runtime: Runtime<TContextSchema extends z.ZodObject<any> ? z.infer<TContextSchema> : {}>, controls: Controls<(TSchema extends z.ZodObject<any> ? z.infer<TSchema> : {}) & AgentBuiltInState>) => Promise<MiddlewareResult<Partial<TSchema extends z.ZodObject<any> ? z.infer<TSchema> : {}>>> | MiddlewareResult<Partial<TSchema extends z.ZodObject<any> ? z.infer<TSchema> : {}>>;\n}): AgentMiddleware<TSchema, TContextSchema, any>;\n"],"mappings":";;;;;;AAiCA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKmHE,iBAL3FK,gBAK2FL,CAAAA,gBAL1DF,CAAAA,CAAEQ,SAKwDN,CAAAA,GAAAA,CAAAA,GAAAA,SAAAA,GAAAA,SAAAA,EAAAA,uBALOF,CAAAA,CAAEQ,SAKTN,CAAAA,GAAAA,CAAAA,GAAAA,SAAAA,GAAAA,SAAAA,CAAAA,CAAAA,MAAAA,EAAAA;EAAO,IAA8FO,EAAAA,MAAAA;EAAO,WAAWD,CAAAA,EAHxNC,OAGwND;EAAS,aAAgBC,CAAAA,EAF/OC,cAE+OD;EAAO,mBAAbE,CAAAA,EAAAA,CAAAA,OAAAA,EADzNL,YACyNK,EAAAA,KAAAA,EAAAA,CADnMF,OACmME,SADnLX,CAAAA,CAAEQ,SACiLG,CAAAA,GAAAA,CAAAA,GADhKX,CAAAA,CAAEW,KAC8JA,CADxJF,OACwJE,CAAAA,GAAAA,CAAAA,CAAAA,CAAAA,GADvIN,iBACuIM,EAAAA,OAAAA,EAD3GT,OAC2GS,CADnGD,cACmGC,SAD5EX,CAAAA,CAAEQ,SAC0EG,CAAAA,GAAAA,CAAAA,GADzDX,CAAAA,CAAEW,KACuDA,CADjDD,cACiDC,CAAAA,GAAAA,CAAAA,CAAAA,CAAAA,EAAAA,GADvBC,OACuBD,CADfL,YACeK,GAAAA,IAAAA,CAAAA,GADQL,YACRK,GAAAA,IAAAA;EAAK,WAAkBN,CAAAA,EAAAA,CAAAA,KAAAA,EAAAA,CAAzPI,OAAyPJ,SAAzOL,CAAAA,CAAEQ,SAAuOH,CAAAA,GAAAA,CAAAA,GAAtNL,CAAAA,CAAEW,KAAoNN,CAA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A,CAAEW,KADwCR,CAClCO,cADkCP,CAAAA,GAAAA,CAAAA,CAAAA,CAAAA,EAAAA,QAAAA,EACDA,QADCA,CAAAA,CACSM,OADTN,SACyBH,CAAAA,CAAEQ,SAD3BL,CAAAA,GAAAA,CAAAA,GAC4CH,CAAAA,CAAEW,KAD9CR,CACoDM,OADpDN,CAAAA,GAAAA,CAAAA,CAAAA,CAAAA,GACqEE,iBADrEF,CAAAA,EAAAA,GAC4FS,OAD5FT,CACoGC,gBADpGD,CACqHU,OADrHV,CAC6HM,OAD7HN,SAC6IH,CAAAA,CAAEQ,SAD/IL,CAAAA,GAAAA,CAAAA,GACgKH,CAAAA,CAAEW,KADlKR,CACwKM,OADxKN,CAAAA,GAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,GAC2LC,gBAD3LD,CAC4MU,OAD5MV,CACoNM,OADpNN,SACoOH,CAAAA,CAAEQ,SADtOL,CAAAA,GAAAA,CAAAA,GACuPH,CAAAA,CAAEW,KADzPR,CAC+PM,OAD/PN,CAAAA,GAAAA,CAAAA,CAAAA,CAAAA,CAAAA;CAAQ,CAAA,EAElNF,eAFwUQ,CAExTA,OAFwTA,EAE/SC,cAF+SD,EAAAA,GAAAA,CAAAA"}
1
+ {"version":3,"file":"middleware.d.cts","names":["InteropZodObject","InteropZodDefault","InteropZodOptional","InferInteropZodInput","InferInteropZodOutput","AgentMiddleware","Runtime","MiddlewareResult","AgentBuiltInState","ModelRequest","JumpToTarget","ClientTool","ServerTool","createMiddleware","TSchema","TContextSchema","Partial","Promise"],"sources":["../../../src/agents/middlewareAgent/middleware.d.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport type { InteropZodObject, InteropZodDefault, InteropZodOptional, InferInteropZodInput, InferInteropZodOutput } from \"@langchain/core/utils/types\";\nimport type { AgentMiddleware, Runtime, MiddlewareResult, AgentBuiltInState, ModelRequest, JumpToTarget } from \"./types.js\";\nimport type { ClientTool, ServerTool } from \"../types.js\";\n/**\n * Creates a middleware instance with automatic schema inference.\n *\n * @param config - Middleware configuration\n * @param config.name - The name of the middleware\n * @param config.stateSchema - The schema of the middleware state\n * @param config.contextSchema - The schema of the middleware context\n * @param config.modifyModelRequest - The function to prepare the model request\n * @param config.beforeModel - The function to run before the model call\n * @param config.afterModel - The function to run after the model call\n * @returns A middleware instance\n *\n * @example\n * ```ts\n * const authMiddleware = createMiddleware({\n * name: \"AuthMiddleware\",\n * stateSchema: z.object({\n * isAuthenticated: z.boolean().default(false),\n * }),\n * contextSchema: z.object({\n * userId: z.string(),\n * }),\n * beforeModel: async (state, runtime, controls) => {\n * if (!state.isAuthenticated) {\n * return controls.terminate(new Error(\"Not authenticated\"));\n * }\n * },\n * });\n * ```\n */\nexport declare function createMiddleware<TSchema extends InteropZodObject | undefined = undefined, TContextSchema extends InteropZodObject | InteropZodOptional<InteropZodObject> | InteropZodDefault<InteropZodObject> | undefined = undefined>(config: {\n /**\n * The name of the middleware\n */\n name: string;\n /**\n * The schema of the middleware state. Middleware state is persisted between multiple invocations. It can be either:\n * - A Zod object\n * - A Zod optional object\n * - A Zod default object\n * - Undefined\n */\n stateSchema?: TSchema;\n /**\n * The schema of the middleware context. Middleware context is read-only and not persisted between multiple invocations. It can be either:\n * - A Zod object\n * - A Zod optional object\n * - A Zod default object\n * - Undefined\n */\n contextSchema?: TContextSchema;\n /**\n * Explitictly defines which targets are allowed to be jumped to from the `beforeModel` hook.\n */\n beforeModelJumpTo?: JumpToTarget[];\n /**\n * Explitictly defines which targets are allowed to be jumped to from the `afterModel` hook.\n */\n afterModelJumpTo?: JumpToTarget[];\n /**\n * Additional tools registered by the middleware.\n */\n tools?: (ClientTool | ServerTool)[];\n /**\n * The function to modify the model request. This function is called after the `beforeModel` hook of this middleware and before the model is invoked.\n * It allows to modify the model request before it is passed to the model.\n *\n * @param request - The model request\n * @param request.model - The model to use for this step.\n * @param request.messages - The messages to send to the model.\n * @param request.systemPrompt - The system message for this step.\n * @param request.toolChoice - The tool choice configuration for this step.\n * @param request.tools - The tools to make available for this step.\n * @param state - The middleware state\n * @param runtime - The middleware runtime\n * @returns The modified model request or undefined to pass through\n */\n modifyModelRequest?: (options: ModelRequest, state: (TSchema extends InteropZodObject ? InferInteropZodInput<TSchema> : {}) & AgentBuiltInState, runtime: Runtime<(TSchema extends InteropZodObject ? InferInteropZodInput<TSchema> : {}) & AgentBuiltInState, TContextSchema extends InteropZodObject ? InferInteropZodOutput<TContextSchema> : TContextSchema extends InteropZodDefault<any> ? InferInteropZodOutput<TContextSchema> : TContextSchema extends InteropZodOptional<any> ? Partial<InferInteropZodOutput<TContextSchema>> : never>) => Promise<ModelRequest | void> | ModelRequest | void;\n /**\n * The function to run before the model call. This function is called before the model is invoked and before the `modifyModelRequest` hook.\n * It allows to modify the state of the agent.\n *\n * @param state - The middleware state\n * @param runtime - The middleware runtime\n * @returns The modified middleware state or undefined to pass through\n */\n beforeModel?: (state: (TSchema extends InteropZodObject ? InferInteropZodInput<TSchema> : {}) & AgentBuiltInState, runtime: Runtime<(TSchema extends InteropZodObject ? InferInteropZodInput<TSchema> : {}) & AgentBuiltInState, TContextSchema extends InteropZodObject ? InferInteropZodOutput<TContextSchema> : TContextSchema extends InteropZodDefault<any> ? InferInteropZodOutput<TContextSchema> : TContextSchema extends InteropZodOptional<any> ? Partial<InferInteropZodOutput<TContextSchema>> : never>) => Promise<MiddlewareResult<Partial<TSchema extends InteropZodObject ? InferInteropZodInput<TSchema> : {}>>> | MiddlewareResult<Partial<TSchema extends InteropZodObject ? InferInteropZodInput<TSchema> : {}>>;\n /**\n * The function to run after the model call. This function is called after the model is invoked and before any tools are called.\n * It allows to modify the state of the agent after the model is invoked, e.g. to update tool call parameters.\n *\n * @param state - The middleware state\n * @param runtime - The middleware runtime\n * @returns The modified middleware state or undefined to pass through\n */\n afterModel?: (state: (TSchema extends InteropZodObject ? InferInteropZodInput<TSchema> : {}) & AgentBuiltInState, runtime: Runtime<(TSchema extends InteropZodObject ? InferInteropZodInput<TSchema> : {}) & AgentBuiltInState, TContextSchema extends InteropZodObject ? InferInteropZodOutput<TContextSchema> : TContextSchema extends InteropZodDefault<any> ? InferInteropZodOutput<TContextSchema> : TContextSchema extends InteropZodOptional<any> ? Partial<InferInteropZodOutput<TContextSchema>> : never>) => Promise<MiddlewareResult<Partial<TSchema extends InteropZodObject ? InferInteropZodInput<TSchema> : {}>>> | MiddlewareResult<Partial<TSchema extends InteropZodObject ? InferInteropZodInput<TSchema> : {}>>;\n}): AgentMiddleware<TSchema, TContextSchema, any>;\n"],"mappings":";;;;;;;AAkCA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+CqVe,iBA/C7TF,gBA+C6TE,CAAAA,gBA/C5Rf,gBA+C4Re,GAAAA,SAAAA,GAAAA,SAAAA,EAAAA,uBA/C3Nf,gBA+C2Ne,GA/CxMb,kBA+CwMa,CA/CrLf,gBA+CqLe,CAAAA,GA/CjKd,iBA+CiKc,CA/C/If,gBA+C+Ie,CAAAA,GAAAA,SAAAA,GAAAA,SAAAA,CAAAA,CAAAA,MAAAA,EAAAA;EAAc;;;EAAuD,IAAmBA,EAAAA,MAAAA;EAAc;;;;;;;EAAsG,WAAwBN,CAAAA,EAnCviBK,OAmCuiBL;EAAY;;;;;;;EAS5Z,aAAwBK,CAAAA,EApC7KC,cAoC6KD;EAAO;;;EAA2C,iBAASd,CAAAA,EAhCpOU,YAgCoOV,EAAAA;EAAgB;;;EAAyD,gBAASC,CAAAA,EA5BvTS,YA4BuTT,EAAAA;EAAiB;;;EAA8D,KAASC,CAAAA,EAAAA,CAxBzZS,UAwByZT,GAxB5YU,UAwB4YV,CAAAA,EAAAA;EAAkB;;;;;;;;;;;;;;EAAwQ,kBAA5BC,CAAAA,EAAAA,CAAAA,OAAAA,EATjoBM,YASioBN,EAAAA,KAAAA,EAAAA,CAT3mBW,OAS2mBX,SAT3lBH,gBAS2lBG,GATxkBA,oBASwkBA,CATnjBW,OASmjBX,CAAAA,GAAAA,CAAAA,CAAAA,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AsVE,oBAAtVF,CAA2Wa,OAA3Wb,CAAAA,GAAAA,CAAAA,CAAAA,CAAAA,CAAAA;CAAiB,CAAA,EAC1VI,eADwXU,CACxWD,OADwWC,EAC/VA,cAD+VA,EAAAA,GAAAA,CAAAA"}
@@ -1,5 +1,6 @@
1
- import { AgentBuiltInState, AgentMiddleware, Controls, MiddlewareResult, ModelRequest, Runtime } from "./types.js";
2
- import { z } from "zod";
1
+ import { ClientTool, ServerTool } from "../types.js";
2
+ import { AgentBuiltInState, AgentMiddleware, JumpToTarget, MiddlewareResult, ModelRequest, Runtime } from "./types.js";
3
+ import { InferInteropZodInput, InferInteropZodOutput, InteropZodDefault, InteropZodObject, InteropZodOptional } from "@langchain/core/utils/types";
3
4
 
4
5
  //#region src/agents/middlewareAgent/middleware.d.ts
5
6
 
@@ -10,7 +11,7 @@ import { z } from "zod";
10
11
  * @param config.name - The name of the middleware
11
12
  * @param config.stateSchema - The schema of the middleware state
12
13
  * @param config.contextSchema - The schema of the middleware context
13
- * @param config.prepareModelRequest - The function to prepare the model request
14
+ * @param config.modifyModelRequest - The function to prepare the model request
14
15
  * @param config.beforeModel - The function to run before the model call
15
16
  * @param config.afterModel - The function to run after the model call
16
17
  * @returns A middleware instance
@@ -33,13 +34,72 @@ import { z } from "zod";
33
34
  * });
34
35
  * ```
35
36
  */
36
- declare function createMiddleware<TSchema extends z.ZodObject<any> | undefined = undefined, TContextSchema extends z.ZodObject<any> | undefined = undefined>(config: {
37
+ declare function createMiddleware<TSchema extends InteropZodObject | undefined = undefined, TContextSchema extends InteropZodObject | InteropZodOptional<InteropZodObject> | InteropZodDefault<InteropZodObject> | undefined = undefined>(config: {
38
+ /**
39
+ * The name of the middleware
40
+ */
37
41
  name: string;
42
+ /**
43
+ * The schema of the middleware state. Middleware state is persisted between multiple invocations. It can be either:
44
+ * - A Zod object
45
+ * - A Zod optional object
46
+ * - A Zod default object
47
+ * - Undefined
48
+ */
38
49
  stateSchema?: TSchema;
50
+ /**
51
+ * The schema of the middleware context. Middleware context is read-only and not persisted between multiple invocations. It can be either:
52
+ * - A Zod object
53
+ * - A Zod optional object
54
+ * - A Zod default object
55
+ * - Undefined
56
+ */
39
57
  contextSchema?: TContextSchema;
40
- prepareModelRequest?: (options: ModelRequest, state: (TSchema extends z.ZodObject<any> ? z.infer<TSchema> : {}) & AgentBuiltInState, runtime: Runtime<TContextSchema extends z.ZodObject<any> ? z.infer<TContextSchema> : {}>) => Promise<ModelRequest | void> | ModelRequest | void;
41
- beforeModel?: (state: (TSchema extends z.ZodObject<any> ? z.infer<TSchema> : {}) & AgentBuiltInState, runtime: Runtime<TContextSchema extends z.ZodObject<any> ? z.infer<TContextSchema> : {}>, controls: Controls<(TSchema extends z.ZodObject<any> ? z.infer<TSchema> : {}) & AgentBuiltInState>) => Promise<MiddlewareResult<Partial<TSchema extends z.ZodObject<any> ? z.infer<TSchema> : {}>>> | MiddlewareResult<Partial<TSchema extends z.ZodObject<any> ? z.infer<TSchema> : {}>>;
42
- afterModel?: (state: (TSchema extends z.ZodObject<any> ? z.infer<TSchema> : {}) & AgentBuiltInState, runtime: Runtime<TContextSchema extends z.ZodObject<any> ? z.infer<TContextSchema> : {}>, controls: Controls<(TSchema extends z.ZodObject<any> ? z.infer<TSchema> : {}) & AgentBuiltInState>) => Promise<MiddlewareResult<Partial<TSchema extends z.ZodObject<any> ? z.infer<TSchema> : {}>>> | MiddlewareResult<Partial<TSchema extends z.ZodObject<any> ? z.infer<TSchema> : {}>>;
58
+ /**
59
+ * Explitictly defines which targets are allowed to be jumped to from the `beforeModel` hook.
60
+ */
61
+ beforeModelJumpTo?: JumpToTarget[];
62
+ /**
63
+ * Explitictly defines which targets are allowed to be jumped to from the `afterModel` hook.
64
+ */
65
+ afterModelJumpTo?: JumpToTarget[];
66
+ /**
67
+ * Additional tools registered by the middleware.
68
+ */
69
+ tools?: (ClientTool | ServerTool)[];
70
+ /**
71
+ * The function to modify the model request. This function is called after the `beforeModel` hook of this middleware and before the model is invoked.
72
+ * It allows to modify the model request before it is passed to the model.
73
+ *
74
+ * @param request - The model request
75
+ * @param request.model - The model to use for this step.
76
+ * @param request.messages - The messages to send to the model.
77
+ * @param request.systemPrompt - The system message for this step.
78
+ * @param request.toolChoice - The tool choice configuration for this step.
79
+ * @param request.tools - The tools to make available for this step.
80
+ * @param state - The middleware state
81
+ * @param runtime - The middleware runtime
82
+ * @returns The modified model request or undefined to pass through
83
+ */
84
+ modifyModelRequest?: (options: ModelRequest, state: (TSchema extends InteropZodObject ? InferInteropZodInput<TSchema> : {}) & AgentBuiltInState, runtime: Runtime<(TSchema extends InteropZodObject ? InferInteropZodInput<TSchema> : {}) & AgentBuiltInState, TContextSchema extends InteropZodObject ? InferInteropZodOutput<TContextSchema> : TContextSchema extends InteropZodDefault<any> ? InferInteropZodOutput<TContextSchema> : TContextSchema extends InteropZodOptional<any> ? Partial<InferInteropZodOutput<TContextSchema>> : never>) => Promise<ModelRequest | void> | ModelRequest | void;
85
+ /**
86
+ * The function to run before the model call. This function is called before the model is invoked and before the `modifyModelRequest` hook.
87
+ * It allows to modify the state of the agent.
88
+ *
89
+ * @param state - The middleware state
90
+ * @param runtime - The middleware runtime
91
+ * @returns The modified middleware state or undefined to pass through
92
+ */
93
+ beforeModel?: (state: (TSchema extends InteropZodObject ? InferInteropZodInput<TSchema> : {}) & AgentBuiltInState, runtime: Runtime<(TSchema extends InteropZodObject ? InferInteropZodInput<TSchema> : {}) & AgentBuiltInState, TContextSchema extends InteropZodObject ? InferInteropZodOutput<TContextSchema> : TContextSchema extends InteropZodDefault<any> ? InferInteropZodOutput<TContextSchema> : TContextSchema extends InteropZodOptional<any> ? Partial<InferInteropZodOutput<TContextSchema>> : never>) => Promise<MiddlewareResult<Partial<TSchema extends InteropZodObject ? InferInteropZodInput<TSchema> : {}>>> | MiddlewareResult<Partial<TSchema extends InteropZodObject ? InferInteropZodInput<TSchema> : {}>>;
94
+ /**
95
+ * The function to run after the model call. This function is called after the model is invoked and before any tools are called.
96
+ * It allows to modify the state of the agent after the model is invoked, e.g. to update tool call parameters.
97
+ *
98
+ * @param state - The middleware state
99
+ * @param runtime - The middleware runtime
100
+ * @returns The modified middleware state or undefined to pass through
101
+ */
102
+ afterModel?: (state: (TSchema extends InteropZodObject ? InferInteropZodInput<TSchema> : {}) & AgentBuiltInState, runtime: Runtime<(TSchema extends InteropZodObject ? InferInteropZodInput<TSchema> : {}) & AgentBuiltInState, TContextSchema extends InteropZodObject ? InferInteropZodOutput<TContextSchema> : TContextSchema extends InteropZodDefault<any> ? InferInteropZodOutput<TContextSchema> : TContextSchema extends InteropZodOptional<any> ? Partial<InferInteropZodOutput<TContextSchema>> : never>) => Promise<MiddlewareResult<Partial<TSchema extends InteropZodObject ? InferInteropZodInput<TSchema> : {}>>> | MiddlewareResult<Partial<TSchema extends InteropZodObject ? InferInteropZodInput<TSchema> : {}>>;
43
103
  }): AgentMiddleware<TSchema, TContextSchema, any>;
44
104
  //#endregion
45
105
  export { createMiddleware };
@@ -1 +1 @@
1
- {"version":3,"file":"middleware.d.ts","names":["z","AgentMiddleware","Runtime","Controls","MiddlewareResult","AgentBuiltInState","ModelRequest","createMiddleware","ZodObject","TSchema","TContextSchema","infer","Promise","Partial"],"sources":["../../../src/agents/middlewareAgent/middleware.d.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/ban-types */\nimport { z } from \"zod\";\nimport type { AgentMiddleware, Runtime, Controls, MiddlewareResult, AgentBuiltInState, ModelRequest } from \"./types.js\";\n/**\n * Creates a middleware instance with automatic schema inference.\n *\n * @param config - Middleware configuration\n * @param config.name - The name of the middleware\n * @param config.stateSchema - The schema of the middleware state\n * @param config.contextSchema - The schema of the middleware context\n * @param config.prepareModelRequest - The function to prepare the model request\n * @param config.beforeModel - The function to run before the model call\n * @param config.afterModel - The function to run after the model call\n * @returns A middleware instance\n *\n * @example\n * ```ts\n * const authMiddleware = createMiddleware({\n * name: \"AuthMiddleware\",\n * stateSchema: z.object({\n * isAuthenticated: z.boolean().default(false),\n * }),\n * contextSchema: z.object({\n * userId: z.string(),\n * }),\n * beforeModel: async (state, runtime, controls) => {\n * if (!state.isAuthenticated) {\n * return controls.terminate(new Error(\"Not authenticated\"));\n * }\n * },\n * });\n * ```\n */\nexport declare function createMiddleware<TSchema extends z.ZodObject<any> | undefined = undefined, TContextSchema extends z.ZodObject<any> | undefined = undefined>(config: {\n name: string;\n stateSchema?: TSchema;\n contextSchema?: TContextSchema;\n prepareModelRequest?: (options: ModelRequest, state: (TSchema extends z.ZodObject<any> ? z.infer<TSchema> : {}) & AgentBuiltInState, runtime: Runtime<TContextSchema extends z.ZodObject<any> ? z.infer<TContextSchema> : {}>) => Promise<ModelRequest | void> | ModelRequest | void;\n beforeModel?: (state: (TSchema extends z.ZodObject<any> ? z.infer<TSchema> : {}) & AgentBuiltInState, runtime: Runtime<TContextSchema extends z.ZodObject<any> ? z.infer<TContextSchema> : {}>, controls: Controls<(TSchema extends z.ZodObject<any> ? z.infer<TSchema> : {}) & AgentBuiltInState>) => Promise<MiddlewareResult<Partial<TSchema extends z.ZodObject<any> ? z.infer<TSchema> : {}>>> | MiddlewareResult<Partial<TSchema extends z.ZodObject<any> ? z.infer<TSchema> : {}>>;\n afterModel?: (state: (TSchema extends z.ZodObject<any> ? z.infer<TSchema> : {}) & AgentBuiltInState, runtime: Runtime<TContextSchema extends z.ZodObject<any> ? z.infer<TContextSchema> : {}>, controls: Controls<(TSchema extends z.ZodObject<any> ? z.infer<TSchema> : {}) & AgentBuiltInState>) => Promise<MiddlewareResult<Partial<TSchema extends z.ZodObject<any> ? z.infer<TSchema> : {}>>> | MiddlewareResult<Partial<TSchema extends z.ZodObject<any> ? z.infer<TSchema> : {}>>;\n}): AgentMiddleware<TSchema, TContextSchema, any>;\n"],"mappings":";;;;;;AAiCA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKmHE,iBAL3FK,gBAK2FL,CAAAA,gBAL1DF,CAAAA,CAAEQ,SAKwDN,CAAAA,GAAAA,CAAAA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V,CAC6HM,OAD7HN,SAC6IH,CAAAA,CAAEQ,SAD/IL,CAAAA,GAAAA,CAAAA,GACgKH,CAAAA,CAAEW,KADlKR,CACwKM,OADxKN,CAAAA,GAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,GAC2LC,gBAD3LD,CAC4MU,OAD5MV,CACoNM,OADpNN,SACoOH,CAAAA,CAAEQ,SADtOL,CAAAA,GAAAA,CAAAA,GACuPH,CAAAA,CAAEW,KADzPR,CAC+PM,OAD/PN,CAAAA,GAAAA,CAAAA,CAAAA,CAAAA,CAAAA;CAAQ,CAAA,EAElNF,eAFwUQ,CAExTA,OAFwTA,EAE/SC,cAF+SD,EAAAA,GAAAA,CAAAA"}
1
+ {"version":3,"file":"middleware.d.ts","names":["InteropZodObject","InteropZodDefault","InteropZodOptional","InferInteropZodInput","InferInteropZodOutput","AgentMiddleware","Runtime","MiddlewareResult","AgentBuiltInState","ModelRequest","JumpToTarget","ClientTool","ServerTool","createMiddleware","TSchema","TContextSchema","Partial","Promise"],"sources":["../../../src/agents/middlewareAgent/middleware.d.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport type { InteropZodObject, InteropZodDefault, InteropZodOptional, InferInteropZodInput, InferInteropZodOutput } from \"@langchain/core/utils/types\";\nimport type { AgentMiddleware, Runtime, MiddlewareResult, AgentBuiltInState, ModelRequest, JumpToTarget } from \"./types.js\";\nimport type { ClientTool, ServerTool } from \"../types.js\";\n/**\n * Creates a middleware instance with automatic schema inference.\n *\n * @param config - Middleware configuration\n * @param config.name - The name of the middleware\n * @param config.stateSchema - The schema of the middleware state\n * @param config.contextSchema - The schema of the middleware context\n * @param config.modifyModelRequest - The function to prepare the model request\n * @param config.beforeModel - The function to run before the model call\n * @param config.afterModel - The function to run after the model call\n * @returns A middleware instance\n *\n * @example\n * ```ts\n * const authMiddleware = createMiddleware({\n * name: \"AuthMiddleware\",\n * stateSchema: z.object({\n * isAuthenticated: z.boolean().default(false),\n * }),\n * contextSchema: z.object({\n * userId: z.string(),\n * }),\n * beforeModel: async (state, runtime, controls) => {\n * if (!state.isAuthenticated) {\n * return controls.terminate(new Error(\"Not authenticated\"));\n * }\n * },\n * });\n * ```\n */\nexport declare function createMiddleware<TSchema extends InteropZodObject | undefined = undefined, TContextSchema extends InteropZodObject | InteropZodOptional<InteropZodObject> | InteropZodDefault<InteropZodObject> | undefined = undefined>(config: {\n /**\n * The name of the middleware\n */\n name: string;\n /**\n * The schema of the middleware state. Middleware state is persisted between multiple invocations. It can be either:\n * - A Zod object\n * - A Zod optional object\n * - A Zod default object\n * - Undefined\n */\n stateSchema?: TSchema;\n /**\n * The schema of the middleware context. Middleware context is read-only and not persisted between multiple invocations. It can be either:\n * - A Zod object\n * - A Zod optional object\n * - A Zod default object\n * - Undefined\n */\n contextSchema?: TContextSchema;\n /**\n * Explitictly defines which targets are allowed to be jumped to from the `beforeModel` hook.\n */\n beforeModelJumpTo?: JumpToTarget[];\n /**\n * Explitictly defines which targets are allowed to be jumped to from the `afterModel` hook.\n */\n afterModelJumpTo?: JumpToTarget[];\n /**\n * Additional tools registered by the middleware.\n */\n tools?: (ClientTool | ServerTool)[];\n /**\n * The function to modify the model request. This function is called after the `beforeModel` hook of this middleware and before the model is invoked.\n * It allows to modify the model request before it is passed to the model.\n *\n * @param request - The model request\n * @param request.model - The model to use for this step.\n * @param request.messages - The messages to send to the model.\n * @param request.systemPrompt - The system message for this step.\n * @param request.toolChoice - The tool choice configuration for this step.\n * @param request.tools - The tools to make available for this step.\n * @param state - The middleware state\n * @param runtime - The middleware runtime\n * @returns The modified model request or undefined to pass through\n */\n modifyModelRequest?: (options: ModelRequest, state: (TSchema extends InteropZodObject ? InferInteropZodInput<TSchema> : {}) & AgentBuiltInState, runtime: Runtime<(TSchema extends InteropZodObject ? InferInteropZodInput<TSchema> : {}) & AgentBuiltInState, TContextSchema extends InteropZodObject ? InferInteropZodOutput<TContextSchema> : TContextSchema extends InteropZodDefault<any> ? InferInteropZodOutput<TContextSchema> : TContextSchema extends InteropZodOptional<any> ? Partial<InferInteropZodOutput<TContextSchema>> : never>) => Promise<ModelRequest | void> | ModelRequest | void;\n /**\n * The function to run before the model call. This function is called before the model is invoked and before the `modifyModelRequest` hook.\n * It allows to modify the state of the agent.\n *\n * @param state - The middleware state\n * @param runtime - The middleware runtime\n * @returns The modified middleware state or undefined to pass through\n */\n beforeModel?: (state: (TSchema extends InteropZodObject ? InferInteropZodInput<TSchema> : {}) & AgentBuiltInState, runtime: Runtime<(TSchema extends InteropZodObject ? InferInteropZodInput<TSchema> : {}) & AgentBuiltInState, TContextSchema extends InteropZodObject ? InferInteropZodOutput<TContextSchema> : TContextSchema extends InteropZodDefault<any> ? InferInteropZodOutput<TContextSchema> : TContextSchema extends InteropZodOptional<any> ? Partial<InferInteropZodOutput<TContextSchema>> : never>) => Promise<MiddlewareResult<Partial<TSchema extends InteropZodObject ? InferInteropZodInput<TSchema> : {}>>> | MiddlewareResult<Partial<TSchema extends InteropZodObject ? InferInteropZodInput<TSchema> : {}>>;\n /**\n * The function to run after the model call. This function is called after the model is invoked and before any tools are called.\n * It allows to modify the state of the agent after the model is invoked, e.g. to update tool call parameters.\n *\n * @param state - The middleware state\n * @param runtime - The middleware runtime\n * @returns The modified middleware state or undefined to pass through\n */\n afterModel?: (state: (TSchema extends InteropZodObject ? InferInteropZodInput<TSchema> : {}) & AgentBuiltInState, runtime: Runtime<(TSchema extends InteropZodObject ? InferInteropZodInput<TSchema> : {}) & AgentBuiltInState, TContextSchema extends InteropZodObject ? InferInteropZodOutput<TContextSchema> : TContextSchema extends InteropZodDefault<any> ? InferInteropZodOutput<TContextSchema> : TContextSchema extends InteropZodOptional<any> ? Partial<InferInteropZodOutput<TContextSchema>> : never>) => Promise<MiddlewareResult<Partial<TSchema extends InteropZodObject ? InferInteropZodInput<TSchema> : {}>>> | MiddlewareResult<Partial<TSchema extends InteropZodObject ? InferInteropZodInput<TSchema> : {}>>;\n}): AgentMiddleware<TSchema, TCont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,UAASC,CAAAA,EAAAA,CAAAA,KAAAA,EAAAA,CAAnTa,OAAmTb,SAAnSD,gBAAmSC,GAAhRE,oBAAgRF,CAA3Pa,OAA2Pb,CAAAA,GAAAA,CAAAA,CAAAA,CAAAA,GAA1OO,iBAA0OP,EAAAA,OAAAA,EAA9MK,OAA8ML,CAAAA,CAArMa,OAAqMb,SAArLD,gBAAqLC,GAAlKE,oBAAkKF,CAA7Ia,OAA6Ib,CAAAA,GAAAA,CAAAA,CAAAA,CAAAA,GAA5HO,iBAA4HP,EAAzGc,cAAyGd,SAAlFD,gBAAkFC,GAA/DG,qBAA+DH,CAAzCc,cAAyCd,CAAAA,GAAvBc,cAAuBd,SAAAA,iBAAAA,CAAAA,GAAAA,CAAAA,GAAyBG,qBAAzBH,CAA+Cc,cAA/Cd,CAAAA,GAAiEc,cAAjEd,SAAwFC,kBAAxFD,CAAAA,GAAAA,CAAAA,GAAkHe,OAAlHf,CAA0HG,qBAA1HH,CAAgJc,cAAhJd,CAAAA,CAAAA,GAAAA,KAAAA,CAAAA,EAAAA,GAA8KgB,OAA9KhB,CAAsLM,gBAAtLN,CAAuMe,OAAvMf,CAA+Ma,OAA/Mb,SAA+ND,gBAA/NC,GAAkPE,oBAAlPF,CAAuQa,OAAvQb,CAAAA,GAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,GAA0RM,gBAA1RN,CAA2Se,OAA3Sf,CAAmTa,OAAnTb,SAAmUD,gBAAnUC,GAAsVE,oBAAtVF,CAA2Wa,OAA3Wb,CAAAA,GAAAA,CAAAA,CAAAA,CAAAA,CAAAA;CAAiB,CAAA,EAC1VI,eADwXU,CACxWD,OADwWC,EAC/VA,cAD+VA,EAAAA,GAAAA,CAAAA"}
@@ -6,7 +6,7 @@
6
6
  * @param config.name - The name of the middleware
7
7
  * @param config.stateSchema - The schema of the middleware state
8
8
  * @param config.contextSchema - The schema of the middleware context
9
- * @param config.prepareModelRequest - The function to prepare the model request
9
+ * @param config.modifyModelRequest - The function to prepare the model request
10
10
  * @param config.beforeModel - The function to run before the model call
11
11
  * @param config.afterModel - The function to run after the model call
12
12
  * @returns A middleware instance
@@ -33,11 +33,14 @@ function createMiddleware(config) {
33
33
  const middleware = {
34
34
  name: config.name,
35
35
  stateSchema: config.stateSchema,
36
- contextSchema: config.contextSchema
36
+ contextSchema: config.contextSchema,
37
+ beforeModelJumpTo: config.beforeModelJumpTo,
38
+ afterModelJumpTo: config.afterModelJumpTo,
39
+ tools: config.tools ?? []
37
40
  };
38
- if (config.prepareModelRequest) middleware.prepareModelRequest = async (options, state, runtime) => Promise.resolve(config.prepareModelRequest(options, state, runtime));
39
- if (config.beforeModel) middleware.beforeModel = async (state, runtime, controls) => Promise.resolve(config.beforeModel(state, runtime, controls));
40
- if (config.afterModel) middleware.afterModel = async (state, runtime, controls) => Promise.resolve(config.afterModel(state, runtime, controls));
41
+ if (config.modifyModelRequest) middleware.modifyModelRequest = async (options, state, runtime) => Promise.resolve(config.modifyModelRequest(options, state, runtime));
42
+ if (config.beforeModel) middleware.beforeModel = async (state, runtime) => Promise.resolve(config.beforeModel(state, runtime));
43
+ if (config.afterModel) middleware.afterModel = async (state, runtime) => Promise.resolve(config.afterModel(state, runtime));
41
44
  return middleware;
42
45
  }
43
46
 
@@ -1 +1 @@
1
- {"version":3,"file":"middleware.js","names":["config: {\n name: string;\n stateSchema?: TSchema;\n contextSchema?: TContextSchema;\n prepareModelRequest?: (\n options: ModelRequest,\n state: (TSchema extends z.ZodObject<any> ? z.infer<TSchema> : {}) &\n AgentBuiltInState,\n runtime: Runtime<\n TContextSchema extends z.ZodObject<any> ? z.infer<TContextSchema> : {}\n >\n ) => Promise<ModelRequest | void> | ModelRequest | void;\n beforeModel?: (\n state: (TSchema extends z.ZodObject<any> ? z.infer<TSchema> : {}) &\n AgentBuiltInState,\n runtime: Runtime<\n TContextSchema extends z.ZodObject<any> ? z.infer<TContextSchema> : {}\n >,\n controls: Controls<\n (TSchema extends z.ZodObject<any> ? z.infer<TSchema> : {}) &\n AgentBuiltInState\n >\n ) =>\n | Promise<\n MiddlewareResult<\n Partial<TSchema extends z.ZodObject<any> ? z.infer<TSchema> : {}>\n >\n >\n | MiddlewareResult<\n Partial<TSchema extends z.ZodObject<any> ? z.infer<TSchema> : {}>\n >;\n afterModel?: (\n state: (TSchema extends z.ZodObject<any> ? z.infer<TSchema> : {}) &\n AgentBuiltInState,\n runtime: Runtime<\n TContextSchema extends z.ZodObject<any> ? z.infer<TContextSchema> : {}\n >,\n controls: Controls<\n (TSchema extends z.ZodObject<any> ? z.infer<TSchema> : {}) &\n AgentBuiltInState\n >\n ) =>\n | Promise<\n MiddlewareResult<\n Partial<TSchema extends z.ZodObject<any> ? z.infer<TSchema> : {}>\n >\n >\n | MiddlewareResult<\n Partial<TSchema extends z.ZodObject<any> ? z.infer<TSchema> : {}>\n >;\n}","middleware: AgentMiddleware<TSchema, TContextSchema, any>"],"sources":["../../../src/agents/middlewareAgent/middleware.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/ban-types */\nimport { z } from \"zod\";\nimport type {\n AgentMiddleware,\n Runtime,\n Controls,\n MiddlewareResult,\n AgentBuiltInState,\n ModelRequest,\n} from \"./types.js\";\n\n/**\n * Creates a middleware instance with automatic schema inference.\n *\n * @param config - Middleware configuration\n * @param config.name - The name of the middleware\n * @param config.stateSchema - The schema of the middleware state\n * @param config.contextSchema - The schema of the middleware context\n * @param config.prepareModelRequest - The function to prepare the model request\n * @param config.beforeModel - The function to run before the model call\n * @param config.afterModel - The function to run after the model call\n * @returns A middleware instance\n *\n * @example\n * ```ts\n * const authMiddleware = createMiddleware({\n * name: \"AuthMiddleware\",\n * stateSchema: z.object({\n * isAuthenticated: z.boolean().default(false),\n * }),\n * contextSchema: z.object({\n * userId: z.string(),\n * }),\n * beforeModel: async (state, runtime, controls) => {\n * if (!state.isAuthenticated) {\n * return controls.terminate(new Error(\"Not authenticated\"));\n * }\n * },\n * });\n * ```\n */\nexport function createMiddleware<\n TSchema extends z.ZodObject<any> | undefined = undefined,\n TContextSchema extends z.ZodObject<any> | undefined = undefined\n>(config: {\n name: string;\n stateSchema?: TSchema;\n contextSchema?: TContextSchema;\n prepareModelRequest?: (\n options: ModelRequest,\n state: (TSchema extends z.ZodObject<any> ? z.infer<TSchema> : {}) &\n AgentBuiltInState,\n runtime: Runtime<\n TContextSchema extends z.ZodObject<any> ? z.infer<TContextSchema> : {}\n >\n ) => Promise<ModelRequest | void> | ModelRequest | void;\n beforeModel?: (\n state: (TSchema extends z.ZodObject<any> ? z.infer<TSchema> : {}) &\n AgentBuiltInState,\n runtime: Runtime<\n TContextSchema extends z.ZodObject<any> ? z.infer<TContextSchema> : {}\n >,\n controls: Controls<\n (TSchema extends z.ZodObject<any> ? z.infer<TSchema> : {}) &\n AgentBuiltInState\n >\n ) =>\n | Promise<\n MiddlewareResult<\n Partial<TSchema extends z.ZodObject<any> ? z.infer<TSchema> : {}>\n >\n >\n | MiddlewareResult<\n Partial<TSchema extends z.ZodObject<any> ? z.infer<TSchema> : {}>\n >;\n afterModel?: (\n state: (TSchema extends z.ZodObject<any> ? z.infer<TSchema> : {}) &\n AgentBuiltInState,\n runtime: Runtime<\n TContextSchema extends z.ZodObject<any> ? z.infer<TContextSchema> : {}\n >,\n controls: Controls<\n (TSchema extends z.ZodObject<any> ? z.infer<TSchema> : {}) &\n AgentBuiltInState\n >\n ) =>\n | Promise<\n MiddlewareResult<\n Partial<TSchema extends z.ZodObject<any> ? z.infer<TSchema> : {}>\n >\n >\n | MiddlewareResult<\n Partial<TSchema extends z.ZodObject<any> ? z.infer<TSchema> : {}>\n >;\n}): AgentMiddleware<TSchema, TContextSchema, any> {\n const middleware: AgentMiddleware<TSchema, TContextSchema, any> = {\n name: config.name,\n stateSchema: config.stateSchema,\n contextSchema: config.contextSchema,\n };\n\n if (config.prepareModelRequest) {\n middleware.prepareModelRequest = async (options, state, runtime) =>\n Promise.resolve(config.prepareModelRequest!(options, state, runtime));\n }\n\n if (config.beforeModel) {\n middleware.beforeModel = async (state, runtime, controls) =>\n Promise.resolve(config.beforeModel!(state, runtime, controls));\n }\n\n if (config.afterModel) {\n middleware.afterModel = async (state, runtime, controls) =>\n Promise.resolve(config.afterModel!(state, runtime, controls));\n }\n\n return middleware;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,SAAgB,iBAGdA,QAkDgD;CAChD,MAAMC,aAA4D;EAChE,MAAM,OAAO;EACb,aAAa,OAAO;EACpB,eAAe,OAAO;CACvB;AAED,KAAI,OAAO,qBACT,WAAW,sBAAsB,OAAO,SAAS,OAAO,YACtD,QAAQ,QAAQ,OAAO,oBAAqB,SAAS,OAAO,QAAQ,CAAC;AAGzE,KAAI,OAAO,aACT,WAAW,cAAc,OAAO,OAAO,SAAS,aAC9C,QAAQ,QAAQ,OAAO,YAAa,OAAO,SAAS,SAAS,CAAC;AAGlE,KAAI,OAAO,YACT,WAAW,aAAa,OAAO,OAAO,SAAS,aAC7C,QAAQ,QAAQ,OAAO,WAAY,OAAO,SAAS,SAAS,CAAC;AAGjE,QAAO;AACR"}
1
+ {"version":3,"file":"middleware.js","names":["config: {\n /**\n * The name of the middleware\n */\n name: string;\n /**\n * The schema of the middleware state. Middleware state is persisted between multiple invocations. It can be either:\n * - A Zod object\n * - A Zod optional object\n * - A Zod default object\n * - Undefined\n */\n stateSchema?: TSchema;\n /**\n * The schema of the middleware context. Middleware context is read-only and not persisted between multiple invocations. It can be either:\n * - A Zod object\n * - A Zod optional object\n * - A Zod default object\n * - Undefined\n */\n contextSchema?: TContextSchema;\n /**\n * Explitictly defines which targets are allowed to be jumped to from the `beforeModel` hook.\n */\n beforeModelJumpTo?: JumpToTarget[];\n /**\n * Explitictly defines which targets are allowed to be jumped to from the `afterModel` hook.\n */\n afterModelJumpTo?: JumpToTarget[];\n /**\n * Additional tools registered by the middleware.\n */\n tools?: (ClientTool | ServerTool)[];\n /**\n * The function to modify the model request. This function is called after the `beforeModel` hook of this middleware and before the model is invoked.\n * It allows to modify the model request before it is passed to the model.\n *\n * @param request - The model request\n * @param request.model - The model to use for this step.\n * @param request.messages - The messages to send to the model.\n * @param request.systemPrompt - The system message for this step.\n * @param request.toolChoice - The tool choice configuration for this step.\n * @param request.tools - The tools to make available for this step.\n * @param state - The middleware state\n * @param runtime - The middleware runtime\n * @returns The modified model request or undefined to pass through\n */\n modifyModelRequest?: (\n options: ModelRequest,\n state: (TSchema extends InteropZodObject\n ? InferInteropZodInput<TSchema>\n : {}) &\n AgentBuiltInState,\n runtime: Runtime<\n (TSchema extends InteropZodObject ? InferInteropZodInput<TSchema> : {}) &\n AgentBuiltInState,\n TContextSchema extends InteropZodObject\n ? InferInteropZodOutput<TContextSchema>\n : TContextSchema extends InteropZodDefault<any>\n ? InferInteropZodOutput<TContextSchema>\n : TContextSchema extends InteropZodOptional<any>\n ? Partial<InferInteropZodOutput<TContextSchema>>\n : never\n >\n ) => Promise<ModelRequest | void> | ModelRequest | void;\n /**\n * The function to run before the model call. This function is called before the model is invoked and before the `modifyModelRequest` hook.\n * It allows to modify the state of the agent.\n *\n * @param state - The middleware state\n * @param runtime - The middleware runtime\n * @returns The modified middleware state or undefined to pass through\n */\n beforeModel?: (\n state: (TSchema extends InteropZodObject\n ? InferInteropZodInput<TSchema>\n : {}) &\n AgentBuiltInState,\n runtime: Runtime<\n (TSchema extends InteropZodObject ? InferInteropZodInput<TSchema> : {}) &\n AgentBuiltInState,\n TContextSchema extends InteropZodObject\n ? InferInteropZodOutput<TContextSchema>\n : TContextSchema extends InteropZodDefault<any>\n ? InferInteropZodOutput<TContextSchema>\n : TContextSchema extends InteropZodOptional<any>\n ? Partial<InferInteropZodOutput<TContextSchema>>\n : never\n >\n ) =>\n | Promise<\n MiddlewareResult<\n Partial<\n TSchema extends InteropZodObject\n ? InferInteropZodInput<TSchema>\n : {}\n >\n >\n >\n | MiddlewareResult<\n Partial<\n TSchema extends InteropZodObject ? InferInteropZodInput<TSchema> : {}\n >\n >;\n /**\n * The function to run after the model call. This function is called after the model is invoked and before any tools are called.\n * It allows to modify the state of the agent after the model is invoked, e.g. to update tool call parameters.\n *\n * @param state - The middleware state\n * @param runtime - The middleware runtime\n * @returns The modified middleware state or undefined to pass through\n */\n afterModel?: (\n state: (TSchema extends InteropZodObject\n ? InferInteropZodInput<TSchema>\n : {}) &\n AgentBuiltInState,\n runtime: Runtime<\n (TSchema extends InteropZodObject ? InferInteropZodInput<TSchema> : {}) &\n AgentBuiltInState,\n TContextSchema extends InteropZodObject\n ? InferInteropZodOutput<TContextSchema>\n : TContextSchema extends InteropZodDefault<any>\n ? InferInteropZodOutput<TContextSchema>\n : TContextSchema extends InteropZodOptional<any>\n ? Partial<InferInteropZodOutput<TContextSchema>>\n : never\n >\n ) =>\n | Promise<\n MiddlewareResult<\n Partial<\n TSchema extends InteropZodObject\n ? InferInteropZodInput<TSchema>\n : {}\n >\n >\n >\n | MiddlewareResult<\n Partial<\n TSchema extends InteropZodObject ? InferInteropZodInput<TSchema> : {}\n >\n >;\n}","middleware: AgentMiddleware<TSchema, TContextSchema, any>"],"sources":["../../../src/agents/middlewareAgent/middleware.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport type {\n InteropZodObject,\n InteropZodDefault,\n InteropZodOptional,\n InferInteropZodInput,\n InferInteropZodOutput,\n} from \"@langchain/core/utils/types\";\nimport type {\n AgentMiddleware,\n Runtime,\n MiddlewareResult,\n AgentBuiltInState,\n ModelRequest,\n JumpToTarget,\n} from \"./types.js\";\nimport type { ClientTool, ServerTool } from \"../types.js\";\n\n/**\n * Creates a middleware instance with automatic schema inference.\n *\n * @param config - Middleware configuration\n * @param config.name - The name of the middleware\n * @param config.stateSchema - The schema of the middleware state\n * @param config.contextSchema - The schema of the middleware context\n * @param config.modifyModelRequest - The function to prepare the model request\n * @param config.beforeModel - The function to run before the model call\n * @param config.afterModel - The function to run after the model call\n * @returns A middleware instance\n *\n * @example\n * ```ts\n * const authMiddleware = createMiddleware({\n * name: \"AuthMiddleware\",\n * stateSchema: z.object({\n * isAuthenticated: z.boolean().default(false),\n * }),\n * contextSchema: z.object({\n * userId: z.string(),\n * }),\n * beforeModel: async (state, runtime, controls) => {\n * if (!state.isAuthenticated) {\n * return controls.terminate(new Error(\"Not authenticated\"));\n * }\n * },\n * });\n * ```\n */\nexport function createMiddleware<\n TSchema extends InteropZodObject | undefined = undefined,\n TContextSchema extends\n | InteropZodObject\n | InteropZodOptional<InteropZodObject>\n | InteropZodDefault<InteropZodObject>\n | undefined = undefined\n>(config: {\n /**\n * The name of the middleware\n */\n name: string;\n /**\n * The schema of the middleware state. Middleware state is persisted between multiple invocations. It can be either:\n * - A Zod object\n * - A Zod optional object\n * - A Zod default object\n * - Undefined\n */\n stateSchema?: TSchema;\n /**\n * The schema of the middleware context. Middleware context is read-only and not persisted between multiple invocations. It can be either:\n * - A Zod object\n * - A Zod optional object\n * - A Zod default object\n * - Undefined\n */\n contextSchema?: TContextSchema;\n /**\n * Explitictly defines which targets are allowed to be jumped to from the `beforeModel` hook.\n */\n beforeModelJumpTo?: JumpToTarget[];\n /**\n * Explitictly defines which targets are allowed to be jumped to from the `afterModel` hook.\n */\n afterModelJumpTo?: JumpToTarget[];\n /**\n * Additional tools registered by the middleware.\n */\n tools?: (ClientTool | ServerTool)[];\n /**\n * The function to modify the model request. This function is called after the `beforeModel` hook of this middleware and before the model is invoked.\n * It allows to modify the model request before it is passed to the model.\n *\n * @param request - The model request\n * @param request.model - The model to use for this step.\n * @param request.messages - The messages to send to the model.\n * @param request.systemPrompt - The system message for this step.\n * @param request.toolChoice - The tool choice configuration for this step.\n * @param request.tools - The tools to make available for this step.\n * @param state - The middleware state\n * @param runtime - The middleware runtime\n * @returns The modified model request or undefined to pass through\n */\n modifyModelRequest?: (\n options: ModelRequest,\n state: (TSchema extends InteropZodObject\n ? InferInteropZodInput<TSchema>\n : {}) &\n AgentBuiltInState,\n runtime: Runtime<\n (TSchema extends InteropZodObject ? InferInteropZodInput<TSchema> : {}) &\n AgentBuiltInState,\n TContextSchema extends InteropZodObject\n ? InferInteropZodOutput<TContextSchema>\n : TContextSchema extends InteropZodDefault<any>\n ? InferInteropZodOutput<TContextSchema>\n : TContextSchema extends InteropZodOptional<any>\n ? Partial<InferInteropZodOutput<TContextSchema>>\n : never\n >\n ) => Promise<ModelRequest | void> | ModelRequest | void;\n /**\n * The function to run before the model call. This function is called before the model is invoked and before the `modifyModelRequest` hook.\n * It allows to modify the state of the agent.\n *\n * @param state - The middleware state\n * @param runtime - The middleware runtime\n * @returns The modified middleware state or undefined to pass through\n */\n beforeModel?: (\n state: (TSchema extends InteropZodObject\n ? InferInteropZodInput<TSchema>\n : {}) &\n AgentBuiltInState,\n runtime: Runtime<\n (TSchema extends InteropZodObject ? InferInteropZodInput<TSchema> : {}) &\n AgentBuiltInState,\n TContextSchema extends InteropZodObject\n ? InferInteropZodOutput<TContextSchema>\n : TContextSchema extends InteropZodDefault<any>\n ? InferInteropZodOutput<TContextSchema>\n : TContextSchema extends InteropZodOptional<any>\n ? Partial<InferInteropZodOutput<TContextSchema>>\n : never\n >\n ) =>\n | Promise<\n MiddlewareResult<\n Partial<\n TSchema extends InteropZodObject\n ? InferInteropZodInput<TSchema>\n : {}\n >\n >\n >\n | MiddlewareResult<\n Partial<\n TSchema extends InteropZodObject ? InferInteropZodInput<TSchema> : {}\n >\n >;\n /**\n * The function to run after the model call. This function is called after the model is invoked and before any tools are called.\n * It allows to modify the state of the agent after the model is invoked, e.g. to update tool call parameters.\n *\n * @param state - The middleware state\n * @param runtime - The middleware runtime\n * @returns The modified middleware state or undefined to pass through\n */\n afterModel?: (\n state: (TSchema extends InteropZodObject\n ? InferInteropZodInput<TSchema>\n : {}) &\n AgentBuiltInState,\n runtime: Runtime<\n (TSchema extends InteropZodObject ? InferInteropZodInput<TSchema> : {}) &\n AgentBuiltInState,\n TContextSchema extends InteropZodObject\n ? InferInteropZodOutput<TContextSchema>\n : TContextSchema extends InteropZodDefault<any>\n ? InferInteropZodOutput<TContextSchema>\n : TContextSchema extends InteropZodOptional<any>\n ? Partial<InferInteropZodOutput<TContextSchema>>\n : never\n >\n ) =>\n | Promise<\n MiddlewareResult<\n Partial<\n TSchema extends InteropZodObject\n ? InferInteropZodInput<TSchema>\n : {}\n >\n >\n >\n | MiddlewareResult<\n Partial<\n TSchema extends InteropZodObject ? InferInteropZodInput<TSchema> : {}\n >\n >;\n}): AgentMiddleware<TSchema, TContextSchema, any> {\n const middleware: AgentMiddleware<TSchema, TContextSchema, any> = {\n name: config.name,\n stateSchema: config.stateSchema,\n contextSchema: config.contextSchema,\n beforeModelJumpTo: config.beforeModelJumpTo,\n afterModelJumpTo: config.afterModelJumpTo,\n tools: config.tools ?? [],\n };\n\n if (config.modifyModelRequest) {\n middleware.modifyModelRequest = async (options, state, runtime) =>\n Promise.resolve(\n config.modifyModelRequest!(\n options,\n state,\n runtime as Runtime<\n (TSchema extends InteropZodObject\n ? InferInteropZodInput<TSchema>\n : {}) &\n AgentBuiltInState,\n TContextSchema extends InteropZodObject\n ? InferInteropZodOutput<TContextSchema>\n : TContextSchema extends InteropZodDefault<any>\n ? InferInteropZodOutput<TContextSchema>\n : TContextSchema extends InteropZodOptional<any>\n ? Partial<InferInteropZodOutput<TContextSchema>>\n : never\n >\n )\n );\n }\n\n if (config.beforeModel) {\n middleware.beforeModel = async (state, runtime) =>\n Promise.resolve(\n config.beforeModel!(\n state,\n runtime as Runtime<\n (TSchema extends InteropZodObject\n ? InferInteropZodInput<TSchema>\n : {}) &\n AgentBuiltInState,\n TContextSchema extends InteropZodObject\n ? InferInteropZodOutput<TContextSchema>\n : TContextSchema extends InteropZodDefault<any>\n ? InferInteropZodOutput<TContextSchema>\n : TContextSchema extends InteropZodOptional<any>\n ? Partial<InferInteropZodOutput<TContextSchema>>\n : never\n >\n )\n );\n }\n\n if (config.afterModel) {\n middleware.afterModel = async (state, runtime) =>\n Promise.resolve(\n config.afterModel!(\n state,\n runtime as Runtime<\n (TSchema extends InteropZodObject\n ? InferInteropZodInput<TSchema>\n : {}) &\n AgentBuiltInState,\n TContextSchema extends InteropZodObject\n ? InferInteropZodOutput<TContextSchema>\n : TContextSchema extends InteropZodDefault<any>\n ? InferInteropZodOutput<TContextSchema>\n : TContextSchema extends InteropZodOptional<any>\n ? Partial<InferInteropZodOutput<TContextSchema>>\n : never\n >\n )\n );\n }\n\n return middleware;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgDA,SAAgB,iBAOdA,QA+IgD;CAChD,MAAMC,aAA4D;EAChE,MAAM,OAAO;EACb,aAAa,OAAO;EACpB,eAAe,OAAO;EACtB,mBAAmB,OAAO;EAC1B,kBAAkB,OAAO;EACzB,OAAO,OAAO,SAAS,CAAE;CAC1B;AAED,KAAI,OAAO,oBACT,WAAW,qBAAqB,OAAO,SAAS,OAAO,YACrD,QAAQ,QACN,OAAO,mBACL,SACA,OACA,QAaD,CACF;AAGL,KAAI,OAAO,aACT,WAAW,cAAc,OAAO,OAAO,YACrC,QAAQ,QACN,OAAO,YACL,OACA,QAaD,CACF;AAGL,KAAI,OAAO,YACT,WAAW,aAAa,OAAO,OAAO,YACpC,QAAQ,QACN,OAAO,WACL,OACA,QAaD,CACF;AAGL,QAAO;AACR"}
@@ -19,8 +19,8 @@ var AfterModelNode = class extends require_middleware.MiddlewareNode {
19
19
  this.middleware = middleware;
20
20
  this.name = `AfterModelNode_${middleware.name}`;
21
21
  }
22
- runHook(state, runtime, controls) {
23
- return this.middleware.afterModel(state, runtime, controls);
22
+ runHook(state, runtime) {
23
+ return this.middleware.afterModel(state, runtime);
24
24
  }
25
25
  };
26
26
 
@@ -1 +1 @@
1
- {"version":3,"file":"AfterModalNode.cjs","names":["MiddlewareNode","middleware: AgentMiddleware<any, any, any>","state: TStateSchema","config?: LangGraphRunnableConfig","runtime: Runtime<TContextSchema>","controls: Controls<TStateSchema>"],"sources":["../../../../src/agents/middlewareAgent/nodes/AfterModalNode.ts"],"sourcesContent":["import { LangGraphRunnableConfig } from \"@langchain/langgraph\";\nimport { MiddlewareNode } from \"./middleware.js\";\nimport type {\n Controls,\n AgentMiddleware,\n MiddlewareResult,\n Runtime,\n} from \"../types.js\";\n\n/**\n * Node for executing a single middleware's afterModel hook.\n */\nexport class AfterModelNode<\n TStateSchema extends Record<string, any> = Record<string, any>,\n TContextSchema extends Record<string, any> = Record<string, any>\n> extends MiddlewareNode<TStateSchema, TContextSchema> {\n lc_namespace = [\"langchain\", \"agents\", \"afterModalNodes\"];\n\n name: string;\n\n constructor(public middleware: AgentMiddleware<any, any, any>) {\n super({\n name: `AfterModelNode_${middleware.name}`,\n func: async (state: TStateSchema, config?: LangGraphRunnableConfig) =>\n this.invokeMiddleware(state, config),\n });\n this.name = `AfterModelNode_${middleware.name}`;\n }\n\n runHook(\n state: TStateSchema,\n runtime: Runtime<TContextSchema>,\n controls: Controls<TStateSchema>\n ) {\n return this.middleware.afterModel!(state, runtime, controls) as Promise<\n MiddlewareResult<TStateSchema>\n >;\n }\n}\n"],"mappings":";;;;;;AAYA,IAAa,iBAAb,cAGUA,kCAA6C;CACrD,eAAe;EAAC;EAAa;EAAU;CAAkB;CAEzD;CAEA,YAAmBC,YAA4C;EAC7D,MAAM;GACJ,MAAM,CAAC,eAAe,EAAE,WAAW,MAAM;GACzC,MAAM,OAAOC,OAAqBC,WAChC,KAAK,iBAAiB,OAAO,OAAO;EACvC,EAAC;EALe;EAMjB,KAAK,OAAO,CAAC,eAAe,EAAE,WAAW,MAAM;CAChD;CAED,QACED,OACAE,SACAC,UACA;AACA,SAAO,KAAK,WAAW,WAAY,OAAO,SAAS,SAAS;CAG7D;AACF"}
1
+ {"version":3,"file":"AfterModalNode.cjs","names":["MiddlewareNode","middleware: AgentMiddleware<any, any, any>","state: TStateSchema","config?: LangGraphRunnableConfig","runtime: Runtime<TStateSchema, TContextSchema>"],"sources":["../../../../src/agents/middlewareAgent/nodes/AfterModalNode.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { LangGraphRunnableConfig } from \"@langchain/langgraph\";\nimport { MiddlewareNode } from \"./middleware.js\";\nimport type {\n AgentBuiltInState,\n AgentMiddleware,\n MiddlewareResult,\n Runtime,\n} from \"../types.js\";\n\n/**\n * Node for executing a single middleware's afterModel hook.\n */\nexport class AfterModelNode<\n TStateSchema extends Record<string, any> = Record<string, any>,\n TContextSchema extends Record<string, any> = Record<string, any>\n> extends MiddlewareNode<TStateSchema, TContextSchema> {\n lc_namespace = [\"langchain\", \"agents\", \"afterModalNodes\"];\n\n name: string;\n\n constructor(public middleware: AgentMiddleware<any, any, any>) {\n super({\n name: `AfterModelNode_${middleware.name}`,\n func: async (state: TStateSchema, config?: LangGraphRunnableConfig) =>\n this.invokeMiddleware(state, config),\n });\n this.name = `AfterModelNode_${middleware.name}`;\n }\n\n runHook(state: TStateSchema, runtime: Runtime<TStateSchema, TContextSchema>) {\n return this.middleware.afterModel!(\n state as Record<string, any> & AgentBuiltInState,\n runtime as Runtime<TStateSchema, unknown>\n ) as Promise<MiddlewareResult<TStateSchema>>;\n }\n}\n"],"mappings":";;;;;;AAaA,IAAa,iBAAb,cAGUA,kCAA6C;CACrD,eAAe;EAAC;EAAa;EAAU;CAAkB;CAEzD;CAEA,YAAmBC,YAA4C;EAC7D,MAAM;GACJ,MAAM,CAAC,eAAe,EAAE,WAAW,MAAM;GACzC,MAAM,OAAOC,OAAqBC,WAChC,KAAK,iBAAiB,OAAO,OAAO;EACvC,EAAC;EALe;EAMjB,KAAK,OAAO,CAAC,eAAe,EAAE,WAAW,MAAM;CAChD;CAED,QAAQD,OAAqBE,SAAgD;AAC3E,SAAO,KAAK,WAAW,WACrB,OACA,QACD;CACF;AACF"}
@@ -19,8 +19,8 @@ var AfterModelNode = class extends MiddlewareNode {
19
19
  this.middleware = middleware;
20
20
  this.name = `AfterModelNode_${middleware.name}`;
21
21
  }
22
- runHook(state, runtime, controls) {
23
- return this.middleware.afterModel(state, runtime, controls);
22
+ runHook(state, runtime) {
23
+ return this.middleware.afterModel(state, runtime);
24
24
  }
25
25
  };
26
26
 
@@ -1 +1 @@
1
- {"version":3,"file":"AfterModalNode.js","names":["middleware: AgentMiddleware<any, any, any>","state: TStateSchema","config?: LangGraphRunnableConfig","runtime: Runtime<TContextSchema>","controls: Controls<TStateSchema>"],"sources":["../../../../src/agents/middlewareAgent/nodes/AfterModalNode.ts"],"sourcesContent":["import { LangGraphRunnableConfig } from \"@langchain/langgraph\";\nimport { MiddlewareNode } from \"./middleware.js\";\nimport type {\n Controls,\n AgentMiddleware,\n MiddlewareResult,\n Runtime,\n} from \"../types.js\";\n\n/**\n * Node for executing a single middleware's afterModel hook.\n */\nexport class AfterModelNode<\n TStateSchema extends Record<string, any> = Record<string, any>,\n TContextSchema extends Record<string, any> = Record<string, any>\n> extends MiddlewareNode<TStateSchema, TContextSchema> {\n lc_namespace = [\"langchain\", \"agents\", \"afterModalNodes\"];\n\n name: string;\n\n constructor(public middleware: AgentMiddleware<any, any, any>) {\n super({\n name: `AfterModelNode_${middleware.name}`,\n func: async (state: TStateSchema, config?: LangGraphRunnableConfig) =>\n this.invokeMiddleware(state, config),\n });\n this.name = `AfterModelNode_${middleware.name}`;\n }\n\n runHook(\n state: TStateSchema,\n runtime: Runtime<TContextSchema>,\n controls: Controls<TStateSchema>\n ) {\n return this.middleware.afterModel!(state, runtime, controls) as Promise<\n MiddlewareResult<TStateSchema>\n >;\n }\n}\n"],"mappings":";;;;;;AAYA,IAAa,iBAAb,cAGU,eAA6C;CACrD,eAAe;EAAC;EAAa;EAAU;CAAkB;CAEzD;CAEA,YAAmBA,YAA4C;EAC7D,MAAM;GACJ,MAAM,CAAC,eAAe,EAAE,WAAW,MAAM;GACzC,MAAM,OAAOC,OAAqBC,WAChC,KAAK,iBAAiB,OAAO,OAAO;EACvC,EAAC;EALe;EAMjB,KAAK,OAAO,CAAC,eAAe,EAAE,WAAW,MAAM;CAChD;CAED,QACED,OACAE,SACAC,UACA;AACA,SAAO,KAAK,WAAW,WAAY,OAAO,SAAS,SAAS;CAG7D;AACF"}
1
+ {"version":3,"file":"AfterModalNode.js","names":["middleware: AgentMiddleware<any, any, any>","state: TStateSchema","config?: LangGraphRunnableConfig","runtime: Runtime<TStateSchema, TContextSchema>"],"sources":["../../../../src/agents/middlewareAgent/nodes/AfterModalNode.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { LangGraphRunnableConfig } from \"@langchain/langgraph\";\nimport { MiddlewareNode } from \"./middleware.js\";\nimport type {\n AgentBuiltInState,\n AgentMiddleware,\n MiddlewareResult,\n Runtime,\n} from \"../types.js\";\n\n/**\n * Node for executing a single middleware's afterModel hook.\n */\nexport class AfterModelNode<\n TStateSchema extends Record<string, any> = Record<string, any>,\n TContextSchema extends Record<string, any> = Record<string, any>\n> extends MiddlewareNode<TStateSchema, TContextSchema> {\n lc_namespace = [\"langchain\", \"agents\", \"afterModalNodes\"];\n\n name: string;\n\n constructor(public middleware: AgentMiddleware<any, any, any>) {\n super({\n name: `AfterModelNode_${middleware.name}`,\n func: async (state: TStateSchema, config?: LangGraphRunnableConfig) =>\n this.invokeMiddleware(state, config),\n });\n this.name = `AfterModelNode_${middleware.name}`;\n }\n\n runHook(state: TStateSchema, runtime: Runtime<TStateSchema, TContextSchema>) {\n return this.middleware.afterModel!(\n state as Record<string, any> & AgentBuiltInState,\n runtime as Runtime<TStateSchema, unknown>\n ) as Promise<MiddlewareResult<TStateSchema>>;\n }\n}\n"],"mappings":";;;;;;AAaA,IAAa,iBAAb,cAGU,eAA6C;CACrD,eAAe;EAAC;EAAa;EAAU;CAAkB;CAEzD;CAEA,YAAmBA,YAA4C;EAC7D,MAAM;GACJ,MAAM,CAAC,eAAe,EAAE,WAAW,MAAM;GACzC,MAAM,OAAOC,OAAqBC,WAChC,KAAK,iBAAiB,OAAO,OAAO;EACvC,EAAC;EALe;EAMjB,KAAK,OAAO,CAAC,eAAe,EAAE,WAAW,MAAM;CAChD;CAED,QAAQD,OAAqBE,SAAgD;AAC3E,SAAO,KAAK,WAAW,WACrB,OACA,QACD;CACF;AACF"}