langchain 0.0.194 → 0.0.196

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 (241) hide show
  1. package/dist/agents/toolkits/conversational_retrieval/token_buffer_memory.d.ts +1 -1
  2. package/dist/base_language/count_tokens.cjs +5 -70
  3. package/dist/base_language/count_tokens.d.ts +1 -10
  4. package/dist/base_language/count_tokens.js +1 -65
  5. package/dist/base_language/index.cjs +6 -196
  6. package/dist/base_language/index.d.ts +1 -111
  7. package/dist/base_language/index.js +1 -191
  8. package/dist/cache/base.cjs +15 -37
  9. package/dist/cache/base.d.ts +1 -20
  10. package/dist/cache/base.js +1 -33
  11. package/dist/cache/index.cjs +2 -46
  12. package/dist/cache/index.d.ts +1 -29
  13. package/dist/cache/index.js +1 -45
  14. package/dist/callbacks/base.cjs +3 -139
  15. package/dist/callbacks/base.d.ts +1 -266
  16. package/dist/callbacks/base.js +1 -126
  17. package/dist/callbacks/handlers/console.cjs +14 -221
  18. package/dist/callbacks/handlers/console.d.ts +1 -117
  19. package/dist/callbacks/handlers/console.js +1 -217
  20. package/dist/callbacks/handlers/initialize.cjs +15 -30
  21. package/dist/callbacks/handlers/initialize.d.ts +1 -16
  22. package/dist/callbacks/handlers/initialize.js +1 -27
  23. package/dist/callbacks/handlers/log_stream.cjs +15 -293
  24. package/dist/callbacks/handlers/log_stream.d.ts +1 -100
  25. package/dist/callbacks/handlers/log_stream.js +1 -289
  26. package/dist/callbacks/handlers/run_collector.cjs +15 -48
  27. package/dist/callbacks/handlers/run_collector.d.ts +1 -26
  28. package/dist/callbacks/handlers/run_collector.js +1 -46
  29. package/dist/callbacks/handlers/tracer.cjs +15 -375
  30. package/dist/callbacks/handlers/tracer.d.ts +1 -70
  31. package/dist/callbacks/handlers/tracer.js +1 -373
  32. package/dist/callbacks/handlers/tracer_langchain.cjs +15 -104
  33. package/dist/callbacks/handlers/tracer_langchain.d.ts +1 -41
  34. package/dist/callbacks/handlers/tracer_langchain.js +1 -102
  35. package/dist/callbacks/handlers/tracer_langchain_v1.cjs +15 -197
  36. package/dist/callbacks/handlers/tracer_langchain_v1.d.ts +1 -57
  37. package/dist/callbacks/handlers/tracer_langchain_v1.js +1 -195
  38. package/dist/callbacks/manager.cjs +15 -676
  39. package/dist/callbacks/manager.d.ts +1 -180
  40. package/dist/callbacks/manager.js +1 -666
  41. package/dist/callbacks/promises.cjs +14 -42
  42. package/dist/callbacks/promises.d.ts +1 -11
  43. package/dist/callbacks/promises.js +1 -37
  44. package/dist/chains/graph_qa/prompts.d.ts +1 -1
  45. package/dist/chains/openai_functions/structured_output.cjs +2 -2
  46. package/dist/chains/openai_functions/structured_output.d.ts +1 -1
  47. package/dist/chains/openai_functions/structured_output.js +1 -1
  48. package/dist/chat_models/baiduwenxin.d.ts +1 -1
  49. package/dist/chat_models/base.cjs +15 -296
  50. package/dist/chat_models/base.d.ts +1 -122
  51. package/dist/chat_models/base.js +1 -292
  52. package/dist/chat_models/bedrock/web.d.ts +1 -1
  53. package/dist/chat_models/fireworks.d.ts +1 -1
  54. package/dist/document.cjs +2 -24
  55. package/dist/document.d.ts +1 -12
  56. package/dist/document.js +1 -23
  57. package/dist/document_loaders/web/azure_blob_storage_file.d.ts +1 -1
  58. package/dist/document_loaders/web/s3.d.ts +1 -1
  59. package/dist/embeddings/base.cjs +15 -22
  60. package/dist/embeddings/base.d.ts +1 -33
  61. package/dist/embeddings/base.js +1 -20
  62. package/dist/embeddings/cache_backed.cjs +2 -2
  63. package/dist/embeddings/cache_backed.js +1 -1
  64. package/dist/embeddings/hf.cjs +1 -2
  65. package/dist/embeddings/hf.js +1 -2
  66. package/dist/evaluation/agents/trajectory.d.ts +1 -1
  67. package/dist/evaluation/criteria/prompt.d.ts +2 -2
  68. package/dist/evaluation/qa/prompt.d.ts +2 -2
  69. package/dist/experimental/hubs/makersuite/googlemakersuitehub.d.ts +1 -1
  70. package/dist/experimental/openai_assistant/index.cjs +2 -1
  71. package/dist/experimental/openai_assistant/index.d.ts +2 -1
  72. package/dist/experimental/openai_assistant/index.js +2 -1
  73. package/dist/experimental/openai_files/index.cjs +88 -0
  74. package/dist/experimental/openai_files/index.d.ts +79 -0
  75. package/dist/experimental/openai_files/index.js +84 -0
  76. package/dist/experimental/plan_and_execute/prompt.d.ts +1 -1
  77. package/dist/llms/base.cjs +15 -278
  78. package/dist/llms/base.d.ts +1 -115
  79. package/dist/llms/base.js +1 -275
  80. package/dist/llms/bedrock/web.d.ts +1 -1
  81. package/dist/llms/fireworks.d.ts +1 -1
  82. package/dist/load/import_constants.cjs +1 -0
  83. package/dist/load/import_constants.js +1 -0
  84. package/dist/load/import_map.cjs +4 -2
  85. package/dist/load/import_map.d.ts +2 -0
  86. package/dist/load/import_map.js +2 -0
  87. package/dist/load/index.cjs +7 -148
  88. package/dist/load/index.js +7 -148
  89. package/dist/load/map_keys.cjs +0 -24
  90. package/dist/load/map_keys.d.ts +0 -6
  91. package/dist/load/map_keys.js +1 -17
  92. package/dist/load/serializable.cjs +15 -178
  93. package/dist/load/serializable.d.ts +1 -66
  94. package/dist/load/serializable.js +1 -175
  95. package/dist/memory/base.cjs +17 -92
  96. package/dist/memory/base.d.ts +2 -68
  97. package/dist/memory/base.js +2 -87
  98. package/dist/output_parsers/openai_functions.cjs +2 -2
  99. package/dist/output_parsers/openai_functions.d.ts +1 -1
  100. package/dist/output_parsers/openai_functions.js +1 -1
  101. package/dist/output_parsers/regex.d.ts +1 -1
  102. package/dist/output_parsers/structured.d.ts +1 -1
  103. package/dist/prompts/base.cjs +8 -183
  104. package/dist/prompts/base.d.ts +3 -132
  105. package/dist/prompts/base.js +3 -178
  106. package/dist/prompts/chat.cjs +15 -477
  107. package/dist/prompts/chat.d.ts +1 -219
  108. package/dist/prompts/chat.js +1 -466
  109. package/dist/prompts/few_shot.cjs +15 -353
  110. package/dist/prompts/few_shot.d.ts +1 -192
  111. package/dist/prompts/few_shot.js +1 -350
  112. package/dist/prompts/index.cjs +3 -2
  113. package/dist/prompts/index.d.ts +2 -1
  114. package/dist/prompts/index.js +2 -1
  115. package/dist/prompts/pipeline.cjs +15 -142
  116. package/dist/prompts/pipeline.d.ts +1 -98
  117. package/dist/prompts/pipeline.js +1 -140
  118. package/dist/prompts/prompt.cjs +15 -146
  119. package/dist/prompts/prompt.d.ts +1 -92
  120. package/dist/prompts/prompt.js +1 -144
  121. package/dist/prompts/selectors/LengthBasedExampleSelector.cjs +15 -148
  122. package/dist/prompts/selectors/LengthBasedExampleSelector.d.ts +1 -89
  123. package/dist/prompts/selectors/LengthBasedExampleSelector.js +1 -146
  124. package/dist/prompts/selectors/SemanticSimilarityExampleSelector.cjs +15 -137
  125. package/dist/prompts/selectors/SemanticSimilarityExampleSelector.d.ts +1 -91
  126. package/dist/prompts/selectors/SemanticSimilarityExampleSelector.js +1 -135
  127. package/dist/prompts/selectors/conditional.cjs +15 -74
  128. package/dist/prompts/selectors/conditional.d.ts +1 -63
  129. package/dist/prompts/selectors/conditional.js +1 -69
  130. package/dist/prompts/serde.cjs +15 -0
  131. package/dist/prompts/serde.d.ts +1 -43
  132. package/dist/prompts/serde.js +1 -1
  133. package/dist/prompts/template.cjs +14 -88
  134. package/dist/prompts/template.d.ts +1 -36
  135. package/dist/prompts/template.js +1 -83
  136. package/dist/retrievers/chaindesk.cjs +9 -1
  137. package/dist/retrievers/chaindesk.d.ts +3 -1
  138. package/dist/retrievers/chaindesk.js +9 -1
  139. package/dist/retrievers/self_query/vectara.cjs +138 -0
  140. package/dist/retrievers/self_query/vectara.d.ts +41 -0
  141. package/dist/retrievers/self_query/vectara.js +134 -0
  142. package/dist/{util/@cfworker/json-schema → runnables}/index.cjs +1 -1
  143. package/dist/runnables/index.d.ts +1 -0
  144. package/dist/runnables/index.js +1 -0
  145. package/dist/schema/document.cjs +3 -34
  146. package/dist/schema/document.d.ts +2 -29
  147. package/dist/schema/document.js +2 -32
  148. package/dist/schema/index.cjs +37 -612
  149. package/dist/schema/index.d.ts +11 -311
  150. package/dist/schema/index.js +8 -583
  151. package/dist/schema/output_parser.cjs +15 -309
  152. package/dist/schema/output_parser.d.ts +1 -173
  153. package/dist/schema/output_parser.js +1 -301
  154. package/dist/schema/retriever.cjs +15 -77
  155. package/dist/schema/retriever.d.ts +1 -43
  156. package/dist/schema/retriever.js +1 -75
  157. package/dist/schema/runnable/base.cjs +10 -1072
  158. package/dist/schema/runnable/base.d.ts +1 -356
  159. package/dist/schema/runnable/base.js +1 -1060
  160. package/dist/schema/runnable/branch.cjs +2 -131
  161. package/dist/schema/runnable/branch.d.ts +1 -94
  162. package/dist/schema/runnable/branch.js +1 -130
  163. package/dist/schema/runnable/config.cjs +0 -6
  164. package/dist/schema/runnable/config.d.ts +1 -3
  165. package/dist/schema/runnable/config.js +1 -4
  166. package/dist/schema/runnable/index.cjs +15 -16
  167. package/dist/schema/runnable/index.d.ts +1 -5
  168. package/dist/schema/runnable/index.js +1 -4
  169. package/dist/schema/runnable/passthrough.cjs +3 -113
  170. package/dist/schema/runnable/passthrough.d.ts +1 -72
  171. package/dist/schema/runnable/passthrough.js +1 -111
  172. package/dist/schema/runnable/router.cjs +2 -71
  173. package/dist/schema/runnable/router.d.ts +1 -29
  174. package/dist/schema/runnable/router.js +1 -70
  175. package/dist/schema/storage.cjs +15 -8
  176. package/dist/schema/storage.d.ts +1 -57
  177. package/dist/schema/storage.js +1 -6
  178. package/dist/tools/bingserpapi.d.ts +1 -1
  179. package/dist/tools/searchapi.d.ts +1 -1
  180. package/dist/tools/serpapi.d.ts +1 -1
  181. package/dist/tools/serper.d.ts +1 -1
  182. package/dist/util/async_caller.cjs +14 -128
  183. package/dist/util/async_caller.d.ts +1 -45
  184. package/dist/util/async_caller.js +1 -124
  185. package/dist/vectorstores/vectara.cjs +77 -7
  186. package/dist/vectorstores/vectara.d.ts +9 -3
  187. package/dist/vectorstores/vectara.js +54 -7
  188. package/experimental/openai_files.cjs +1 -0
  189. package/experimental/openai_files.d.ts +1 -0
  190. package/experimental/openai_files.js +1 -0
  191. package/package.json +27 -5
  192. package/retrievers/self_query/vectara.cjs +1 -0
  193. package/retrievers/self_query/vectara.d.ts +1 -0
  194. package/retrievers/self_query/vectara.js +1 -0
  195. package/runnables.cjs +1 -0
  196. package/runnables.d.ts +1 -0
  197. package/runnables.js +1 -0
  198. package/dist/util/@cfworker/json-schema/index.d.ts +0 -1
  199. package/dist/util/@cfworker/json-schema/index.js +0 -1
  200. package/dist/util/@cfworker/json-schema/src/deep-compare-strict.cjs +0 -43
  201. package/dist/util/@cfworker/json-schema/src/deep-compare-strict.d.ts +0 -1
  202. package/dist/util/@cfworker/json-schema/src/deep-compare-strict.js +0 -39
  203. package/dist/util/@cfworker/json-schema/src/dereference.cjs +0 -169
  204. package/dist/util/@cfworker/json-schema/src/dereference.d.ts +0 -12
  205. package/dist/util/@cfworker/json-schema/src/dereference.js +0 -165
  206. package/dist/util/@cfworker/json-schema/src/format.cjs +0 -139
  207. package/dist/util/@cfworker/json-schema/src/format.d.ts +0 -2
  208. package/dist/util/@cfworker/json-schema/src/format.js +0 -136
  209. package/dist/util/@cfworker/json-schema/src/index.cjs +0 -24
  210. package/dist/util/@cfworker/json-schema/src/index.d.ts +0 -8
  211. package/dist/util/@cfworker/json-schema/src/index.js +0 -8
  212. package/dist/util/@cfworker/json-schema/src/pointer.cjs +0 -11
  213. package/dist/util/@cfworker/json-schema/src/pointer.d.ts +0 -2
  214. package/dist/util/@cfworker/json-schema/src/pointer.js +0 -6
  215. package/dist/util/@cfworker/json-schema/src/types.cjs +0 -2
  216. package/dist/util/@cfworker/json-schema/src/types.d.ts +0 -72
  217. package/dist/util/@cfworker/json-schema/src/types.js +0 -1
  218. package/dist/util/@cfworker/json-schema/src/ucs2-length.cjs +0 -28
  219. package/dist/util/@cfworker/json-schema/src/ucs2-length.d.ts +0 -6
  220. package/dist/util/@cfworker/json-schema/src/ucs2-length.js +0 -24
  221. package/dist/util/@cfworker/json-schema/src/validate.cjs +0 -808
  222. package/dist/util/@cfworker/json-schema/src/validate.d.ts +0 -3
  223. package/dist/util/@cfworker/json-schema/src/validate.js +0 -804
  224. package/dist/util/@cfworker/json-schema/src/validator.cjs +0 -44
  225. package/dist/util/@cfworker/json-schema/src/validator.d.ts +0 -10
  226. package/dist/util/@cfworker/json-schema/src/validator.js +0 -40
  227. package/dist/util/fast-json-patch/index.cjs +0 -49
  228. package/dist/util/fast-json-patch/index.d.ts +0 -22
  229. package/dist/util/fast-json-patch/index.js +0 -16
  230. package/dist/util/fast-json-patch/src/core.cjs +0 -469
  231. package/dist/util/fast-json-patch/src/core.d.ts +0 -111
  232. package/dist/util/fast-json-patch/src/core.js +0 -459
  233. package/dist/util/fast-json-patch/src/duplex.cjs +0 -237
  234. package/dist/util/fast-json-patch/src/duplex.d.ts +0 -23
  235. package/dist/util/fast-json-patch/src/duplex.js +0 -230
  236. package/dist/util/fast-json-patch/src/helpers.cjs +0 -194
  237. package/dist/util/fast-json-patch/src/helpers.d.ts +0 -36
  238. package/dist/util/fast-json-patch/src/helpers.js +0 -181
  239. package/dist/util/js-sha1/hash.cjs +0 -358
  240. package/dist/util/js-sha1/hash.d.ts +0 -1
  241. package/dist/util/js-sha1/hash.js +0 -355
