@zodic/shared 0.0.151 β†’ 0.0.152

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.
@@ -393,7 +393,15 @@ export class ConceptService {
393
393
  structuredContentPT: StructuredConceptContent;
394
394
  } {
395
395
  console.log('πŸ“Œ [START] Parsing structured content from ChatGPT response.');
396
- console.log('πŸ”Ή [RAW RESPONSE]:', response);
396
+
397
+ // βœ… Step 1: Clean artifacts before processing
398
+ let cleanedResponse = response
399
+ .replace(/[*#β€’]/g, '') // Remove bullet points, bold markers, headings
400
+ .replace(/---+/g, '') // Remove dividers (like "---")
401
+ .replace(/\n\s*\n/g, '\n\n') // Normalize multiple line breaks
402
+ .trim();
403
+
404
+ console.log('πŸ”Ή [CLEANED RESPONSE]:', cleanedResponse.slice(0, 500) + '...');
397
405
 
398
406
  const sectionsEN = [
399
407
  'Core Identity',
@@ -411,9 +419,9 @@ export class ConceptService {
411
419
  'VisΓ£o e AspiraΓ§Γ΅es',
412
420
  ];
413
421
 
414
- // βœ… Match English and Portuguese content separately
415
- const enMatches = response.match(/### EN:\s*([\s\S]+?)\s*### PT:/);
416
- const ptMatches = response.match(/### PT:\s*([\s\S]+)/);
422
+ // βœ… Step 2: Extract English and Portuguese content separately
423
+ const enMatches = cleanedResponse.match(/EN:\s*([\s\S]+?)\s*PT:/);
424
+ const ptMatches = cleanedResponse.match(/PT:\s*([\s\S]+)/);
417
425
 
418
426
  if (!enMatches || !ptMatches) {
419
427
  console.error('❌ [ERROR] Missing English or Portuguese content in response.');
@@ -423,20 +431,15 @@ export class ConceptService {
423
431
  const enContent = enMatches[1].trim();
424
432
  const ptContent = ptMatches[1].trim();
425
433
 
426
- console.log('βœ… [MATCH SUCCESS] Extracted English Content:', enContent.slice(0, 500) + '...'); // Log first 500 chars
427
- console.log('βœ… [MATCH SUCCESS] Extracted Portuguese Content:', ptContent.slice(0, 500) + '...'); // Log first 500 chars
434
+ console.log('βœ… [MATCH SUCCESS] Extracted English Content:', enContent.slice(0, 500) + '...');
435
+ console.log('βœ… [MATCH SUCCESS] Extracted Portuguese Content:', ptContent.slice(0, 500) + '...');
428
436
 
429
- // βœ… Function to clean AI artifacts (*, extra spaces, etc.)
430
- function cleanText(text: string): string {
431
- return text.replace(/\*/g, '').trim();
432
- }
433
-
434
- // βœ… Function to extract structured sections from text
437
+ // βœ… Step 3: Extract structured sections
435
438
  function extractSections(text: string, sectionTitles: string[]) {
436
439
  return sectionTitles.map((title) => {
437
440
  console.log(`πŸ” [PROCESSING] Extracting section: "${title}"`);
438
441
 
439
- // βœ… Improved regex: Ensures section detection even with different AI formatting
442
+ // βœ… Improved regex: Detects sections even if AI formatting changes
440
443
  const regex = new RegExp(`\\d+\\.\\s*${title}:\\s*([\\s\\S]+?)(?=\\n\\d+\\.\\s*[A-Z]|$)`);
441
444
  const match = text.match(regex);
442
445
 
@@ -449,7 +452,7 @@ export class ConceptService {
449
452
  const paragraphs = match[1]
450
453
  .trim()
451
454
  .split(/\n{2,}/) // Handles cases where paragraphs are separated by multiple new lines
452
- .map((p) => cleanText(p))
455
+ .map((p) => p.trim())
453
456
  .filter((p) => p.length > 0); // Removes empty paragraphs
454
457
 
455
458
  console.log(`βœ… [EXTRACTED] "${title}" - Parsed Content:`, paragraphs);
@@ -472,7 +475,6 @@ export class ConceptService {
472
475
  structuredContentPT,
473
476
  };
474
477
  }
475
-
476
478
  /**
477
479
  * Queue image generation for a concept.
478
480
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zodic/shared",
3
- "version": "0.0.151",
3
+ "version": "0.0.152",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "publishConfig": {