@braze/sanity-plugin-ai-translation 0.2.56 → 0.2.57

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
@@ -1527,8 +1527,35 @@ const globalTransformRegistry = new TransformRegistry(), callGPT5 = async (apiKe
1527
1527
  }, modelPricing = pricing[model] || pricing["gpt-5"], cachedInputRate = model === "gpt-5.1" ? 0.125 / 1e6 : modelPricing.input;
1528
1528
  return Math.max(0, tokens.prompt - tokens.cached) * modelPricing.input + tokens.cached * cachedInputRate + tokens.completion * modelPricing.output + tokens.reasoning * modelPricing.reasoning;
1529
1529
  }, deserializeDocument = (originalDoc, reviewedText) => {
1530
- const parsed = parseReviewFormat(reviewedText, originalDoc), result = cloneDeep(originalDoc);
1530
+ devLog.debug("Raw GPT-5 response received", {
1531
+ length: reviewedText.length,
1532
+ preview: reviewedText.substring(0, 1e3),
1533
+ hasReasoning: reviewedText.includes("<reasoning>"),
1534
+ hasCodeBlocks: reviewedText.includes("```")
1535
+ });
1536
+ const cleanedText = preprocessResponse(reviewedText);
1537
+ cleanedText.length !== reviewedText.length && devLog.debug("Response after preprocessing", {
1538
+ originalLength: reviewedText.length,
1539
+ cleanedLength: cleanedText.length,
1540
+ preview: cleanedText.substring(0, 500)
1541
+ });
1542
+ const parsed = parseReviewFormat(cleanedText, originalDoc), result = cloneDeep(originalDoc);
1531
1543
  return applyTextChanges(result, parsed), result;
1544
+ }, preprocessResponse = (text) => {
1545
+ const originalLength = text.length;
1546
+ let cleaned = text;
1547
+ const beforeReasoning = cleaned.length;
1548
+ cleaned = cleaned.replace(/<reasoning>[\s\S]*?<\/reasoning>/gi, "");
1549
+ const reasoningRemoved = beforeReasoning !== cleaned.length, beforeCodeBlocks = cleaned.length;
1550
+ cleaned = cleaned.replace(/^```[a-z]*\s*$/gim, ""), cleaned = cleaned.replace(/^```\s*$/gim, "");
1551
+ const codeBlocksRemoved = beforeCodeBlocks !== cleaned.length, finalLength = cleaned.trim().length;
1552
+ return (reasoningRemoved || codeBlocksRemoved) && devLog.debug("Preprocessed GPT-5 response", {
1553
+ originalLength,
1554
+ finalLength,
1555
+ reasoningRemoved,
1556
+ codeBlocksRemoved,
1557
+ preview: cleaned.trim().substring(0, 200)
1558
+ }), cleaned.trim();
1532
1559
  }, parseReviewFormat = (text, originalDoc) => {
1533
1560
  const root = [], stack = [], lines = text.split(`
1534
1561
  `);