@digipair/skill-llm 0.22.0 → 0.22.2

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 +36 -120
  2. package/chat.esm.js +37 -121
  3. package/index.cjs2.js +54762 -37525
  4. package/index.esm2.js +54762 -37525
  5. package/package.json +1 -1
package/chat.cjs.js CHANGED
@@ -27,35 +27,6 @@ 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
- }
59
30
  function _get_prototype_of$2(o) {
60
31
  _get_prototype_of$2 = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
61
32
  return o.__proto__ || Object.getPrototypeOf(o);
@@ -75,45 +46,6 @@ function _inherits$2(subClass, superClass) {
75
46
  });
76
47
  if (superClass) _set_prototype_of$2(subClass, superClass);
77
48
  }
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
- }
117
49
  function _possible_constructor_return$2(self, call) {
118
50
  if (call && (_type_of$2(call) === "object" || typeof call === "function")) {
119
51
  return call;
@@ -127,13 +59,6 @@ function _set_prototype_of$2(o, p) {
127
59
  };
128
60
  return _set_prototype_of$2(o, p);
129
61
  }
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
- }
137
62
  function _type_of$2(obj) {
138
63
  "@swc/helpers - typeof";
139
64
  return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
@@ -193,14 +118,6 @@ function _create_super$2(Derived) {
193
118
  value: function _getType() {
194
119
  return "generic";
195
120
  }
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
- }
204
121
  }
