@langchain/core 1.0.0-alpha.6 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (245) hide show
  1. package/CHANGELOG.md +131 -0
  2. package/LICENSE +6 -6
  3. package/README.md +2 -23
  4. package/dist/agents.d.ts.map +1 -1
  5. package/dist/caches/base.d.cts.map +1 -1
  6. package/dist/callbacks/base.d.cts.map +1 -1
  7. package/dist/callbacks/base.d.ts.map +1 -1
  8. package/dist/callbacks/manager.cjs +9 -64
  9. package/dist/callbacks/manager.cjs.map +1 -1
  10. package/dist/callbacks/manager.d.cts +1 -23
  11. package/dist/callbacks/manager.d.cts.map +1 -1
  12. package/dist/callbacks/manager.d.ts +1 -23
  13. package/dist/callbacks/manager.d.ts.map +1 -1
  14. package/dist/callbacks/manager.js +10 -63
  15. package/dist/callbacks/manager.js.map +1 -1
  16. package/dist/chat_history.cjs +0 -4
  17. package/dist/chat_history.cjs.map +1 -1
  18. package/dist/chat_history.d.cts +1 -3
  19. package/dist/chat_history.d.cts.map +1 -1
  20. package/dist/chat_history.d.ts +1 -3
  21. package/dist/chat_history.d.ts.map +1 -1
  22. package/dist/chat_history.js +0 -4
  23. package/dist/chat_history.js.map +1 -1
  24. package/dist/document_loaders/base.cjs +1 -13
  25. package/dist/document_loaders/base.cjs.map +1 -1
  26. package/dist/document_loaders/base.d.cts +0 -9
  27. package/dist/document_loaders/base.d.cts.map +1 -1
  28. package/dist/document_loaders/base.d.ts +0 -9
  29. package/dist/document_loaders/base.d.ts.map +1 -1
  30. package/dist/document_loaders/base.js +1 -13
  31. package/dist/document_loaders/base.js.map +1 -1
  32. package/dist/document_loaders/langsmith.d.cts +1 -1
  33. package/dist/language_models/base.cjs.map +1 -1
  34. package/dist/language_models/base.d.cts +0 -16
  35. package/dist/language_models/base.d.cts.map +1 -1
  36. package/dist/language_models/base.d.ts +0 -16
  37. package/dist/language_models/base.d.ts.map +1 -1
  38. package/dist/language_models/base.js.map +1 -1
  39. package/dist/language_models/chat_models.cjs +10 -83
  40. package/dist/language_models/chat_models.cjs.map +1 -1
  41. package/dist/language_models/chat_models.d.cts +21 -55
  42. package/dist/language_models/chat_models.d.cts.map +1 -1
  43. package/dist/language_models/chat_models.d.ts +21 -55
  44. package/dist/language_models/chat_models.d.ts.map +1 -1
  45. package/dist/language_models/chat_models.js +11 -83
  46. package/dist/language_models/chat_models.js.map +1 -1
  47. package/dist/language_models/llms.cjs +0 -56
  48. package/dist/language_models/llms.cjs.map +1 -1
  49. package/dist/language_models/llms.d.cts +1 -43
  50. package/dist/language_models/llms.d.cts.map +1 -1
  51. package/dist/language_models/llms.d.ts +1 -43
  52. package/dist/language_models/llms.d.ts.map +1 -1
  53. package/dist/language_models/llms.js +0 -56
  54. package/dist/language_models/llms.js.map +1 -1
  55. package/dist/load/import_map.cjs +1 -7
  56. package/dist/load/import_map.cjs.map +1 -1
  57. package/dist/load/import_map.js +1 -7
  58. package/dist/load/import_map.js.map +1 -1
  59. package/dist/messages/ai.cjs +4 -0
  60. package/dist/messages/ai.cjs.map +1 -1
  61. package/dist/messages/ai.js +4 -0
  62. package/dist/messages/ai.js.map +1 -1
  63. package/dist/messages/block_translators/anthropic.cjs +191 -144
  64. package/dist/messages/block_translators/anthropic.cjs.map +1 -1
  65. package/dist/messages/block_translators/anthropic.js +191 -144
  66. package/dist/messages/block_translators/anthropic.js.map +1 -1
  67. package/dist/messages/block_translators/index.cjs +2 -2
  68. package/dist/messages/block_translators/index.cjs.map +1 -1
  69. package/dist/messages/block_translators/index.js +4 -4
  70. package/dist/messages/block_translators/index.js.map +1 -1
  71. package/dist/messages/block_translators/openai.cjs +78 -22
  72. package/dist/messages/block_translators/openai.cjs.map +1 -1
  73. package/dist/messages/block_translators/openai.js +78 -22
  74. package/dist/messages/block_translators/openai.js.map +1 -1
  75. package/dist/messages/content/tools.cjs +1 -5
  76. package/dist/messages/content/tools.cjs.map +1 -1
  77. package/dist/messages/content/tools.d.cts +1 -85
  78. package/dist/messages/content/tools.d.cts.map +1 -1
  79. package/dist/messages/content/tools.d.ts +1 -85
  80. package/dist/messages/content/tools.d.ts.map +1 -1
  81. package/dist/messages/content/tools.js +1 -5
  82. package/dist/messages/content/tools.js.map +1 -1
  83. package/dist/messages/metadata.cjs.map +1 -1
  84. package/dist/messages/metadata.d.cts +3 -0
  85. package/dist/messages/metadata.d.cts.map +1 -1
  86. package/dist/messages/metadata.d.ts +3 -0
  87. package/dist/messages/metadata.d.ts.map +1 -1
  88. package/dist/messages/metadata.js.map +1 -1
  89. package/dist/messages/tool.cjs +2 -0
  90. package/dist/messages/tool.cjs.map +1 -1
  91. package/dist/messages/tool.d.cts +2 -0
  92. package/dist/messages/tool.d.cts.map +1 -1
  93. package/dist/messages/tool.d.ts +2 -0
  94. package/dist/messages/tool.d.ts.map +1 -1
  95. package/dist/messages/tool.js +2 -0
  96. package/dist/messages/tool.js.map +1 -1
  97. package/dist/output_parsers/json.cjs +5 -0
  98. package/dist/output_parsers/json.cjs.map +1 -1
  99. package/dist/output_parsers/json.d.cts +2 -0
  100. package/dist/output_parsers/json.d.cts.map +1 -1
  101. package/dist/output_parsers/json.d.ts +2 -0
  102. package/dist/output_parsers/json.d.ts.map +1 -1
  103. package/dist/output_parsers/json.js +5 -0
  104. package/dist/output_parsers/json.js.map +1 -1
  105. package/dist/prompts/base.cjs +0 -36
  106. package/dist/prompts/base.cjs.map +1 -1
  107. package/dist/prompts/base.d.cts +0 -16
  108. package/dist/prompts/base.d.cts.map +1 -1
  109. package/dist/prompts/base.d.ts +0 -16
  110. package/dist/prompts/base.d.ts.map +1 -1
  111. package/dist/prompts/base.js +0 -36
  112. package/dist/prompts/base.js.map +1 -1
  113. package/dist/prompts/chat.cjs +1 -5
  114. package/dist/prompts/chat.cjs.map +1 -1
  115. package/dist/prompts/chat.d.cts +1 -4
  116. package/dist/prompts/chat.d.cts.map +1 -1
  117. package/dist/prompts/chat.d.ts +1 -4
  118. package/dist/prompts/chat.d.ts.map +1 -1
  119. package/dist/prompts/chat.js +1 -5
  120. package/dist/prompts/chat.js.map +1 -1
  121. package/dist/prompts/dict.d.cts +1 -1
  122. package/dist/prompts/dict.d.ts +1 -1
  123. package/dist/prompts/few_shot.d.cts +2 -2
  124. package/dist/prompts/few_shot.d.ts +2 -2
  125. package/dist/prompts/image.d.cts +1 -1
  126. package/dist/prompts/image.d.ts +1 -1
  127. package/dist/prompts/index.d.cts +2 -2
  128. package/dist/prompts/index.d.ts +2 -2
  129. package/dist/prompts/pipeline.d.cts +1 -1
  130. package/dist/prompts/pipeline.d.ts +1 -1
  131. package/dist/prompts/prompt.d.cts +2 -2
  132. package/dist/prompts/prompt.d.ts +2 -2
  133. package/dist/retrievers/index.cjs +3 -18
  134. package/dist/retrievers/index.cjs.map +1 -1
  135. package/dist/retrievers/index.d.cts +2 -27
  136. package/dist/retrievers/index.d.cts.map +1 -1
  137. package/dist/retrievers/index.d.ts +2 -27
  138. package/dist/retrievers/index.d.ts.map +1 -1
  139. package/dist/retrievers/index.js +3 -18
  140. package/dist/retrievers/index.js.map +1 -1
  141. package/dist/runnables/base.cjs +24 -63
  142. package/dist/runnables/base.cjs.map +1 -1
  143. package/dist/runnables/base.d.cts +10 -39
  144. package/dist/runnables/base.d.cts.map +1 -1
  145. package/dist/runnables/base.d.ts +10 -39
  146. package/dist/runnables/base.d.ts.map +1 -1
  147. package/dist/runnables/base.js +24 -63
  148. package/dist/runnables/base.js.map +1 -1
  149. package/dist/runnables/graph.cjs +1 -1
  150. package/dist/runnables/graph.cjs.map +1 -1
  151. package/dist/runnables/graph.js +2 -2
  152. package/dist/runnables/graph.js.map +1 -1
  153. package/dist/runnables/graph_mermaid.cjs +1 -10
  154. package/dist/runnables/graph_mermaid.cjs.map +1 -1
  155. package/dist/runnables/graph_mermaid.js +1 -10
  156. package/dist/runnables/graph_mermaid.js.map +1 -1
  157. package/dist/runnables/history.cjs +1 -1
  158. package/dist/runnables/history.cjs.map +1 -1
  159. package/dist/runnables/history.d.cts +2 -2
  160. package/dist/runnables/history.d.cts.map +1 -1
  161. package/dist/runnables/history.d.ts +2 -2
  162. package/dist/runnables/history.d.ts.map +1 -1
  163. package/dist/runnables/history.js +1 -1
  164. package/dist/runnables/history.js.map +1 -1
  165. package/dist/stores.cjs.map +1 -1
  166. package/dist/stores.d.cts +3 -29
  167. package/dist/stores.d.cts.map +1 -1
  168. package/dist/stores.d.ts +3 -29
  169. package/dist/stores.d.ts.map +1 -1
  170. package/dist/stores.js.map +1 -1
  171. package/dist/tools/index.cjs +12 -4
  172. package/dist/tools/index.cjs.map +1 -1
  173. package/dist/tools/index.js +12 -4
  174. package/dist/tools/index.js.map +1 -1
  175. package/dist/tools/types.cjs.map +1 -1
  176. package/dist/tools/types.d.cts +4 -0
  177. package/dist/tools/types.d.cts.map +1 -1
  178. package/dist/tools/types.d.ts +4 -0
  179. package/dist/tools/types.d.ts.map +1 -1
  180. package/dist/tools/types.js.map +1 -1
  181. package/dist/tracers/base.cjs +1 -1
  182. package/dist/tracers/base.cjs.map +1 -1
  183. package/dist/tracers/base.d.cts +1 -1
  184. package/dist/tracers/base.js +2 -2
  185. package/dist/tracers/base.js.map +1 -1
  186. package/dist/tracers/log_stream.d.cts +1 -1
  187. package/dist/tracers/log_stream.d.ts +1 -1
  188. package/dist/tracers/tracer_langchain.cjs +1 -0
  189. package/dist/tracers/tracer_langchain.cjs.map +1 -1
  190. package/dist/tracers/tracer_langchain.d.cts +2 -2
  191. package/dist/tracers/tracer_langchain.js +1 -0
  192. package/dist/tracers/tracer_langchain.js.map +1 -1
  193. package/dist/utils/env.cjs +1 -9
  194. package/dist/utils/env.cjs.map +1 -1
  195. package/dist/utils/env.d.cts +2 -6
  196. package/dist/utils/env.d.cts.map +1 -1
  197. package/dist/utils/env.d.ts +2 -6
  198. package/dist/utils/env.d.ts.map +1 -1
  199. package/dist/utils/env.js +2 -9
  200. package/dist/utils/env.js.map +1 -1
  201. package/dist/utils/testing/message_history.cjs +1 -1
  202. package/dist/utils/testing/message_history.cjs.map +1 -1
  203. package/dist/utils/testing/message_history.d.cts +1 -1
  204. package/dist/utils/testing/message_history.d.cts.map +1 -1
  205. package/dist/utils/testing/message_history.d.ts +1 -1
  206. package/dist/utils/testing/message_history.d.ts.map +1 -1
  207. package/dist/utils/testing/message_history.js +1 -1
  208. package/dist/utils/testing/message_history.js.map +1 -1
  209. package/dist/utils/types/index.cjs +6 -0
  210. package/dist/utils/types/index.d.cts +2 -2
  211. package/dist/utils/types/index.d.ts +2 -2
  212. package/dist/utils/types/index.js +5 -2
  213. package/dist/utils/types/zod.cjs +23 -0
  214. package/dist/utils/types/zod.cjs.map +1 -1
  215. package/dist/utils/types/zod.d.cts +11 -1
  216. package/dist/utils/types/zod.d.cts.map +1 -1
  217. package/dist/utils/types/zod.d.ts +11 -1
  218. package/dist/utils/types/zod.d.ts.map +1 -1
  219. package/dist/utils/types/zod.js +21 -1
  220. package/dist/utils/types/zod.js.map +1 -1
  221. package/package.json +121 -154
  222. package/dist/runnables/remote.cjs +0 -399
  223. package/dist/runnables/remote.cjs.map +0 -1
  224. package/dist/runnables/remote.d.cts +0 -73
  225. package/dist/runnables/remote.d.cts.map +0 -1
  226. package/dist/runnables/remote.d.ts +0 -73
  227. package/dist/runnables/remote.d.ts.map +0 -1
  228. package/dist/runnables/remote.js +0 -393
  229. package/dist/runnables/remote.js.map +0 -1
  230. package/dist/tracers/initialize.cjs +0 -46
  231. package/dist/tracers/initialize.cjs.map +0 -1
  232. package/dist/tracers/initialize.d.cts +0 -26
  233. package/dist/tracers/initialize.d.cts.map +0 -1
  234. package/dist/tracers/initialize.d.ts +0 -26
  235. package/dist/tracers/initialize.d.ts.map +0 -1
  236. package/dist/tracers/initialize.js +0 -39
  237. package/dist/tracers/initialize.js.map +0 -1
  238. package/dist/tracers/tracer_langchain_v1.cjs +0 -168
  239. package/dist/tracers/tracer_langchain_v1.cjs.map +0 -1
  240. package/dist/tracers/tracer_langchain_v1.d.cts +0 -64
  241. package/dist/tracers/tracer_langchain_v1.d.cts.map +0 -1
  242. package/dist/tracers/tracer_langchain_v1.d.ts +0 -64
  243. package/dist/tracers/tracer_langchain_v1.d.ts.map +0 -1
  244. package/dist/tracers/tracer_langchain_v1.js +0 -162
  245. package/dist/tracers/tracer_langchain_v1.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"stores.cjs","names":["Serializable","keys: string[]","keyValuePairs: [string, T][]","prefix?: string | undefined"],"sources":["../src/stores.ts"],"sourcesContent":["import { Serializable } from \"./load/serializable.js\";\n\n/** @deprecated For backwards compatibility only. Remove on next minor version upgrade. */\nexport interface BaseStoreInterface<K, V> {\n /**\n * Method to get multiple values for a set of keys.\n * @param {K[]} keys - An array of keys.\n * @returns {Promise<(V | undefined)[]>} - A Promise that resolves with array of values or undefined if key not found.\n */\n mget(keys: K[]): Promise<(V | undefined)[]>;\n\n /**\n * Method to set a value for multiple keys.\n * @param {[K, V][]} keyValuePairs - An array of key-value pairs.\n * @returns {Promise<void>} - A Promise that resolves when the operation is complete.\n */\n mset(keyValuePairs: [K, V][]): Promise<void>;\n\n /**\n * Method to delete multiple keys.\n * @param {K[]} keys - An array of keys to delete.\n * @returns {Promise<void>} - A Promise that resolves when the operation is complete.\n */\n mdelete(keys: K[]): Promise<void>;\n\n /**\n * Method to yield keys optionally based on a prefix.\n * @param {string} prefix - Optional prefix to filter keys.\n * @returns {AsyncGenerator<K | string>} - An asynchronous generator that yields keys on iteration.\n */\n yieldKeys(prefix?: string): AsyncGenerator<K | string>;\n}\n\n/**\n * Abstract interface for a key-value store.\n */\nexport abstract class BaseStore<K, V>\n extends Serializable\n implements BaseStoreInterface<K, V>\n{\n /**\n * Abstract method to get multiple values for a set of keys.\n * @param {K[]} keys - An array of keys.\n * @returns {Promise<(V | undefined)[]>} - A Promise that resolves with array of values or undefined if key not found.\n */\n abstract mget(keys: K[]): Promise<(V | undefined)[]>;\n\n /**\n * Abstract method to set a value for multiple keys.\n * @param {[K, V][]} keyValuePairs - An array of key-value pairs.\n * @returns {Promise<void>} - A Promise that resolves when the operation is complete.\n */\n abstract mset(keyValuePairs: [K, V][]): Promise<void>;\n\n /**\n * Abstract method to delete multiple keys.\n * @param {K[]} keys - An array of keys to delete.\n * @returns {Promise<void>} - A Promise that resolves when the operation is complete.\n */\n abstract mdelete(keys: K[]): Promise<void>;\n\n /**\n * Abstract method to yield keys optionally based on a prefix.\n * @param {string} prefix - Optional prefix to filter keys.\n * @returns {AsyncGenerator<K | string>} - An asynchronous generator that yields keys on iteration.\n */\n abstract yieldKeys(prefix?: string): AsyncGenerator<K | string>;\n}\n\n/**\n * In-memory implementation of the BaseStore using a dictionary. Used for\n * storing key-value pairs in memory.\n * @example\n * ```typescript\n * const store = new InMemoryStore<BaseMessage>();\n * await store.mset(\n * Array.from({ length: 5 }).map((_, index) => [\n * `message:id:${index}`,\n * index % 2 === 0\n * ? new AIMessage(\"ai stuff...\")\n * : new HumanMessage(\"human stuff...\"),\n * ]),\n * );\n *\n * const retrievedMessages = await store.mget([\"message:id:0\", \"message:id:1\"]);\n * await store.mdelete(await store.yieldKeys(\"message:id:\").toArray());\n * ```\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport class InMemoryStore<T = any> extends BaseStore<string, T> {\n lc_namespace = [\"langchain\", \"storage\"];\n\n protected store: Record<string, T> = {};\n\n /**\n * Retrieves the values associated with the given keys from the store.\n * @param keys Keys to retrieve values for.\n * @returns Array of values associated with the given keys.\n */\n async mget(keys: string[]) {\n return keys.map((key) => this.store[key]);\n }\n\n /**\n * Sets the values for the given keys in the store.\n * @param keyValuePairs Array of key-value pairs to set in the store.\n * @returns Promise that resolves when all key-value pairs have been set.\n */\n async mset(keyValuePairs: [string, T][]): Promise<void> {\n for (const [key, value] of keyValuePairs) {\n this.store[key] = value;\n }\n }\n\n /**\n * Deletes the given keys and their associated values from the store.\n * @param keys Keys to delete from the store.\n * @returns Promise that resolves when all keys have been deleted.\n */\n async mdelete(keys: string[]): Promise<void> {\n for (const key of keys) {\n delete this.store[key];\n }\n }\n\n /**\n * Asynchronous generator that yields keys from the store. If a prefix is\n * provided, it only yields keys that start with the prefix.\n * @param prefix Optional prefix to filter keys.\n * @returns AsyncGenerator that yields keys from the store.\n */\n async *yieldKeys(prefix?: string | undefined): AsyncGenerator<string> {\n const keys = Object.keys(this.store);\n for (const key of keys) {\n if (prefix === undefined || key.startsWith(prefix)) {\n yield key;\n }\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;AAoCA,IAAsB,YAAtB,cACUA,uCAEV,CA4BC;;;;;;;;;;;;;;;;;;;;AAsBD,IAAa,gBAAb,cAA4C,UAAqB;CAC/D,eAAe,CAAC,aAAa,SAAU;CAEvC,AAAU,QAA2B,CAAE;;;;;;CAOvC,MAAM,KAAKC,MAAgB;AACzB,SAAO,KAAK,IAAI,CAAC,QAAQ,KAAK,MAAM,KAAK;CAC1C;;;;;;CAOD,MAAM,KAAKC,eAA6C;AACtD,OAAK,MAAM,CAAC,KAAK,MAAM,IAAI,eACzB,KAAK,MAAM,OAAO;CAErB;;;;;;CAOD,MAAM,QAAQD,MAA+B;AAC3C,OAAK,MAAM,OAAO,MAChB,OAAO,KAAK,MAAM;CAErB;;;;;;;CAQD,OAAO,UAAUE,QAAqD;EACpE,MAAM,OAAO,OAAO,KAAK,KAAK,MAAM;AACpC,OAAK,MAAM,OAAO,KAChB,KAAI,WAAW,UAAa,IAAI,WAAW,OAAO,EAChD,MAAM;CAGX;AACF"}
