@zodic/shared 0.0.292 → 0.0.294

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,5 +1,7 @@
1
1
  import { inject, injectable } from 'inversify';
2
- import { KVArchetype } from '../../types/scopes/legacy';
2
+ import { ChatMessages, schema } from '../..';
3
+ import { KVArchetype, ZodiacSignSlug } from '../../types/scopes/legacy';
4
+ import { generateArchetypePrompt } from '../../utils/archetypeNamesMessages';
3
5
  import { buildCosmicMirrorArchetypeKVKey } from '../../utils/KVKeysBuilders';
4
6
  import { AppContext } from '../base';
5
7
 
@@ -281,4 +283,104 @@ export class ArchetypeService {
281
283
  })
282
284
  );
283
285
  }
286
+
287
+ async generateArchetypeNames(
288
+ combination: string,
289
+ gender: 'male' | 'female' | 'non-binary'
290
+ ) {
291
+ const [sun, ascendant, moon] = combination.split('-') as ZodiacSignSlug[];
292
+
293
+ const prompt = generateArchetypePrompt([{ sun, ascendant, moon }]);
294
+ const messages: ChatMessages = [
295
+ {
296
+ role: 'user',
297
+ content: prompt,
298
+ },
299
+ ];
300
+ const response = await this.context.api().callTogether.single(messages, {});
301
+
302
+ if (!response) {
303
+ throw new Error(
304
+ `No response when generating archetype names for ${combination}`
305
+ );
306
+ }
307
+
308
+ const blocks = response
309
+ .split('-EN')[1]
310
+ .split('-PT')[0]
311
+ .trim()
312
+ .split(/\n\d\.\s*\n?/)
313
+ .filter(Boolean);
314
+ const ptBlocks = response
315
+ .split('-PT')[1]
316
+ .trim()
317
+ .split(/\n\d\.\s*\n?/)
318
+ .filter(Boolean);
319
+
320
+ const englishNames = blocks.map((block) => {
321
+ const nameMatch = block.match(/• Name:\s*(.+)/);
322
+ const essenceMatch = block.match(/• Essence:\s*(.+)/);
323
+ return {
324
+ name: nameMatch?.[1]?.trim() || '',
325
+ essenceLine: essenceMatch?.[1]?.trim() || '',
326
+ };
327
+ });
328
+
329
+ const portugueseVariants = ptBlocks.map((block) => {
330
+ const masc = block.match(/• Masculino:\s*(.+)/)?.[1]?.trim() || '';
331
+ const fem = block.match(/• Feminino:\s*(.+)/)?.[1]?.trim() || '';
332
+ const essence = block.match(/• Essência:\s*(.+)/)?.[1]?.trim() || '';
333
+ return { masc, fem, essenceLine: essence };
334
+ });
335
+
336
+ const db = this.context.drizzle();
337
+
338
+ await Promise.all(
339
+ englishNames.map(async (entry, i) => {
340
+ const index = (i + 1).toString();
341
+ await db
342
+ .insert(schema.archetypesData)
343
+ .values({
344
+ id: `${combination}:${gender}:${index}`,
345
+ combination,
346
+ gender,
347
+ archetypeIndex: index,
348
+ language: 'en-us',
349
+ name: entry.name,
350
+ essenceLine: entry.essenceLine,
351
+ status: 'idle',
352
+
353
+ })
354
+ .onConflictDoUpdate({
355
+ target: [schema.archetypesData.id],
356
+ set: {
357
+ name: entry.name,
358
+ essenceLine: entry.essenceLine,
359
+ updatedAt: new Date(),
360
+ },
361
+ });
362
+
363
+ await db
364
+ .insert(schema.archetypesData)
365
+ .values({
366
+ id: `${combination}:${gender}:${index}:pt`,
367
+ combination,
368
+ gender,
369
+ archetypeIndex: index,
370
+ language: 'pt-br',
371
+ name: portugueseVariants[i].masc,
372
+ essenceLine: portugueseVariants[i].essenceLine,
373
+ status: 'idle',
374
+ })
375
+ .onConflictDoUpdate({
376
+ target: [schema.archetypesData.id],
377
+ set: {
378
+ name: portugueseVariants[i].masc,
379
+ essenceLine: portugueseVariants[i].essenceLine,
380
+ updatedAt: new Date(),
381
+ },
382
+ });
383
+ })
384
+ );
385
+ }
284
386
  }
@@ -0,0 +1 @@
1
+ ALTER TABLE `archetypes_data` ADD `images` text DEFAULT '[]' NOT NULL;
@@ -0,0 +1,27 @@
1
+ PRAGMA foreign_keys=OFF;--> statement-breakpoint
2
+ CREATE TABLE `__new_archetypes_data` (
3
+ `id` text PRIMARY KEY NOT NULL,
4
+ `language` text NOT NULL,
5
+ `gender` text,
6
+ `combination` text NOT NULL,
7
+ `archetype_index` text NOT NULL,
8
+ `name` text NOT NULL,
9
+ `essence_line` text NOT NULL,
10
+ `description` text,
11
+ `content` text DEFAULT '[]' NOT NULL,
12
+ `virtues` text DEFAULT '[]' NOT NULL,
13
+ `leonardo_prompt` text,
14
+ `status` text DEFAULT 'idle',
15
+ `created_at` integer DEFAULT CURRENT_TIMESTAMP,
16
+ `images` text DEFAULT '[]' NOT NULL,
17
+ `updated_at` integer DEFAULT CURRENT_TIMESTAMP
18
+ );
19
+ --> statement-breakpoint
20
+ INSERT INTO `__new_archetypes_data`("id", "language", "gender", "combination", "archetype_index", "name", "essence_line", "description", "content", "virtues", "leonardo_prompt", "status", "created_at", "images", "updated_at") SELECT "id", "language", "gender", "combination", "archetype_index", "name", "essence_line", "description", "content", "virtues", "leonardo_prompt", "status", "created_at", "images", "updated_at" FROM `archetypes_data`;--> statement-breakpoint
21
+ DROP TABLE `archetypes_data`;--> statement-breakpoint
22
+ ALTER TABLE `__new_archetypes_data` RENAME TO `archetypes_data`;--> statement-breakpoint
23
+ PRAGMA foreign_keys=ON;--> statement-breakpoint
24
+ CREATE INDEX `archetypes_data_language_idx` ON `archetypes_data` (`language`);--> statement-breakpoint
25
+ CREATE INDEX `archetypes_data_combination_idx` ON `archetypes_data` (`combination`);--> statement-breakpoint
26
+ CREATE INDEX `archetypes_data_archetype_index_idx` ON `archetypes_data` (`archetype_index`);--> statement-breakpoint
27
+ CREATE INDEX `archetypes_data_gender_idx` ON `archetypes_data` (`gender`);