@zodic/shared 0.0.80 → 0.0.82

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.
@@ -18,7 +18,7 @@ export class ArchetypeService {
18
18
  .buildLLMMessages()
19
19
  .generateCosmicMirrorArchetypeBasicInfo({ sun, ascendant, moon });
20
20
 
21
- const response = await this.context.api().callDeepSeek.single(messages, {});
21
+ const response = await this.context.api().callChatGPT.single(messages, {});
22
22
 
23
23
  if (!response) {
24
24
  throw new Error(
@@ -152,12 +152,7 @@ export class ArchetypeService {
152
152
  const kvStore = this.context.kvCosmicMirrorArchetypesStore();
153
153
 
154
154
  const kvKeys = [1, 2, 3].map((index) =>
155
- buildCosmicMirrorArchetypeKVKey(
156
- 'en-us',
157
- combinationString,
158
- 'male',
159
- index
160
- )
155
+ buildCosmicMirrorArchetypeKVKey('en-us', combinationString, 'male', index)
161
156
  );
162
157
 
163
158
  const archetypeEntries = await Promise.all(
@@ -179,7 +174,7 @@ export class ArchetypeService {
179
174
  }))
180
175
  );
181
176
 
182
- const response = await this.context.api().callDeepSeek.single(messages, {});
177
+ const response = await this.context.api().callChatGPT.single(messages, {});
183
178
  if (!response) {
184
179
  throw new Error(
185
180
  `Failed to generate Leonardo prompts for: ${combinationString}`
@@ -155,7 +155,7 @@ export class LeonardoService {
155
155
  const messages = this.context
156
156
  .buildLLMMessages()
157
157
  .generateCosmicMirrorArchetypesLeonardoPrompts(archetypes);
158
- const response = await this.context.api().callDeepSeek.single(messages, {});
158
+ const response = await this.context.api().callChatGPT.single(messages, {});
159
159
 
160
160
  if (!response) {
161
161
  throw new Error('Leonardo prompts not generated');
@@ -194,4 +194,195 @@ export class LeonardoService {
194
194
  throw error;
195
195
  }
196
196
  }
197
+
198
+ async uploadImage(
199
+ file: File
200
+ ): Promise<{ uploadedImageId: string; uploadedImageUrl: string }> {
201
+ const fileName = file.name;
202
+ const fileExtension = fileName.split('.').pop()?.toLowerCase();
203
+ const mimeType = `image/${fileExtension}`;
204
+
205
+ if (!fileExtension) {
206
+ throw new Error('Invalid file extension');
207
+ }
208
+
209
+ console.log('Starting uploadImage with details:', {
210
+ fileName,
211
+ fileExtension,
212
+ mimeType,
213
+ });
214
+
215
+ try {
216
+ console.log('Requesting presigned URL...');
217
+ const presignedUrlData = await this.context
218
+ .api()
219
+ .callLeonardo.generatePresignedUrl({
220
+ extension: fileExtension,
221
+ });
222
+
223
+ if (
224
+ !presignedUrlData.url ||
225
+ !presignedUrlData.fields ||
226
+ !presignedUrlData.id
227
+ ) {
228
+ throw new Error('Invalid presigned URL response from API');
229
+ }
230
+
231
+ console.log('Uploading file...');
232
+ await this.uploadToPresignedUrl(
233
+ presignedUrlData.url,
234
+ presignedUrlData.fields,
235
+ file
236
+ );
237
+
238
+ const uploadedImageId = presignedUrlData.id;
239
+ const uploadedImageUrl = `https://cdn.leonardo.ai/users/b117a933-e5c9-45b2-96aa-4b619c2d74ba/initImages/${uploadedImageId}.${fileExtension}`;
240
+
241
+ console.log('File uploaded successfully:', {
242
+ uploadedImageId,
243
+ uploadedImageUrl,
244
+ });
245
+
246
+ return { uploadedImageId, uploadedImageUrl };
247
+ } catch (error: any) {
248
+ console.error('Error during image upload:', error.message);
249
+ throw new Error('Failed to upload image');
250
+ }
251
+ }
252
+
253
+ async uploadImageByUrl(
254
+ imageUrl: string
255
+ ): Promise<{ uploadedImageId: string; uploadedImageUrl: string }> {
256
+ console.log('Starting uploadImageByUrl with imageUrl:', imageUrl);
257
+
258
+ try {
259
+ // Fetch the image from the provided URL
260
+ console.log('Fetching image from URL...');
261
+ const response = await fetch(imageUrl);
262
+
263
+ if (!response.ok) {
264
+ throw new Error(
265
+ `Failed to fetch image from URL: ${response.statusText}`
266
+ );
267
+ }
268
+
269
+ const blob = await response.blob();
270
+ const fileExtension = imageUrl.split('.').pop()?.toLowerCase() || 'jpg';
271
+ const mimeType = blob.type || `image/${fileExtension}`;
272
+
273
+ if (!fileExtension || !mimeType.startsWith('image/')) {
274
+ throw new Error('Invalid image URL or file type');
275
+ }
276
+
277
+ console.log('Image fetched successfully:', {
278
+ fileExtension,
279
+ mimeType,
280
+ });
281
+
282
+ // Request a presigned URL for uploading
283
+ console.log('Requesting presigned URL...');
284
+ const presignedUrlData = await this.context
285
+ .api()
286
+ .callLeonardo.generatePresignedUrl({
287
+ extension: fileExtension,
288
+ });
289
+
290
+ if (
291
+ !presignedUrlData.url ||
292
+ !presignedUrlData.fields ||
293
+ !presignedUrlData.id
294
+ ) {
295
+ throw new Error('Invalid presigned URL response from API');
296
+ }
297
+
298
+ console.log('Presigned URL obtained:', presignedUrlData);
299
+
300
+ // Prepare the file to upload
301
+ const file = new File([blob], `upload.${fileExtension}`, {
302
+ type: mimeType,
303
+ });
304
+
305
+ console.log('Uploading file to presigned URL...');
306
+ await this.uploadToPresignedUrl(
307
+ presignedUrlData.url,
308
+ presignedUrlData.fields,
309
+ file as any
310
+ );
311
+
312
+ const uploadedImageId = presignedUrlData.id;
313
+ const uploadedImageUrl = `https://cdn.leonardo.ai/users/b117a933-e5c9-45b2-96aa-4b619c2d74ba/initImages/${uploadedImageId}.${fileExtension}`;
314
+
315
+ console.log('Image uploaded successfully:', {
316
+ uploadedImageId,
317
+ uploadedImageUrl,
318
+ });
319
+
320
+ return { uploadedImageId, uploadedImageUrl };
321
+ } catch (error: any) {
322
+ console.error('Error during uploadImageByUrl:', error.message);
323
+ throw new Error('Failed to upload image by URL');
324
+ }
325
+ }
326
+
327
+ private async uploadToPresignedUrl(
328
+ presignedUrl: string,
329
+ fields: string,
330
+ file: File
331
+ ): Promise<void> {
332
+ const parsedFields = JSON.parse(fields);
333
+ const formData = new FormData();
334
+
335
+ Object.entries(parsedFields).forEach(([key, value]) => {
336
+ formData.append(key, value as string);
337
+ });
338
+ formData.append('file', file);
339
+
340
+ console.log('Uploading with FormData:', Array.from(formData.entries()));
341
+
342
+ const response = await fetch(presignedUrl, {
343
+ method: 'POST',
344
+ body: formData,
345
+ });
346
+
347
+ if (!response.ok) {
348
+ const errorDetails = await response.text();
349
+ console.error('Upload failed:', errorDetails);
350
+ throw new Error(`Image upload failed: ${response.status}`);
351
+ }
352
+
353
+ console.log('Upload to presigned URL successful');
354
+ }
355
+
356
+ /**
357
+ * Personalizes a Leonardo prompt based on user-specific traits.
358
+ * @param params - Details for prompt personalization
359
+ * @returns {Promise<string>} - The personalized prompt
360
+ */
361
+ async personalizeCosmicMirrorLeonardoPrompt(params: {
362
+ leonardoPrompt: string;
363
+ traits: string;
364
+ }): Promise<string> {
365
+ const { leonardoPrompt, traits } = params;
366
+
367
+ const messages = this.context
368
+ .buildLLMMessages()
369
+ .personalizeCosmicMirrorLeonardoPrompt({ leonardoPrompt, traits });
370
+
371
+ try {
372
+ const personalizedPrompt = await this.context
373
+ .api()
374
+ .callChatGPT.single(messages, {});
375
+
376
+ if (!personalizedPrompt) {
377
+ throw new Error('Failed to generate personalized prompt');
378
+ }
379
+
380
+ console.log('Personalized Leonardo Prompt:', personalizedPrompt);
381
+
382
+ return personalizedPrompt.trim();
383
+ } catch (error) {
384
+ console.error('Error personalizing Leonardo prompt:', error);
385
+ throw error;
386
+ }
387
+ }
197
388
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zodic/shared",
3
- "version": "0.0.80",
3
+ "version": "0.0.82",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "publishConfig": {