langchain 0.0.195 → 0.0.197-rc.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 (236) hide show
  1. package/LICENSE +21 -0
  2. package/dist/agents/openai/index.cjs +6 -2
  3. package/dist/agents/openai/index.js +6 -2
  4. package/dist/agents/toolkits/conversational_retrieval/token_buffer_memory.d.ts +1 -1
  5. package/dist/base_language/count_tokens.cjs +5 -70
  6. package/dist/base_language/count_tokens.d.ts +1 -10
  7. package/dist/base_language/count_tokens.js +1 -65
  8. package/dist/base_language/index.cjs +6 -196
  9. package/dist/base_language/index.d.ts +1 -111
  10. package/dist/base_language/index.js +1 -191
  11. package/dist/cache/base.cjs +15 -37
  12. package/dist/cache/base.d.ts +1 -20
  13. package/dist/cache/base.js +1 -33
  14. package/dist/cache/index.cjs +2 -46
  15. package/dist/cache/index.d.ts +1 -29
  16. package/dist/cache/index.js +1 -45
  17. package/dist/callbacks/base.cjs +3 -139
  18. package/dist/callbacks/base.d.ts +1 -266
  19. package/dist/callbacks/base.js +1 -126
  20. package/dist/callbacks/handlers/console.cjs +14 -221
  21. package/dist/callbacks/handlers/console.d.ts +1 -117
  22. package/dist/callbacks/handlers/console.js +1 -217
  23. package/dist/callbacks/handlers/initialize.cjs +15 -30
  24. package/dist/callbacks/handlers/initialize.d.ts +1 -16
  25. package/dist/callbacks/handlers/initialize.js +1 -27
  26. package/dist/callbacks/handlers/log_stream.cjs +15 -293
  27. package/dist/callbacks/handlers/log_stream.d.ts +1 -100
  28. package/dist/callbacks/handlers/log_stream.js +1 -289
  29. package/dist/callbacks/handlers/run_collector.cjs +15 -48
  30. package/dist/callbacks/handlers/run_collector.d.ts +1 -26
  31. package/dist/callbacks/handlers/run_collector.js +1 -46
  32. package/dist/callbacks/handlers/tracer.cjs +15 -375
  33. package/dist/callbacks/handlers/tracer.d.ts +1 -70
  34. package/dist/callbacks/handlers/tracer.js +1 -373
  35. package/dist/callbacks/handlers/tracer_langchain.cjs +15 -104
  36. package/dist/callbacks/handlers/tracer_langchain.d.ts +1 -41
  37. package/dist/callbacks/handlers/tracer_langchain.js +1 -102
  38. package/dist/callbacks/handlers/tracer_langchain_v1.cjs +15 -197
  39. package/dist/callbacks/handlers/tracer_langchain_v1.d.ts +1 -57
  40. package/dist/callbacks/handlers/tracer_langchain_v1.js +1 -195
  41. package/dist/callbacks/manager.cjs +15 -676
  42. package/dist/callbacks/manager.d.ts +1 -180
  43. package/dist/callbacks/manager.js +1 -666
  44. package/dist/callbacks/promises.cjs +14 -42
  45. package/dist/callbacks/promises.d.ts +1 -11
  46. package/dist/callbacks/promises.js +1 -37
  47. package/dist/chains/graph_qa/prompts.d.ts +1 -1
  48. package/dist/chains/openai_functions/structured_output.cjs +2 -2
  49. package/dist/chains/openai_functions/structured_output.d.ts +1 -1
  50. package/dist/chains/openai_functions/structured_output.js +1 -1
  51. package/dist/chat_models/anthropic.cjs +15 -348
  52. package/dist/chat_models/anthropic.d.ts +1 -156
  53. package/dist/chat_models/anthropic.js +1 -346
  54. package/dist/chat_models/baiduwenxin.d.ts +1 -1
  55. package/dist/chat_models/base.cjs +15 -296
  56. package/dist/chat_models/base.d.ts +1 -122
  57. package/dist/chat_models/base.js +1 -292
  58. package/dist/chat_models/bedrock/web.cjs +21 -1
  59. package/dist/chat_models/bedrock/web.d.ts +2 -2
  60. package/dist/chat_models/bedrock/web.js +21 -1
  61. package/dist/chat_models/fireworks.d.ts +1 -1
  62. package/dist/document.cjs +2 -24
  63. package/dist/document.d.ts +1 -12
  64. package/dist/document.js +1 -23
  65. package/dist/document_loaders/web/azure_blob_storage_file.d.ts +1 -1
  66. package/dist/document_loaders/web/github.cjs +105 -0
  67. package/dist/document_loaders/web/github.d.ts +26 -0
  68. package/dist/document_loaders/web/github.js +105 -0
  69. package/dist/document_loaders/web/s3.d.ts +1 -1
  70. package/dist/embeddings/base.cjs +15 -22
  71. package/dist/embeddings/base.d.ts +1 -33
  72. package/dist/embeddings/base.js +1 -20
  73. package/dist/embeddings/cache_backed.cjs +2 -2
  74. package/dist/embeddings/cache_backed.js +1 -1
  75. package/dist/evaluation/agents/trajectory.d.ts +1 -1
  76. package/dist/evaluation/criteria/prompt.d.ts +2 -2
  77. package/dist/evaluation/qa/prompt.d.ts +2 -2
  78. package/dist/experimental/hubs/makersuite/googlemakersuitehub.d.ts +1 -1
  79. package/dist/experimental/plan_and_execute/prompt.d.ts +1 -1
  80. package/dist/llms/base.cjs +15 -278
  81. package/dist/llms/base.d.ts +1 -115
  82. package/dist/llms/base.js +1 -275
  83. package/dist/llms/bedrock/web.cjs +21 -1
  84. package/dist/llms/bedrock/web.d.ts +2 -2
  85. package/dist/llms/bedrock/web.js +21 -1
  86. package/dist/llms/fireworks.d.ts +1 -1
  87. package/dist/load/import_map.cjs +2 -1
  88. package/dist/load/import_map.d.ts +1 -0
  89. package/dist/load/import_map.js +1 -0
  90. package/dist/load/index.cjs +7 -148
  91. package/dist/load/index.js +7 -148
  92. package/dist/load/map_keys.cjs +0 -24
  93. package/dist/load/map_keys.d.ts +0 -6
  94. package/dist/load/map_keys.js +1 -17
  95. package/dist/load/serializable.cjs +15 -178
  96. package/dist/load/serializable.d.ts +1 -66
  97. package/dist/load/serializable.js +1 -175
  98. package/dist/memory/base.cjs +17 -92
  99. package/dist/memory/base.d.ts +2 -68
  100. package/dist/memory/base.js +2 -87
  101. package/dist/output_parsers/list.cjs +4 -122
  102. package/dist/output_parsers/list.d.ts +1 -57
  103. package/dist/output_parsers/list.js +1 -119
  104. package/dist/output_parsers/openai_functions.cjs +2 -2
  105. package/dist/output_parsers/openai_functions.d.ts +1 -1
  106. package/dist/output_parsers/openai_functions.js +1 -1
  107. package/dist/output_parsers/regex.d.ts +1 -1
  108. package/dist/output_parsers/structured.d.ts +1 -1
  109. package/dist/prompts/base.cjs +8 -183
  110. package/dist/prompts/base.d.ts +3 -132
  111. package/dist/prompts/base.js +3 -178
  112. package/dist/prompts/chat.cjs +13 -477
  113. package/dist/prompts/chat.d.ts +2 -219
  114. package/dist/prompts/chat.js +2 -466
  115. package/dist/prompts/few_shot.cjs +3 -352
  116. package/dist/prompts/few_shot.d.ts +1 -192
  117. package/dist/prompts/few_shot.js +1 -350
  118. package/dist/prompts/index.cjs +3 -2
  119. package/dist/prompts/index.d.ts +2 -1
  120. package/dist/prompts/index.js +2 -1
  121. package/dist/prompts/pipeline.cjs +2 -141
  122. package/dist/prompts/pipeline.d.ts +1 -98
  123. package/dist/prompts/pipeline.js +1 -140
  124. package/dist/prompts/prompt.cjs +2 -145
  125. package/dist/prompts/prompt.d.ts +1 -92
  126. package/dist/prompts/prompt.js +1 -144
  127. package/dist/prompts/selectors/LengthBasedExampleSelector.cjs +2 -147
  128. package/dist/prompts/selectors/LengthBasedExampleSelector.d.ts +1 -89
  129. package/dist/prompts/selectors/LengthBasedExampleSelector.js +1 -146
  130. package/dist/prompts/selectors/SemanticSimilarityExampleSelector.cjs +15 -137
  131. package/dist/prompts/selectors/SemanticSimilarityExampleSelector.d.ts +1 -91
  132. package/dist/prompts/selectors/SemanticSimilarityExampleSelector.js +1 -135
  133. package/dist/prompts/selectors/conditional.cjs +5 -73
  134. package/dist/prompts/selectors/conditional.d.ts +1 -63
  135. package/dist/prompts/selectors/conditional.js +1 -69
  136. package/dist/prompts/serde.d.ts +1 -43
  137. package/dist/prompts/template.cjs +8 -88
  138. package/dist/prompts/template.d.ts +1 -36
  139. package/dist/prompts/template.js +1 -83
  140. package/dist/{util/@cfworker/json-schema → runnables}/index.cjs +1 -1
  141. package/dist/runnables/index.d.ts +1 -0
  142. package/dist/runnables/index.js +1 -0
  143. package/dist/schema/document.cjs +3 -34
  144. package/dist/schema/document.d.ts +2 -29
  145. package/dist/schema/document.js +2 -32
  146. package/dist/schema/index.cjs +37 -612
  147. package/dist/schema/index.d.ts +11 -311
  148. package/dist/schema/index.js +8 -583
  149. package/dist/schema/output_parser.cjs +15 -309
  150. package/dist/schema/output_parser.d.ts +1 -173
  151. package/dist/schema/output_parser.js +1 -301
  152. package/dist/schema/retriever.cjs +15 -77
  153. package/dist/schema/retriever.d.ts +1 -43
  154. package/dist/schema/retriever.js +1 -75
  155. package/dist/schema/runnable/base.cjs +10 -1072
  156. package/dist/schema/runnable/base.d.ts +1 -356
  157. package/dist/schema/runnable/base.js +1 -1060
  158. package/dist/schema/runnable/branch.cjs +2 -131
  159. package/dist/schema/runnable/branch.d.ts +1 -94
  160. package/dist/schema/runnable/branch.js +1 -130
  161. package/dist/schema/runnable/config.cjs +0 -6
  162. package/dist/schema/runnable/config.d.ts +1 -3
  163. package/dist/schema/runnable/config.js +1 -4
  164. package/dist/schema/runnable/index.cjs +15 -16
  165. package/dist/schema/runnable/index.d.ts +1 -5
  166. package/dist/schema/runnable/index.js +1 -4
  167. package/dist/schema/runnable/passthrough.cjs +3 -113
  168. package/dist/schema/runnable/passthrough.d.ts +1 -72
  169. package/dist/schema/runnable/passthrough.js +1 -111
  170. package/dist/schema/runnable/router.cjs +2 -71
  171. package/dist/schema/runnable/router.d.ts +1 -29
  172. package/dist/schema/runnable/router.js +1 -70
  173. package/dist/schema/storage.cjs +15 -8
  174. package/dist/schema/storage.d.ts +1 -57
  175. package/dist/schema/storage.js +1 -6
  176. package/dist/tools/bingserpapi.d.ts +1 -1
  177. package/dist/tools/searchapi.d.ts +1 -1
  178. package/dist/tools/serpapi.d.ts +1 -1
  179. package/dist/tools/serper.d.ts +1 -1
  180. package/dist/util/async_caller.cjs +14 -128
  181. package/dist/util/async_caller.d.ts +1 -45
  182. package/dist/util/async_caller.js +1 -124
  183. package/dist/vectorstores/momento_vector_index.cjs +39 -0
  184. package/dist/vectorstores/momento_vector_index.d.ts +17 -1
  185. package/dist/vectorstores/momento_vector_index.js +40 -1
  186. package/dist/vectorstores/mongodb_atlas.cjs +22 -2
  187. package/dist/vectorstores/mongodb_atlas.d.ts +13 -0
  188. package/dist/vectorstores/mongodb_atlas.js +22 -2
  189. package/package.json +18 -11
  190. package/runnables.cjs +1 -0
  191. package/runnables.d.ts +1 -0
  192. package/runnables.js +1 -0
  193. package/dist/util/@cfworker/json-schema/index.d.ts +0 -1
  194. package/dist/util/@cfworker/json-schema/index.js +0 -1
  195. package/dist/util/@cfworker/json-schema/src/deep-compare-strict.cjs +0 -43
  196. package/dist/util/@cfworker/json-schema/src/deep-compare-strict.d.ts +0 -1
  197. package/dist/util/@cfworker/json-schema/src/deep-compare-strict.js +0 -39
  198. package/dist/util/@cfworker/json-schema/src/dereference.cjs +0 -169
  199. package/dist/util/@cfworker/json-schema/src/dereference.d.ts +0 -12
  200. package/dist/util/@cfworker/json-schema/src/dereference.js +0 -165
  201. package/dist/util/@cfworker/json-schema/src/format.cjs +0 -139
  202. package/dist/util/@cfworker/json-schema/src/format.d.ts +0 -2
  203. package/dist/util/@cfworker/json-schema/src/format.js +0 -136
  204. package/dist/util/@cfworker/json-schema/src/index.cjs +0 -24
  205. package/dist/util/@cfworker/json-schema/src/index.d.ts +0 -8
  206. package/dist/util/@cfworker/json-schema/src/index.js +0 -8
  207. package/dist/util/@cfworker/json-schema/src/pointer.cjs +0 -11
  208. package/dist/util/@cfworker/json-schema/src/pointer.d.ts +0 -2
  209. package/dist/util/@cfworker/json-schema/src/pointer.js +0 -6
  210. package/dist/util/@cfworker/json-schema/src/types.cjs +0 -2
  211. package/dist/util/@cfworker/json-schema/src/types.d.ts +0 -72
  212. package/dist/util/@cfworker/json-schema/src/types.js +0 -1
  213. package/dist/util/@cfworker/json-schema/src/ucs2-length.cjs +0 -28
  214. package/dist/util/@cfworker/json-schema/src/ucs2-length.d.ts +0 -6
  215. package/dist/util/@cfworker/json-schema/src/ucs2-length.js +0 -24
  216. package/dist/util/@cfworker/json-schema/src/validate.cjs +0 -808
  217. package/dist/util/@cfworker/json-schema/src/validate.d.ts +0 -3
  218. package/dist/util/@cfworker/json-schema/src/validate.js +0 -804
  219. package/dist/util/@cfworker/json-schema/src/validator.cjs +0 -44
  220. package/dist/util/@cfworker/json-schema/src/validator.d.ts +0 -10
  221. package/dist/util/@cfworker/json-schema/src/validator.js +0 -40
  222. package/dist/util/fast-json-patch/index.cjs +0 -49
  223. package/dist/util/fast-json-patch/index.d.ts +0 -22
  224. package/dist/util/fast-json-patch/index.js +0 -16
  225. package/dist/util/fast-json-patch/src/core.cjs +0 -469
  226. package/dist/util/fast-json-patch/src/core.d.ts +0 -111
  227. package/dist/util/fast-json-patch/src/core.js +0 -459
  228. package/dist/util/fast-json-patch/src/duplex.cjs +0 -237
  229. package/dist/util/fast-json-patch/src/duplex.d.ts +0 -23
  230. package/dist/util/fast-json-patch/src/duplex.js +0 -230
  231. package/dist/util/fast-json-patch/src/helpers.cjs +0 -194
  232. package/dist/util/fast-json-patch/src/helpers.d.ts +0 -36
  233. package/dist/util/fast-json-patch/src/helpers.js +0 -181
  234. package/dist/util/js-sha1/hash.cjs +0 -358
  235. package/dist/util/js-sha1/hash.d.ts +0 -1
  236. package/dist/util/js-sha1/hash.js +0 -355
