@zodic/shared 0.0.231 → 0.0.232

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