@digipair/skill-llm 0.21.2 → 0.21.7

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 (5) hide show
  1. package/chat.cjs.js +120 -36
  2. package/chat.esm.js +121 -37
  3. package/index.cjs2.js +38715 -55949
  4. package/index.esm2.js +38715 -55949
  5. package/package.json +1 -1
package/chat.cjs.js CHANGED
@@ -27,6 +27,35 @@ function _create_class$2(Constructor, protoProps, staticProps) {
27
27
  if (staticProps) _defineProperties$2(Constructor, staticProps);
28
28
  return Constructor;
29
29
  }
30
+ function _define_property$2(obj, key, value) {
31
+ if (key in obj) {
32
+ Object.defineProperty(obj, key, {
33
+ value: value,
34
+ enumerable: true,
35
+ configurable: true,
36
+ writable: true
37
+ });
38
+ } else {
39
+ obj[key] = value;
40
+ }
41
+ return obj;
42
+ }
43
+ function _get(target, property, receiver) {
44
+ if (typeof Reflect !== "undefined" && Reflect.get) {
45
+ _get = Reflect.get;
46
+ } else {
47
+ _get = function get(target, property, receiver) {
48
+ var base = _super_prop_base(target, property);
49
+ if (!base) return;
50
+ var desc = Object.getOwnPropertyDescriptor(base, property);
51
+ if (desc.get) {
52
+ return desc.get.call(receiver || target);
53
+ }
54
+ return desc.value;
55
+ };
56
+ }
57
+ return _get(target, property, receiver || target);
58
+ }
30
59
  function _get_prototype_of$2(o) {
31
60
  _get_prototype_of$2 = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
32
61
  return o.__proto__ || Object.getPrototypeOf(o);
@@ -46,6 +75,45 @@ function _inherits$2(subClass, superClass) {
46
75
  });
47
76
  if (superClass) _set_prototype_of$2(subClass, superClass);
48
77
  }