@@ -1,301 +1,8 @@
1
+ import { BaseMessage, HumanMessage, AIMessage, SystemMessage, } from "langchain-core/messages";
1
2
  import { Serializable } from "../load/serializable.js";
2
- export const RUN_KEY = "__run";
3
- /**
4
- * Chunk of a single generation. Used for streaming.
5
- */
6
- export class GenerationChunk {
7
- constructor(fields) {
8
- Object.defineProperty(this, "text", {
9
- enumerable: true,
10
- configurable: true,
11
- writable: true,
12
- value: void 0
13
- });
14
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
15
- Object.defineProperty(this, "generationInfo", {
16
- enumerable: true,
17
- configurable: true,
18
- writable: true,
19
- value: void 0
20
- });
21
- this.text = fields.text;
22
- this.generationInfo = fields.generationInfo;
23
- }
24
- concat(chunk) {
25
- return new GenerationChunk({
26
- text: this.text + chunk.text,
27
- generationInfo: {
28
- ...this.generationInfo,
29
- ...chunk.generationInfo,
30
- },
31
- });
32
- }
33
- }
34
- function mergeContent(firstContent, secondContent) {
35
- // If first content is a string
36
- if (typeof firstContent === "string") {
37
- if (typeof secondContent === "string") {
38
- return firstContent + secondContent;
39
- }
40
- else {
41
- return [{ type: "text", text: firstContent }, ...secondContent];
42
- }
43
- // If both are arrays
44
- }
45
- else if (Array.isArray(secondContent)) {
46
- return [...firstContent, ...secondContent];
47
- // If the first content is a list and second is a string
48
- }
49
- else {
50
- // Otherwise, add the second content as a new element of the list
51
- return [...firstContent, { type: "text", text: secondContent }];
52
- }
53
- }
54
- /**
55
- * Base class for all types of messages in a conversation. It includes
56
- * properties like `content`, `name`, and `additional_kwargs`. It also
57
- * includes methods like `toDict()` and `_getType()`.
58
- */
59
- export class BaseMessage extends Serializable {
60
- /**
61
- * @deprecated
62
- * Use {@link BaseMessage.content} instead.
63
- */
64
- get text() {
65
- return typeof this.content === "string" ? this.content : "";
66
- }
67
- constructor(fields,
68
- /** @deprecated */
69
- kwargs) {
70
- if (typeof fields === "string") {
71
- // eslint-disable-next-line no-param-reassign
72
- fields = { content: fields, additional_kwargs: kwargs };
73
- }
74
- // Make sure the default value for additional_kwargs is passed into super() for serialization
75
- if (!fields.additional_kwargs) {
76
- // eslint-disable-next-line no-param-reassign
77
- fields.additional_kwargs = {};
78
- }
79
- super(fields);
80
- Object.defineProperty(this, "lc_namespace", {
81
- enumerable: true,
82
- configurable: true,
83
- writable: true,
84
- value: ["langchain", "schema"]
85
- });
86
- Object.defineProperty(this, "lc_serializable", {
87
- enumerable: true,
88
- configurable: true,
89
- writable: true,
90
- value: true
91
- });
92
- /** The content of the message. */
93
- Object.defineProperty(this, "content", {
94
- enumerable: true,
95
- configurable: true,
96
- writable: true,
97
- value: void 0
98
- });
99
- /** The name of the message sender in a multi-user chat. */
100
- Object.defineProperty(this, "name", {
101
- enumerable: true,
102
- configurable: true,
103
- writable: true,
104
- value: void 0
105
- });
106
- /** Additional keyword arguments */
107
- Object.defineProperty(this, "additional_kwargs", {
108
- enumerable: true,
109
- configurable: true,
110
- writable: true,
111
- value: void 0
112
- });
113
- this.name = fields.name;
114
- this.content = fields.content;
115
- this.additional_kwargs = fields.additional_kwargs;
116
- }
117
- toDict() {
118
- return {
119
- type: this._getType(),
120
- data: this.toJSON()
121
- .kwargs,
122
- };
123
- }
124
- toChunk() {
125
- const type = this._getType();
126
- if (type === "human") {
127
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
128
- return new HumanMessageChunk({ ...this });
129
- }
130
- else if (type === "ai") {
131
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
132
- return new AIMessageChunk({ ...this });
133
- }
134
- else if (type === "system") {
135
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
136
- return new SystemMessageChunk({ ...this });
137
- }
138
- else if (type === "function") {
139
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
140
- return new FunctionMessageChunk({ ...this });
141
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
142
- }
143
- else if (ChatMessage.isInstance(this)) {
144
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
145
- return new ChatMessageChunk({ ...this });
146
- }
147
- else {
148
- throw new Error("Unknown message type.");
149
- }
150
- }
151
- }
152
- function isOpenAIToolCallArray(value) {
153
- return (Array.isArray(value) &&
154
- value.every((v) => typeof v.index === "number"));
155
- }
156
- /**
157
- * Represents a chunk of a message, which can be concatenated with other
158
- * message chunks. It includes a method `_merge_kwargs_dict()` for merging
159
- * additional keyword arguments from another `BaseMessageChunk` into this
160
- * one. It also overrides the `__add__()` method to support concatenation
161
- * of `BaseMessageChunk` instances.
162
- */
163
- export class BaseMessageChunk extends BaseMessage {
164
- static _mergeAdditionalKwargs(left, right) {
165
- const merged = { ...left };
166
- for (const [key, value] of Object.entries(right)) {
167
- if (merged[key] === undefined) {
168
- merged[key] = value;
169
- }
170
- else if (typeof merged[key] !== typeof value) {
171
- throw new Error(`additional_kwargs[${key}] already exists in the message chunk, but with a different type.`);
172
- }
173
- else if (typeof merged[key] === "string") {
174
- merged[key] = merged[key] + value;
175
- }
176
- else if (!Array.isArray(merged[key]) &&
177
- typeof merged[key] === "object") {
178
- merged[key] = this._mergeAdditionalKwargs(merged[key], value);
179
- }
180
- else if (key === "tool_calls" &&
181
- isOpenAIToolCallArray(merged[key]) &&
182
- isOpenAIToolCallArray(value)) {
183
- for (const toolCall of value) {
184
- if (merged[key]?.[toolCall.index] !== undefined) {
185
- merged[key] = merged[key]?.map((value, i) => {
186
- if (i !== toolCall.index) {
187
- return value;
188
- }
189
- return {
190
- ...value,
191
- ...toolCall,
192
- function: {
193
- name: toolCall.function.name ?? value.function.name,
194
- arguments: (value.function.arguments ?? "") +
195
- (toolCall.function.arguments ?? ""),
196
- },
197
- };
198
- });
199
- }
200
- else {
201
- merged[key][toolCall.index] = toolCall;
202
- }
203
- }
204
- }
205
- else {
206
- throw new Error(`additional_kwargs[${key}] already exists in this message chunk.`);
207
- }
208
- }
209
- return merged;
210
- }
211
- }
212
- /**
213
- * Represents a human message in a conversation.
214
- */
215
- export class HumanMessage extends BaseMessage {
216
- static lc_name() {
217
- return "HumanMessage";
218
- }
219
- _getType() {
220
- return "human";
221
- }
222
- }
223
- /**
224
- * Represents a chunk of a human message, which can be concatenated with
225
- * other human message chunks.
226
- */
227
- export class HumanMessageChunk extends BaseMessageChunk {
228
- static lc_name() {
229
- return "HumanMessageChunk";
230
- }
231
- _getType() {
232
- return "human";
233
- }
234
- concat(chunk) {
235
- return new HumanMessageChunk({
236
- content: mergeContent(this.content, chunk.content),
237
- additional_kwargs: HumanMessageChunk._mergeAdditionalKwargs(this.additional_kwargs, chunk.additional_kwargs),
238
- });
239
- }
240
- }
241
- /**
242
- * Represents an AI message in a conversation.
243
- */
244
- export class AIMessage extends BaseMessage {
245
- static lc_name() {
246
- return "AIMessage";
247
- }
248
- _getType() {
249
- return "ai";
250
- }
251
- }
252
- /**
253
- * Represents a chunk of an AI message, which can be concatenated with
254
- * other AI message chunks.
255
- */
256
- export class AIMessageChunk extends BaseMessageChunk {
257
- static lc_name() {
258
- return "AIMessageChunk";
259
- }
260
- _getType() {
261
- return "ai";
262
- }
263
- concat(chunk) {
264
- return new AIMessageChunk({
265
- content: mergeContent(this.content, chunk.content),
266
- additional_kwargs: AIMessageChunk._mergeAdditionalKwargs(this.additional_kwargs, chunk.additional_kwargs),
267
- });
268
- }
269
- }
270
- /**
271
- * Represents a system message in a conversation.
272
- */
273
- export class SystemMessage extends BaseMessage {
274
- static lc_name() {
275
- return "SystemMessage";
276
- }
277
- _getType() {
278
- return "system";
279
- }
280
- }
281
- /**
282
- * Represents a chunk of a system message, which can be concatenated with
283
- * other system message chunks.
284
- */
285
- export class SystemMessageChunk extends BaseMessageChunk {
286
- static lc_name() {
287
- return "SystemMessageChunk";
288
- }
289
- _getType() {
290
- return "system";
291
- }
292
- concat(chunk) {
293
- return new SystemMessageChunk({
294
- content: mergeContent(this.content, chunk.content),
295
- additional_kwargs: SystemMessageChunk._mergeAdditionalKwargs(this.additional_kwargs, chunk.additional_kwargs),
296
- });
297
- }
298
- }
3
+ export { RUN_KEY } from "langchain-core/outputs";
4
+ export { BaseMessageChunk, HumanMessageChunk, AIMessageChunk, SystemMessageChunk, FunctionMessage, FunctionMessageChunk, ToolMessage, ToolMessageChunk, ChatMessage, mapStoredMessageToChatMessage, ChatMessageChunk, coerceMessageLikeToMessage, isBaseMessage, isBaseMessageChunk, } from "langchain-core/messages";
5
+ export { BaseMessage, HumanMessage, AIMessage, SystemMessage };
299
6
  /**
300
7
  * @deprecated
301
8
  * Use {@link BaseMessage} instead.
@@ -316,292 +23,10 @@ export const AIChatMessage = AIMessage;
316
23
  * Use {@link SystemMessage} instead.
317
24
  */
