debug-parse.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. const fs = require('fs');
  2. const content = fs.readFileSync('temp/rich-outline-fail_57_1779014018760.txt', 'utf-8');
  3. const marker = '========== AI 原始响应 ';
  4. const idx = content.indexOf(marker);
  5. const start = content.indexOf('\n', idx) + 1;
  6. const end = content.indexOf('\n\n========== 响应结尾');
  7. const aiResponse = content.substring(start, end).trim();
  8. console.log('Length:', aiResponse.length);
  9. console.log('First 100:', JSON.stringify(aiResponse.substring(0, 100)));
  10. console.log('Last 100:', JSON.stringify(aiResponse.substring(aiResponse.length - 100)));
  11. const pos = 798;
  12. console.log('\n--- Error at position 798 ---');
  13. console.log('Char at 798:', JSON.stringify(aiResponse[pos]));
  14. console.log('Char code at 798:', aiResponse.charCodeAt(798));
  15. // Check if this is inside a string value (unescaped newline inside quotes)
  16. let inString = false;
  17. let escapeNext = false;
  18. let i = 0;
  19. const str = aiResponse;
  20. while (i < pos) {
  21. const ch = str[i];
  22. if (escapeNext) {
  23. escapeNext = false;
  24. } else if (ch === '"') {
  25. inString = !inString;
  26. } else if (ch === '\\' && inString) {
  27. escapeNext = true;
  28. }
  29. i++;
  30. }
  31. console.log('Is inside string at pos 798:', inString);
  32. // Check if it's truncation
  33. console.log('\n--- Truncation check ---');
  34. console.log('Ends with }:', aiResponse.trim().endsWith('}'));
  35. console.log('Ends with ,:', aiResponse.trim().endsWith(','));
  36. // Find the actual last complete property
  37. const lastComma = aiResponse.lastIndexOf(',');
  38. const lastBrace = aiResponse.lastIndexOf('}');
  39. const lastBracket = aiResponse.lastIndexOf(']');
  40. console.log('Last comma pos:', lastComma, 'char:', JSON.stringify(aiResponse[lastComma]));
  41. console.log('Last brace pos:', lastBrace);
  42. console.log('Last bracket pos:', lastBracket);
  43. // Check the trailing content
  44. console.log('\n--- Trailing content ---');
  45. console.log(JSON.stringify(aiResponse.substring(aiResponse.length - 200)));