78
+ function _object_spread$2(target) {
79
+ for(var i = 1; i < arguments.length; i++){
80
+ var source = arguments[i] != null ? arguments[i] : {};
81
+ var ownKeys = Object.keys(source);
82
+ if (typeof Object.getOwnPropertySymbols === "function") {
83
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
84
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
85
+ }));
86
+ }
87
+ ownKeys.forEach(function(key) {
88
+ _define_property$2(target, key, source[key]);
89
+ });
90
+ }
91
+ return target;
92
+ }
93
+ function ownKeys$2(object, enumerableOnly) {
94
+ var keys = Object.keys(object);
95
+ if (Object.getOwnPropertySymbols) {
96
+ var symbols = Object.getOwnPropertySymbols(object);
97
+ if (enumerableOnly) {
98
+ symbols = symbols.filter(function(sym) {
99
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
100
+ });
101
+ }
102
+ keys.push.apply(keys, symbols);
103
+ }
104
+ return keys;
105
+ }
106
+ function _object_spread_props$2(target, source) {
107
+ source = source != null ? source : {};
108
+ if (Object.getOwnPropertyDescriptors) {
109
+ Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
110
+ } else {
111
+ ownKeys$2(Object(source)).forEach(function(key) {
112
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
113
+ });
114
+ }
115
+ return target;
116
+ }
49
117
  function _possible_constructor_return$2(self, call) {
50
118
  if (call && (_type_of$2(call) === "object" || typeof call === "function")) {
51
119
  return call;
@@ -59,6 +127,13 @@ function _set_prototype_of$2(o, p) {
59
127
  };
60
128
  return _set_prototype_of$2(o, p);
61
129
  }
130
+ function _super_prop_base(object, property) {
131
+ while(!Object.prototype.hasOwnProperty.call(object, property)){
132
+ object = _get_prototype_of$2(object);
133
+ if (object === null) break;
134
+ }
135
+ return object;
136
+ }
62
137
  function _type_of$2(obj) {
63
138
  "@swc/helpers - typeof";
64
139
  return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
@@ -118,6 +193,14 @@ function _create_super$2(Derived) {
118
193
  value: function _getType() {
119
194
  return "generic";
120
195
  }
196
+ },
197
+ {
198
+ key: "_printableFields",
199
+ get: function get() {
200
+ return _object_spread_props$2(_object_spread$2({}, _get(_get_prototype_of$2(ChatMessage.prototype), "_printableFields", this)), {
201
+ role: this.role
202
+ });
203
+ }
121
204
  }
122
205
  ], [
123
206
  {
@@ -557,10 +640,7 @@ function _ts_generator$1(thisArg, body) {
557
640
  for(_iterator = Object.entries(_this.template)[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
558
641
  _step_value = _sliced_to_array(_step.value, 2), key = _step_value[0], value = _step_value[1];
559
642
  if (typeof value === "string") {
560
- formatted[key] = value.replace(/{([^{}]*)}/g, function(match, group) {
561
- var replacement = values[group];
562
- return typeof replacement === "string" || typeof replacement === "number" ? String(replacement) : match;
563
- });
643
+ formatted[key] = index.renderTemplate(value, _this.templateFormat, values);
564
644
  } else {
565
645
  formatted[key] = value;
566
646
  }
@@ -1050,44 +1130,46 @@ function _ts_values(o) {
1050
1130
  ];
1051
1131
  }
1052
1132
  },
1053
- {
1054
- key: "validateInputOrThrow",
1055
- value: function validateInputOrThrow(input, variableName) {
1056
- if (this.optional && !input) {
1057
- return false;
1058
- } else if (!input) {
1059
- var error = new Error('Error: Field "'.concat(variableName, '" in prompt uses a MessagesPlaceholder, which expects an array of BaseMessages as an input value. Received: undefined'));
1060
- error.name = "InputFormatError";
1061
- throw error;
1062
- }
1063
- var isInputBaseMessage = false;
1064
- if (Array.isArray(input)) {
1065
- isInputBaseMessage = input.every(function(message) {
1066
- return index.isBaseMessage(message);
1067
- });
1068
- } else {
1069
- isInputBaseMessage = index.isBaseMessage(input);
1070
- }
1071
- if (!isInputBaseMessage) {
1072
- var readableInput = typeof input === "string" ? input : JSON.stringify(input, null, 2);
1073
- var error1 = new Error('Error: Field "'.concat(variableName, '" in prompt uses a MessagesPlaceholder, which expects an array of BaseMessages as an input value. Received: ').concat(readableInput));
1074
- error1.name = "InputFormatError";
1075
- throw error1;
1076
- }
1077
- return true;
1078
- }
1079
- },
1080
1133
  {
1081
1134
  key: "formatMessages",
1082
1135
  value: function formatMessages(values) {
1083
1136
  var _this = this;
1084
1137
  return _async_to_generator(function() {
1085
- var _values_this_variableName;
1138
+ var input, error, formattedMessages, readableInput, error1;
1086
1139
  return _ts_generator(this, function(_state) {
1087
- _this.validateInputOrThrow(values[_this.variableName], _this.variableName);
1140
+ input = values[_this.variableName];
1141
+ if (_this.optional && !input) {
1142
+ return [
1143
+ 2,
1144
+ []
1145
+ ];
1146
+ } else if (!input) {
1147
+ error = new Error('Field "'.concat(_this.variableName, '" in prompt uses a MessagesPlaceholder, which expects an array of BaseMessages as an input value. Received: undefined'));
1148
+ error.name = "InputFormatError";
1149
+ throw error;
1150
+ }
1151
+ try {
1152
+ if (Array.isArray(input)) {
1153
+ formattedMessages = input.map(index.coerceMessageLikeToMessage);
1154
+ } else {
1155
+ formattedMessages = [
1156
+ index.coerceMessageLikeToMessage(input)
1157
+ ];
1158
+ }
1159
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1160
+ } catch (e) {
1161
+ readableInput = typeof input === "string" ? input : JSON.stringify(input, null, 2);
1162
+ error1 = new Error([
1163
+ 'Field "'.concat(_this.variableName, '" in prompt uses a MessagesPlaceholder, which expects an array of BaseMessages or coerceable values as input.'),
1164
+ "Received value: ".concat(readableInput),
1165
+ "Additional message: ".concat(e.message)
1166
+ ].join("\n\n"));
1167
+ error1.name = "InputFormatError";
1168
+ throw error1;
1169
+ }
1088
1170
  return [
1089
1171
  2,
1090
- (_values_this_variableName = values[_this.variableName]) !== null && _values_this_variableName !== void 0 ? _values_this_variableName : []
1172
+ formattedMessages
1091
1173
  ];
1092
1174
  });
1093
1175
  })();
@@ -1646,7 +1728,8 @@ var _StringImageMessagePromptTemplate = /*#__PURE__*/ function(BaseMessagePrompt
1646
1728
  };
1647
1729
  imgTemplateObject = new ImagePromptTemplate({
1648
1730
  template: imgTemplate,
1649
- inputVariables: inputVariables
1731
+ inputVariables: inputVariables,
1732
+ templateFormat: additionalOptions === null || additionalOptions === void 0 ? void 0 : additionalOptions.templateFormat
1650
1733
  });
1651
1734
  } else if (typeof imgTemplate === "object") {
1652
1735
  if ("url" in imgTemplate) {
@@ -1666,7 +1749,8 @@ var _StringImageMessagePromptTemplate = /*#__PURE__*/ function(BaseMessagePrompt
1666
1749
  }
1667
1750
  imgTemplateObject = new ImagePromptTemplate({
1668
1751
  template: imgTemplate,
1669
- inputVariables: inputVariables
1752
+ inputVariables: inputVariables,
1753
+ templateFormat: additionalOptions === null || additionalOptions === void 0 ? void 0 : additionalOptions.templateFormat
1670
1754
  });
1671
1755
  } else {
1672
1756
  throw new Error("Invalid image template");
package/chat.esm.js CHANGED
@@ -1,4 +1,4 @@
1
- import { a as BaseMessage, c as checkValidTemplate, b as BasePromptTemplate, I as ImagePromptValue, P as PromptTemplate, H as HumanMessage, S as SystemMessage, i as isBaseMessage, d as coerceMessageLikeToMessage, C as ChatPromptValue, p as parseMustache, e as parseFString, B as BaseStringPromptTemplate, A as AIMessage, R as Runnable } from './index.esm2.js';
1
+ import { a as BaseMessage, c as checkValidTemplate, b as BasePromptTemplate, r as renderTemplate, I as ImagePromptValue, P as PromptTemplate, H as HumanMessage, S as SystemMessage, i as isBaseMessage, d as coerceMessageLikeToMessage, C as ChatPromptValue, p as parseMustache, e as parseFString, B as BaseStringPromptTemplate, A as AIMessage, R as Runnable } from './index.esm2.js';
2
2
 
3
3
  function _assert_this_initialized$2(self) {
4
4
  if (self === void 0) {
@@ -25,6 +25,35 @@ function _create_class$2(Constructor, protoProps, staticProps) {
25
25
  if (staticProps) _defineProperties$2(Constructor, staticProps);
26
26
  return Constructor;
27
27
  }
28
+ function _define_property$2(obj, key, value) {
29
+ if (key in obj) {
30
+ Object.defineProperty(obj, key, {
31
+ value: value,
32
+ enumerable: true,
33
+ configurable: true,
34
+ writable: true
35
+ });
36
+ } else {
37
+ obj[key] = value;
38
+ }
39
+ return obj;
40
+ }
41
+ function _get(target, property, receiver) {
42
+ if (typeof Reflect !== "undefined" && Reflect.get) {
43
+ _get = Reflect.get;
44
+ } else {
45
+ _get = function get(target, property, receiver) {
46
+ var base = _super_prop_base(target, property);
47
+ if (!base) return;
48
+ var desc = Object.getOwnPropertyDescriptor(base, property);
49
+ if (desc.get) {
50
+ return desc.get.call(receiver || target);
51
+ }
52
+ return desc.value;
53
+ };
54
+ }
55
+ return _get(target, property, receiver || target);
56
+ }
28
57
  function _get_prototype_of$2(o) {
29
58
  _get_prototype_of$2 = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
30
59
  return o.__proto__ || Object.getPrototypeOf(o);
@@ -44,6 +73,45 @@ function _inherits$2(subClass, superClass) {
44
73
  });
45
74
  if (superClass) _set_prototype_of$2(subClass, superClass);
46
75
  }
76
+ function _object_spread$2(target) {
77
+ for(var i = 1; i < arguments.length; i++){
78
+ var source = arguments[i] != null ? arguments[i] : {};
79
+ var ownKeys = Object.keys(source);
80
+ if (typeof Object.getOwnPropertySymbols === "function") {
81
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
82
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
83
+ }));
84
+ }
85
+ ownKeys.forEach(function(key) {
86
+ _define_property$2(target, key, source[key]);
87
+ });
88
+ }
89
+ return target;
90
+ }
91
+ function ownKeys$2(object, enumerableOnly) {
92
+ var keys = Object.keys(object);
93
+ if (Object.getOwnPropertySymbols) {
94
+ var symbols = Object.getOwnPropertySymbols(object);
95
+ if (enumerableOnly) {
96
+ symbols = symbols.filter(function(sym) {
97
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
98
+ });
99
+ }
100
+ keys.push.apply(keys, symbols);
101
+ }
102
+ return keys;
103
+ }
104
+ function _object_spread_props$2(target, source) {
105
+ source = source != null ? source : {};
106
+ if (Object.getOwnPropertyDescriptors) {
107
+ Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
108
+ } else {
109
+ ownKeys$2(Object(source)).forEach(function(key) {
110
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
111
+ });
112
+ }
113
+ return target;
114
+ }
47
115
  function _possible_constructor_return$2(self, call) {
48
116
  if (call && (_type_of$2(call) === "object" || typeof call === "function")) {
49
117
  return call;
@@ -57,6 +125,13 @@ function _set_prototype_of$2(o, p) {
57
125
  };
58
126
  return _set_prototype_of$2(o, p);
59
127
  }
128
+ function _super_prop_base(object, property) {
129
+ while(!Object.prototype.hasOwnProperty.call(object, property)){
130
+ object = _get_prototype_of$2(object);
131
+ if (object === null) break;
132
+ }
133
+ return object;
134
+ }
60
135
  function _type_of$2(obj) {
61
136
  "@swc/helpers - typeof";
62
137
  return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
@@ -116,6 +191,14 @@ function _create_super$2(Derived) {
116
191
  value: function _getType() {
117
192
  return "generic";
118
193
  }
194
+ },
195
+ {
196
+ key: "_printableFields",
197
+ get: function get() {
198
+ return _object_spread_props$2(_object_spread$2({}, _get(_get_prototype_of$2(ChatMessage.prototype), "_printableFields", this)), {
199
+ role: this.role
200
+ });
201
+ }
119
202
  }
120
203
  ], [
121
204
  {
@@ -555,10 +638,7 @@ function _ts_generator$1(thisArg, body) {
555
638
  for(_iterator = Object.entries(_this.template)[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
556
639
  _step_value = _sliced_to_array(_step.value, 2), key = _step_value[0], value = _step_value[1];
557
640
  if (typeof value === "string") {
558
- formatted[key] = value.replace(/{([^{}]*)}/g, function(match, group) {
559
- var replacement = values[group];
560
- return typeof replacement === "string" || typeof replacement === "number" ? String(replacement) : match;
561
- });
641
+ formatted[key] = renderTemplate(value, _this.templateFormat, values);
562
642
  } else {
563
643
  formatted[key] = value;
564
644
  }
@@ -1048,44 +1128,46 @@ function _ts_values(o) {
1048
1128
  ];
1049
1129
  }
1050
1130
  },
1051
- {
1052
- key: "validateInputOrThrow",
1053
- value: function validateInputOrThrow(input, variableName) {
1054
- if (this.optional && !input) {
1055
- return false;
1056
- } else if (!input) {
1057
- var error = new Error('Error: Field "'.concat(variableName, '" in prompt uses a MessagesPlaceholder, which expects an array of BaseMessages as an input value. Received: undefined'));
1058
- error.name = "InputFormatError";
1059
- throw error;
1060
- }
1061
- var isInputBaseMessage = false;
1062
- if (Array.isArray(input)) {
1063
- isInputBaseMessage = input.every(function(message) {
1064
- return isBaseMessage(message);
1065
- });
1066
- } else {
1067
- isInputBaseMessage = isBaseMessage(input);
1068
- }
1069
- if (!isInputBaseMessage) {
1070
- var readableInput = typeof input === "string" ? input : JSON.stringify(input, null, 2);
1071
- var error1 = new Error('Error: Field "'.concat(variableName, '" in prompt uses a MessagesPlaceholder, which expects an array of BaseMessages as an input value. Received: ').concat(readableInput));
1072
- error1.name = "InputFormatError";
1073
- throw error1;
1074
- }
1075
- return true;
1076
- }
1077
- },
1078
1131
  {
1079
1132
  key: "formatMessages",
1080
1133
  value: function formatMessages(values) {
1081
1134
  var _this = this;
1082
1135
  return _async_to_generator(function() {
1083
- var _values_this_variableName;
1136
+ var input, error, formattedMessages, readableInput, error1;
1084
1137
  return _ts_generator(this, function(_state) {
1085
- _this.validateInputOrThrow(values[_this.variableName], _this.variableName);
1138
+ input = values[_this.variableName];
1139
+ if (_this.optional && !input) {
1140
+ return [
1141
+ 2,
1142
+ []
1143
+ ];
1144
+ } else if (!input) {
1145
+ error = new Error('Field "'.concat(_this.variableName, '" in prompt uses a MessagesPlaceholder, which expects an array of BaseMessages as an input value. Received: undefined'));
1146
+ error.name = "InputFormatError";
1147
+ throw error;
1148
+ }
1149
+ try {
1150
+ if (Array.isArray(input)) {
1151
+ formattedMessages = input.map(coerceMessageLikeToMessage);
1152
+ } else {
1153
+ formattedMessages = [
1154
+ coerceMessageLikeToMessage(input)
1155
+ ];
1156
+ }
1157
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1158
+ } catch (e) {
1159
+ readableInput = typeof input === "string" ? input : JSON.stringify(input, null, 2);
1160
+ error1 = new Error([
1161
+ 'Field "'.concat(_this.variableName, '" in prompt uses a MessagesPlaceholder, which expects an array of BaseMessages or coerceable values as input.'),
1162
+ "Received value: ".concat(readableInput),
1163
+ "Additional message: ".concat(e.message)
1164
+ ].join("\n\n"));
1165
+ error1.name = "InputFormatError";
1166
+ throw error1;
1167
+ }
1086
1168
  return [
1087
1169
  2,
1088
- (_values_this_variableName = values[_this.variableName]) !== null && _values_this_variableName !== void 0 ? _values_this_variableName : []
1170
+ formattedMessages
1089
1171
  ];
1090
1172
  });
1091
1173
  })();
@@ -1644,7 +1726,8 @@ var _StringImageMessagePromptTemplate = /*#__PURE__*/ function(BaseMessagePrompt
1644
1726
  };
1645
1727
  imgTemplateObject = new ImagePromptTemplate({
1646
1728
  template: imgTemplate,
1647
- inputVariables: inputVariables
1729
+ inputVariables: inputVariables,
1730
+ templateFormat: additionalOptions === null || additionalOptions === void 0 ? void 0 : additionalOptions.templateFormat
1648
1731
  });
1649
1732
  } else if (typeof imgTemplate === "object") {
1650
1733
  if ("url" in imgTemplate) {
@@ -1664,7 +1747,8 @@ var _StringImageMessagePromptTemplate = /*#__PURE__*/ function(BaseMessagePrompt
1664
1747
  }
1665
1748
  imgTemplateObject = new ImagePromptTemplate({
1666
1749
  template: imgTemplate,
1667
- inputVariables: inputVariables
1750
+ inputVariables: inputVariables,
1751
+ templateFormat: additionalOptions === null || additionalOptions === void 0 ? void 0 : additionalOptions.templateFormat
1668
1752
  });
1669
1753
  } else {
1670
1754
  throw new Error("Invalid image template");