@langchain/core 0.1.55 → 0.1.56

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 (52) hide show
  1. package/dist/agents.d.ts +1 -1
  2. package/dist/caches.d.ts +1 -1
  3. package/dist/language_models/chat_models.d.ts +14 -3
  4. package/dist/messages/ai.cjs +213 -0
  5. package/dist/messages/ai.d.ts +37 -0
  6. package/dist/messages/ai.js +207 -0
  7. package/dist/messages/base.cjs +212 -0
  8. package/dist/messages/base.d.ts +137 -0
  9. package/dist/messages/base.js +201 -0
  10. package/dist/messages/chat.cjs +71 -0
  11. package/dist/messages/chat.d.ts +28 -0
  12. package/dist/messages/chat.js +66 -0
  13. package/dist/messages/function.cjs +46 -0
  14. package/dist/messages/function.d.ts +24 -0
  15. package/dist/messages/function.js +41 -0
  16. package/dist/messages/human.cjs +36 -0
  17. package/dist/messages/human.d.ts +17 -0
  18. package/dist/messages/human.js +31 -0
  19. package/dist/messages/index.cjs +27 -633
  20. package/dist/messages/index.d.ts +8 -273
  21. package/dist/messages/index.js +10 -611
  22. package/dist/messages/system.cjs +36 -0
  23. package/dist/messages/system.d.ts +17 -0
  24. package/dist/messages/system.js +31 -0
  25. package/dist/messages/tool.cjs +101 -0
  26. package/dist/messages/tool.d.ts +101 -0
  27. package/dist/messages/tool.js +95 -0
  28. package/dist/messages/utils.cjs +172 -0
  29. package/dist/messages/utils.d.ts +31 -0
  30. package/dist/messages/utils.js +163 -0
  31. package/dist/output_parsers/json.cjs +6 -93
  32. package/dist/output_parsers/json.d.ts +2 -2
  33. package/dist/output_parsers/json.js +2 -88
  34. package/dist/output_parsers/openai_tools/json_output_tools_parsers.cjs +79 -13
  35. package/dist/output_parsers/openai_tools/json_output_tools_parsers.d.ts +18 -0
  36. package/dist/output_parsers/openai_tools/json_output_tools_parsers.js +75 -12
  37. package/dist/output_parsers/transform.cjs +7 -6
  38. package/dist/output_parsers/transform.d.ts +1 -1
  39. package/dist/output_parsers/transform.js +3 -2
  40. package/dist/utils/function_calling.cjs +18 -6
  41. package/dist/utils/function_calling.d.ts +2 -1
  42. package/dist/utils/function_calling.js +16 -5
  43. package/dist/utils/json.cjs +93 -0
  44. package/dist/utils/json.d.ts +2 -0
  45. package/dist/utils/json.js +88 -0
  46. package/dist/utils/testing/index.cjs +3 -0
  47. package/dist/utils/testing/index.js +3 -0
  48. package/messages/tool.cjs +1 -0
  49. package/messages/tool.d.cts +1 -0
  50. package/messages/tool.d.ts +1 -0
  51. package/messages/tool.js +1 -0
  52. package/package.json +14 -1