1
+ {"version":3,"file":"stores.cjs","names":["Serializable","keys: string[]","keyValuePairs: [string, T][]","prefix?: string | undefined"],"sources":["../src/stores.ts"],"sourcesContent":["import { Serializable } from \"./load/serializable.js\";\n\n/**\n * Abstract interface for a key-value store.\n */\nexport abstract class BaseStore<K, V> extends Serializable {\n /**\n * Abstract method to get multiple values for a set of keys.\n * @param {K[]} keys - An array of keys.\n * @returns {Promise<(V | undefined)[]>} - A Promise that resolves with array of values or undefined if key not found.\n */\n abstract mget(keys: K[]): Promise<(V | undefined)[]>;\n\n /**\n * Abstract method to set a value for multiple keys.\n * @param {[K, V][]} keyValuePairs - An array of key-value pairs.\n * @returns {Promise<void>} - A Promise that resolves when the operation is complete.\n */\n abstract mset(keyValuePairs: [K, V][]): Promise<void>;\n\n /**\n * Abstract method to delete multiple keys.\n * @param {K[]} keys - An array of keys to delete.\n * @returns {Promise<void>} - A Promise that resolves when the operation is complete.\n */\n abstract mdelete(keys: K[]): Promise<void>;\n\n /**\n * Abstract method to yield keys optionally based on a prefix.\n * @param {string} prefix - Optional prefix to filter keys.\n * @returns {AsyncGenerator<K | string>} - An asynchronous generator that yields keys on iteration.\n */\n abstract yieldKeys(prefix?: string): AsyncGenerator<K | string>;\n}\n\n/**\n * In-memory implementation of the BaseStore using a dictionary. Used for\n * storing key-value pairs in memory.\n * @example\n * ```typescript\n * const store = new InMemoryStore<BaseMessage>();\n * await store.mset(\n * Array.from({ length: 5 }).map((_, index) => [\n * `message:id:${index}`,\n * index % 2 === 0\n * ? new AIMessage(\"ai stuff...\")\n * : new HumanMessage(\"human stuff...\"),\n * ]),\n * );\n *\n * const retrievedMessages = await store.mget([\"message:id:0\", \"message:id:1\"]);\n * await store.mdelete(await store.yieldKeys(\"message:id:\").toArray());\n * ```\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport class InMemoryStore<T = any> extends BaseStore<string, T> {\n lc_namespace = [\"langchain\", \"storage\"];\n\n protected store: Record<string, T> = {};\n\n /**\n * Retrieves the values associated with the given keys from the store.\n * @param keys Keys to retrieve values for.\n * @returns Array of values associated with the given keys.\n */\n async mget(keys: string[]) {\n return keys.map((key) => this.store[key]);\n }\n\n /**\n * Sets the values for the given keys in the store.\n * @param keyValuePairs Array of key-value pairs to set in the store.\n * @returns Promise that resolves when all key-value pairs have been set.\n */\n async mset(keyValuePairs: [string, T][]): Promise<void> {\n for (const [key, value] of keyValuePairs) {\n this.store[key] = value;\n }\n }\n\n /**\n * Deletes the given keys and their associated values from the store.\n * @param keys Keys to delete from the store.\n * @returns Promise that resolves when all keys have been deleted.\n */\n async mdelete(keys: string[]): Promise<void> {\n for (const key of keys) {\n delete this.store[key];\n }\n }\n\n /**\n * Asynchronous generator that yields keys from the store. If a prefix is\n * provided, it only yields keys that start with the prefix.\n * @param prefix Optional prefix to filter keys.\n * @returns AsyncGenerator that yields keys from the store.\n */\n async *yieldKeys(prefix?: string | undefined): AsyncGenerator<string> {\n const keys = Object.keys(this.store);\n for (const key of keys) {\n if (prefix === undefined || key.startsWith(prefix)) {\n yield key;\n }\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;AAKA,IAAsB,YAAtB,cAA8CA,uCAAa,CA4B1D;;;;;;;;;;;;;;;;;;;;AAsBD,IAAa,gBAAb,cAA4C,UAAqB;CAC/D,eAAe,CAAC,aAAa,SAAU;CAEvC,AAAU,QAA2B,CAAE;;;;;;CAOvC,MAAM,KAAKC,MAAgB;AACzB,SAAO,KAAK,IAAI,CAAC,QAAQ,KAAK,MAAM,KAAK;CAC1C;;;;;;CAOD,MAAM,KAAKC,eAA6C;AACtD,OAAK,MAAM,CAAC,KAAK,MAAM,IAAI,eACzB,KAAK,MAAM,OAAO;CAErB;;;;;;CAOD,MAAM,QAAQD,MAA+B;AAC3C,OAAK,MAAM,OAAO,MAChB,OAAO,KAAK,MAAM;CAErB;;;;;;;CAQD,OAAO,UAAUE,QAAqD;EACpE,MAAM,OAAO,OAAO,KAAK,KAAK,MAAM;AACpC,OAAK,MAAM,OAAO,KAChB,KAAI,WAAW,UAAa,IAAI,WAAW,OAAO,EAChD,MAAM;CAGX;AACF"}
package/dist/stores.d.cts CHANGED
@@ -1,37 +1,11 @@
1
1
  import { Serializable } from "./load/serializable.cjs";
2
2
 
3
3
  //#region src/stores.d.ts
4
- /** @deprecated For backwards compatibility only. Remove on next minor version upgrade. */
5
- interface BaseStoreInterface<K, V> {
6
- /**
7
- * Method to get multiple values for a set of keys.
8
- * @param {K[]} keys - An array of keys.
9
- * @returns {Promise<(V | undefined)[]>} - A Promise that resolves with array of values or undefined if key not found.
10
- */
11
- mget(keys: K[]): Promise<(V | undefined)[]>;
12
- /**
13
- * Method to set a value for multiple keys.
14
- * @param {[K, V][]} keyValuePairs - An array of key-value pairs.
15
- * @returns {Promise<void>} - A Promise that resolves when the operation is complete.
16
- */
17
- mset(keyValuePairs: [K, V][]): Promise<void>;
18
- /**
19
- * Method to delete multiple keys.
20
- * @param {K[]} keys - An array of keys to delete.
21
- * @returns {Promise<void>} - A Promise that resolves when the operation is complete.
22
- */
23
- mdelete(keys: K[]): Promise<void>;
24
- /**
25
- * Method to yield keys optionally based on a prefix.
26
- * @param {string} prefix - Optional prefix to filter keys.
27
- * @returns {AsyncGenerator<K | string>} - An asynchronous generator that yields keys on iteration.
28
- */
29
- yieldKeys(prefix?: string): AsyncGenerator<K | string>;
30
- }
4
+
31
5
  /**
32
6
  * Abstract interface for a key-value store.
33
7
  */
34
- declare abstract class BaseStore<K, V> extends Serializable implements BaseStoreInterface<K, V> {
8
+ declare abstract class BaseStore<K, V> extends Serializable {
35
9
  /**
36
10
  * Abstract method to get multiple values for a set of keys.
37
11
  * @param {K[]} keys - An array of keys.
@@ -107,5 +81,5 @@ declare class InMemoryStore<T = any> extends BaseStore<string, T> {
107
81
  yieldKeys(prefix?: string | undefined): AsyncGenerator<string>;
108
82
  }
109
83
  //#endregion
110
- export { BaseStore, BaseStoreInterface, InMemoryStore };
84
+ export { BaseStore, InMemoryStore };
111
85
  //# sourceMappingURL=stores.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"stores.d.cts","names":["Serializable","BaseStoreInterface","K","V","Promise","AsyncGenerator","BaseStore","InMemoryStore","T","Record"],"sources":["../src/stores.d.ts"],"sourcesContent":["import { Serializable } from \"./load/serializable.js\";\n/** @deprecated For backwards compatibility only. Remove on next minor version upgrade. */\nexport interface BaseStoreInterface<K, V> {\n /**\n * Method to get multiple values for a set of keys.\n * @param {K[]} keys - An array of keys.\n * @returns {Promise<(V | undefined)[]>} - A Promise that resolves with array of values or undefined if key not found.\n */\n mget(keys: K[]): Promise<(V | undefined)[]>;\n /**\n * Method to set a value for multiple keys.\n * @param {[K, V][]} keyValuePairs - An array of key-value pairs.\n * @returns {Promise<void>} - A Promise that resolves when the operation is complete.\n */\n mset(keyValuePairs: [K, V][]): Promise<void>;\n /**\n * Method to delete multiple keys.\n * @param {K[]} keys - An array of keys to delete.\n * @returns {Promise<void>} - A Promise that resolves when the operation is complete.\n */\n mdelete(keys: K[]): Promise<void>;\n /**\n * Method to yield keys optionally based on a prefix.\n * @param {string} prefix - Optional prefix to filter keys.\n * @returns {AsyncGenerator<K | string>} - An asynchronous generator that yields keys on iteration.\n */\n yieldKeys(prefix?: string): AsyncGenerator<K | string>;\n}\n/**\n * Abstract interface for a key-value store.\n */\nexport declare abstract class BaseStore<K, V> extends Serializable implements BaseStoreInterface<K, V> {\n /**\n * Abstract method to get multiple values for a set of keys.\n * @param {K[]} keys - An array of keys.\n * @returns {Promise<(V | undefined)[]>} - A Promise that resolves with array of values or undefined if key not found.\n */\n abstract mget(keys: K[]): Promise<(V | undefined)[]>;\n /**\n * Abstract method to set a value for multiple keys.\n * @param {[K, V][]} keyValuePairs - An array of key-value pairs.\n * @returns {Promise<void>} - A Promise that resolves when the operation is complete.\n */\n abstract mset(keyValuePairs: [K, V][]): Promise<void>;\n /**\n * Abstract method to delete multiple keys.\n * @param {K[]} keys - An array of keys to delete.\n * @returns {Promise<void>} - A Promise that resolves when the operation is complete.\n */\n abstract mdelete(keys: K[]): Promise<void>;\n /**\n * Abstract method to yield keys optionally based on a prefix.\n * @param {string} prefix - Optional prefix to filter keys.\n * @returns {AsyncGenerator<K | string>} - An asynchronous generator that yields keys on iteration.\n */\n abstract yieldKeys(prefix?: string): AsyncGenerator<K | string>;\n}\n/**\n * In-memory implementation of the BaseStore using a dictionary. Used for\n * storing key-value pairs in memory.\n * @example\n * ```typescript\n * const store = new InMemoryStore<BaseMessage>();\n * await store.mset(\n * Array.from({ length: 5 }).map((_, index) => [\n * `message:id:${index}`,\n * index % 2 === 0\n * ? new AIMessage(\"ai stuff...\")\n * : new HumanMessage(\"human stuff...\"),\n * ]),\n * );\n *\n * const retrievedMessages = await store.mget([\"message:id:0\", \"message:id:1\"]);\n * await store.mdelete(await store.yieldKeys(\"message:id:\").toArray());\n * ```\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport declare class InMemoryStore<T = any> extends BaseStore<string, T> {\n lc_namespace: string[];\n protected store: Record<string, T>;\n /**\n * Retrieves the values associated with the given keys from the store.\n * @param keys Keys to retrieve values for.\n * @returns Array of values associated with the given keys.\n */\n mget(keys: string[]): Promise<T[]>;\n /**\n * Sets the values for the given keys in the store.\n * @param keyValuePairs Array of key-value pairs to set in the store.\n * @returns Promise that resolves when all key-value pairs have been set.\n */\n mset(keyValuePairs: [string, T][]): Promise<void>;\n /**\n * Deletes the given keys and their associated values from the store.\n * @param keys Keys to delete from the store.\n * @returns Promise that resolves when all keys have been deleted.\n */\n mdelete(keys: string[]): Promise<void>;\n /**\n * Asynchronous generator that yields keys from the store. If a prefix is\n * provided, it only yields keys that start with the prefix.\n * @param prefix Optional prefix to filter keys.\n * @returns AsyncGenerator that yields keys from the store.\n */\n yieldKeys(prefix?: string | undefined): AsyncGenerator<string>;\n}\n"],"mappings":";;;;UAEiBC;EAAAA;;;;;EAMW,IAMHC,CAAAA,IAAAA,EANVA,CAMUA,EAAAA,CAAAA,EANJE,OAMIF,CAAAA,CANKC,CAMLD,GAAAA,SAAAA,CAAAA,EAAAA,CAAAA;EAAC;;;;;EAYsB,IAAhBG,CAAAA,aAAAA,EAAAA,CAZPH,CAYOG,EAZJF,CAYIE,CAAAA,EAAAA,CAAAA,EAZGD,OAYHC,CAAAA,IAAAA,CAAAA;EAAc;AAK9C;;;;EAAqG,OAM7EH,CAAAA,IAAAA,EAjBNA,CAiBMA,EAAAA,CAAAA,EAjBAE,OAiBAF,CAAAA,IAAAA,CAAAA;EAAC;;;;;EAM0B,SAMxBA,CAAAA,MAAAA,CAAAA,EAAAA,MAAAA,CAAAA,EAvBKG,cAuBLH,CAvBoBA,CAuBpBA,GAAAA,MAAAA,CAAAA;;;;;AAlBmDD,uBAAhDK,SAAgDL,CAAAA,CAAAA,EAAAA,CAAAA,CAAAA,SAAxBD,YAAAA,YAAwBC,kBAAAA,CAAmBC,CAAnBD,EAAsBE,CAAtBF,CAAAA,CAAAA;EAAkB;AA8ChG;;;;EAEqC,SAAhBQ,IAAAA,CAAAA,IAAAA,EA1CGP,CA0CHO,EAAAA,CAAAA,EA1CSL,OA0CTK,CAAAA,CA1CkBN,CA0ClBM,GAAAA,SAAAA,CAAAA,EAAAA,CAAAA;EAAM;;;;;EAkBS,SAOQJ,IAAAA,CAAAA,aAAAA,EAAAA,CA7DVH,CA6DUG,EA7DPF,CA6DOE,CAAAA,EAAAA,CAAAA,EA7DAD,OA6DAC,CAAAA,IAAAA,CAAAA;EAAc;AA3BG;;;;yBA5BlCH,MAAME;;;;;;uCAMQC,eAAeH;;;;;;;;;;;;;;;;;;;;;;cAsBnCK,+BAA+BD,kBAAkBE;;mBAEjDC,eAAeD;;;;;;wBAMVJ,QAAQI;;;;;;+BAMDA,OAAOJ;;;;;;2BAMXA;;;;;;;0CAOeC"}
1
+ {"version":3,"file":"stores.d.cts","names":["Serializable","BaseStore","K","V","Promise","AsyncGenerator","InMemoryStore","T","Record"],"sources":["../src/stores.d.ts"],"sourcesContent":["import { Serializable } from \"./load/serializable.js\";\n/**\n * Abstract interface for a key-value store.\n */\nexport declare abstract class BaseStore<K, V> extends Serializable {\n /**\n * Abstract method to get multiple values for a set of keys.\n * @param {K[]} keys - An array of keys.\n * @returns {Promise<(V | undefined)[]>} - A Promise that resolves with array of values or undefined if key not found.\n */\n abstract mget(keys: K[]): Promise<(V | undefined)[]>;\n /**\n * Abstract method to set a value for multiple keys.\n * @param {[K, V][]} keyValuePairs - An array of key-value pairs.\n * @returns {Promise<void>} - A Promise that resolves when the operation is complete.\n */\n abstract mset(keyValuePairs: [K, V][]): Promise<void>;\n /**\n * Abstract method to delete multiple keys.\n * @param {K[]} keys - An array of keys to delete.\n * @returns {Promise<void>} - A Promise that resolves when the operation is complete.\n */\n abstract mdelete(keys: K[]): Promise<void>;\n /**\n * Abstract method to yield keys optionally based on a prefix.\n * @param {string} prefix - Optional prefix to filter keys.\n * @returns {AsyncGenerator<K | string>} - An asynchronous generator that yields keys on iteration.\n */\n abstract yieldKeys(prefix?: string): AsyncGenerator<K | string>;\n}\n/**\n * In-memory implementation of the BaseStore using a dictionary. Used for\n * storing key-value pairs in memory.\n * @example\n * ```typescript\n * const store = new InMemoryStore<BaseMessage>();\n * await store.mset(\n * Array.from({ length: 5 }).map((_, index) => [\n * `message:id:${index}`,\n * index % 2 === 0\n * ? new AIMessage(\"ai stuff...\")\n * : new HumanMessage(\"human stuff...\"),\n * ]),\n * );\n *\n * const retrievedMessages = await store.mget([\"message:id:0\", \"message:id:1\"]);\n * await store.mdelete(await store.yieldKeys(\"message:id:\").toArray());\n * ```\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport declare class InMemoryStore<T = any> extends BaseStore<string, T> {\n lc_namespace: string[];\n protected store: Record<string, T>;\n /**\n * Retrieves the values associated with the given keys from the store.\n * @param keys Keys to retrieve values for.\n * @returns Array of values associated with the given keys.\n */\n mget(keys: string[]): Promise<T[]>;\n /**\n * Sets the values for the given keys in the store.\n * @param keyValuePairs Array of key-value pairs to set in the store.\n * @returns Promise that resolves when all key-value pairs have been set.\n */\n mset(keyValuePairs: [string, T][]): Promise<void>;\n /**\n * Deletes the given keys and their associated values from the store.\n * @param keys Keys to delete from the store.\n * @returns Promise that resolves when all keys have been deleted.\n */\n mdelete(keys: string[]): Promise<void>;\n /**\n * Asynchronous generator that yields keys from the store. If a prefix is\n * provided, it only yields keys that start with the prefix.\n * @param prefix Optional prefix to filter keys.\n * @returns AsyncGenerator that yields keys from the store.\n */\n yieldKeys(prefix?: string | undefined): AsyncGenerator<string>;\n}\n"],"mappings":";;;;;;AAIA;AAAuC,uBAATC,SAAS,CAAA,CAAA,EAAA,CAAA,CAAA,SAAeD,YAAAA,CAAf;EAAA;;;;;EAYD,SAAMI,IAAAA,CAAAA,IAAAA,EANpBF,CAMoBE,EAAAA,CAAAA,EANdA,OAMcA,CAAAA,CANLD,CAMKC,GAAAA,SAAAA,CAAAA,EAAAA,CAAAA;EAAO;;;;;EAZe,SAAA,IAAA,CAAA,aAAA,EAAA,CAYhCF,CAZgC,EAY7BC,CAZ6B,CAAA,EAAA,CAAA,EAYtBC,OAZsB,CAAA,IAAA,CAAA;EA8C7CE;;;;;EAEM,SAMOC,OAAAA,CAAAA,IAAAA,EApCPL,CAoCOK,EAAAA,CAAAA,EApCDH,OAoCCG,CAAAA,IAAAA,CAAAA;EAAC;;;;;EAmBuB,SA3BNN,SAAAA,CAAAA,MAAAA,CAAAA,EAAAA,MAAAA,CAAAA,EAtBXI,cAsBWJ,CAtBIC,CAsBJD,GAAAA,MAAAA,CAAAA;AAAS;;;;;;;;;;;;;;;;;;;;;cAAxCK,+BAA+BL,kBAAkBM;;mBAEjDC,eAAeD;;;;;;wBAMVH,QAAQG;;;;;;+BAMDA,OAAOH;;;;;;2BAMXA;;;;;;;0CAOeC"}
package/dist/stores.d.ts CHANGED
@@ -1,37 +1,11 @@
1
1
  import { Serializable } from "./load/serializable.js";
2
2
 
3
3
  //#region src/stores.d.ts
4
- /** @deprecated For backwards compatibility only. Remove on next minor version upgrade. */
5
- interface BaseStoreInterface<K, V> {
6
- /**
7
- * Method to get multiple values for a set of keys.
8
- * @param {K[]} keys - An array of keys.
9
- * @returns {Promise<(V | undefined)[]>} - A Promise that resolves with array of values or undefined if key not found.
10
- */
11
- mget(keys: K[]): Promise<(V | undefined)[]>;
12
- /**
13
- * Method to set a value for multiple keys.
14
- * @param {[K, V][]} keyValuePairs - An array of key-value pairs.
15
- * @returns {Promise<void>} - A Promise that resolves when the operation is complete.
16
- */
17
- mset(keyValuePairs: [K, V][]): Promise<void>;
18
- /**
19
- * Method to delete multiple keys.
20
- * @param {K[]} keys - An array of keys to delete.
21
- * @returns {Promise<void>} - A Promise that resolves when the operation is complete.
22
- */
23
- mdelete(keys: K[]): Promise<void>;
24
- /**
25
- * Method to yield keys optionally based on a prefix.
26
- * @param {string} prefix - Optional prefix to filter keys.
27
- * @returns {AsyncGenerator<K | string>} - An asynchronous generator that yields keys on iteration.
28
- */
29
- yieldKeys(prefix?: string): AsyncGenerator<K | string>;
30
- }
4
+
31
5
  /**
32
6
  * Abstract interface for a key-value store.
33
7
  */
34
- declare abstract class BaseStore<K, V> extends Serializable implements BaseStoreInterface<K, V> {
8
+ declare abstract class BaseStore<K, V> extends Serializable {
35
9
  /**
36
10
  * Abstract method to get multiple values for a set of keys.
37
11
  * @param {K[]} keys - An array of keys.
@@ -107,5 +81,5 @@ declare class InMemoryStore<T = any> extends BaseStore<string, T> {
107
81
  yieldKeys(prefix?: string | undefined): AsyncGenerator<string>;
108
82
  }
109
83
  //#endregion
110
- export { BaseStore, BaseStoreInterface, InMemoryStore };
84
+ export { BaseStore, InMemoryStore };
111
85
  //# sourceMappingURL=stores.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"stores.d.ts","names":["Serializable","BaseStoreInterface","K","V","Promise","AsyncGenerator","BaseStore","InMemoryStore","T","Record"],"sources":["../src/stores.d.ts"],"sourcesContent":["import { Serializable } from \"./load/serializable.js\";\n/** @deprecated For backwards compatibility only. Remove on next minor version upgrade. */\nexport interface BaseStoreInterface<K, V> {\n /**\n * Method to get multiple values for a set of keys.\n * @param {K[]} keys - An array of keys.\n * @returns {Promise<(V | undefined)[]>} - A Promise that resolves with array of values or undefined if key not found.\n */\n mget(keys: K[]): Promise<(V | undefined)[]>;\n /**\n * Method to set a value for multiple keys.\n * @param {[K, V][]} keyValuePairs - An array of key-value pairs.\n * @returns {Promise<void>} - A Promise that resolves when the operation is complete.\n */\n mset(keyValuePairs: [K, V][]): Promise<void>;\n /**\n * Method to delete multiple keys.\n * @param {K[]} keys - An array of keys to delete.\n * @returns {Promise<void>} - A Promise that resolves when the operation is complete.\n */\n mdelete(keys: K[]): Promise<void>;\n /**\n * Method to yield keys optionally based on a prefix.\n * @param {string} prefix - Optional prefix to filter keys.\n * @returns {AsyncGenerator<K | string>} - An asynchronous generator that yields keys on iteration.\n */\n yieldKeys(prefix?: string): AsyncGenerator<K | string>;\n}\n/**\n * Abstract interface for a key-value store.\n */\nexport declare abstract class BaseStore<K, V> extends Serializable implements BaseStoreInterface<K, V> {\n /**\n * Abstract method to get multiple values for a set of keys.\n * @param {K[]} keys - An array of keys.\n * @returns {Promise<(V | undefined)[]>} - A Promise that resolves with array of values or undefined if key not found.\n */\n abstract mget(keys: K[]): Promise<(V | undefined)[]>;\n /**\n * Abstract method to set a value for multiple keys.\n * @param {[K, V][]} keyValuePairs - An array of key-value pairs.\n * @returns {Promise<void>} - A Promise that resolves when the operation is complete.\n */\n abstract mset(keyValuePairs: [K, V][]): Promise<void>;\n /**\n * Abstract method to delete multiple keys.\n * @param {K[]} keys - An array of keys to delete.\n * @returns {Promise<void>} - A Promise that resolves when the operation is complete.\n */\n abstract mdelete(keys: K[]): Promise<void>;\n /**\n * Abstract method to yield keys optionally based on a prefix.\n * @param {string} prefix - Optional prefix to filter keys.\n * @returns {AsyncGenerator<K | string>} - An asynchronous generator that yields keys on iteration.\n */\n abstract yieldKeys(prefix?: string): AsyncGenerator<K | string>;\n}\n/**\n * In-memory implementation of the BaseStore using a dictionary. Used for\n * storing key-value pairs in memory.\n * @example\n * ```typescript\n * const store = new InMemoryStore<BaseMessage>();\n * await store.mset(\n * Array.from({ length: 5 }).map((_, index) => [\n * `message:id:${index}`,\n * index % 2 === 0\n * ? new AIMessage(\"ai stuff...\")\n * : new HumanMessage(\"human stuff...\"),\n * ]),\n * );\n *\n * const retrievedMessages = await store.mget([\"message:id:0\", \"message:id:1\"]);\n * await store.mdelete(await store.yieldKeys(\"message:id:\").toArray());\n * ```\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport declare class InMemoryStore<T = any> extends BaseStore<string, T> {\n lc_namespace: string[];\n protected store: Record<string, T>;\n /**\n * Retrieves the values associated with the given keys from the store.\n * @param keys Keys to retrieve values for.\n * @returns Array of values associated with the given keys.\n */\n mget(keys: string[]): Promise<T[]>;\n /**\n * Sets the values for the given keys in the store.\n * @param keyValuePairs Array of key-value pairs to set in the store.\n * @returns Promise that resolves when all key-value pairs have been set.\n */\n mset(keyValuePairs: [string, T][]): Promise<void>;\n /**\n * Deletes the given keys and their associated values from the store.\n * @param keys Keys to delete from the store.\n * @returns Promise that resolves when all keys have been deleted.\n */\n mdelete(keys: string[]): Promise<void>;\n /**\n * Asynchronous generator that yields keys from the store. If a prefix is\n * provided, it only yields keys that start with the prefix.\n * @param prefix Optional prefix to filter keys.\n * @returns AsyncGenerator that yields keys from the store.\n */\n yieldKeys(prefix?: string | undefined): AsyncGenerator<string>;\n}\n"],"mappings":";;;;UAEiBC;EAAAA;;;;;EAMW,IAMHC,CAAAA,IAAAA,EANVA,CAMUA,EAAAA,CAAAA,EANJE,OAMIF,CAAAA,CANKC,CAMLD,GAAAA,SAAAA,CAAAA,EAAAA,CAAAA;EAAC;;;;;EAYsB,IAAhBG,CAAAA,aAAAA,EAAAA,CAZPH,CAYOG,EAZJF,CAYIE,CAAAA,EAAAA,CAAAA,EAZGD,OAYHC,CAAAA,IAAAA,CAAAA;EAAc;AAK9C;;;;EAAqG,OAM7EH,CAAAA,IAAAA,EAjBNA,CAiBMA,EAAAA,CAAAA,EAjBAE,OAiBAF,CAAAA,IAAAA,CAAAA;EAAC;;;;;EAM0B,SAMxBA,CAAAA,MAAAA,CAAAA,EAAAA,MAAAA,CAAAA,EAvBKG,cAuBLH,CAvBoBA,CAuBpBA,GAAAA,MAAAA,CAAAA;;;;;AAlBmDD,uBAAhDK,SAAgDL,CAAAA,CAAAA,EAAAA,CAAAA,CAAAA,SAAxBD,YAAAA,YAAwBC,kBAAAA,CAAmBC,CAAnBD,EAAsBE,CAAtBF,CAAAA,CAAAA;EAAkB;AA8ChG;;;;EAEqC,SAAhBQ,IAAAA,CAAAA,IAAAA,EA1CGP,CA0CHO,EAAAA,CAAAA,EA1CSL,OA0CTK,CAAAA,CA1CkBN,CA0ClBM,GAAAA,SAAAA,CAAAA,EAAAA,CAAAA;EAAM;;;;;EAkBS,SAOQJ,IAAAA,CAAAA,aAAAA,EAAAA,CA7DVH,CA6DUG,EA7DPF,CA6DOE,CAAAA,EAAAA,CAAAA,EA7DAD,OA6DAC,CAAAA,IAAAA,CAAAA;EAAc;AA3BG;;;;yBA5BlCH,MAAME;;;;;;uCAMQC,eAAeH;;;;;;;;;;;;;;;;;;;;;;cAsBnCK,+BAA+BD,kBAAkBE;;mBAEjDC,eAAeD;;;;;;wBAMVJ,QAAQI;;;;;;+BAMDA,OAAOJ;;;;;;2BAMXA;;;;;;;0CAOeC"}
1
+ {"version":3,"file":"stores.d.ts","names":["Serializable","BaseStore","K","V","Promise","AsyncGenerator","InMemoryStore","T","Record"],"sources":["../src/stores.d.ts"],"sourcesContent":["import { Serializable } from \"./load/serializable.js\";\n/**\n * Abstract interface for a key-value store.\n */\nexport declare abstract class BaseStore<K, V> extends Serializable {\n /**\n * Abstract method to get multiple values for a set of keys.\n * @param {K[]} keys - An array of keys.\n * @returns {Promise<(V | undefined)[]>} - A Promise that resolves with array of values or undefined if key not found.\n */\n abstract mget(keys: K[]): Promise<(V | undefined)[]>;\n /**\n * Abstract method to set a value for multiple keys.\n * @param {[K, V][]} keyValuePairs - An array of key-value pairs.\n * @returns {Promise<void>} - A Promise that resolves when the operation is complete.\n */\n abstract mset(keyValuePairs: [K, V][]): Promise<void>;\n /**\n * Abstract method to delete multiple keys.\n * @param {K[]} keys - An array of keys to delete.\n * @returns {Promise<void>} - A Promise that resolves when the operation is complete.\n */\n abstract mdelete(keys: K[]): Promise<void>;\n /**\n * Abstract method to yield keys optionally based on a prefix.\n * @param {string} prefix - Optional prefix to filter keys.\n * @returns {AsyncGenerator<K | string>} - An asynchronous generator that yields keys on iteration.\n */\n abstract yieldKeys(prefix?: string): AsyncGenerator<K | string>;\n}\n/**\n * In-memory implementation of the BaseStore using a dictionary. Used for\n * storing key-value pairs in memory.\n * @example\n * ```typescript\n * const store = new InMemoryStore<BaseMessage>();\n * await store.mset(\n * Array.from({ length: 5 }).map((_, index) => [\n * `message:id:${index}`,\n * index % 2 === 0\n * ? new AIMessage(\"ai stuff...\")\n * : new HumanMessage(\"human stuff...\"),\n * ]),\n * );\n *\n * const retrievedMessages = await store.mget([\"message:id:0\", \"message:id:1\"]);\n * await store.mdelete(await store.yieldKeys(\"message:id:\").toArray());\n * ```\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport declare class InMemoryStore<T = any> extends BaseStore<string, T> {\n lc_namespace: string[];\n protected store: Record<string, T>;\n /**\n * Retrieves the values associated with the given keys from the store.\n * @param keys Keys to retrieve values for.\n * @returns Array of values associated with the given keys.\n */\n mget(keys: string[]): Promise<T[]>;\n /**\n * Sets the values for the given keys in the store.\n * @param keyValuePairs Array of key-value pairs to set in the store.\n * @returns Promise that resolves when all key-value pairs have been set.\n */\n mset(keyValuePairs: [string, T][]): Promise<void>;\n /**\n * Deletes the given keys and their associated values from the store.\n * @param keys Keys to delete from the store.\n * @returns Promise that resolves when all keys have been deleted.\n */\n mdelete(keys: string[]): Promise<void>;\n /**\n * Asynchronous generator that yields keys from the store. If a prefix is\n * provided, it only yields keys that start with the prefix.\n * @param prefix Optional prefix to filter keys.\n * @returns AsyncGenerator that yields keys from the store.\n */\n yieldKeys(prefix?: string | undefined): AsyncGenerator<string>;\n}\n"],"mappings":";;;;;;AAIA;AAAuC,uBAATC,SAAS,CAAA,CAAA,EAAA,CAAA,CAAA,SAAeD,YAAAA,CAAf;EAAA;;;;;EAYD,SAAMI,IAAAA,CAAAA,IAAAA,EANpBF,CAMoBE,EAAAA,CAAAA,EANdA,OAMcA,CAAAA,CANLD,CAMKC,GAAAA,SAAAA,CAAAA,EAAAA,CAAAA;EAAO;;;;;EAZe,SAAA,IAAA,CAAA,aAAA,EAAA,CAYhCF,CAZgC,EAY7BC,CAZ6B,CAAA,EAAA,CAAA,EAYtBC,OAZsB,CAAA,IAAA,CAAA;EA8C7CE;;;;;EAEM,SAMOC,OAAAA,CAAAA,IAAAA,EApCPL,CAoCOK,EAAAA,CAAAA,EApCDH,OAoCCG,CAAAA,IAAAA,CAAAA;EAAC;;;;;EAmBuB,SA3BNN,SAAAA,CAAAA,MAAAA,CAAAA,EAAAA,MAAAA,CAAAA,EAtBXI,cAsBWJ,CAtBIC,CAsBJD,GAAAA,MAAAA,CAAAA;AAAS;;;;;;;;;;;;;;;;;;;;;cAAxCK,+BAA+BL,kBAAkBM;;mBAEjDC,eAAeD;;;;;;wBAMVH,QAAQG;;;;;;+BAMDA,OAAOH;;;;;;2BAMXA;;;;;;;0CAOeC"}
@@ -1 +1 @@
1
- {"version":3,"file":"stores.js","names":["keys: string[]","keyValuePairs: [string, T][]","prefix?: string | undefined"],"sources":["../src/stores.ts"],"sourcesContent":["import { Serializable } from \"./load/serializable.js\";\n\n/** @deprecated For backwards compatibility only. Remove on next minor version upgrade. */\nexport interface BaseStoreInterface<K, V> {\n /**\n * Method to get multiple values for a set of keys.\n * @param {K[]} keys - An array of keys.\n * @returns {Promise<(V | undefined)[]>} - A Promise that resolves with array of values or undefined if key not found.\n */\n mget(keys: K[]): Promise<(V | undefined)[]>;\n\n /**\n * Method to set a value for multiple keys.\n * @param {[K, V][]} keyValuePairs - An array of key-value pairs.\n * @returns {Promise<void>} - A Promise that resolves when the operation is complete.\n */\n mset(keyValuePairs: [K, V][]): Promise<void>;\n\n /**\n * Method to delete multiple keys.\n * @param {K[]} keys - An array of keys to delete.\n * @returns {Promise<void>} - A Promise that resolves when the operation is complete.\n */\n mdelete(keys: K[]): Promise<void>;\n\n /**\n * Method to yield keys optionally based on a prefix.\n * @param {string} prefix - Optional prefix to filter keys.\n * @returns {AsyncGenerator<K | string>} - An asynchronous generator that yields keys on iteration.\n */\n yieldKeys(prefix?: string): AsyncGenerator<K | string>;\n}\n\n/**\n * Abstract interface for a key-value store.\n */\nexport abstract class BaseStore<K, V>\n extends Serializable\n implements BaseStoreInterface<K, V>\n{\n /**\n * Abstract method to get multiple values for a set of keys.\n * @param {K[]} keys - An array of keys.\n * @returns {Promise<(V | undefined)[]>} - A Promise that resolves with array of values or undefined if key not found.\n */\n abstract mget(keys: K[]): Promise<(V | undefined)[]>;\n\n /**\n * Abstract method to set a value for multiple keys.\n * @param {[K, V][]} keyValuePairs - An array of key-value pairs.\n * @returns {Promise<void>} - A Promise that resolves when the operation is complete.\n */\n abstract mset(keyValuePairs: [K, V][]): Promise<void>;\n\n /**\n * Abstract method to delete multiple keys.\n * @param {K[]} keys - An array of keys to delete.\n * @returns {Promise<void>} - A Promise that resolves when the operation is complete.\n */\n abstract mdelete(keys: K[]): Promise<void>;\n\n /**\n * Abstract method to yield keys optionally based on a prefix.\n * @param {string} prefix - Optional prefix to filter keys.\n * @returns {AsyncGenerator<K | string>} - An asynchronous generator that yields keys on iteration.\n */\n abstract yieldKeys(prefix?: string): AsyncGenerator<K | string>;\n}\n\n/**\n * In-memory implementation of the BaseStore using a dictionary. Used for\n * storing key-value pairs in memory.\n * @example\n * ```typescript\n * const store = new InMemoryStore<BaseMessage>();\n * await store.mset(\n * Array.from({ length: 5 }).map((_, index) => [\n * `message:id:${index}`,\n * index % 2 === 0\n * ? new AIMessage(\"ai stuff...\")\n * : new HumanMessage(\"human stuff...\"),\n * ]),\n * );\n *\n * const retrievedMessages = await store.mget([\"message:id:0\", \"message:id:1\"]);\n * await store.mdelete(await store.yieldKeys(\"message:id:\").toArray());\n * ```\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport class InMemoryStore<T = any> extends BaseStore<string, T> {\n lc_namespace = [\"langchain\", \"storage\"];\n\n protected store: Record<string, T> = {};\n\n /**\n * Retrieves the values associated with the given keys from the store.\n * @param keys Keys to retrieve values for.\n * @returns Array of values associated with the given keys.\n */\n async mget(keys: string[]) {\n return keys.map((key) => this.store[key]);\n }\n\n /**\n * Sets the values for the given keys in the store.\n * @param keyValuePairs Array of key-value pairs to set in the store.\n * @returns Promise that resolves when all key-value pairs have been set.\n */\n async mset(keyValuePairs: [string, T][]): Promise<void> {\n for (const [key, value] of keyValuePairs) {\n this.store[key] = value;\n }\n }\n\n /**\n * Deletes the given keys and their associated values from the store.\n * @param keys Keys to delete from the store.\n * @returns Promise that resolves when all keys have been deleted.\n */\n async mdelete(keys: string[]): Promise<void> {\n for (const key of keys) {\n delete this.store[key];\n }\n }\n\n /**\n * Asynchronous generator that yields keys from the store. If a prefix is\n * provided, it only yields keys that start with the prefix.\n * @param prefix Optional prefix to filter keys.\n * @returns AsyncGenerator that yields keys from the store.\n */\n async *yieldKeys(prefix?: string | undefined): AsyncGenerator<string> {\n const keys = Object.keys(this.store);\n for (const key of keys) {\n if (prefix === undefined || key.startsWith(prefix)) {\n yield key;\n }\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;AAoCA,IAAsB,YAAtB,cACU,aAEV,CA4BC;;;;;;;;;;;;;;;;;;;;AAsBD,IAAa,gBAAb,cAA4C,UAAqB;CAC/D,eAAe,CAAC,aAAa,SAAU;CAEvC,AAAU,QAA2B,CAAE;;;;;;CAOvC,MAAM,KAAKA,MAAgB;AACzB,SAAO,KAAK,IAAI,CAAC,QAAQ,KAAK,MAAM,KAAK;CAC1C;;;;;;CAOD,MAAM,KAAKC,eAA6C;AACtD,OAAK,MAAM,CAAC,KAAK,MAAM,IAAI,eACzB,KAAK,MAAM,OAAO;CAErB;;;;;;CAOD,MAAM,QAAQD,MAA+B;AAC3C,OAAK,MAAM,OAAO,MAChB,OAAO,KAAK,MAAM;CAErB;;;;;;;CAQD,OAAO,UAAUE,QAAqD;EACpE,MAAM,OAAO,OAAO,KAAK,KAAK,MAAM;AACpC,OAAK,MAAM,OAAO,KAChB,KAAI,WAAW,UAAa,IAAI,WAAW,OAAO,EAChD,MAAM;CAGX;AACF"}
1
+ {"version":3,"file":"stores.js","names":["keys: string[]","keyValuePairs: [string, T][]","prefix?: string | undefined"],"sources":["../src/stores.ts"],"sourcesContent":["import { Serializable } from \"./load/serializable.js\";\n\n/**\n * Abstract interface for a key-value store.\n */\nexport abstract class BaseStore<K, V> extends Serializable {\n /**\n * Abstract method to get multiple values for a set of keys.\n * @param {K[]} keys - An array of keys.\n * @returns {Promise<(V | undefined)[]>} - A Promise that resolves with array of values or undefined if key not found.\n */\n abstract mget(keys: K[]): Promise<(V | undefined)[]>;\n\n /**\n * Abstract method to set a value for multiple keys.\n * @param {[K, V][]} keyValuePairs - An array of key-value pairs.\n * @returns {Promise<void>} - A Promise that resolves when the operation is complete.\n */\n abstract mset(keyValuePairs: [K, V][]): Promise<void>;\n\n /**\n * Abstract method to delete multiple keys.\n * @param {K[]} keys - An array of keys to delete.\n * @returns {Promise<void>} - A Promise that resolves when the operation is complete.\n */\n abstract mdelete(keys: K[]): Promise<void>;\n\n /**\n * Abstract method to yield keys optionally based on a prefix.\n * @param {string} prefix - Optional prefix to filter keys.\n * @returns {AsyncGenerator<K | string>} - An asynchronous generator that yields keys on iteration.\n */\n abstract yieldKeys(prefix?: string): AsyncGenerator<K | string>;\n}\n\n/**\n * In-memory implementation of the BaseStore using a dictionary. Used for\n * storing key-value pairs in memory.\n * @example\n * ```typescript\n * const store = new InMemoryStore<BaseMessage>();\n * await store.mset(\n * Array.from({ length: 5 }).map((_, index) => [\n * `message:id:${index}`,\n * index % 2 === 0\n * ? new AIMessage(\"ai stuff...\")\n * : new HumanMessage(\"human stuff...\"),\n * ]),\n * );\n *\n * const retrievedMessages = await store.mget([\"message:id:0\", \"message:id:1\"]);\n * await store.mdelete(await store.yieldKeys(\"message:id:\").toArray());\n * ```\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport class InMemoryStore<T = any> extends BaseStore<string, T> {\n lc_namespace = [\"langchain\", \"storage\"];\n\n protected store: Record<string, T> = {};\n\n /**\n * Retrieves the values associated with the given keys from the store.\n * @param keys Keys to retrieve values for.\n * @returns Array of values associated with the given keys.\n */\n async mget(keys: string[]) {\n return keys.map((key) => this.store[key]);\n }\n\n /**\n * Sets the values for the given keys in the store.\n * @param keyValuePairs Array of key-value pairs to set in the store.\n * @returns Promise that resolves when all key-value pairs have been set.\n */\n async mset(keyValuePairs: [string, T][]): Promise<void> {\n for (const [key, value] of keyValuePairs) {\n this.store[key] = value;\n }\n }\n\n /**\n * Deletes the given keys and their associated values from the store.\n * @param keys Keys to delete from the store.\n * @returns Promise that resolves when all keys have been deleted.\n */\n async mdelete(keys: string[]): Promise<void> {\n for (const key of keys) {\n delete this.store[key];\n }\n }\n\n /**\n * Asynchronous generator that yields keys from the store. If a prefix is\n * provided, it only yields keys that start with the prefix.\n * @param prefix Optional prefix to filter keys.\n * @returns AsyncGenerator that yields keys from the store.\n */\n async *yieldKeys(prefix?: string | undefined): AsyncGenerator<string> {\n const keys = Object.keys(this.store);\n for (const key of keys) {\n if (prefix === undefined || key.startsWith(prefix)) {\n yield key;\n }\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;AAKA,IAAsB,YAAtB,cAA8C,aAAa,CA4B1D;;;;;;;;;;;;;;;;;;;;AAsBD,IAAa,gBAAb,cAA4C,UAAqB;CAC/D,eAAe,CAAC,aAAa,SAAU;CAEvC,AAAU,QAA2B,CAAE;;;;;;CAOvC,MAAM,KAAKA,MAAgB;AACzB,SAAO,KAAK,IAAI,CAAC,QAAQ,KAAK,MAAM,KAAK;CAC1C;;;;;;CAOD,MAAM,KAAKC,eAA6C;AACtD,OAAK,MAAM,CAAC,KAAK,MAAM,IAAI,eACzB,KAAK,MAAM,OAAO;CAErB;;;;;;CAOD,MAAM,QAAQD,MAA+B;AAC3C,OAAK,MAAM,OAAO,MAChB,OAAO,KAAK,MAAM;CAErB;;;;;;;CAQD,OAAO,UAAUE,QAAqD;EACpE,MAAM,OAAO,OAAO,KAAK,KAAK,MAAM;AACpC,OAAK,MAAM,OAAO,KAChB,KAAI,WAAW,UAAa,IAAI,WAAW,OAAO,EAChD,MAAM;CAGX;AACF"}
@@ -12,6 +12,7 @@ const require_language_models_base = require('../language_models/base.cjs');
12
12
  const require_types = require('./types.cjs');
13
13
  const zod_v3 = require_rolldown_runtime.__toESM(require("zod/v3"));
14
14
  const __cfworker_json_schema = require_rolldown_runtime.__toESM(require("@cfworker/json-schema"));
15
+ const zod_v4 = require_rolldown_runtime.__toESM(require("zod/v4"));
15
16
 
16
17
  //#region src/tools/index.ts
17
18
  var tools_exports = {};
@@ -62,6 +63,7 @@ var StructuredTool = class extends require_language_models_base.BaseLangChain {
62
63
  this.verboseParsingErrors = fields?.verboseParsingErrors ?? this.verboseParsingErrors;
63
64
  this.responseFormat = fields?.responseFormat ?? this.responseFormat;
64
65
  this.defaultConfig = fields?.defaultConfig ?? this.defaultConfig;
66
+ this.metadata = fields?.metadata ?? this.metadata;
65
67
  }
66
68
  /**
67
69
  * Invokes the tool with the provided input and configuration.
@@ -100,6 +102,7 @@ var StructuredTool = class extends require_language_models_base.BaseLangChain {
100
102
  } catch (e) {
101
103
  let message = `Received tool input did not match expected schema`;
102
104
  if (this.verboseParsingErrors) message = `${message}\nDetails: ${e.message}`;
105
+ if (e instanceof Error && e.constructor.name === "ZodError") message = `${message}\n\n${zod_v4.z.prettifyError(e)}`;
103
106
  throw new require_utils.ToolInputParsingException(message, JSON.stringify(arg));
104
107
  }
105
108
  else {
@@ -134,7 +137,8 @@ var StructuredTool = class extends require_language_models_base.BaseLangChain {
134
137
  content,
135
138
  artifact,
136
139
  toolCallId,
137
- name: this.name
140
+ name: this.name,
141
+ metadata: this.metadata
138
142
  });
139
143
  await runManager?.handleToolEnd(formattedOutput);
140
144
  return formattedOutput;
@@ -288,18 +292,22 @@ function tool(func, fields) {
288
292
  });
289
293
  }
290
294
  function _formatToolOutput(params) {
291
- const { content, artifact, toolCallId } = params;
295
+ const { content, artifact, toolCallId, metadata } = params;
292
296
  if (toolCallId && !require_messages_tool.isDirectToolOutput(content)) if (typeof content === "string" || Array.isArray(content) && content.every((item) => typeof item === "object")) return new require_messages_tool.ToolMessage({
297
+ status: "success",
293
298
  content,
294
299
  artifact,
295
300
  tool_call_id: toolCallId,
296
- name: params.name
301
+ name: params.name,
302
+ metadata
297
303
  });
298
304
  else return new require_messages_tool.ToolMessage({
305
+ status: "success",
299
306
  content: _stringify(content),
300
307
  artifact,
301
308
  tool_call_id: toolCallId,
302
- name: params.name
309
+ name: params.name,
310
+ metadata
303
311
  });
304
312
  else return content;
305
313
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["BaseLangChain","fields?: ToolParams","input: TInput","config?: TConfig","toolInput: Exclude<\n StructuredToolCallInput<SchemaT, SchemaInputT>,\n ToolCall\n >","enrichedConfig: ToolRunnableConfig","ensureConfig","mergeConfigs","_isToolCall","arg: TArg","configArg?: TConfig","tags?: string[]","parsed: SchemaOutputT","isInteropZodSchema","interopParseAsync","ToolInputParsingException","result","parseCallbackConfigArg","CallbackManager","toolCallId: string | undefined","_configHasToolCallId","z","callbacks?: TConfig","fields: DynamicToolInput<ToolOutputT>","input: string","runManager?: CallbackManagerForToolRun","parentConfig?: ToolRunnableConfig","fields: DynamicStructuredToolInput<SchemaT, SchemaOutputT, ToolOutputT>","arg: Parameters<\n DynamicStructuredToolInput<SchemaT, SchemaOutputT>[\"func\"]\n >[0]","parentConfig?: RunnableConfig","func: RunnableFunc<SchemaOutputT, ToolOutputT, ToolRunnableConfig>","fields: ToolWrapperParams<SchemaT>","isSimpleStringZodSchema","validatesOnlyStrings","patchConfig","AsyncLocalStorageProviderSingleton","pickRunnableConfigKeys","getAbortSignalError","params: {\n content: TOutput;\n name: string;\n artifact?: unknown;\n toolCallId?: string;\n}","isDirectToolOutput","ToolMessage","content: unknown"],"sources":["../../src/tools/index.ts"],"sourcesContent":["import { z } from \"zod/v3\";\nimport {\n validate,\n type Schema as ValidationSchema,\n} from \"@cfworker/json-schema\";\nimport {\n CallbackManager,\n CallbackManagerForToolRun,\n parseCallbackConfigArg,\n} from \"../callbacks/manager.js\";\nimport { BaseLangChain } from \"../language_models/base.js\";\nimport {\n mergeConfigs,\n ensureConfig,\n patchConfig,\n pickRunnableConfigKeys,\n type RunnableConfig,\n} from \"../runnables/config.js\";\nimport type { RunnableFunc } from \"../runnables/base.js\";\nimport { isDirectToolOutput, ToolCall, ToolMessage } from \"../messages/tool.js\";\nimport { AsyncLocalStorageProviderSingleton } from \"../singletons/index.js\";\nimport {\n _configHasToolCallId,\n _isToolCall,\n ToolInputParsingException,\n} from \"./utils.js\";\nimport {\n type InferInteropZodInput,\n type InferInteropZodOutput,\n type InteropZodObject,\n type InteropZodType,\n interopParseAsync,\n isSimpleStringZodSchema,\n isInteropZodSchema,\n type ZodStringV3,\n type ZodStringV4,\n type ZodObjectV3,\n type ZodObjectV4,\n} from \"../utils/types/zod.js\";\nimport { getAbortSignalError } from \"../utils/signal.js\";\nimport type {\n StructuredToolCallInput,\n ToolInputSchemaBase,\n ToolReturnType,\n ResponseFormat,\n ToolInputSchemaInputType,\n ToolInputSchemaOutputType,\n ToolParams,\n ToolRunnableConfig,\n StructuredToolInterface,\n DynamicToolInput,\n DynamicStructuredToolInput,\n StringInputToolSchema,\n ToolInterface,\n ToolOutputType,\n} from \"./types.js\";\nimport { type JSONSchema, validatesOnlyStrings } from \"../utils/json_schema.js\";\n\nexport type {\n BaseDynamicToolInput,\n ContentAndArtifact,\n DynamicToolInput,\n DynamicStructuredToolInput,\n ResponseFormat,\n StructuredToolCallInput,\n StructuredToolInterface,\n StructuredToolParams,\n ToolInterface,\n ToolParams,\n ToolReturnType,\n ToolRunnableConfig,\n ToolInputSchemaBase as ToolSchemaBase,\n} from \"./types.js\";\n\nexport {\n isLangChainTool,\n isRunnableToolLike,\n isStructuredTool,\n isStructuredToolParams,\n} from \"./types.js\";\n\nexport { ToolInputParsingException };\n/**\n * Base class for Tools that accept input of any shape defined by a Zod schema.\n */\nexport abstract class StructuredTool<\n SchemaT = ToolInputSchemaBase,\n SchemaOutputT = ToolInputSchemaOutputType<SchemaT>,\n SchemaInputT = ToolInputSchemaInputType<SchemaT>,\n ToolOutputT = ToolOutputType\n >\n extends BaseLangChain<\n StructuredToolCallInput<SchemaT, SchemaInputT>,\n ToolOutputT | ToolMessage\n >\n implements StructuredToolInterface<SchemaT, SchemaInputT, ToolOutputT>\n{\n abstract name: string;\n\n abstract description: string;\n\n abstract schema: SchemaT;\n\n /**\n * Whether to return the tool's output directly.\n *\n * Setting this to true means that after the tool is called,\n * an agent should stop looping.\n */\n returnDirect = false;\n\n verboseParsingErrors = false;\n\n get lc_namespace() {\n return [\"langchain\", \"tools\"];\n }\n\n /**\n * The tool response format.\n *\n * If \"content\" then the output of the tool is interpreted as the contents of a\n * ToolMessage. If \"content_and_artifact\" then the output is expected to be a\n * two-tuple corresponding to the (content, artifact) of a ToolMessage.\n *\n * @default \"content\"\n */\n responseFormat?: ResponseFormat = \"content\";\n\n /**\n * Default config object for the tool runnable.\n */\n defaultConfig?: ToolRunnableConfig;\n\n constructor(fields?: ToolParams) {\n super(fields ?? {});\n\n this.verboseParsingErrors =\n fields?.verboseParsingErrors ?? this.verboseParsingErrors;\n this.responseFormat = fields?.responseFormat ?? this.responseFormat;\n this.defaultConfig = fields?.defaultConfig ?? this.defaultConfig;\n }\n\n protected abstract _call(\n arg: SchemaOutputT,\n runManager?: CallbackManagerForToolRun,\n parentConfig?: ToolRunnableConfig\n ): Promise<ToolOutputT>;\n\n /**\n * Invokes the tool with the provided input and configuration.\n * @param input The input for the tool.\n * @param config Optional configuration for the tool.\n * @returns A Promise that resolves with the tool's output.\n */\n async invoke<\n TInput extends StructuredToolCallInput<SchemaT, SchemaInputT>,\n TConfig extends ToolRunnableConfig | undefined\n >(\n input: TInput,\n config?: TConfig\n ): Promise<ToolReturnType<TInput, TConfig, ToolOutputT>> {\n let toolInput: Exclude<\n StructuredToolCallInput<SchemaT, SchemaInputT>,\n ToolCall\n >;\n\n let enrichedConfig: ToolRunnableConfig = ensureConfig(\n mergeConfigs(this.defaultConfig, config)\n );\n if (_isToolCall(input)) {\n toolInput = input.args as Exclude<\n StructuredToolCallInput<SchemaT, SchemaInputT>,\n ToolCall\n >;\n enrichedConfig = {\n ...enrichedConfig,\n toolCall: input,\n };\n } else {\n toolInput = input as Exclude<\n StructuredToolCallInput<SchemaT, SchemaInputT>,\n ToolCall\n >;\n }\n\n return this.call(toolInput, enrichedConfig) as Promise<\n ToolReturnType<TInput, TConfig, ToolOutputT>\n >;\n }\n\n /**\n * @deprecated Use .invoke() instead. Will be removed in 0.3.0.\n *\n * Calls the tool with the provided argument, configuration, and tags. It\n * parses the input according to the schema, handles any errors, and\n * manages callbacks.\n * @param arg The input argument for the tool.\n * @param configArg Optional configuration or callbacks for the tool.\n * @param tags Optional tags for the tool.\n * @returns A Promise that resolves with a string.\n */\n async call<\n TArg extends StructuredToolCallInput<SchemaT, SchemaInputT>,\n TConfig extends ToolRunnableConfig | undefined\n >(\n arg: TArg,\n configArg?: TConfig,\n /** @deprecated */\n tags?: string[]\n ): Promise<ToolReturnType<TArg, TConfig, ToolOutputT>> {\n // Determine the actual input that needs parsing/validation.\n // If arg is a ToolCall, use its args; otherwise, use arg directly.\n const inputForValidation = _isToolCall(arg) ? arg.args : arg;\n\n let parsed: SchemaOutputT; // This will hold the successfully parsed input of the expected output type.\n if (isInteropZodSchema(this.schema)) {\n try {\n // Validate the inputForValidation - TS needs help here as it can't exclude ToolCall based on the check\n parsed = await interopParseAsync(\n this.schema as InteropZodType,\n inputForValidation as Exclude<TArg, ToolCall>\n );\n } catch (e) {\n let message = `Received tool input did not match expected schema`;\n if (this.verboseParsingErrors) {\n message = `${message}\\nDetails: ${(e as Error).message}`;\n }\n // Pass the original raw input arg to the exception\n throw new ToolInputParsingException(message, JSON.stringify(arg));\n }\n } else {\n const result = validate(\n inputForValidation,\n this.schema as ValidationSchema\n );\n if (!result.valid) {\n let message = `Received tool input did not match expected schema`;\n if (this.verboseParsingErrors) {\n message = `${message}\\nDetails: ${result.errors\n .map((e) => `${e.keywordLocation}: ${e.error}`)\n .join(\"\\n\")}`;\n }\n // Pass the original raw input arg to the exception\n throw new ToolInputParsingException(message, JSON.stringify(arg));\n }\n // Assign the validated input to parsed\n // We cast here because validate() doesn't narrow the type sufficiently for TS, but we know it's valid.\n parsed = inputForValidation as SchemaOutputT;\n }\n\n const config = parseCallbackConfigArg(configArg);\n const callbackManager_ = CallbackManager.configure(\n config.callbacks,\n this.callbacks,\n config.tags || tags,\n this.tags,\n config.metadata,\n this.metadata,\n { verbose: this.verbose }\n );\n const runManager = await callbackManager_?.handleToolStart(\n this.toJSON(),\n // Log the original raw input arg\n typeof arg === \"string\" ? arg : JSON.stringify(arg),\n config.runId,\n undefined,\n undefined,\n undefined,\n config.runName\n );\n delete config.runId;\n let result;\n try {\n // Pass the correctly typed parsed input to _call\n result = await this._call(parsed, runManager, config);\n } catch (e) {\n await runManager?.handleToolError(e);\n throw e;\n }\n let content;\n let artifact;\n if (this.responseFormat === \"content_and_artifact\") {\n if (Array.isArray(result) && result.length === 2) {\n [content, artifact] = result;\n } else {\n throw new Error(\n `Tool response format is \"content_and_artifact\" but the output was not a two-tuple.\\nResult: ${JSON.stringify(\n result\n )}`\n );\n }\n } else {\n content = result;\n }\n\n let toolCallId: string | undefined;\n // Extract toolCallId ONLY if the original arg was a ToolCall\n if (_isToolCall(arg)) {\n toolCallId = arg.id;\n }\n // Or if it was provided in the config's toolCall property\n if (!toolCallId && _configHasToolCallId(config)) {\n toolCallId = config.toolCall.id;\n }\n\n const formattedOutput = _formatToolOutput<ToolOutputT>({\n content,\n artifact,\n toolCallId,\n name: this.name,\n });\n await runManager?.handleToolEnd(formattedOutput);\n return formattedOutput as ToolReturnType<TArg, TConfig, ToolOutputT>;\n }\n}\n\n/**\n * Base class for Tools that accept input as a string.\n */\nexport abstract class Tool<ToolOutputT = ToolOutputType>\n extends StructuredTool<\n StringInputToolSchema,\n ToolInputSchemaOutputType<StringInputToolSchema>,\n ToolInputSchemaInputType<StringInputToolSchema>,\n ToolOutputT\n >\n implements\n ToolInterface<\n StringInputToolSchema,\n ToolInputSchemaInputType<StringInputToolSchema>,\n ToolOutputT\n >\n{\n schema = z\n .object({ input: z.string().optional() })\n .transform((obj) => obj.input);\n\n constructor(fields?: ToolParams) {\n super(fields);\n }\n\n /**\n * @deprecated Use .invoke() instead. Will be removed in 0.3.0.\n *\n * Calls the tool with the provided argument and callbacks. It handles\n * string inputs specifically.\n * @param arg The input argument for the tool, which can be a string, undefined, or an input of the tool's schema.\n * @param callbacks Optional callbacks for the tool.\n * @returns A Promise that resolves with a string.\n */\n // Match the base class signature including the generics and conditional return type\n call<\n TArg extends string | undefined | z.input<this[\"schema\"]> | ToolCall,\n TConfig extends ToolRunnableConfig | undefined\n >(\n arg: TArg,\n callbacks?: TConfig\n ): Promise<ToolReturnType<NonNullable<TArg>, TConfig, ToolOutputT>> {\n // Prepare the input for the base class call method.\n // If arg is string or undefined, wrap it; otherwise, pass ToolCall or { input: ... } directly.\n const structuredArg =\n typeof arg === \"string\" || arg == null ? { input: arg } : arg;\n\n // Ensure TConfig is passed to super.call\n return super.call(structuredArg, callbacks);\n }\n}\n\n/**\n * A tool that can be created dynamically from a function, name, and description.\n */\nexport class DynamicTool<\n ToolOutputT = ToolOutputType\n> extends Tool<ToolOutputT> {\n static lc_name() {\n return \"DynamicTool\";\n }\n\n name: string;\n\n description: string;\n\n func: DynamicToolInput<ToolOutputT>[\"func\"];\n\n constructor(fields: DynamicToolInput<ToolOutputT>) {\n super(fields);\n this.name = fields.name;\n this.description = fields.description;\n this.func = fields.func;\n this.returnDirect = fields.returnDirect ?? this.returnDirect;\n }\n\n /**\n * @deprecated Use .invoke() instead. Will be removed in 0.3.0.\n */\n async call<\n TArg extends string | undefined | z.input<this[\"schema\"]> | ToolCall,\n TConfig extends ToolRunnableConfig | undefined\n >(\n arg: TArg,\n configArg?: TConfig\n ): Promise<ToolReturnType<NonNullable<TArg>, TConfig, ToolOutputT>> {\n const config = parseCallbackConfigArg(configArg);\n if (config.runName === undefined) {\n config.runName = this.name;\n }\n // Call the Tool class's call method, passing generics through\n // Cast config to TConfig to satisfy the super.call signature\n return super.call<TArg, TConfig>(arg, config as TConfig);\n }\n\n /** @ignore */\n async _call(\n input: string, // DynamicTool's _call specifically expects a string after schema transformation\n runManager?: CallbackManagerForToolRun,\n parentConfig?: ToolRunnableConfig\n ): Promise<ToolOutputT> {\n return this.func(input, runManager, parentConfig);\n }\n}\n\n/**\n * A tool that can be created dynamically from a function, name, and\n * description, designed to work with structured data. It extends the\n * StructuredTool class and overrides the _call method to execute the\n * provided function when the tool is called.\n *\n * Schema can be passed as Zod or JSON schema. The tool will not validate\n * input if JSON schema is passed.\n */\nexport class DynamicStructuredTool<\n SchemaT = ToolInputSchemaBase,\n SchemaOutputT = ToolInputSchemaOutputType<SchemaT>,\n SchemaInputT = ToolInputSchemaInputType<SchemaT>,\n ToolOutputT = ToolOutputType\n> extends StructuredTool<SchemaT, SchemaOutputT, SchemaInputT, ToolOutputT> {\n static lc_name() {\n return \"DynamicStructuredTool\";\n }\n\n name: string;\n\n description: string;\n\n func: DynamicStructuredToolInput<SchemaT, SchemaOutputT, ToolOutputT>[\"func\"];\n\n schema: SchemaT;\n\n constructor(\n fields: DynamicStructuredToolInput<SchemaT, SchemaOutputT, ToolOutputT>\n ) {\n super(fields);\n this.name = fields.name;\n this.description = fields.description;\n this.func = fields.func;\n this.returnDirect = fields.returnDirect ?? this.returnDirect;\n this.schema = fields.schema;\n }\n\n /**\n * @deprecated Use .invoke() instead. Will be removed in 0.3.0.\n */\n // Match the base class signature\n async call<\n TArg extends StructuredToolCallInput<SchemaT, SchemaInputT>,\n TConfig extends ToolRunnableConfig | undefined\n >(\n arg: TArg,\n configArg?: TConfig,\n /** @deprecated */\n tags?: string[]\n ): Promise<ToolReturnType<NonNullable<TArg>, TConfig, ToolOutputT>> {\n const config = parseCallbackConfigArg(configArg);\n if (config.runName === undefined) {\n config.runName = this.name;\n }\n\n // Call the base class method, passing generics through\n // Cast config to TConfig to satisfy the super.call signature\n return super.call<TArg, TConfig>(arg, config as TConfig, tags);\n }\n\n protected _call(\n arg: Parameters<\n DynamicStructuredToolInput<SchemaT, SchemaOutputT>[\"func\"]\n >[0],\n runManager?: CallbackManagerForToolRun,\n parentConfig?: RunnableConfig\n ): Promise<ToolOutputT> {\n return this.func(arg, runManager, parentConfig);\n }\n}\n\n/**\n * Abstract base class for toolkits in LangChain. Toolkits are collections\n * of tools that agents can use. Subclasses must implement the `tools`\n * property to provide the specific tools for the toolkit.\n */\nexport abstract class BaseToolkit {\n abstract tools: StructuredToolInterface[];\n\n getTools(): StructuredToolInterface[] {\n return this.tools;\n }\n}\n\n/**\n * Parameters for the tool function.\n * Schema can be provided as Zod or JSON schema.\n * Both schema types will be validated.\n * @template {ToolInputSchemaBase} RunInput The input schema for the tool.\n */\ninterface ToolWrapperParams<RunInput = ToolInputSchemaBase | undefined>\n extends ToolParams {\n /**\n * The name of the tool. If using with an LLM, this\n * will be passed as the tool name.\n */\n name: string;\n /**\n * The description of the tool.\n * @default `${fields.name} tool`\n */\n description?: string;\n /**\n * The input schema for the tool. If using an LLM, this\n * will be passed as the tool schema to generate arguments\n * for.\n */\n schema?: RunInput;\n /**\n * The tool response format.\n *\n * If \"content\" then the output of the tool is interpreted as the contents of a\n * ToolMessage. If \"content_and_artifact\" then the output is expected to be a\n * two-tuple corresponding to the (content, artifact) of a ToolMessage.\n *\n * @default \"content\"\n */\n responseFormat?: ResponseFormat;\n /**\n * Whether to return the tool's output directly.\n *\n * Setting this to true means that after the tool is called,\n * an agent should stop looping.\n */\n returnDirect?: boolean;\n}\n\n/**\n * Creates a new StructuredTool instance with the provided function, name, description, and schema.\n *\n * Schema can be provided as Zod or JSON schema, and both will be validated.\n *\n * @function\n * @template {ToolInputSchemaBase} SchemaT The input schema for the tool.\n * @template {ToolReturnType} ToolOutputT The output type of the tool.\n *\n * @param {RunnableFunc<z.output<SchemaT>, ToolOutputT>} func - The function to invoke when the tool is called.\n * @param {ToolWrapperParams<SchemaT>} fields - An object containing the following properties:\n * @param {string} fields.name The name of the tool.\n * @param {string | undefined} fields.description The description of the tool. Defaults to either the description on the Zod schema, or `${fields.name} tool`.\n * @param {z.AnyZodObject | z.ZodString | undefined} fields.schema The Zod schema defining the input for the tool. If undefined, it will default to a Zod string schema.\n *\n * @returns {DynamicStructuredTool<SchemaT>} A new StructuredTool instance.\n */\nexport function tool<SchemaT extends ZodStringV3, ToolOutputT = ToolOutputType>(\n func: RunnableFunc<\n InferInteropZodOutput<SchemaT>,\n ToolOutputT,\n ToolRunnableConfig\n >,\n fields: ToolWrapperParams<SchemaT>\n): DynamicTool<ToolOutputT>;\n\nexport function tool<SchemaT extends ZodStringV4, ToolOutputT = ToolOutputType>(\n func: RunnableFunc<\n InferInteropZodOutput<SchemaT>,\n ToolOutputT,\n ToolRunnableConfig\n >,\n fields: ToolWrapperParams<SchemaT>\n): DynamicTool<ToolOutputT>;\n\nexport function tool<\n SchemaT extends ZodObjectV3,\n SchemaOutputT = InferInteropZodOutput<SchemaT>,\n SchemaInputT = InferInteropZodInput<SchemaT>,\n ToolOutputT = ToolOutputType\n>(\n func: RunnableFunc<SchemaOutputT, ToolOutputT, ToolRunnableConfig>,\n fields: ToolWrapperParams<SchemaT>\n): DynamicStructuredTool<SchemaT, SchemaOutputT, SchemaInputT, ToolOutputT>;\n\nexport function tool<\n SchemaT extends ZodObjectV4,\n SchemaOutputT = InferInteropZodOutput<SchemaT>,\n SchemaInputT = InferInteropZodInput<SchemaT>,\n ToolOutputT = ToolOutputType\n>(\n func: RunnableFunc<SchemaOutputT, ToolOutputT, ToolRunnableConfig>,\n fields: ToolWrapperParams<SchemaT>\n): DynamicStructuredTool<SchemaT, SchemaOutputT, SchemaInputT, ToolOutputT>;\n\nexport function tool<\n SchemaT extends JSONSchema,\n SchemaOutputT = ToolInputSchemaOutputType<SchemaT>,\n SchemaInputT = ToolInputSchemaInputType<SchemaT>,\n ToolOutputT = ToolOutputType\n>(\n func: RunnableFunc<\n Parameters<DynamicStructuredToolInput<SchemaT>[\"func\"]>[0],\n ToolOutputT,\n ToolRunnableConfig\n >,\n fields: ToolWrapperParams<SchemaT>\n): DynamicStructuredTool<SchemaT, SchemaOutputT, SchemaInputT, ToolOutputT>;\n\nexport function tool<\n SchemaT extends\n | InteropZodObject\n | InteropZodType<string>\n | JSONSchema = InteropZodObject,\n SchemaOutputT = ToolInputSchemaOutputType<SchemaT>,\n SchemaInputT = ToolInputSchemaInputType<SchemaT>,\n ToolOutputT = ToolOutputType\n>(\n func: RunnableFunc<SchemaOutputT, ToolOutputT, ToolRunnableConfig>,\n fields: ToolWrapperParams<SchemaT>\n):\n | DynamicStructuredTool<SchemaT, SchemaOutputT, SchemaInputT, ToolOutputT>\n | DynamicTool<ToolOutputT> {\n const isSimpleStringSchema = isSimpleStringZodSchema(fields.schema);\n const isStringJSONSchema = validatesOnlyStrings(fields.schema);\n\n // If the schema is not provided, or it's a simple string schema, create a DynamicTool\n if (!fields.schema || isSimpleStringSchema || isStringJSONSchema) {\n return new DynamicTool<ToolOutputT>({\n ...fields,\n description:\n fields.description ??\n (fields.schema as { description?: string } | undefined)?.description ??\n `${fields.name} tool`,\n func: async (input, runManager, config) => {\n return new Promise<ToolOutputT>((resolve, reject) => {\n const childConfig = patchConfig(config, {\n callbacks: runManager?.getChild(),\n });\n // eslint-disable-next-line no-void\n void AsyncLocalStorageProviderSingleton.runWithConfig(\n pickRunnableConfigKeys(childConfig),\n async () => {\n try {\n // TS doesn't restrict the type here based on the guard above\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n resolve(func(input as any, childConfig));\n } catch (e) {\n reject(e);\n }\n }\n );\n });\n },\n });\n }\n\n const schema = fields.schema as InteropZodObject | JSONSchema;\n\n const description =\n fields.description ??\n (fields.schema as { description?: string }).description ??\n `${fields.name} tool`;\n\n return new DynamicStructuredTool<\n typeof schema,\n SchemaOutputT,\n SchemaInputT,\n ToolOutputT\n >({\n ...fields,\n description,\n schema,\n func: async (input, runManager, config) => {\n return new Promise<ToolOutputT>((resolve, reject) => {\n if (config?.signal) {\n config.signal.addEventListener(\"abort\", () => {\n return reject(getAbortSignalError(config.signal));\n });\n }\n\n const childConfig = patchConfig(config, {\n callbacks: runManager?.getChild(),\n });\n // eslint-disable-next-line no-void\n void AsyncLocalStorageProviderSingleton.runWithConfig(\n pickRunnableConfigKeys(childConfig),\n async () => {\n try {\n const result = await func(input, childConfig);\n\n /**\n * If the signal is aborted, we don't want to resolve the promise\n * as the promise is already rejected.\n */\n if (config?.signal?.aborted) {\n return;\n }\n\n resolve(result);\n } catch (e) {\n reject(e);\n }\n }\n );\n });\n },\n }) as DynamicStructuredTool<\n SchemaT,\n SchemaOutputT,\n SchemaInputT,\n ToolOutputT\n >;\n}\n\nfunction _formatToolOutput<TOutput extends ToolOutputType>(params: {\n content: TOutput;\n name: string;\n artifact?: unknown;\n toolCallId?: string;\n}): ToolMessage | TOutput {\n const { content, artifact, toolCallId } = params;\n if (toolCallId && !isDirectToolOutput(content)) {\n if (\n typeof content === \"string\" ||\n (Array.isArray(content) &&\n content.every((item) => typeof item === \"object\"))\n ) {\n return new ToolMessage({\n content,\n artifact,\n tool_call_id: toolCallId,\n name: params.name,\n });\n } else {\n return new ToolMessage({\n content: _stringify(content),\n artifact,\n tool_call_id: toolCallId,\n name: params.name,\n });\n }\n } else {\n return content;\n }\n}\n\nfunction _stringify(content: unknown): string {\n try {\n return JSON.stringify(content, null, 2) ?? \"\";\n } catch (_noOp) {\n return `${content}`;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqFA,IAAsB,iBAAtB,cAMUA,2CAKV;;;;;;;CAaE,eAAe;CAEf,uBAAuB;CAEvB,IAAI,eAAe;AACjB,SAAO,CAAC,aAAa,OAAQ;CAC9B;;;;;;;;;;CAWD,iBAAkC;;;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CAC5C,KACE,OAAO,YAAY,YAClB,MAAM,QAAQ,QAAQ,IACrB,QAAQ,MAAM,CAAC,SAAS,OAAO,SAAS,SAAS,CAEnD,QAAO,IAAIC,kCAAY;EACrB;EACA;EACA,cAAc;EACd,MAAM,OAAO;CACd;KAED,QAAO,IAAIA,kCAAY;EACrB,SAAS,WAAW,QAAQ;EAC5B;EACA,cAAc;EACd,MAAM,OAAO;CACd;KAGH,QAAO;AAEV;AAED,SAAS,WAAWC,SAA0B;AAC5C,KAAI;AACF,SAAO,KAAK,UAAU,SAAS,MAAM,EAAE,IAAI;CAC5C,SAAQ,OAAO;AACd,SAAO,GAAG,SAAS;CACpB;AACF"}
1
+ {"version":3,"file":"index.cjs","names":["BaseLangChain","fields?: ToolParams","input: TInput","config?: TConfig","toolInput: Exclude<\n StructuredToolCallInput<SchemaT, SchemaInputT>,\n ToolCall\n >","enrichedConfig: ToolRunnableConfig","ensureConfig","mergeConfigs","_isToolCall","arg: TArg","configArg?: TConfig","tags?: string[]","parsed: SchemaOutputT","isInteropZodSchema","interopParseAsync","z4","ToolInputParsingException","result","parseCallbackConfigArg","CallbackManager","toolCallId: string | undefined","_configHasToolCallId","z","callbacks?: TConfig","fields: DynamicToolInput<ToolOutputT>","input: string","runManager?: CallbackManagerForToolRun","parentConfig?: ToolRunnableConfig","fields: DynamicStructuredToolInput<SchemaT, SchemaOutputT, ToolOutputT>","arg: Parameters<\n DynamicStructuredToolInput<SchemaT, SchemaOutputT>[\"func\"]\n >[0]","parentConfig?: RunnableConfig","func: RunnableFunc<SchemaOutputT, ToolOutputT, ToolRunnableConfig>","fields: ToolWrapperParams<SchemaT>","isSimpleStringZodSchema","validatesOnlyStrings","patchConfig","AsyncLocalStorageProviderSingleton","pickRunnableConfigKeys","getAbortSignalError","params: {\n content: TOutput;\n name: string;\n artifact?: unknown;\n toolCallId?: string;\n metadata?: Record<string, unknown>;\n}","isDirectToolOutput","ToolMessage","content: unknown"],"sources":["../../src/tools/index.ts"],"sourcesContent":["import { z } from \"zod/v3\";\nimport { z as z4, ZodError } from \"zod/v4\";\nimport {\n validate,\n type Schema as ValidationSchema,\n} from \"@cfworker/json-schema\";\nimport {\n CallbackManager,\n CallbackManagerForToolRun,\n parseCallbackConfigArg,\n} from \"../callbacks/manager.js\";\nimport { BaseLangChain } from \"../language_models/base.js\";\nimport {\n mergeConfigs,\n ensureConfig,\n patchConfig,\n pickRunnableConfigKeys,\n type RunnableConfig,\n} from \"../runnables/config.js\";\nimport type { RunnableFunc } from \"../runnables/base.js\";\nimport { isDirectToolOutput, ToolCall, ToolMessage } from \"../messages/tool.js\";\nimport { AsyncLocalStorageProviderSingleton } from \"../singletons/index.js\";\nimport {\n _configHasToolCallId,\n _isToolCall,\n ToolInputParsingException,\n} from \"./utils.js\";\nimport {\n type InferInteropZodInput,\n type InferInteropZodOutput,\n type InteropZodObject,\n type InteropZodType,\n interopParseAsync,\n isSimpleStringZodSchema,\n isInteropZodSchema,\n type ZodStringV3,\n type ZodStringV4,\n type ZodObjectV3,\n type ZodObjectV4,\n} from \"../utils/types/zod.js\";\nimport { getAbortSignalError } from \"../utils/signal.js\";\nimport type {\n StructuredToolCallInput,\n ToolInputSchemaBase,\n ToolReturnType,\n ResponseFormat,\n ToolInputSchemaInputType,\n ToolInputSchemaOutputType,\n ToolParams,\n ToolRunnableConfig,\n StructuredToolInterface,\n DynamicToolInput,\n DynamicStructuredToolInput,\n StringInputToolSchema,\n ToolInterface,\n ToolOutputType,\n} from \"./types.js\";\nimport { type JSONSchema, validatesOnlyStrings } from \"../utils/json_schema.js\";\n\nexport type {\n BaseDynamicToolInput,\n ContentAndArtifact,\n DynamicToolInput,\n DynamicStructuredToolInput,\n ResponseFormat,\n StructuredToolCallInput,\n StructuredToolInterface,\n StructuredToolParams,\n ToolInterface,\n ToolParams,\n ToolReturnType,\n ToolRunnableConfig,\n ToolInputSchemaBase as ToolSchemaBase,\n} from \"./types.js\";\n\nexport {\n isLangChainTool,\n isRunnableToolLike,\n isStructuredTool,\n isStructuredToolParams,\n} from \"./types.js\";\n\nexport { ToolInputParsingException };\n/**\n * Base class for Tools that accept input of any shape defined by a Zod schema.\n */\nexport abstract class StructuredTool<\n SchemaT = ToolInputSchemaBase,\n SchemaOutputT = ToolInputSchemaOutputType<SchemaT>,\n SchemaInputT = ToolInputSchemaInputType<SchemaT>,\n ToolOutputT = ToolOutputType\n >\n extends BaseLangChain<\n StructuredToolCallInput<SchemaT, SchemaInputT>,\n ToolOutputT | ToolMessage\n >\n implements StructuredToolInterface<SchemaT, SchemaInputT, ToolOutputT>\n{\n abstract name: string;\n\n abstract description: string;\n\n abstract schema: SchemaT;\n\n /**\n * Whether to return the tool's output directly.\n *\n * Setting this to true means that after the tool is called,\n * an agent should stop looping.\n */\n returnDirect = false;\n\n verboseParsingErrors = false;\n\n get lc_namespace() {\n return [\"langchain\", \"tools\"];\n }\n\n /**\n * The tool response format.\n *\n * If \"content\" then the output of the tool is interpreted as the contents of a\n * ToolMessage. If \"content_and_artifact\" then the output is expected to be a\n * two-tuple corresponding to the (content, artifact) of a ToolMessage.\n *\n * @default \"content\"\n */\n responseFormat?: ResponseFormat = \"content\";\n\n /**\n * Default config object for the tool runnable.\n */\n defaultConfig?: ToolRunnableConfig;\n\n constructor(fields?: ToolParams) {\n super(fields ?? {});\n\n this.verboseParsingErrors =\n fields?.verboseParsingErrors ?? this.verboseParsingErrors;\n this.responseFormat = fields?.responseFormat ?? this.responseFormat;\n this.defaultConfig = fields?.defaultConfig ?? this.defaultConfig;\n this.metadata = fields?.metadata ?? this.metadata;\n }\n\n protected abstract _call(\n arg: SchemaOutputT,\n runManager?: CallbackManagerForToolRun,\n parentConfig?: ToolRunnableConfig\n ): Promise<ToolOutputT>;\n\n /**\n * Invokes the tool with the provided input and configuration.\n * @param input The input for the tool.\n * @param config Optional configuration for the tool.\n * @returns A Promise that resolves with the tool's output.\n */\n async invoke<\n TInput extends StructuredToolCallInput<SchemaT, SchemaInputT>,\n TConfig extends ToolRunnableConfig | undefined\n >(\n input: TInput,\n config?: TConfig\n ): Promise<ToolReturnType<TInput, TConfig, ToolOutputT>> {\n let toolInput: Exclude<\n StructuredToolCallInput<SchemaT, SchemaInputT>,\n ToolCall\n >;\n\n let enrichedConfig: ToolRunnableConfig = ensureConfig(\n mergeConfigs(this.defaultConfig, config)\n );\n if (_isToolCall(input)) {\n toolInput = input.args as Exclude<\n StructuredToolCallInput<SchemaT, SchemaInputT>,\n ToolCall\n >;\n enrichedConfig = {\n ...enrichedConfig,\n toolCall: input,\n };\n } else {\n toolInput = input as Exclude<\n StructuredToolCallInput<SchemaT, SchemaInputT>,\n ToolCall\n >;\n }\n\n return this.call(toolInput, enrichedConfig) as Promise<\n ToolReturnType<TInput, TConfig, ToolOutputT>\n >;\n }\n\n /**\n * @deprecated Use .invoke() instead. Will be removed in 0.3.0.\n *\n * Calls the tool with the provided argument, configuration, and tags. It\n * parses the input according to the schema, handles any errors, and\n * manages callbacks.\n * @param arg The input argument for the tool.\n * @param configArg Optional configuration or callbacks for the tool.\n * @param tags Optional tags for the tool.\n * @returns A Promise that resolves with a string.\n */\n async call<\n TArg extends StructuredToolCallInput<SchemaT, SchemaInputT>,\n TConfig extends ToolRunnableConfig | undefined\n >(\n arg: TArg,\n configArg?: TConfig,\n /** @deprecated */\n tags?: string[]\n ): Promise<ToolReturnType<TArg, TConfig, ToolOutputT>> {\n // Determine the actual input that needs parsing/validation.\n // If arg is a ToolCall, use its args; otherwise, use arg directly.\n const inputForValidation = _isToolCall(arg) ? arg.args : arg;\n\n let parsed: SchemaOutputT; // This will hold the successfully parsed input of the expected output type.\n if (isInteropZodSchema(this.schema)) {\n try {\n // Validate the inputForValidation - TS needs help here as it can't exclude ToolCall based on the check\n parsed = await interopParseAsync(\n this.schema as InteropZodType,\n inputForValidation as Exclude<TArg, ToolCall>\n );\n } catch (e) {\n let message = `Received tool input did not match expected schema`;\n if (this.verboseParsingErrors) {\n message = `${message}\\nDetails: ${(e as Error).message}`;\n }\n // eslint-disable-next-line no-instanceof/no-instanceof\n if (e instanceof Error && e.constructor.name === \"ZodError\") {\n message = `${message}\\n\\n${z4.prettifyError(e as ZodError)}`;\n }\n // Pass the original raw input arg to the exception\n throw new ToolInputParsingException(message, JSON.stringify(arg));\n }\n } else {\n const result = validate(\n inputForValidation,\n this.schema as ValidationSchema\n );\n if (!result.valid) {\n let message = `Received tool input did not match expected schema`;\n if (this.verboseParsingErrors) {\n message = `${message}\\nDetails: ${result.errors\n .map((e) => `${e.keywordLocation}: ${e.error}`)\n .join(\"\\n\")}`;\n }\n // Pass the original raw input arg to the exception\n throw new ToolInputParsingException(message, JSON.stringify(arg));\n }\n // Assign the validated input to parsed\n // We cast here because validate() doesn't narrow the type sufficiently for TS, but we know it's valid.\n parsed = inputForValidation as SchemaOutputT;\n }\n\n const config = parseCallbackConfigArg(configArg);\n const callbackManager_ = CallbackManager.configure(\n config.callbacks,\n this.callbacks,\n config.tags || tags,\n this.tags,\n config.metadata,\n this.metadata,\n { verbose: this.verbose }\n );\n const runManager = await callbackManager_?.handleToolStart(\n this.toJSON(),\n // Log the original raw input arg\n typeof arg === \"string\" ? arg : JSON.stringify(arg),\n config.runId,\n undefined,\n undefined,\n undefined,\n config.runName\n );\n delete config.runId;\n let result;\n try {\n // Pass the correctly typed parsed input to _call\n result = await this._call(parsed, runManager, config);\n } catch (e) {\n await runManager?.handleToolError(e);\n throw e;\n }\n let content;\n let artifact;\n if (this.responseFormat === \"content_and_artifact\") {\n if (Array.isArray(result) && result.length === 2) {\n [content, artifact] = result;\n } else {\n throw new Error(\n `Tool response format is \"content_and_artifact\" but the output was not a two-tuple.\\nResult: ${JSON.stringify(\n result\n )}`\n );\n }\n } else {\n content = result;\n }\n\n let toolCallId: string | undefined;\n // Extract toolCallId ONLY if the original arg was a ToolCall\n if (_isToolCall(arg)) {\n toolCallId = arg.id;\n }\n // Or if it was provided in the config's toolCall property\n if (!toolCallId && _configHasToolCallId(config)) {\n toolCallId = config.toolCall.id;\n }\n\n const formattedOutput = _formatToolOutput<ToolOutputT>({\n content,\n artifact,\n toolCallId,\n name: this.name,\n metadata: this.metadata,\n });\n await runManager?.handleToolEnd(formattedOutput);\n return formattedOutput as ToolReturnType<TArg, TConfig, ToolOutputT>;\n }\n}\n\n/**\n * Base class for Tools that accept input as a string.\n */\nexport abstract class Tool<ToolOutputT = ToolOutputType>\n extends StructuredTool<\n StringInputToolSchema,\n ToolInputSchemaOutputType<StringInputToolSchema>,\n ToolInputSchemaInputType<StringInputToolSchema>,\n ToolOutputT\n >\n implements\n ToolInterface<\n StringInputToolSchema,\n ToolInputSchemaInputType<StringInputToolSchema>,\n ToolOutputT\n >\n{\n schema = z\n .object({ input: z.string().optional() })\n .transform((obj) => obj.input);\n\n constructor(fields?: ToolParams) {\n super(fields);\n }\n\n /**\n * @deprecated Use .invoke() instead. Will be removed in 0.3.0.\n *\n * Calls the tool with the provided argument and callbacks. It handles\n * string inputs specifically.\n * @param arg The input argument for the tool, which can be a string, undefined, or an input of the tool's schema.\n * @param callbacks Optional callbacks for the tool.\n * @returns A Promise that resolves with a string.\n */\n // Match the base class signature including the generics and conditional return type\n call<\n TArg extends string | undefined | z.input<this[\"schema\"]> | ToolCall,\n TConfig extends ToolRunnableConfig | undefined\n >(\n arg: TArg,\n callbacks?: TConfig\n ): Promise<ToolReturnType<NonNullable<TArg>, TConfig, ToolOutputT>> {\n // Prepare the input for the base class call method.\n // If arg is string or undefined, wrap it; otherwise, pass ToolCall or { input: ... } directly.\n const structuredArg =\n typeof arg === \"string\" || arg == null ? { input: arg } : arg;\n\n // Ensure TConfig is passed to super.call\n return super.call(structuredArg, callbacks);\n }\n}\n\n/**\n * A tool that can be created dynamically from a function, name, and description.\n */\nexport class DynamicTool<\n ToolOutputT = ToolOutputType\n> extends Tool<ToolOutputT> {\n static lc_name() {\n return \"DynamicTool\";\n }\n\n name: string;\n\n description: string;\n\n func: DynamicToolInput<ToolOutputT>[\"func\"];\n\n constructor(fields: DynamicToolInput<ToolOutputT>) {\n super(fields);\n this.name = fields.name;\n this.description = fields.description;\n this.func = fields.func;\n this.returnDirect = fields.returnDirect ?? this.returnDirect;\n }\n\n /**\n * @deprecated Use .invoke() instead. Will be removed in 0.3.0.\n */\n async call<\n TArg extends string | undefined | z.input<this[\"schema\"]> | ToolCall,\n TConfig extends ToolRunnableConfig | undefined\n >(\n arg: TArg,\n configArg?: TConfig\n ): Promise<ToolReturnType<NonNullable<TArg>, TConfig, ToolOutputT>> {\n const config = parseCallbackConfigArg(configArg);\n if (config.runName === undefined) {\n config.runName = this.name;\n }\n // Call the Tool class's call method, passing generics through\n // Cast config to TConfig to satisfy the super.call signature\n return super.call<TArg, TConfig>(arg, config as TConfig);\n }\n\n /** @ignore */\n async _call(\n input: string, // DynamicTool's _call specifically expects a string after schema transformation\n runManager?: CallbackManagerForToolRun,\n parentConfig?: ToolRunnableConfig\n ): Promise<ToolOutputT> {\n return this.func(input, runManager, parentConfig);\n }\n}\n\n/**\n * A tool that can be created dynamically from a function, name, and\n * description, designed to work with structured data. It extends the\n * StructuredTool class and overrides the _call method to execute the\n * provided function when the tool is called.\n *\n * Schema can be passed as Zod or JSON schema. The tool will not validate\n * input if JSON schema is passed.\n */\nexport class DynamicStructuredTool<\n SchemaT = ToolInputSchemaBase,\n SchemaOutputT = ToolInputSchemaOutputType<SchemaT>,\n SchemaInputT = ToolInputSchemaInputType<SchemaT>,\n ToolOutputT = ToolOutputType\n> extends StructuredTool<SchemaT, SchemaOutputT, SchemaInputT, ToolOutputT> {\n static lc_name() {\n return \"DynamicStructuredTool\";\n }\n\n name: string;\n\n description: string;\n\n func: DynamicStructuredToolInput<SchemaT, SchemaOutputT, ToolOutputT>[\"func\"];\n\n schema: SchemaT;\n\n constructor(\n fields: DynamicStructuredToolInput<SchemaT, SchemaOutputT, ToolOutputT>\n ) {\n super(fields);\n this.name = fields.name;\n this.description = fields.description;\n this.func = fields.func;\n this.returnDirect = fields.returnDirect ?? this.returnDirect;\n this.schema = fields.schema;\n }\n\n /**\n * @deprecated Use .invoke() instead. Will be removed in 0.3.0.\n */\n // Match the base class signature\n async call<\n TArg extends StructuredToolCallInput<SchemaT, SchemaInputT>,\n TConfig extends ToolRunnableConfig | undefined\n >(\n arg: TArg,\n configArg?: TConfig,\n /** @deprecated */\n tags?: string[]\n ): Promise<ToolReturnType<NonNullable<TArg>, TConfig, ToolOutputT>> {\n const config = parseCallbackConfigArg(configArg);\n if (config.runName === undefined) {\n config.runName = this.name;\n }\n\n // Call the base class method, passing generics through\n // Cast config to TConfig to satisfy the super.call signature\n return super.call<TArg, TConfig>(arg, config as TConfig, tags);\n }\n\n protected _call(\n arg: Parameters<\n DynamicStructuredToolInput<SchemaT, SchemaOutputT>[\"func\"]\n >[0],\n runManager?: CallbackManagerForToolRun,\n parentConfig?: RunnableConfig\n ): Promise<ToolOutputT> {\n return this.func(arg, runManager, parentConfig);\n }\n}\n\n/**\n * Abstract base class for toolkits in LangChain. Toolkits are collections\n * of tools that agents can use. Subclasses must implement the `tools`\n * property to provide the specific tools for the toolkit.\n */\nexport abstract class BaseToolkit {\n abstract tools: StructuredToolInterface[];\n\n getTools(): StructuredToolInterface[] {\n return this.tools;\n }\n}\n\n/**\n * Parameters for the tool function.\n * Schema can be provided as Zod or JSON schema.\n * Both schema types will be validated.\n * @template {ToolInputSchemaBase} RunInput The input schema for the tool.\n */\ninterface ToolWrapperParams<RunInput = ToolInputSchemaBase | undefined>\n extends ToolParams {\n /**\n * The name of the tool. If using with an LLM, this\n * will be passed as the tool name.\n */\n name: string;\n /**\n * The description of the tool.\n * @default `${fields.name} tool`\n */\n description?: string;\n /**\n * The input schema for the tool. If using an LLM, this\n * will be passed as the tool schema to generate arguments\n * for.\n */\n schema?: RunInput;\n /**\n * The tool response format.\n *\n * If \"content\" then the output of the tool is interpreted as the contents of a\n * ToolMessage. If \"content_and_artifact\" then the output is expected to be a\n * two-tuple corresponding to the (content, artifact) of a ToolMessage.\n *\n * @default \"content\"\n */\n responseFormat?: ResponseFormat;\n /**\n * Whether to return the tool's output directly.\n *\n * Setting this to true means that after the tool is called,\n * an agent should stop looping.\n */\n returnDirect?: boolean;\n}\n\n/**\n * Creates a new StructuredTool instance with the provided function, name, description, and schema.\n *\n * Schema can be provided as Zod or JSON schema, and both will be validated.\n *\n * @function\n * @template {ToolInputSchemaBase} SchemaT The input schema for the tool.\n * @template {ToolReturnType} ToolOutputT The output type of the tool.\n *\n * @param {RunnableFunc<z.output<SchemaT>, ToolOutputT>} func - The function to invoke when the tool is called.\n * @param {ToolWrapperParams<SchemaT>} fields - An object containing the following properties:\n * @param {string} fields.name The name of the tool.\n * @param {string | undefined} fields.description The description of the tool. Defaults to either the description on the Zod schema, or `${fields.name} tool`.\n * @param {z.AnyZodObject | z.ZodString | undefined} fields.schema The Zod schema defining the input for the tool. If undefined, it will default to a Zod string schema.\n *\n * @returns {DynamicStructuredTool<SchemaT>} A new StructuredTool instance.\n */\nexport function tool<SchemaT extends ZodStringV3, ToolOutputT = ToolOutputType>(\n func: RunnableFunc<\n InferInteropZodOutput<SchemaT>,\n ToolOutputT,\n ToolRunnableConfig\n >,\n fields: ToolWrapperParams<SchemaT>\n): DynamicTool<ToolOutputT>;\n\nexport function tool<SchemaT extends ZodStringV4, ToolOutputT = ToolOutputType>(\n func: RunnableFunc<\n InferInteropZodOutput<SchemaT>,\n ToolOutputT,\n ToolRunnableConfig\n >,\n fields: ToolWrapperParams<SchemaT>\n): DynamicTool<ToolOutputT>;\n\nexport function tool<\n SchemaT extends ZodObjectV3,\n SchemaOutputT = InferInteropZodOutput<SchemaT>,\n SchemaInputT = InferInteropZodInput<SchemaT>,\n ToolOutputT = ToolOutputType\n>(\n func: RunnableFunc<SchemaOutputT, ToolOutputT, ToolRunnableConfig>,\n fields: ToolWrapperParams<SchemaT>\n): DynamicStructuredTool<SchemaT, SchemaOutputT, SchemaInputT, ToolOutputT>;\n\nexport function tool<\n SchemaT extends ZodObjectV4,\n SchemaOutputT = InferInteropZodOutput<SchemaT>,\n SchemaInputT = InferInteropZodInput<SchemaT>,\n ToolOutputT = ToolOutputType\n>(\n func: RunnableFunc<SchemaOutputT, ToolOutputT, ToolRunnableConfig>,\n fields: ToolWrapperParams<SchemaT>\n): DynamicStructuredTool<SchemaT, SchemaOutputT, SchemaInputT, ToolOutputT>;\n\nexport function tool<\n SchemaT extends JSONSchema,\n SchemaOutputT = ToolInputSchemaOutputType<SchemaT>,\n SchemaInputT = ToolInputSchemaInputType<SchemaT>,\n ToolOutputT = ToolOutputType\n>(\n func: RunnableFunc<\n Parameters<DynamicStructuredToolInput<SchemaT>[\"func\"]>[0],\n ToolOutputT,\n ToolRunnableConfig\n >,\n fields: ToolWrapperParams<SchemaT>\n): DynamicStructuredTool<SchemaT, SchemaOutputT, SchemaInputT, ToolOutputT>;\n\nexport function tool<\n SchemaT extends\n | InteropZodObject\n | InteropZodType<string>\n | JSONSchema = InteropZodObject,\n SchemaOutputT = ToolInputSchemaOutputType<SchemaT>,\n SchemaInputT = ToolInputSchemaInputType<SchemaT>,\n ToolOutputT = ToolOutputType\n>(\n func: RunnableFunc<SchemaOutputT, ToolOutputT, ToolRunnableConfig>,\n fields: ToolWrapperParams<SchemaT>\n):\n | DynamicStructuredTool<SchemaT, SchemaOutputT, SchemaInputT, ToolOutputT>\n | DynamicTool<ToolOutputT> {\n const isSimpleStringSchema = isSimpleStringZodSchema(fields.schema);\n const isStringJSONSchema = validatesOnlyStrings(fields.schema);\n\n // If the schema is not provided, or it's a simple string schema, create a DynamicTool\n if (!fields.schema || isSimpleStringSchema || isStringJSONSchema) {\n return new DynamicTool<ToolOutputT>({\n ...fields,\n description:\n fields.description ??\n (fields.schema as { description?: string } | undefined)?.description ??\n `${fields.name} tool`,\n func: async (input, runManager, config) => {\n return new Promise<ToolOutputT>((resolve, reject) => {\n const childConfig = patchConfig(config, {\n callbacks: runManager?.getChild(),\n });\n // eslint-disable-next-line no-void\n void AsyncLocalStorageProviderSingleton.runWithConfig(\n pickRunnableConfigKeys(childConfig),\n async () => {\n try {\n // TS doesn't restrict the type here based on the guard above\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n resolve(func(input as any, childConfig));\n } catch (e) {\n reject(e);\n }\n }\n );\n });\n },\n });\n }\n\n const schema = fields.schema as InteropZodObject | JSONSchema;\n\n const description =\n fields.description ??\n (fields.schema as { description?: string }).description ??\n `${fields.name} tool`;\n\n return new DynamicStructuredTool<\n typeof schema,\n SchemaOutputT,\n SchemaInputT,\n ToolOutputT\n >({\n ...fields,\n description,\n schema,\n func: async (input, runManager, config) => {\n return new Promise<ToolOutputT>((resolve, reject) => {\n if (config?.signal) {\n config.signal.addEventListener(\"abort\", () => {\n return reject(getAbortSignalError(config.signal));\n });\n }\n\n const childConfig = patchConfig(config, {\n callbacks: runManager?.getChild(),\n });\n // eslint-disable-next-line no-void\n void AsyncLocalStorageProviderSingleton.runWithConfig(\n pickRunnableConfigKeys(childConfig),\n async () => {\n try {\n const result = await func(input, childConfig);\n\n /**\n * If the signal is aborted, we don't want to resolve the promise\n * as the promise is already rejected.\n */\n if (config?.signal?.aborted) {\n return;\n }\n\n resolve(result);\n } catch (e) {\n reject(e);\n }\n }\n );\n });\n },\n }) as DynamicStructuredTool<\n SchemaT,\n SchemaOutputT,\n SchemaInputT,\n ToolOutputT\n >;\n}\n\nfunction _formatToolOutput<TOutput extends ToolOutputType>(params: {\n content: TOutput;\n name: string;\n artifact?: unknown;\n toolCallId?: string;\n metadata?: Record<string, unknown>;\n}): ToolMessage | TOutput {\n const { content, artifact, toolCallId, metadata } = params;\n if (toolCallId && !isDirectToolOutput(content)) {\n if (\n typeof content === \"string\" ||\n (Array.isArray(content) &&\n content.every((item) => typeof item === \"object\"))\n ) {\n return new ToolMessage({\n status: \"success\",\n content,\n artifact,\n tool_call_id: toolCallId,\n name: params.name,\n metadata,\n });\n } else {\n return new ToolMessage({\n status: \"success\",\n content: _stringify(content),\n artifact,\n tool_call_id: toolCallId,\n name: params.name,\n metadata,\n });\n }\n } else {\n return content;\n }\n}\n\nfunction _stringify(content: unknown): string {\n try {\n return JSON.stringify(content, null, 2) ?? \"\";\n } catch (_noOp) {\n return `${content}`;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsFA,IAAsB,iBAAtB,cAMUA,2CAKV;;;;;;;CAaE,eAAe;CAEf,uBAAuB;CAEvB,IAAI,eAAe;AACjB,SAAO,CAAC,aAAa,OAAQ;CAC9B;;;;;;;;;;CAWD,iBAAkC;;;;CAKlC;CAEA,YAAYC,QAAqB;EAC/B,MAAM,UAAU,CAAE,EAAC;EAEnB,KAAK,uBACH,QAAQ,wBAAwB,KAAK;EACvC,KAAK,iBAAiB,QAAQ,kBAAkB,KAAK;EACrD,KAAK,gBAAgB,QAAQ,iBAAiB,KAAK;EACnD,KAAK,WAAW,QAAQ,YAAY,KAAK;CAC1C;;;;;;;CAcD,MAAM,OAIJC,OACAC,QACuD;EACvD,IAAIC;EAKJ,IAAIC,iBAAqCC,4BACvCC,4BAAa,KAAK,eAAe,OAAO,CACzC;AACD,MAAIC,0BAAY,MAAM,EAAE;GACtB,YAAY,MAAM;GAIlB,iBAAiB;IACf,GAAG;IACH,UAAU;GACX;EACF,OACC,YAAY;AAMd,SAAO,KAAK,KAAK,WAAW,eAAe;CAG5C;;;;;;;;;;;;CAaD,MAAM,KAIJC,KACAC,WAEAC,MACqD;EAGrD,MAAM,qBAAqBH,0BAAY,IAAI,GAAG,IAAI,OAAO;EAEzD,IAAII;AACJ,MAAIC,+BAAmB,KAAK,OAAO,CACjC,KAAI;GAEF,SAAS,MAAMC,8BACb,KAAK,QACL,mBACD;EACF,SAAQ,GAAG;GACV,IAAI,UAAU,CAAC,iDAAiD,CAAC;AACjE,OAAI,KAAK,sBACP,UAAU,GAAG,QAAQ,WAAW,EAAG,EAAY,SAAS;AAG1D,OAAI,aAAa,SAAS,EAAE,YAAY,SAAS,YAC/C,UAAU,GAAG,QAAQ,IAAI,EAAEC,SAAG,cAAc,EAAc,EAA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C,YAAO,OAAOC,mCAAoB,OAAO,OAAO,CAAC;IAClD,EAAC;IAGJ,MAAM,cAAcH,2BAAY,QAAQ,EACtC,WAAW,YAAY,UAAU,CAClC,EAAC;IAEGC,iDAAmC,cACtCC,sCAAuB,YAAY,EACnC,YAAY;AACV,SAAI;MACF,MAAM,SAAS,MAAM,KAAK,OAAO,YAAY;;;;;AAM7C,UAAI,QAAQ,QAAQ,QAClB;MAGF,QAAQ,OAAO;KAChB,SAAQ,GAAG;MACV,OAAO,EAAE;KACV;IACF,EACF;GACF;EACF;CACF;AAMF;AAED,SAAS,kBAAkDE,QAMjC;CACxB,MAAM,EAAE,SAAS,UAAU,YAAY,UAAU,GAAG;AACpD,KAAI,cAAc,CAACC,yCAAmB,QAAQ,CAC5C,KACE,OAAO,YAAY,YAClB,MAAM,QAAQ,QAAQ,IACrB,QAAQ,MAAM,CAAC,SAAS,OAAO,SAAS,SAAS,CAEnD,QAAO,IAAIC,kCAAY;EACrB,QAAQ;EACR;EACA;EACA,cAAc;EACd,MAAM,OAAO;EACb;CACD;KAED,QAAO,IAAIA,kCAAY;EACrB,QAAQ;EACR,SAAS,WAAW,QAAQ;EAC5B;EACA,cAAc;EACd,MAAM,OAAO;EACb;CACD;KAGH,QAAO;AAEV;AAED,SAAS,WAAWC,SAA0B;AAC5C,KAAI;AACF,SAAO,KAAK,UAAU,SAAS,MAAM,EAAE,IAAI;CAC5C,SAAQ,OAAO;AACd,SAAO,GAAG,SAAS;CACpB;AACF"}
@@ -12,6 +12,7 @@ import { BaseLangChain } from "../language_models/base.js";
12
12
  import { isLangChainTool, isRunnableToolLike, isStructuredTool, isStructuredToolParams } from "./types.js";
13
13
  import { z } from "zod/v3";
14
14
  import { validate } from "@cfworker/json-schema";
15
+ import { z as z$1 } from "zod/v4";
15
16
 
16
17
  //#region src/tools/index.ts
17
18
  var tools_exports = {};
@@ -62,6 +63,7 @@ var StructuredTool = class extends BaseLangChain {
62
63
  this.verboseParsingErrors = fields?.verboseParsingErrors ?? this.verboseParsingErrors;
63
64
  this.responseFormat = fields?.responseFormat ?? this.responseFormat;
64
65
  this.defaultConfig = fields?.defaultConfig ?? this.defaultConfig;
66
+ this.metadata = fields?.metadata ?? this.metadata;
65
67
  }
66
68
  /**
67
69
  * Invokes the tool with the provided input and configuration.
@@ -100,6 +102,7 @@ var StructuredTool = class extends BaseLangChain {
100
102
  } catch (e) {
101
103
  let message = `Received tool input did not match expected schema`;
102
104
  if (this.verboseParsingErrors) message = `${message}\nDetails: ${e.message}`;
105
+ if (e instanceof Error && e.constructor.name === "ZodError") message = `${message}\n\n${z$1.prettifyError(e)}`;
103
106
  throw new ToolInputParsingException(message, JSON.stringify(arg));
104
107
  }
105
108
  else {
@@ -134,7 +137,8 @@ var StructuredTool = class extends BaseLangChain {
134
137
  content,
135
138
  artifact,
136
139
  toolCallId,
137
- name: this.name
140
+ name: this.name,
141
+ metadata: this.metadata
138
142
  });
139
143
  await runManager?.handleToolEnd(formattedOutput);
140
144
  return formattedOutput;
@@ -288,18 +292,22 @@ function tool(func, fields) {
288
292
  });
289
293
  }
290
294
  function _formatToolOutput(params) {
291
- const { content, artifact, toolCallId } = params;
295
+ const { content, artifact, toolCallId, metadata } = params;
292
296
  if (toolCallId && !isDirectToolOutput(content)) if (typeof content === "string" || Array.isArray(content) && content.every((item) => typeof item === "object")) return new ToolMessage({
297
+ status: "success",
293
298
  content,
294
299
  artifact,
295
300
  tool_call_id: toolCallId,
296
- name: params.name
301
+ name: params.name,
302
+ metadata
297
303
  });
298
304
  else return new ToolMessage({
305
+ status: "success",
299
306
  content: _stringify(content),
300
307
  artifact,
301
308
  tool_call_id: toolCallId,
302
- name: params.name
309
+ name: params.name,
310
+ metadata
303
311
  });
304
312
  else return content;
305
313
  }