@burtson-labs/bandit-engine 2.0.148 → 2.0.149

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.
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  chat_default
3
- } from "./chunk-NCZX5YKN.mjs";
3
+ } from "./chunk-ANX33XAO.mjs";
4
4
  import {
5
5
  chat_provider_default
6
6
  } from "./chunk-PU74BI6Y.mjs";
@@ -10,7 +10,7 @@ import {
10
10
  useGatewayHealth,
11
11
  useGatewayMemory,
12
12
  useGatewayModels
13
- } from "./chunk-3ADU3BFL.mjs";
13
+ } from "./chunk-JQSZNGII.mjs";
14
14
  import "./chunk-P5IJLX6I.mjs";
15
15
  import "./chunk-F7JXIW6T.mjs";
16
16
  import "./chunk-K2JGFKEB.mjs";
@@ -24184,6 +24184,10 @@ ${protocol}`;
24184
24184
  /\b(?:web_search|web_fetch|image_generation|create_file|ask_user)\s*\(/
24185
24185
  );
24186
24186
  if (callIdx !== -1) t = t.slice(0, callIdx);
24187
+ const jsonIdx = t.search(
24188
+ /\{\s*"name"\s*:\s*"(?:web_search|web_fetch|image_generation|create_file|ask_user)"/
24189
+ );
24190
+ if (jsonIdx !== -1) t = t.slice(0, jsonIdx);
24187
24191
  t = t.replace(/```[\w-]*\s*$/, "");
24188
24192
  const fenceCount = (t.match(/```/g) || []).length;
24189
24193
  if (fenceCount % 2 === 1) t = t.slice(0, t.lastIndexOf("```"));
@@ -24249,6 +24253,9 @@ ${protocol}`;
24249
24253
  const visibleMessage = stripThinking(fullMessage);
24250
24254
  const bareToolMatch = visibleMessage.match(
24251
24255
  /\b(web_search|web_fetch|image_generation|create_file|ask_user)\s*\(/
24256
+ ) || // JSON-form calls from cloud/native-tool engines.
24257
+ visibleMessage.match(
24258
+ /\{\s*"name"\s*:\s*"(web_search|web_fetch|image_generation|create_file|ask_user)"/
24252
24259
  );
24253
24260
  if (/```(?:tool_code|TOOL_CODE)/.test(visibleMessage) || bareToolMatch) {
24254
24261
  sawToolBlock = true;
@@ -24376,6 +24383,70 @@ ${fn}(${argStr})
24376
24383
  }
24377
24384
  return out;
24378
24385
  };
24386
+ const bridgeJsonToolBlobs = (message) => {
24387
+ const KNOWN = ["web_search", "web_fetch", "image_generation", "create_file", "ask_user", "ask-user"];
24388
+ const re = new RegExp(`\\{\\s*"name"\\s*:\\s*"(${KNOWN.join("|")})"`, "g");
24389
+ const spans = [];
24390
+ let m;
24391
+ while ((m = re.exec(message)) !== null) {
24392
+ let depth = 0;
24393
+ let i = m.index;
24394
+ let inStr = false;
24395
+ let esc = false;
24396
+ for (; i < message.length; i++) {
24397
+ const ch = message[i];
24398
+ if (esc) {
24399
+ esc = false;
24400
+ continue;
24401
+ }
24402
+ if (ch === "\\") {
24403
+ esc = true;
24404
+ continue;
24405
+ }
24406
+ if (ch === '"') {
24407
+ inStr = !inStr;
24408
+ continue;
24409
+ }
24410
+ if (inStr) continue;
24411
+ if (ch === "{") depth++;
24412
+ else if (ch === "}") {
24413
+ depth--;
24414
+ if (depth === 0) {
24415
+ i++;
24416
+ break;
24417
+ }
24418
+ }
24419
+ }
24420
+ const blob = message.slice(m.index, i);
24421
+ try {
24422
+ const parsed = JSON.parse(blob);
24423
+ const args = parsed.arguments ?? parsed.parameters ?? parsed.input ?? {};
24424
+ let start = m.index;
24425
+ let end = i;
24426
+ const fenceOpen = message.slice(0, start).match(/```[a-zA-Z0-9_-]*[ \t]*\n[ \t]*$/);
24427
+ if (fenceOpen) {
24428
+ start -= fenceOpen[0].length;
24429
+ const fenceClose = message.slice(end).match(/^[ \t]*\n?```/);
24430
+ if (fenceClose) end += fenceClose[0].length;
24431
+ }
24432
+ spans.push({
24433
+ start,
24434
+ end,
24435
+ fn: parsed.name,
24436
+ args: typeof args === "string" ? args : JSON.stringify(args)
24437
+ });
24438
+ } catch {
24439
+ }
24440
+ re.lastIndex = i;
24441
+ }
24442
+ let result = message;
24443
+ for (let k = spans.length - 1; k >= 0; k--) {
24444
+ const s = spans[k];
24445
+ result = result.slice(0, s.start) + "\n```tool_code\n" + s.fn + "(" + s.args + ")\n```\n" + result.slice(s.end);
24446
+ }
24447
+ return result;
24448
+ };
24449
+ fullMessage = bridgeJsonToolBlobs(fullMessage);
24379
24450
  const toolCallMatches = extractToolCalls(fullMessage);
24380
24451
  let enhancedMessage = fullMessage;
24381
24452
  const summarizableResults = [];