@zodic/shared 0.0.87 → 0.0.89

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,8 @@
1
+ import { and, eq } from 'drizzle-orm';
1
2
  import { inject, injectable } from 'inversify';
2
3
  import 'reflect-metadata';
4
+ import { v4 as uuidv4 } from 'uuid';
5
+ import { schema } from '../..';
3
6
  import { Languages } from '../../types';
4
7
  import { KVConcept, sizes } from '../../types/scopes/legacy';
5
8
  import { buildConceptKVKey } from '../../utils/KVKeysBuilders';
@@ -155,31 +158,129 @@ export class ConceptService {
155
158
  conceptSlug: string,
156
159
  combinationString: string
157
160
  ): Promise<void> {
161
+ const drizzle = this.context.drizzle();
162
+ const { width, height } = sizes['alchemy']['post4:5'];
163
+ const { generations, conceptCombinations, concepts } = schema;
164
+
158
165
  const kvKey = buildConceptKVKey(language, conceptSlug, combinationString);
159
166
  console.log(
160
- `Queuing image generation for concept: ${conceptSlug}, combination: ${combinationString}, language: ${language}`
167
+ `🚀 Queuing image generation for concept: ${conceptSlug}, combination: ${combinationString}, language: ${language}`
161
168
  );
162
169
 
163
170
  const concept = await this.getKVConcept(kvKey);
164
171
  if (!concept.leonardoPrompt) {
165
172
  throw new Error(
166
- `Leonardo prompt must be populated before generating images for concept: ${conceptSlug}`
173
+ `❌ Leonardo prompt must be populated before generating images for concept: ${conceptSlug}`
167
174
  );
168
175
  }
169
176
 
170
- const { width, height } = sizes['alchemy']['post4:5'];
177
+ // 🔍 Fetch Concept ID using conceptSlug
178
+ const conceptRecord = await drizzle
179
+ .select({
180
+ id: concepts.id,
181
+ planet1: concepts.planet1,
182
+ planet2: concepts.planet2,
183
+ planet3: concepts.planet3,
184
+ })
185
+ .from(concepts)
186
+ .where(eq(concepts.slug, conceptSlug))
187
+ .limit(1);
188
+
189
+ if (conceptRecord.length === 0) {
190
+ throw new Error(`❌ No concept found for slug: ${conceptSlug}`);
191
+ }
192
+
193
+ const { id: conceptId, planet1, planet2, planet3 } = conceptRecord[0];
194
+ console.log(
195
+ `✅ Retrieved conceptId: ${conceptId} for slug: ${conceptSlug}`
196
+ );
197
+
198
+ const [planet1Sign, planet2Sign, planet3Sign] =
199
+ combinationString.split('-');
200
+
201
+ if (!planet1Sign || !planet2Sign || !planet3Sign) {
202
+ throw new Error(
203
+ `❌ Invalid combinationString: ${combinationString} (Expected format: sign1-sign2-[sign3])`
204
+ );
205
+ }
206
+
207
+ console.log(
208
+ `🌌 Extracted planet signs: ${planet1} -> ${planet1Sign}, ${planet2} -> ${planet2Sign}, ${planet3} -> ${planet3Sign}`
209
+ );
210
+
211
+ // 🔍 Ensure Concept Combination exists
212
+ let [conceptCombination] = await drizzle
213
+ .select({ id: conceptCombinations.id })
214
+ .from(conceptCombinations)
215
+ .where(
216
+ and(
217
+ eq(conceptCombinations.combinationString, combinationString),
218
+ eq(conceptCombinations.conceptId, conceptId)
219
+ )
220
+ )
221
+ .limit(1);
222
+
223
+ if (!conceptCombination) {
224
+ console.log(
225
+ `🔍 No existing conceptCombination found. Creating new entry for ${conceptSlug}:${combinationString}`
226
+ );
227
+
228
+ const [insertedCombination] = await drizzle
229
+ .insert(conceptCombinations)
230
+ .values({
231
+ id: uuidv4(),
232
+ combinationString,
233
+ conceptId,
234
+ planet1Sign,
235
+ planet2Sign,
236
+ planet3Sign, // Ensure null if planet3 is not used
237
+ })
238
+ .returning({ id: conceptCombinations.id });
239
+
240
+ conceptCombination = insertedCombination;
241
+ }
242
+
243
+ const conceptCombinationId = conceptCombination.id;
244
+ console.log(
245
+ `✅ Using conceptCombinationId: ${conceptCombinationId} for ${conceptSlug}:${combinationString}`
246
+ );
247
+
248
+ // 🎨 Request Leonardo AI image generation
249
+ console.log(`🎨 Requesting Leonardo AI image generation...`);
250
+ const leonardoResponse = await this.context
251
+ .api()
252
+ .callLeonardo.generateImage({
253
+ prompt: concept.leonardoPrompt,
254
+ width,
255
+ height,
256
+ });
171
257
 
172
- await this.context.api().callLeonardo.generateImage({
173
- prompt: concept.leonardoPrompt,
174
- width,
175
- height,
258
+ const generationId = leonardoResponse?.sdGenerationJob?.generationId;
259
+ if (!generationId) {
260
+ throw new Error(
261
+ `❌ Failed to retrieve generationId from Leonardo response`
262
+ );
263
+ }
264
+
265
+ console.log(`✅ Leonardo Generation ID received: ${generationId}`);
266
+
267
+ // 📝 Insert Generation Record with the received generationId
268
+ await drizzle.insert(generations).values({
269
+ id: generationId, // Use the ID from Leonardo
270
+ conceptCombinationId,
271
+ type: 'concept_image',
272
+ status: 'pending',
273
+ createdAt: new Date(),
176
274
  });
177
275
 
178
276
  console.log(
179
- `Post images queued for concept: ${conceptSlug}, combination: ${combinationString}, language: ${language}`
277
+ `📝 Generation record created: ${generationId} for ${conceptSlug}:${combinationString}`
180
278
  );
181
- }
182
279
 
280
+ console.log(
281
+ `🎨 Leonardo AI image generation triggered for ${conceptSlug}:${combinationString}, tracking ID: ${generationId}`
282
+ );
283
+ }
183
284
  /**
184
285
  * Fetch and initialize a KVConcept object if not present.
185
286
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zodic/shared",
3
- "version": "0.0.87",
3
+ "version": "0.0.89",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -32,6 +32,7 @@
32
32
  "inversify": "^6.2.1",
33
33
  "jose": "^5.9.6",
34
34
  "openai": "^4.81.0",
35
- "reflect-metadata": "^0.2.2"
35
+ "reflect-metadata": "^0.2.2",
36
+ "uuid": "^11.0.5"
36
37
  }
37
38
  }
@@ -0,0 +1,9 @@
1
+ export const leonardoInitImages = {
2
+ concetps: {
3
+ crown: {
4
+ imageId: '450076a1-c6bb-4877-8a0b-c0d3ba72fca7',
5
+ imageUrl:
6
+ 'https://cdn.leonardo.ai/users/b117a933-e5c9-45b2-96aa-4b619c2d74ba/initImages/450076a1-c6bb-4877-8a0b-c0d3ba72fca7.jpg',
7
+ },
8
+ },
9
+ };
@@ -1,25 +1,28 @@
1
- export const mapConceptToPlanets = (conceptSlug: string, combination: string): string => {
1
+ export const mapConceptToPlanets = (
2
+ conceptSlug: string,
3
+ combination: string
4
+ ): string => {
2
5
  const signs = combination.split('-');
3
6
 
4
7
  const conceptPlanetMapping: Record<string, string[]> = {
5
8
  crown: ['Sun', 'Ascendant', 'Moon'],
6
9
  scepter: ['Mercury', 'Venus', 'Mars'],
7
10
  amulet: ['Jupiter', 'Saturn', 'Chiron'],
8
- lantern: ['Uranus', 'Pluto', 'Neptune'],
11
+ lantern: ['Uranus', 'Neptune', 'Pluto'],
9
12
  orb: ['North Node', 'Midheaven', 'Pars Fortuna'],
10
13
  };
11
14
 
12
15
  const planets = conceptPlanetMapping[conceptSlug];
13
-
16
+
14
17
  if (!planets) {
15
18
  throw new Error(`Invalid conceptSlug provided: ${conceptSlug}`);
16
19
  }
17
20
 
18
21
  if (signs.length !== planets.length) {
19
- throw new Error(`Combination does not match the expected number of planets for concept: ${conceptSlug}`);
22
+ throw new Error(
23
+ `Combination does not match the expected number of planets for concept: ${conceptSlug}`
24
+ );
20
25
  }
21
26
 
22
- return signs
23
- .map((sign, index) => `- ${planets[index]}: ${sign}`)
24
- .join('\n');
25
- };
27
+ return signs.map((sign, index) => `- ${planets[index]}: ${sign}`).join('\n');
28
+ };