@braze/sanity-plugin-ai-translation 0.2.58 → 0.2.59

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
@@ -1564,11 +1564,26 @@ const globalTransformRegistry = new TransformRegistry(), callGPT5 = async (apiKe
1564
1564
  }, parseReviewFormat = (text, originalDoc) => {
1565
1565
  const root = [], stack = [], lines = text.split(`
1566
1566
  `);
1567
+ devLog.debug("Parsing response text", {
1568
+ lineCount: lines.length,
1569
+ firstLines: lines.slice(0, 10).map((l, idx) => ({ line: idx, content: l.substring(0, 100) })),
1570
+ hasFieldTags: text.includes("<field"),
1571
+ hasBlockTags: text.includes("<block"),
1572
+ hasSpanTags: text.includes("<span"),
1573
+ textLength: text.length,
1574
+ textPreview: text.substring(0, 500)
1575
+ });
1576
+ let processedLineCount = 0, skippedEmptyLineCount = 0, matchedPatternCount = 0;
1567
1577
  for (let i = 0; i < lines.length; i++) {
1568
1578
  const trimmed = lines[i].trim();
1569
- if (!trimmed) continue;
1579
+ if (!trimmed) {
1580
+ skippedEmptyLineCount++;
1581
+ continue;
1582
+ }
1583
+ processedLineCount++;
1570
1584
  const compactStringMatch = trimmed.match(/^(\w+):\s*(.*)$/);
1571
1585
  if (compactStringMatch && !trimmed.includes("<")) {
1586
+ matchedPatternCount++;
1572
1587
  const [, fieldName, text2] = compactStringMatch, node = {
1573
1588
  type: "field",
1574
1589
  name: fieldName,
@@ -1585,6 +1600,7 @@ const globalTransformRegistry = new TransformRegistry(), callGPT5 = async (apiKe
1585
1600
  }
1586
1601
  const compactStartMatch = trimmed.match(/^---\s+(\w+)\s+---$/);
1587
1602
  if (compactStartMatch) {
1603
+ matchedPatternCount++;
1588
1604
  const fieldName = compactStartMatch[1], contentLines = [];
1589
1605
  for (i++; i < lines.length; ) {
1590
1606
  const currentLine = lines[i];
@@ -1620,6 +1636,12 @@ const globalTransformRegistry = new TransformRegistry(), callGPT5 = async (apiKe
1620
1636
  }
1621
1637
  const openMatch = trimmed.match(/^<(field|block|span)([^>]*)>(.*)$/);
1622
1638
  if (openMatch) {
1639
+ matchedPatternCount++, devLog.debug("Matched opening tag", {
1640
+ line: i,
1641
+ tagName: openMatch[1],
1642
+ attributes: openMatch[2],
1643
+ contentPreview: openMatch[3]?.substring(0, 50)
1644
+ });
1623
1645
  const [, tagName, attrsStr, content] = openMatch, attributes = parseAttributes(attrsStr), node = {
1624
1646
  type: tagName,
1625
1647
  name: attributes.name,
@@ -1679,6 +1701,7 @@ const globalTransformRegistry = new TransformRegistry(), callGPT5 = async (apiKe
1679
1701
  continue;
1680
1702
  }
1681
1703
  if (trimmed.match(/^<\/(field|block|span)>$/) && stack.length > 0) {
1704
+ matchedPatternCount++;
1682
1705
  const node = stack.pop();
1683
1706
  if (node)
1684
1707
  if (stack.length > 0) {
@@ -1686,9 +1709,24 @@ const globalTransformRegistry = new TransformRegistry(), callGPT5 = async (apiKe
1686
1709
  parent && parent.children.push(node);
1687
1710
  } else
1688
1711
  root.push(node);
1712
+ continue;
1689
1713
  }
1714
+ processedLineCount <= 20 && devLog.debug("Line did not match any pattern", {
1715
+ line: i,
1716
+ trimmed,
1717
+ startsWithLessThan: trimmed.startsWith("<"),
1718
+ startsWithField: trimmed.startsWith("<field"),
1719
+ startsWithBacktick: trimmed.startsWith("`")
1720
+ });
1690
1721
  }
1691
- return root;
1722
+ return devLog.debug("Parse complete", {
1723
+ totalLines: lines.length,
1724
+ processedLines: processedLineCount,
1725
+ skippedEmptyLines: skippedEmptyLineCount,
1726
+ rootNodeCount: root.length,
1727
+ stackLength: stack.length,
1728
+ matchedPatterns: matchedPatternCount
1729
+ }), root;
1692
1730
  }, parseAttributes = (attrStr) => {
1693
1731
  const attrs = {}, attrRegex = /(\w+)="([^"]*)"/g;
1694
1732
  let match = attrRegex.exec(attrStr);