@akropolys/kiku 1.5.7 → 1.5.8

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.js CHANGED
@@ -1489,20 +1489,28 @@ var getFriendlyError = (err) => {
1489
1489
  }
1490
1490
  };
1491
1491
  function parseThinking(text) {
1492
- const openTag = "<thinking>";
1493
- const closeTag = "</thinking>";
1494
- const openIdx = text.indexOf(openTag);
1495
- if (openIdx === -1) {
1492
+ const openMatch = text.match(/<\s*thinking\s*>/i);
1493
+ if (!openMatch) {
1496
1494
  return { thinking: "", content: text, isComplete: true };
1497
1495
  }
1498
- const start = openIdx + openTag.length;
1499
- const closeIdx = text.indexOf(closeTag, start);
1500
- if (closeIdx === -1) {
1501
- return { thinking: text.slice(start), content: "", isComplete: false };
1496
+ const openIdx = openMatch.index ?? 0;
1497
+ const openTagLength = openMatch[0].length;
1498
+ const start = openIdx + openTagLength;
1499
+ const contentBefore = text.slice(0, openIdx);
1500
+ const textAfterOpen = text.slice(start);
1501
+ const closeMatch = textAfterOpen.match(/<\/\s*thinking\s*>/i);
1502
+ if (!closeMatch) {
1503
+ return {
1504
+ thinking: textAfterOpen,
1505
+ content: contentBefore,
1506
+ isComplete: false
1507
+ };
1502
1508
  }
1509
+ const closeIdx = closeMatch.index ?? 0;
1510
+ const closeTagLength = closeMatch[0].length;
1503
1511
  return {
1504
- thinking: text.slice(start, closeIdx),
1505
- content: text.slice(closeIdx + closeTag.length),
1512
+ thinking: textAfterOpen.slice(0, closeIdx),
1513
+ content: contentBefore + textAfterOpen.slice(closeIdx + closeTagLength),
1506
1514
  isComplete: true
1507
1515
  };
1508
1516
  }