@zodic/shared 0.0.232 → 0.0.233

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.
@@ -551,21 +551,10 @@ export class ConceptService {
551
551
  structuredContentEN: StructuredConceptContent;
552
552
  structuredContentPT: StructuredConceptContent;
553
553
  } {
554
- console.log(
555
- `📌 [START] Parsing structured content for ${conceptSlug} from ChatGPT response.`
556
- );
554
+ console.log(`📌 [START] Parsing structured content for ${conceptSlug} from ChatGPT response.`);
557
555
 
558
- // ✅ Step 1: Clean artifacts before processing
559
- let cleanedResponse = response
560
- .replace(/[*#•]/g, '') // Remove bullet points, bold markers, headings
561
- .replace(/---+/g, '') // Remove dividers (like "---")
562
- .replace(/\n\s*\n/g, '\n\n') // Normalize multiple line breaks
563
- .trim();
564
-
565
- console.log(
566
- '🔹 [CLEANED RESPONSE]:',
567
- cleanedResponse.slice(0, 500) + '...'
568
- );
556
+ // ✅ Step 1: Log the entire raw response before processing
557
+ console.log('🔹 [RAW RESPONSE]:', response);
569
558
 
570
559
  // ✅ Step 2: Define Section Titles Per Concept
571
560
  const conceptSections: Record<string, { en: string[]; pt: string[] }> = {
@@ -675,37 +664,31 @@ export class ConceptService {
675
664
  }
676
665
 
677
666
  // ✅ Step 3: Extract English and Portuguese content separately
678
- const enMatches = cleanedResponse.match(/EN:\s*([\s\S]+?)\s*PT:/);
679
- const ptMatches = cleanedResponse.match(/PT:\s*([\s\S]+)/);
667
+ const enMatches = response.match(/EN:\s*([\s\S]+?)\s*PT:/);
668
+ const ptMatches = response.match(/PT:\s*([\s\S]+)/);
680
669
 
681
670
  if (!enMatches || !ptMatches) {
682
- console.error(
683
- '❌ [ERROR] Missing English or Portuguese content in response.'
684
- );
671
+ console.error('❌ [ERROR] Missing English or Portuguese content in response.');
685
672
  throw new Error('❌ Missing English or Portuguese content in response.');
686
673
  }
687
674
 
688
- const enContent = enMatches[1].trim();
689
- const ptContent = ptMatches[1].trim();
675
+ let enContent = enMatches[1].trim();
676
+ let ptContent = ptMatches[1].trim();
690
677
 
691
- console.log(
692
- '✅ [MATCH SUCCESS] Extracted English Content:',
693
- enContent.slice(0, 500) + '...'
694
- );
695
- console.log(
696
- ' [MATCH SUCCESS] Extracted Portuguese Content:',
697
- ptContent.slice(0, 500) + '...'
698
- );
678
+ console.log('✅ [MATCH SUCCESS] Extracted English Content:', enContent.slice(0, 500) + '...');
679
+ console.log('✅ [MATCH SUCCESS] Extracted Portuguese Content:', ptContent.slice(0, 500) + '...');
680
+
681
+ // ✅ Step 4: Debug **why** PT content has "EN:"
682
+ if (ptContent.includes('EN:')) {
683
+ console.warn('⚠️ PT content contains "EN:". Check if parsing was incorrect.');
684
+ }
699
685
 
700
- // ✅ Step 4: Extract structured sections
686
+ // ✅ Step 5: Extract structured sections
701
687
  function extractSections(text: string, sectionTitles: string[]) {
702
688
  return sectionTitles.map((title) => {
703
689
  console.log(`🔍 [PROCESSING] Extracting section: "${title}"`);
704
690
 
705
- // ✅ Improved regex: Detects sections even if AI formatting changes
706
- const regex = new RegExp(
707
- `\\d+\\.\\s*${title}:\\s*([\\s\\S]+?)(?=\\n\\d+\\.\\s*[A-Z]|$)`
708
- );
691
+ const regex = new RegExp(`\\d+\\.\\s*${title}:\\s*([\\s\\S]+?)(?=\\n\\d+\\.\\s*[A-Z]|$)`);
709
692
  const match = text.match(regex);
710
693
 
711
694
  if (!match) {
@@ -713,12 +696,11 @@ export class ConceptService {
713
696
  return { type: 'section', title, content: ['❌ Section Missing'] };
714
697
  }
715
698
 
716
- // ✅ Split content into paragraphs and clean them
717
699
  const paragraphs = match[1]
718
700
  .trim()
719
- .split(/\n{2,}/) // Handles cases where paragraphs are separated by multiple new lines
701
+ .split(/\n{2,}/)
720
702
  .map((p) => p.trim())
721
- .filter((p) => p.length > 0); // Removes empty paragraphs
703
+ .filter((p) => p.length > 0);
722
704
 
723
705
  console.log(`✅ [EXTRACTED] "${title}" - Parsed Content:`, paragraphs);
724
706
 
@@ -726,22 +708,13 @@ export class ConceptService {
726
708
  });
727
709
  }
728
710
 
729
- // ✅ Return parsed and cleaned structured content
730
711
  const structuredContentEN = extractSections(enContent, sectionsEN);
731
712
  const structuredContentPT = extractSections(ptContent, sectionsPT);
732
713
 
733
- console.log(
734
- '🎯 [FINAL RESULT] Parsed English Content:',
735
- JSON.stringify(structuredContentEN, null, 2)
736
- );
737
- console.log(
738
- '🎯 [FINAL RESULT] Parsed Portuguese Content:',
739
- JSON.stringify(structuredContentPT, null, 2)
740
- );
714
+ console.log('🎯 [FINAL RESULT] Parsed English Content:', JSON.stringify(structuredContentEN, null, 2));
715
+ console.log('🎯 [FINAL RESULT] Parsed Portuguese Content:', JSON.stringify(structuredContentPT, null, 2));
741
716
 
742
- console.log(
743
- '✅ [COMPLETE] Structured content parsing finished successfully.'
744
- );
717
+ console.log('✅ [COMPLETE] Structured content parsing finished successfully.');
745
718
 
746
719
  return {
747
720
  structuredContentEN,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zodic/shared",
3
- "version": "0.0.232",
3
+ "version": "0.0.233",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "publishConfig": {