@zodic/shared 0.0.298 → 0.0.299
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/services/ArchetypeService.ts +127 -166
- package/package.json +1 -1
|
@@ -290,21 +290,21 @@ export class ArchetypeService {
|
|
|
290
290
|
overrideExisting: boolean = false
|
|
291
291
|
) {
|
|
292
292
|
const db = this.context.drizzle();
|
|
293
|
+
console.log(`🚀 [Single] Starting generation for combination: ${combination} | Override: ${overrideExisting}`);
|
|
294
|
+
|
|
293
295
|
const [sun, ascendant, moon] = combination.split('-') as ZodiacSignSlug[];
|
|
294
|
-
|
|
295
296
|
const prompt = generateArchetypePrompt([{ sun, ascendant, moon }]);
|
|
296
297
|
const messages: ChatMessages = [{ role: 'user', content: prompt }];
|
|
297
298
|
const response = await this.context.api().callTogether.single(messages, {});
|
|
298
|
-
|
|
299
|
+
|
|
299
300
|
if (!response) {
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
);
|
|
301
|
+
console.error(`❌ [Single] No response for: ${combination}`);
|
|
302
|
+
return;
|
|
303
303
|
}
|
|
304
|
-
|
|
304
|
+
|
|
305
305
|
let blocks: string[] = [];
|
|
306
306
|
let ptBlocks: string[] = [];
|
|
307
|
-
|
|
307
|
+
|
|
308
308
|
try {
|
|
309
309
|
blocks = response
|
|
310
310
|
.split('-EN')[1]
|
|
@@ -312,14 +312,14 @@ export class ArchetypeService {
|
|
|
312
312
|
.trim()
|
|
313
313
|
.split(/\n\d\.\s*\n?/)
|
|
314
314
|
.filter(Boolean);
|
|
315
|
-
|
|
315
|
+
|
|
316
316
|
ptBlocks = response
|
|
317
317
|
.split('-PT')[1]
|
|
318
318
|
.trim()
|
|
319
319
|
.split(/\n\d\.\s*\n?/)
|
|
320
320
|
.filter(Boolean);
|
|
321
321
|
} catch (err) {
|
|
322
|
-
console.error(
|
|
322
|
+
console.error(`❌ [Single] Parsing failed for ${combination}`, err);
|
|
323
323
|
await db.insert(schema.archetypeNameDumps).values({
|
|
324
324
|
id: combination,
|
|
325
325
|
combination,
|
|
@@ -329,24 +329,18 @@ export class ArchetypeService {
|
|
|
329
329
|
});
|
|
330
330
|
return;
|
|
331
331
|
}
|
|
332
|
-
|
|
333
|
-
const englishNames = blocks.map((block) => {
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
const fem = block.match(/• Feminino:\s*(.+)/)?.[1]?.trim() || '';
|
|
345
|
-
const essence = block.match(/• Essência:\s*(.+)/)?.[1]?.trim() || '';
|
|
346
|
-
return { masc, fem, essenceLine: essence };
|
|
347
|
-
});
|
|
348
|
-
|
|
349
|
-
// Duplicate helper
|
|
332
|
+
|
|
333
|
+
const englishNames = blocks.map((block) => ({
|
|
334
|
+
name: block.match(/• Name:\s*(.+)/)?.[1]?.trim() || '',
|
|
335
|
+
essenceLine: block.match(/• Essence:\s*(.+)/)?.[1]?.trim() || '',
|
|
336
|
+
}));
|
|
337
|
+
|
|
338
|
+
const portugueseVariants = ptBlocks.map((block) => ({
|
|
339
|
+
masc: block.match(/• Masculino:\s*(.+)/)?.[1]?.trim() || '',
|
|
340
|
+
fem: block.match(/• Feminino:\s*(.+)/)?.[1]?.trim() || '',
|
|
341
|
+
essenceLine: block.match(/• Essência:\s*(.+)/)?.[1]?.trim() || '',
|
|
342
|
+
}));
|
|
343
|
+
|
|
350
344
|
async function isEnglishNameDuplicate(name: string): Promise<boolean> {
|
|
351
345
|
const result = await db
|
|
352
346
|
.select({ name: schema.archetypesData.name })
|
|
@@ -359,85 +353,67 @@ export class ArchetypeService {
|
|
|
359
353
|
)
|
|
360
354
|
.limit(1)
|
|
361
355
|
.execute();
|
|
362
|
-
|
|
356
|
+
|
|
363
357
|
return result.length > 0;
|
|
364
358
|
}
|
|
365
|
-
|
|
359
|
+
|
|
366
360
|
await Promise.all(
|
|
367
361
|
englishNames.map(async (entry, i) => {
|
|
368
362
|
const index = (i + 1).toString();
|
|
369
363
|
const ptVariant = portugueseVariants[i];
|
|
370
|
-
|
|
364
|
+
|
|
371
365
|
if (await isEnglishNameDuplicate(entry.name)) {
|
|
372
|
-
console.warn(
|
|
366
|
+
console.warn(`⚠️ [Single] Duplicate name skipped: ${entry.name}`);
|
|
373
367
|
return;
|
|
374
368
|
}
|
|
375
|
-
|
|
369
|
+
|
|
376
370
|
for (const gender of ['male', 'female']) {
|
|
377
371
|
const enId = `${combination}:${gender}:${index}`;
|
|
378
372
|
const ptId = `${combination}:${gender}:${index}:pt`;
|
|
379
373
|
const ptName = gender === 'female' ? ptVariant.fem : ptVariant.masc;
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
.insert(schema.archetypesData)
|
|
419
|
-
.values({
|
|
420
|
-
id: ptId,
|
|
421
|
-
combination,
|
|
422
|
-
gender,
|
|
423
|
-
archetypeIndex: index,
|
|
424
|
-
language: 'pt-br',
|
|
425
|
-
name: ptName,
|
|
426
|
-
essenceLine: ptVariant.essenceLine,
|
|
427
|
-
status: 'idle',
|
|
428
|
-
})
|
|
429
|
-
.onConflictDoUpdate({
|
|
430
|
-
target: [schema.archetypesData.id],
|
|
431
|
-
set: {
|
|
432
|
-
name: ptName,
|
|
433
|
-
essenceLine: ptVariant.essenceLine,
|
|
434
|
-
updatedAt: new Date().getTime(),
|
|
435
|
-
},
|
|
436
|
-
});
|
|
437
|
-
}
|
|
374
|
+
|
|
375
|
+
await db.insert(schema.archetypesData).values({
|
|
376
|
+
id: enId,
|
|
377
|
+
combination,
|
|
378
|
+
gender,
|
|
379
|
+
archetypeIndex: index,
|
|
380
|
+
language: 'en-us',
|
|
381
|
+
name: entry.name,
|
|
382
|
+
essenceLine: entry.essenceLine,
|
|
383
|
+
status: 'idle',
|
|
384
|
+
}).onConflictDoUpdate({
|
|
385
|
+
target: [schema.archetypesData.id],
|
|
386
|
+
set: {
|
|
387
|
+
name: entry.name,
|
|
388
|
+
essenceLine: entry.essenceLine,
|
|
389
|
+
updatedAt: new Date().getTime(),
|
|
390
|
+
},
|
|
391
|
+
});
|
|
392
|
+
|
|
393
|
+
await db.insert(schema.archetypesData).values({
|
|
394
|
+
id: ptId,
|
|
395
|
+
combination,
|
|
396
|
+
gender,
|
|
397
|
+
archetypeIndex: index,
|
|
398
|
+
language: 'pt-br',
|
|
399
|
+
name: ptName,
|
|
400
|
+
essenceLine: ptVariant.essenceLine,
|
|
401
|
+
status: 'idle',
|
|
402
|
+
}).onConflictDoUpdate({
|
|
403
|
+
target: [schema.archetypesData.id],
|
|
404
|
+
set: {
|
|
405
|
+
name: ptName,
|
|
406
|
+
essenceLine: ptVariant.essenceLine,
|
|
407
|
+
updatedAt: new Date().getTime(),
|
|
408
|
+
},
|
|
409
|
+
});
|
|
410
|
+
|
|
411
|
+
console.log(`✅ [Single] Saved archetype ${index} (${gender}) for ${combination}`);
|
|
438
412
|
}
|
|
439
413
|
})
|
|
440
414
|
);
|
|
415
|
+
|
|
416
|
+
console.log(`🏁 [Single] Done generating names for ${combination}`);
|
|
441
417
|
}
|
|
442
418
|
|
|
443
419
|
async generateArchetypeNamesBatch(
|
|
@@ -445,25 +421,27 @@ export class ArchetypeService {
|
|
|
445
421
|
overrideExisting: boolean = false
|
|
446
422
|
) {
|
|
447
423
|
const db = this.context.drizzle();
|
|
448
|
-
|
|
424
|
+
console.log(`🚀 [Batch] Starting generation for ${entries.length} combinations | Override: ${overrideExisting}`);
|
|
425
|
+
|
|
449
426
|
const prompts = entries.map(({ combination }) => {
|
|
450
427
|
const [sun, ascendant, moon] = combination.split('-') as ZodiacSignSlug[];
|
|
451
428
|
return { sun, ascendant, moon };
|
|
452
429
|
});
|
|
453
|
-
|
|
430
|
+
|
|
454
431
|
const prompt = generateArchetypePrompt(prompts);
|
|
455
432
|
const messages: ChatMessages = [{ role: 'user', content: prompt }];
|
|
456
433
|
const response = await this.context.api().callTogether.single(messages, {});
|
|
457
|
-
|
|
434
|
+
|
|
458
435
|
if (!response) {
|
|
459
|
-
|
|
436
|
+
console.error(`❌ [Batch] No response from model`);
|
|
437
|
+
return;
|
|
460
438
|
}
|
|
461
|
-
|
|
439
|
+
|
|
462
440
|
const blocks = response
|
|
463
441
|
.split(/Composition \d+/)
|
|
464
442
|
.slice(1)
|
|
465
443
|
.map((b) => b.trim());
|
|
466
|
-
|
|
444
|
+
|
|
467
445
|
async function isEnglishNameDuplicate(name: string): Promise<boolean> {
|
|
468
446
|
const result = await db
|
|
469
447
|
.select({ name: schema.archetypesData.name })
|
|
@@ -476,21 +454,22 @@ export class ArchetypeService {
|
|
|
476
454
|
)
|
|
477
455
|
.limit(1)
|
|
478
456
|
.execute();
|
|
479
|
-
|
|
457
|
+
|
|
480
458
|
return result.length > 0;
|
|
481
459
|
}
|
|
482
|
-
|
|
460
|
+
|
|
483
461
|
for (let i = 0; i < entries.length; i++) {
|
|
484
462
|
const { combination } = entries[i];
|
|
485
463
|
const block = blocks[i];
|
|
486
|
-
|
|
464
|
+
console.log(`📦 [Batch] Processing: ${combination}`);
|
|
465
|
+
|
|
487
466
|
let en = '';
|
|
488
467
|
let pt = '';
|
|
489
468
|
try {
|
|
490
469
|
en = block.split('-EN')[1].split('-PT')[0].trim();
|
|
491
470
|
pt = block.split('-PT')[1].trim();
|
|
492
471
|
} catch (err) {
|
|
493
|
-
console.error(
|
|
472
|
+
console.error(`❌ [Batch] Parsing failed for: ${combination}`, err);
|
|
494
473
|
await db.insert(schema.archetypeNameDumps).values({
|
|
495
474
|
id: combination,
|
|
496
475
|
combination,
|
|
@@ -500,7 +479,7 @@ export class ArchetypeService {
|
|
|
500
479
|
});
|
|
501
480
|
continue;
|
|
502
481
|
}
|
|
503
|
-
|
|
482
|
+
|
|
504
483
|
const english = en
|
|
505
484
|
.split(/\n\d\.\s*\n?/)
|
|
506
485
|
.filter(Boolean)
|
|
@@ -508,7 +487,7 @@ export class ArchetypeService {
|
|
|
508
487
|
name: line.match(/• Name:\s*(.+)/)?.[1]?.trim() || '',
|
|
509
488
|
essenceLine: line.match(/• Essence:\s*(.+)/)?.[1]?.trim() || '',
|
|
510
489
|
}));
|
|
511
|
-
|
|
490
|
+
|
|
512
491
|
const portuguese = pt
|
|
513
492
|
.split(/\n\d\.\s*\n?/)
|
|
514
493
|
.filter(Boolean)
|
|
@@ -517,83 +496,65 @@ export class ArchetypeService {
|
|
|
517
496
|
fem: line.match(/• Feminino:\s*(.+)/)?.[1]?.trim() || '',
|
|
518
497
|
essenceLine: line.match(/• Essência:\s*(.+)/)?.[1]?.trim() || '',
|
|
519
498
|
}));
|
|
520
|
-
|
|
499
|
+
|
|
521
500
|
for (let j = 0; j < 3; j++) {
|
|
522
501
|
const index = (j + 1).toString();
|
|
523
502
|
const englishEntry = english[j];
|
|
524
503
|
const ptEntry = portuguese[j];
|
|
525
|
-
|
|
504
|
+
|
|
526
505
|
if (await isEnglishNameDuplicate(englishEntry.name)) {
|
|
527
|
-
console.warn(
|
|
528
|
-
`Duplicate English name "${englishEntry.name}" — skipping.`
|
|
529
|
-
);
|
|
506
|
+
console.warn(`⚠️ [Batch] Duplicate name skipped: ${englishEntry.name}`);
|
|
530
507
|
continue;
|
|
531
508
|
}
|
|
532
|
-
|
|
509
|
+
|
|
533
510
|
for (const gender of ['male', 'female']) {
|
|
534
511
|
const enId = `${combination}:${gender}:${index}`;
|
|
535
512
|
const ptId = `${combination}:${gender}:${index}:pt`;
|
|
536
513
|
const ptName = gender === 'female' ? ptEntry.fem : ptEntry.masc;
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
}
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
.insert(schema.archetypesData)
|
|
576
|
-
.values({
|
|
577
|
-
id: ptId,
|
|
578
|
-
combination,
|
|
579
|
-
gender,
|
|
580
|
-
archetypeIndex: index,
|
|
581
|
-
language: 'pt-br',
|
|
582
|
-
name: ptName,
|
|
583
|
-
essenceLine: ptEntry.essenceLine,
|
|
584
|
-
status: 'idle',
|
|
585
|
-
})
|
|
586
|
-
.onConflictDoUpdate({
|
|
587
|
-
target: [schema.archetypesData.id],
|
|
588
|
-
set: {
|
|
589
|
-
name: ptName,
|
|
590
|
-
essenceLine: ptEntry.essenceLine,
|
|
591
|
-
updatedAt: new Date().getTime(),
|
|
592
|
-
},
|
|
593
|
-
});
|
|
594
|
-
}
|
|
514
|
+
|
|
515
|
+
await db.insert(schema.archetypesData).values({
|
|
516
|
+
id: enId,
|
|
517
|
+
combination,
|
|
518
|
+
gender,
|
|
519
|
+
archetypeIndex: index,
|
|
520
|
+
language: 'en-us',
|
|
521
|
+
name: englishEntry.name,
|
|
522
|
+
essenceLine: englishEntry.essenceLine,
|
|
523
|
+
status: 'idle',
|
|
524
|
+
}).onConflictDoUpdate({
|
|
525
|
+
target: [schema.archetypesData.id],
|
|
526
|
+
set: {
|
|
527
|
+
name: englishEntry.name,
|
|
528
|
+
essenceLine: englishEntry.essenceLine,
|
|
529
|
+
updatedAt: new Date().getTime(),
|
|
530
|
+
},
|
|
531
|
+
});
|
|
532
|
+
|
|
533
|
+
await db.insert(schema.archetypesData).values({
|
|
534
|
+
id: ptId,
|
|
535
|
+
combination,
|
|
536
|
+
gender,
|
|
537
|
+
archetypeIndex: index,
|
|
538
|
+
language: 'pt-br',
|
|
539
|
+
name: ptName,
|
|
540
|
+
essenceLine: ptEntry.essenceLine,
|
|
541
|
+
status: 'idle',
|
|
542
|
+
}).onConflictDoUpdate({
|
|
543
|
+
target: [schema.archetypesData.id],
|
|
544
|
+
set: {
|
|
545
|
+
name: ptName,
|
|
546
|
+
essenceLine: ptEntry.essenceLine,
|
|
547
|
+
updatedAt: new Date().getTime(),
|
|
548
|
+
},
|
|
549
|
+
});
|
|
550
|
+
|
|
551
|
+
console.log(`✅ [Batch] Saved archetype ${index} (${gender}) for ${combination}`);
|
|
595
552
|
}
|
|
596
553
|
}
|
|
554
|
+
|
|
555
|
+
console.log(`🏁 [Batch] Finished combination: ${combination}`);
|
|
597
556
|
}
|
|
557
|
+
|
|
558
|
+
console.log(`🎉 [Batch] Completed processing for all ${entries.length} combinations`);
|
|
598
559
|
}
|
|
599
560
|
}
|