@zodic/shared 0.0.371 → 0.0.372

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.
@@ -342,14 +342,14 @@ export class ConceptService {
342
342
  console.log(
343
343
  `[${new Date().toISOString()}] 🚀 Generating Leonardo prompt for concept: ${conceptSlug}, combination: ${combinationString}, override: ${override}`
344
344
  );
345
-
345
+
346
346
  const db = drizzle(this.context.env.DB); // ✅ Initialize Drizzle with Cloudflare D1
347
-
347
+
348
348
  // ✅ Fetch concept data from D1 for both languages
349
349
  console.log(
350
350
  `[${new Date().toISOString()}] 📡 Fetching concept data for ${conceptSlug}:${combinationString}`
351
351
  );
352
-
352
+
353
353
  const conceptEntries = await db
354
354
  .select({
355
355
  id: conceptsData.id,
@@ -368,28 +368,34 @@ export class ConceptService {
368
368
  )
369
369
  )
370
370
  .execute();
371
-
371
+
372
372
  if (conceptEntries.length !== 2) {
373
373
  throw new Error(
374
374
  `❌ Missing concept data for ${conceptSlug}:${combinationString}. Ensure basic info is populated first.`
375
375
  );
376
376
  }
377
-
377
+
378
378
  const conceptEN = conceptEntries.find((c) => c.language === 'en-us');
379
379
  const conceptPT = conceptEntries.find((c) => c.language === 'pt-br');
380
-
380
+
381
381
  if (!conceptEN || !conceptPT) {
382
382
  throw new Error(`❌ Could not find both EN and PT versions.`);
383
383
  }
384
-
384
+
385
+ const leonardoPromptExistsEN =
386
+ conceptEN.leonardoPrompt && conceptEN.leonardoPrompt.length > 4;
387
+
388
+ const leonardoPromptExistsPT =
389
+ conceptPT.leonardoPrompt && conceptPT.leonardoPrompt.length > 4;
390
+
385
391
  // ✅ Check if prompt already exists and skip if override is false
386
- if (!override && conceptEN.leonardoPrompt && conceptPT.leonardoPrompt) {
392
+ if (!override && leonardoPromptExistsEN && leonardoPromptExistsPT) {
387
393
  console.log(
388
394
  `[${new Date().toISOString()}] ⚡ Leonardo prompt already exists for ${conceptSlug}, skipping.`
389
395
  );
390
- return { generatedPrompt: conceptEN.leonardoPrompt };
396
+ return { generatedPrompt: conceptEN.leonardoPrompt! };
391
397
  }
392
-
398
+
393
399
  // ✅ Ensure basic info is present
394
400
  if (
395
401
  !conceptEN.name ||
@@ -403,7 +409,7 @@ export class ConceptService {
403
409
  `❌ Basic info must be populated before generating Leonardo prompt for concept: ${conceptSlug}`
404
410
  );
405
411
  }
406
-
412
+
407
413
  // ✅ Generate prompt request
408
414
  const messages = this.context
409
415
  .buildLLMMessages()
@@ -411,7 +417,7 @@ export class ConceptService {
411
417
  conceptSlug,
412
418
  combination: combinationString,
413
419
  });
414
-
420
+
415
421
  // ✅ Call ChatGPT API
416
422
  const response = await this.context.api().callTogether.single(messages, {});
417
423
  if (!response) {
@@ -419,25 +425,28 @@ export class ConceptService {
419
425
  `❌ Failed to generate Leonardo prompt for concept: ${conceptSlug}`
420
426
  );
421
427
  }
422
-
428
+
423
429
  // Clean the response to remove unwanted elements
424
430
  let generatedPrompt = response.trim();
425
-
431
+
426
432
  // Step 1: Remove **Prompt:** or Prompt: from the start
427
- generatedPrompt = generatedPrompt.replace(/^(?:\*\*Prompt:\*\*|Prompt:)\s*/, '');
428
-
433
+ generatedPrompt = generatedPrompt.replace(
434
+ /^(?:\*\*Prompt:\*\*|Prompt:)\s*/,
435
+ ''
436
+ );
437
+
429
438
  // Step 2: Remove character count suffix (e.g., *(Character count: 749)* or *(1498 characters)*)
430
439
  generatedPrompt = generatedPrompt.replace(/\s*\*\([^()]*\)*\s*$/, '');
431
-
440
+
432
441
  // Step 3: Remove surrounding quotes if they wrap the entire prompt
433
442
  if (generatedPrompt.startsWith('"') && generatedPrompt.endsWith('"')) {
434
443
  generatedPrompt = generatedPrompt.slice(1, -1).trim();
435
444
  }
436
-
445
+
437
446
  console.log(
438
447
  `[${new Date().toISOString()}] ✨ Cleaned generated prompt: "${generatedPrompt}"`
439
448
  );
440
-
449
+
441
450
  // ✅ Store the generated prompt in D1 for both languages
442
451
  console.log(
443
452
  `[${new Date().toISOString()}] 💾 Storing Leonardo prompt for ${conceptSlug}:${combinationString} in D1...`
@@ -462,11 +471,11 @@ export class ConceptService {
462
471
  )
463
472
  ),
464
473
  ]);