318
25
  export const SystemChatMessage = SystemMessage;
319
- /**
320
- * Represents a function message in a conversation.
321
- */
322
- export class FunctionMessage extends BaseMessage {
323
- static lc_name() {
324
- return "FunctionMessage";
325
- }
326
- constructor(fields,
327
- /** @deprecated */
328
- name) {
329
- if (typeof fields === "string") {
330
- // eslint-disable-next-line no-param-reassign, @typescript-eslint/no-non-null-assertion
331
- fields = { content: fields, name: name };
332
- }
333
- super(fields);
334
- }
335
- _getType() {
336
- return "function";
337
- }
338
- }
339
- /**
340
- * Represents a chunk of a function message, which can be concatenated
341
- * with other function message chunks.
342
- */
343
- export class FunctionMessageChunk extends BaseMessageChunk {
344
- static lc_name() {
345
- return "FunctionMessageChunk";
346
- }
347
- _getType() {
348
- return "function";
349
- }
350
- concat(chunk) {
351
- return new FunctionMessageChunk({
352
- content: mergeContent(this.content, chunk.content),
353
- additional_kwargs: FunctionMessageChunk._mergeAdditionalKwargs(this.additional_kwargs, chunk.additional_kwargs),
354
- name: this.name ?? "",
355
- });
356
- }
357
- }
358
- /**
359
- * Represents a tool message in a conversation.
360
- */
361
- export class ToolMessage extends BaseMessage {
362
- static lc_name() {
363
- return "ToolMessage";
364
- }
365
- constructor(fields, tool_call_id, name) {
366
- if (typeof fields === "string") {
367
- // eslint-disable-next-line no-param-reassign, @typescript-eslint/no-non-null-assertion
368
- fields = { content: fields, name, tool_call_id: tool_call_id };
369
- }
370
- super(fields);
371
- Object.defineProperty(this, "tool_call_id", {
372
- enumerable: true,
373
- configurable: true,
374
- writable: true,
375
- value: void 0
376
- });
377
- this.tool_call_id = fields.tool_call_id;
378
- }
379
- _getType() {
380
- return "tool";
381
- }
382
- }
383
- /**
384
- * Represents a chunk of a tool message, which can be concatenated
385
- * with other tool message chunks.
386
- */
387
- export class ToolMessageChunk extends BaseMessageChunk {
388
- constructor(fields) {
389
- super(fields);
390
- Object.defineProperty(this, "tool_call_id", {
391
- enumerable: true,
392
- configurable: true,
393
- writable: true,
394
- value: void 0
395
- });
396
- this.tool_call_id = fields.tool_call_id;
397
- }
398
- static lc_name() {
399
- return "ToolMessageChunk";
400
- }
401
- _getType() {
402
- return "tool";
403
- }
404
- concat(chunk) {
405
- return new ToolMessageChunk({
406
- content: mergeContent(this.content, chunk.content),
407
- additional_kwargs: ToolMessageChunk._mergeAdditionalKwargs(this.additional_kwargs, chunk.additional_kwargs),
408
- tool_call_id: this.tool_call_id,
409
- });
410
- }
411
- }
412
- /**
413
- * Represents a chat message in a conversation.
414
- */
415
- export class ChatMessage extends BaseMessage {
416
- static lc_name() {
417
- return "ChatMessage";
418
- }
419
- constructor(fields, role) {
420
- if (typeof fields === "string") {
421
- // eslint-disable-next-line no-param-reassign, @typescript-eslint/no-non-null-assertion
422
- fields = { content: fields, role: role };
423
- }
424
- super(fields);
425
- Object.defineProperty(this, "role", {
426
- enumerable: true,
427
- configurable: true,
428
- writable: true,
429
- value: void 0
430
- });
431
- this.role = fields.role;
432
- }
433
- _getType() {
434
- return "generic";
435
- }
436
- static isInstance(message) {
437
- return message._getType() === "generic";
438
- }
439
- }
440
- export function isBaseMessage(messageLike) {
441
- return typeof messageLike?._getType === "function";
442
- }
443
- export function isBaseMessageChunk(messageLike) {
444
- return (isBaseMessage(messageLike) &&
445
- typeof messageLike.concat === "function");
446
- }
447
- export function coerceMessageLikeToMessage(messageLike) {
448
- if (typeof messageLike === "string") {
449
- return new HumanMessage(messageLike);
450
- }
451
- else if (isBaseMessage(messageLike)) {
452
- return messageLike;
453
- }
454
- const [type, content] = messageLike;
455
- if (type === "human" || type === "user") {
456
- return new HumanMessage({ content });
457
- }
458
- else if (type === "ai" || type === "assistant") {
459
- return new AIMessage({ content });
460
- }
461
- else if (type === "system") {
462
- return new SystemMessage({ content });
463
- }
464
- else {
465
- throw new Error(`Unable to coerce message from array: only human, AI, or system message coercion is currently supported.`);
466
- }
467
- }
468
- /**
469
- * Represents a chunk of a chat message, which can be concatenated with
470
- * other chat message chunks.
471
- */
472
- export class ChatMessageChunk extends BaseMessageChunk {
473
- static lc_name() {
474
- return "ChatMessageChunk";
475
- }
476
- constructor(fields, role) {
477
- if (typeof fields === "string") {
478
- // eslint-disable-next-line no-param-reassign, @typescript-eslint/no-non-null-assertion
479
- fields = { content: fields, role: role };
480
- }
481
- super(fields);
482
- Object.defineProperty(this, "role", {
483
- enumerable: true,
484
- configurable: true,
485
- writable: true,
486
- value: void 0
487
- });
488
- this.role = fields.role;
489
- }
490
- _getType() {
491
- return "generic";
492
- }
493
- concat(chunk) {
494
- return new ChatMessageChunk({
495
- content: mergeContent(this.content, chunk.content),
496
- additional_kwargs: ChatMessageChunk._mergeAdditionalKwargs(this.additional_kwargs, chunk.additional_kwargs),
497
- role: this.role,
498
- });
499
- }
500
- }
501
- export class ChatGenerationChunk extends GenerationChunk {
502
- constructor(fields) {
503
- super(fields);
504
- Object.defineProperty(this, "message", {
505
- enumerable: true,
506
- configurable: true,
507
- writable: true,
508
- value: void 0
509
- });
510
- this.message = fields.message;
511
- }
512
- concat(chunk) {
513
- return new ChatGenerationChunk({
514
- text: this.text + chunk.text,
515
- generationInfo: {
516
- ...this.generationInfo,
517
- ...chunk.generationInfo,
518
- },
519
- message: this.message.concat(chunk.message),
520
- });
521
- }
522
- }
523
- /**
524
- * Maps messages from an older format (V1) to the current `StoredMessage`
525
- * format. If the message is already in the `StoredMessage` format, it is
526
- * returned as is. Otherwise, it transforms the V1 message into a
527
- * `StoredMessage`. This function is important for maintaining
528
- * compatibility with older message formats.
529
- */
530
- function mapV1MessageToStoredMessage(message) {
531
- // TODO: Remove this mapper when we deprecate the old message format.
532
- if (message.data !== undefined) {
533
- return message;
534
- }
535
- else {
536
- const v1Message = message;
537
- return {
538
- type: v1Message.type,
539
- data: {
540
- content: v1Message.text,
541
- role: v1Message.role,
542
- name: undefined,
543
- tool_call_id: undefined,
544
- },
545
- };
546
- }
547
- }
548
- export function mapStoredMessageToChatMessage(message) {
549
- const storedMessage = mapV1MessageToStoredMessage(message);
550
- switch (storedMessage.type) {
551
- case "human":
552
- return new HumanMessage(storedMessage.data);
553
- case "ai":
554
- return new AIMessage(storedMessage.data);
555
- case "system":
556
- return new SystemMessage(storedMessage.data);
557
- case "function":
558
- if (storedMessage.data.name === undefined) {
559
- throw new Error("Name must be defined for function messages");
560
- }
561
- return new FunctionMessage(storedMessage.data);
562
- case "tool":
563
- if (storedMessage.data.tool_call_id === undefined) {
564
- throw new Error("Tool call ID must be defined for tool messages");
565
- }
566
- return new ToolMessage(storedMessage.data);
567
- case "chat": {
568
- if (storedMessage.data.role === undefined) {
569
- throw new Error("Role must be defined for chat messages");
570
- }
571
- return new ChatMessage(storedMessage.data);
572
- }
573
- default:
574
- throw new Error(`Got unexpected type: ${storedMessage.type}`);
575
- }
576
- }
577
- /**
578
- * Base PromptValue class. All prompt values should extend this class.
579
- */
580
- export class BasePromptValue extends Serializable {
581
- }
582
- /**
583
- * Base class for all chat message histories. All chat message histories
584
- * should extend this class.
585
- */
586
- export class BaseChatMessageHistory extends Serializable {
587
- }
588
- /**
589
- * Base class for all list chat message histories. All list chat message
590
- * histories should extend this class.
591
- */
592
- export class BaseListChatMessageHistory extends Serializable {
593
- addUserMessage(message) {
594
- return this.addMessage(new HumanMessage(message));
595
- }
596
- addAIChatMessage(message) {
597
- return this.addMessage(new AIMessage(message));
598
- }
599
- }
600
- /**
601
- * Base class for all caches. All caches should extend this class.
602
- */
603
- export class BaseCache {
604
- }
26
+ export { GenerationChunk, ChatGenerationChunk, } from "langchain-core/outputs";
27
+ export { BasePromptValue } from "langchain-core/prompt_values";
28
+ export { BaseChatMessageHistory, BaseListChatMessageHistory, } from "langchain-core/chat_history";
29
+ export { BaseCache } from "langchain-core/caches";
605
30
  /**
606
31
  * Base class for all file stores. All file stores should extend this
607
32
  * class.