@digipair/skill-llm 0.7.3 → 0.8.1

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.
package/chat.esm.js ADDED
@@ -0,0 +1,2010 @@
1
+ import { c as checkValidTemplate, a as BasePromptTemplate, I as ImagePromptValue, b as BaseMessage, P as PromptTemplate, H as HumanMessage, S as SystemMessage, i as isBaseMessage, d as coerceMessageLikeToMessage, C as ChatMessage, e as ChatPromptValue, p as parseFString, B as BaseStringPromptTemplate, A as AIMessage, R as Runnable } from './index.esm2.js';
2
+
3
+ function _array_like_to_array$1(arr, len) {
4
+ if (len == null || len > arr.length) len = arr.length;
5
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
6
+ return arr2;
7
+ }
8
+ function _array_with_holes(arr) {
9
+ if (Array.isArray(arr)) return arr;
10
+ }
11
+ function _assert_this_initialized$1(self) {
12
+ if (self === void 0) {
13
+ throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
14
+ }
15
+ return self;
16
+ }
17
+ function asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, key, arg) {
18
+ try {
19
+ var info = gen[key](arg);
20
+ var value = info.value;
21
+ } catch (error) {
22
+ reject(error);
23
+ return;
24
+ }
25
+ if (info.done) {
26
+ resolve(value);
27
+ } else {
28
+ Promise.resolve(value).then(_next, _throw);
29
+ }
30
+ }
31
+ function _async_to_generator$1(fn) {
32
+ return function() {
33
+ var self = this, args = arguments;
34
+ return new Promise(function(resolve, reject) {
35
+ var gen = fn.apply(self, args);
36
+ function _next(value) {
37
+ asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "next", value);
38
+ }
39
+ function _throw(err) {
40
+ asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "throw", err);
41
+ }
42
+ _next(undefined);
43
+ });
44
+ };
45
+ }
46
+ function _class_call_check$1(instance, Constructor) {
47
+ if (!(instance instanceof Constructor)) {
48
+ throw new TypeError("Cannot call a class as a function");
49
+ }
50
+ }
51
+ function _defineProperties$1(target, props) {
52
+ for(var i = 0; i < props.length; i++){
53
+ var descriptor = props[i];
54
+ descriptor.enumerable = descriptor.enumerable || false;
55
+ descriptor.configurable = true;
56
+ if ("value" in descriptor) descriptor.writable = true;
57
+ Object.defineProperty(target, descriptor.key, descriptor);
58
+ }
59
+ }
60
+ function _create_class$1(Constructor, protoProps, staticProps) {
61
+ if (protoProps) _defineProperties$1(Constructor.prototype, protoProps);
62
+ if (staticProps) _defineProperties$1(Constructor, staticProps);
63
+ return Constructor;
64
+ }
65
+ function _define_property$1(obj, key, value) {
66
+ if (key in obj) {
67
+ Object.defineProperty(obj, key, {
68
+ value: value,
69
+ enumerable: true,
70
+ configurable: true,
71
+ writable: true
72
+ });
73
+ } else {
74
+ obj[key] = value;
75
+ }
76
+ return obj;
77
+ }
78
+ function _get_prototype_of$1(o) {
79
+ _get_prototype_of$1 = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
80
+ return o.__proto__ || Object.getPrototypeOf(o);
81
+ };
82
+ return _get_prototype_of$1(o);
83
+ }
84
+ function _inherits$1(subClass, superClass) {
85
+ if (typeof superClass !== "function" && superClass !== null) {
86
+ throw new TypeError("Super expression must either be null or a function");
87
+ }
88
+ subClass.prototype = Object.create(superClass && superClass.prototype, {
89
+ constructor: {
90
+ value: subClass,
91
+ writable: true,
92
+ configurable: true
93
+ }
94
+ });
95
+ if (superClass) _set_prototype_of$1(subClass, superClass);
96
+ }
97
+ function _iterable_to_array_limit(arr, i) {
98
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
99
+ if (_i == null) return;
100
+ var _arr = [];
101
+ var _n = true;
102
+ var _d = false;
103
+ var _s, _e;
104
+ try {
105
+ for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
106
+ _arr.push(_s.value);
107
+ if (i && _arr.length === i) break;
108
+ }
109
+ } catch (err) {
110
+ _d = true;
111
+ _e = err;
112
+ } finally{
113
+ try {
114
+ if (!_n && _i["return"] != null) _i["return"]();
115
+ } finally{
116
+ if (_d) throw _e;
117
+ }
118
+ }
119
+ return _arr;
120
+ }
121
+ function _non_iterable_rest() {
122
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
123
+ }
124
+ function _object_spread$1(target) {
125
+ for(var i = 1; i < arguments.length; i++){
126
+ var source = arguments[i] != null ? arguments[i] : {};
127
+ var ownKeys = Object.keys(source);
128
+ if (typeof Object.getOwnPropertySymbols === "function") {
129
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
130
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
131
+ }));
132
+ }
133
+ ownKeys.forEach(function(key) {
134
+ _define_property$1(target, key, source[key]);
135
+ });
136
+ }
137
+ return target;
138
+ }
139
+ function ownKeys$1(object, enumerableOnly) {
140
+ var keys = Object.keys(object);
141
+ if (Object.getOwnPropertySymbols) {
142
+ var symbols = Object.getOwnPropertySymbols(object);
143
+ if (enumerableOnly) {
144
+ symbols = symbols.filter(function(sym) {
145
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
146
+ });
147
+ }
148
+ keys.push.apply(keys, symbols);
149
+ }
150
+ return keys;
151
+ }
152
+ function _object_spread_props$1(target, source) {
153
+ source = source != null ? source : {};
154
+ if (Object.getOwnPropertyDescriptors) {
155
+ Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
156
+ } else {
157
+ ownKeys$1(Object(source)).forEach(function(key) {
158
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
159
+ });
160
+ }
161
+ return target;
162
+ }
163
+ function _possible_constructor_return$1(self, call) {
164
+ if (call && (_type_of$1(call) === "object" || typeof call === "function")) {
165
+ return call;
166
+ }
167
+ return _assert_this_initialized$1(self);
168
+ }
169
+ function _set_prototype_of$1(o, p) {
170
+ _set_prototype_of$1 = Object.setPrototypeOf || function setPrototypeOf(o, p) {
171
+ o.__proto__ = p;
172
+ return o;
173
+ };
174
+ return _set_prototype_of$1(o, p);
175
+ }
176
+ function _sliced_to_array(arr, i) {
177
+ return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array$1(arr, i) || _non_iterable_rest();
178
+ }
179
+ function _type_of$1(obj) {
180
+ "@swc/helpers - typeof";
181
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
182
+ }
183
+ function _unsupported_iterable_to_array$1(o, minLen) {
184
+ if (!o) return;
185
+ if (typeof o === "string") return _array_like_to_array$1(o, minLen);
186
+ var n = Object.prototype.toString.call(o).slice(8, -1);
187
+ if (n === "Object" && o.constructor) n = o.constructor.name;
188
+ if (n === "Map" || n === "Set") return Array.from(n);
189
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array$1(o, minLen);
190
+ }
191
+ function _is_native_reflect_construct$1() {
192
+ if (typeof Reflect === "undefined" || !Reflect.construct) return false;
193
+ if (Reflect.construct.sham) return false;
194
+ if (typeof Proxy === "function") return true;
195
+ try {
196
+ Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
197
+ return true;
198
+ } catch (e) {
199
+ return false;
200
+ }
201
+ }
202
+ function _create_super$1(Derived) {
203
+ var hasNativeReflectConstruct = _is_native_reflect_construct$1();
204
+ return function _createSuperInternal() {
205
+ var Super = _get_prototype_of$1(Derived), result;
206
+ if (hasNativeReflectConstruct) {
207
+ var NewTarget = _get_prototype_of$1(this).constructor;
208
+ result = Reflect.construct(Super, arguments, NewTarget);
209
+ } else {
210
+ result = Super.apply(this, arguments);
211
+ }
212
+ return _possible_constructor_return$1(this, result);
213
+ };
214
+ }
215
+ function _ts_generator$1(thisArg, body) {
216
+ var f, y, t, g, _ = {
217
+ label: 0,
218
+ sent: function() {
219
+ if (t[0] & 1) throw t[1];
220
+ return t[1];
221
+ },
222
+ trys: [],
223
+ ops: []
224
+ };
225
+ return g = {
226
+ next: verb(0),
227
+ "throw": verb(1),
228
+ "return": verb(2)
229
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
230
+ return this;
231
+ }), g;
232
+ function verb(n) {
233
+ return function(v) {
234
+ return step([
235
+ n,
236
+ v
237
+ ]);
238
+ };
239
+ }
240
+ function step(op) {
241
+ if (f) throw new TypeError("Generator is already executing.");
242
+ while(_)try {
243
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
244
+ if (y = 0, t) op = [
245
+ op[0] & 2,
246
+ t.value
247
+ ];
248
+ switch(op[0]){
249
+ case 0:
250
+ case 1:
251
+ t = op;
252
+ break;
253
+ case 4:
254
+ _.label++;
255
+ return {
256
+ value: op[1],
257
+ done: false
258
+ };
259
+ case 5:
260
+ _.label++;
261
+ y = op[1];
262
+ op = [
263
+ 0
264
+ ];
265
+ continue;
266
+ case 7:
267
+ op = _.ops.pop();
268
+ _.trys.pop();
269
+ continue;
270
+ default:
271
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
272
+ _ = 0;
273
+ continue;
274
+ }
275
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
276
+ _.label = op[1];
277
+ break;
278
+ }
279
+ if (op[0] === 6 && _.label < t[1]) {
280
+ _.label = t[1];
281
+ t = op;
282
+ break;
283
+ }
284
+ if (t && _.label < t[2]) {
285
+ _.label = t[2];
286
+ _.ops.push(op);
287
+ break;
288
+ }
289
+ if (t[2]) _.ops.pop();
290
+ _.trys.pop();
291
+ continue;
292
+ }
293
+ op = body.call(thisArg, _);
294
+ } catch (e) {
295
+ op = [
296
+ 6,
297
+ e
298
+ ];
299
+ y = 0;
300
+ } finally{
301
+ f = t = 0;
302
+ }
303
+ if (op[0] & 5) throw op[1];
304
+ return {
305
+ value: op[0] ? op[1] : void 0,
306
+ done: true
307
+ };
308
+ }
309
+ }
310
+ /**
311
+ * An image prompt template for a multimodal model.
312
+ */ var ImagePromptTemplate = /*#__PURE__*/ function(BasePromptTemplate) {
313
+ _inherits$1(ImagePromptTemplate, BasePromptTemplate);
314
+ var _super = _create_super$1(ImagePromptTemplate);
315
+ function ImagePromptTemplate(input) {
316
+ _class_call_check$1(this, ImagePromptTemplate);
317
+ var _this;
318
+ _this = _super.call(this, input);
319
+ Object.defineProperty(_assert_this_initialized$1(_this), "lc_namespace", {
320
+ enumerable: true,
321
+ configurable: true,
322
+ writable: true,
323
+ value: [
324
+ "langchain_core",
325
+ "prompts",
326
+ "image"
327
+ ]
328
+ });
329
+ Object.defineProperty(_assert_this_initialized$1(_this), "template", {
330
+ enumerable: true,
331
+ configurable: true,
332
+ writable: true,
333
+ value: void 0
334
+ });
335
+ Object.defineProperty(_assert_this_initialized$1(_this), "templateFormat", {
336
+ enumerable: true,
337
+ configurable: true,
338
+ writable: true,
339
+ value: "f-string"
340
+ });
341
+ Object.defineProperty(_assert_this_initialized$1(_this), "validateTemplate", {
342
+ enumerable: true,
343
+ configurable: true,
344
+ writable: true,
345
+ value: true
346
+ });
347
+ _this.template = input.template;
348
+ var _input_templateFormat;
349
+ _this.templateFormat = (_input_templateFormat = input.templateFormat) !== null && _input_templateFormat !== void 0 ? _input_templateFormat : _this.templateFormat;
350
+ var _input_validateTemplate;
351
+ _this.validateTemplate = (_input_validateTemplate = input.validateTemplate) !== null && _input_validateTemplate !== void 0 ? _input_validateTemplate : _this.validateTemplate;
352
+ if (_this.validateTemplate) {
353
+ var totalInputVariables = _this.inputVariables;
354
+ if (_this.partialVariables) {
355
+ totalInputVariables = totalInputVariables.concat(Object.keys(_this.partialVariables));
356
+ }
357
+ checkValidTemplate([
358
+ {
359
+ type: "image_url",
360
+ image_url: _this.template
361
+ }
362
+ ], _this.templateFormat, totalInputVariables);
363
+ }
364
+ return _this;
365
+ }
366
+ _create_class$1(ImagePromptTemplate, [
367
+ {
368
+ key: "_getPromptType",
369
+ value: function _getPromptType() {
370
+ return "prompt";
371
+ }
372
+ },
373
+ {
374
+ key: "partial",
375
+ value: /**
376
+ * Partially applies values to the prompt template.
377
+ * @param values The values to be partially applied to the prompt template.
378
+ * @returns A new instance of ImagePromptTemplate with the partially applied values.
379
+ */ function partial(values) {
380
+ var _this = this;
381
+ return _async_to_generator$1(function() {
382
+ var newInputVariables, _this_partialVariables, newPartialVariables, promptDict;
383
+ return _ts_generator$1(this, function(_state) {
384
+ newInputVariables = _this.inputVariables.filter(function(iv) {
385
+ return !(iv in values);
386
+ });
387
+ newPartialVariables = _object_spread$1({}, (_this_partialVariables = _this.partialVariables) !== null && _this_partialVariables !== void 0 ? _this_partialVariables : {}, values);
388
+ promptDict = _object_spread_props$1(_object_spread$1({}, _this), {
389
+ inputVariables: newInputVariables,
390
+ partialVariables: newPartialVariables
391
+ });
392
+ return [
393
+ 2,
394
+ new ImagePromptTemplate(promptDict)
395
+ ];
396
+ });
397
+ })();
398
+ }
399
+ },
400
+ {
401
+ key: "format",
402
+ value: /**
403
+ * Formats the prompt template with the provided values.
404
+ * @param values The values to be used to format the prompt template.
405
+ * @returns A promise that resolves to a string which is the formatted prompt.
406
+ */ function format(values) {
407
+ var _this = this;
408
+ return _async_to_generator$1(function() {
409
+ var formatted, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, _step_value, key, value, url, detail, output;
410
+ return _ts_generator$1(this, function(_state) {
411
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
412
+ formatted = {};
413
+ _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
414
+ try {
415
+ for(_iterator = Object.entries(_this.template)[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
416
+ _step_value = _sliced_to_array(_step.value, 2), key = _step_value[0], value = _step_value[1];
417
+ if (typeof value === "string") {
418
+ formatted[key] = value.replace(/{([^{}]*)}/g, function(match, group) {
419
+ var replacement = values[group];
420
+ return typeof replacement === "string" || typeof replacement === "number" ? String(replacement) : match;
421
+ });
422
+ } else {
423
+ formatted[key] = value;
424
+ }
425
+ }
426
+ } catch (err) {
427
+ _didIteratorError = true;
428
+ _iteratorError = err;
429
+ } finally{
430
+ try {
431
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
432
+ _iterator.return();
433
+ }
434
+ } finally{
435
+ if (_didIteratorError) {
436
+ throw _iteratorError;
437
+ }
438
+ }
439
+ }
440
+ url = values.url || formatted.url;
441
+ detail = values.detail || formatted.detail;
442
+ if (!url) {
443
+ throw new Error("Must provide either an image URL.");
444
+ }
445
+ if (typeof url !== "string") {
446
+ throw new Error("url must be a string.");
447
+ }
448
+ output = {
449
+ url: url
450
+ };
451
+ if (detail) {
452
+ output.detail = detail;
453
+ }
454
+ return [
455
+ 2,
456
+ output
457
+ ];
458
+ });
459
+ })();
460
+ }
461
+ },
462
+ {
463
+ key: "formatPromptValue",
464
+ value: /**
465
+ * Formats the prompt given the input values and returns a formatted
466
+ * prompt value.
467
+ * @param values The input values to format the prompt.
468
+ * @returns A Promise that resolves to a formatted prompt value.
469
+ */ function formatPromptValue(values) {
470
+ var _this = this;
471
+ return _async_to_generator$1(function() {
472
+ var formattedPrompt;
473
+ return _ts_generator$1(this, function(_state) {
474
+ switch(_state.label){
475
+ case 0:
476
+ return [
477
+ 4,
478
+ _this.format(values)
479
+ ];
480
+ case 1:
481
+ formattedPrompt = _state.sent();
482
+ return [
483
+ 2,
484
+ new ImagePromptValue(formattedPrompt)
485
+ ];
486
+ }
487
+ });
488
+ })();
489
+ }
490
+ }
491
+ ], [
492
+ {
493
+ key: "lc_name",
494
+ value: function lc_name() {
495
+ return "ImagePromptTemplate";
496
+ }
497
+ }
498
+ ]);
499
+ return ImagePromptTemplate;
500
+ }(BasePromptTemplate);
501
+
502
+ // Default generic "any" values are for backwards compatibility.
503
+ // Replace with "string" when we are comfortable with a breaking change.
504
+ function _array_like_to_array(arr, len) {
505
+ if (len == null || len > arr.length) len = arr.length;
506
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
507
+ return arr2;
508
+ }
509
+ function _array_without_holes(arr) {
510
+ if (Array.isArray(arr)) return _array_like_to_array(arr);
511
+ }
512
+ function _assert_this_initialized(self) {
513
+ if (self === void 0) {
514
+ throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
515
+ }
516
+ return self;
517
+ }
518
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
519
+ try {
520
+ var info = gen[key](arg);
521
+ var value = info.value;
522
+ } catch (error) {
523
+ reject(error);
524
+ return;
525
+ }
526
+ if (info.done) {
527
+ resolve(value);
528
+ } else {
529
+ Promise.resolve(value).then(_next, _throw);
530
+ }
531
+ }
532
+ function _async_to_generator(fn) {
533
+ return function() {
534
+ var self = this, args = arguments;
535
+ return new Promise(function(resolve, reject) {
536
+ var gen = fn.apply(self, args);
537
+ function _next(value) {
538
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
539
+ }
540
+ function _throw(err) {
541
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
542
+ }
543
+ _next(undefined);
544
+ });
545
+ };
546
+ }
547
+ function _class_call_check(instance, Constructor) {
548
+ if (!(instance instanceof Constructor)) {
549
+ throw new TypeError("Cannot call a class as a function");
550
+ }
551
+ }
552
+ function _defineProperties(target, props) {
553
+ for(var i = 0; i < props.length; i++){
554
+ var descriptor = props[i];
555
+ descriptor.enumerable = descriptor.enumerable || false;
556
+ descriptor.configurable = true;
557
+ if ("value" in descriptor) descriptor.writable = true;
558
+ Object.defineProperty(target, descriptor.key, descriptor);
559
+ }
560
+ }
561
+ function _create_class(Constructor, protoProps, staticProps) {
562
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
563
+ if (staticProps) _defineProperties(Constructor, staticProps);
564
+ return Constructor;
565
+ }
566
+ function _define_property(obj, key, value) {
567
+ if (key in obj) {
568
+ Object.defineProperty(obj, key, {
569
+ value: value,
570
+ enumerable: true,
571
+ configurable: true,
572
+ writable: true
573
+ });
574
+ } else {
575
+ obj[key] = value;
576
+ }
577
+ return obj;
578
+ }
579
+ function _get_prototype_of(o) {
580
+ _get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
581
+ return o.__proto__ || Object.getPrototypeOf(o);
582
+ };
583
+ return _get_prototype_of(o);
584
+ }
585
+ function _inherits(subClass, superClass) {
586
+ if (typeof superClass !== "function" && superClass !== null) {
587
+ throw new TypeError("Super expression must either be null or a function");
588
+ }
589
+ subClass.prototype = Object.create(superClass && superClass.prototype, {
590
+ constructor: {
591
+ value: subClass,
592
+ writable: true,
593
+ configurable: true
594
+ }
595
+ });
596
+ if (superClass) _set_prototype_of(subClass, superClass);
597
+ }
598
+ function _instanceof(left, right) {
599
+ if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
600
+ return !!right[Symbol.hasInstance](left);
601
+ } else {
602
+ return left instanceof right;
603
+ }
604
+ }
605
+ function _iterable_to_array(iter) {
606
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
607
+ }
608
+ function _non_iterable_spread() {
609
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
610
+ }
611
+ function _object_spread(target) {
612
+ for(var i = 1; i < arguments.length; i++){
613
+ var source = arguments[i] != null ? arguments[i] : {};
614
+ var ownKeys = Object.keys(source);
615
+ if (typeof Object.getOwnPropertySymbols === "function") {
616
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
617
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
618
+ }));
619
+ }
620
+ ownKeys.forEach(function(key) {
621
+ _define_property(target, key, source[key]);
622
+ });
623
+ }
624
+ return target;
625
+ }
626
+ function ownKeys(object, enumerableOnly) {
627
+ var keys = Object.keys(object);
628
+ if (Object.getOwnPropertySymbols) {
629
+ var symbols = Object.getOwnPropertySymbols(object);
630
+ if (enumerableOnly) {
631
+ symbols = symbols.filter(function(sym) {
632
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
633
+ });
634
+ }
635
+ keys.push.apply(keys, symbols);
636
+ }
637
+ return keys;
638
+ }
639
+ function _object_spread_props(target, source) {
640
+ source = source != null ? source : {};
641
+ if (Object.getOwnPropertyDescriptors) {
642
+ Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
643
+ } else {
644
+ ownKeys(Object(source)).forEach(function(key) {
645
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
646
+ });
647
+ }
648
+ return target;
649
+ }
650
+ function _possible_constructor_return(self, call) {
651
+ if (call && (_type_of(call) === "object" || typeof call === "function")) {
652
+ return call;
653
+ }
654
+ return _assert_this_initialized(self);
655
+ }
656
+ function _set_prototype_of(o, p) {
657
+ _set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
658
+ o.__proto__ = p;
659
+ return o;
660
+ };
661
+ return _set_prototype_of(o, p);
662
+ }
663
+ function _to_consumable_array(arr) {
664
+ return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
665
+ }
666
+ function _type_of(obj) {
667
+ "@swc/helpers - typeof";
668
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
669
+ }
670
+ function _unsupported_iterable_to_array(o, minLen) {
671
+ if (!o) return;
672
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
673
+ var n = Object.prototype.toString.call(o).slice(8, -1);
674
+ if (n === "Object" && o.constructor) n = o.constructor.name;
675
+ if (n === "Map" || n === "Set") return Array.from(n);
676
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
677
+ }
678
+ function _is_native_reflect_construct() {
679
+ if (typeof Reflect === "undefined" || !Reflect.construct) return false;
680
+ if (Reflect.construct.sham) return false;
681
+ if (typeof Proxy === "function") return true;
682
+ try {
683
+ Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
684
+ return true;
685
+ } catch (e) {
686
+ return false;
687
+ }
688
+ }
689
+ function _create_super(Derived) {
690
+ var hasNativeReflectConstruct = _is_native_reflect_construct();
691
+ return function _createSuperInternal() {
692
+ var Super = _get_prototype_of(Derived), result;
693
+ if (hasNativeReflectConstruct) {
694
+ var NewTarget = _get_prototype_of(this).constructor;
695
+ result = Reflect.construct(Super, arguments, NewTarget);
696
+ } else {
697
+ result = Super.apply(this, arguments);
698
+ }
699
+ return _possible_constructor_return(this, result);
700
+ };
701
+ }
702
+ function _ts_generator(thisArg, body) {
703
+ var f, y, t, g, _ = {
704
+ label: 0,
705
+ sent: function() {
706
+ if (t[0] & 1) throw t[1];
707
+ return t[1];
708
+ },
709
+ trys: [],
710
+ ops: []
711
+ };
712
+ return g = {
713
+ next: verb(0),
714
+ "throw": verb(1),
715
+ "return": verb(2)
716
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
717
+ return this;
718
+ }), g;
719
+ function verb(n) {
720
+ return function(v) {
721
+ return step([
722
+ n,
723
+ v
724
+ ]);
725
+ };
726
+ }
727
+ function step(op) {
728
+ if (f) throw new TypeError("Generator is already executing.");
729
+ while(_)try {
730
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
731
+ if (y = 0, t) op = [
732
+ op[0] & 2,
733
+ t.value
734
+ ];
735
+ switch(op[0]){
736
+ case 0:
737
+ case 1:
738
+ t = op;
739
+ break;
740
+ case 4:
741
+ _.label++;
742
+ return {
743
+ value: op[1],
744
+ done: false
745
+ };
746
+ case 5:
747
+ _.label++;
748
+ y = op[1];
749
+ op = [
750
+ 0
751
+ ];
752
+ continue;
753
+ case 7:
754
+ op = _.ops.pop();
755
+ _.trys.pop();
756
+ continue;
757
+ default:
758
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
759
+ _ = 0;
760
+ continue;
761
+ }
762
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
763
+ _.label = op[1];
764
+ break;
765
+ }
766
+ if (op[0] === 6 && _.label < t[1]) {
767
+ _.label = t[1];
768
+ t = op;
769
+ break;
770
+ }
771
+ if (t && _.label < t[2]) {
772
+ _.label = t[2];
773
+ _.ops.push(op);
774
+ break;
775
+ }
776
+ if (t[2]) _.ops.pop();
777
+ _.trys.pop();
778
+ continue;
779
+ }
780
+ op = body.call(thisArg, _);
781
+ } catch (e) {
782
+ op = [
783
+ 6,
784
+ e
785
+ ];
786
+ y = 0;
787
+ } finally{
788
+ f = t = 0;
789
+ }
790
+ if (op[0] & 5) throw op[1];
791
+ return {
792
+ value: op[0] ? op[1] : void 0,
793
+ done: true
794
+ };
795
+ }
796
+ }
797
+ function _ts_values(o) {
798
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
799
+ if (m) return m.call(o);
800
+ if (o && typeof o.length === "number") return {
801
+ next: function() {
802
+ if (o && i >= o.length) o = void 0;
803
+ return {
804
+ value: o && o[i++],
805
+ done: !o
806
+ };
807
+ }
808
+ };
809
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
810
+ }
811
+ /**
812
+ * Abstract class that serves as a base for creating message prompt
813
+ * templates. It defines how to format messages for different roles in a
814
+ * conversation.
815
+ */ var BaseMessagePromptTemplate = /*#__PURE__*/ function(Runnable) {
816
+ _inherits(BaseMessagePromptTemplate, Runnable);
817
+ var _super = _create_super(BaseMessagePromptTemplate);
818
+ function BaseMessagePromptTemplate() {
819
+ _class_call_check(this, BaseMessagePromptTemplate);
820
+ var _this;
821
+ _this = _super.call.apply(_super, [
822
+ this
823
+ ].concat(Array.prototype.slice.call(arguments)));
824
+ Object.defineProperty(_assert_this_initialized(_this), "lc_namespace", {
825
+ enumerable: true,
826
+ configurable: true,
827
+ writable: true,
828
+ value: [
829
+ "langchain_core",
830
+ "prompts",
831
+ "chat"
832
+ ]
833
+ });
834
+ Object.defineProperty(_assert_this_initialized(_this), "lc_serializable", {
835
+ enumerable: true,
836
+ configurable: true,
837
+ writable: true,
838
+ value: true
839
+ });
840
+ return _this;
841
+ }
842
+ _create_class(BaseMessagePromptTemplate, [
843
+ {
844
+ key: "invoke",
845
+ value: /**
846
+ * Calls the formatMessages method with the provided input and options.
847
+ * @param input Input for the formatMessages method
848
+ * @param options Optional BaseCallbackConfig
849
+ * @returns Formatted output messages
850
+ */ function invoke(input, options) {
851
+ var _this = this;
852
+ return _async_to_generator(function() {
853
+ return _ts_generator(this, function(_state) {
854
+ return [
855
+ 2,
856
+ _this._callWithConfig(function(input) {
857
+ return _this.formatMessages(input);
858
+ }, input, _object_spread_props(_object_spread({}, options), {
859
+ runType: "prompt"
860
+ }))
861
+ ];
862
+ });
863
+ })();
864
+ }
865
+ }
866
+ ]);
867
+ return BaseMessagePromptTemplate;
868
+ }(Runnable);
869
+ /**
870
+ * Abstract class that serves as a base for creating message string prompt
871
+ * templates. It extends the BaseMessagePromptTemplate.
872
+ */ var BaseMessageStringPromptTemplate = /*#__PURE__*/ function(BaseMessagePromptTemplate) {
873
+ _inherits(BaseMessageStringPromptTemplate, BaseMessagePromptTemplate);
874
+ var _super = _create_super(BaseMessageStringPromptTemplate);
875
+ function BaseMessageStringPromptTemplate(fields) {
876
+ _class_call_check(this, BaseMessageStringPromptTemplate);
877
+ var _this;
878
+ if (!("prompt" in fields)) {
879
+ // eslint-disable-next-line no-param-reassign
880
+ fields = {
881
+ prompt: fields
882
+ };
883
+ }
884
+ _this = _super.call(this, fields);
885
+ Object.defineProperty(_assert_this_initialized(_this), "prompt", {
886
+ enumerable: true,
887
+ configurable: true,
888
+ writable: true,
889
+ value: void 0
890
+ });
891
+ _this.prompt = fields.prompt;
892
+ return _this;
893
+ }
894
+ _create_class(BaseMessageStringPromptTemplate, [
895
+ {
896
+ key: "inputVariables",
897
+ get: function get() {
898
+ return this.prompt.inputVariables;
899
+ }
900
+ },
901
+ {
902
+ key: "formatMessages",
903
+ value: function formatMessages(values) {
904
+ var _this = this;
905
+ return _async_to_generator(function() {
906
+ return _ts_generator(this, function(_state) {
907
+ switch(_state.label){
908
+ case 0:
909
+ return [
910
+ 4,
911
+ _this.format(values)
912
+ ];
913
+ case 1:
914
+ return [
915
+ 2,
916
+ [
917
+ _state.sent()
918
+ ]
919
+ ];
920
+ }
921
+ });
922
+ })();
923
+ }
924
+ }
925
+ ]);
926
+ return BaseMessageStringPromptTemplate;
927
+ }(BaseMessagePromptTemplate);
928
+ /**
929
+ * Abstract class that serves as a base for creating chat prompt
930
+ * templates. It extends the BasePromptTemplate.
931
+ */ var BaseChatPromptTemplate = /*#__PURE__*/ function(BasePromptTemplate) {
932
+ _inherits(BaseChatPromptTemplate, BasePromptTemplate);
933
+ var _super = _create_super(BaseChatPromptTemplate);
934
+ function BaseChatPromptTemplate(input) {
935
+ _class_call_check(this, BaseChatPromptTemplate);
936
+ return _super.call(this, input);
937
+ }
938
+ _create_class(BaseChatPromptTemplate, [
939
+ {
940
+ key: "format",
941
+ value: function format(values) {
942
+ var _this = this;
943
+ return _async_to_generator(function() {
944
+ return _ts_generator(this, function(_state) {
945
+ switch(_state.label){
946
+ case 0:
947
+ return [
948
+ 4,
949
+ _this.formatPromptValue(values)
950
+ ];
951
+ case 1:
952
+ return [
953
+ 2,
954
+ _state.sent().toString()
955
+ ];
956
+ }
957
+ });
958
+ })();
959
+ }
960
+ },
961
+ {
962
+ key: "formatPromptValue",
963
+ value: function formatPromptValue(values) {
964
+ var _this = this;
965
+ return _async_to_generator(function() {
966
+ var resultMessages;
967
+ return _ts_generator(this, function(_state) {
968
+ switch(_state.label){
969
+ case 0:
970
+ return [
971
+ 4,
972
+ _this.formatMessages(values)
973
+ ];
974
+ case 1:
975
+ resultMessages = _state.sent();
976
+ return [
977
+ 2,
978
+ new ChatPromptValue(resultMessages)
979
+ ];
980
+ }
981
+ });
982
+ })();
983
+ }
984
+ }
985
+ ]);
986
+ return BaseChatPromptTemplate;
987
+ }(BasePromptTemplate);
988
+ /**
989
+ * Class that represents a chat message prompt template. It extends the
990
+ * BaseMessageStringPromptTemplate.
991
+ */ var ChatMessagePromptTemplate = /*#__PURE__*/ function(BaseMessageStringPromptTemplate) {
992
+ _inherits(ChatMessagePromptTemplate, BaseMessageStringPromptTemplate);
993
+ var _super = _create_super(ChatMessagePromptTemplate);
994
+ function ChatMessagePromptTemplate(fields, role) {
995
+ _class_call_check(this, ChatMessagePromptTemplate);
996
+ var _this;
997
+ if (!("prompt" in fields)) {
998
+ // eslint-disable-next-line no-param-reassign, @typescript-eslint/no-non-null-assertion
999
+ fields = {
1000
+ prompt: fields,
1001
+ role: role
1002
+ };
1003
+ }
1004
+ _this = _super.call(this, fields);
1005
+ Object.defineProperty(_assert_this_initialized(_this), "role", {
1006
+ enumerable: true,
1007
+ configurable: true,
1008
+ writable: true,
1009
+ value: void 0
1010
+ });
1011
+ _this.role = fields.role;
1012
+ return _this;
1013
+ }
1014
+ _create_class(ChatMessagePromptTemplate, [
1015
+ {
1016
+ key: "format",
1017
+ value: function format(values) {
1018
+ var _this = this;
1019
+ return _async_to_generator(function() {
1020
+ var _;
1021
+ return _ts_generator(this, function(_state) {
1022
+ switch(_state.label){
1023
+ case 0:
1024
+ _ = ChatMessage.bind;
1025
+ return [
1026
+ 4,
1027
+ _this.prompt.format(values)
1028
+ ];
1029
+ case 1:
1030
+ return [
1031
+ 2,
1032
+ new (_.apply(ChatMessage, [
1033
+ void 0,
1034
+ _state.sent(),
1035
+ _this.role
1036
+ ]))
1037
+ ];
1038
+ }
1039
+ });
1040
+ })();
1041
+ }
1042
+ }
1043
+ ], [
1044
+ {
1045
+ key: "lc_name",
1046
+ value: function lc_name() {
1047
+ return "ChatMessagePromptTemplate";
1048
+ }
1049
+ },
1050
+ {
1051
+ key: "fromTemplate",
1052
+ value: function fromTemplate(template, role) {
1053
+ return new this(PromptTemplate.fromTemplate(template), role);
1054
+ }
1055
+ }
1056
+ ]);
1057
+ return ChatMessagePromptTemplate;
1058
+ }(BaseMessageStringPromptTemplate);
1059
+ var _StringImageMessagePromptTemplate = /*#__PURE__*/ function(BaseMessagePromptTemplate) {
1060
+ _inherits(_StringImageMessagePromptTemplate, BaseMessagePromptTemplate);
1061
+ var _super = _create_super(_StringImageMessagePromptTemplate);
1062
+ function _StringImageMessagePromptTemplate(/** @TODO When we come up with a better way to type prompt templates, fix this */ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1063
+ fields, additionalOptions) {
1064
+ _class_call_check(this, _StringImageMessagePromptTemplate);
1065
+ var _this;
1066
+ if (!("prompt" in fields)) {
1067
+ // eslint-disable-next-line no-param-reassign
1068
+ fields = {
1069
+ prompt: fields
1070
+ };
1071
+ }
1072
+ _this = _super.call(this, fields);
1073
+ Object.defineProperty(_assert_this_initialized(_this), "lc_namespace", {
1074
+ enumerable: true,
1075
+ configurable: true,
1076
+ writable: true,
1077
+ value: [
1078
+ "langchain_core",
1079
+ "prompts",
1080
+ "chat"
1081
+ ]
1082
+ });
1083
+ Object.defineProperty(_assert_this_initialized(_this), "lc_serializable", {
1084
+ enumerable: true,
1085
+ configurable: true,
1086
+ writable: true,
1087
+ value: true
1088
+ });
1089
+ Object.defineProperty(_assert_this_initialized(_this), "inputVariables", {
1090
+ enumerable: true,
1091
+ configurable: true,
1092
+ writable: true,
1093
+ value: []
1094
+ });
1095
+ Object.defineProperty(_assert_this_initialized(_this), "additionalOptions", {
1096
+ enumerable: true,
1097
+ configurable: true,
1098
+ writable: true,
1099
+ value: {}
1100
+ });
1101
+ Object.defineProperty(_assert_this_initialized(_this), "prompt", {
1102
+ enumerable: true,
1103
+ configurable: true,
1104
+ writable: true,
1105
+ value: void 0
1106
+ });
1107
+ Object.defineProperty(_assert_this_initialized(_this), "messageClass", {
1108
+ enumerable: true,
1109
+ configurable: true,
1110
+ writable: true,
1111
+ value: void 0
1112
+ });
1113
+ // ChatMessage contains role field, others don't.
1114
+ // Because of this, we have a separate class property for ChatMessage.
1115
+ Object.defineProperty(_assert_this_initialized(_this), "chatMessageClass", {
1116
+ enumerable: true,
1117
+ configurable: true,
1118
+ writable: true,
1119
+ value: void 0
1120
+ });
1121
+ _this.prompt = fields.prompt;
1122
+ if (Array.isArray(_this.prompt)) {
1123
+ var inputVariables = [];
1124
+ _this.prompt.forEach(function(prompt) {
1125
+ if ("inputVariables" in prompt) {
1126
+ inputVariables = inputVariables.concat(prompt.inputVariables);
1127
+ }
1128
+ });
1129
+ _this.inputVariables = inputVariables;
1130
+ } else {
1131
+ _this.inputVariables = _this.prompt.inputVariables;
1132
+ }
1133
+ _this.additionalOptions = additionalOptions !== null && additionalOptions !== void 0 ? additionalOptions : _this.additionalOptions;
1134
+ return _this;
1135
+ }
1136
+ _create_class(_StringImageMessagePromptTemplate, [
1137
+ {
1138
+ key: "createMessage",
1139
+ value: function createMessage(content) {
1140
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1141
+ var constructor = this.constructor;
1142
+ if (constructor._messageClass()) {
1143
+ var MsgClass = constructor._messageClass();
1144
+ return new MsgClass({
1145
+ content: content
1146
+ });
1147
+ } else if (constructor.chatMessageClass) {
1148
+ var MsgClass1 = constructor.chatMessageClass();
1149
+ // Assuming ChatMessage constructor also takes a content argument
1150
+ return new MsgClass1({
1151
+ content: content,
1152
+ role: this.getRoleFromMessageClass(MsgClass1.lc_name())
1153
+ });
1154
+ } else {
1155
+ throw new Error("No message class defined");
1156
+ }
1157
+ }
1158
+ },
1159
+ {
1160
+ key: "getRoleFromMessageClass",
1161
+ value: function getRoleFromMessageClass(name) {
1162
+ switch(name){
1163
+ case "HumanMessage":
1164
+ return "human";
1165
+ case "AIMessage":
1166
+ return "ai";
1167
+ case "SystemMessage":
1168
+ return "system";
1169
+ case "ChatMessage":
1170
+ return "chat";
1171
+ default:
1172
+ throw new Error("Invalid message class name");
1173
+ }
1174
+ }
1175
+ },
1176
+ {
1177
+ key: "format",
1178
+ value: function format(input) {
1179
+ var _this = this;
1180
+ return _async_to_generator(function() {
1181
+ var text, content, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, prompt, inputs, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, item, formatted, formatted1, err;
1182
+ return _ts_generator(this, function(_state) {
1183
+ switch(_state.label){
1184
+ case 0:
1185
+ if (!_instanceof(_this.prompt, BaseStringPromptTemplate)) return [
1186
+ 3,
1187
+ 2
1188
+ ];
1189
+ return [
1190
+ 4,
1191
+ _this.prompt.format(input)
1192
+ ];
1193
+ case 1:
1194
+ text = _state.sent();
1195
+ return [
1196
+ 2,
1197
+ _this.createMessage(text)
1198
+ ];
1199
+ case 2:
1200
+ content = [];
1201
+ _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
1202
+ _state.label = 3;
1203
+ case 3:
1204
+ _state.trys.push([
1205
+ 3,
1206
+ 10,
1207
+ 11,
1208
+ 12
1209
+ ]);
1210
+ _iterator = _this.prompt[Symbol.iterator]();
1211
+ _state.label = 4;
1212
+ case 4:
1213
+ if (!!(_iteratorNormalCompletion = (_step = _iterator.next()).done)) return [
1214
+ 3,
1215
+ 9
1216
+ ];
1217
+ prompt = _step.value;
1218
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1219
+ inputs = {};
1220
+ if (!("inputVariables" in prompt)) {
1221
+ throw new Error("Prompt ".concat(prompt, " does not have inputVariables defined."));
1222
+ }
1223
+ _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
1224
+ try {
1225
+ for(_iterator1 = prompt.inputVariables[Symbol.iterator](); !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
1226
+ item = _step1.value;
1227
+ if (!inputs) {
1228
+ inputs = _define_property({}, item, input[item]);
1229
+ }
1230
+ inputs = _object_spread_props(_object_spread({}, inputs), _define_property({}, item, input[item]));
1231
+ }
1232
+ } catch (err) {
1233
+ _didIteratorError1 = true;
1234
+ _iteratorError1 = err;
1235
+ } finally{
1236
+ try {
1237
+ if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
1238
+ _iterator1.return();
1239
+ }
1240
+ } finally{
1241
+ if (_didIteratorError1) {
1242
+ throw _iteratorError1;
1243
+ }
1244
+ }
1245
+ }
1246
+ if (!_instanceof(prompt, BaseStringPromptTemplate)) return [
1247
+ 3,
1248
+ 6
1249
+ ];
1250
+ return [
1251
+ 4,
1252
+ prompt.format(inputs)
1253
+ ];
1254
+ case 5:
1255
+ formatted = _state.sent();
1256
+ content.push({
1257
+ type: "text",
1258
+ text: formatted
1259
+ });
1260
+ return [
1261
+ 3,
1262
+ 8
1263
+ ];
1264
+ case 6:
1265
+ if (!_instanceof(prompt, ImagePromptTemplate)) return [
1266
+ 3,
1267
+ 8
1268
+ ];
1269
+ return [
1270
+ 4,
1271
+ prompt.format(inputs)
1272
+ ];
1273
+ case 7:
1274
+ formatted1 = _state.sent();
1275
+ content.push({
1276
+ type: "image_url",
1277
+ image_url: formatted1
1278
+ });
1279
+ _state.label = 8;
1280
+ case 8:
1281
+ _iteratorNormalCompletion = true;
1282
+ return [
1283
+ 3,
1284
+ 4
1285
+ ];
1286
+ case 9:
1287
+ return [
1288
+ 3,
1289
+ 12
1290
+ ];
1291
+ case 10:
1292
+ err = _state.sent();
1293
+ _didIteratorError = true;
1294
+ _iteratorError = err;
1295
+ return [
1296
+ 3,
1297
+ 12
1298
+ ];
1299
+ case 11:
1300
+ try {
1301
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
1302
+ _iterator.return();
1303
+ }
1304
+ } finally{
1305
+ if (_didIteratorError) {
1306
+ throw _iteratorError;
1307
+ }
1308
+ }
1309
+ return [
1310
+ 7
1311
+ ];
1312
+ case 12:
1313
+ return [
1314
+ 2,
1315
+ _this.createMessage(content)
1316
+ ];
1317
+ case 13:
1318
+ return [
1319
+ 2
1320
+ ];
1321
+ }
1322
+ });
1323
+ })();
1324
+ }
1325
+ },
1326
+ {
1327
+ key: "formatMessages",
1328
+ value: function formatMessages(values) {
1329
+ var _this = this;
1330
+ return _async_to_generator(function() {
1331
+ return _ts_generator(this, function(_state) {
1332
+ switch(_state.label){
1333
+ case 0:
1334
+ return [
1335
+ 4,
1336
+ _this.format(values)
1337
+ ];
1338
+ case 1:
1339
+ return [
1340
+ 2,
1341
+ [
1342
+ _state.sent()
1343
+ ]
1344
+ ];
1345
+ }
1346
+ });
1347
+ })();
1348
+ }
1349
+ }
1350
+ ], [
1351
+ {
1352
+ key: "_messageClass",
1353
+ value: function _messageClass() {
1354
+ throw new Error("Can not invoke _messageClass from inside _StringImageMessagePromptTemplate");
1355
+ }
1356
+ },
1357
+ {
1358
+ key: "fromTemplate",
1359
+ value: function fromTemplate(template, additionalOptions) {
1360
+ if (typeof template === "string") {
1361
+ return new this(PromptTemplate.fromTemplate(template));
1362
+ }
1363
+ var prompt = [];
1364
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
1365
+ try {
1366
+ for(var _iterator = template[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
1367
+ var item = _step.value;
1368
+ if (typeof item === "string" || typeof item === "object" && "text" in item) {
1369
+ var text = "";
1370
+ if (typeof item === "string") {
1371
+ text = item;
1372
+ } else if (typeof item.text === "string") {
1373
+ var _item_text;
1374
+ text = (_item_text = item.text) !== null && _item_text !== void 0 ? _item_text : "";
1375
+ }
1376
+ prompt.push(PromptTemplate.fromTemplate(text));
1377
+ } else if (typeof item === "object" && "image_url" in item) {
1378
+ var _item_image_url;
1379
+ var imgTemplate = (_item_image_url = item.image_url) !== null && _item_image_url !== void 0 ? _item_image_url : "";
1380
+ var imgTemplateObject = void 0;
1381
+ var inputVariables = [];
1382
+ if (typeof imgTemplate === "string") {
1383
+ var parsedTemplate = parseFString(imgTemplate);
1384
+ var variables = parsedTemplate.flatMap(function(item) {
1385
+ return item.type === "variable" ? [
1386
+ item.name
1387
+ ] : [];
1388
+ });
1389
+ var _variables_length;
1390
+ if (((_variables_length = variables === null || variables === void 0 ? void 0 : variables.length) !== null && _variables_length !== void 0 ? _variables_length : 0) > 0) {
1391
+ if (variables.length > 1) {
1392
+ throw new Error("Only one format variable allowed per image template.\nGot: ".concat(variables, "\nFrom: ").concat(imgTemplate));
1393
+ }
1394
+ inputVariables = [
1395
+ variables[0]
1396
+ ];
1397
+ } else {
1398
+ inputVariables = [];
1399
+ }
1400
+ imgTemplate = {
1401
+ url: imgTemplate
1402
+ };
1403
+ imgTemplateObject = new ImagePromptTemplate({
1404
+ template: imgTemplate,
1405
+ inputVariables: inputVariables
1406
+ });
1407
+ } else if (typeof imgTemplate === "object") {
1408
+ if ("url" in imgTemplate) {
1409
+ var parsedTemplate1 = parseFString(imgTemplate.url);
1410
+ inputVariables = parsedTemplate1.flatMap(function(item) {
1411
+ return item.type === "variable" ? [
1412
+ item.name
1413
+ ] : [];
1414
+ });
1415
+ } else {
1416
+ inputVariables = [];
1417
+ }
1418
+ imgTemplateObject = new ImagePromptTemplate({
1419
+ template: imgTemplate,
1420
+ inputVariables: inputVariables
1421
+ });
1422
+ } else {
1423
+ throw new Error("Invalid image template");
1424
+ }
1425
+ prompt.push(imgTemplateObject);
1426
+ }
1427
+ }
1428
+ } catch (err) {
1429
+ _didIteratorError = true;
1430
+ _iteratorError = err;
1431
+ } finally{
1432
+ try {
1433
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
1434
+ _iterator.return();
1435
+ }
1436
+ } finally{
1437
+ if (_didIteratorError) {
1438
+ throw _iteratorError;
1439
+ }
1440
+ }
1441
+ }
1442
+ return new this({
1443
+ prompt: prompt,
1444
+ additionalOptions: additionalOptions
1445
+ });
1446
+ }
1447
+ }
1448
+ ]);
1449
+ return _StringImageMessagePromptTemplate;
1450
+ }(BaseMessagePromptTemplate);
1451
+ /**
1452
+ * Class that represents a human message prompt template. It extends the
1453
+ * BaseMessageStringPromptTemplate.
1454
+ * @example
1455
+ * ```typescript
1456
+ * const message = HumanMessagePromptTemplate.fromTemplate("{text}");
1457
+ * const formatted = await message.format({ text: "Hello world!" });
1458
+ *
1459
+ * const chatPrompt = ChatPromptTemplate.fromMessages([message]);
1460
+ * const formattedChatPrompt = await chatPrompt.invoke({
1461
+ * text: "Hello world!",
1462
+ * });
1463
+ * ```
1464
+ */ var HumanMessagePromptTemplate = /*#__PURE__*/ function(_StringImageMessagePromptTemplate) {
1465
+ _inherits(HumanMessagePromptTemplate, _StringImageMessagePromptTemplate);
1466
+ var _super = _create_super(HumanMessagePromptTemplate);
1467
+ function HumanMessagePromptTemplate() {
1468
+ _class_call_check(this, HumanMessagePromptTemplate);
1469
+ return _super.apply(this, arguments);
1470
+ }
1471
+ _create_class(HumanMessagePromptTemplate, null, [
1472
+ {
1473
+ key: "_messageClass",
1474
+ value: function _messageClass() {
1475
+ return HumanMessage;
1476
+ }
1477
+ },
1478
+ {
1479
+ key: "lc_name",
1480
+ value: function lc_name() {
1481
+ return "HumanMessagePromptTemplate";
1482
+ }
1483
+ }
1484
+ ]);
1485
+ return HumanMessagePromptTemplate;
1486
+ }(_StringImageMessagePromptTemplate);
1487
+ /**
1488
+ * Class that represents an AI message prompt template. It extends the
1489
+ * BaseMessageStringPromptTemplate.
1490
+ */ var AIMessagePromptTemplate = /*#__PURE__*/ function(_StringImageMessagePromptTemplate) {
1491
+ _inherits(AIMessagePromptTemplate, _StringImageMessagePromptTemplate);
1492
+ var _super = _create_super(AIMessagePromptTemplate);
1493
+ function AIMessagePromptTemplate() {
1494
+ _class_call_check(this, AIMessagePromptTemplate);
1495
+ return _super.apply(this, arguments);
1496
+ }
1497
+ _create_class(AIMessagePromptTemplate, null, [
1498
+ {
1499
+ key: "_messageClass",
1500
+ value: function _messageClass() {
1501
+ return AIMessage;
1502
+ }
1503
+ },
1504
+ {
1505
+ key: "lc_name",
1506
+ value: function lc_name() {
1507
+ return "AIMessagePromptTemplate";
1508
+ }
1509
+ }
1510
+ ]);
1511
+ return AIMessagePromptTemplate;
1512
+ }(_StringImageMessagePromptTemplate);
1513
+ /**
1514
+ * Class that represents a system message prompt template. It extends the
1515
+ * BaseMessageStringPromptTemplate.
1516
+ * @example
1517
+ * ```typescript
1518
+ * const message = SystemMessagePromptTemplate.fromTemplate("{text}");
1519
+ * const formatted = await message.format({ text: "Hello world!" });
1520
+ *
1521
+ * const chatPrompt = ChatPromptTemplate.fromMessages([message]);
1522
+ * const formattedChatPrompt = await chatPrompt.invoke({
1523
+ * text: "Hello world!",
1524
+ * });
1525
+ * ```
1526
+ */ var SystemMessagePromptTemplate = /*#__PURE__*/ function(_StringImageMessagePromptTemplate) {
1527
+ _inherits(SystemMessagePromptTemplate, _StringImageMessagePromptTemplate);
1528
+ var _super = _create_super(SystemMessagePromptTemplate);
1529
+ function SystemMessagePromptTemplate() {
1530
+ _class_call_check(this, SystemMessagePromptTemplate);
1531
+ return _super.apply(this, arguments);
1532
+ }
1533
+ _create_class(SystemMessagePromptTemplate, null, [
1534
+ {
1535
+ key: "_messageClass",
1536
+ value: function _messageClass() {
1537
+ return SystemMessage;
1538
+ }
1539
+ },
1540
+ {
1541
+ key: "lc_name",
1542
+ value: function lc_name() {
1543
+ return "SystemMessagePromptTemplate";
1544
+ }
1545
+ }
1546
+ ]);
1547
+ return SystemMessagePromptTemplate;
1548
+ }(_StringImageMessagePromptTemplate);
1549
+ function _isBaseMessagePromptTemplate(baseMessagePromptTemplateLike) {
1550
+ return typeof baseMessagePromptTemplateLike.formatMessages === "function";
1551
+ }
1552
+ function _coerceMessagePromptTemplateLike(messagePromptTemplateLike) {
1553
+ if (_isBaseMessagePromptTemplate(messagePromptTemplateLike) || isBaseMessage(messagePromptTemplateLike)) {
1554
+ return messagePromptTemplateLike;
1555
+ }
1556
+ var message = coerceMessageLikeToMessage(messagePromptTemplateLike);
1557
+ if (message._getType() === "human") {
1558
+ return HumanMessagePromptTemplate.fromTemplate(message.content);
1559
+ } else if (message._getType() === "ai") {
1560
+ return AIMessagePromptTemplate.fromTemplate(message.content);
1561
+ } else if (message._getType() === "system") {
1562
+ return SystemMessagePromptTemplate.fromTemplate(message.content);
1563
+ } else if (ChatMessage.isInstance(message)) {
1564
+ return ChatMessagePromptTemplate.fromTemplate(message.content, message.role);
1565
+ } else {
1566
+ throw new Error('Could not coerce message prompt template from input. Received message type: "'.concat(message._getType(), '".'));
1567
+ }
1568
+ }
1569
+ function isMessagesPlaceholder(x) {
1570
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1571
+ return x.constructor.lc_name() === "MessagesPlaceholder";
1572
+ }
1573
+ /**
1574
+ * Class that represents a chat prompt. It extends the
1575
+ * BaseChatPromptTemplate and uses an array of BaseMessagePromptTemplate
1576
+ * instances to format a series of messages for a conversation.
1577
+ * @example
1578
+ * ```typescript
1579
+ * const message = SystemMessagePromptTemplate.fromTemplate("{text}");
1580
+ * const chatPrompt = ChatPromptTemplate.fromMessages([
1581
+ * ["ai", "You are a helpful assistant."],
1582
+ * message,
1583
+ * ]);
1584
+ * const formattedChatPrompt = await chatPrompt.invoke({
1585
+ * text: "Hello world!",
1586
+ * });
1587
+ * ```
1588
+ */ var ChatPromptTemplate = /*#__PURE__*/ function(BaseChatPromptTemplate) {
1589
+ _inherits(ChatPromptTemplate, BaseChatPromptTemplate);
1590
+ var _super = _create_super(ChatPromptTemplate);
1591
+ function ChatPromptTemplate(input) {
1592
+ _class_call_check(this, ChatPromptTemplate);
1593
+ var _this;
1594
+ _this = _super.call(this, input);
1595
+ Object.defineProperty(_assert_this_initialized(_this), "promptMessages", {
1596
+ enumerable: true,
1597
+ configurable: true,
1598
+ writable: true,
1599
+ value: void 0
1600
+ });
1601
+ Object.defineProperty(_assert_this_initialized(_this), "validateTemplate", {
1602
+ enumerable: true,
1603
+ configurable: true,
1604
+ writable: true,
1605
+ value: true
1606
+ });
1607
+ Object.assign(_assert_this_initialized(_this), input);
1608
+ if (_this.validateTemplate) {
1609
+ var inputVariablesMessages = new Set();
1610
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
1611
+ try {
1612
+ for(var _iterator = _this.promptMessages[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
1613
+ var promptMessage = _step.value;
1614
+ // eslint-disable-next-line no-instanceof/no-instanceof
1615
+ if (_instanceof(promptMessage, BaseMessage)) continue;
1616
+ var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
1617
+ try {
1618
+ for(var _iterator1 = promptMessage.inputVariables[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
1619
+ var inputVariable = _step1.value;
1620
+ inputVariablesMessages.add(inputVariable);
1621
+ }
1622
+ } catch (err) {
1623
+ _didIteratorError1 = true;
1624
+ _iteratorError1 = err;
1625
+ } finally{
1626
+ try {
1627
+ if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
1628
+ _iterator1.return();
1629
+ }
1630
+ } finally{
1631
+ if (_didIteratorError1) {
1632
+ throw _iteratorError1;
1633
+ }
1634
+ }
1635
+ }
1636
+ }
1637
+ } catch (err) {
1638
+ _didIteratorError = true;
1639
+ _iteratorError = err;
1640
+ } finally{
1641
+ try {
1642
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
1643
+ _iterator.return();
1644
+ }
1645
+ } finally{
1646
+ if (_didIteratorError) {
1647
+ throw _iteratorError;
1648
+ }
1649
+ }
1650
+ }
1651
+ var totalInputVariables = _this.inputVariables;
1652
+ var inputVariablesInstance = new Set(_this.partialVariables ? totalInputVariables.concat(Object.keys(_this.partialVariables)) : totalInputVariables);
1653
+ var difference = new Set(_to_consumable_array(inputVariablesInstance).filter(function(x) {
1654
+ return !inputVariablesMessages.has(x);
1655
+ }));
1656
+ if (difference.size > 0) {
1657
+ throw new Error("Input variables `".concat(_to_consumable_array(difference), "` are not used in any of the prompt messages."));
1658
+ }
1659
+ var otherDifference = new Set(_to_consumable_array(inputVariablesMessages).filter(function(x) {
1660
+ return !inputVariablesInstance.has(x);
1661
+ }));
1662
+ if (otherDifference.size > 0) {
1663
+ throw new Error("Input variables `".concat(_to_consumable_array(otherDifference), "` are used in prompt messages but not in the prompt template."));
1664
+ }
1665
+ }
1666
+ return _this;
1667
+ }
1668
+ _create_class(ChatPromptTemplate, [
1669
+ {
1670
+ key: "lc_aliases",
1671
+ get: function get() {
1672
+ return {
1673
+ promptMessages: "messages"
1674
+ };
1675
+ }
1676
+ },
1677
+ {
1678
+ key: "_getPromptType",
1679
+ value: function _getPromptType() {
1680
+ return "chat";
1681
+ }
1682
+ },
1683
+ {
1684
+ key: "_parseImagePrompts",
1685
+ value: function _parseImagePrompts(message, inputValues) {
1686
+ return _async_to_generator(function() {
1687
+ var formattedMessageContent;
1688
+ return _ts_generator(this, function(_state) {
1689
+ switch(_state.label){
1690
+ case 0:
1691
+ if (typeof message.content === "string") {
1692
+ return [
1693
+ 2,
1694
+ message
1695
+ ];
1696
+ }
1697
+ return [
1698
+ 4,
1699
+ Promise.all(message.content.map(function() {
1700
+ var _ref = _async_to_generator(function(item) {
1701
+ var imageUrl, promptTemplatePlaceholder, formattedUrl;
1702
+ return _ts_generator(this, function(_state) {
1703
+ switch(_state.label){
1704
+ case 0:
1705
+ if (item.type !== "image_url") {
1706
+ return [
1707
+ 2,
1708
+ item
1709
+ ];
1710
+ }
1711
+ imageUrl = "";
1712
+ if (typeof item.image_url === "string") {
1713
+ imageUrl = item.image_url;
1714
+ } else {
1715
+ imageUrl = item.image_url.url;
1716
+ }
1717
+ promptTemplatePlaceholder = PromptTemplate.fromTemplate(imageUrl);
1718
+ return [
1719
+ 4,
1720
+ promptTemplatePlaceholder.format(inputValues)
1721
+ ];
1722
+ case 1:
1723
+ formattedUrl = _state.sent();
1724
+ if (typeof item.image_url !== "string" && "url" in item.image_url) {
1725
+ // eslint-disable-next-line no-param-reassign
1726
+ item.image_url.url = formattedUrl;
1727
+ } else {
1728
+ // eslint-disable-next-line no-param-reassign
1729
+ item.image_url = formattedUrl;
1730
+ }
1731
+ return [
1732
+ 2,
1733
+ item
1734
+ ];
1735
+ }
1736
+ });
1737
+ });
1738
+ return function(item) {
1739
+ return _ref.apply(this, arguments);
1740
+ };
1741
+ }()))
1742
+ ];
1743
+ case 1:
1744
+ formattedMessageContent = _state.sent();
1745
+ // eslint-disable-next-line no-param-reassign
1746
+ message.content = formattedMessageContent;
1747
+ return [
1748
+ 2,
1749
+ message
1750
+ ];
1751
+ }
1752
+ });
1753
+ })();
1754
+ }
1755
+ },
1756
+ {
1757
+ key: "formatMessages",
1758
+ value: function formatMessages(values) {
1759
+ var _this = this;
1760
+ return _async_to_generator(function() {
1761
+ var allValues, resultMessages, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _loop, _iterator, _step, err;
1762
+ return _ts_generator(this, function(_state) {
1763
+ switch(_state.label){
1764
+ case 0:
1765
+ return [
1766
+ 4,
1767
+ _this.mergePartialAndUserVariables(values)
1768
+ ];
1769
+ case 1:
1770
+ allValues = _state.sent();
1771
+ resultMessages = [];
1772
+ _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
1773
+ _state.label = 2;
1774
+ case 2:
1775
+ _state.trys.push([
1776
+ 2,
1777
+ 7,
1778
+ 8,
1779
+ 9
1780
+ ]);
1781
+ _loop = function() {
1782
+ var promptMessage, _, inputValues, message;
1783
+ return _ts_generator(this, function(_state) {
1784
+ switch(_state.label){
1785
+ case 0:
1786
+ promptMessage = _step.value;
1787
+ if (!_instanceof(promptMessage, BaseMessage)) return [
1788
+ 3,
1789
+ 2
1790
+ ];
1791
+ _ = resultMessages.push;
1792
+ return [
1793
+ 4,
1794
+ _this._parseImagePrompts(promptMessage, allValues)
1795
+ ];
1796
+ case 1:
1797
+ _.apply(resultMessages, [
1798
+ _state.sent()
1799
+ ]);
1800
+ return [
1801
+ 3,
1802
+ 4
1803
+ ];
1804
+ case 2:
1805
+ inputValues = promptMessage.inputVariables.reduce(function(acc, inputVariable) {
1806
+ if (!(inputVariable in allValues) && !(isMessagesPlaceholder(promptMessage) && promptMessage.optional)) {
1807
+ throw new Error("Missing value for input variable `".concat(inputVariable.toString(), "`"));
1808
+ }
1809
+ acc[inputVariable] = allValues[inputVariable];
1810
+ return acc;
1811
+ }, {});
1812
+ return [
1813
+ 4,
1814
+ promptMessage.formatMessages(inputValues)
1815
+ ];
1816
+ case 3:
1817
+ message = _state.sent();
1818
+ resultMessages = resultMessages.concat(message);
1819
+ _state.label = 4;
1820
+ case 4:
1821
+ return [
1822
+ 2
1823
+ ];
1824
+ }
1825
+ });
1826
+ };
1827
+ _iterator = _this.promptMessages[Symbol.iterator]();
1828
+ _state.label = 3;
1829
+ case 3:
1830
+ if (!!(_iteratorNormalCompletion = (_step = _iterator.next()).done)) return [
1831
+ 3,
1832
+ 6
1833
+ ];
1834
+ return [
1835
+ 5,
1836
+ _ts_values(_loop())
1837
+ ];
1838
+ case 4:
1839
+ _state.sent();
1840
+ _state.label = 5;
1841
+ case 5:
1842
+ _iteratorNormalCompletion = true;
1843
+ return [
1844
+ 3,
1845
+ 3
1846
+ ];
1847
+ case 6:
1848
+ return [
1849
+ 3,
1850
+ 9
1851
+ ];
1852
+ case 7:
1853
+ err = _state.sent();
1854
+ _didIteratorError = true;
1855
+ _iteratorError = err;
1856
+ return [
1857
+ 3,
1858
+ 9
1859
+ ];
1860
+ case 8:
1861
+ try {
1862
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
1863
+ _iterator.return();
1864
+ }
1865
+ } finally{
1866
+ if (_didIteratorError) {
1867
+ throw _iteratorError;
1868
+ }
1869
+ }
1870
+ return [
1871
+ 7
1872
+ ];
1873
+ case 9:
1874
+ return [
1875
+ 2,
1876
+ resultMessages
1877
+ ];
1878
+ }
1879
+ });
1880
+ })();
1881
+ }
1882
+ },
1883
+ {
1884
+ key: "partial",
1885
+ value: function partial(values) {
1886
+ var _this = this;
1887
+ return _async_to_generator(function() {
1888
+ var newInputVariables, _this_partialVariables, newPartialVariables, promptDict;
1889
+ return _ts_generator(this, function(_state) {
1890
+ // This is implemented in a way it doesn't require making
1891
+ // BaseMessagePromptTemplate aware of .partial()
1892
+ newInputVariables = _this.inputVariables.filter(function(iv) {
1893
+ return !(iv in values);
1894
+ });
1895
+ newPartialVariables = _object_spread({}, (_this_partialVariables = _this.partialVariables) !== null && _this_partialVariables !== void 0 ? _this_partialVariables : {}, values);
1896
+ promptDict = _object_spread_props(_object_spread({}, _this), {
1897
+ inputVariables: newInputVariables,
1898
+ partialVariables: newPartialVariables
1899
+ });
1900
+ return [
1901
+ 2,
1902
+ new ChatPromptTemplate(promptDict)
1903
+ ];
1904
+ });
1905
+ })();
1906
+ }
1907
+ }
1908
+ ], [
1909
+ {
1910
+ key: "lc_name",
1911
+ value: function lc_name() {
1912
+ return "ChatPromptTemplate";
1913
+ }
1914
+ },
1915
+ {
1916
+ key: "fromTemplate",
1917
+ value: /**
1918
+ * Load prompt template from a template f-string
1919
+ */ function fromTemplate(template) {
1920
+ var prompt = PromptTemplate.fromTemplate(template);
1921
+ var humanTemplate = new HumanMessagePromptTemplate({
1922
+ prompt: prompt
1923
+ });
1924
+ return this.fromMessages([
1925
+ humanTemplate
1926
+ ]);
1927
+ }
1928
+ },
1929
+ {
1930
+ key: "fromMessages",
1931
+ value: /**
1932
+ * Create a chat model-specific prompt from individual chat messages
1933
+ * or message-like tuples.
1934
+ * @param promptMessages Messages to be passed to the chat model
1935
+ * @returns A new ChatPromptTemplate
1936
+ */ function fromMessages(promptMessages, extra) {
1937
+ var flattenedMessages = promptMessages.reduce(function(acc, promptMessage) {
1938
+ return acc.concat(// eslint-disable-next-line no-instanceof/no-instanceof
1939
+ _instanceof(promptMessage, ChatPromptTemplate) ? promptMessage.promptMessages : [
1940
+ _coerceMessagePromptTemplateLike(promptMessage)
1941
+ ]);
1942
+ }, []);
1943
+ var flattenedPartialVariables = promptMessages.reduce(function(acc, promptMessage) {
1944
+ return(// eslint-disable-next-line no-instanceof/no-instanceof
1945
+ _instanceof(promptMessage, ChatPromptTemplate) ? Object.assign(acc, promptMessage.partialVariables) : acc);
1946
+ }, Object.create(null));
1947
+ var inputVariables = new Set();
1948
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
1949
+ try {
1950
+ for(var _iterator = flattenedMessages[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
1951
+ var promptMessage = _step.value;
1952
+ // eslint-disable-next-line no-instanceof/no-instanceof
1953
+ if (_instanceof(promptMessage, BaseMessage)) continue;
1954
+ var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
1955
+ try {
1956
+ for(var _iterator1 = promptMessage.inputVariables[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
1957
+ var inputVariable = _step1.value;
1958
+ if (inputVariable in flattenedPartialVariables) {
1959
+ continue;
1960
+ }
1961
+ inputVariables.add(inputVariable);
1962
+ }
1963
+ } catch (err) {
1964
+ _didIteratorError1 = true;
1965
+ _iteratorError1 = err;
1966
+ } finally{
1967
+ try {
1968
+ if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
1969
+ _iterator1.return();
1970
+ }
1971
+ } finally{
1972
+ if (_didIteratorError1) {
1973
+ throw _iteratorError1;
1974
+ }
1975
+ }
1976
+ }
1977
+ }
1978
+ } catch (err) {
1979
+ _didIteratorError = true;
1980
+ _iteratorError = err;
1981
+ } finally{
1982
+ try {
1983
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
1984
+ _iterator.return();
1985
+ }
1986
+ } finally{
1987
+ if (_didIteratorError) {
1988
+ throw _iteratorError;
1989
+ }
1990
+ }
1991
+ }
1992
+ return new this(_object_spread_props(_object_spread({}, extra), {
1993
+ inputVariables: _to_consumable_array(inputVariables),
1994
+ promptMessages: flattenedMessages,
1995
+ partialVariables: flattenedPartialVariables
1996
+ }));
1997
+ }
1998
+ },
1999
+ {
2000
+ key: "fromPromptMessages",
2001
+ value: /** @deprecated Renamed to .fromMessages */ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2002
+ function fromPromptMessages(promptMessages) {
2003
+ return this.fromMessages(promptMessages);
2004
+ }
2005
+ }
2006
+ ]);
2007
+ return ChatPromptTemplate;
2008
+ }(BaseChatPromptTemplate);
2009
+
2010
+ export { BaseChatPromptTemplate as B, ChatPromptTemplate as C, HumanMessagePromptTemplate as H, SystemMessagePromptTemplate as S };