@sprucelabs/sprucebot-llm 11.3.2 → 11.3.4

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.
@@ -14,7 +14,7 @@ class SpruceError extends error_1.default {
14
14
  message = `You must create a bot and set it using 'SprucebotLlmFactory.setInstance(bot)' before you can get an instance of it.`;
15
15
  break;
16
16
  case 'INVALID_CALLBACK':
17
- message = `The callback you tried to invoke (${options.matchedCallback}) is not valid. Make sure you have the syntax correct and are calling a valid callback:\n${options.validCallbacks.map((name, idx) => `${idx + 1}: ${name}`).join('\n')}`;
17
+ message = `The callback you tried to invoke (${options.matchedCallback}) is not valid. If you are calling a valid callback, make sure the tag is closed correctly with />> or <</{tagname}>> depending on whether you are passing it arguments. Here is a list of valid callbacks for reference:\n${options.validCallbacks.map((name, idx) => `${idx + 1}: ${name}`).join('\n')}`;
18
18
  break;
19
19
  case 'CALLBACK_ERROR':
20
20
  message =
@@ -9,7 +9,7 @@ export default class SpruceError extends BaseSpruceError {
9
9
  message = `You must create a bot and set it using 'SprucebotLlmFactory.setInstance(bot)' before you can get an instance of it.`;
10
10
  break;
11
11
  case 'INVALID_CALLBACK':
12
- message = `The callback you tried to invoke (${options.matchedCallback}) is not valid. Make sure you have the syntax correct and are calling a valid callback:\n${options.validCallbacks.map((name, idx) => `${idx + 1}: ${name}`).join('\n')}`;
12
+ message = `The callback you tried to invoke (${options.matchedCallback}) is not valid. If you are calling a valid callback, make sure the tag is closed correctly with />> or <</{tagname}>> depending on whether you are passing it arguments. Here is a list of valid callbacks for reference:\n${options.validCallbacks.map((name, idx) => `${idx + 1}: ${name}`).join('\n')}`;
13
13
  break;
14
14
  case 'CALLBACK_ERROR':
15
15
  message =
@@ -65,28 +65,9 @@ class ResponseParser {
65
65
  matchedCallback,
66
66
  });
67
67
  }
68
- const { match, fullMatch, index } = this.parseState(message);
69
- if (match && fullMatch) {
70
- const matchStart = typeof index === 'number' ? index : message.indexOf(fullMatch);
71
- let removalStart = matchStart;
72
- if (removalStart > 0 && message[removalStart - 1] === '\n') {
73
- removalStart--;
74
- if (removalStart > 0 && message[removalStart - 1] === '\r') {
75
- removalStart--;
76
- }
77
- }
78
- let removalEnd = matchStart + fullMatch.length;
79
- if (message[removalEnd] === '\r') {
80
- removalEnd++;
81
- if (message[removalEnd] === '\n') {
82
- removalEnd++;
83
- }
84
- }
85
- else if (message[removalEnd] === '\n') {
86
- removalEnd++;
87
- }
88
- message = message.slice(0, removalStart) + message.slice(removalEnd);
89
- message = message.trim();
68
+ const { match, regex } = this.parseState(message);
69
+ if (match && regex) {
70
+ message = message.replace(regex, '').trim();
90
71
  state = JSON.parse(match);
91
72
  }
92
73
  return {
@@ -116,14 +97,10 @@ class ResponseParser {
116
97
  }
117
98
  parseState(message) {
118
99
  const ESCAPED_BOUNDARY = STATE_BOUNDARY.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
119
- const searchRegex = new RegExp(`${ESCAPED_BOUNDARY}\\s*(.*?)\\s*${ESCAPED_BOUNDARY}`, 's');
100
+ const searchRegex = new RegExp(`((?:\\r?\\n)+)?${ESCAPED_BOUNDARY}\\s*(.*?)\\s*${ESCAPED_BOUNDARY}((?:\\r?\\n)+)?`, 's');
120
101
  const stateMatches = searchRegex.exec(message);
121
- const match = stateMatches === null || stateMatches === void 0 ? void 0 : stateMatches[1];
122
- return {
123
- match,
124
- fullMatch: stateMatches === null || stateMatches === void 0 ? void 0 : stateMatches[0],
125
- index: stateMatches === null || stateMatches === void 0 ? void 0 : stateMatches.index,
126
- };
102
+ const match = stateMatches === null || stateMatches === void 0 ? void 0 : stateMatches[2];
103
+ return { match, regex: match ? searchRegex : undefined };
127
104
  }
128
105
  assertAtMostOneCallback(invocations) {
129
106
  if (invocations > 1) {
@@ -59,28 +59,9 @@ class ResponseParser {
59
59
  matchedCallback,
60
60
  });
61
61
  }
62
- const { match, fullMatch, index } = this.parseState(message);
63
- if (match && fullMatch) {
64
- const matchStart = typeof index === 'number' ? index : message.indexOf(fullMatch);
65
- let removalStart = matchStart;
66
- if (removalStart > 0 && message[removalStart - 1] === '\n') {
67
- removalStart--;
68
- if (removalStart > 0 && message[removalStart - 1] === '\r') {
69
- removalStart--;
70
- }
71
- }
72
- let removalEnd = matchStart + fullMatch.length;
73
- if (message[removalEnd] === '\r') {
74
- removalEnd++;
75
- if (message[removalEnd] === '\n') {
76
- removalEnd++;
77
- }
78
- }
79
- else if (message[removalEnd] === '\n') {
80
- removalEnd++;
81
- }
82
- message = message.slice(0, removalStart) + message.slice(removalEnd);
83
- message = message.trim();
62
+ const { match, regex } = this.parseState(message);
63
+ if (match && regex) {
64
+ message = message.replace(regex, '').trim();
84
65
  state = JSON.parse(match);
85
66
  }
86
67
  return {
@@ -106,14 +87,10 @@ class ResponseParser {
106
87
  }
107
88
  parseState(message) {
108
89
  const ESCAPED_BOUNDARY = templates_1.STATE_BOUNDARY.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
109
- const searchRegex = new RegExp(`${ESCAPED_BOUNDARY}\\s*(.*?)\\s*${ESCAPED_BOUNDARY}`, 's');
90
+ const searchRegex = new RegExp(`((?:\\r?\\n)+)?${ESCAPED_BOUNDARY}\\s*(.*?)\\s*${ESCAPED_BOUNDARY}((?:\\r?\\n)+)?`, 's');
110
91
  const stateMatches = searchRegex.exec(message);
111
- const match = stateMatches?.[1];
112
- return {
113
- match,
114
- fullMatch: stateMatches?.[0],
115
- index: stateMatches?.index,
116
- };
92
+ const match = stateMatches?.[2];
93
+ return { match, regex: match ? searchRegex : undefined };
117
94
  }
118
95
  assertAtMostOneCallback(invocations) {
119
96
  if (invocations > 1) {
package/package.json CHANGED
@@ -8,7 +8,7 @@
8
8
  "eta"
9
9
  ]
10
10
  },
11
- "version": "11.3.2",
11
+ "version": "11.3.4",
12
12
  "files": [
13
13
  "build"
14
14
  ],