@zodic/shared 0.0.150 β†’ 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.
package/app/api/index.ts CHANGED
@@ -38,7 +38,7 @@ export const Api = (env: BackendBindings) => ({
38
38
  callTogether: {
39
39
  single: async (
40
40
  messages: ChatMessages,
41
- { model = 'deepseek-ai/DeepSeek-V3', options = {} }: DeepSeekOptions
41
+ { model = 'deepseek-ai/DeepSeek-V3', options = { } }: DeepSeekOptions
42
42
  ): Promise<string> => {
43
43
  try {
44
44
  const response = await together(env).chat.completions.create({
@@ -392,7 +392,16 @@ export class ConceptService {
392
392
  structuredContentEN: StructuredConceptContent;
393
393
  structuredContentPT: StructuredConceptContent;
394
394
  } {
395
- console.log('πŸ“Œ Parsing structured content from ChatGPT response:', response);
395
+ console.log('πŸ“Œ [START] Parsing structured content from ChatGPT 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) + '...');
396
405
 
397
406
  const sectionsEN = [
398
407
  'Core Identity',
@@ -410,32 +419,32 @@ export class ConceptService {
410
419
  'VisΓ£o e AspiraΓ§Γ΅es',
411
420
  ];
412
421
 
413
- // βœ… Match English and Portuguese content separately
414
- const enMatches = response.match(/EN:\s*([\s\S]+?)\s*PT:/);
415
- 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]+)/);
416
425
 
417
426
  if (!enMatches || !ptMatches) {
418
- console.error('❌ Missing English or Portuguese content in response.');
427
+ console.error('❌ [ERROR] Missing English or Portuguese content in response.');
419
428
  throw new Error('❌ Missing English or Portuguese content in response.');
420
429
  }
421
430
 
422
431
  const enContent = enMatches[1].trim();
423
432
  const ptContent = ptMatches[1].trim();
424
433
 
425
- // βœ… Function to clean AI artifacts (removes * and trims text)
426
- function cleanText(text: string): string {
427
- return text.replace(/\*/g, '').trim();
428
- }
434
+ console.log('βœ… [MATCH SUCCESS] Extracted English Content:', enContent.slice(0, 500) + '...');
435
+ console.log('βœ… [MATCH SUCCESS] Extracted Portuguese Content:', ptContent.slice(0, 500) + '...');
429
436
 
430
- // βœ… Function to extract structured sections from text
437
+ // βœ… Step 3: Extract structured sections
431
438
  function extractSections(text: string, sectionTitles: string[]) {
432
439
  return sectionTitles.map((title) => {
433
- // βœ… Improved regex: Ensures section detection even with different AI formatting
434
- const regex = new RegExp(`${title}:\\s*([\\s\\S]+?)(?=\\n\\d|\\n[A-Z]|$)`);
440
+ console.log(`πŸ” [PROCESSING] Extracting section: "${title}"`);
441
+
442
+ // βœ… Improved regex: Detects sections even if AI formatting changes
443
+ const regex = new RegExp(`\\d+\\.\\s*${title}:\\s*([\\s\\S]+?)(?=\\n\\d+\\.\\s*[A-Z]|$)`);
435
444
  const match = text.match(regex);
436
445
 
437
446
  if (!match) {
438
- console.warn(`⚠️ Missing section: ${title}`);
447
+ console.warn(`⚠️ [WARNING] Missing section: "${title}"`);
439
448
  return { type: 'section', title, content: ['❌ Section Missing'] };
440
449
  }
441
450
 
@@ -443,19 +452,29 @@ export class ConceptService {
443
452
  const paragraphs = match[1]
444
453
  .trim()
445
454
  .split(/\n{2,}/) // Handles cases where paragraphs are separated by multiple new lines
446
- .map((p) => cleanText(p));
455
+ .map((p) => p.trim())
456
+ .filter((p) => p.length > 0); // Removes empty paragraphs
457
+
458
+ console.log(`βœ… [EXTRACTED] "${title}" - Parsed Content:`, paragraphs);
447
459
 
448
460
  return { type: 'section', title, content: paragraphs };
449
461
  });
450
462
  }
451
463
 
452
464
  // βœ… Return parsed and cleaned structured content
465
+ const structuredContentEN = extractSections(enContent, sectionsEN);
466
+ const structuredContentPT = extractSections(ptContent, sectionsPT);
467
+
468
+ console.log('🎯 [FINAL RESULT] Parsed English Content:', JSON.stringify(structuredContentEN, null, 2));
469
+ console.log('🎯 [FINAL RESULT] Parsed Portuguese Content:', JSON.stringify(structuredContentPT, null, 2));
470
+
471
+ console.log('βœ… [COMPLETE] Structured content parsing finished successfully.');
472
+
453
473
  return {
454
- structuredContentEN: extractSections(enContent, sectionsEN),
455
- structuredContentPT: extractSections(ptContent, sectionsPT),
474
+ structuredContentEN,
475
+ structuredContentPT,
456
476
  };
457
477
  }
458
-
459
478
  /**
460
479
  * Queue image generation for a concept.
461
480
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zodic/shared",
3
- "version": "0.0.150",
3
+ "version": "0.0.152",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "publishConfig": {