@zodic/shared 0.0.149 → 0.0.151

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({
@@ -155,34 +155,38 @@ export class ConceptService {
155
155
  poemPT: string[];
156
156
  } {
157
157
  console.log('📌 Parsing basic info response from ChatGPT:', response);
158
-
158
+
159
159
  const enMatch = response.match(
160
160
  /EN:\s*•\s*Name:\s*(.+?)\s*•\s*Description:\s*([\s\S]+?)\s*•\s*Poetic Passage:\s*([\s\S]+?)\s*(?=PT:|$)/
161
161
  );
162
162
  const ptMatch = response.match(
163
163
  /PT:\s*•\s*Nome:\s*(.+?)\s*•\s*Descrição:\s*([\s\S]+?)\s*•\s*Passagem Poética:\s*([\s\S]+)/
164
164
  );
165
-
165
+
166
166
  if (!enMatch || !ptMatch) {
167
167
  console.error('❌ Invalid basic info response format:', response);
168
168
  throw new Error('Invalid basic info response format');
169
169
  }
170
-
171
- const nameEN = enMatch[1].trim();
172
- const descriptionEN = enMatch[2].trim();
170
+
171
+ // Function to clean text (removes leading/trailing spaces & unwanted "*")
172
+ const cleanText = (text: string) => text.trim().replace(/\*/g, '');
173
+
174
+ // ✅ Parse and clean extracted content
175
+ const nameEN = cleanText(enMatch[1]);
176
+ const descriptionEN = cleanText(enMatch[2]);
173
177
  const poemEN = enMatch[3]
174
178
  .trim()
175
179
  .split(/\n+/)
176
- .map((line) => line.trim()); // ✅ Split into array
177
-
178
- const namePT = ptMatch[1].trim();
179
- const descriptionPT = ptMatch[2].trim();
180
+ .map((line) => cleanText(line)); // ✅ Split into array & clean lines
181
+
182
+ const namePT = cleanText(ptMatch[1]);
183
+ const descriptionPT = cleanText(ptMatch[2]);
180
184
  const poemPT = ptMatch[3]
181
185
  .trim()
182
186
  .split(/\n+/)
183
- .map((line) => line.trim()); // ✅ Split into array
184
-
185
- console.log('✅ Successfully parsed basic info:', {
187
+ .map((line) => cleanText(line)); // ✅ Split into array & clean lines
188
+
189
+ console.log('✅ Successfully parsed and cleaned basic info:', {
186
190
  nameEN,
187
191
  descriptionEN,
188
192
  poemEN,
@@ -190,7 +194,7 @@ export class ConceptService {
190
194
  descriptionPT,
191
195
  poemPT,
192
196
  });
193
-
197
+
194
198
  return { nameEN, descriptionEN, poemEN, namePT, descriptionPT, poemPT };
195
199
  }
196
200
 
@@ -388,19 +392,17 @@ export class ConceptService {
388
392
  structuredContentEN: StructuredConceptContent;
389
393
  structuredContentPT: StructuredConceptContent;
390
394
  } {
391
- console.log(
392
- '📌 Parsing structured content from ChatGPT response:',
393
- response
394
- );
395
-
396
- const sections = [
395
+ console.log('📌 [START] Parsing structured content from ChatGPT response.');
396
+ console.log('🔹 [RAW RESPONSE]:', response);
397
+
398
+ const sectionsEN = [
397
399
  'Core Identity',
398
400
  'Strengths and Challenges',
399
401
  'Path to Fulfillment',
400
402
  'Emotional Depth',
401
403
  'Vision and Aspirations',
402
404
  ];
403
-
405
+
404
406
  const sectionsPT = [
405
407
  'Identidade Essencial',
406
408
  'Forças e Desafios',
@@ -408,40 +410,66 @@ export class ConceptService {
408
410
  'Profundidade Emocional',
409
411
  'Visão e Aspirações',
410
412
  ];
411
-
413
+
412
414
  // ✅ Match English and Portuguese content separately
413
- const enMatches = response.match(/EN:\s*([\s\S]+?)\s*PT:/);
414
- const ptMatches = response.match(/PT:\s*([\s\S]+)/);
415
-
415
+ const enMatches = response.match(/### EN:\s*([\s\S]+?)\s*### PT:/);
416
+ const ptMatches = response.match(/### PT:\s*([\s\S]+)/);
417
+
416
418
  if (!enMatches || !ptMatches) {
419
+ console.error('❌ [ERROR] Missing English or Portuguese content in response.');
417
420
  throw new Error('❌ Missing English or Portuguese content in response.');
418
421
  }
419
-
422
+
420
423
  const enContent = enMatches[1].trim();
421
424
  const ptContent = ptMatches[1].trim();
422
-
425
+
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
428
+
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
423
435
  function extractSections(text: string, sectionTitles: string[]) {
424
436
  return sectionTitles.map((title) => {
425
- const regex = new RegExp(`${title}:\\s*([\\s\\S]+?)(?=\\n\\d|$)`);
437
+ console.log(`🔍 [PROCESSING] Extracting section: "${title}"`);
438
+
439
+ // ✅ Improved regex: Ensures section detection even with different AI formatting
440
+ const regex = new RegExp(`\\d+\\.\\s*${title}:\\s*([\\s\\S]+?)(?=\\n\\d+\\.\\s*[A-Z]|$)`);
426
441
  const match = text.match(regex);
427
-
442
+
428
443
  if (!match) {
444
+ console.warn(`⚠️ [WARNING] Missing section: "${title}"`);
429
445
  return { type: 'section', title, content: ['❌ Section Missing'] };
430
446
  }
431
-
432
- // ✅ Split content into paragraphs
447
+
448
+ // ✅ Split content into paragraphs and clean them
433
449
  const paragraphs = match[1]
434
450
  .trim()
435
- .split(/\n\n+/)
436
- .map((p) => p.trim());
437
-
451
+ .split(/\n{2,}/) // Handles cases where paragraphs are separated by multiple new lines
452
+ .map((p) => cleanText(p))
453
+ .filter((p) => p.length > 0); // Removes empty paragraphs
454
+
455
+ console.log(`✅ [EXTRACTED] "${title}" - Parsed Content:`, paragraphs);
456
+
438
457
  return { type: 'section', title, content: paragraphs };
439
458
  });
440
459
  }
441
-
460
+
461
+ // ✅ Return parsed and cleaned structured content
462
+ const structuredContentEN = extractSections(enContent, sectionsEN);
463
+ const structuredContentPT = extractSections(ptContent, sectionsPT);
464
+
465
+ console.log('🎯 [FINAL RESULT] Parsed English Content:', JSON.stringify(structuredContentEN, null, 2));
466
+ console.log('🎯 [FINAL RESULT] Parsed Portuguese Content:', JSON.stringify(structuredContentPT, null, 2));
467
+
468
+ console.log('✅ [COMPLETE] Structured content parsing finished successfully.');
469
+
442
470
  return {
443
- structuredContentEN: extractSections(enContent, sections),
444
- structuredContentPT: extractSections(ptContent, sectionsPT),
471
+ structuredContentEN,
472
+ structuredContentPT,
445
473
  };
446
474
  }
447
475
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zodic/shared",
3
- "version": "0.0.149",
3
+ "version": "0.0.151",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "publishConfig": {