@zodic/shared 0.0.115 → 0.0.116
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/ConceptService.ts +32 -38
- package/package.json +1 -1
- package/types/scopes/generic.ts +20 -2
- package/types/scopes/legacy.ts +2 -7
- package/utils/initImages.ts +33 -6
|
@@ -3,7 +3,7 @@ import { inject, injectable } from 'inversify';
|
|
|
3
3
|
import 'reflect-metadata';
|
|
4
4
|
import { v4 as uuidv4 } from 'uuid';
|
|
5
5
|
import { schema } from '../..';
|
|
6
|
-
import { Concept, Languages } from '../../types';
|
|
6
|
+
import { Concept, ControlNetConfig, Languages } from '../../types';
|
|
7
7
|
import { KVConcept, sizes } from '../../types/scopes/legacy';
|
|
8
8
|
import { leonardoInitImages } from '../../utils/initImages';
|
|
9
9
|
import { buildConceptKVKey } from '../../utils/KVKeysBuilders';
|
|
@@ -168,19 +168,19 @@ export class ConceptService {
|
|
|
168
168
|
const drizzle = this.context.drizzle();
|
|
169
169
|
const { width, height } = sizes['alchemy']['post4:5'];
|
|
170
170
|
const { generations, conceptCombinations, concepts } = schema;
|
|
171
|
-
|
|
171
|
+
|
|
172
172
|
const kvKey = buildConceptKVKey(language, conceptSlug, combinationString);
|
|
173
173
|
console.log(
|
|
174
174
|
`🚀 Queuing image generation for concept: ${conceptSlug}, combination: ${combinationString}, language: ${language}`
|
|
175
175
|
);
|
|
176
|
-
|
|
176
|
+
|
|
177
177
|
const concept = await this.getKVConcept(kvKey);
|
|
178
178
|
if (!concept.leonardoPrompt) {
|
|
179
179
|
throw new Error(
|
|
180
180
|
`❌ Leonardo prompt must be populated before generating images for concept: ${conceptSlug}`
|
|
181
181
|
);
|
|
182
182
|
}
|
|
183
|
-
|
|
183
|
+
|
|
184
184
|
const conceptRecord = await drizzle
|
|
185
185
|
.select({
|
|
186
186
|
id: concepts.id,
|
|
@@ -191,30 +191,29 @@ export class ConceptService {
|
|
|
191
191
|
.from(concepts)
|
|
192
192
|
.where(eq(concepts.slug, conceptSlug))
|
|
193
193
|
.limit(1);
|
|
194
|
-
|
|
194
|
+
|
|
195
195
|
if (conceptRecord.length === 0) {
|
|
196
196
|
throw new Error(`❌ No concept found for slug: ${conceptSlug}`);
|
|
197
197
|
}
|
|
198
|
-
|
|
198
|
+
|
|
199
199
|
const { id: conceptId, planet1, planet2, planet3 } = conceptRecord[0];
|
|
200
200
|
console.log(
|
|
201
201
|
`✅ Retrieved conceptId: ${conceptId} for slug: ${conceptSlug}`
|
|
202
202
|
);
|
|
203
|
-
|
|
203
|
+
|
|
204
204
|
const [planet1Sign, planet2Sign, planet3Sign] =
|
|
205
205
|
combinationString.split('-');
|
|
206
|
-
|
|
206
|
+
|
|
207
207
|
if (!planet1Sign || !planet2Sign || !planet3Sign) {
|
|
208
208
|
throw new Error(
|
|
209
209
|
`❌ Invalid combinationString: ${combinationString} (Expected format: sign1-sign2-[sign3])`
|
|
210
210
|
);
|
|
211
211
|
}
|
|
212
|
-
|
|
212
|
+
|
|
213
213
|
console.log(
|
|
214
214
|
`🔹 Extracted planet signs: ${planet1} -> ${planet1Sign}, ${planet2} -> ${planet2Sign}, ${planet3} -> ${planet3Sign}`
|
|
215
215
|
);
|
|
216
|
-
|
|
217
|
-
// 🔍 Ensure Concept Combination exists
|
|
216
|
+
|
|
218
217
|
let [conceptCombination] = await drizzle
|
|
219
218
|
.select({ id: conceptCombinations.id })
|
|
220
219
|
.from(conceptCombinations)
|
|
@@ -225,12 +224,12 @@ export class ConceptService {
|
|
|
225
224
|
)
|
|
226
225
|
)
|
|
227
226
|
.limit(1);
|
|
228
|
-
|
|
227
|
+
|
|
229
228
|
if (!conceptCombination) {
|
|
230
229
|
console.log(
|
|
231
230
|
`🔍 No existing conceptCombination found. Creating new entry for ${conceptSlug}:${combinationString}`
|
|
232
231
|
);
|
|
233
|
-
|
|
232
|
+
|
|
234
233
|
const [insertedCombination] = await drizzle
|
|
235
234
|
.insert(conceptCombinations)
|
|
236
235
|
.values({
|
|
@@ -242,36 +241,31 @@ export class ConceptService {
|
|
|
242
241
|
planet3Sign,
|
|
243
242
|
})
|
|
244
243
|
.returning({ id: conceptCombinations.id });
|
|
245
|
-
|
|
244
|
+
|
|
246
245
|
conceptCombination = insertedCombination;
|
|
247
246
|
}
|
|
248
|
-
|
|
247
|
+
|
|
249
248
|
const conceptCombinationId = conceptCombination.id;
|
|
250
249
|
console.log(
|
|
251
250
|
`✅ Using conceptCombinationId: ${conceptCombinationId} for ${conceptSlug}:${combinationString}`
|
|
252
251
|
);
|
|
253
|
-
|
|
252
|
+
|
|
254
253
|
console.log(`🎨 Requesting Leonardo AI image generation...`);
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
const
|
|
258
|
-
|
|
259
|
-
? ([
|
|
254
|
+
|
|
255
|
+
const initImage = leonardoInitImages.concepts[conceptSlug];
|
|
256
|
+
const controlNets = initImage.imageId
|
|
257
|
+
? [
|
|
260
258
|
{
|
|
261
|
-
initImageId,
|
|
259
|
+
initImageId: initImage.imageId,
|
|
262
260
|
initImageType: 'UPLOADED',
|
|
263
|
-
preprocessorId:
|
|
264
|
-
|
|
261
|
+
preprocessorId: initImage.preprocessorId!,
|
|
262
|
+
...(initImage.preprocessorId === 100
|
|
263
|
+
? { strengthType: initImage.strengthType! }
|
|
264
|
+
: { weight: initImage.weight! }),
|
|
265
265
|
},
|
|
266
|
-
]
|
|
267
|
-
initImageId: string;
|
|
268
|
-
initImageType: 'UPLOADED' | 'GENERATED';
|
|
269
|
-
preprocessorId: number;
|
|
270
|
-
strengthType: 'Low' | 'Mid' | 'High';
|
|
271
|
-
}>)
|
|
266
|
+
]
|
|
272
267
|
: [];
|
|
273
|
-
|
|
274
|
-
// 🎨 Call Leonardo with or without ControlNet
|
|
268
|
+
|
|
275
269
|
const leonardoResponse = await this.context
|
|
276
270
|
.api()
|
|
277
271
|
.callLeonardo.generateImage({
|
|
@@ -279,18 +273,18 @@ export class ConceptService {
|
|
|
279
273
|
width,
|
|
280
274
|
height,
|
|
281
275
|
...(controlNets.length > 0 ? { controlNets } : {}),
|
|
282
|
-
negPrompt: 'person, hands, face, body parts, people, animals, fingers'
|
|
276
|
+
negPrompt: 'person, hands, face, body parts, people, animals, fingers',
|
|
283
277
|
});
|
|
284
|
-
|
|
278
|
+
|
|
285
279
|
const generationId = leonardoResponse?.sdGenerationJob?.generationId;
|
|
286
280
|
if (!generationId) {
|
|
287
281
|
throw new Error(
|
|
288
282
|
`❌ Failed to retrieve generationId from Leonardo response`
|
|
289
283
|
);
|
|
290
284
|
}
|
|
291
|
-
|
|
285
|
+
|
|
292
286
|
console.log(`✅ Leonardo Generation ID received: ${generationId}`);
|
|
293
|
-
|
|
287
|
+
|
|
294
288
|
await drizzle.insert(generations).values({
|
|
295
289
|
id: generationId,
|
|
296
290
|
conceptCombinationId,
|
|
@@ -298,11 +292,11 @@ export class ConceptService {
|
|
|
298
292
|
status: 'pending',
|
|
299
293
|
createdAt: new Date(),
|
|
300
294
|
});
|
|
301
|
-
|
|
295
|
+
|
|
302
296
|
console.log(
|
|
303
297
|
`📝 Generation record created: ${generationId} for ${conceptSlug}:${combinationString}`
|
|
304
298
|
);
|
|
305
|
-
|
|
299
|
+
|
|
306
300
|
console.log(
|
|
307
301
|
`🎨 Leonardo AI image generation triggered for ${conceptSlug}:${combinationString}, tracking ID: ${generationId}`
|
|
308
302
|
);
|
package/package.json
CHANGED
package/types/scopes/generic.ts
CHANGED
|
@@ -148,7 +148,7 @@ export type Concept =
|
|
|
148
148
|
| 'lantern'
|
|
149
149
|
| 'orb'
|
|
150
150
|
| 'ring';
|
|
151
|
-
|
|
151
|
+
|
|
152
152
|
export type Concepts = ['crown', 'scepter', 'amulet', 'lantern', 'orb', 'ring'];
|
|
153
153
|
export type ConceptQueueMessage = {
|
|
154
154
|
conceptSlug: Concept;
|
|
@@ -296,4 +296,22 @@ export interface JWK {
|
|
|
296
296
|
|
|
297
297
|
export interface JWKS {
|
|
298
298
|
keys: JWK[];
|
|
299
|
-
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
export type ControlNetStrenghtType = 'Low' | 'Mid' | 'High';
|
|
302
|
+
|
|
303
|
+
export type ControlNetPreprocessorId = 100 | 19;
|
|
304
|
+
|
|
305
|
+
export type ControlNetConfig =
|
|
306
|
+
| {
|
|
307
|
+
initImageId: string;
|
|
308
|
+
initImageType: 'UPLOADED' | 'GENERATED';
|
|
309
|
+
preprocessorId: 100; // Content Reference
|
|
310
|
+
strengthType: ControlNetStrenghtType;
|
|
311
|
+
}
|
|
312
|
+
| {
|
|
313
|
+
initImageId: string;
|
|
314
|
+
initImageType: 'UPLOADED' | 'GENERATED';
|
|
315
|
+
preprocessorId: 19; // Edge to Image
|
|
316
|
+
weight: string;
|
|
317
|
+
};
|
package/types/scopes/legacy.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BackendBindings } from './cloudflare';
|
|
2
|
-
import { Gender } from './generic';
|
|
2
|
+
import { ControlNetConfig, Gender } from './generic';
|
|
3
3
|
|
|
4
4
|
export const zodiacSigns = [
|
|
5
5
|
'Aries',
|
|
@@ -25,12 +25,7 @@ export interface LeonardoGenerateImageParams {
|
|
|
25
25
|
prompt: string;
|
|
26
26
|
width: number;
|
|
27
27
|
height: number;
|
|
28
|
-
controlNets?: Array<
|
|
29
|
-
initImageId: string;
|
|
30
|
-
initImageType: 'UPLOADED' | 'GENERATED';
|
|
31
|
-
preprocessorId: number;
|
|
32
|
-
strengthType: 'Low' | 'Mid' | 'High';
|
|
33
|
-
}>;
|
|
28
|
+
controlNets?: Array<ControlNetConfig>;
|
|
34
29
|
quantity?: number;
|
|
35
30
|
negPrompt?: string | null;
|
|
36
31
|
}
|
package/utils/initImages.ts
CHANGED
|
@@ -6,11 +6,15 @@ export const leonardoInitImages: LeonardoInitImages = {
|
|
|
6
6
|
imageId: '450076a1-c6bb-4877-8a0b-c0d3ba72fca7',
|
|
7
7
|
imageUrl:
|
|
8
8
|
'https://cdn.leonardo.ai/users/b117a933-e5c9-45b2-96aa-4b619c2d74ba/initImages/450076a1-c6bb-4877-8a0b-c0d3ba72fca7.jpg',
|
|
9
|
+
preprocessorId: 100,
|
|
10
|
+
strengthType: 'Low',
|
|
9
11
|
},
|
|
10
12
|
scepter: {
|
|
11
13
|
imageId: '744169ef-3db4-416d-86dd-9bd814e33432',
|
|
12
14
|
imageUrl:
|
|
13
15
|
'https://cdn.leonardo.ai/users/b117a933-e5c9-45b2-96aa-4b619c2d74ba/initImages/744169ef-3db4-416d-86dd-9bd814e33432.jpg',
|
|
16
|
+
preprocessorId: 100,
|
|
17
|
+
strengthType: 'Low',
|
|
14
18
|
},
|
|
15
19
|
amulet: {
|
|
16
20
|
imageId: null,
|
|
@@ -21,8 +25,11 @@ export const leonardoInitImages: LeonardoInitImages = {
|
|
|
21
25
|
imageUrl: null,
|
|
22
26
|
},
|
|
23
27
|
orb: {
|
|
24
|
-
imageId:
|
|
25
|
-
imageUrl:
|
|
28
|
+
imageId: 'c489e496-00c4-4958-8bcd-4460a43a43bf',
|
|
29
|
+
imageUrl:
|
|
30
|
+
'https://cdn.leonardo.ai/users/b117a933-e5c9-45b2-96aa-4b619c2d74ba/initImages/c489e496-00c4-4958-8bcd-4460a43a43bf.jpg',
|
|
31
|
+
preprocessorId: 19,
|
|
32
|
+
weight: '0.3',
|
|
26
33
|
},
|
|
27
34
|
ring: {
|
|
28
35
|
imageId: null,
|
|
@@ -31,10 +38,30 @@ export const leonardoInitImages: LeonardoInitImages = {
|
|
|
31
38
|
},
|
|
32
39
|
};
|
|
33
40
|
|
|
34
|
-
type ConceptsInitImages = Record<
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
41
|
+
type ConceptsInitImages = Record<Concept, ControlNetSettings>;
|
|
42
|
+
|
|
43
|
+
type ControlNetSettings =
|
|
44
|
+
| {
|
|
45
|
+
imageId: string;
|
|
46
|
+
imageUrl: string;
|
|
47
|
+
preprocessorId: 100;
|
|
48
|
+
strengthType: 'Low' | 'Mid' | 'High';
|
|
49
|
+
weight?: null;
|
|
50
|
+
}
|
|
51
|
+
| {
|
|
52
|
+
imageId: string;
|
|
53
|
+
imageUrl: string;
|
|
54
|
+
preprocessorId: 19;
|
|
55
|
+
weight: string;
|
|
56
|
+
strengthType?: null;
|
|
57
|
+
}
|
|
58
|
+
| {
|
|
59
|
+
imageId: null;
|
|
60
|
+
imageUrl: null;
|
|
61
|
+
preprocessorId?: undefined;
|
|
62
|
+
strengthType?: undefined;
|
|
63
|
+
weight?: undefined;
|
|
64
|
+
};
|
|
38
65
|
|
|
39
66
|
type LeonardoInitImages = {
|
|
40
67
|
concepts: ConceptsInitImages;
|