205
122
  ], [
206
123
  {
@@ -640,7 +557,10 @@ function _ts_generator$1(thisArg, body) {
640
557
  for(_iterator = Object.entries(_this.template)[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
641
558
  _step_value = _sliced_to_array(_step.value, 2), key = _step_value[0], value = _step_value[1];
642
559
  if (typeof value === "string") {
643
- formatted[key] = index.renderTemplate(value, _this.templateFormat, values);
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
+ });
644
564
  } else {
645
565
  formatted[key] = value;
646
566
  }
@@ -1130,46 +1050,44 @@ function _ts_values(o) {
1130
1050
  ];
1131
1051
  }
1132
1052
  },
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
+ },
1133
1080
  {
1134
1081
  key: "formatMessages",
1135
1082
  value: function formatMessages(values) {
1136
1083
  var _this = this;
1137
1084
  return _async_to_generator(function() {
1138
- var input, error, formattedMessages, readableInput, error1;
1085
+ var _values_this_variableName;
1139
1086
  return _ts_generator(this, function(_state) {
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
- }
1087
+ _this.validateInputOrThrow(values[_this.variableName], _this.variableName);
1170
1088
  return [
1171
1089
  2,
1172
- formattedMessages
1090
+ (_values_this_variableName = values[_this.variableName]) !== null && _values_this_variableName !== void 0 ? _values_this_variableName : []
1173
1091
  ];
1174
1092
  });
1175
1093
  })();
@@ -1728,8 +1646,7 @@ var _StringImageMessagePromptTemplate = /*#__PURE__*/ function(BaseMessagePrompt
1728
1646
  };
1729
1647
  imgTemplateObject = new ImagePromptTemplate({
1730
1648
  template: imgTemplate,
1731
- inputVariables: inputVariables,
1732
- templateFormat: additionalOptions === null || additionalOptions === void 0 ? void 0 : additionalOptions.templateFormat
1649
+ inputVariables: inputVariables
1733
1650
  });
1734
1651
  } else if (typeof imgTemplate === "object") {
1735
1652
  if ("url" in imgTemplate) {
@@ -1749,8 +1666,7 @@ var _StringImageMessagePromptTemplate = /*#__PURE__*/ function(BaseMessagePrompt
1749
1666
  }
1750
1667
  imgTemplateObject = new ImagePromptTemplate({
1751
1668
  template: imgTemplate,
1752
- inputVariables: inputVariables,
1753
- templateFormat: additionalOptions === null || additionalOptions === void 0 ? void 0 : additionalOptions.templateFormat
1669
+ inputVariables: inputVariables
1754
1670
  });
1755
1671
  } else {
1756
1672
  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, 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';
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';
2
2
 
3
3
  function _assert_this_initialized$2(self) {
4
4
  if (self === void 0) {
@@ -25,35 +25,6 @@ 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
- }
57
28
  function _get_prototype_of$2(o) {
58
29
  _get_prototype_of$2 = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
59
30
  return o.__proto__ || Object.getPrototypeOf(o);
@@ -73,45 +44,6 @@ function _inherits$2(subClass, superClass) {
73
44
  });
74
45
  if (superClass) _set_prototype_of$2(subClass, superClass);
75
46
  }
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
- }
115
47
  function _possible_constructor_return$2(self, call) {
116
48
  if (call && (_type_of$2(call) === "object" || typeof call === "function")) {
117
49
  return call;
@@ -125,13 +57,6 @@ function _set_prototype_of$2(o, p) {
125
57
  };
126
58
  return _set_prototype_of$2(o, p);
127
59
  }
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
- }
135
60
  function _type_of$2(obj) {
136
61
  "@swc/helpers - typeof";
137
62
  return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
@@ -191,14 +116,6 @@ function _create_super$2(Derived) {
191
116
  value: function _getType() {
192
117
  return "generic";
193
118
  }
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
- }
202
119
  }
203
120
  ], [
204
121
  {
@@ -638,7 +555,10 @@ function _ts_generator$1(thisArg, body) {
638
555
  for(_iterator = Object.entries(_this.template)[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
639
556
  _step_value = _sliced_to_array(_step.value, 2), key = _step_value[0], value = _step_value[1];
640
557
  if (typeof value === "string") {
641
- formatted[key] = renderTemplate(value, _this.templateFormat, values);
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
+ });
642
562
  } else {
643
563
  formatted[key] = value;
644
564
  }
@@ -1128,46 +1048,44 @@ function _ts_values(o) {
1128
1048
  ];
1129
1049
  }
1130
1050
  },
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
+ },
1131
1078
  {
1132
1079
  key: "formatMessages",
1133
1080
  value: function formatMessages(values) {
1134
1081
  var _this = this;
1135
1082
  return _async_to_generator(function() {
1136
- var input, error, formattedMessages, readableInput, error1;
1083
+ var _values_this_variableName;
1137
1084
  return _ts_generator(this, function(_state) {
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
- }
1085
+ _this.validateInputOrThrow(values[_this.variableName], _this.variableName);
1168
1086
  return [
1169
1087
  2,
1170
- formattedMessages
1088
+ (_values_this_variableName = values[_this.variableName]) !== null && _values_this_variableName !== void 0 ? _values_this_variableName : []
1171
1089
  ];
1172
1090
  });
1173
1091
  })();
@@ -1726,8 +1644,7 @@ var _StringImageMessagePromptTemplate = /*#__PURE__*/ function(BaseMessagePrompt
1726
1644
  };
1727
1645
  imgTemplateObject = new ImagePromptTemplate({
1728
1646
  template: imgTemplate,
1729
- inputVariables: inputVariables,
1730
- templateFormat: additionalOptions === null || additionalOptions === void 0 ? void 0 : additionalOptions.templateFormat
1647
+ inputVariables: inputVariables
1731
1648
  });
1732
1649
  } else if (typeof imgTemplate === "object") {
1733
1650
  if ("url" in imgTemplate) {
@@ -1747,8 +1664,7 @@ var _StringImageMessagePromptTemplate = /*#__PURE__*/ function(BaseMessagePrompt
1747
1664
  }
1748
1665
  imgTemplateObject = new ImagePromptTemplate({
1749
1666
  template: imgTemplate,
1750
- inputVariables: inputVariables,
1751
- templateFormat: additionalOptions === null || additionalOptions === void 0 ? void 0 : additionalOptions.templateFormat
1667
+ inputVariables: inputVariables
1752
1668
  });
1753
1669
  } else {
1754
1670
  throw new Error("Invalid image template");