@zodic/shared 0.0.307 → 0.0.308
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,4 +1,3 @@
|
|
|
1
|
-
|
|
2
1
|
import { and, eq, sql } from 'drizzle-orm';
|
|
3
2
|
import { inject, injectable } from 'inversify';
|
|
4
3
|
import { ChatMessages, Composition, schema } from '../..';
|
|
@@ -313,7 +312,8 @@ export class ArchetypeService {
|
|
|
313
312
|
return;
|
|
314
313
|
}
|
|
315
314
|
|
|
316
|
-
const { english: englishNames, portuguese: portugueseVariants } =
|
|
315
|
+
const { english: englishNames, portuguese: portugueseVariants } =
|
|
316
|
+
this.parseArchetypeNameBlocks(response);
|
|
317
317
|
|
|
318
318
|
async function isEnglishNameDuplicate(name: string): Promise<boolean> {
|
|
319
319
|
const result = await db
|
|
@@ -610,7 +610,12 @@ export class ArchetypeService {
|
|
|
610
610
|
return;
|
|
611
611
|
}
|
|
612
612
|
|
|
613
|
-
|
|
613
|
+
// Clean up the response by removing unexpected suffixes
|
|
614
|
+
const cleanedResponse = response
|
|
615
|
+
.replace(/###|---\s*###|-\s*###/g, '')
|
|
616
|
+
.trim();
|
|
617
|
+
|
|
618
|
+
const blocks = cleanedResponse
|
|
614
619
|
.split(/Composition \d+/)
|
|
615
620
|
.slice(1)
|
|
616
621
|
.map((b) => b.trim());
|
|
@@ -623,13 +628,13 @@ export class ArchetypeService {
|
|
|
623
628
|
|
|
624
629
|
console.log(`🔄 [Batch] Processing: ${combination}`);
|
|
625
630
|
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
console.error(`❌ [Batch] Parsing failed for: ${combination}
|
|
631
|
+
const { english, portuguese } = this.parseArchetypeNameBlocks(block);
|
|
632
|
+
|
|
633
|
+
if (
|
|
634
|
+
english.length !== indexes.length ||
|
|
635
|
+
portuguese.length !== indexes.length
|
|
636
|
+
) {
|
|
637
|
+
console.error(`❌ [Batch] Parsing failed for: ${combination}`);
|
|
633
638
|
await this.context
|
|
634
639
|
.drizzle()
|
|
635
640
|
.insert(schema.archetypeNameDumps)
|
|
@@ -643,37 +648,27 @@ export class ArchetypeService {
|
|
|
643
648
|
continue;
|
|
644
649
|
}
|
|
645
650
|
|
|
646
|
-
const english = en
|
|
647
|
-
.split(/\n\d\.\s*\n?/)
|
|
648
|
-
.filter(Boolean)
|
|
649
|
-
.map((line) => ({
|
|
650
|
-
name: line.match(/• Name:\s*(.+)/)?.[1]?.trim() || '',
|
|
651
|
-
essenceLine: line.match(/• Essence:\s*(.+)/)?.[1]?.trim() || '',
|
|
652
|
-
}));
|
|
653
|
-
|
|
654
|
-
const portuguese = pt
|
|
655
|
-
.split(/\n\d\.\s*\n?/)
|
|
656
|
-
.filter(Boolean)
|
|
657
|
-
.map((line) => ({
|
|
658
|
-
masc: line.match(/• Masculino:\s*(.+)/)?.[1]?.trim() || '',
|
|
659
|
-
fem: line.match(/• Feminino:\s*(.+)/)?.[1]?.trim() || '',
|
|
660
|
-
essenceLine: line.match(/• Essência:\s*(.+)/)?.[1]?.trim() || '',
|
|
661
|
-
}));
|
|
662
|
-
|
|
663
651
|
for (const index of indexes) {
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
652
|
+
const idx = index - 1;
|
|
653
|
+
const englishEntry = english[idx];
|
|
654
|
+
const ptEntry = portuguese[idx];
|
|
655
|
+
|
|
656
|
+
if (!englishEntry || !ptEntry) {
|
|
657
|
+
await this.context
|
|
658
|
+
.drizzle()
|
|
659
|
+
.insert(schema.archetypeNameDumps)
|
|
660
|
+
.values({
|
|
661
|
+
id: `${combination}:${index}:${Date.now()}`,
|
|
662
|
+
combination,
|
|
663
|
+
rawText: block,
|
|
664
|
+
parsedSuccessfully: 0,
|
|
665
|
+
createdAt: Date.now(),
|
|
666
|
+
});
|
|
667
|
+
console.warn(
|
|
668
|
+
`⚠️ [Batch] Skipping index ${index} for ${combination} due to missing parsed block`
|
|
669
|
+
);
|
|
673
670
|
continue;
|
|
674
671
|
}
|
|
675
|
-
const englishEntry = english[index - 1];
|
|
676
|
-
const ptEntry = portuguese[index - 1];
|
|
677
672
|
|
|
678
673
|
for (const gender of ['male', 'female']) {
|
|
679
674
|
const enId = `${combination}:${gender}:${index}`;
|
|
@@ -737,11 +732,13 @@ export class ArchetypeService {
|
|
|
737
732
|
`🎉 [Batch] Completed regenerating ${compositions.length} combinations`
|
|
738
733
|
);
|
|
739
734
|
}
|
|
740
|
-
|
|
735
|
+
|
|
741
736
|
async fetchMissingArchetypeCompositions(): Promise<Composition[]> {
|
|
742
737
|
const db = this.context.drizzle();
|
|
743
738
|
const incomplete = await this.findIncompleteCombinations();
|
|
744
|
-
console.log(
|
|
739
|
+
console.log(
|
|
740
|
+
`🔎 [Fetch] Retrieved ${incomplete.length} incomplete combinations`
|
|
741
|
+
);
|
|
745
742
|
const limited = incomplete.slice(0, 400);
|
|
746
743
|
|
|
747
744
|
const compositions: Composition[] = [];
|
|
@@ -776,13 +773,18 @@ export class ArchetypeService {
|
|
|
776
773
|
moon,
|
|
777
774
|
indexesToGenerate,
|
|
778
775
|
});
|
|
779
|
-
console.log(
|
|
776
|
+
console.log(
|
|
777
|
+
`✅ [Fetch] Will regenerate indexes [${indexesToGenerate.join(
|
|
778
|
+
', '
|
|
779
|
+
)}] for ${combination}`
|
|
780
|
+
);
|
|
780
781
|
}
|
|
781
782
|
}
|
|
782
783
|
|
|
783
|
-
console.log(
|
|
784
|
-
|
|
785
|
-
|
|
784
|
+
console.log(
|
|
785
|
+
`📦 [Fetch] Total compositions to regenerate (limited to 400): ${compositions.length}`
|
|
786
|
+
);
|
|
787
|
+
|
|
786
788
|
return compositions;
|
|
787
789
|
}
|
|
788
790
|
|
|
@@ -794,43 +796,69 @@ export class ArchetypeService {
|
|
|
794
796
|
english: [] as { name: string; essenceLine: string }[],
|
|
795
797
|
portuguese: [] as { masc: string; fem: string; essenceLine: string }[],
|
|
796
798
|
};
|
|
797
|
-
|
|
799
|
+
|
|
798
800
|
try {
|
|
799
|
-
|
|
800
|
-
const
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
801
|
+
// Normalize the block by replacing multiple spaces with a single space and ensuring newlines
|
|
802
|
+
const normalizedBlock = block
|
|
803
|
+
.replace(/\s+/g, ' ')
|
|
804
|
+
.replace(/-EN\s*/, '-EN\n')
|
|
805
|
+
.replace(/-PT\s*/, '\n-PT\n')
|
|
806
|
+
.trim();
|
|
807
|
+
|
|
808
|
+
// Split into EN and PT sections
|
|
809
|
+
const sections = normalizedBlock.split(/\n?-PT\n/);
|
|
810
|
+
const enSection = sections[0]?.replace(/-EN\n/, '').trim() ?? '';
|
|
811
|
+
const ptSection = sections[1]?.trim() ?? '';
|
|
812
|
+
|
|
813
|
+
// Parse English entries
|
|
814
|
+
result.english = enSection
|
|
815
|
+
.split(/\n?\d+\.\s*\n?/)
|
|
807
816
|
.filter(Boolean)
|
|
808
817
|
.map((entry, i) => {
|
|
809
|
-
const
|
|
810
|
-
const
|
|
818
|
+
const nameMatch = entry.match(/• Name:\s*([^•]+)/);
|
|
819
|
+
const essenceMatch = entry.match(/• Essence:\s*([^•]+)/);
|
|
820
|
+
const name = nameMatch?.[1]?.trim() ?? '';
|
|
821
|
+
const essenceLine = essenceMatch?.[1]?.trim() ?? '';
|
|
811
822
|
if (!name || !essenceLine) {
|
|
812
|
-
console.warn(
|
|
823
|
+
console.warn(
|
|
824
|
+
`⚠️ [Parse] Incomplete English entry ${i + 1}:`,
|
|
825
|
+
entry
|
|
826
|
+
);
|
|
813
827
|
}
|
|
814
828
|
return { name, essenceLine };
|
|
815
829
|
});
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
830
|
+
|
|
831
|
+
// Parse Portuguese entries
|
|
832
|
+
result.portuguese = ptSection
|
|
833
|
+
.split(/\n?\d+\.\s*\n?/)
|
|
819
834
|
.filter(Boolean)
|
|
820
835
|
.map((entry, i) => {
|
|
821
|
-
const
|
|
822
|
-
const
|
|
823
|
-
const
|
|
836
|
+
const mascMatch = entry.match(/• Masculino:\s*([^•]+)/);
|
|
837
|
+
const femMatch = entry.match(/• Feminino:\s*([^•]+)/);
|
|
838
|
+
const essenceMatch = entry.match(/• Essência:\s*([^•]+)/);
|
|
839
|
+
const masc = mascMatch?.[1]?.trim() ?? '';
|
|
840
|
+
const fem = femMatch?.[1]?.trim() ?? '';
|
|
841
|
+
const essenceLine = essenceMatch?.[1]?.trim() ?? '';
|
|
824
842
|
if (!masc || !fem || !essenceLine) {
|
|
825
|
-
console.warn(
|
|
843
|
+
console.warn(
|
|
844
|
+
`⚠️ [Parse] Incomplete Portuguese entry ${i + 1}:`,
|
|
845
|
+
entry
|
|
846
|
+
);
|
|
847
|
+
}
|
|
848
|
+
// Validate gender consistency
|
|
849
|
+
if (masc.startsWith('A ') && fem.startsWith('O ')) {
|
|
850
|
+
console.warn(
|
|
851
|
+
`⚠️ [Parse] Gender mismatch in Portuguese entry ${i + 1}:`,
|
|
852
|
+
entry
|
|
853
|
+
);
|
|
854
|
+
return { masc: fem, fem: masc, essenceLine }; // Swap to correct the mismatch
|
|
826
855
|
}
|
|
827
856
|
return { masc, fem, essenceLine };
|
|
828
857
|
});
|
|
829
|
-
|
|
830
858
|
} catch (error) {
|
|
831
859
|
console.error('❌ [Parse] Failed to parse block:', error);
|
|
832
860
|
}
|
|
833
|
-
|
|
861
|
+
|
|
834
862
|
return result;
|
|
835
863
|
}
|
|
836
864
|
}
|
package/package.json
CHANGED
|
@@ -211,6 +211,14 @@ 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
|
+
**Formatting Rules**:
|
|
215
|
+
- Each composition block must start with "Composition <number>" on its own line.
|
|
216
|
+
- Within each composition block, the English section must start with "-EN" on its own line, followed by the entries.
|
|
217
|
+
- The Portuguese section must start with "-PT" on its own line, followed by the entries.
|
|
218
|
+
- Each entry (e.g., "1.", "2.", "3.") must be on its own line, with its sub-items (e.g., "• Name: ...", "• Masculino: ...") on separate lines.
|
|
219
|
+
- Do not include any extra characters, suffixes, or separators (e.g., "###", "---", or extra newlines) at the end of the response or between composition blocks.
|
|
220
|
+
- Ensure that Portuguese names correctly match the gender: "Masculino" names should use masculine forms (e.g., "O Sábio"), and "Feminino" names should use feminine forms (e.g., "A Sábia").
|
|
221
|
+
|
|
214
222
|
Do not include any commentary or explanations outside the defined output structure. Only return the output block for each composition, exactly as described:`;
|
|
215
223
|
|
|
216
224
|
const compositionBlocks = compositions.map((comp, i) => {
|
|
@@ -219,7 +227,7 @@ Do not include any commentary or explanations outside the defined output structu
|
|
|
219
227
|
const moon = influenceMap.moon[comp.moon];
|
|
220
228
|
const indexes = comp.indexesToGenerate ?? [1, 2, 3];
|
|
221
229
|
|
|
222
|
-
const influences = `\n\
|
|
230
|
+
const influences = `\n\nComposition ${i + 1}
|
|
223
231
|
|
|
224
232
|
• First Influence – ${sun.label}: ${sun.description}
|
|
225
233
|
• Second Influence – ${asc.label}: ${asc.description}
|
|
@@ -228,28 +236,28 @@ Do not include any commentary or explanations outside the defined output structu
|
|
|
228
236
|
const enLines = indexes
|
|
229
237
|
.map(
|
|
230
238
|
(idx) => `${idx}.
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
239
|
+
• Name: [Name that emphasizes the ${
|
|
240
|
+
['first', 'second', 'third'][idx - 1]
|
|
241
|
+
} influence, while blending the other two]
|
|
242
|
+
• Essence: [Short poetic description line in English]`
|
|
235
243
|
)
|
|
236
244
|
.join('\n');
|
|
237
245
|
|
|
238
246
|
const ptLines = indexes
|
|
239
247
|
.map(
|
|
240
248
|
(idx) => `${idx}.
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
249
|
+
• Masculino: [Portuguese name (masc)]
|
|
250
|
+
• Feminino: [Portuguese name (fem)]
|
|
251
|
+
• Essência: [Short poetic description line in Portuguese]`
|
|
244
252
|
)
|
|
245
253
|
.join('\n');
|
|
246
254
|
|
|
247
255
|
return `${influences}
|
|
248
256
|
|
|
249
|
-
\`\n-EN
|
|
257
|
+
\`\n-EN
|
|
250
258
|
${enLines}
|
|
251
259
|
|
|
252
|
-
-PT
|
|
260
|
+
-PT
|
|
253
261
|
${ptLines}
|
|
254
262
|
\``;
|
|
255
263
|
});
|