@memberjunction/codegen-lib 2.29.2 → 2.30.0
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/Config/config.d.ts +75 -0
- package/dist/Config/config.d.ts.map +1 -1
- package/dist/Config/config.js +6 -0
- package/dist/Config/config.js.map +1 -1
- package/dist/Database/manage-metadata.d.ts +37 -14
- package/dist/Database/manage-metadata.d.ts.map +1 -1
- package/dist/Database/manage-metadata.js +162 -77
- package/dist/Database/manage-metadata.js.map +1 -1
- package/dist/Database/sql_codegen.d.ts +2 -2
- package/dist/Database/sql_codegen.d.ts.map +1 -1
- package/dist/Database/sql_codegen.js +2 -2
- package/dist/Database/sql_codegen.js.map +1 -1
- package/dist/Misc/advanced_generation.d.ts.map +1 -1
- package/dist/Misc/advanced_generation.js +33 -9
- package/dist/Misc/advanced_generation.js.map +1 -1
- package/dist/Misc/entity_subclasses_codegen.d.ts +13 -5
- package/dist/Misc/entity_subclasses_codegen.d.ts.map +1 -1
- package/dist/Misc/entity_subclasses_codegen.js +58 -32
- package/dist/Misc/entity_subclasses_codegen.js.map +1 -1
- package/dist/runCodeGen.d.ts.map +1 -1
- package/dist/runCodeGen.js +17 -8
- package/dist/runCodeGen.js.map +1 -1
- package/package.json +12 -11
|
@@ -33,7 +33,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
33
33
|
};
|
|
34
34
|
var ManageMetadataBase_1;
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.ManageMetadataBase = exports.
|
|
36
|
+
exports.ManageMetadataBase = exports.ValidatorResult = void 0;
|
|
37
37
|
const config_1 = require("../Config/config");
|
|
38
38
|
const core_1 = require("@memberjunction/core");
|
|
39
39
|
const status_logging_1 = require("../Misc/status_logging");
|
|
@@ -44,19 +44,27 @@ const uuid_1 = require("uuid");
|
|
|
44
44
|
const fs = __importStar(require("fs"));
|
|
45
45
|
const path_1 = __importDefault(require("path"));
|
|
46
46
|
const sql_logging_1 = require("../Misc/sql_logging");
|
|
47
|
-
|
|
47
|
+
const aiengine_1 = require("@memberjunction/aiengine");
|
|
48
|
+
class ValidatorResult {
|
|
48
49
|
constructor() {
|
|
49
50
|
this.entityName = "";
|
|
50
|
-
this.fieldName = "";
|
|
51
51
|
this.sourceCheckConstraint = "";
|
|
52
52
|
this.functionText = "";
|
|
53
53
|
this.functionName = "";
|
|
54
54
|
this.functionDescription = "";
|
|
55
|
+
/**
|
|
56
|
+
* The ID value in the Generated Codes entity that was created for this validator.
|
|
57
|
+
*/
|
|
58
|
+
this.generatedCodeId = "";
|
|
59
|
+
/**
|
|
60
|
+
* The ID for the AI Model that was used to generate the code
|
|
61
|
+
*/
|
|
62
|
+
this.aiModelID = "";
|
|
55
63
|
this.wasGenerated = true;
|
|
56
64
|
this.success = false;
|
|
57
65
|
}
|
|
58
66
|
}
|
|
59
|
-
exports.
|
|
67
|
+
exports.ValidatorResult = ValidatorResult;
|
|
60
68
|
/**
|
|
61
69
|
* Base class for managing metadata within the CodeGen system. This class can be sub-classed to extend/override base class functionality. Make sure to use the RegisterClass decorator from the @memberjunction/global package
|
|
62
70
|
* to properly register your subclass with a priority of 1+ to ensure it gets instantiated.
|
|
@@ -81,17 +89,17 @@ let ManageMetadataBase = ManageMetadataBase_1 = class ManageMetadataBase {
|
|
|
81
89
|
return this._modifiedEntityList;
|
|
82
90
|
}
|
|
83
91
|
/**
|
|
84
|
-
* Globally scoped list of
|
|
92
|
+
* Globally scoped list of validators that have been generated during the metadata management process.
|
|
85
93
|
*/
|
|
86
|
-
static get
|
|
87
|
-
return this.
|
|
94
|
+
static get generatedValidators() {
|
|
95
|
+
return this._generatedValidators;
|
|
88
96
|
}
|
|
89
97
|
/**
|
|
90
98
|
* Primary function to manage metadata within the CodeGen system. This function will call a series of sub-functions to manage the metadata.
|
|
91
99
|
* @param ds - the DataSource object to use for querying and updating the database
|
|
92
100
|
* @returns
|
|
93
101
|
*/
|
|
94
|
-
async manageMetadata(ds) {
|
|
102
|
+
async manageMetadata(ds, currentUser) {
|
|
95
103
|
const md = new core_1.Metadata();
|
|
96
104
|
const excludeSchemas = config_1.configInfo.excludeSchemas ? config_1.configInfo.excludeSchemas : [];
|
|
97
105
|
let bSuccess = true;
|
|
@@ -131,7 +139,7 @@ let ManageMetadataBase = ManageMetadataBase_1 = class ManageMetadataBase {
|
|
|
131
139
|
(0, status_logging_1.logStatus)(` > Recompiled base views in ${(new Date().getTime() - start.getTime()) / 1000} seconds`);
|
|
132
140
|
start = new Date();
|
|
133
141
|
(0, status_logging_1.logStatus)(' Managing entity fields...');
|
|
134
|
-
if (!await this.manageEntityFields(ds, excludeSchemas, false, false)) {
|
|
142
|
+
if (!await this.manageEntityFields(ds, excludeSchemas, false, false, currentUser)) {
|
|
135
143
|
(0, status_logging_1.logError)(' Error managing entity fields');
|
|
136
144
|
bSuccess = false;
|
|
137
145
|
}
|
|
@@ -472,7 +480,7 @@ let ManageMetadataBase = ManageMetadataBase_1 = class ManageMetadataBase {
|
|
|
472
480
|
* @param excludeSchemas
|
|
473
481
|
* @returns
|
|
474
482
|
*/
|
|
475
|
-
async manageEntityFields(ds, excludeSchemas, skipCreatedAtUpdatedAtDeletedAtFieldValidation, skipEntityFieldValues) {
|
|
483
|
+
async manageEntityFields(ds, excludeSchemas, skipCreatedAtUpdatedAtDeletedAtFieldValidation, skipEntityFieldValues, currentUser) {
|
|
476
484
|
let bSuccess = true;
|
|
477
485
|
const startTime = new Date();
|
|
478
486
|
if (!skipCreatedAtUpdatedAtDeletedAtFieldValidation) {
|
|
@@ -516,7 +524,7 @@ let ManageMetadataBase = ManageMetadataBase_1 = class ManageMetadataBase {
|
|
|
516
524
|
if (!skipEntityFieldValues) {
|
|
517
525
|
const step6StartTime = new Date();
|
|
518
526
|
(0, status_logging_1.logStatus)(` Starting to manage entity field values...`);
|
|
519
|
-
if (!await this.
|
|
527
|
+
if (!await this.manageEntityFieldValuesAndValidatorFunctions(ds, excludeSchemas, currentUser, false)) {
|
|
520
528
|
(0, status_logging_1.logError)('Error managing entity field values');
|
|
521
529
|
bSuccess = false;
|
|
522
530
|
}
|
|
@@ -1158,7 +1166,7 @@ let ManageMetadataBase = ManageMetadataBase_1 = class ManageMetadataBase {
|
|
|
1158
1166
|
return false;
|
|
1159
1167
|
}
|
|
1160
1168
|
}
|
|
1161
|
-
async
|
|
1169
|
+
async manageEntityFieldValuesAndValidatorFunctions(ds, excludeSchemas, currentUser, skipDBUpdate) {
|
|
1162
1170
|
try {
|
|
1163
1171
|
// here we want to get all of the entity fields that have check constraints attached to them. For each field that has a check constraint, we want to
|
|
1164
1172
|
// evaluate it to see if it is a simple series of OR statements or not, if it is a simple series of OR statements, we can parse the possible values
|
|
@@ -1169,36 +1177,57 @@ let ManageMetadataBase = ManageMetadataBase_1 = class ManageMetadataBase {
|
|
|
1169
1177
|
const result = await ds.query(sSQL);
|
|
1170
1178
|
const efvSQL = `SELECT * FROM [${(0, config_1.mj_core_schema)()}].EntityFieldValue`;
|
|
1171
1179
|
const allEntityFieldValues = await ds.query(efvSQL);
|
|
1180
|
+
const efSQL = `SELECT * FROM [${(0, config_1.mj_core_schema)()}].vwEntityFields ORDER BY EntityID, Sequence`;
|
|
1181
|
+
const allEntityFields = await ds.query(efSQL);
|
|
1172
1182
|
const generationPromises = [];
|
|
1173
|
-
|
|
1174
|
-
|
|
1183
|
+
const columnLevelResults = result.filter((r) => r.EntityFieldID); // get the column level constraints
|
|
1184
|
+
const tableLevelResults = result.filter((r) => !r.EntityFieldID); // get the table level constraints
|
|
1185
|
+
for (const r of columnLevelResults) {
|
|
1186
|
+
// now, for each of the constraints we get back here, loop through and evaluate if they're simple and if they're simple, parse and sync with entity field values for that field
|
|
1175
1187
|
if (r.ConstraintDefinition && r.ConstraintDefinition.length > 0) {
|
|
1176
1188
|
const parsedValues = this.parseCheckConstraintValues(r.ConstraintDefinition, r.ColumnName, r.EntityName);
|
|
1177
1189
|
if (parsedValues) {
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
const
|
|
1188
|
-
|
|
1190
|
+
if (!skipDBUpdate) {
|
|
1191
|
+
// we only do this part if we are not skiping the database update as this code will sync values from the CHECK
|
|
1192
|
+
// with the EntityFieldValues in the database.
|
|
1193
|
+
// 1st, flip the order of parsedValues because they come out in reverse order from SQL Server
|
|
1194
|
+
parsedValues.reverse();
|
|
1195
|
+
// we have parsed values from the check constraint, so sync them with the entity field values
|
|
1196
|
+
await this.syncEntityFieldValues(ds, r.EntityFieldID, parsedValues, allEntityFieldValues);
|
|
1197
|
+
// finally, make sure the ValueListType column within the EntityField table is set to "List" because for check constraints we only allow the values specified in the list.
|
|
1198
|
+
// check to see if the ValueListType is already set to "List", if not, update it
|
|
1199
|
+
const sSQLCheck = `SELECT ValueListType FROM [${(0, config_1.mj_core_schema)()}].EntityField WHERE ID='${r.EntityFieldID}'`;
|
|
1200
|
+
const checkResult = await ds.query(sSQLCheck);
|
|
1201
|
+
if (checkResult && checkResult.length > 0 && checkResult[0].ValueListType.trim().toLowerCase() !== 'list') {
|
|
1202
|
+
const sSQL = `UPDATE [${(0, config_1.mj_core_schema)()}].EntityField SET ValueListType='List' WHERE ID='${r.EntityFieldID}'`;
|
|
1203
|
+
await this.LogSQLAndExecute(ds, sSQL, `SQL text to update ValueListType for entity field ID ${r.EntityFieldID}`);
|
|
1204
|
+
}
|
|
1205
|
+
}
|
|
1206
|
+
else {
|
|
1207
|
+
// we are skipping the DB update, nothing to do, eh?
|
|
1189
1208
|
}
|
|
1190
1209
|
}
|
|
1191
1210
|
else {
|
|
1192
1211
|
// if we get here that means we don't have a simple condition in the check constraint that the RegEx could parse. If Advanced Generation is enabled, we will
|
|
1193
1212
|
// attempt to use an LLM to do things fancier now
|
|
1194
|
-
if (config_1.configInfo.advancedGeneration?.enableAdvancedGeneration &&
|
|
1213
|
+
if (config_1.configInfo.advancedGeneration?.enableAdvancedGeneration &&
|
|
1214
|
+
config_1.configInfo.advancedGeneration?.features.find(f => f.name === 'ParseCheckConstraints' && f.enabled)) {
|
|
1195
1215
|
// the user has the feature turned on, let's generate a description of the constraint and then build a Validate function for the constraint
|
|
1196
1216
|
// run this in parallel
|
|
1197
|
-
generationPromises.push(this.runValidationGeneration(r));
|
|
1217
|
+
generationPromises.push(this.runValidationGeneration(r, allEntityFields, !skipDBUpdate, currentUser));
|
|
1198
1218
|
}
|
|
1199
1219
|
}
|
|
1200
1220
|
}
|
|
1201
1221
|
}
|
|
1222
|
+
// now for the table level constraints run the process for advanced generation
|
|
1223
|
+
for (const r of tableLevelResults) {
|
|
1224
|
+
if (config_1.configInfo.advancedGeneration?.enableAdvancedGeneration &&
|
|
1225
|
+
config_1.configInfo.advancedGeneration?.features.find(f => f.name === 'ParseCheckConstraints' && f.enabled)) {
|
|
1226
|
+
// the user has the feature turned on, let's generate a description of the constraint and then build a Validate function for the constraint
|
|
1227
|
+
// run this in parallel
|
|
1228
|
+
generationPromises.push(this.runValidationGeneration(r, allEntityFields, !skipDBUpdate, currentUser));
|
|
1229
|
+
}
|
|
1230
|
+
}
|
|
1202
1231
|
// await the completion of all generation promises here
|
|
1203
1232
|
await Promise.all(generationPromises);
|
|
1204
1233
|
return true;
|
|
@@ -1208,21 +1237,37 @@ let ManageMetadataBase = ManageMetadataBase_1 = class ManageMetadataBase {
|
|
|
1208
1237
|
return false;
|
|
1209
1238
|
}
|
|
1210
1239
|
}
|
|
1211
|
-
|
|
1212
|
-
|
|
1240
|
+
/**
|
|
1241
|
+
* This method will load all generated code from the database - this is intended to be used when you are bypassing managing the metadata.
|
|
1242
|
+
* @param ds
|
|
1243
|
+
* @param currentUser
|
|
1244
|
+
*/
|
|
1245
|
+
async loadGeneratedCode(ds, currentUser) {
|
|
1246
|
+
try {
|
|
1247
|
+
// right now we're just doing validator functions which are handled here
|
|
1248
|
+
return await this.manageEntityFieldValuesAndValidatorFunctions(ds, [], currentUser, true);
|
|
1249
|
+
}
|
|
1250
|
+
catch (e) {
|
|
1251
|
+
(0, status_logging_1.logError)(e);
|
|
1252
|
+
return false;
|
|
1253
|
+
}
|
|
1254
|
+
}
|
|
1255
|
+
async runValidationGeneration(r, allEntityFields, generateNewCode, currentUser) {
|
|
1256
|
+
const generatedFunction = await this.generateValidatorFunctionFromCheckConstraint(r, allEntityFields, currentUser, generateNewCode);
|
|
1213
1257
|
if (generatedFunction?.success) {
|
|
1214
1258
|
// LLM was able to generate a function for us, so let's store it in the static array, will be used later when we emit the BaseEntity sub-class
|
|
1215
|
-
ManageMetadataBase_1.
|
|
1259
|
+
ManageMetadataBase_1._generatedValidators.push(generatedFunction);
|
|
1216
1260
|
}
|
|
1217
1261
|
}
|
|
1218
1262
|
/**
|
|
1219
1263
|
* Generates a TypeScript field validator function from the text of a SQL CHECK constraint.
|
|
1220
|
-
* @param
|
|
1221
|
-
* @param
|
|
1222
|
-
* @param
|
|
1264
|
+
* @param data - the data object containing the entity name, column name, and constraint definition
|
|
1265
|
+
* @param allEntityFields - all of the entity fields in the system
|
|
1266
|
+
* @param currentUser - the current user
|
|
1267
|
+
* @param generateNewCode - a flag indicating whether or not to generate new code, this is set to false when we are just loading the generated code from the database.
|
|
1223
1268
|
* @returns a data structure with the function text, function name, function description, and a success flag
|
|
1224
1269
|
*/
|
|
1225
|
-
async
|
|
1270
|
+
async generateValidatorFunctionFromCheckConstraint(data, allEntityFields, currentUser, generateNewCode) {
|
|
1226
1271
|
const entityName = data.EntityName;
|
|
1227
1272
|
const fieldName = data.ColumnName;
|
|
1228
1273
|
const constraintDefinition = data.ConstraintDefinition;
|
|
@@ -1230,10 +1275,11 @@ let ManageMetadataBase = ManageMetadataBase_1 = class ManageMetadataBase {
|
|
|
1230
1275
|
const generatedValidationFunctionDescription = data.GeneratedValidationFunctionDescription;
|
|
1231
1276
|
const generatedValidationFunctionCode = data.GeneratedValidationFunctionCode;
|
|
1232
1277
|
const generatedValidationFunctionCheckConstraint = data.GeneratedValidationFunctionCheckConstraint;
|
|
1233
|
-
const returnResult = new
|
|
1278
|
+
const returnResult = new ValidatorResult();
|
|
1234
1279
|
returnResult.success = false;
|
|
1235
1280
|
returnResult.entityName = entityName;
|
|
1236
1281
|
returnResult.fieldName = fieldName;
|
|
1282
|
+
returnResult.generatedCodeId = data.GeneratedCodeID; // this came from the database, so we'll store it here for reference so we update the record later instead of creating a new one
|
|
1237
1283
|
returnResult.sourceCheckConstraint = constraintDefinition;
|
|
1238
1284
|
if (generatedValidationFunctionCheckConstraint === constraintDefinition) {
|
|
1239
1285
|
// in this situation, we have an EXACT match of the previous version of a CHECK constraint and what is now the CHECK constraint - meaning it hasn't changed
|
|
@@ -1248,21 +1294,32 @@ let ManageMetadataBase = ManageMetadataBase_1 = class ManageMetadataBase {
|
|
|
1248
1294
|
}
|
|
1249
1295
|
}
|
|
1250
1296
|
try {
|
|
1251
|
-
if (config_1.configInfo.advancedGeneration?.enableAdvancedGeneration && config_1.configInfo.advancedGeneration?.features.find(f => f.name === 'ParseCheckConstraints' && f.enabled)) {
|
|
1297
|
+
if (generateNewCode && config_1.configInfo.advancedGeneration?.enableAdvancedGeneration && config_1.configInfo.advancedGeneration?.features.find(f => f.name === 'ParseCheckConstraints' && f.enabled)) {
|
|
1252
1298
|
// feature is enabled, so let's call the LLM to generate a function for us
|
|
1253
1299
|
const ag = new advanced_generation_1.AdvancedGeneration();
|
|
1254
1300
|
const llm = ag.LLM;
|
|
1255
1301
|
if (!llm) {
|
|
1256
1302
|
// we weren't able to get an LLM instance, so log an error and return
|
|
1257
|
-
(0, status_logging_1.logError)(' >>> Error generating
|
|
1303
|
+
(0, status_logging_1.logError)(' >>> Error generating validator function from check constraint. Unable to get an LLM instance.');
|
|
1258
1304
|
return returnResult;
|
|
1259
1305
|
}
|
|
1306
|
+
await aiengine_1.AIEngine.Instance.Config(false, currentUser); // make sure metadata loaded
|
|
1307
|
+
const model = aiengine_1.AIEngine.Instance.Models.find(m => m.APINameOrName.trim().toLowerCase() === ag.AIModel.trim().toLowerCase() &&
|
|
1308
|
+
m.Vendor?.trim().toLowerCase() === ag.AIVendor.trim().toLowerCase());
|
|
1309
|
+
if (!model)
|
|
1310
|
+
throw new Error(` >>> Error generating validator function from check constraint. Unable to find AI Model with name ${ag.AIModel} and vendor ${ag.AIVendor}.`);
|
|
1260
1311
|
const prompt = ag.getPrompt('CheckConstraintParser');
|
|
1312
|
+
const entityFieldListInfo = allEntityFields.filter(item => item.Entity.trim().toLowerCase() === data.EntityName.trim().toLowerCase()).map(item => ` * ${item.Name} - ${item.Type}`).join('\n');
|
|
1313
|
+
const existingMethodNameBlock = generatedValidationFunctionName ? `Existing Method Name: ${generatedValidationFunctionName}\n Please reuse this SAME method name for the new generation` : '';
|
|
1314
|
+
const markedUpSysPrompt = ag.fillTemplate(prompt.systemPrompt, {
|
|
1315
|
+
ENTITY_FIELD_LIST: entityFieldListInfo,
|
|
1316
|
+
EXISTING_METHOD_NAME: existingMethodNameBlock
|
|
1317
|
+
}); // prompt.systemPrompt.replace(/{{ENTITY_FIELD_LIST}}/g, entityFieldListInfo);
|
|
1261
1318
|
const result = await llm.ChatCompletion({
|
|
1262
1319
|
messages: [
|
|
1263
1320
|
{
|
|
1264
1321
|
role: 'system',
|
|
1265
|
-
content:
|
|
1322
|
+
content: markedUpSysPrompt
|
|
1266
1323
|
},
|
|
1267
1324
|
{
|
|
1268
1325
|
role: 'user',
|
|
@@ -1279,6 +1336,7 @@ let ManageMetadataBase = ManageMetadataBase_1 = class ManageMetadataBase {
|
|
|
1279
1336
|
returnResult.functionText = structuredResult.Code;
|
|
1280
1337
|
returnResult.functionName = structuredResult.MethodName;
|
|
1281
1338
|
returnResult.functionDescription = structuredResult.Description;
|
|
1339
|
+
returnResult.aiModelID = model.ID;
|
|
1282
1340
|
returnResult.wasGenerated = true; // we just generated this code
|
|
1283
1341
|
returnResult.success = true;
|
|
1284
1342
|
}
|
|
@@ -1450,53 +1508,80 @@ let ManageMetadataBase = ManageMetadataBase_1 = class ManageMetadataBase {
|
|
|
1450
1508
|
async createNewEntityName(newEntity) {
|
|
1451
1509
|
const ag = new advanced_generation_1.AdvancedGeneration();
|
|
1452
1510
|
if (ag.featureEnabled('EntityNames')) {
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
if (structuredResult?.entityName) {
|
|
1476
|
-
return structuredResult.entityName;
|
|
1477
|
-
}
|
|
1478
|
-
else {
|
|
1479
|
-
console.warn(' >>> Advanced Generation Error: LLM returned a blank entity name, falling back to simple generated entity name');
|
|
1480
|
-
return this.simpleNewEntityName(newEntity.TableName);
|
|
1481
|
-
}
|
|
1511
|
+
return this.newEntityNameWithAdvancedGeneration(ag, newEntity);
|
|
1512
|
+
}
|
|
1513
|
+
else {
|
|
1514
|
+
return this.simpleNewEntityName(newEntity.SchemaName, newEntity.TableName);
|
|
1515
|
+
}
|
|
1516
|
+
}
|
|
1517
|
+
async newEntityNameWithAdvancedGeneration(ag, newEntity) {
|
|
1518
|
+
// get the LLM for this entity
|
|
1519
|
+
const chat = ag.LLM;
|
|
1520
|
+
const prompt = ag.getPrompt('EntityNames');
|
|
1521
|
+
const systemPrompt = ag.fillTemplate(prompt.systemPrompt, newEntity);
|
|
1522
|
+
const userMessage = ag.fillTemplate(prompt.userMessage, newEntity);
|
|
1523
|
+
const result = await chat.ChatCompletion({
|
|
1524
|
+
model: ag.AIModel,
|
|
1525
|
+
messages: [
|
|
1526
|
+
{
|
|
1527
|
+
role: 'system',
|
|
1528
|
+
content: systemPrompt
|
|
1529
|
+
},
|
|
1530
|
+
{
|
|
1531
|
+
role: 'user',
|
|
1532
|
+
content: userMessage
|
|
1482
1533
|
}
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1534
|
+
]
|
|
1535
|
+
});
|
|
1536
|
+
if (result?.success) {
|
|
1537
|
+
const resultText = result?.data.choices[0].message.content;
|
|
1538
|
+
try {
|
|
1539
|
+
const structuredResult = JSON.parse(resultText);
|
|
1540
|
+
if (structuredResult?.entityName) {
|
|
1541
|
+
return this.markupEntityName(newEntity.SchemaName, structuredResult.entityName);
|
|
1542
|
+
}
|
|
1543
|
+
else {
|
|
1544
|
+
console.warn(' >>> Advanced Generation Error: LLM returned a blank entity name, falling back to simple generated entity name');
|
|
1545
|
+
return this.simpleNewEntityName(newEntity.SchemaName, newEntity.TableName);
|
|
1486
1546
|
}
|
|
1487
1547
|
}
|
|
1488
|
-
|
|
1489
|
-
console.warn(' >>> Advanced Generation Error: LLM
|
|
1490
|
-
return this.simpleNewEntityName(newEntity.TableName);
|
|
1548
|
+
catch (e) {
|
|
1549
|
+
console.warn(' >>> Advanced Generation Error: LLM returned invalid result, falling back to simple generated entity name. Result from LLM: ' + resultText, e);
|
|
1550
|
+
return this.simpleNewEntityName(newEntity.SchemaName, newEntity.TableName);
|
|
1491
1551
|
}
|
|
1492
1552
|
}
|
|
1493
1553
|
else {
|
|
1494
|
-
|
|
1554
|
+
console.warn(' >>> Advanced Generation Error: LLM call failed, falling back to simple generated entity name.');
|
|
1555
|
+
return this.simpleNewEntityName(newEntity.SchemaName, newEntity.TableName);
|
|
1495
1556
|
}
|
|
1496
1557
|
}
|
|
1497
|
-
simpleNewEntityName(tableName) {
|
|
1558
|
+
simpleNewEntityName(schemaName, tableName) {
|
|
1498
1559
|
const convertedTableName = (0, global_1.convertCamelCaseToHaveSpaces)(tableName);
|
|
1499
|
-
|
|
1560
|
+
const pluralName = (0, global_1.generatePluralName)(convertedTableName, { capitalizeFirstLetterOnly: true });
|
|
1561
|
+
return this.markupEntityName(schemaName, pluralName);
|
|
1562
|
+
}
|
|
1563
|
+
/**
|
|
1564
|
+
* Uses the optional NameRulesBySchema section of the newEntityDefaults section of the config object to auto prefix/suffix a given entity name
|
|
1565
|
+
* @param schemaName
|
|
1566
|
+
* @param entityName
|
|
1567
|
+
*/
|
|
1568
|
+
markupEntityName(schemaName, entityName) {
|
|
1569
|
+
const rule = config_1.configInfo.newEntityDefaults?.NameRulesBySchema?.find(r => {
|
|
1570
|
+
let schemaNameToUse = r.SchemaName;
|
|
1571
|
+
if (schemaNameToUse?.trim().toLowerCase() === '${mj_core_schema}') {
|
|
1572
|
+
// markup for this is to be replaced with the mj_core_schema() config
|
|
1573
|
+
schemaNameToUse = (0, config_1.mj_core_schema)();
|
|
1574
|
+
}
|
|
1575
|
+
return schemaNameToUse.trim().toLowerCase() === schemaName.trim().toLowerCase();
|
|
1576
|
+
});
|
|
1577
|
+
if (rule) {
|
|
1578
|
+
// found a matching rule, apply it
|
|
1579
|
+
return rule.EntityNamePrefix + entityName + rule.EntityNameSuffix;
|
|
1580
|
+
}
|
|
1581
|
+
else {
|
|
1582
|
+
// no matching rule, just return the entity name as is
|
|
1583
|
+
return entityName;
|
|
1584
|
+
}
|
|
1500
1585
|
}
|
|
1501
1586
|
createNewUUID() {
|
|
1502
1587
|
return (0, uuid_1.v4)();
|
|
@@ -1669,7 +1754,7 @@ let ManageMetadataBase = ManageMetadataBase_1 = class ManageMetadataBase {
|
|
|
1669
1754
|
exports.ManageMetadataBase = ManageMetadataBase;
|
|
1670
1755
|
ManageMetadataBase._newEntityList = [];
|
|
1671
1756
|
ManageMetadataBase._modifiedEntityList = [];
|
|
1672
|
-
ManageMetadataBase.
|
|
1757
|
+
ManageMetadataBase._generatedValidators = [];
|
|
1673
1758
|
exports.ManageMetadataBase = ManageMetadataBase = ManageMetadataBase_1 = __decorate([
|
|
1674
1759
|
(0, global_1.RegisterClass)(ManageMetadataBase)
|
|
1675
1760
|
], ManageMetadataBase);
|