@@ -1,635 +1,29 @@
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.mapChatMessagesToStoredMessages = exports.mapStoredMessagesToChatMessages = exports.mapStoredMessageToChatMessage = exports.getBufferString = exports.ChatMessageChunk = exports.coerceMessageLikeToMessage = exports.isBaseMessageChunk = exports.isBaseMessage = exports.ChatMessage = exports.ToolMessageChunk = exports.ToolMessage = exports.FunctionMessageChunk = exports.FunctionMessage = exports.SystemMessageChunk = exports.SystemMessage = exports.AIMessageChunk = exports.AIMessage = exports.HumanMessageChunk = exports.HumanMessage = exports.BaseMessageChunk = exports.BaseMessage = void 0;
4
- const serializable_js_1 = require("../load/serializable.cjs");
5
- function mergeContent(firstContent, secondContent) {
6
- // If first content is a string
7
- if (typeof firstContent === "string") {
8
- if (typeof secondContent === "string") {
9
- return firstContent + secondContent;
10
- }
11
- else {
12
- return [{ type: "text", text: firstContent }, ...secondContent];
13
- }
14
- // If both are arrays
15
- }
16
- else if (Array.isArray(secondContent)) {
17
- return [...firstContent, ...secondContent];
18
- // If the first content is a list and second is a string
19
- }
20
- else {
21
- // Otherwise, add the second content as a new element of the list
22
- return [...firstContent, { type: "text", text: secondContent }];
23
- }
24
- }
25
- /**
26
- * Base class for all types of messages in a conversation. It includes
27
- * properties like `content`, `name`, and `additional_kwargs`. It also
28
- * includes methods like `toDict()` and `_getType()`.
29
- */
30
- class BaseMessage extends serializable_js_1.Serializable {
31
- get lc_aliases() {
32
- // exclude snake case conversion to pascal case
33
- return {
34
- additional_kwargs: "additional_kwargs",
35
- response_metadata: "response_metadata",
36
- };
37
- }
38
- /**
39
- * @deprecated
40
- * Use {@link BaseMessage.content} instead.
41
- */
42
- get text() {
43
- return typeof this.content === "string" ? this.content : "";
44
- }
45
- constructor(fields,
46
- /** @deprecated */
47
- kwargs) {
48
- if (typeof fields === "string") {
49
- // eslint-disable-next-line no-param-reassign
50
- fields = {
51
- content: fields,
52
- additional_kwargs: kwargs,
53
- response_metadata: {},
54
- };
55
- }
56
- // Make sure the default value for additional_kwargs is passed into super() for serialization
57
- if (!fields.additional_kwargs) {
58
- // eslint-disable-next-line no-param-reassign
59
- fields.additional_kwargs = {};
60
- }
61
- if (!fields.response_metadata) {
62
- // eslint-disable-next-line no-param-reassign
63
- fields.response_metadata = {};
64
- }
65
- super(fields);
66
- Object.defineProperty(this, "lc_namespace", {
67
- enumerable: true,
68
- configurable: true,
69
- writable: true,
70
- value: ["langchain_core", "messages"]
71
- });
72
- Object.defineProperty(this, "lc_serializable", {
73
- enumerable: true,
74
- configurable: true,
75
- writable: true,
76
- value: true
77
- });
78
- /** The content of the message. */
79
- Object.defineProperty(this, "content", {
80
- enumerable: true,
81
- configurable: true,
82
- writable: true,
83
- value: void 0
84
- });
85
- /** The name of the message sender in a multi-user chat. */
86
- Object.defineProperty(this, "name", {
87
- enumerable: true,
88
- configurable: true,
89
- writable: true,
90
- value: void 0
91
- });
92
- /** Additional keyword arguments */
93
- Object.defineProperty(this, "additional_kwargs", {
94
- enumerable: true,
95
- configurable: true,
96
- writable: true,
97
- value: void 0
98
- });
99
- /** Response metadata. For example: response headers, logprobs, token counts. */
100
- Object.defineProperty(this, "response_metadata", {
101
- enumerable: true,
102
- configurable: true,
103
- writable: true,
104
- value: void 0
105
- });
106
- this.name = fields.name;
107
- this.content = fields.content;
108
- this.additional_kwargs = fields.additional_kwargs;
109
- this.response_metadata = fields.response_metadata;
110
- }
111
- toDict() {
112
- return {
113
- type: this._getType(),
114
- data: this.toJSON()
115
- .kwargs,
116
- };
117
- }
118
- toChunk() {
119
- const type = this._getType();
120
- if (type === "human") {
121
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
122
- return new HumanMessageChunk({ ...this });
123
- }
124
- else if (type === "ai") {
125
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
126
- return new AIMessageChunk({ ...this });
127
- }
128
- else if (type === "system") {
129
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
130
- return new SystemMessageChunk({ ...this });
131
- }
132
- else if (type === "function") {
133
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
134
- return new FunctionMessageChunk({ ...this });
135
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
136
- }
137
- else if (ChatMessage.isInstance(this)) {
138
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
139
- return new ChatMessageChunk({ ...this });
140
- }
141
- else {
142
- throw new Error("Unknown message type.");
143
- }
144
- }
145
- }
146
- exports.BaseMessage = BaseMessage;
147
- function isOpenAIToolCallArray(value) {
148
- return (Array.isArray(value) &&
149
- value.every((v) => typeof v.index === "number"));
150
- }
151
- function _mergeDicts(
152
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
153
- left,
154
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
155
- right
156
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
157
- ) {
158
- const merged = { ...left };
159
- for (const [key, value] of Object.entries(right)) {
160
- if (merged[key] == null) {
161
- merged[key] = value;
162
- }
163
- else if (value == null) {
164
- continue;
165
- }
166
- else if (typeof merged[key] !== typeof value ||
167
- Array.isArray(merged[key]) !== Array.isArray(value)) {
168
- throw new Error(`field[${key}] already exists in the message chunk, but with a different type.`);
169
- }
170
- else if (typeof merged[key] === "string") {
171
- merged[key] = merged[key] + value;
172
- }
173
- else if (!Array.isArray(merged[key]) && typeof merged[key] === "object") {
174
- merged[key] = _mergeDicts(merged[key], value);
175
- }
176
- else if (key === "tool_calls" &&
177
- isOpenAIToolCallArray(merged[key]) &&
178
- isOpenAIToolCallArray(value)) {
179
- for (const toolCall of value) {
180
- if (merged[key]?.[toolCall.index] !== undefined) {
181
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
182
- merged[key] = merged[key]?.map((value, i) => {
183
- if (i !== toolCall.index) {
184
- return value;
185
- }
186
- return {
187
- ...value,
188
- ...toolCall,
189
- function: {
190
- name: toolCall.function.name ?? value.function.name,
191
- arguments: (value.function.arguments ?? "") +
192
- (toolCall.function.arguments ?? ""),
193
- },
194
- };
195
- });
196
- }
197
- else {
198
- merged[key][toolCall.index] = toolCall;
199
- }
200
- }
201
- }
202
- else if (Array.isArray(merged[key])) {
203
- merged[key] = merged[key].concat(value);
204
- }
205
- else if (merged[key] === value) {
206
- continue;
207
- }
208
- else {
209
- console.warn(`field[${key}] already exists in this message chunk and value has unsupported type.`);
210
- }
211
- }
212
- return merged;
213
- }
214
- /**
215
- * Represents a chunk of a message, which can be concatenated with other
216
- * message chunks. It includes a method `_merge_kwargs_dict()` for merging
217
- * additional keyword arguments from another `BaseMessageChunk` into this
218
- * one. It also overrides the `__add__()` method to support concatenation
219
- * of `BaseMessageChunk` instances.
220
- */
221
- class BaseMessageChunk extends BaseMessage {
222
- }
223
- exports.BaseMessageChunk = BaseMessageChunk;
224
- /**
225
- * Represents a human message in a conversation.
226
- */
227
- class HumanMessage extends BaseMessage {
228
- static lc_name() {
229
- return "HumanMessage";
230
- }
231
- _getType() {
232
- return "human";
233
- }
234
- }
235
- exports.HumanMessage = HumanMessage;
236
- /**
237
- * Represents a chunk of a human message, which can be concatenated with
238
- * other human message chunks.
239
- */
240
- class HumanMessageChunk extends BaseMessageChunk {
241
- static lc_name() {
242
- return "HumanMessageChunk";
243
- }
244
- _getType() {
245
- return "human";
246
- }
247
- concat(chunk) {
248
- return new HumanMessageChunk({
249
- content: mergeContent(this.content, chunk.content),
250
- additional_kwargs: _mergeDicts(this.additional_kwargs, chunk.additional_kwargs),
251
- response_metadata: _mergeDicts(this.response_metadata, chunk.response_metadata),
252
- });
253
- }
254
- }
255
- exports.HumanMessageChunk = HumanMessageChunk;
256
- /**
257
- * Represents an AI message in a conversation.
258
- */
259
- class AIMessage extends BaseMessage {
260
- static lc_name() {
261
- return "AIMessage";
262
- }
263
- _getType() {
264
- return "ai";
265
- }
266
- }
267
- exports.AIMessage = AIMessage;
268
- /**
269
- * Represents a chunk of an AI message, which can be concatenated with
270
- * other AI message chunks.
271
- */
272
- class AIMessageChunk extends BaseMessageChunk {
273
- static lc_name() {
274
- return "AIMessageChunk";
275
- }
276
- _getType() {
277
- return "ai";
278
- }
279
- concat(chunk) {
280
- return new AIMessageChunk({
281
- content: mergeContent(this.content, chunk.content),
282
- additional_kwargs: _mergeDicts(this.additional_kwargs, chunk.additional_kwargs),
283
- response_metadata: _mergeDicts(this.response_metadata, chunk.response_metadata),
284
- });
285
- }
286
- }
287
- exports.AIMessageChunk = AIMessageChunk;
288
- /**
289
- * Represents a system message in a conversation.
290
- */
291
- class SystemMessage extends BaseMessage {
292
- static lc_name() {
293
- return "SystemMessage";
294
- }
295
- _getType() {
296
- return "system";
297
- }
298
- }
299
- exports.SystemMessage = SystemMessage;
300
- /**
301
- * Represents a chunk of a system message, which can be concatenated with
302
- * other system message chunks.
303
- */
304
- class SystemMessageChunk extends BaseMessageChunk {
305
- static lc_name() {
306
- return "SystemMessageChunk";
307
- }
308
- _getType() {
309
- return "system";
310
- }
311
- concat(chunk) {
312
- return new SystemMessageChunk({
313
- content: mergeContent(this.content, chunk.content),
314
- additional_kwargs: _mergeDicts(this.additional_kwargs, chunk.additional_kwargs),
315
- response_metadata: _mergeDicts(this.response_metadata, chunk.response_metadata),
316
- });
317
- }
318
- }
319
- exports.SystemMessageChunk = SystemMessageChunk;
320
- /**
321
- * Represents a function message in a conversation.
322
- */
323
- class FunctionMessage extends BaseMessage {
324
- static lc_name() {
325
- return "FunctionMessage";
326
- }
327
- constructor(fields,
328
- /** @deprecated */
329
- name) {
330
- if (typeof fields === "string") {
331
- // eslint-disable-next-line no-param-reassign, @typescript-eslint/no-non-null-assertion
332
- fields = { content: fields, name: name };
333
- }
334
- super(fields);
335
- }
336
- _getType() {
337
- return "function";
338
- }
339
- }
340
- exports.FunctionMessage = FunctionMessage;
341
- /**
342
- * Represents a chunk of a function message, which can be concatenated
343
- * with other function message chunks.
344
- */
345
- class FunctionMessageChunk extends BaseMessageChunk {
346
- static lc_name() {
347
- return "FunctionMessageChunk";
348
- }
349
- _getType() {
350
- return "function";
351
- }
352
- concat(chunk) {
353
- return new FunctionMessageChunk({
354
- content: mergeContent(this.content, chunk.content),
355
- additional_kwargs: _mergeDicts(this.additional_kwargs, chunk.additional_kwargs),
356
- response_metadata: _mergeDicts(this.response_metadata, chunk.response_metadata),
357
- name: this.name ?? "",
358
- });
359
- }
360
- }
361
- exports.FunctionMessageChunk = FunctionMessageChunk;
362
- /**
363
- * Represents a tool message in a conversation.
364
- */
365
- class ToolMessage extends BaseMessage {
366
- static lc_name() {
367
- return "ToolMessage";
368
- }
369
- get lc_aliases() {
370
- // exclude snake case conversion to pascal case
371
- return { tool_call_id: "tool_call_id" };
372
- }
373
- constructor(fields, tool_call_id, name) {
374
- if (typeof fields === "string") {
375
- // eslint-disable-next-line no-param-reassign, @typescript-eslint/no-non-null-assertion
376
- fields = { content: fields, name, tool_call_id: tool_call_id };
377
- }
378
- super(fields);
379
- Object.defineProperty(this, "tool_call_id", {
380
- enumerable: true,
381
- configurable: true,
382
- writable: true,
383
- value: void 0
384
- });
385
- this.tool_call_id = fields.tool_call_id;
386
- }
387
- _getType() {
388
- return "tool";
389
- }
390
- static isInstance(message) {
391
- return message._getType() === "tool";
392
- }
393
- }
394
- exports.ToolMessage = ToolMessage;
395
- /**
396
- * Represents a chunk of a tool message, which can be concatenated
397
- * with other tool message chunks.
398
- */
399
- class ToolMessageChunk extends BaseMessageChunk {
400
- constructor(fields) {
401
- super(fields);
402
- Object.defineProperty(this, "tool_call_id", {
403
- enumerable: true,
404
- configurable: true,
405
- writable: true,
406
- value: void 0
407
- });
408
- this.tool_call_id = fields.tool_call_id;
409
- }
410
- static lc_name() {
411
- return "ToolMessageChunk";
412
- }
413
- _getType() {
414
- return "tool";
415
- }
416
- concat(chunk) {
417
- return new ToolMessageChunk({
418
- content: mergeContent(this.content, chunk.content),
419
- additional_kwargs: _mergeDicts(this.additional_kwargs, chunk.additional_kwargs),
420
- response_metadata: _mergeDicts(this.response_metadata, chunk.response_metadata),
421
- tool_call_id: this.tool_call_id,
422
- });
423
- }
424
- }
425
- exports.ToolMessageChunk = ToolMessageChunk;
426
- /**
427
- * Represents a chat message in a conversation.
428
- */
429
- class ChatMessage extends BaseMessage {
430
- static lc_name() {
431
- return "ChatMessage";
432
- }
433
- static _chatMessageClass() {
434
- return ChatMessage;
435
- }
436
- constructor(fields, role) {
437
- if (typeof fields === "string") {
438
- // eslint-disable-next-line no-param-reassign, @typescript-eslint/no-non-null-assertion
439
- fields = { content: fields, role: role };
440
- }
441
- super(fields);
442
- Object.defineProperty(this, "role", {
443
- enumerable: true,
444
- configurable: true,
445
- writable: true,
446
- value: void 0
447
- });
448
- this.role = fields.role;
449
- }
450
- _getType() {
451
- return "generic";
452
- }
453
- static isInstance(message) {
454
- return message._getType() === "generic";
455
- }
456
- }
457
- exports.ChatMessage = ChatMessage;
458
- function isBaseMessage(messageLike) {
459
- return typeof messageLike?._getType === "function";
460
- }
461
- exports.isBaseMessage = isBaseMessage;
462
- function isBaseMessageChunk(messageLike) {
463
- return (isBaseMessage(messageLike) &&
464
- typeof messageLike.concat === "function");
465
- }
466
- exports.isBaseMessageChunk = isBaseMessageChunk;
467
- function coerceMessageLikeToMessage(messageLike) {
468
- if (typeof messageLike === "string") {
469
- return new HumanMessage(messageLike);
470
- }
471
- else if (isBaseMessage(messageLike)) {
472
- return messageLike;
473
- }
474
- const [type, content] = messageLike;
475
- if (type === "human" || type === "user") {
476
- return new HumanMessage({ content });
477
- }
478
- else if (type === "ai" || type === "assistant") {
479
- return new AIMessage({ content });
480
- }
481
- else if (type === "system") {
482
- return new SystemMessage({ content });
483
- }
484
- else {
485
- throw new Error(`Unable to coerce message from array: only human, AI, or system message coercion is currently supported.`);
486
- }
487
- }
488
- exports.coerceMessageLikeToMessage = coerceMessageLikeToMessage;
489
- /**
490
- * Represents a chunk of a chat message, which can be concatenated with
491
- * other chat message chunks.
492
- */
493
- class ChatMessageChunk extends BaseMessageChunk {
494
- static lc_name() {
495
- return "ChatMessageChunk";
496
- }
497
- constructor(fields, role) {
498
- if (typeof fields === "string") {
499
- // eslint-disable-next-line no-param-reassign, @typescript-eslint/no-non-null-assertion
500
- fields = { content: fields, role: role };
501
- }
502
- super(fields);
503
- Object.defineProperty(this, "role", {
504
- enumerable: true,
505
- configurable: true,
506
- writable: true,
507
- value: void 0
508
- });
509
- this.role = fields.role;
510
- }
511
- _getType() {
512
- return "generic";
513
- }
514
- concat(chunk) {
515
- return new ChatMessageChunk({
516
- content: mergeContent(this.content, chunk.content),
517
- additional_kwargs: _mergeDicts(this.additional_kwargs, chunk.additional_kwargs),
518
- response_metadata: _mergeDicts(this.response_metadata, chunk.response_metadata),
519
- role: this.role,
520
- });
521
- }
522
- }
523
- exports.ChatMessageChunk = ChatMessageChunk;
524
- /**
525
- * This function is used by memory classes to get a string representation
526
- * of the chat message history, based on the message content and role.
527
- */
528
- function getBufferString(messages, humanPrefix = "Human", aiPrefix = "AI") {
529
- const string_messages = [];
530
- for (const m of messages) {
531
- let role;
532
- if (m._getType() === "human") {
533
- role = humanPrefix;
534
- }
535
- else if (m._getType() === "ai") {
536
- role = aiPrefix;
537
- }
538
- else if (m._getType() === "system") {
539
- role = "System";
540
- }
541
- else if (m._getType() === "function") {
542
- role = "Function";
543
- }
544
- else if (m._getType() === "tool") {
545
- role = "Tool";
546
- }
547
- else if (m._getType() === "generic") {
548
- role = m.role;
549
- }
550
- else {
551
- throw new Error(`Got unsupported message type: ${m._getType()}`);
552
- }
553
- const nameStr = m.name ? `${m.name}, ` : "";
554
- string_messages.push(`${role}: ${nameStr}${m.content}`);
555
- }
556
- return string_messages.join("\n");
557
- }
558
- exports.getBufferString = getBufferString;
559
- /**
560
- * Maps messages from an older format (V1) to the current `StoredMessage`
561
- * format. If the message is already in the `StoredMessage` format, it is
562
- * returned as is. Otherwise, it transforms the V1 message into a
563
- * `StoredMessage`. This function is important for maintaining
564
- * compatibility with older message formats.
565
- */
566
- function mapV1MessageToStoredMessage(message) {
567
- // TODO: Remove this mapper when we deprecate the old message format.
568
- if (message.data !== undefined) {
569
- return message;
570
- }
571
- else {
572
- const v1Message = message;
573
- return {
574
- type: v1Message.type,
575
- data: {
576
- content: v1Message.text,
577
- role: v1Message.role,
578
- name: undefined,
579
- tool_call_id: undefined,
580
- },
581
- };
582
- }
583
- }
584
- function mapStoredMessageToChatMessage(message) {
585
- const storedMessage = mapV1MessageToStoredMessage(message);
586
- switch (storedMessage.type) {
587
- case "human":
588
- return new HumanMessage(storedMessage.data);
589
- case "ai":
590
- return new AIMessage(storedMessage.data);
591
- case "system":
592
- return new SystemMessage(storedMessage.data);
593
- case "function":
594
- if (storedMessage.data.name === undefined) {
595
- throw new Error("Name must be defined for function messages");
596
- }
597
- return new FunctionMessage(storedMessage.data);
598
- case "tool":
599
- if (storedMessage.data.tool_call_id === undefined) {
600
- throw new Error("Tool call ID must be defined for tool messages");
601
- }
602
- return new ToolMessage(storedMessage.data);
603
- case "chat": {
604
- if (storedMessage.data.role === undefined) {
605
- throw new Error("Role must be defined for chat messages");
606
- }
607
- return new ChatMessage(storedMessage.data);
608
- }
609
- default:
610
- throw new Error(`Got unexpected type: ${storedMessage.type}`);
611
- }
612
- }
613
- exports.mapStoredMessageToChatMessage = mapStoredMessageToChatMessage;
614
- /**
615
- * Transforms an array of `StoredMessage` instances into an array of
616
- * `BaseMessage` instances. It uses the `mapV1MessageToStoredMessage`
617
- * function to ensure all messages are in the `StoredMessage` format, then
618
- * creates new instances of the appropriate `BaseMessage` subclass based
619
- * on the type of each message. This function is used to prepare stored
620
- * messages for use in a chat context.
621
- */
622
- function mapStoredMessagesToChatMessages(messages) {
623
- return messages.map(mapStoredMessageToChatMessage);
624
- }
625
- exports.mapStoredMessagesToChatMessages = mapStoredMessagesToChatMessages;
626
- /**
627
- * Transforms an array of `BaseMessage` instances into an array of
628
- * `StoredMessage` instances. It does this by calling the `toDict` method
629
- * on each `BaseMessage`, which returns a `StoredMessage`. This function
630
- * is used to prepare chat messages for storage.
631
- */
632
- function mapChatMessagesToStoredMessages(messages) {
633
- return messages.map((message) => message.toDict());
634
- }
635
- exports.mapChatMessagesToStoredMessages = mapChatMessagesToStoredMessages;
17
+ exports.ToolMessageChunk = exports.ToolMessage = void 0;
18
+ __exportStar(require("./ai.cjs"), exports);
19
+ __exportStar(require("./base.cjs"), exports);
20
+ __exportStar(require("./chat.cjs"), exports);
21
+ __exportStar(require("./function.cjs"), exports);
22
+ __exportStar(require("./human.cjs"), exports);
23
+ __exportStar(require("./system.cjs"), exports);
24
+ __exportStar(require("./utils.cjs"), exports);
25
+ // TODO: Use a star export when we deprecate the
26
+ // existing "ToolCall" type in "base.js".
27
+ var tool_js_1 = require("./tool.cjs");
28
+ Object.defineProperty(exports, "ToolMessage", { enumerable: true, get: function () { return tool_js_1.ToolMessage; } });
29
+ Object.defineProperty(exports, "ToolMessageChunk", { enumerable: true, get: function () { return tool_js_1.ToolMessageChunk; } });