@zodic/shared 0.0.317 → 0.0.319

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.
@@ -7,10 +7,6 @@ import { AppContext } from '../base/AppContext';
7
7
 
8
8
  interface QueueMessage {
9
9
  archetypeDataId: string;
10
- combination: string;
11
- gender: Gender;
12
- language: string;
13
- archetypeIndex: string;
14
10
  }
15
11
 
16
12
  @injectable()
@@ -53,39 +49,52 @@ export class LeonardoService {
53
49
  * Processes a message from ARCHETYPE_POPULATION_QUEUE to ensure the archetype has three images.
54
50
  */
55
51
  async processArchetypePopulation(message: QueueMessage): Promise<void> {
56
- const { archetypeDataId, combination, gender, language, archetypeIndex } =
57
- message;
52
+ const { archetypeDataId } = message;
58
53
  await this.log('info', 'Processing archetype population', {
59
54
  archetypeDataId,
60
- combination,
61
- gender,
62
- language,
63
- archetypeIndex,
64
55
  });
65
-
56
+
66
57
  const db = this.context.drizzle();
67
58
  const archetype = await db
68
- .select()
59
+ .select({
60
+ id: schema.archetypesData.id,
61
+ combination: schema.archetypesData.combination,
62
+ gender: schema.archetypesData.gender,
63
+ language: schema.archetypesData.language,
64
+ archetypeIndex: schema.archetypesData.archetypeIndex,
65
+ leonardoPrompt: schema.archetypesData.leonardoPrompt,
66
+ images: schema.archetypesData.images,
67
+ })
69
68
  .from(schema.archetypesData)
70
69
  .where(eq(schema.archetypesData.id, archetypeDataId))
71
70
  .limit(1)
72
71
  .execute();
73
-
72
+
74
73
  if (!archetype[0]) {
75
74
  await this.log('error', 'Archetype not found', { archetypeDataId });
76
75
  throw new Error(`Archetype not found: ${archetypeDataId}`);
77
76
  }
78
-
79
- const images = JSON.parse(archetype[0].images || '[]');
80
- if (images.length >= 3) {
77
+
78
+ const { combination, gender, language, archetypeIndex, leonardoPrompt, images } = archetype[0];
79
+
80
+ await this.log('info', 'Fetched archetype details', {
81
+ archetypeDataId,
82
+ combination,
83
+ gender,
84
+ language,
85
+ archetypeIndex,
86
+ });
87
+
88
+ const parsedImages = JSON.parse(images || '[]');
89
+ if (parsedImages.length >= 3) {
81
90
  await this.log('info', 'Archetype already has sufficient images', {
82
91
  archetypeDataId,
83
- imageCount: images.length,
92
+ imageCount: parsedImages.length,
84
93
  });
85
94
  return;
86
95
  }
87
-
88
- if (!archetype[0].leonardoPrompt) {
96
+
97
+ if (!leonardoPrompt) {
89
98
  await this.log('error', 'Missing Leonardo prompt for archetype', {
90
99
  archetypeDataId,
91
100
  });
@@ -93,21 +102,21 @@ export class LeonardoService {
93
102
  `Missing Leonardo prompt for archetype: ${archetypeDataId}`
94
103
  );
95
104
  }
96
-
105
+
97
106
  await this.log('debug', 'Generating images for archetype', {
98
107
  archetypeDataId,
99
- prompt: archetype[0].leonardoPrompt,
108
+ prompt: leonardoPrompt,
100
109
  });
101
-
110
+
102
111
  const generationResponse = await this.context
103
112
  .api()
104
113
  .callLeonardo.generateImage({
105
- prompt: archetype[0].leonardoPrompt,
114
+ prompt: leonardoPrompt,
106
115
  width: 512,
107
116
  height: 640,
108
- quantity: 3 - images.length,
117
+ quantity: 3 - parsedImages.length,
109
118
  });
110
-
119
+
111
120
  const generationId = generationResponse.sdGenerationJob.generationId;
112
121
  if (!generationId) {
113
122
  await this.log(
@@ -117,7 +126,7 @@ export class LeonardoService {
117
126
  );
118
127
  throw new Error('Leonardo generation failed to return a valid ID');
119
128
  }
120
-
129
+
121
130
  await db.insert(schema.generations).values({
122
131
  id: generationId,
123
132
  archetypeIndex: parseInt(archetypeIndex),
@@ -127,11 +136,11 @@ export class LeonardoService {
127
136
  gender,
128
137
  createdAt: new Date(),
129
138
  });
130
-
139
+
131
140
  await this.log('info', 'Queued image generation', {
132
141
  generationId,
133
142
  archetypeDataId,
134
- imagesToGenerate: 3 - images.length,
143
+ imagesToGenerate: 3 - parsedImages.length,
135
144
  });
136
145
  }
137
146
 
@@ -1,4 +1,4 @@
1
- import { and, eq } from 'drizzle-orm';
1
+ import { and, eq, inArray } from 'drizzle-orm';
2
2
  import { inject, injectable } from 'inversify';
3
3
  import { schema } from '../..';
4
4
  import { Gender } from '../../types';
@@ -55,7 +55,7 @@ export class ArchetypeWorkflow {
55
55
  gender,
56
56
  language,
57
57
  });
58
-
58
+
59
59
  // Step 1: Check if archetypes exist, if not, generate names
60
60
  let archetypes = await this.archetypeService.fetchArchetypesFromDB(
61
61
  combinationString,
@@ -79,7 +79,7 @@ export class ArchetypeWorkflow {
79
79
  archetypesCount: archetypes.length,
80
80
  archetypeIds: archetypes.map((a) => a.id),
81
81
  });
82
-
82
+
83
83
  // Step 2: Check if any archetypes are already being processed (images are generating)
84
84
  const db = this.context.drizzle();
85
85
  await this.log('debug', 'Checking for in-progress image generations', {
@@ -93,11 +93,14 @@ export class ArchetypeWorkflow {
93
93
  and(
94
94
  eq(schema.generations.status, 'pending'),
95
95
  eq(schema.generations.gender, gender),
96
- eq(schema.generations.archetypeDataId, combinationString)
96
+ inArray(
97
+ schema.generations.archetypeDataId,
98
+ archetypes.map((a) => a.id)
99
+ )
97
100
  )
98
101
  )
99
102
  .execute();
100
-
103
+
101
104
  if (inProgressGenerations.length > 0) {
102
105
  await this.log(
103
106
  'warn',
@@ -113,7 +116,7 @@ export class ArchetypeWorkflow {
113
116
  combinationString,
114
117
  gender,
115
118
  });
116
-
119
+
117
120
  // Step 3: Generate missing textual content (description, virtues, content, leonardoPrompt)
118
121
  const archetypesNeedingText = archetypes.filter(
119
122
  (arc) =>
@@ -122,7 +125,7 @@ export class ArchetypeWorkflow {
122
125
  arc.content === '[]' ||
123
126
  !arc.leonardoPrompt
124
127
  );
125
-
128
+
126
129
  if (archetypesNeedingText.length > 0) {
127
130
  await this.log('info', 'Generating missing textual content', {
128
131
  combinationString,
@@ -131,7 +134,7 @@ export class ArchetypeWorkflow {
131
134
  archetypesNeedingTextCount: archetypesNeedingText.length,
132
135
  archetypeIds: archetypesNeedingText.map((a) => a.id),
133
136
  });
134
-
137
+
135
138
  const descVirtues =
136
139
  await this.archetypeService.generateDescriptionsAndVirtues(
137
140
  combinationString,
@@ -157,7 +160,7 @@ export class ArchetypeWorkflow {
157
160
  language,
158
161
  });
159
162
  }
160
-
163
+
161
164
  // Refetch archetypes after generating textual content
162
165
  const updatedArchetypes = await this.archetypeService.fetchArchetypesFromDB(
163
166
  combinationString,
@@ -168,12 +171,12 @@ export class ArchetypeWorkflow {
168
171
  updatedArchetypesCount: updatedArchetypes.length,
169
172
  archetypeIds: updatedArchetypes.map((a) => a.id),
170
173
  });
171
-
174
+
172
175
  // Step 4: Queue image generation if needed
173
176
  const archetypesNeedingImages = updatedArchetypes.filter(
174
177
  (arc) => JSON.parse(arc.images).length < 3
175
178
  );
176
-
179
+
177
180
  if (archetypesNeedingImages.length > 0) {
178
181
  await this.log(
179
182
  'info',
@@ -183,14 +186,10 @@ export class ArchetypeWorkflow {
183
186
  archetypeIds: archetypesNeedingImages.map((a) => a.id),
184
187
  }
185
188
  );
186
-
189
+
187
190
  const batch = archetypesNeedingImages.map((arc) => ({
188
191
  body: {
189
192
  archetypeDataId: arc.id,
190
- combination: combinationString,
191
- gender,
192
- language,
193
- archetypeIndex: arc.archetypeIndex,
194
193
  },
195
194
  }));
196
195
  await this.log('debug', 'Sending batch to ARCHETYPE_POPULATION_QUEUE', {
@@ -201,10 +200,10 @@ export class ArchetypeWorkflow {
201
200
  await this.log('info', 'Successfully queued image generation', {
202
201
  batchCount: batch.length,
203
202
  });
204
-
203
+
205
204
  return { message: 'Images are being processed, please try again later.' };
206
205
  }
207
-
206
+
208
207
  await this.log('info', 'Archetypes fully processed and ready', {
209
208
  updatedArchetypes,
210
209
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zodic/shared",
3
- "version": "0.0.317",
3
+ "version": "0.0.319",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "publishConfig": {