@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.mjs CHANGED
@@ -1454,20 +1454,28 @@ var getFriendlyError = (err) => {
1454
1454
  }
1455
1455
  };
1456
1456
  function parseThinking(text) {
1457
- const openTag = "<thinking>";
1458
- const closeTag = "</thinking>";
1459
- const openIdx = text.indexOf(openTag);
1460
- if (openIdx === -1) {
1457
+ const openMatch = text.match(/<\s*thinking\s*>/i);
1458
+ if (!openMatch) {
1461
1459
  return { thinking: "", content: text, isComplete: true };
1462
1460
  }
1463
- const start = openIdx + openTag.length;
1464
- const closeIdx = text.indexOf(closeTag, start);
1465
- if (closeIdx === -1) {
1466
- return { thinking: text.slice(start), content: "", isComplete: false };
1461
+ const openIdx = openMatch.index ?? 0;
1462
+ const openTagLength = openMatch[0].length;
1463
+ const start = openIdx + openTagLength;
1464
+ const contentBefore = text.slice(0, openIdx);
1465
+ const textAfterOpen = text.slice(start);
1466
+ const closeMatch = textAfterOpen.match(/<\/\s*thinking\s*>/i);
1467
+ if (!closeMatch) {
1468
+ return {
1469
+ thinking: textAfterOpen,
1470
+ content: contentBefore,
1471
+ isComplete: false
1472
+ };
1467
1473
  }
1474
+ const closeIdx = closeMatch.index ?? 0;
1475
+ const closeTagLength = closeMatch[0].length;
1468
1476
  return {
1469
- thinking: text.slice(start, closeIdx),
1470
- content: text.slice(closeIdx + closeTag.length),
1477
+ thinking: textAfterOpen.slice(0, closeIdx),
1478
+ content: contentBefore + textAfterOpen.slice(closeIdx + closeTagLength),
1471
1479
  isComplete: true
1472
1480
  };
1473
1481
  }