@sprucelabs/sprucebot-llm 11.3.1 → 11.3.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.
@@ -65,9 +65,28 @@ class ResponseParser {
65
65
  matchedCallback,
66
66
  });
67
67
  }
68
- const { match, fullMatch } = this.parseState(message);
68
+ const { match, fullMatch, index } = this.parseState(message);
69
69
  if (match && fullMatch) {
70
- message = message.replace(fullMatch, '').trim();
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();
71
90
  state = JSON.parse(match);
72
91
  }
73
92
  return {
@@ -97,10 +116,14 @@ class ResponseParser {
97
116
  }
98
117
  parseState(message) {
99
118
  const ESCAPED_BOUNDARY = STATE_BOUNDARY.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
100
- const searchRegex = new RegExp(`${ESCAPED_BOUNDARY}(.*?)${ESCAPED_BOUNDARY}`);
101
- const stateMatches = message.match(searchRegex);
119
+ const searchRegex = new RegExp(`${ESCAPED_BOUNDARY}\\s*(.*?)\\s*${ESCAPED_BOUNDARY}`, 's');
120
+ const stateMatches = searchRegex.exec(message);
102
121
  const match = stateMatches === null || stateMatches === void 0 ? void 0 : stateMatches[1];
103
- return { match, fullMatch: stateMatches === null || stateMatches === void 0 ? void 0 : stateMatches[0] };
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
+ };
104
127
  }
105
128
  assertAtMostOneCallback(invocations) {
106
129
  if (invocations > 1) {
@@ -59,9 +59,28 @@ class ResponseParser {
59
59
  matchedCallback,
60
60
  });
61
61
  }
62
- const { match, fullMatch } = this.parseState(message);
62
+ const { match, fullMatch, index } = this.parseState(message);
63
63
  if (match && fullMatch) {
64
- message = message.replace(fullMatch, '').trim();
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();
65
84
  state = JSON.parse(match);
66
85
  }
67
86
  return {
@@ -87,10 +106,14 @@ class ResponseParser {
87
106
  }
88
107
  parseState(message) {
89
108
  const ESCAPED_BOUNDARY = templates_1.STATE_BOUNDARY.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
90
- const searchRegex = new RegExp(`${ESCAPED_BOUNDARY}(.*?)${ESCAPED_BOUNDARY}`);
91
- const stateMatches = message.match(searchRegex);
109
+ const searchRegex = new RegExp(`${ESCAPED_BOUNDARY}\\s*(.*?)\\s*${ESCAPED_BOUNDARY}`, 's');
110
+ const stateMatches = searchRegex.exec(message);
92
111
  const match = stateMatches?.[1];
93
- return { match, fullMatch: stateMatches?.[0] };
112
+ return {
113
+ match,
114
+ fullMatch: stateMatches?.[0],
115
+ index: stateMatches?.index,
116
+ };
94
117
  }
95
118
  assertAtMostOneCallback(invocations) {
96
119
  if (invocations > 1) {
package/package.json CHANGED
@@ -8,7 +8,7 @@
8
8
  "eta"
9
9
  ]
10
10
  },
11
- "version": "11.3.1",
11
+ "version": "11.3.2",
12
12
  "files": [
13
13
  "build"
14
14
  ],