465
-
474
+
466
475
  console.log(
467
476
  `[${new Date().toISOString()}] ✅ Leonardo prompt stored for concept: ${conceptSlug}, combination: ${combinationString}, in both languages.`
468
477
  );
469
-
478
+
470
479
  return { generatedPrompt };
471
480
  }
472
481
 
@@ -1817,41 +1826,44 @@ export class ConceptService {
1817
1826
  .limit(1)
1818
1827
  .execute();
1819
1828
 
1820
- return !!conceptData?.leonardoPrompt && conceptData.leonardoPrompt.length > 10;
1829
+ return (
1830
+ !!conceptData?.leonardoPrompt && conceptData.leonardoPrompt.length > 10
1831
+ );
1821
1832
  }
1822
1833
 
1823
- // src/services/ConceptService.ts
1824
- async checkConceptCompletion(
1825
- conceptSlug: Concept,
1826
- combinationString: string,
1827
- lang: string = 'en-us'
1828
- ): Promise<boolean> {
1829
- const db = this.context.drizzle();
1830
- const [conceptData] = await db
1831
- .select({
1832
- leonardoPrompt: schema.conceptsData.leonardoPrompt,
1833
- postImages: schema.conceptsData.postImages,
1834
- reelImages: schema.conceptsData.reelImages,
1835
- })
1836
- .from(schema.conceptsData)
1837
- .where(
1838
- and(
1839
- eq(schema.conceptsData.conceptSlug, conceptSlug),
1840
- eq(schema.conceptsData.combination, combinationString),
1841
- eq(schema.conceptsData.language, lang)
1834
+ // src/services/ConceptService.ts
1835
+ async checkConceptCompletion(
1836
+ conceptSlug: Concept,
1837
+ combinationString: string,
1838
+ lang: string = 'en-us'
1839
+ ): Promise<boolean> {
1840
+ const db = this.context.drizzle();
1841
+ const [conceptData] = await db
1842
+ .select({
1843
+ leonardoPrompt: schema.conceptsData.leonardoPrompt,
1844
+ postImages: schema.conceptsData.postImages,
1845
+ reelImages: schema.conceptsData.reelImages,
1846
+ })
1847
+ .from(schema.conceptsData)
1848
+ .where(
1849
+ and(
1850
+ eq(schema.conceptsData.conceptSlug, conceptSlug),
1851
+ eq(schema.conceptsData.combination, combinationString),
1852
+ eq(schema.conceptsData.language, lang)
1853
+ )
1842
1854
  )
1843
- )
1844
- .limit(1)
1845
- .execute();
1846
-
1847
- if (!conceptData) return false; // No concept data found
1855
+ .limit(1)
1856
+ .execute();
1848
1857
 
1849
- // Check if postImages and reelImages are valid non-empty JSON arrays
1850
- const hasPostImages =
1851
- conceptData.postImages &&
1852
- conceptData.postImages.trim().length > 4 && // Ensures length > 4 to exclude "[]"
1853
- JSON.parse(conceptData.postImages).length > 2;
1858
+ if (!conceptData) return false; // No concept data found
1859
+ const hasPrompt =
1860
+ !!conceptData?.leonardoPrompt && conceptData.leonardoPrompt.length > 10;
1861
+ // Check if postImages and reelImages are valid non-empty JSON arrays
1862
+ const hasPostImages =
1863
+ conceptData.postImages &&
1864
+ conceptData.postImages.trim().length > 4 && // Ensures length > 4 to exclude "[]"
1865
+ JSON.parse(conceptData.postImages).length > 2;
1854
1866
 
1855
- return !!conceptData.leonardoPrompt && !!hasPostImages;
1856
- }
1867
+ return hasPrompt && !!hasPostImages;
1868
+ }
1857
1869
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zodic/shared",
3
- "version": "0.0.371",
3
+ "version": "0.0.372",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "publishConfig": {