@langchain/core 1.1.6 → 1.1.8-dev-1766726832377

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 (302) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/caches/index.d.ts.map +1 -1
  3. package/dist/callbacks/base.cjs.map +1 -1
  4. package/dist/callbacks/base.d.cts +2 -2
  5. package/dist/callbacks/base.d.cts.map +1 -1
  6. package/dist/callbacks/base.d.ts +2 -2
  7. package/dist/callbacks/base.d.ts.map +1 -1
  8. package/dist/callbacks/base.js.map +1 -1
  9. package/dist/callbacks/manager.cjs +3 -3
  10. package/dist/callbacks/manager.cjs.map +1 -1
  11. package/dist/callbacks/manager.d.cts +1 -1
  12. package/dist/callbacks/manager.d.cts.map +1 -1
  13. package/dist/callbacks/manager.d.ts +1 -1
  14. package/dist/callbacks/manager.d.ts.map +1 -1
  15. package/dist/callbacks/manager.js +3 -3
  16. package/dist/callbacks/manager.js.map +1 -1
  17. package/dist/load/import_map.cjs +2 -0
  18. package/dist/load/import_map.cjs.map +1 -1
  19. package/dist/load/import_map.js +2 -0
  20. package/dist/load/import_map.js.map +1 -1
  21. package/dist/load/index.d.cts.map +1 -1
  22. package/dist/messages/base.cjs +1 -0
  23. package/dist/messages/base.cjs.map +1 -1
  24. package/dist/messages/base.d.cts +2 -3
  25. package/dist/messages/base.d.cts.map +1 -1
  26. package/dist/messages/base.d.ts +2 -3
  27. package/dist/messages/base.d.ts.map +1 -1
  28. package/dist/messages/base.js +1 -0
  29. package/dist/messages/base.js.map +1 -1
  30. package/dist/messages/message.cjs.map +1 -1
  31. package/dist/messages/message.d.cts +34 -1
  32. package/dist/messages/message.d.cts.map +1 -1
  33. package/dist/messages/message.d.ts +34 -1
  34. package/dist/messages/message.d.ts.map +1 -1
  35. package/dist/messages/message.js.map +1 -1
  36. package/dist/messages/tool.d.cts.map +1 -1
  37. package/dist/runnables/base.cjs +1 -1
  38. package/dist/runnables/base.cjs.map +1 -1
  39. package/dist/runnables/base.js +1 -1
  40. package/dist/runnables/base.js.map +1 -1
  41. package/dist/stores.d.cts.map +1 -1
  42. package/dist/tracers/base.cjs +5 -2
  43. package/dist/tracers/base.cjs.map +1 -1
  44. package/dist/tracers/base.d.cts +1 -1
  45. package/dist/tracers/base.d.cts.map +1 -1
  46. package/dist/tracers/base.d.ts +1 -1
  47. package/dist/tracers/base.d.ts.map +1 -1
  48. package/dist/tracers/base.js +5 -2
  49. package/dist/tracers/base.js.map +1 -1
  50. package/dist/tracers/tracer_langchain.cjs +31 -3
  51. package/dist/tracers/tracer_langchain.cjs.map +1 -1
  52. package/dist/tracers/tracer_langchain.d.cts +8 -7
  53. package/dist/tracers/tracer_langchain.d.cts.map +1 -1
  54. package/dist/tracers/tracer_langchain.d.ts +8 -7
  55. package/dist/tracers/tracer_langchain.d.ts.map +1 -1
  56. package/dist/tracers/tracer_langchain.js +31 -3
  57. package/dist/tracers/tracer_langchain.js.map +1 -1
  58. package/dist/utils/context.cjs +107 -0
  59. package/dist/utils/context.cjs.map +1 -0
  60. package/dist/utils/context.d.cts +44 -0
  61. package/dist/utils/context.d.cts.map +1 -0
  62. package/dist/utils/context.d.ts +44 -0
  63. package/dist/utils/context.d.ts.map +1 -0
  64. package/dist/utils/context.js +101 -0
  65. package/dist/utils/context.js.map +1 -0
  66. package/package.json +13 -2
  67. package/agents.cjs +0 -1
  68. package/agents.d.cts +0 -1
  69. package/agents.d.ts +0 -1
  70. package/agents.js +0 -1
  71. package/caches.cjs +0 -1
  72. package/caches.d.cts +0 -1
  73. package/caches.d.ts +0 -1
  74. package/caches.js +0 -1
  75. package/callbacks/base.cjs +0 -1
  76. package/callbacks/base.d.cts +0 -1
  77. package/callbacks/base.d.ts +0 -1
  78. package/callbacks/base.js +0 -1
  79. package/callbacks/dispatch/web.cjs +0 -1
  80. package/callbacks/dispatch/web.d.cts +0 -1
  81. package/callbacks/dispatch/web.d.ts +0 -1
  82. package/callbacks/dispatch/web.js +0 -1
  83. package/callbacks/dispatch.cjs +0 -1
  84. package/callbacks/dispatch.d.cts +0 -1
  85. package/callbacks/dispatch.d.ts +0 -1
  86. package/callbacks/dispatch.js +0 -1
  87. package/callbacks/manager.cjs +0 -1
  88. package/callbacks/manager.d.cts +0 -1
  89. package/callbacks/manager.d.ts +0 -1
  90. package/callbacks/manager.js +0 -1
  91. package/callbacks/promises.cjs +0 -1
  92. package/callbacks/promises.d.cts +0 -1
  93. package/callbacks/promises.d.ts +0 -1
  94. package/callbacks/promises.js +0 -1
  95. package/chat_history.cjs +0 -1
  96. package/chat_history.d.cts +0 -1
  97. package/chat_history.d.ts +0 -1
  98. package/chat_history.js +0 -1
  99. package/context.cjs +0 -1
  100. package/context.d.cts +0 -1
  101. package/context.d.ts +0 -1
  102. package/context.js +0 -1
  103. package/document_loaders/base.cjs +0 -1
  104. package/document_loaders/base.d.cts +0 -1
  105. package/document_loaders/base.d.ts +0 -1
  106. package/document_loaders/base.js +0 -1
  107. package/document_loaders/langsmith.cjs +0 -1
  108. package/document_loaders/langsmith.d.cts +0 -1
  109. package/document_loaders/langsmith.d.ts +0 -1
  110. package/document_loaders/langsmith.js +0 -1
  111. package/documents.cjs +0 -1
  112. package/documents.d.cts +0 -1
  113. package/documents.d.ts +0 -1
  114. package/documents.js +0 -1
  115. package/embeddings.cjs +0 -1
  116. package/embeddings.d.cts +0 -1
  117. package/embeddings.d.ts +0 -1
  118. package/embeddings.js +0 -1
  119. package/example_selectors.cjs +0 -1
  120. package/example_selectors.d.cts +0 -1
  121. package/example_selectors.d.ts +0 -1
  122. package/example_selectors.js +0 -1
  123. package/indexing.cjs +0 -1
  124. package/indexing.d.cts +0 -1
  125. package/indexing.d.ts +0 -1
  126. package/indexing.js +0 -1
  127. package/language_models/base.cjs +0 -1
  128. package/language_models/base.d.cts +0 -1
  129. package/language_models/base.d.ts +0 -1
  130. package/language_models/base.js +0 -1
  131. package/language_models/chat_models.cjs +0 -1
  132. package/language_models/chat_models.d.cts +0 -1
  133. package/language_models/chat_models.d.ts +0 -1
  134. package/language_models/chat_models.js +0 -1
  135. package/language_models/llms.cjs +0 -1
  136. package/language_models/llms.d.cts +0 -1
  137. package/language_models/llms.d.ts +0 -1
  138. package/language_models/llms.js +0 -1
  139. package/language_models/profile.cjs +0 -1
  140. package/language_models/profile.d.cts +0 -1
  141. package/language_models/profile.d.ts +0 -1
  142. package/language_models/profile.js +0 -1
  143. package/load/serializable.cjs +0 -1
  144. package/load/serializable.d.cts +0 -1
  145. package/load/serializable.d.ts +0 -1
  146. package/load/serializable.js +0 -1
  147. package/load.cjs +0 -1
  148. package/load.d.cts +0 -1
  149. package/load.d.ts +0 -1
  150. package/load.js +0 -1
  151. package/memory.cjs +0 -1
  152. package/memory.d.cts +0 -1
  153. package/memory.d.ts +0 -1
  154. package/memory.js +0 -1
  155. package/messages/tool.cjs +0 -1
  156. package/messages/tool.d.cts +0 -1
  157. package/messages/tool.d.ts +0 -1
  158. package/messages/tool.js +0 -1
  159. package/messages.cjs +0 -1
  160. package/messages.d.cts +0 -1
  161. package/messages.d.ts +0 -1
  162. package/messages.js +0 -1
  163. package/output_parsers/openai_functions.cjs +0 -1
  164. package/output_parsers/openai_functions.d.cts +0 -1
  165. package/output_parsers/openai_functions.d.ts +0 -1
  166. package/output_parsers/openai_functions.js +0 -1
  167. package/output_parsers/openai_tools.cjs +0 -1
  168. package/output_parsers/openai_tools.d.cts +0 -1
  169. package/output_parsers/openai_tools.d.ts +0 -1
  170. package/output_parsers/openai_tools.js +0 -1
  171. package/output_parsers.cjs +0 -1
  172. package/output_parsers.d.cts +0 -1
  173. package/output_parsers.d.ts +0 -1
  174. package/output_parsers.js +0 -1
  175. package/outputs.cjs +0 -1
  176. package/outputs.d.cts +0 -1
  177. package/outputs.d.ts +0 -1
  178. package/outputs.js +0 -1
  179. package/prompt_values.cjs +0 -1
  180. package/prompt_values.d.cts +0 -1
  181. package/prompt_values.d.ts +0 -1
  182. package/prompt_values.js +0 -1
  183. package/prompts.cjs +0 -1
  184. package/prompts.d.cts +0 -1
  185. package/prompts.d.ts +0 -1
  186. package/prompts.js +0 -1
  187. package/retrievers/document_compressors.cjs +0 -1
  188. package/retrievers/document_compressors.d.cts +0 -1
  189. package/retrievers/document_compressors.d.ts +0 -1
  190. package/retrievers/document_compressors.js +0 -1
  191. package/retrievers.cjs +0 -1
  192. package/retrievers.d.cts +0 -1
  193. package/retrievers.d.ts +0 -1
  194. package/retrievers.js +0 -1
  195. package/runnables/graph.cjs +0 -1
  196. package/runnables/graph.d.cts +0 -1
  197. package/runnables/graph.d.ts +0 -1
  198. package/runnables/graph.js +0 -1
  199. package/runnables.cjs +0 -1
  200. package/runnables.d.cts +0 -1
  201. package/runnables.d.ts +0 -1
  202. package/runnables.js +0 -1
  203. package/singletons.cjs +0 -1
  204. package/singletons.d.cts +0 -1
  205. package/singletons.d.ts +0 -1
  206. package/singletons.js +0 -1
  207. package/stores.cjs +0 -1
  208. package/stores.d.cts +0 -1
  209. package/stores.d.ts +0 -1
  210. package/stores.js +0 -1
  211. package/structured_query.cjs +0 -1
  212. package/structured_query.d.cts +0 -1
  213. package/structured_query.d.ts +0 -1
  214. package/structured_query.js +0 -1
  215. package/tools.cjs +0 -1
  216. package/tools.d.cts +0 -1
  217. package/tools.d.ts +0 -1
  218. package/tools.js +0 -1
  219. package/tracers/base.cjs +0 -1
  220. package/tracers/base.d.cts +0 -1
  221. package/tracers/base.d.ts +0 -1
  222. package/tracers/base.js +0 -1
  223. package/tracers/console.cjs +0 -1
  224. package/tracers/console.d.cts +0 -1
  225. package/tracers/console.d.ts +0 -1
  226. package/tracers/console.js +0 -1
  227. package/tracers/log_stream.cjs +0 -1
  228. package/tracers/log_stream.d.cts +0 -1
  229. package/tracers/log_stream.d.ts +0 -1
  230. package/tracers/log_stream.js +0 -1
  231. package/tracers/run_collector.cjs +0 -1
  232. package/tracers/run_collector.d.cts +0 -1
  233. package/tracers/run_collector.d.ts +0 -1
  234. package/tracers/run_collector.js +0 -1
  235. package/tracers/tracer_langchain.cjs +0 -1
  236. package/tracers/tracer_langchain.d.cts +0 -1
  237. package/tracers/tracer_langchain.d.ts +0 -1
  238. package/tracers/tracer_langchain.js +0 -1
  239. package/types/stream.cjs +0 -1
  240. package/types/stream.d.cts +0 -1
  241. package/types/stream.d.ts +0 -1
  242. package/types/stream.js +0 -1
  243. package/utils/async_caller.cjs +0 -1
  244. package/utils/async_caller.d.cts +0 -1
  245. package/utils/async_caller.d.ts +0 -1
  246. package/utils/async_caller.js +0 -1
  247. package/utils/chunk_array.cjs +0 -1
  248. package/utils/chunk_array.d.cts +0 -1
  249. package/utils/chunk_array.d.ts +0 -1
  250. package/utils/chunk_array.js +0 -1
  251. package/utils/env.cjs +0 -1
  252. package/utils/env.d.cts +0 -1
  253. package/utils/env.d.ts +0 -1
  254. package/utils/env.js +0 -1
  255. package/utils/event_source_parse.cjs +0 -1
  256. package/utils/event_source_parse.d.cts +0 -1
  257. package/utils/event_source_parse.d.ts +0 -1
  258. package/utils/event_source_parse.js +0 -1
  259. package/utils/format.cjs +0 -1
  260. package/utils/format.d.cts +0 -1
  261. package/utils/format.d.ts +0 -1
  262. package/utils/format.js +0 -1
  263. package/utils/function_calling.cjs +0 -1
  264. package/utils/function_calling.d.cts +0 -1
  265. package/utils/function_calling.d.ts +0 -1
  266. package/utils/function_calling.js +0 -1
  267. package/utils/hash.cjs +0 -1
  268. package/utils/hash.d.cts +0 -1
  269. package/utils/hash.d.ts +0 -1
  270. package/utils/hash.js +0 -1
  271. package/utils/json_patch.cjs +0 -1
  272. package/utils/json_patch.d.cts +0 -1
  273. package/utils/json_patch.d.ts +0 -1
  274. package/utils/json_patch.js +0 -1
  275. package/utils/json_schema.cjs +0 -1
  276. package/utils/json_schema.d.cts +0 -1
  277. package/utils/json_schema.d.ts +0 -1
  278. package/utils/json_schema.js +0 -1
  279. package/utils/math.cjs +0 -1
  280. package/utils/math.d.cts +0 -1
  281. package/utils/math.d.ts +0 -1
  282. package/utils/math.js +0 -1
  283. package/utils/stream.cjs +0 -1
  284. package/utils/stream.d.cts +0 -1
  285. package/utils/stream.d.ts +0 -1
  286. package/utils/stream.js +0 -1
  287. package/utils/testing.cjs +0 -1
  288. package/utils/testing.d.cts +0 -1
  289. package/utils/testing.d.ts +0 -1
  290. package/utils/testing.js +0 -1
  291. package/utils/tiktoken.cjs +0 -1
  292. package/utils/tiktoken.d.cts +0 -1
  293. package/utils/tiktoken.d.ts +0 -1
  294. package/utils/tiktoken.js +0 -1
  295. package/utils/types.cjs +0 -1
  296. package/utils/types.d.cts +0 -1
  297. package/utils/types.d.ts +0 -1
  298. package/utils/types.js +0 -1
  299. package/vectorstores.cjs +0 -1
  300. package/vectorstores.d.cts +0 -1
  301. package/vectorstores.d.ts +0 -1
  302. package/vectorstores.js +0 -1
