@sprucelabs/sprucebot-llm 8.3.0 → 8.3.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.
@@ -4,6 +4,7 @@ export default class ResponseParser {
4
4
  static setInstance(parser: ResponseParser): void;
5
5
  static getInstance(): ResponseParser;
6
6
  parse(response: string, callbacks?: LlmCallbackMap): Promise<ParsedResponse>;
7
+ private findFirstBadCallback;
7
8
  private invokeCallbackAndDropInLegacyResults;
8
9
  private doesIncludeDoneToken;
9
10
  private parseState;
@@ -19,7 +19,7 @@ class ResponseParser {
19
19
  }
20
20
  parse(response, callbacks) {
21
21
  return __awaiter(this, void 0, void 0, function* () {
22
- var _a, _b;
22
+ var _a;
23
23
  let message = response.replace(DONE_TOKEN, '').trim();
24
24
  let state;
25
25
  let callbackResults;
@@ -44,13 +44,12 @@ class ResponseParser {
44
44
  message = message.replace(simpleMatches[0], '').trim();
45
45
  }
46
46
  }
47
- let extraMatches = message.match(new RegExp(`<<(.*)\/>>`, 'g'));
48
- if (extraMatches && ((_b = extraMatches === null || extraMatches === void 0 ? void 0 : extraMatches.length) !== null && _b !== void 0 ? _b : 0) > 0) {
49
- debugger;
47
+ const matchedCallback = this.findFirstBadCallback(message);
48
+ if (matchedCallback) {
50
49
  throw new SpruceError({
51
50
  code: 'INVALID_CALLBACK',
52
51
  validCallbacks: Object.keys(callbacks !== null && callbacks !== void 0 ? callbacks : {}),
53
- matchedCallback: extraMatches[0],
52
+ matchedCallback,
54
53
  });
55
54
  }
56
55
  const { match, fullMatch } = this.parseState(message);
@@ -66,6 +65,12 @@ class ResponseParser {
66
65
  };
67
66
  });
68
67
  }
68
+ findFirstBadCallback(message) {
69
+ const simpleMatches = message.match(new RegExp(`<<(.*)\/>>`, 'g'));
70
+ const extraJsonMatches = message.match(new RegExp(`<<.*?>>(.*?)<<\/.*?>>`, 'gs'));
71
+ const matchedCallback = (extraJsonMatches === null || extraJsonMatches === void 0 ? void 0 : extraJsonMatches[0]) || (simpleMatches === null || simpleMatches === void 0 ? void 0 : simpleMatches[0]);
72
+ return matchedCallback;
73
+ }
69
74
  invokeCallbackAndDropInLegacyResults(callbacks, key, message) {
70
75
  return __awaiter(this, void 0, void 0, function* () {
71
76
  var _a;
@@ -4,6 +4,7 @@ export default class ResponseParser {
4
4
  static setInstance(parser: ResponseParser): void;
5
5
  static getInstance(): ResponseParser;
6
6
  parse(response: string, callbacks?: LlmCallbackMap): Promise<ParsedResponse>;
7
+ private findFirstBadCallback;
7
8
  private invokeCallbackAndDropInLegacyResults;
8
9
  private doesIncludeDoneToken;
9
10
  private parseState;
@@ -38,13 +38,12 @@ class ResponseParser {
38
38
  message = message.replace(simpleMatches[0], '').trim();
39
39
  }
40
40
  }
41
- let extraMatches = message.match(new RegExp(`<<(.*)\/>>`, 'g'));
42
- if (extraMatches && (extraMatches?.length ?? 0) > 0) {
43
- debugger;
41
+ const matchedCallback = this.findFirstBadCallback(message);
42
+ if (matchedCallback) {
44
43
  throw new SpruceError_1.default({
45
44
  code: 'INVALID_CALLBACK',
46
45
  validCallbacks: Object.keys(callbacks ?? {}),
47
- matchedCallback: extraMatches[0],
46
+ matchedCallback,
48
47
  });
49
48
  }
50
49
  const { match, fullMatch } = this.parseState(message);
@@ -59,6 +58,12 @@ class ResponseParser {
59
58
  callbackResults,
60
59
  };
61
60
  }
61
+ findFirstBadCallback(message) {
62
+ const simpleMatches = message.match(new RegExp(`<<(.*)\/>>`, 'g'));
63
+ const extraJsonMatches = message.match(new RegExp(`<<.*?>>(.*?)<<\/.*?>>`, 'gs'));
64
+ const matchedCallback = extraJsonMatches?.[0] || simpleMatches?.[0];
65
+ return matchedCallback;
66
+ }
62
67
  async invokeCallbackAndDropInLegacyResults(callbacks, key, message) {
63
68
  const v = await callbacks?.[key]?.cb();
64
69
  message = message.replace((0, renderPlaceholder_1.default)(key), v ?? '').trim();
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "@sprucelabs/spruce-test-fixtures"
10
10
  ]
11
11
  },
12
- "version": "8.3.0",
12
+ "version": "8.3.1",
13
13
  "files": [
14
14
  "build"
15
15
  ],