clhq-postgres-module 1.1.0-alpha.105 → 1.1.0-alpha.107
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/dist/entities/ai-embedding.entity.d.ts +33 -0
- package/dist/entities/ai-embedding.entity.js +102 -0
- package/dist/entities/asset-metadata.entity.d.ts +72 -0
- package/dist/entities/asset-metadata.entity.js +140 -0
- package/dist/entities/index.d.ts +5 -0
- package/dist/entities/index.js +5 -0
- package/dist/entities/metadata-activity-log.entity.d.ts +50 -0
- package/dist/entities/metadata-activity-log.entity.js +123 -0
- package/dist/entities/project-metadata.entity.d.ts +70 -0
- package/dist/entities/project-metadata.entity.js +141 -0
- package/dist/entities/user-context.entity.d.ts +59 -0
- package/dist/entities/user-context.entity.js +162 -0
- package/dist/repositories/ai-embedding.repository.d.ts +38 -0
- package/dist/repositories/ai-embedding.repository.js +146 -0
- package/dist/repositories/asset-metadata.repository.d.ts +39 -0
- package/dist/repositories/asset-metadata.repository.js +195 -0
- package/dist/repositories/index.d.ts +5 -0
- package/dist/repositories/index.js +11 -1
- package/dist/repositories/metadata-activity-log.repository.d.ts +41 -0
- package/dist/repositories/metadata-activity-log.repository.js +220 -0
- package/dist/repositories/project-metadata.repository.d.ts +32 -0
- package/dist/repositories/project-metadata.repository.js +186 -0
- package/dist/repositories/repository.module.js +10 -0
- package/dist/repositories/user-context.repository.d.ts +66 -0
- package/dist/repositories/user-context.repository.js +161 -0
- package/package.json +4 -1
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.ProjectMetadataRepository = void 0;
|
|
16
|
+
const typeorm_1 = require("typeorm");
|
|
17
|
+
const common_1 = require("@nestjs/common");
|
|
18
|
+
const typeorm_2 = require("@nestjs/typeorm");
|
|
19
|
+
const base_repository_1 = require("./base.repository");
|
|
20
|
+
const project_metadata_entity_1 = require("../entities/project-metadata.entity");
|
|
21
|
+
let ProjectMetadataRepository = class ProjectMetadataRepository extends base_repository_1.BaseRepository {
|
|
22
|
+
constructor(projectMetadataRepository) {
|
|
23
|
+
super(projectMetadataRepository);
|
|
24
|
+
this.projectMetadataRepository = projectMetadataRepository;
|
|
25
|
+
}
|
|
26
|
+
async findByProjectId(projectId) {
|
|
27
|
+
return this.projectMetadataRepository.findOne({
|
|
28
|
+
where: { projectId },
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
async findByUserId(userId) {
|
|
32
|
+
return this.projectMetadataRepository.find({
|
|
33
|
+
where: { userId },
|
|
34
|
+
order: { updatedAt: 'DESC' },
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
async findByWorkspaceId(workspaceId) {
|
|
38
|
+
return this.projectMetadataRepository.find({
|
|
39
|
+
where: { workspaceId },
|
|
40
|
+
order: { updatedAt: 'DESC' },
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
async findByProjectType(userId, projectType) {
|
|
44
|
+
return this.projectMetadataRepository.find({
|
|
45
|
+
where: { userId, projectType },
|
|
46
|
+
order: { updatedAt: 'DESC' },
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
async updateComposition(projectId, composition) {
|
|
50
|
+
await this.projectMetadataRepository.update({ projectId }, { composition });
|
|
51
|
+
return this.findByProjectId(projectId);
|
|
52
|
+
}
|
|
53
|
+
async updateStyleFingerprint(projectId, styleFingerprint) {
|
|
54
|
+
await this.projectMetadataRepository.update({ projectId }, { styleFingerprint });
|
|
55
|
+
return this.findByProjectId(projectId);
|
|
56
|
+
}
|
|
57
|
+
async updateEmbedding(projectId, embedding) {
|
|
58
|
+
await this.projectMetadataRepository.update({ projectId }, {
|
|
59
|
+
projectEmbedding: embedding,
|
|
60
|
+
embeddingGeneratedAt: new Date(),
|
|
61
|
+
});
|
|
62
|
+
return this.findByProjectId(projectId);
|
|
63
|
+
}
|
|
64
|
+
async recordEditSession(projectId, sessionDurationMs) {
|
|
65
|
+
await this.projectMetadataRepository
|
|
66
|
+
.createQueryBuilder()
|
|
67
|
+
.update()
|
|
68
|
+
.set({
|
|
69
|
+
editSessionsCount: () => 'edit_sessions_count + 1',
|
|
70
|
+
totalEditTimeMs: () => `total_edit_time_ms + ${sessionDurationMs}`,
|
|
71
|
+
})
|
|
72
|
+
.where('project_id = :projectId', { projectId })
|
|
73
|
+
.execute();
|
|
74
|
+
}
|
|
75
|
+
async addAssetUsed(projectId, assetId) {
|
|
76
|
+
const metadata = await this.findByProjectId(projectId);
|
|
77
|
+
if (!metadata)
|
|
78
|
+
return;
|
|
79
|
+
const assetsUsed = metadata.assetsUsed || [];
|
|
80
|
+
if (!assetsUsed.includes(assetId)) {
|
|
81
|
+
assetsUsed.push(assetId);
|
|
82
|
+
await this.projectMetadataRepository.update({ projectId }, { assetsUsed });
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
async incrementEffectUsage(projectId, effectName) {
|
|
86
|
+
const metadata = await this.findByProjectId(projectId);
|
|
87
|
+
if (!metadata)
|
|
88
|
+
return;
|
|
89
|
+
const effectsUsed = metadata.effectsUsed || {};
|
|
90
|
+
effectsUsed[effectName] = (effectsUsed[effectName] || 0) + 1;
|
|
91
|
+
await this.projectMetadataRepository.update({ projectId }, { effectsUsed });
|
|
92
|
+
}
|
|
93
|
+
async addExportToHistory(projectId, exportData) {
|
|
94
|
+
const metadata = await this.findByProjectId(projectId);
|
|
95
|
+
if (!metadata)
|
|
96
|
+
return;
|
|
97
|
+
const exportHistory = metadata.exportHistory || [];
|
|
98
|
+
exportHistory.push({
|
|
99
|
+
...exportData,
|
|
100
|
+
exportedAt: new Date().toISOString(),
|
|
101
|
+
});
|
|
102
|
+
await this.projectMetadataRepository.update({ projectId }, { exportHistory });
|
|
103
|
+
}
|
|
104
|
+
async recordAiSuggestion(projectId, suggestionType, accepted) {
|
|
105
|
+
const metadata = await this.findByProjectId(projectId);
|
|
106
|
+
if (!metadata)
|
|
107
|
+
return;
|
|
108
|
+
const aiSuggestionsApplied = metadata.aiSuggestionsApplied || [];
|
|
109
|
+
aiSuggestionsApplied.push({
|
|
110
|
+
suggestionType,
|
|
111
|
+
appliedAt: new Date().toISOString(),
|
|
112
|
+
accepted,
|
|
113
|
+
});
|
|
114
|
+
await this.projectMetadataRepository.update({ projectId }, { aiSuggestionsApplied });
|
|
115
|
+
}
|
|
116
|
+
async findSimilarByEmbedding(embedding, userId, limit = 10, excludeProjectId) {
|
|
117
|
+
const embeddingStr = JSON.stringify(embedding);
|
|
118
|
+
let query = this.projectMetadataRepository
|
|
119
|
+
.createQueryBuilder('pm')
|
|
120
|
+
.select('pm.*')
|
|
121
|
+
.addSelect(`1 - (pm.project_embedding::vector(1536) <=> '${embeddingStr}'::vector(1536))`, 'similarity')
|
|
122
|
+
.where('pm.user_id = :userId', { userId })
|
|
123
|
+
.andWhere('pm.project_embedding IS NOT NULL');
|
|
124
|
+
if (excludeProjectId) {
|
|
125
|
+
query = query.andWhere('pm.project_id != :excludeProjectId', {
|
|
126
|
+
excludeProjectId,
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
const results = await query
|
|
130
|
+
.orderBy('similarity', 'DESC')
|
|
131
|
+
.limit(limit)
|
|
132
|
+
.getRawMany();
|
|
133
|
+
return results;
|
|
134
|
+
}
|
|
135
|
+
async getStylePreferencesForUser(userId) {
|
|
136
|
+
const projects = await this.projectMetadataRepository.find({
|
|
137
|
+
where: { userId },
|
|
138
|
+
select: ['styleFingerprint', 'effectsUsed'],
|
|
139
|
+
});
|
|
140
|
+
const transitions = {};
|
|
141
|
+
const effects = {};
|
|
142
|
+
let totalClipDuration = 0;
|
|
143
|
+
let clipDurationCount = 0;
|
|
144
|
+
const pacingCounts = {};
|
|
145
|
+
for (const project of projects) {
|
|
146
|
+
if (project.styleFingerprint?.transitions) {
|
|
147
|
+
for (const t of project.styleFingerprint.transitions) {
|
|
148
|
+
transitions[t] = (transitions[t] || 0) + 1;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
if (project.effectsUsed) {
|
|
152
|
+
for (const [effect, count] of Object.entries(project.effectsUsed)) {
|
|
153
|
+
effects[effect] = (effects[effect] || 0) + count;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
if (project.styleFingerprint?.avgClipDuration) {
|
|
157
|
+
totalClipDuration += project.styleFingerprint.avgClipDuration;
|
|
158
|
+
clipDurationCount++;
|
|
159
|
+
}
|
|
160
|
+
if (project.styleFingerprint?.pacing) {
|
|
161
|
+
pacingCounts[project.styleFingerprint.pacing] =
|
|
162
|
+
(pacingCounts[project.styleFingerprint.pacing] || 0) + 1;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
let preferredPacing = 'medium';
|
|
166
|
+
let maxPacingCount = 0;
|
|
167
|
+
for (const [pacing, count] of Object.entries(pacingCounts)) {
|
|
168
|
+
if (count > maxPacingCount) {
|
|
169
|
+
maxPacingCount = count;
|
|
170
|
+
preferredPacing = pacing;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return {
|
|
174
|
+
topTransitions: transitions,
|
|
175
|
+
topEffects: effects,
|
|
176
|
+
avgClipDuration: clipDurationCount > 0 ? totalClipDuration / clipDurationCount : 0,
|
|
177
|
+
preferredPacing,
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
exports.ProjectMetadataRepository = ProjectMetadataRepository;
|
|
182
|
+
exports.ProjectMetadataRepository = ProjectMetadataRepository = __decorate([
|
|
183
|
+
(0, common_1.Injectable)(),
|
|
184
|
+
__param(0, (0, typeorm_2.InjectRepository)(project_metadata_entity_1.ProjectMetadata)),
|
|
185
|
+
__metadata("design:paramtypes", [typeorm_1.Repository])
|
|
186
|
+
], ProjectMetadataRepository);
|
|
@@ -37,6 +37,11 @@ const repositories = [
|
|
|
37
37
|
_1.VideoRenderRepository,
|
|
38
38
|
_1.VideoFilmstripRepository,
|
|
39
39
|
_1.AudioWaveformRepository,
|
|
40
|
+
_1.AssetMetadataRepository,
|
|
41
|
+
_1.ProjectMetadataRepository,
|
|
42
|
+
_1.UserContextRepository,
|
|
43
|
+
_1.AiEmbeddingRepository,
|
|
44
|
+
_1.MetadataActivityLogRepository,
|
|
40
45
|
];
|
|
41
46
|
const entities = [
|
|
42
47
|
entities_1.User,
|
|
@@ -64,6 +69,11 @@ const entities = [
|
|
|
64
69
|
entities_1.VideoRender,
|
|
65
70
|
entities_1.VideoFilmstrip,
|
|
66
71
|
entities_1.AudioWaveform,
|
|
72
|
+
entities_1.AssetMetadata,
|
|
73
|
+
entities_1.ProjectMetadata,
|
|
74
|
+
entities_1.UserContext,
|
|
75
|
+
entities_1.AiEmbedding,
|
|
76
|
+
entities_1.MetadataActivityLog,
|
|
67
77
|
];
|
|
68
78
|
let RepositoryModule = class RepositoryModule {
|
|
69
79
|
};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { Repository } from 'typeorm';
|
|
2
|
+
import { BaseRepository } from './base.repository';
|
|
3
|
+
import { UserContext } from '../entities/user-context.entity';
|
|
4
|
+
export declare class UserContextRepository extends BaseRepository<UserContext> {
|
|
5
|
+
private readonly userContextRepository;
|
|
6
|
+
constructor(userContextRepository: Repository<UserContext>);
|
|
7
|
+
findByUserId(userId: string): Promise<UserContext | null>;
|
|
8
|
+
getOrCreate(userId: string): Promise<UserContext>;
|
|
9
|
+
updateStylePreferences(userId: string, preferences: {
|
|
10
|
+
preferredStyles?: string[];
|
|
11
|
+
preferredGenres?: string[];
|
|
12
|
+
preferredTransitions?: string[];
|
|
13
|
+
preferredEffects?: string[];
|
|
14
|
+
preferredFonts?: string[];
|
|
15
|
+
}): Promise<UserContext | null>;
|
|
16
|
+
updateDefaultSettings(userId: string, settings: {
|
|
17
|
+
defaultAspectRatio?: string;
|
|
18
|
+
defaultResolution?: string;
|
|
19
|
+
defaultFps?: number;
|
|
20
|
+
}): Promise<UserContext | null>;
|
|
21
|
+
updateBrandAssets(userId: string, brandAssets: {
|
|
22
|
+
brandColors?: UserContext['brandColors'];
|
|
23
|
+
brandFonts?: UserContext['brandFonts'];
|
|
24
|
+
brandLogoAssetIds?: string[];
|
|
25
|
+
brandWatermarkAssetId?: string;
|
|
26
|
+
}): Promise<UserContext | null>;
|
|
27
|
+
updateBehavioralAnalytics(userId: string, analytics: {
|
|
28
|
+
avgProjectDurationMs?: number;
|
|
29
|
+
avgSessionLengthMs?: number;
|
|
30
|
+
mostUsedEffects?: Record<string, number>;
|
|
31
|
+
mostUsedTransitions?: Record<string, number>;
|
|
32
|
+
editingPatterns?: UserContext['editingPatterns'];
|
|
33
|
+
skillLevel?: UserContext['skillLevel'];
|
|
34
|
+
activityHeatmap?: UserContext['activityHeatmap'];
|
|
35
|
+
}): Promise<UserContext | null>;
|
|
36
|
+
incrementProjectCount(userId: string, completed?: boolean): Promise<void>;
|
|
37
|
+
addEditTime(userId: string, durationMs: number): Promise<void>;
|
|
38
|
+
recordAiInteraction(userId: string, accepted: boolean): Promise<void>;
|
|
39
|
+
addRecentPrompt(userId: string, prompt: string, successful: boolean): Promise<void>;
|
|
40
|
+
updateEmbedding(userId: string, embedding: number[]): Promise<UserContext | null>;
|
|
41
|
+
markAggregated(userId: string): Promise<void>;
|
|
42
|
+
findNeedingAggregation(limit?: number): Promise<UserContext[]>;
|
|
43
|
+
getAiContext(userId: string): Promise<{
|
|
44
|
+
preferences: {
|
|
45
|
+
styles: string[];
|
|
46
|
+
genres: string[];
|
|
47
|
+
transitions: string[];
|
|
48
|
+
effects: string[];
|
|
49
|
+
};
|
|
50
|
+
defaults: {
|
|
51
|
+
aspectRatio: string;
|
|
52
|
+
resolution: string;
|
|
53
|
+
fps: number;
|
|
54
|
+
};
|
|
55
|
+
analytics: {
|
|
56
|
+
totalProjects: number;
|
|
57
|
+
avgProjectDuration: number;
|
|
58
|
+
skillLevel: string;
|
|
59
|
+
preferredPacing: string;
|
|
60
|
+
};
|
|
61
|
+
brand: {
|
|
62
|
+
colors: UserContext['brandColors'];
|
|
63
|
+
fonts: UserContext['brandFonts'];
|
|
64
|
+
};
|
|
65
|
+
} | null>;
|
|
66
|
+
}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.UserContextRepository = void 0;
|
|
16
|
+
const typeorm_1 = require("typeorm");
|
|
17
|
+
const common_1 = require("@nestjs/common");
|
|
18
|
+
const typeorm_2 = require("@nestjs/typeorm");
|
|
19
|
+
const base_repository_1 = require("./base.repository");
|
|
20
|
+
const user_context_entity_1 = require("../entities/user-context.entity");
|
|
21
|
+
let UserContextRepository = class UserContextRepository extends base_repository_1.BaseRepository {
|
|
22
|
+
constructor(userContextRepository) {
|
|
23
|
+
super(userContextRepository);
|
|
24
|
+
this.userContextRepository = userContextRepository;
|
|
25
|
+
}
|
|
26
|
+
async findByUserId(userId) {
|
|
27
|
+
return this.userContextRepository.findOne({
|
|
28
|
+
where: { userId },
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
async getOrCreate(userId) {
|
|
32
|
+
let context = await this.findByUserId(userId);
|
|
33
|
+
if (!context) {
|
|
34
|
+
context = await this.create({ userId });
|
|
35
|
+
}
|
|
36
|
+
return context;
|
|
37
|
+
}
|
|
38
|
+
async updateStylePreferences(userId, preferences) {
|
|
39
|
+
await this.userContextRepository.update({ userId }, preferences);
|
|
40
|
+
return this.findByUserId(userId);
|
|
41
|
+
}
|
|
42
|
+
async updateDefaultSettings(userId, settings) {
|
|
43
|
+
await this.userContextRepository.update({ userId }, settings);
|
|
44
|
+
return this.findByUserId(userId);
|
|
45
|
+
}
|
|
46
|
+
async updateBrandAssets(userId, brandAssets) {
|
|
47
|
+
await this.userContextRepository.update({ userId }, brandAssets);
|
|
48
|
+
return this.findByUserId(userId);
|
|
49
|
+
}
|
|
50
|
+
async updateBehavioralAnalytics(userId, analytics) {
|
|
51
|
+
await this.userContextRepository.update({ userId }, analytics);
|
|
52
|
+
return this.findByUserId(userId);
|
|
53
|
+
}
|
|
54
|
+
async incrementProjectCount(userId, completed = false) {
|
|
55
|
+
const updates = {
|
|
56
|
+
totalProjectsCount: () => 'total_projects_count + 1',
|
|
57
|
+
};
|
|
58
|
+
if (completed) {
|
|
59
|
+
updates.completedProjectsCount = () => 'completed_projects_count + 1';
|
|
60
|
+
}
|
|
61
|
+
await this.userContextRepository
|
|
62
|
+
.createQueryBuilder()
|
|
63
|
+
.update()
|
|
64
|
+
.set(updates)
|
|
65
|
+
.where('user_id = :userId', { userId })
|
|
66
|
+
.execute();
|
|
67
|
+
}
|
|
68
|
+
async addEditTime(userId, durationMs) {
|
|
69
|
+
await this.userContextRepository
|
|
70
|
+
.createQueryBuilder()
|
|
71
|
+
.update()
|
|
72
|
+
.set({
|
|
73
|
+
totalEditTimeMs: () => `total_edit_time_ms + ${durationMs}`,
|
|
74
|
+
})
|
|
75
|
+
.where('user_id = :userId', { userId })
|
|
76
|
+
.execute();
|
|
77
|
+
}
|
|
78
|
+
async recordAiInteraction(userId, accepted) {
|
|
79
|
+
const updates = {
|
|
80
|
+
aiPromptsCount: () => 'ai_prompts_count + 1',
|
|
81
|
+
};
|
|
82
|
+
if (accepted) {
|
|
83
|
+
updates.aiSuggestionsAccepted = () => 'ai_suggestions_accepted + 1';
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
updates.aiSuggestionsRejected = () => 'ai_suggestions_rejected + 1';
|
|
87
|
+
}
|
|
88
|
+
await this.userContextRepository
|
|
89
|
+
.createQueryBuilder()
|
|
90
|
+
.update()
|
|
91
|
+
.set(updates)
|
|
92
|
+
.where('user_id = :userId', { userId })
|
|
93
|
+
.execute();
|
|
94
|
+
}
|
|
95
|
+
async addRecentPrompt(userId, prompt, successful) {
|
|
96
|
+
const context = await this.findByUserId(userId);
|
|
97
|
+
if (!context)
|
|
98
|
+
return;
|
|
99
|
+
const recentPrompts = context.recentPrompts || [];
|
|
100
|
+
recentPrompts.unshift({
|
|
101
|
+
prompt,
|
|
102
|
+
timestamp: new Date().toISOString(),
|
|
103
|
+
successful,
|
|
104
|
+
});
|
|
105
|
+
const trimmedPrompts = recentPrompts.slice(0, 20);
|
|
106
|
+
await this.userContextRepository.update({ userId }, { recentPrompts: trimmedPrompts });
|
|
107
|
+
}
|
|
108
|
+
async updateEmbedding(userId, embedding) {
|
|
109
|
+
await this.userContextRepository.update({ userId }, {
|
|
110
|
+
userEmbedding: embedding,
|
|
111
|
+
embeddingGeneratedAt: new Date(),
|
|
112
|
+
});
|
|
113
|
+
return this.findByUserId(userId);
|
|
114
|
+
}
|
|
115
|
+
async markAggregated(userId) {
|
|
116
|
+
await this.userContextRepository.update({ userId }, { lastAggregatedAt: new Date() });
|
|
117
|
+
}
|
|
118
|
+
async findNeedingAggregation(limit = 100) {
|
|
119
|
+
const oneDayAgo = new Date(Date.now() - 24 * 60 * 60 * 1000);
|
|
120
|
+
return this.userContextRepository
|
|
121
|
+
.createQueryBuilder('uc')
|
|
122
|
+
.where('(uc.last_aggregated_at IS NULL OR uc.last_aggregated_at < :oneDayAgo)', { oneDayAgo })
|
|
123
|
+
.orderBy('uc.last_aggregated_at', 'ASC', 'NULLS FIRST')
|
|
124
|
+
.limit(limit)
|
|
125
|
+
.getMany();
|
|
126
|
+
}
|
|
127
|
+
async getAiContext(userId) {
|
|
128
|
+
const context = await this.findByUserId(userId);
|
|
129
|
+
if (!context)
|
|
130
|
+
return null;
|
|
131
|
+
return {
|
|
132
|
+
preferences: {
|
|
133
|
+
styles: context.preferredStyles || [],
|
|
134
|
+
genres: context.preferredGenres || [],
|
|
135
|
+
transitions: context.preferredTransitions || [],
|
|
136
|
+
effects: context.preferredEffects || [],
|
|
137
|
+
},
|
|
138
|
+
defaults: {
|
|
139
|
+
aspectRatio: context.defaultAspectRatio || '16:9',
|
|
140
|
+
resolution: context.defaultResolution || '1080p',
|
|
141
|
+
fps: context.defaultFps || 30,
|
|
142
|
+
},
|
|
143
|
+
analytics: {
|
|
144
|
+
totalProjects: context.totalProjectsCount || 0,
|
|
145
|
+
avgProjectDuration: context.avgProjectDurationMs || 0,
|
|
146
|
+
skillLevel: context.skillLevel || 'beginner',
|
|
147
|
+
preferredPacing: context.editingPatterns?.preferredPacing || 'medium',
|
|
148
|
+
},
|
|
149
|
+
brand: {
|
|
150
|
+
colors: context.brandColors,
|
|
151
|
+
fonts: context.brandFonts,
|
|
152
|
+
},
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
exports.UserContextRepository = UserContextRepository;
|
|
157
|
+
exports.UserContextRepository = UserContextRepository = __decorate([
|
|
158
|
+
(0, common_1.Injectable)(),
|
|
159
|
+
__param(0, (0, typeorm_2.InjectRepository)(user_context_entity_1.UserContext)),
|
|
160
|
+
__metadata("design:paramtypes", [typeorm_1.Repository])
|
|
161
|
+
], UserContextRepository);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clhq-postgres-module",
|
|
3
|
-
"version": "1.1.0-alpha.
|
|
3
|
+
"version": "1.1.0-alpha.107",
|
|
4
4
|
"description": "PostgreSQL module using TypeORM for Clippy",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -38,6 +38,9 @@
|
|
|
38
38
|
"db:migrate:016": "npx ts-node scripts/run-migrations.ts 016",
|
|
39
39
|
"db:migrate:017": "npx ts-node scripts/run-migrations.ts 017",
|
|
40
40
|
"db:migrate:018": "npx ts-node scripts/run-migrations.ts 018",
|
|
41
|
+
"db:migrate:019": "npx ts-node scripts/run-migrations.ts 019",
|
|
42
|
+
"db:migrate:020": "npx ts-node scripts/run-migrations.ts 020",
|
|
43
|
+
"db:migrate:metadata": "npx ts-node scripts/run-migrations.ts 019 && npx ts-node scripts/run-migrations.ts 020",
|
|
41
44
|
"db:verify": "env-cmd -f ../../.env.dev npx ts-node scripts/verify-tables.ts",
|
|
42
45
|
"db:test": "env-cmd -f ../../.env.dev npx ts-node scripts/test-connections.ts",
|
|
43
46
|
"db:sync": "env-cmd -f ../../.env.dev npm run typeorm schema:sync -- -d src/config/data-source.ts",
|