@zodic/shared 0.0.232 → 0.0.234

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