@zodic/shared 0.0.305 → 0.0.307

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.
@@ -1,3 +1,4 @@
1
+
1
2
  import { and, eq, sql } from 'drizzle-orm';
2
3
  import { inject, injectable } from 'inversify';
3
4
  import { ChatMessages, Composition, schema } from '../..';
@@ -312,44 +313,7 @@ export class ArchetypeService {
312
313
  return;
313
314
  }
314
315
 
315
- let blocks: string[] = [];
316
- let ptBlocks: string[] = [];
317
-
318
- try {
319
- blocks = response
320
- .split('-EN')[1]
321
- .split('-PT')[0]
322
- .trim()
323
- .split(/\n\d\.\s*\n?/)
324
- .filter(Boolean);
325
-
326
- ptBlocks = response
327
- .split('-PT')[1]
328
- .trim()
329
- .split(/\n\d\.\s*\n?/)
330
- .filter(Boolean);
331
- } catch (err) {
332
- console.error(`❌ [Single] Parsing failed for ${combination}`, err);
333
- await db.insert(schema.archetypeNameDumps).values({
334
- id: combination,
335
- combination,
336
- rawText: response,
337
- parsedSuccessfully: 0,
338
- createdAt: Date.now(),
339
- });
340
- return;
341
- }
342
-
343
- const englishNames = blocks.map((block) => ({
344
- name: block.match(/• Name:\s*(.+)/)?.[1]?.trim() || '',
345
- essenceLine: block.match(/• Essence:\s*(.+)/)?.[1]?.trim() || '',
346
- }));
347
-
348
- const portugueseVariants = ptBlocks.map((block) => ({
349
- masc: block.match(/• Masculino:\s*(.+)/)?.[1]?.trim() || '',
350
- fem: block.match(/• Feminino:\s*(.+)/)?.[1]?.trim() || '',
351
- essenceLine: block.match(/• Essência:\s*(.+)/)?.[1]?.trim() || '',
352
- }));
316
+ const { english: englishNames, portuguese: portugueseVariants } = this.parseArchetypeNameBlocks(response);
353
317
 
