@sprucelabs/sprucebot-llm 18.1.5 → 18.1.7
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.
|
@@ -187,6 +187,15 @@ export default class ResponseParserV2 {
|
|
|
187
187
|
let message = response.replace(DONE_TOKEN, '').trim();
|
|
188
188
|
let state = undefined;
|
|
189
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
|
+
}
|
|
190
199
|
// Enter the pass when any @name( call shape is present (incl. typos)
|
|
191
200
|
// or when a registered callback name appears as a call prefix.
|
|
192
201
|
const hasCallShape = message != null && /^[ \t]*@\w+\(/m.test(message);
|
|
@@ -195,7 +204,8 @@ export default class ResponseParserV2 {
|
|
|
195
204
|
const hasCallbacks = hasCallShape || hasRegisteredName;
|
|
196
205
|
if (hasCallbacks) {
|
|
197
206
|
const { callbackResults: c, message: m } = yield this.invokeCallbacks(message, callbacks);
|
|
198
|
-
callbackResults =
|
|
207
|
+
callbackResults =
|
|
208
|
+
`${callbackResults !== null && callbackResults !== void 0 ? callbackResults : ''}\n${c !== null && c !== void 0 ? c : ''}`.trim() || undefined;
|
|
199
209
|
message = m;
|
|
200
210
|
}
|
|
201
211
|
const hasState = response.includes('@updateState');
|
|
@@ -234,11 +244,17 @@ export default class ResponseParserV2 {
|
|
|
234
244
|
let callbackResults = '';
|
|
235
245
|
const spans = extractCallbackSpans(message);
|
|
236
246
|
for (const span of spans) {
|
|
237
|
-
|
|
247
|
+
const name = span.name;
|
|
248
|
+
if (name === 'results') {
|
|
249
|
+
callbackResults += this.renderCallbackResults({
|
|
250
|
+
name,
|
|
251
|
+
error: `Agent cannot respond with built-in response callback @results()`,
|
|
252
|
+
});
|
|
253
|
+
continue;
|
|
254
|
+
}
|
|
255
|
+
if (RESERVED_CALLBACK_NAMES.has(name)) {
|
|
238
256
|
continue;
|
|
239
257
|
}
|
|
240
|
-
const name = span.name;
|
|
241
|
-
// Always strip the call from the user-facing message once recognized.
|
|
242
258
|
callbackStrippedMessage = stripCallFromMessage(callbackStrippedMessage, span.fullMatch.trim());
|
|
243
259
|
let options;
|
|
244
260
|
try {
|
|
@@ -183,6 +183,15 @@ class ResponseParserV2 {
|
|
|
183
183
|
let message = response.replace(templates_1.DONE_TOKEN, '').trim();
|
|
184
184
|
let state = undefined;
|
|
185
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
|
+
}
|
|
186
195
|
// Enter the pass when any @name( call shape is present (incl. typos)
|
|
187
196
|
// or when a registered callback name appears as a call prefix.
|
|
188
197
|
const hasCallShape = message != null && /^[ \t]*@\w+\(/m.test(message);
|
|
@@ -191,7 +200,8 @@ class ResponseParserV2 {
|
|
|
191
200
|
const hasCallbacks = hasCallShape || hasRegisteredName;
|
|
192
201
|
if (hasCallbacks) {
|
|
193
202
|
const { callbackResults: c, message: m } = await this.invokeCallbacks(message, callbacks);
|
|
194
|
-
callbackResults =
|
|
203
|
+
callbackResults =
|
|
204
|
+
`${callbackResults ?? ''}\n${c ?? ''}`.trim() || undefined;
|
|
195
205
|
message = m;
|
|
196
206
|
}
|
|
197
207
|
const hasState = response.includes('@updateState');
|
|
@@ -227,11 +237,17 @@ class ResponseParserV2 {
|
|
|
227
237
|
let callbackResults = '';
|
|
228
238
|
const spans = extractCallbackSpans(message);
|
|
229
239
|
for (const span of spans) {
|
|
230
|
-
|
|
240
|
+
const name = span.name;
|
|
241
|
+
if (name === 'results') {
|
|
242
|
+
callbackResults += this.renderCallbackResults({
|
|
243
|
+
name,
|
|
244
|
+
error: `Agent cannot respond with built-in response callback @results()`,
|
|
245
|
+
});
|
|
246
|
+
continue;
|
|
247
|
+
}
|
|
248
|
+
if (RESERVED_CALLBACK_NAMES.has(name)) {
|
|
231
249
|
continue;
|
|
232
250
|
}
|
|
233
|
-
const name = span.name;
|
|
234
|
-
// Always strip the call from the user-facing message once recognized.
|
|
235
251
|
callbackStrippedMessage = stripCallFromMessage(callbackStrippedMessage, span.fullMatch.trim());
|
|
236
252
|
let options;
|
|
237
253
|
try {
|