@sprucelabs/sprucebot-llm 18.1.4 → 18.1.6

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.
@@ -136,8 +136,12 @@ function extractCallbackSpans(message) {
136
136
  closeParen = j;
137
137
  }
138
138
  else {
139
- re.lastIndex = openParen + 1;
140
- continue;
139
+ closeParen = message.indexOf(')', i);
140
+ if (closeParen === -1) {
141
+ re.lastIndex = openParen + 1;
142
+ continue;
143
+ }
144
+ argsJson = message.slice(i, closeParen);
141
145
  }
142
146
  let end = closeParen + 1;
143
147
  // Include trailing newline after the call when present (common LLM layout)
@@ -183,6 +187,15 @@ export default class ResponseParserV2 {
183
187
  let message = response.replace(DONE_TOKEN, '').trim();
184
188
  let state = undefined;
185
189
  let callbackResults = undefined;
190
+ const missingParens = message.matchAll(/^@(\w+) \{.*\}/gm);
191
+ for (const match of missingParens) {
192
+ const name = match[1];
193
+ const error = this.renderCallbackResults({
194
+ name,
195
+ error: `Missing parentheses for @${name}()`,
196
+ }).trim();
197
+ callbackResults = `${callbackResults !== null && callbackResults !== void 0 ? callbackResults : ''}\n${error}`.trim();
198
+ }
186
199
  // Enter the pass when any @name( call shape is present (incl. typos)
187
200
  // or when a registered callback name appears as a call prefix.
188
201
  const hasCallShape = message != null && /^[ \t]*@\w+\(/m.test(message);
@@ -191,7 +204,8 @@ export default class ResponseParserV2 {
191
204
  const hasCallbacks = hasCallShape || hasRegisteredName;
192
205
  if (hasCallbacks) {
193
206
  const { callbackResults: c, message: m } = yield this.invokeCallbacks(message, callbacks);
194
- callbackResults = c;
207
+ callbackResults =
208
+ `${callbackResults !== null && callbackResults !== void 0 ? callbackResults : ''}\n${c !== null && c !== void 0 ? c : ''}`.trim() || undefined;
195
209
  message = m;
196
210
  }
197
211
  const hasState = response.includes('@updateState');
@@ -247,6 +261,16 @@ export default class ResponseParserV2 {
247
261
  });
248
262
  continue;
249
263
  }
264
+ if (options !== undefined &&
265
+ (options === null ||
266
+ Array.isArray(options) ||
267
+ typeof options !== 'object')) {
268
+ callbackResults += this.renderCallbackResults({
269
+ name,
270
+ error: 'Arguments not valid JSON',
271
+ });
272
+ continue;
273
+ }
250
274
  const callback = callbacks === null || callbacks === void 0 ? void 0 : callbacks[name];
251
275
  if (!callback) {
252
276
  callbackResults += this.renderCallbackResults({
@@ -133,8 +133,12 @@ function extractCallbackSpans(message) {
133
133
  closeParen = j;
134
134
  }
135
135
  else {
136
- re.lastIndex = openParen + 1;
137
- continue;
136
+ closeParen = message.indexOf(')', i);
137
+ if (closeParen === -1) {
138
+ re.lastIndex = openParen + 1;
139
+ continue;
140
+ }
141
+ argsJson = message.slice(i, closeParen);
138
142
  }
139
143
  let end = closeParen + 1;
140
144
  // Include trailing newline after the call when present (common LLM layout)
@@ -179,6 +183,15 @@ class ResponseParserV2 {
179
183
  let message = response.replace(templates_1.DONE_TOKEN, '').trim();
180
184
  let state = undefined;
181
185
  let callbackResults = undefined;
186
+ const missingParens = message.matchAll(/^@(\w+) \{.*\}/gm);
187
+ for (const match of missingParens) {
188
+ const name = match[1];
189
+ const error = this.renderCallbackResults({
190
+ name,
191
+ error: `Missing parentheses for @${name}()`,
192
+ }).trim();
193
+ callbackResults = `${callbackResults ?? ''}\n${error}`.trim();
194
+ }
182
195
  // Enter the pass when any @name( call shape is present (incl. typos)
183
196
  // or when a registered callback name appears as a call prefix.
184
197
  const hasCallShape = message != null && /^[ \t]*@\w+\(/m.test(message);
@@ -187,7 +200,8 @@ class ResponseParserV2 {
187
200
  const hasCallbacks = hasCallShape || hasRegisteredName;
188
201
  if (hasCallbacks) {
189
202
  const { callbackResults: c, message: m } = await this.invokeCallbacks(message, callbacks);
190
- callbackResults = c;
203
+ callbackResults =
204
+ `${callbackResults ?? ''}\n${c ?? ''}`.trim() || undefined;
191
205
  message = m;
192
206
  }
193
207
  const hasState = response.includes('@updateState');
@@ -240,6 +254,16 @@ class ResponseParserV2 {
240
254
  });
241
255
  continue;
242
256
  }
257
+ if (options !== undefined &&
258
+ (options === null ||
259
+ Array.isArray(options) ||
260
+ typeof options !== 'object')) {
261
+ callbackResults += this.renderCallbackResults({
262
+ name,
263
+ error: 'Arguments not valid JSON',
264
+ });
265
+ continue;
266
+ }
243
267
  const callback = callbacks?.[name];
244
268
  if (!callback) {
245
269
  callbackResults += this.renderCallbackResults({
package/package.json CHANGED
@@ -8,7 +8,7 @@
8
8
  "eta"
9
9
  ]
10
10
  },
11
- "version": "18.1.4",
11
+ "version": "18.1.6",
12
12
  "files": [
13
13
  "build"
14
14
  ],