@@ -1,32 +1,17 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getTracingV2CallbackHandler = exports.getTracingCallbackHandler = void 0;
4
- const tracer_langchain_js_1 = require("./tracer_langchain.cjs");
5
- const tracer_langchain_v1_js_1 = require("./tracer_langchain_v1.cjs");
6
- /**
7
- * Function that returns an instance of `LangChainTracerV1`. If a session
8
- * is provided, it loads that session into the tracer; otherwise, it loads
9
- * a default session.
10
- * @param session Optional session to load into the tracer.
11
- * @returns An instance of `LangChainTracerV1`.
12
- */
13
- async function getTracingCallbackHandler(session) {
14
- const tracer = new tracer_langchain_v1_js_1.LangChainTracerV1();
15
- if (session) {
16
- await tracer.loadSession(session);
17
- }
18
- else {
19
- await tracer.loadDefaultSession();
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
20
7
  }
21
- return tracer;
22
- }
23
- exports.getTracingCallbackHandler = getTracingCallbackHandler;
24
- /**
25
- * Function that returns an instance of `LangChainTracer`. It does not
26
- * load any session data.
27
- * @returns An instance of `LangChainTracer`.
28
- */
29
- async function getTracingV2CallbackHandler() {
30
- return new tracer_langchain_js_1.LangChainTracer();
31
- }
32
- exports.getTracingV2CallbackHandler = getTracingV2CallbackHandler;
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("langchain-core/callbacks/tracers/initialize"), exports);
@@ -1,16 +1 @@
1
- import { LangChainTracer } from "./tracer_langchain.js";
2
- import { LangChainTracerV1 } from "./tracer_langchain_v1.js";
3
- /**
4
- * Function that returns an instance of `LangChainTracerV1`. If a session
5
- * is provided, it loads that session into the tracer; otherwise, it loads
6
- * a default session.
7
- * @param session Optional session to load into the tracer.
8
- * @returns An instance of `LangChainTracerV1`.
9
- */
10
- export declare function getTracingCallbackHandler(session?: string): Promise<LangChainTracerV1>;
11
- /**
12
- * Function that returns an instance of `LangChainTracer`. It does not
13
- * load any session data.
14
- * @returns An instance of `LangChainTracer`.
15
- */
16
- export declare function getTracingV2CallbackHandler(): Promise<LangChainTracer>;
1
+ export * from "langchain-core/callbacks/tracers/initialize";
@@ -1,27 +1 @@
1
- import { LangChainTracer } from "./tracer_langchain.js";
2
- import { LangChainTracerV1 } from "./tracer_langchain_v1.js";
3
- /**
4
- * Function that returns an instance of `LangChainTracerV1`. If a session
5
- * is provided, it loads that session into the tracer; otherwise, it loads
6
- * a default session.
7
- * @param session Optional session to load into the tracer.
8
- * @returns An instance of `LangChainTracerV1`.
9
- */
10
- export async function getTracingCallbackHandler(session) {
11
- const tracer = new LangChainTracerV1();
12
- if (session) {
13
- await tracer.loadSession(session);
14
- }
15
- else {
16
- await tracer.loadDefaultSession();
17
- }
18
- return tracer;
19
- }
20
- /**
21
- * Function that returns an instance of `LangChainTracer`. It does not
22
- * load any session data.
23
- * @returns An instance of `LangChainTracer`.
24
- */
25
- export async function getTracingV2CallbackHandler() {
26
- return new LangChainTracer();
27
- }
1
+ export * from "langchain-core/callbacks/tracers/initialize";
@@ -1,295 +1,17 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
2
16
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.LogStreamCallbackHandler = exports.RunLog = exports.RunLogPatch = void 0;
4
- const index_js_1 = require("../../util/fast-json-patch/index.cjs");
5
- const tracer_js_1 = require("./tracer.cjs");
6
- const stream_js_1 = require("../../util/stream.cjs");
7
- /**
8
- * List of jsonpatch JSONPatchOperations, which describe how to create the run state
9
- * from an empty dict. This is the minimal representation of the log, designed to
10
- * be serialized as JSON and sent over the wire to reconstruct the log on the other
11
- * side. Reconstruction of the state can be done with any jsonpatch-compliant library,
12
- * see https://jsonpatch.com for more information.
13
- */
14
- class RunLogPatch {
15
- constructor(fields) {
16
- Object.defineProperty(this, "ops", {
17
- enumerable: true,
18
- configurable: true,
19
- writable: true,
20
- value: void 0
21
- });
22
- this.ops = fields.ops;
23
- }
24
- concat(other) {
25
- const ops = this.ops.concat(other.ops);
26
- const states = (0, index_js_1.applyPatch)({}, ops);
27
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
28
- return new RunLog({
29
- ops,
30
- state: states[states.length - 1].newDocument,
31
- });
32
- }
33
- }
34
- exports.RunLogPatch = RunLogPatch;
35
- class RunLog extends RunLogPatch {
36
- constructor(fields) {
37
- super(fields);
38
- Object.defineProperty(this, "state", {
39
- enumerable: true,
40
- configurable: true,
41
- writable: true,
42
- value: void 0
43
- });
44
- this.state = fields.state;
45
- }
46
- concat(other) {
47
- const ops = this.ops.concat(other.ops);
48
- const states = (0, index_js_1.applyPatch)(this.state, other.ops);
49
- return new RunLog({ ops, state: states[states.length - 1].newDocument });
50
- }
51
- }
52
- exports.RunLog = RunLog;
53
- /**
54
- * Class that extends the `BaseTracer` class from the
55
- * `langchain.callbacks.tracers.base` module. It represents a callback
56
- * handler that logs the execution of runs and emits `RunLog` instances to a
57
- * `RunLogStream`.
58
- */
59
- class LogStreamCallbackHandler extends tracer_js_1.BaseTracer {
60
- constructor(fields) {
61
- super(fields);
62
- Object.defineProperty(this, "autoClose", {
63
- enumerable: true,
64
- configurable: true,
65
- writable: true,
66
- value: true
67
- });
68
- Object.defineProperty(this, "includeNames", {
69
- enumerable: true,
70
- configurable: true,
71
- writable: true,
72
- value: void 0
73
- });
74
- Object.defineProperty(this, "includeTypes", {
75
- enumerable: true,
76
- configurable: true,
77
- writable: true,
78
- value: void 0
79
- });
80
- Object.defineProperty(this, "includeTags", {
81
- enumerable: true,
82
- configurable: true,
83
- writable: true,
84
- value: void 0
85
- });
86
- Object.defineProperty(this, "excludeNames", {
87
- enumerable: true,
88
- configurable: true,
89
- writable: true,
90
- value: void 0
91
- });
92
- Object.defineProperty(this, "excludeTypes", {
93
- enumerable: true,
94
- configurable: true,
95
- writable: true,
96
- value: void 0
97
- });
98
- Object.defineProperty(this, "excludeTags", {
99
- enumerable: true,
100
- configurable: true,
101
- writable: true,
102
- value: void 0
103
- });
104
- Object.defineProperty(this, "keyMapByRunId", {
105
- enumerable: true,
106
- configurable: true,
107
- writable: true,
108
- value: {}
109
- });
110
- Object.defineProperty(this, "counterMapByRunName", {
111
- enumerable: true,
112
- configurable: true,
113
- writable: true,
114
- value: {}
115
- });
116
- Object.defineProperty(this, "transformStream", {
117
- enumerable: true,
118
- configurable: true,
119
- writable: true,
120
- value: void 0
121
- });
122
- Object.defineProperty(this, "writer", {
123
- enumerable: true,
124
- configurable: true,
125
- writable: true,
126
- value: void 0
127
- });
128
- Object.defineProperty(this, "receiveStream", {
129
- enumerable: true,
130
- configurable: true,
131
- writable: true,
132
- value: void 0
133
- });
134
- Object.defineProperty(this, "name", {
135
- enumerable: true,
136
- configurable: true,
137
- writable: true,
138
- value: "log_stream_tracer"
139
- });
140
- this.autoClose = fields?.autoClose ?? true;
141
- this.includeNames = fields?.includeNames;
142
- this.includeTypes = fields?.includeTypes;
143
- this.includeTags = fields?.includeTags;
144
- this.excludeNames = fields?.excludeNames;
145
- this.excludeTypes = fields?.excludeTypes;
146
- this.excludeTags = fields?.excludeTags;
147
- this.transformStream = new TransformStream();
148
- this.writer = this.transformStream.writable.getWriter();
149
- this.receiveStream = stream_js_1.IterableReadableStream.fromReadableStream(this.transformStream.readable);
150
- }
151
- [Symbol.asyncIterator]() {
152
- return this.receiveStream;
153
- }
154
- async persistRun(_run) {
155
- // This is a legacy method only called once for an entire run tree
156
- // and is therefore not useful here
157
- }
158
- _includeRun(run) {
159
- if (run.parent_run_id === undefined) {
160
- return false;
161
- }
162
- const runTags = run.tags ?? [];
163
- let include = this.includeNames === undefined &&
164
- this.includeTags === undefined &&
165
- this.includeTypes === undefined;
166
- if (this.includeNames !== undefined) {
167
- include = include || this.includeNames.includes(run.name);
168
- }
169
- if (this.includeTypes !== undefined) {
170
- include = include || this.includeTypes.includes(run.run_type);
171
- }
172
- if (this.includeTags !== undefined) {
173
- include =
174
- include ||
175
- runTags.find((tag) => this.includeTags?.includes(tag)) !== undefined;
176
- }
177
- if (this.excludeNames !== undefined) {
178
- include = include && !this.excludeNames.includes(run.name);
179
- }
180
- if (this.excludeTypes !== undefined) {
181
- include = include && !this.excludeTypes.includes(run.run_type);
182
- }
183
- if (this.excludeTags !== undefined) {
184
- include =
185
- include && runTags.every((tag) => !this.excludeTags?.includes(tag));
186
- }
187
- return include;
188
- }
189
- async onRunCreate(run) {
190
- if (run.parent_run_id === undefined) {
191
- await this.writer.write(new RunLogPatch({
192
- ops: [
193
- {
194
- op: "replace",
195
- path: "",
196
- value: {
197
- id: run.id,
198
- streamed_output: [],
199
- final_output: undefined,
200
- logs: {},
201
- },
202
- },
203
- ],
204
- }));
205
- }
206
- if (!this._includeRun(run)) {
207
- return;
208
- }
209
- if (this.counterMapByRunName[run.name] === undefined) {
210
- this.counterMapByRunName[run.name] = 0;
211
- }
212
- this.counterMapByRunName[run.name] += 1;
213
- const count = this.counterMapByRunName[run.name];
214
- this.keyMapByRunId[run.id] =
215
- count === 1 ? run.name : `${run.name}:${count}`;
216
- const logEntry = {
217
- id: run.id,
218
- name: run.name,
219
- type: run.run_type,
220
- tags: run.tags ?? [],
221
- metadata: run.extra?.metadata ?? {},
222
- start_time: new Date(run.start_time).toISOString(),
223
- streamed_output_str: [],
224
- final_output: undefined,
225
- end_time: undefined,
226
- };
227
- await this.writer.write(new RunLogPatch({
228
- ops: [
229
- {
230
- op: "add",
231
- path: `/logs/${this.keyMapByRunId[run.id]}`,
232
- value: logEntry,
233
- },
234
- ],
235
- }));
236
- }
237
- async onRunUpdate(run) {
238
- try {
239
- const runName = this.keyMapByRunId[run.id];
240
- if (runName === undefined) {
241
- return;
242
- }
243
- const ops = [
244
- {
245
- op: "add",
246
- path: `/logs/${runName}/final_output`,
247
- value: run.outputs,
248
- },
249
- ];
250
- if (run.end_time !== undefined) {
251
- ops.push({
252
- op: "add",
253
- path: `/logs/${runName}/end_time`,
254
- value: new Date(run.end_time).toISOString(),
255
- });
256
- }
257
- const patch = new RunLogPatch({ ops });
258
- await this.writer.write(patch);
259
- }
260
- finally {
261
- if (run.parent_run_id === undefined) {
262
- const patch = new RunLogPatch({
263
- ops: [
264
- {
265
- op: "replace",
266
- path: "/final_output",
267
- value: run.outputs,
268
- },
269
- ],
270
- });
271
- await this.writer.write(patch);
272
- if (this.autoClose) {
273
- await this.writer.close();
274
- }
275
- }
276
- }
277
- }
278
- async onLLMNewToken(run, token) {
279
- const runName = this.keyMapByRunId[run.id];
280
- if (runName === undefined) {
281
- return;
282
- }
283
- const patch = new RunLogPatch({
284
- ops: [
285
- {
286
- op: "add",
287
- path: `/logs/${runName}/streamed_output_str/-`,
288
- value: token,
289
- },
290
- ],
291
- });
292
- await this.writer.write(patch);
293
- }
294
- }
295
- exports.LogStreamCallbackHandler = LogStreamCallbackHandler;
17
+ __exportStar(require("langchain-core/callbacks/tracers/log_stream"), exports);
@@ -1,100 +1 @@
1
- import { type Operation as JSONPatchOperation } from "../../util/fast-json-patch/index.js";
2
- import { BaseTracer, type Run } from "./tracer.js";
3
- import { BaseCallbackHandlerInput } from "../base.js";
4
- import { IterableReadableStream } from "../../util/stream.js";
5
- /**
6
- * Interface that represents the structure of a log entry in the
7
- * `LogStreamCallbackHandler`.
8
- */
9
- export type LogEntry = {
10
- /** ID of the sub-run. */
11
- id: string;
12
- /** Name of the object being run. */
13
- name: string;
14
- /** Type of the object being run, eg. prompt, chain, llm, etc. */
15
- type: string;
16
- /** List of tags for the run. */
17
- tags: string[];
18
- /** Key-value pairs of metadata for the run. */
19
- metadata: Record<string, any>;
20
- /** ISO-8601 timestamp of when the run started. */
21
- start_time: string;
22
- /** List of LLM tokens streamed by this run, if applicable. */
23
- streamed_output_str: string[];
24
- /** Final output of this run. Only available after the run has finished successfully. */
25
- final_output?: any;
26
- /** ISO-8601 timestamp of when the run ended. Only available after the run has finished. */
27
- end_time?: string;
28
- };
29
- export type RunState = {
30
- /** ID of the sub-run. */
31
- id: string;
32
- /** List of output chunks streamed by Runnable.stream() */
33
- streamed_output: any[];
34
- /** Final output of the run, usually the result of aggregating streamed_output. Only available after the run has finished successfully. */
35
- final_output?: any;
36
- /**
37
- * List of sub-runs contained in this run, if any, in the order they were started.
38
- * If filters were supplied, this list will contain only the runs that matched the filters.
39
- */
40
- logs: Record<string, LogEntry>;
41
- };
42
- /**
43
- * List of jsonpatch JSONPatchOperations, which describe how to create the run state
44
- * from an empty dict. This is the minimal representation of the log, designed to
45
- * be serialized as JSON and sent over the wire to reconstruct the log on the other
46
- * side. Reconstruction of the state can be done with any jsonpatch-compliant library,
47
- * see https://jsonpatch.com for more information.
48
- */
49
- export declare class RunLogPatch {
50
- ops: JSONPatchOperation[];
51
- constructor(fields: {
52
- ops: JSONPatchOperation[];
53
- });
54
- concat(other: RunLogPatch): RunLog;
55
- }
56
- export declare class RunLog extends RunLogPatch {
57
- state: RunState;
58
- constructor(fields: {
59
- ops: JSONPatchOperation[];
60
- state: RunState;
61
- });
62
- concat(other: RunLogPatch): RunLog;
63
- }
64
- export interface LogStreamCallbackHandlerInput extends BaseCallbackHandlerInput {
65
- autoClose?: boolean;
66
- includeNames?: string[];
67
- includeTypes?: string[];
68
- includeTags?: string[];
69
- excludeNames?: string[];
70
- excludeTypes?: string[];
71
- excludeTags?: string[];
72
- }
73
- /**
74
- * Class that extends the `BaseTracer` class from the
75
- * `langchain.callbacks.tracers.base` module. It represents a callback
76
- * handler that logs the execution of runs and emits `RunLog` instances to a
77
- * `RunLogStream`.
78
- */
79
- export declare class LogStreamCallbackHandler extends BaseTracer {
80
- protected autoClose: boolean;
81
- protected includeNames?: string[];
82
- protected includeTypes?: string[];
83
- protected includeTags?: string[];
84
- protected excludeNames?: string[];
85
- protected excludeTypes?: string[];
86
- protected excludeTags?: string[];
87
- private keyMapByRunId;
88
- private counterMapByRunName;
89
- protected transformStream: TransformStream;
90
- writer: WritableStreamDefaultWriter;
91
- receiveStream: IterableReadableStream<RunLogPatch>;
92
- name: string;
93
- constructor(fields?: LogStreamCallbackHandlerInput);
94
- [Symbol.asyncIterator](): IterableReadableStream<RunLogPatch>;
95
- protected persistRun(_run: Run): Promise<void>;
96
- _includeRun(run: Run): boolean;
97
- onRunCreate(run: Run): Promise<void>;
98
- onRunUpdate(run: Run): Promise<void>;
99
- onLLMNewToken(run: Run, token: string): Promise<void>;
100
- }
1
+ export * from "langchain-core/callbacks/tracers/log_stream";