354
318
  async function isEnglishNameDuplicate(name: string): Promise<boolean> {
355
319
  const result = await db
@@ -483,39 +447,7 @@ export class ArchetypeService {
483
447
  const block = blocks[i];
484
448
  console.log(`📦 [Batch] Processing: ${combination}`);
485
449
 
486
- let en = '';
487
- let pt = '';
488
- try {
489
- en = block.split('-EN')[1].split('-PT')[0].trim();
490
- pt = block.split('-PT')[1].trim();
491
- } catch (err) {
492
- console.error(`❌ [Batch] Parsing failed for: ${combination}`, err);
493
- await db.insert(schema.archetypeNameDumps).values({
494
- id: combination,
495
- combination,
496
- rawText: block,
497
- parsedSuccessfully: 0,
498
- createdAt: Date.now(),
499
- });
500
- continue;
501
- }
502
-
503
- const english = en
504
- .split(/\n\d\.\s*\n?/)
505
- .filter(Boolean)
506
- .map((line) => ({
507
- name: line.match(/• Name:\s*(.+)/)?.[1]?.trim() || '',
508
- essenceLine: line.match(/• Essence:\s*(.+)/)?.[1]?.trim() || '',
509
- }));
510
-
511
- const portuguese = pt
512
- .split(/\n\d\.\s*\n?/)
513
- .filter(Boolean)
514
- .map((line) => ({
515
- masc: line.match(/• Masculino:\s*(.+)/)?.[1]?.trim() || '',
516
- fem: line.match(/• Feminino:\s*(.+)/)?.[1]?.trim() || '',
517
- essenceLine: line.match(/• Essência:\s*(.+)/)?.[1]?.trim() || '',
518
- }));
450
+ const { english, portuguese } = this.parseArchetypeNameBlocks(block);
519
451
 
520
452
  for (let j = 0; j < 3; j++) {
521
453
  const index = (j + 1).toString();
@@ -729,6 +661,17 @@ export class ArchetypeService {
729
661
  }));
730
662
 
731
663
  for (const index of indexes) {
664
+ if (!english[index - 1] || !portuguese[index - 1]) {
665
+ await this.context.drizzle().insert(schema.archetypeNameDumps).values({
666
+ id: `${combination}:${index}:${Date.now()}`,
667
+ combination,
668
+ rawText: block,
669
+ parsedSuccessfully: 0,
670
+ createdAt: Date.now(),
671
+ });
672
+ console.warn(`⚠️ [Batch] Skipping index ${index} for ${combination} due to missing parsed block`);
673
+ continue;
674
+ }
732
675
  const englishEntry = english[index - 1];
733
676
  const ptEntry = portuguese[index - 1];
734
677
 
@@ -842,4 +785,52 @@ export class ArchetypeService {
842
785
 
843
786
  return compositions;
844
787
  }
788
+
789
+ private parseArchetypeNameBlocks(block: string): {
790
+ english: { name: string; essenceLine: string }[];
791
+ portuguese: { masc: string; fem: string; essenceLine: string }[];
792
+ } {
793
+ const result = {
794
+ english: [] as { name: string; essenceLine: string }[],
795
+ portuguese: [] as { masc: string; fem: string; essenceLine: string }[],
796
+ };
797
+
798
+ try {
799
+ const enMatch = block.match(/-EN[\s\S]*?-PT/);
800
+ const ptMatch = block.match(/-PT[\s\S]*/);
801
+
802
+ const enBlock = enMatch?.[0].replace(/-EN/, '').replace(/-PT/, '').trim() ?? '';
803
+ const ptBlock = ptMatch?.[0].replace(/-PT/, '').trim() ?? '';
804
+
805
+ result.english = enBlock
806
+ .split(/\n\d\.\s*\n?/)
807
+ .filter(Boolean)
808
+ .map((entry, i) => {
809
+ const name = entry.match(/• Name:\s*(.+)/)?.[1]?.trim() ?? '';
810
+ const essenceLine = entry.match(/• Essence:\s*(.+)/)?.[1]?.trim() ?? '';
811
+ if (!name || !essenceLine) {
812
+ console.warn(`⚠️ [Parse] Incomplete English entry ${i + 1}:`, entry);
813
+ }
814
+ return { name, essenceLine };
815
+ });
816
+
817
+ result.portuguese = ptBlock
818
+ .split(/\n\d\.\s*\n?/)
819
+ .filter(Boolean)
820
+ .map((entry, i) => {
821
+ const masc = entry.match(/• Masculino:\s*(.+)/)?.[1]?.trim() ?? '';
822
+ const fem = entry.match(/• Feminino:\s*(.+)/)?.[1]?.trim() ?? '';
823
+ const essenceLine = entry.match(/• Essência:\s*(.+)/)?.[1]?.trim() ?? '';
824
+ if (!masc || !fem || !essenceLine) {
825
+ console.warn(`⚠️ [Parse] Incomplete Portuguese entry ${i + 1}:`, entry);
826
+ }
827
+ return { masc, fem, essenceLine };
828
+ });
829
+
830
+ } catch (error) {
831
+ console.error('❌ [Parse] Failed to parse block:', error);
832
+ }
833
+
834
+ return result;
835
+ }
845
836
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zodic/shared",
3
- "version": "0.0.305",
3
+ "version": "0.0.307",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -211,7 +211,7 @@ For every composition, return:
211
211
  Avoid names that sound like objects, titles, or abstract forces (e.g., The Lantern, The Eclipse, The Veil).
212
212
  Instead, use names that suggest a personified being or living archetype, such as The Masked Oracle, The Starborn Seeker, or The Dancer of the Falling Sky.
213
213
 
214
- Do not include any commentary or explanations outside the defined output structure. Only return the output block for each composition.`;
214
+ Do not include any commentary or explanations outside the defined output structure. Only return the output block for each composition, exactly as described:`;
215
215
 
216
216
  const compositionBlocks = compositions.map((comp, i) => {
217
217
  const sun = influenceMap.sun[comp.sun];