@zodic/shared 0.0.336 → 0.0.338

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.
@@ -0,0 +1,104 @@
1
+ import { inject, injectable } from 'inversify';
2
+ import { and, eq } from 'drizzle-orm';
3
+ import { AppContext, schema } from '../..';
4
+ import { BackendCtx } from '../../types/backend';
5
+ import { ArtifactList } from '../../types';
6
+
7
+ @injectable()
8
+ export class ArtifactService {
9
+ constructor(@inject(AppContext) private context: AppContext) {}
10
+
11
+ private async log(
12
+ level: 'info' | 'debug' | 'warn' | 'error',
13
+ message: string,
14
+ context: Record<string, any> = {}
15
+ ) {
16
+ const logId = `artifact-service:${Date.now()}`;
17
+ const logMessage = `[${level.toUpperCase()}] ${message}`;
18
+
19
+ console[level](logMessage, context);
20
+ const db = this.context.drizzle();
21
+ try {
22
+ await db
23
+ .insert(schema.logs)
24
+ .values({
25
+ id: logId,
26
+ level,
27
+ message,
28
+ context: JSON.stringify(context),
29
+ createdAt: new Date().getTime(),
30
+ })
31
+ .execute();
32
+ } catch (error) {
33
+ console.error('[ERROR] Failed to persist log to database:', {
34
+ error,
35
+ logId,
36
+ message,
37
+ context,
38
+ });
39
+ }
40
+ }
41
+
42
+ async generateCosmicMirror(
43
+ artifactId: string,
44
+ userId: string,
45
+ generatedImageId: string,
46
+ archetypeDataId: string,
47
+ size: string
48
+ ) {
49
+ await this.log('info', 'Starting cosmic mirror generation', {
50
+ artifactId,
51
+ userId,
52
+ generatedImageId,
53
+ archetypeDataId,
54
+ size
55
+ });
56
+
57
+ const drizzle = this.context.drizzle();
58
+ const { artifacts, userArtifacts, generations, userConcepts } = schema;
59
+
60
+ // Implementation will be moved from ArtifactController
61
+ }
62
+
63
+ async cleanupStaleCosmicMirror(
64
+ userArtifact: typeof schema.userArtifacts.$inferSelect
65
+ ): Promise<void> {
66
+ await this.log('info', 'Cleaning up stale cosmic mirror', {
67
+ userArtifactId: userArtifact.id
68
+ });
69
+
70
+ const drizzle = this.context.drizzle();
71
+ const { generations } = schema;
72
+
73
+ // Delete KV entries
74
+ const kvKeys = await this.context.kvCosmicMirrorManagementStore().list({
75
+ prefix: `cosmic-mirror:${userArtifact.id}:`
76
+ });
77
+ for (const key of kvKeys.keys) {
78
+ await this.context.kvCosmicMirrorManagementStore().delete(key.name);
79
+ }
80
+
81
+ // Delete generations
82
+ await drizzle
83
+ .delete(generations)
84
+ .where(eq(generations.userArtifactId, userArtifact.id));
85
+
86
+ // Delete user artifact
87
+ await drizzle
88
+ .delete(schema.userArtifacts)
89
+ .where(eq(schema.userArtifacts.id, userArtifact.id));
90
+ }
91
+
92
+ async retryStaleCosmicMirror(
93
+ userArtifact: typeof schema.userArtifacts.$inferSelect
94
+ ): Promise<any> {
95
+ await this.log('info', 'Retrying stale cosmic mirror', {
96
+ userArtifactId: userArtifact.id
97
+ });
98
+
99
+ const drizzle = this.context.drizzle();
100
+ const { users, artifactFaceswap } = schema;
101
+
102
+ // Implementation will be moved from ArtifactController
103
+ }
104
+ }
@@ -1,3 +1,4 @@
1
1
  export * from './ConceptService';
2
2
  export * from './ArchetypeService';
3
- export * from './LeonardoService';
3
+ export * from './LeonardoService';
4
+ export * from './ArtifactService';
@@ -209,7 +209,8 @@ export class ArchetypeWorkflow {
209
209
  });
210
210
  return {
211
211
  archetypes: updatedArchetypes.map(
212
- ({ name, essenceLine, description, virtues, images }) => ({
212
+ ({ id, name, essenceLine, description, virtues, images }) => ({
213
+ id,
213
214
  name,
214
215
  essenceLine,
215
216
  description,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zodic/shared",
3
- "version": "0.0.336",
3
+ "version": "0.0.338",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "publishConfig": {