agrs-sequelize-sdk 1.3.14 → 1.3.16
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/models/AIGenerationLog.js +85 -0
- package/models/AIGenerationRequest.js +206 -0
- package/models/GenericFlowRequest.js +115 -0
- package/package.json +1 -1
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AI Generation Log Model
|
|
3
|
+
*
|
|
4
|
+
* Stores detailed logs for each step of the generation process.
|
|
5
|
+
* Useful for debugging and monitoring.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
module.exports = (sequelize, DataTypes) => {
|
|
9
|
+
const AIGenerationLog = sequelize.define(
|
|
10
|
+
"AIGenerationLog",
|
|
11
|
+
{
|
|
12
|
+
id: {
|
|
13
|
+
type: DataTypes.UUID,
|
|
14
|
+
defaultValue: DataTypes.UUIDV4,
|
|
15
|
+
primaryKey: true,
|
|
16
|
+
},
|
|
17
|
+
requestId: {
|
|
18
|
+
type: DataTypes.STRING,
|
|
19
|
+
allowNull: false,
|
|
20
|
+
comment: "Reference to AIGenerationRequest.requestId",
|
|
21
|
+
indexes: [
|
|
22
|
+
{
|
|
23
|
+
fields: ["requestId"],
|
|
24
|
+
},
|
|
25
|
+
],
|
|
26
|
+
},
|
|
27
|
+
step: {
|
|
28
|
+
type: DataTypes.STRING,
|
|
29
|
+
allowNull: false,
|
|
30
|
+
comment:
|
|
31
|
+
"Step name: parsing, prompt_generation, image_generation, storage, logging",
|
|
32
|
+
},
|
|
33
|
+
level: {
|
|
34
|
+
type: DataTypes.ENUM("info", "warning", "error", "success"),
|
|
35
|
+
allowNull: false,
|
|
36
|
+
defaultValue: "info",
|
|
37
|
+
comment: "Log level",
|
|
38
|
+
},
|
|
39
|
+
message: {
|
|
40
|
+
type: DataTypes.TEXT,
|
|
41
|
+
allowNull: false,
|
|
42
|
+
comment: "Log message",
|
|
43
|
+
},
|
|
44
|
+
data: {
|
|
45
|
+
type: DataTypes.JSONB,
|
|
46
|
+
allowNull: true,
|
|
47
|
+
comment: "Additional log data (JSON)",
|
|
48
|
+
},
|
|
49
|
+
duration: {
|
|
50
|
+
type: DataTypes.INTEGER,
|
|
51
|
+
allowNull: true,
|
|
52
|
+
comment: "Step duration in milliseconds",
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
tableName: "ai_generation_logs",
|
|
57
|
+
timestamps: true,
|
|
58
|
+
createdAt: "createdAt",
|
|
59
|
+
updatedAt: false, // Logs are immutable
|
|
60
|
+
indexes: [
|
|
61
|
+
{
|
|
62
|
+
fields: ["requestId", "step"],
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
fields: ["level"],
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
fields: ["createdAt"],
|
|
69
|
+
},
|
|
70
|
+
],
|
|
71
|
+
}
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
// Associations
|
|
75
|
+
AIGenerationLog.associate = function (models) {
|
|
76
|
+
// Each log belongs to a request
|
|
77
|
+
AIGenerationLog.belongsTo(models.AIGenerationRequest, {
|
|
78
|
+
foreignKey: "requestId",
|
|
79
|
+
targetKey: "requestId",
|
|
80
|
+
as: "request",
|
|
81
|
+
});
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
return AIGenerationLog;
|
|
85
|
+
};
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AI Generation Request Model
|
|
3
|
+
*
|
|
4
|
+
* Stores all AI generation requests (banners, text, etc.)
|
|
5
|
+
* Replaces Google Sheets logging with database storage.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
module.exports = (sequelize, DataTypes) => {
|
|
9
|
+
const AIGenerationRequest = sequelize.define(
|
|
10
|
+
"AIGenerationRequest",
|
|
11
|
+
{
|
|
12
|
+
id: {
|
|
13
|
+
type: DataTypes.UUID,
|
|
14
|
+
defaultValue: DataTypes.UUIDV4,
|
|
15
|
+
primaryKey: true,
|
|
16
|
+
},
|
|
17
|
+
requestId: {
|
|
18
|
+
type: DataTypes.STRING,
|
|
19
|
+
allowNull: false,
|
|
20
|
+
unique: true,
|
|
21
|
+
comment: "Unique request identifier",
|
|
22
|
+
},
|
|
23
|
+
generatorType: {
|
|
24
|
+
type: DataTypes.STRING,
|
|
25
|
+
allowNull: false,
|
|
26
|
+
defaultValue: "banner",
|
|
27
|
+
comment: "Type of generator: banner, text, video, etc.",
|
|
28
|
+
},
|
|
29
|
+
// Request data
|
|
30
|
+
requestText: {
|
|
31
|
+
type: DataTypes.TEXT,
|
|
32
|
+
allowNull: false,
|
|
33
|
+
comment: "Original user request text",
|
|
34
|
+
},
|
|
35
|
+
hasReferenceImage: {
|
|
36
|
+
type: DataTypes.BOOLEAN,
|
|
37
|
+
allowNull: false,
|
|
38
|
+
defaultValue: false,
|
|
39
|
+
comment: "Whether reference image was provided",
|
|
40
|
+
},
|
|
41
|
+
referenceImageUrl: {
|
|
42
|
+
type: DataTypes.STRING,
|
|
43
|
+
allowNull: true,
|
|
44
|
+
comment: "URL to reference image if provided",
|
|
45
|
+
},
|
|
46
|
+
// Parsed request data
|
|
47
|
+
subject: {
|
|
48
|
+
type: DataTypes.STRING,
|
|
49
|
+
allowNull: true,
|
|
50
|
+
comment: "Extracted subject from request",
|
|
51
|
+
},
|
|
52
|
+
language: {
|
|
53
|
+
type: DataTypes.STRING,
|
|
54
|
+
allowNull: true,
|
|
55
|
+
comment: "Detected language",
|
|
56
|
+
},
|
|
57
|
+
styleDescription: {
|
|
58
|
+
type: DataTypes.TEXT,
|
|
59
|
+
allowNull: true,
|
|
60
|
+
comment: "Style description from parsing",
|
|
61
|
+
},
|
|
62
|
+
bannerText: {
|
|
63
|
+
type: DataTypes.TEXT,
|
|
64
|
+
allowNull: true,
|
|
65
|
+
comment: "Banner text to display",
|
|
66
|
+
},
|
|
67
|
+
visualElements: {
|
|
68
|
+
type: DataTypes.TEXT,
|
|
69
|
+
allowNull: true,
|
|
70
|
+
comment: "Visual elements description",
|
|
71
|
+
},
|
|
72
|
+
// Generation prompts
|
|
73
|
+
promptVersion1: {
|
|
74
|
+
type: DataTypes.TEXT,
|
|
75
|
+
allowNull: true,
|
|
76
|
+
comment: "First prompt version",
|
|
77
|
+
},
|
|
78
|
+
promptVersion2: {
|
|
79
|
+
type: DataTypes.TEXT,
|
|
80
|
+
allowNull: true,
|
|
81
|
+
comment: "Second prompt version",
|
|
82
|
+
},
|
|
83
|
+
promptVersion3: {
|
|
84
|
+
type: DataTypes.TEXT,
|
|
85
|
+
allowNull: true,
|
|
86
|
+
comment: "Third prompt version",
|
|
87
|
+
},
|
|
88
|
+
// Storage info
|
|
89
|
+
driveFolderId: {
|
|
90
|
+
type: DataTypes.STRING,
|
|
91
|
+
allowNull: true,
|
|
92
|
+
comment: "Google Drive folder ID",
|
|
93
|
+
},
|
|
94
|
+
driveFolderName: {
|
|
95
|
+
type: DataTypes.STRING,
|
|
96
|
+
allowNull: true,
|
|
97
|
+
comment: "Google Drive folder name",
|
|
98
|
+
},
|
|
99
|
+
driveFolderLink: {
|
|
100
|
+
type: DataTypes.STRING,
|
|
101
|
+
allowNull: true,
|
|
102
|
+
comment: "Google Drive folder link",
|
|
103
|
+
},
|
|
104
|
+
// Generation results
|
|
105
|
+
imagesTotal: {
|
|
106
|
+
type: DataTypes.INTEGER,
|
|
107
|
+
allowNull: false,
|
|
108
|
+
defaultValue: 0,
|
|
109
|
+
comment: "Total number of images generated",
|
|
110
|
+
},
|
|
111
|
+
imagesSuccessful: {
|
|
112
|
+
type: DataTypes.INTEGER,
|
|
113
|
+
allowNull: false,
|
|
114
|
+
defaultValue: 0,
|
|
115
|
+
comment: "Number of successfully generated images",
|
|
116
|
+
},
|
|
117
|
+
imagesFailed: {
|
|
118
|
+
type: DataTypes.INTEGER,
|
|
119
|
+
allowNull: false,
|
|
120
|
+
defaultValue: 0,
|
|
121
|
+
comment: "Number of failed image generations",
|
|
122
|
+
},
|
|
123
|
+
// Status
|
|
124
|
+
status: {
|
|
125
|
+
type: DataTypes.ENUM(
|
|
126
|
+
"pending",
|
|
127
|
+
"processing",
|
|
128
|
+
"completed",
|
|
129
|
+
"failed",
|
|
130
|
+
"partial"
|
|
131
|
+
),
|
|
132
|
+
allowNull: false,
|
|
133
|
+
defaultValue: "pending",
|
|
134
|
+
comment: "Request status",
|
|
135
|
+
},
|
|
136
|
+
errorMessage: {
|
|
137
|
+
type: DataTypes.TEXT,
|
|
138
|
+
allowNull: true,
|
|
139
|
+
comment: "Error message if generation failed",
|
|
140
|
+
},
|
|
141
|
+
// Metadata
|
|
142
|
+
user: {
|
|
143
|
+
type: DataTypes.STRING,
|
|
144
|
+
allowNull: true,
|
|
145
|
+
comment: "User who made the request",
|
|
146
|
+
},
|
|
147
|
+
duration: {
|
|
148
|
+
type: DataTypes.INTEGER,
|
|
149
|
+
allowNull: true,
|
|
150
|
+
comment: "Generation duration in milliseconds",
|
|
151
|
+
},
|
|
152
|
+
// Model info
|
|
153
|
+
parsingModel: {
|
|
154
|
+
type: DataTypes.STRING,
|
|
155
|
+
allowNull: true,
|
|
156
|
+
comment: "Model used for parsing",
|
|
157
|
+
},
|
|
158
|
+
promptModel: {
|
|
159
|
+
type: DataTypes.STRING,
|
|
160
|
+
allowNull: true,
|
|
161
|
+
comment: "Model used for prompt generation",
|
|
162
|
+
},
|
|
163
|
+
imageModel: {
|
|
164
|
+
type: DataTypes.STRING,
|
|
165
|
+
allowNull: true,
|
|
166
|
+
comment: "Model used for image generation",
|
|
167
|
+
},
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
tableName: "ai_generation_requests",
|
|
171
|
+
timestamps: true,
|
|
172
|
+
createdAt: "createdAt",
|
|
173
|
+
updatedAt: "updatedAt",
|
|
174
|
+
indexes: [
|
|
175
|
+
{
|
|
176
|
+
fields: ["requestId"],
|
|
177
|
+
unique: true,
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
fields: ["generatorType"],
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
fields: ["status"],
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
fields: ["createdAt"],
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
fields: ["user"],
|
|
190
|
+
},
|
|
191
|
+
],
|
|
192
|
+
}
|
|
193
|
+
);
|
|
194
|
+
|
|
195
|
+
// Associations
|
|
196
|
+
AIGenerationRequest.associate = function (models) {
|
|
197
|
+
// One request has many logs
|
|
198
|
+
AIGenerationRequest.hasMany(models.AIGenerationLog, {
|
|
199
|
+
foreignKey: "requestId",
|
|
200
|
+
sourceKey: "requestId",
|
|
201
|
+
as: "logs",
|
|
202
|
+
});
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
return AIGenerationRequest;
|
|
206
|
+
};
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
// models/GenericFlowRequest.js
|
|
2
|
+
module.exports = (sequelize, DataTypes) => {
|
|
3
|
+
const GenericFlowRequest = sequelize.define(
|
|
4
|
+
"GenericFlowRequest",
|
|
5
|
+
{
|
|
6
|
+
id: {
|
|
7
|
+
type: DataTypes.BIGINT,
|
|
8
|
+
autoIncrement: true,
|
|
9
|
+
primaryKey: true,
|
|
10
|
+
},
|
|
11
|
+
request_id: {
|
|
12
|
+
type: DataTypes.UUID,
|
|
13
|
+
allowNull: false,
|
|
14
|
+
unique: true,
|
|
15
|
+
field: "request_id",
|
|
16
|
+
},
|
|
17
|
+
flow_type: {
|
|
18
|
+
type: DataTypes.ENUM("article", "texts", "keywords", "creative"),
|
|
19
|
+
allowNull: false,
|
|
20
|
+
field: "flow_type",
|
|
21
|
+
},
|
|
22
|
+
status: {
|
|
23
|
+
type: DataTypes.ENUM("pending", "processing", "completed", "failed", "retrying"),
|
|
24
|
+
defaultValue: "pending",
|
|
25
|
+
allowNull: false,
|
|
26
|
+
},
|
|
27
|
+
retry_count: {
|
|
28
|
+
type: DataTypes.INTEGER,
|
|
29
|
+
defaultValue: 0,
|
|
30
|
+
field: "retry_count",
|
|
31
|
+
},
|
|
32
|
+
max_retries: {
|
|
33
|
+
type: DataTypes.INTEGER,
|
|
34
|
+
defaultValue: 3,
|
|
35
|
+
field: "max_retries",
|
|
36
|
+
},
|
|
37
|
+
input_params: {
|
|
38
|
+
type: DataTypes.JSONB,
|
|
39
|
+
allowNull: true,
|
|
40
|
+
field: "input_params",
|
|
41
|
+
},
|
|
42
|
+
output_result: {
|
|
43
|
+
type: DataTypes.JSONB,
|
|
44
|
+
allowNull: true,
|
|
45
|
+
field: "output_result",
|
|
46
|
+
},
|
|
47
|
+
error_message: {
|
|
48
|
+
type: DataTypes.TEXT,
|
|
49
|
+
allowNull: true,
|
|
50
|
+
field: "error_message",
|
|
51
|
+
},
|
|
52
|
+
error_stack: {
|
|
53
|
+
type: DataTypes.TEXT,
|
|
54
|
+
allowNull: true,
|
|
55
|
+
field: "error_stack",
|
|
56
|
+
},
|
|
57
|
+
AGRS_CID: {
|
|
58
|
+
type: DataTypes.UUID,
|
|
59
|
+
allowNull: true,
|
|
60
|
+
field: "AGRS_CID",
|
|
61
|
+
},
|
|
62
|
+
process_id: {
|
|
63
|
+
type: DataTypes.UUID,
|
|
64
|
+
allowNull: true,
|
|
65
|
+
field: "process_id",
|
|
66
|
+
},
|
|
67
|
+
parent_request_id: {
|
|
68
|
+
type: DataTypes.UUID,
|
|
69
|
+
allowNull: true,
|
|
70
|
+
field: "parent_request_id",
|
|
71
|
+
},
|
|
72
|
+
related_request_ids: {
|
|
73
|
+
type: DataTypes.JSONB,
|
|
74
|
+
allowNull: true,
|
|
75
|
+
field: "related_request_ids",
|
|
76
|
+
},
|
|
77
|
+
metadata: {
|
|
78
|
+
type: DataTypes.JSONB,
|
|
79
|
+
allowNull: true,
|
|
80
|
+
},
|
|
81
|
+
processing_time_ms: {
|
|
82
|
+
type: DataTypes.INTEGER,
|
|
83
|
+
allowNull: true,
|
|
84
|
+
field: "processing_time_ms",
|
|
85
|
+
},
|
|
86
|
+
started_at: {
|
|
87
|
+
type: DataTypes.DATE,
|
|
88
|
+
allowNull: true,
|
|
89
|
+
field: "started_at",
|
|
90
|
+
},
|
|
91
|
+
completed_at: {
|
|
92
|
+
type: DataTypes.DATE,
|
|
93
|
+
allowNull: true,
|
|
94
|
+
field: "completed_at",
|
|
95
|
+
},
|
|
96
|
+
failed_at: {
|
|
97
|
+
type: DataTypes.DATE,
|
|
98
|
+
allowNull: true,
|
|
99
|
+
field: "failed_at",
|
|
100
|
+
},
|
|
101
|
+
last_retry_at: {
|
|
102
|
+
type: DataTypes.DATE,
|
|
103
|
+
allowNull: true,
|
|
104
|
+
field: "last_retry_at",
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
tableName: "generic_flow_requests",
|
|
109
|
+
timestamps: true, // Adds createdAt and updatedAt
|
|
110
|
+
underscored: false, // We're using explicit field mappings
|
|
111
|
+
}
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
return GenericFlowRequest;
|
|
115
|
+
};
|