@@ -0,0 +1,44 @@
1
+ //#region src/utils/context.d.ts
2
+ /**
3
+ * A tagged template function for creating formatted strings.
4
+ *
5
+ * This utility provides a clean, template literal-based API for string formatting
6
+ * that can be used for prompts, descriptions, and other text formatting needs.
7
+ *
8
+ * It automatically handles whitespace normalization and indentation, making it
9
+ * ideal for multi-line strings in code.
10
+ *
11
+ * When using this utility, it will:
12
+ * - Strip common leading indentation from all lines
13
+ * - Trim leading/trailing whitespace
14
+ * - Align multi-line interpolated values to match indentation
15
+ * - Support escape sequences: `\\n` (newline), `\\`` (backtick), `\\$` (dollar), `\\{` (brace)
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * import { context } from "@langchain/core/utils/context";
20
+ *
21
+ * const role = "agent";
22
+ * const prompt = context`
23
+ * You are an ${role}.
24
+ * Your task is to help users.
25
+ * `;
26
+ * // Returns: "You are an agent.\nYour task is to help users."
27
+ * ```
28
+ *
29
+ * @example
30
+ * ```typescript
31
+ * // Multi-line interpolated values are aligned
32
+ * const items = "- Item 1\n- Item 2\n- Item 3";
33
+ * const message = context`
34
+ * Shopping list:
35
+ * ${items}
36
+ * End of list.
37
+ * `;
38
+ * // The items will be indented to match " " (4 spaces)
39
+ * ```
40
+ */
41
+ declare function context(strings: TemplateStringsArray, ...values: unknown[]): string;
42
+ //#endregion
43
+ export { context };
44
+ //# sourceMappingURL=context.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.d.cts","names":["context","TemplateStringsArray"],"sources":["../../src/utils/context.d.ts"],"sourcesContent":["/**\n * A tagged template function for creating formatted strings.\n *\n * This utility provides a clean, template literal-based API for string formatting\n * that can be used for prompts, descriptions, and other text formatting needs.\n *\n * It automatically handles whitespace normalization and indentation, making it\n * ideal for multi-line strings in code.\n *\n * When using this utility, it will:\n * - Strip common leading indentation from all lines\n * - Trim leading/trailing whitespace\n * - Align multi-line interpolated values to match indentation\n * - Support escape sequences: `\\\\n` (newline), `\\\\`` (backtick), `\\\\$` (dollar), `\\\\{` (brace)\n *\n * @example\n * ```typescript\n * import { context } from \"@langchain/core/utils/context\";\n *\n * const role = \"agent\";\n * const prompt = context`\n * You are an ${role}.\n * Your task is to help users.\n * `;\n * // Returns: \"You are an agent.\\nYour task is to help users.\"\n * ```\n *\n * @example\n * ```typescript\n * // Multi-line interpolated values are aligned\n * const items = \"- Item 1\\n- Item 2\\n- Item 3\";\n * const message = context`\n * Shopping list:\n * ${items}\n * End of list.\n * `;\n * // The items will be indented to match \" \" (4 spaces)\n * ```\n */\nexport declare function context(strings: TemplateStringsArray, ...values: unknown[]): string;\n//# sourceMappingURL=context.d.ts.map"],"mappings":";;AAuCA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAAwBA,OAAAA,UAAiBC"}
@@ -0,0 +1,44 @@
1
+ //#region src/utils/context.d.ts
2
+ /**
3
+ * A tagged template function for creating formatted strings.
4
+ *
5
+ * This utility provides a clean, template literal-based API for string formatting
6
+ * that can be used for prompts, descriptions, and other text formatting needs.
7
+ *
8
+ * It automatically handles whitespace normalization and indentation, making it
9
+ * ideal for multi-line strings in code.
10
+ *
11
+ * When using this utility, it will:
12
+ * - Strip common leading indentation from all lines
13
+ * - Trim leading/trailing whitespace
14
+ * - Align multi-line interpolated values to match indentation
15
+ * - Support escape sequences: `\\n` (newline), `\\`` (backtick), `\\$` (dollar), `\\{` (brace)
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * import { context } from "@langchain/core/utils/context";
20
+ *
21
+ * const role = "agent";
22
+ * const prompt = context`
23
+ * You are an ${role}.
24
+ * Your task is to help users.
25
+ * `;
26
+ * // Returns: "You are an agent.\nYour task is to help users."
27
+ * ```
28
+ *
29
+ * @example
30
+ * ```typescript
31
+ * // Multi-line interpolated values are aligned
32
+ * const items = "- Item 1\n- Item 2\n- Item 3";
33
+ * const message = context`
34
+ * Shopping list:
35
+ * ${items}
36
+ * End of list.
37
+ * `;
38
+ * // The items will be indented to match " " (4 spaces)
39
+ * ```
40
+ */
41
+ declare function context(strings: TemplateStringsArray, ...values: unknown[]): string;
42
+ //#endregion
43
+ export { context };
44
+ //# sourceMappingURL=context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.d.ts","names":["context","TemplateStringsArray"],"sources":["../../src/utils/context.d.ts"],"sourcesContent":["/**\n * A tagged template function for creating formatted strings.\n *\n * This utility provides a clean, template literal-based API for string formatting\n * that can be used for prompts, descriptions, and other text formatting needs.\n *\n * It automatically handles whitespace normalization and indentation, making it\n * ideal for multi-line strings in code.\n *\n * When using this utility, it will:\n * - Strip common leading indentation from all lines\n * - Trim leading/trailing whitespace\n * - Align multi-line interpolated values to match indentation\n * - Support escape sequences: `\\\\n` (newline), `\\\\`` (backtick), `\\\\$` (dollar), `\\\\{` (brace)\n *\n * @example\n * ```typescript\n * import { context } from \"@langchain/core/utils/context\";\n *\n * const role = \"agent\";\n * const prompt = context`\n * You are an ${role}.\n * Your task is to help users.\n * `;\n * // Returns: \"You are an agent.\\nYour task is to help users.\"\n * ```\n *\n * @example\n * ```typescript\n * // Multi-line interpolated values are aligned\n * const items = \"- Item 1\\n- Item 2\\n- Item 3\";\n * const message = context`\n * Shopping list:\n * ${items}\n * End of list.\n * `;\n * // The items will be indented to match \" \" (4 spaces)\n * ```\n */\nexport declare function context(strings: TemplateStringsArray, ...values: unknown[]): string;\n//# sourceMappingURL=context.d.ts.map"],"mappings":";;AAuCA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAAwBA,OAAAA,UAAiBC"}
@@ -0,0 +1,101 @@
1
+ import { __export } from "../_virtual/rolldown_runtime.js";
2
+
3
+ //#region src/utils/context.ts
4
+ var context_exports = {};
5
+ __export(context_exports, { context: () => context });
6
+ /**
7
+ * A tagged template function for creating formatted strings.
8
+ *
9
+ * This utility provides a clean, template literal-based API for string formatting
10
+ * that can be used for prompts, descriptions, and other text formatting needs.
11
+ *
12
+ * It automatically handles whitespace normalization and indentation, making it
13
+ * ideal for multi-line strings in code.
14
+ *
15
+ * When using this utility, it will:
16
+ * - Strip common leading indentation from all lines
17
+ * - Trim leading/trailing whitespace
18
+ * - Align multi-line interpolated values to match indentation
19
+ * - Support escape sequences: `\\n` (newline), `\\`` (backtick), `\\$` (dollar), `\\{` (brace)
20
+ *
21
+ * @example
22
+ * ```typescript
23
+ * import { context } from "@langchain/core/utils/context";
24
+ *
25
+ * const role = "agent";
26
+ * const prompt = context`
27
+ * You are an ${role}.
28
+ * Your task is to help users.
29
+ * `;
30
+ * // Returns: "You are an agent.\nYour task is to help users."
31
+ * ```
32
+ *
33
+ * @example
34
+ * ```typescript
35
+ * // Multi-line interpolated values are aligned
36
+ * const items = "- Item 1\n- Item 2\n- Item 3";
37
+ * const message = context`
38
+ * Shopping list:
39
+ * ${items}
40
+ * End of list.
41
+ * `;
42
+ * // The items will be indented to match " " (4 spaces)
43
+ * ```
44
+ */
45
+ function context(strings, ...values) {
46
+ const raw = strings.raw;
47
+ let result = "";
48
+ for (let i = 0; i < raw.length; i++) {
49
+ const next = raw[i].replace(/\\\n[ \t]*/g, "").replace(/\\`/g, "`").replace(/\\\$/g, "$").replace(/\\\{/g, "{");
50
+ result += next;
51
+ if (i < values.length) {
52
+ const value = alignValue(values[i], result);
53
+ result += typeof value === "string" ? value : JSON.stringify(value);
54
+ }
55
+ }
56
+ result = stripIndent(result);
57
+ result = result.trim();
58
+ result = result.replace(/\\n/g, "\n");
59
+ return result;
60
+ }
61
+ /**
62
+ * Adjusts the indentation of a multi-line interpolated value to match the current line.
63
+ *
64
+ * @param value - The interpolated value
65
+ * @param precedingText - The text that comes before this value
66
+ * @returns The value with adjusted indentation
67
+ */
68
+ function alignValue(value, precedingText) {
69
+ if (typeof value !== "string" || !value.includes("\n")) return value;
70
+ const currentLine = precedingText.slice(precedingText.lastIndexOf("\n") + 1);
71
+ const indentMatch = currentLine.match(/^(\s+)/);
72
+ if (indentMatch) {
73
+ const indent = indentMatch[1];
74
+ return value.replace(/\n/g, `\n${indent}`);
75
+ }
76
+ return value;
77
+ }
78
+ /**
79
+ * Strips common leading indentation from all lines.
80
+ *
81
+ * @param text - The text to process
82
+ * @returns The text with common indentation removed
83
+ */
84
+ function stripIndent(text) {
85
+ const lines = text.split("\n");
86
+ let minIndent = null;
87
+ for (const line of lines) {
88
+ const match = line.match(/^(\s+)\S+/);
89
+ if (match) {
90
+ const indent = match[1].length;
91
+ if (minIndent === null) minIndent = indent;
92
+ else minIndent = Math.min(minIndent, indent);
93
+ }
94
+ }
95
+ if (minIndent === null) return text;
96
+ return lines.map((line) => line[0] === " " || line[0] === " " ? line.slice(minIndent) : line).join("\n");
97
+ }
98
+
99
+ //#endregion
100
+ export { context, context_exports };
101
+ //# sourceMappingURL=context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.js","names":["strings: TemplateStringsArray","value: unknown","precedingText: string","text: string","minIndent: number | null"],"sources":["../../src/utils/context.ts"],"sourcesContent":["/**\n * A tagged template function for creating formatted strings.\n *\n * This utility provides a clean, template literal-based API for string formatting\n * that can be used for prompts, descriptions, and other text formatting needs.\n *\n * It automatically handles whitespace normalization and indentation, making it\n * ideal for multi-line strings in code.\n *\n * When using this utility, it will:\n * - Strip common leading indentation from all lines\n * - Trim leading/trailing whitespace\n * - Align multi-line interpolated values to match indentation\n * - Support escape sequences: `\\\\n` (newline), `\\\\`` (backtick), `\\\\$` (dollar), `\\\\{` (brace)\n *\n * @example\n * ```typescript\n * import { context } from \"@langchain/core/utils/context\";\n *\n * const role = \"agent\";\n * const prompt = context`\n * You are an ${role}.\n * Your task is to help users.\n * `;\n * // Returns: \"You are an agent.\\nYour task is to help users.\"\n * ```\n *\n * @example\n * ```typescript\n * // Multi-line interpolated values are aligned\n * const items = \"- Item 1\\n- Item 2\\n- Item 3\";\n * const message = context`\n * Shopping list:\n * ${items}\n * End of list.\n * `;\n * // The items will be indented to match \" \" (4 spaces)\n * ```\n */\nexport function context(\n strings: TemplateStringsArray,\n ...values: unknown[]\n): string {\n const raw = strings.raw;\n let result = \"\";\n\n for (let i = 0; i < raw.length; i++) {\n // Handle escaped characters in template literals\n const next = raw[i]\n .replace(/\\\\\\n[ \\t]*/g, \"\") // escaped newlines (line continuation)\n .replace(/\\\\`/g, \"`\") // escaped backticks\n .replace(/\\\\\\$/g, \"$\") // escaped dollar signs\n .replace(/\\\\\\{/g, \"{\"); // escaped braces\n\n result += next;\n\n if (i < values.length) {\n const value = alignValue(values[i], result);\n result += typeof value === \"string\" ? value : JSON.stringify(value);\n }\n }\n\n // Strip common indentation\n result = stripIndent(result);\n\n // Trim leading/trailing whitespace\n result = result.trim();\n\n // Handle escaped \\n at the end (preserve intentional newlines)\n result = result.replace(/\\\\n/g, \"\\n\");\n\n return result;\n}\n\n/**\n * Adjusts the indentation of a multi-line interpolated value to match the current line.\n *\n * @param value - The interpolated value\n * @param precedingText - The text that comes before this value\n * @returns The value with adjusted indentation\n */\nfunction alignValue(value: unknown, precedingText: string): unknown {\n if (typeof value !== \"string\" || !value.includes(\"\\n\")) {\n return value;\n }\n\n const currentLine = precedingText.slice(precedingText.lastIndexOf(\"\\n\") + 1);\n const indentMatch = currentLine.match(/^(\\s+)/);\n\n if (indentMatch) {\n const indent = indentMatch[1];\n return value.replace(/\\n/g, `\\n${indent}`);\n }\n\n return value;\n}\n\n/**\n * Strips common leading indentation from all lines.\n *\n * @param text - The text to process\n * @returns The text with common indentation removed\n */\nfunction stripIndent(text: string): string {\n const lines = text.split(\"\\n\");\n\n // Find minimum indentation (only from lines that have content)\n let minIndent: number | null = null;\n for (const line of lines) {\n const match = line.match(/^(\\s+)\\S+/);\n if (match) {\n const indent = match[1].length;\n if (minIndent === null) {\n minIndent = indent;\n } else {\n minIndent = Math.min(minIndent, indent);\n }\n }\n }\n\n if (minIndent === null) {\n return text;\n }\n\n // Remove the common indentation from all lines\n return lines\n .map((line) =>\n line[0] === \" \" || line[0] === \"\\t\" ? line.slice(minIndent) : line\n )\n .join(\"\\n\");\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuCA,SAAgB,QACdA,SACA,GAAG,QACK;CACR,MAAM,MAAM,QAAQ;CACpB,IAAI,SAAS;AAEb,MAAK,IAAI,IAAI,GAAG,IAAI,IAAI,QAAQ,KAAK;EAEnC,MAAM,OAAO,IAAI,GACd,QAAQ,eAAe,GAAG,CAC1B,QAAQ,QAAQ,IAAI,CACpB,QAAQ,SAAS,IAAI,CACrB,QAAQ,SAAS,IAAI;EAExB,UAAU;AAEV,MAAI,IAAI,OAAO,QAAQ;GACrB,MAAM,QAAQ,WAAW,OAAO,IAAI,OAAO;GAC3C,UAAU,OAAO,UAAU,WAAW,QAAQ,KAAK,UAAU,MAAM;EACpE;CACF;CAGD,SAAS,YAAY,OAAO;CAG5B,SAAS,OAAO,MAAM;CAGtB,SAAS,OAAO,QAAQ,QAAQ,KAAK;AAErC,QAAO;AACR;;;;;;;;AASD,SAAS,WAAWC,OAAgBC,eAAgC;AAClE,KAAI,OAAO,UAAU,YAAY,CAAC,MAAM,SAAS,KAAK,CACpD,QAAO;CAGT,MAAM,cAAc,cAAc,MAAM,cAAc,YAAY,KAAK,GAAG,EAAE;CAC5E,MAAM,cAAc,YAAY,MAAM,SAAS;AAE/C,KAAI,aAAa;EACf,MAAM,SAAS,YAAY;AAC3B,SAAO,MAAM,QAAQ,OAAO,CAAC,EAAE,EAAE,QAAQ,CAAC;CAC3C;AAED,QAAO;AACR;;;;;;;AAQD,SAAS,YAAYC,MAAsB;CACzC,MAAM,QAAQ,KAAK,MAAM,KAAK;CAG9B,IAAIC,YAA2B;AAC/B,MAAK,MAAM,QAAQ,OAAO;EACxB,MAAM,QAAQ,KAAK,MAAM,YAAY;AACrC,MAAI,OAAO;GACT,MAAM,SAAS,MAAM,GAAG;AACxB,OAAI,cAAc,MAChB,YAAY;QAEZ,YAAY,KAAK,IAAI,WAAW,OAAO;EAE1C;CACF;AAED,KAAI,cAAc,KAChB,QAAO;AAIT,QAAO,MACJ,IAAI,CAAC,SACJ,KAAK,OAAO,OAAO,KAAK,OAAO,MAAO,KAAK,MAAM,UAAU,GAAG,KAC/D,CACA,KAAK,KAAK;AACd"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@langchain/core",
3
- "version": "1.1.6",
3
+ "version": "1.1.8-dev-1766726832377",
4
4
  "description": "Core LangChain.js abstractions and schemas",
5
5
  "type": "module",
6
6
  "engines": {
@@ -21,7 +21,7 @@
21
21
  "camelcase": "6",
22
22
  "decamelize": "1.2.0",
23
23
  "js-tiktoken": "^1.0.12",
24
- "langsmith": "^0.3.82",
24
+ "langsmith": ">=0.4.0 <1.0.0",
25
25
  "mustache": "^4.2.0",
26
26
  "p-queue": "^6.6.2",
27
27
  "uuid": "^10.0.0",
@@ -578,6 +578,17 @@
578
578
  "default": "./dist/utils/chunk_array.js"
579
579
  }
580
580
  },
581
+ "./utils/context": {
582
+ "input": "./src/utils/context.ts",
583
+ "require": {
584
+ "types": "./dist/utils/context.d.cts",
585
+ "default": "./dist/utils/context.cjs"
586
+ },
587
+ "import": {
588
+ "types": "./dist/utils/context.d.ts",
589
+ "default": "./dist/utils/context.js"
590
+ }
591
+ },
581
592
  "./utils/env": {
582
593
  "input": "./src/utils/env.ts",
583
594
  "require": {
package/agents.cjs DELETED
@@ -1 +0,0 @@
1
- module.exports = require("./dist/agents.cjs");
package/agents.d.cts DELETED
@@ -1 +0,0 @@
1
- export * from "./dist/agents.js";
package/agents.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from "./dist/agents.js";
package/agents.js DELETED
@@ -1 +0,0 @@
1
- export * from "./dist/agents.js";
package/caches.cjs DELETED
@@ -1 +0,0 @@
1
- module.exports = require("./dist/caches/index.cjs");
package/caches.d.cts DELETED
@@ -1 +0,0 @@
1
- export * from "./dist/caches/index.js";
package/caches.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from "./dist/caches/index.js";
package/caches.js DELETED
@@ -1 +0,0 @@
1
- export * from "./dist/caches/index.js";
@@ -1 +0,0 @@
1
- module.exports = require("../dist/callbacks/base.cjs");
@@ -1 +0,0 @@
1
- export * from "../dist/callbacks/base.js";
@@ -1 +0,0 @@
1
- export * from "../dist/callbacks/base.js";
package/callbacks/base.js DELETED
@@ -1 +0,0 @@
1
- export * from "../dist/callbacks/base.js";
@@ -1 +0,0 @@
1
- module.exports = require("../../dist/callbacks/dispatch/web.cjs");
@@ -1 +0,0 @@
1
- export * from "../../dist/callbacks/dispatch/web.js";
@@ -1 +0,0 @@
1
- export * from "../../dist/callbacks/dispatch/web.js";
@@ -1 +0,0 @@
1
- export * from "../../dist/callbacks/dispatch/web.js";
@@ -1 +0,0 @@
1
- module.exports = require("../dist/callbacks/dispatch/index.cjs");
@@ -1 +0,0 @@
1
- export * from "../dist/callbacks/dispatch/index.js";
@@ -1 +0,0 @@
1
- export * from "../dist/callbacks/dispatch/index.js";
@@ -1 +0,0 @@
1
- export * from "../dist/callbacks/dispatch/index.js";
@@ -1 +0,0 @@
1
- module.exports = require("../dist/callbacks/manager.cjs");
@@ -1 +0,0 @@
1
- export * from "../dist/callbacks/manager.js";
@@ -1 +0,0 @@
1
- export * from "../dist/callbacks/manager.js";
@@ -1 +0,0 @@
1
- export * from "../dist/callbacks/manager.js";
@@ -1 +0,0 @@
1
- module.exports = require("../dist/callbacks/promises.cjs");
@@ -1 +0,0 @@
1
- export * from "../dist/callbacks/promises.js";
@@ -1 +0,0 @@
1
- export * from "../dist/callbacks/promises.js";
@@ -1 +0,0 @@
1
- export * from "../dist/callbacks/promises.js";
package/chat_history.cjs DELETED
@@ -1 +0,0 @@
1
- module.exports = require("./dist/chat_history.cjs");
@@ -1 +0,0 @@
1
- export * from "./dist/chat_history.js";
package/chat_history.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from "./dist/chat_history.js";
package/chat_history.js DELETED
@@ -1 +0,0 @@
1
- export * from "./dist/chat_history.js";
package/context.cjs DELETED
@@ -1 +0,0 @@
1
- module.exports = require("./dist/context.cjs");
package/context.d.cts DELETED
@@ -1 +0,0 @@
1
- export * from "./dist/context.js";
package/context.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from "./dist/context.js";
package/context.js DELETED
@@ -1 +0,0 @@
1
- export * from "./dist/context.js";
@@ -1 +0,0 @@
1
- module.exports = require("../dist/document_loaders/base.cjs");
@@ -1 +0,0 @@
1
- export * from "../dist/document_loaders/base.js";
@@ -1 +0,0 @@
1
- export * from "../dist/document_loaders/base.js";
@@ -1 +0,0 @@
1
- export * from "../dist/document_loaders/base.js";
@@ -1 +0,0 @@
1
- module.exports = require("../dist/document_loaders/langsmith.cjs");
@@ -1 +0,0 @@
1
- export * from "../dist/document_loaders/langsmith.js";
@@ -1 +0,0 @@
1
- export * from "../dist/document_loaders/langsmith.js";
@@ -1 +0,0 @@
1
- export * from "../dist/document_loaders/langsmith.js";
package/documents.cjs DELETED
@@ -1 +0,0 @@
1
- module.exports = require("./dist/documents/index.cjs");
package/documents.d.cts DELETED
@@ -1 +0,0 @@
1
- export * from "./dist/documents/index.js";
package/documents.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from "./dist/documents/index.js";
package/documents.js DELETED
@@ -1 +0,0 @@
1
- export * from "./dist/documents/index.js";
package/embeddings.cjs DELETED
@@ -1 +0,0 @@
1
- module.exports = require("./dist/embeddings.cjs");
package/embeddings.d.cts DELETED
@@ -1 +0,0 @@
1
- export * from "./dist/embeddings.js";
package/embeddings.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from "./dist/embeddings.js";
package/embeddings.js DELETED
@@ -1 +0,0 @@
1
- export * from "./dist/embeddings.js";
@@ -1 +0,0 @@
1
- module.exports = require("./dist/example_selectors/index.cjs");
@@ -1 +0,0 @@
1
- export * from "./dist/example_selectors/index.js";
@@ -1 +0,0 @@
1
- export * from "./dist/example_selectors/index.js";
@@ -1 +0,0 @@
1
- export * from "./dist/example_selectors/index.js";
package/indexing.cjs DELETED
@@ -1 +0,0 @@
1
- module.exports = require("./dist/indexing/index.cjs");
package/indexing.d.cts DELETED
@@ -1 +0,0 @@
1
- export * from "./dist/indexing/index.js";
package/indexing.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from "./dist/indexing/index.js";
package/indexing.js DELETED
@@ -1 +0,0 @@
1
- export * from "./dist/indexing/index.js";
@@ -1 +0,0 @@
1
- module.exports = require("../dist/language_models/base.cjs");
@@ -1 +0,0 @@
1
- export * from "../dist/language_models/base.js";
@@ -1 +0,0 @@
1
- export * from "../dist/language_models/base.js";
@@ -1 +0,0 @@
1
- export * from "../dist/language_models/base.js";
@@ -1 +0,0 @@
1
- module.exports = require("../dist/language_models/chat_models.cjs");
@@ -1 +0,0 @@
1
- export * from "../dist/language_models/chat_models.js";
@@ -1 +0,0 @@
1
- export * from "../dist/language_models/chat_models.js";
@@ -1 +0,0 @@
1
- export * from "../dist/language_models/chat_models.js";
@@ -1 +0,0 @@
1
- module.exports = require("../dist/language_models/llms.cjs");
@@ -1 +0,0 @@
1
- export * from "../dist/language_models/llms.js";
@@ -1 +0,0 @@
1
- export * from "../dist/language_models/llms.js";
@@ -1 +0,0 @@
1
- export * from "../dist/language_models/llms.js";
@@ -1 +0,0 @@
1
- module.exports = require("../dist/language_models/profile.cjs");
@@ -1 +0,0 @@
1
- export * from "../dist/language_models/profile.js";
@@ -1 +0,0 @@
1
- export * from "../dist/language_models/profile.js";
@@ -1 +0,0 @@
1
- export * from "../dist/language_models/profile.js";
@@ -1 +0,0 @@
1
- module.exports = require("../dist/load/serializable.cjs");
@@ -1 +0,0 @@
1
- export * from "../dist/load/serializable.js";
@@ -1 +0,0 @@
1
- export * from "../dist/load/serializable.js";
@@ -1 +0,0 @@
1
- export * from "../dist/load/serializable.js";
package/load.cjs DELETED
@@ -1 +0,0 @@
1
- module.exports = require("./dist/load/index.cjs");
package/load.d.cts DELETED
@@ -1 +0,0 @@
1
- export * from "./dist/load/index.js";
package/load.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from "./dist/load/index.js";
package/load.js DELETED
@@ -1 +0,0 @@
1
- export * from "./dist/load/index.js";
package/memory.cjs DELETED
@@ -1 +0,0 @@
1
- module.exports = require("./dist/memory.cjs");
package/memory.d.cts DELETED
@@ -1 +0,0 @@
1
- export * from "./dist/memory.js";
package/memory.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from "./dist/memory.js";
package/memory.js DELETED
@@ -1 +0,0 @@
1
- export * from "./dist/memory.js";
package/messages/tool.cjs DELETED
@@ -1 +0,0 @@
1
- module.exports = require("../dist/messages/tool.cjs");
@@ -1 +0,0 @@
1
- export * from "../dist/messages/tool.js";
@@ -1 +0,0 @@
1
- export * from "../dist/messages/tool.js";
package/messages/tool.js DELETED
@@ -1 +0,0 @@
1
- export * from "../dist/messages/tool.js";
package/messages.cjs DELETED
@@ -1 +0,0 @@
1
- module.exports = require("./dist/messages/index.cjs");
package/messages.d.cts DELETED
@@ -1 +0,0 @@
1
- export * from "./dist/messages/index.js";
package/messages.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from "./dist/messages/index.js";
package/messages.js DELETED
@@ -1 +0,0 @@
1
- export * from "./dist/messages/index.js";
@@ -1 +0,0 @@
1
- module.exports = require("../dist/output_parsers/openai_functions/index.cjs");
@@ -1 +0,0 @@
1
- export * from "../dist/output_parsers/openai_functions/index.js";
@@ -1 +0,0 @@
1
- export * from "../dist/output_parsers/openai_functions/index.js";
@@ -1 +0,0 @@
1
- export * from "../dist/output_parsers/openai_functions/index.js";
@@ -1 +0,0 @@
1
- module.exports = require("../dist/output_parsers/openai_tools/index.cjs");
@@ -1 +0,0 @@
1
- export * from "../dist/output_parsers/openai_tools/index.js";
@@ -1 +0,0 @@
1
- export * from "../dist/output_parsers/openai_tools/index.js";
@@ -1 +0,0 @@
1
- export * from "../dist/output_parsers/openai_tools/index.js";