@zodic/shared 0.0.375 → 0.0.376
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/workflow/ArchetypeWorkflow.ts +109 -64
- package/package.json +1 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { and, eq } from 'drizzle-orm';
|
|
1
2
|
import { inject, injectable } from 'inversify';
|
|
2
|
-
import { AppContext } from '../base';
|
|
3
|
-
import { Gender, Languages } from '../../types';
|
|
4
3
|
import { ArchetypeService, LeonardoService, schema } from '../..';
|
|
5
|
-
import {
|
|
4
|
+
import { Gender, Languages } from '../../types';
|
|
5
|
+
import { AppContext } from '../base';
|
|
6
6
|
|
|
7
7
|
@injectable()
|
|
8
8
|
export class ArchetypeWorkflow {
|
|
@@ -38,8 +38,17 @@ export class ArchetypeWorkflow {
|
|
|
38
38
|
|
|
39
39
|
try {
|
|
40
40
|
// Step 1: Generate archetype names for both genders
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
if (override) {
|
|
42
|
+
await this.log('debug', 'Generating archetype names', {
|
|
43
|
+
combinationString,
|
|
44
|
+
override,
|
|
45
|
+
userId,
|
|
46
|
+
});
|
|
47
|
+
await this.archetypeService.generateArchetypeNames(
|
|
48
|
+
combinationString,
|
|
49
|
+
override
|
|
50
|
+
);
|
|
51
|
+
}
|
|
43
52
|
|
|
44
53
|
// Step 2: Generate descriptions and virtues for both genders
|
|
45
54
|
await this.log('debug', 'Generating descriptions and virtues', {
|
|
@@ -49,12 +58,13 @@ export class ArchetypeWorkflow {
|
|
|
49
58
|
override,
|
|
50
59
|
userId,
|
|
51
60
|
});
|
|
52
|
-
const descriptions =
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
61
|
+
const descriptions =
|
|
62
|
+
await this.archetypeService.generateDescriptionsAndVirtues(
|
|
63
|
+
combinationString,
|
|
64
|
+
gender, // Service processes both genders internally
|
|
65
|
+
language,
|
|
66
|
+
override
|
|
67
|
+
);
|
|
58
68
|
|
|
59
69
|
// Step 3: Generate content for both genders
|
|
60
70
|
await this.log('debug', 'Generating content', {
|
|
@@ -102,50 +112,70 @@ export class ArchetypeWorkflow {
|
|
|
102
112
|
);
|
|
103
113
|
|
|
104
114
|
if (archetypes.length !== 3) {
|
|
105
|
-
await this.log(
|
|
106
|
-
|
|
107
|
-
gender,
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
115
|
+
await this.log(
|
|
116
|
+
'error',
|
|
117
|
+
`Expected 3 archetypes for ${gender}, found ${archetypes.length}`,
|
|
118
|
+
{
|
|
119
|
+
combinationString,
|
|
120
|
+
gender,
|
|
121
|
+
language,
|
|
122
|
+
userId,
|
|
123
|
+
}
|
|
124
|
+
);
|
|
111
125
|
throw new Error(
|
|
112
126
|
`Expected 3 archetypes for combination ${combinationString}, gender ${gender}, language ${language}, but found ${archetypes.length}`
|
|
113
127
|
);
|
|
114
128
|
}
|
|
115
129
|
|
|
116
130
|
// Step 6: Process image generation only for the requested gender
|
|
117
|
-
await this.log(
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
131
|
+
await this.log(
|
|
132
|
+
'info',
|
|
133
|
+
`Processing image generation for gender ${gender}`,
|
|
134
|
+
{
|
|
135
|
+
archetypeIds: archetypes.map((a) => a.id),
|
|
136
|
+
archetypeIndexes: archetypes.map((a) => a.archetypeIndex),
|
|
137
|
+
userId,
|
|
138
|
+
}
|
|
139
|
+
);
|
|
122
140
|
for (const archetype of archetypes) {
|
|
123
141
|
if (!archetype.leonardoPrompt) {
|
|
124
|
-
await this.log(
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
142
|
+
await this.log(
|
|
143
|
+
'warn',
|
|
144
|
+
`No Leonardo prompt for archetype ${archetype.id}`,
|
|
145
|
+
{
|
|
146
|
+
archetypeIndex: archetype.archetypeIndex,
|
|
147
|
+
gender,
|
|
148
|
+
language,
|
|
149
|
+
userId,
|
|
150
|
+
}
|
|
151
|
+
);
|
|
130
152
|
continue;
|
|
131
153
|
}
|
|
132
154
|
|
|
133
155
|
if (override || !archetype.images || archetype.images === '[]') {
|
|
134
|
-
await this.log(
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
156
|
+
await this.log(
|
|
157
|
+
'debug',
|
|
158
|
+
`Queueing image generation for archetype ${archetype.id}`,
|
|
159
|
+
{
|
|
160
|
+
archetypeIndex: archetype.archetypeIndex,
|
|
161
|
+
gender,
|
|
162
|
+
language,
|
|
163
|
+
userId,
|
|
164
|
+
}
|
|
165
|
+
);
|
|
140
166
|
await this.leonardoService.processArchetypePopulation(archetype.id);
|
|
141
167
|
} else {
|
|
142
|
-
await this.log(
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
168
|
+
await this.log(
|
|
169
|
+
'debug',
|
|
170
|
+
`Skipping image generation for archetype ${archetype.id}`,
|
|
171
|
+
{
|
|
172
|
+
reason: 'Images already exist and override is false',
|
|
173
|
+
archetypeIndex: archetype.archetypeIndex,
|
|
174
|
+
gender,
|
|
175
|
+
language,
|
|
176
|
+
userId,
|
|
177
|
+
}
|
|
178
|
+
);
|
|
149
179
|
}
|
|
150
180
|
}
|
|
151
181
|
|
|
@@ -163,13 +193,17 @@ export class ArchetypeWorkflow {
|
|
|
163
193
|
const images = archetype.images ? JSON.parse(archetype.images) : [];
|
|
164
194
|
imageCount = Array.isArray(images) ? images.length : 0;
|
|
165
195
|
} catch (error) {
|
|
166
|
-
await this.log(
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
196
|
+
await this.log(
|
|
197
|
+
'warn',
|
|
198
|
+
`Failed to parse images for archetype ${archetype.id}`,
|
|
199
|
+
{
|
|
200
|
+
archetypeIndex: archetype.archetypeIndex,
|
|
201
|
+
gender,
|
|
202
|
+
language,
|
|
203
|
+
userId,
|
|
204
|
+
error: error instanceof Error ? error.message : String(error),
|
|
205
|
+
}
|
|
206
|
+
);
|
|
173
207
|
continue;
|
|
174
208
|
}
|
|
175
209
|
|
|
@@ -185,24 +219,35 @@ export class ArchetypeWorkflow {
|
|
|
185
219
|
eq(schema.archetypesData.id, archetype.id),
|
|
186
220
|
eq(schema.archetypesData.gender, gender),
|
|
187
221
|
eq(schema.archetypesData.language, language),
|
|
188
|
-
eq(
|
|
222
|
+
eq(
|
|
223
|
+
schema.archetypesData.archetypeIndex,
|
|
224
|
+
archetype.archetypeIndex
|
|
225
|
+
)
|
|
189
226
|
)
|
|
190
227
|
);
|
|
191
|
-
await this.log(
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
228
|
+
await this.log(
|
|
229
|
+
'info',
|
|
230
|
+
`Updated status to 'completed' for archetype ${archetype.id}`,
|
|
231
|
+
{
|
|
232
|
+
archetypeIndex: archetype.archetypeIndex,
|
|
233
|
+
gender,
|
|
234
|
+
language,
|
|
235
|
+
imageCount,
|
|
236
|
+
userId,
|
|
237
|
+
}
|
|
238
|
+
);
|
|
198
239
|
} else {
|
|
199
|
-
await this.log(
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
240
|
+
await this.log(
|
|
241
|
+
'debug',
|
|
242
|
+
`Skipping status update for archetype ${archetype.id}`,
|
|
243
|
+
{
|
|
244
|
+
reason: `Fewer than 3 images (found ${imageCount})`,
|
|
245
|
+
archetypeIndex: archetype.archetypeIndex,
|
|
246
|
+
gender,
|
|
247
|
+
language,
|
|
248
|
+
userId,
|
|
249
|
+
}
|
|
250
|
+
);
|
|
206
251
|
}
|
|
207
252
|
}
|
|
208
253
|
|
|
@@ -223,4 +268,4 @@ export class ArchetypeWorkflow {
|
|
|
223
268
|
throw error;
|
|
224
269
|
}
|
|
225
270
|
}
|
|
226
|
-
}
|
|
271
|
+
}
|