@memberjunction/server 1.8.1 → 2.1.1
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/CHANGELOG.json +130 -1
- package/CHANGELOG.md +29 -2
- package/package.json +31 -40
- package/src/apolloServer/index.ts +0 -1
- package/src/auth/newUsers.ts +4 -3
- package/src/context.ts +19 -27
- package/src/entitySubclasses/entityPermissions.server.ts +3 -3
- package/src/entitySubclasses/userViewEntity.server.ts +1 -1
- package/src/generated/generated.ts +9482 -8398
- package/src/generic/ResolverBase.ts +299 -172
- package/src/generic/RunViewResolver.ts +204 -14
- package/src/index.ts +18 -19
- package/src/resolvers/AskSkipResolver.ts +35 -35
- package/src/resolvers/ColorResolver.ts +3 -14
- package/src/resolvers/DatasetResolver.ts +4 -4
- package/src/resolvers/EntityCommunicationsResolver.ts +37 -15
- package/src/resolvers/FileCategoryResolver.ts +2 -2
- package/src/resolvers/FileResolver.ts +6 -4
- package/src/resolvers/MergeRecordsResolver.ts +3 -2
- package/src/resolvers/PotentialDuplicateRecordResolver.ts +48 -40
- package/src/resolvers/QueryResolver.ts +2 -2
- package/src/resolvers/ReportResolver.ts +6 -6
- package/src/resolvers/UserFavoriteResolver.ts +8 -8
- package/src/resolvers/UserResolver.ts +3 -1
- package/src/resolvers/UserViewResolver.ts +1 -1
- package/src/types.ts +21 -0
- package/tsconfig.json +3 -4
- package/dist/apolloServer/TransactionPlugin.d.ts +0 -4
- package/dist/apolloServer/TransactionPlugin.d.ts.map +0 -1
- package/dist/apolloServer/TransactionPlugin.js +0 -49
- package/dist/apolloServer/TransactionPlugin.js.map +0 -1
- package/dist/apolloServer/index.d.ts +0 -11
- package/dist/apolloServer/index.d.ts.map +0 -1
- package/dist/apolloServer/index.js +0 -27
- package/dist/apolloServer/index.js.map +0 -1
- package/dist/auth/exampleNewUserSubClass.d.ts +0 -6
- package/dist/auth/exampleNewUserSubClass.d.ts.map +0 -1
- package/dist/auth/exampleNewUserSubClass.js +0 -54
- package/dist/auth/exampleNewUserSubClass.js.map +0 -1
- package/dist/auth/index.d.ts +0 -30
- package/dist/auth/index.d.ts.map +0 -1
- package/dist/auth/index.js +0 -129
- package/dist/auth/index.js.map +0 -1
- package/dist/auth/newUsers.d.ts +0 -5
- package/dist/auth/newUsers.d.ts.map +0 -1
- package/dist/auth/newUsers.js +0 -66
- package/dist/auth/newUsers.js.map +0 -1
- package/dist/auth/tokenExpiredError.d.ts +0 -5
- package/dist/auth/tokenExpiredError.d.ts.map +0 -1
- package/dist/auth/tokenExpiredError.js +0 -16
- package/dist/auth/tokenExpiredError.js.map +0 -1
- package/dist/cache.d.ts +0 -3
- package/dist/cache.d.ts.map +0 -1
- package/dist/cache.js +0 -11
- package/dist/cache.js.map +0 -1
- package/dist/config.d.ts +0 -196
- package/dist/config.d.ts.map +0 -1
- package/dist/config.js +0 -72
- package/dist/config.js.map +0 -1
- package/dist/context.d.ts +0 -17
- package/dist/context.d.ts.map +0 -1
- package/dist/context.js +0 -114
- package/dist/context.js.map +0 -1
- package/dist/directives/Public.d.ts +0 -4
- package/dist/directives/Public.d.ts.map +0 -1
- package/dist/directives/Public.js +0 -34
- package/dist/directives/Public.js.map +0 -1
- package/dist/directives/index.d.ts +0 -2
- package/dist/directives/index.d.ts.map +0 -1
- package/dist/directives/index.js +0 -18
- package/dist/directives/index.js.map +0 -1
- package/dist/entitySubclasses/DuplicateRunEntity.server.d.ts +0 -6
- package/dist/entitySubclasses/DuplicateRunEntity.server.d.ts.map +0 -1
- package/dist/entitySubclasses/DuplicateRunEntity.server.js +0 -37
- package/dist/entitySubclasses/DuplicateRunEntity.server.js.map +0 -1
- package/dist/entitySubclasses/EntityBehavior.server.d.ts +0 -29
- package/dist/entitySubclasses/EntityBehavior.server.d.ts.map +0 -1
- package/dist/entitySubclasses/EntityBehavior.server.js +0 -213
- package/dist/entitySubclasses/EntityBehavior.server.js.map +0 -1
- package/dist/entitySubclasses/entityPermissions.server.d.ts +0 -23
- package/dist/entitySubclasses/entityPermissions.server.d.ts.map +0 -1
- package/dist/entitySubclasses/entityPermissions.server.js +0 -99
- package/dist/entitySubclasses/entityPermissions.server.js.map +0 -1
- package/dist/entitySubclasses/userViewEntity.server.d.ts +0 -13
- package/dist/entitySubclasses/userViewEntity.server.d.ts.map +0 -1
- package/dist/entitySubclasses/userViewEntity.server.js +0 -164
- package/dist/entitySubclasses/userViewEntity.server.js.map +0 -1
- package/dist/generated/generated.d.ts +0 -6482
- package/dist/generated/generated.d.ts.map +0 -1
- package/dist/generated/generated.js +0 -35073
- package/dist/generated/generated.js.map +0 -1
- package/dist/generic/DeleteOptionsInput.d.ts +0 -5
- package/dist/generic/DeleteOptionsInput.d.ts.map +0 -1
- package/dist/generic/DeleteOptionsInput.js +0 -28
- package/dist/generic/DeleteOptionsInput.js.map +0 -1
- package/dist/generic/KeyInputOutputTypes.d.ts +0 -16
- package/dist/generic/KeyInputOutputTypes.d.ts.map +0 -1
- package/dist/generic/KeyInputOutputTypes.js +0 -62
- package/dist/generic/KeyInputOutputTypes.js.map +0 -1
- package/dist/generic/KeyValuePairInput.d.ts +0 -5
- package/dist/generic/KeyValuePairInput.d.ts.map +0 -1
- package/dist/generic/KeyValuePairInput.js +0 -28
- package/dist/generic/KeyValuePairInput.js.map +0 -1
- package/dist/generic/PushStatusResolver.d.ts +0 -14
- package/dist/generic/PushStatusResolver.d.ts.map +0 -1
- package/dist/generic/PushStatusResolver.js +0 -58
- package/dist/generic/PushStatusResolver.js.map +0 -1
- package/dist/generic/ResolverBase.d.ts +0 -37
- package/dist/generic/ResolverBase.d.ts.map +0 -1
- package/dist/generic/ResolverBase.js +0 -468
- package/dist/generic/ResolverBase.js.map +0 -1
- package/dist/generic/RunViewResolver.d.ts +0 -88
- package/dist/generic/RunViewResolver.d.ts.map +0 -1
- package/dist/generic/RunViewResolver.js +0 -443
- package/dist/generic/RunViewResolver.js.map +0 -1
- package/dist/index.d.ts +0 -28
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -145
- package/dist/index.js.map +0 -1
- package/dist/orm.d.ts +0 -4
- package/dist/orm.d.ts.map +0 -1
- package/dist/orm.js +0 -34
- package/dist/orm.js.map +0 -1
- package/dist/resolvers/AskSkipResolver.d.ts +0 -54
- package/dist/resolvers/AskSkipResolver.d.ts.map +0 -1
- package/dist/resolvers/AskSkipResolver.js +0 -800
- package/dist/resolvers/AskSkipResolver.js.map +0 -1
- package/dist/resolvers/ColorResolver.d.ts +0 -22
- package/dist/resolvers/ColorResolver.d.ts.map +0 -1
- package/dist/resolvers/ColorResolver.js +0 -94
- package/dist/resolvers/ColorResolver.js.map +0 -1
- package/dist/resolvers/DatasetResolver.d.ts +0 -42
- package/dist/resolvers/DatasetResolver.d.ts.map +0 -1
- package/dist/resolvers/DatasetResolver.js +0 -168
- package/dist/resolvers/DatasetResolver.js.map +0 -1
- package/dist/resolvers/EntityCommunicationsResolver.d.ts +0 -49
- package/dist/resolvers/EntityCommunicationsResolver.d.ts.map +0 -1
- package/dist/resolvers/EntityCommunicationsResolver.js +0 -228
- package/dist/resolvers/EntityCommunicationsResolver.js.map +0 -1
- package/dist/resolvers/EntityRecordNameResolver.d.ts +0 -21
- package/dist/resolvers/EntityRecordNameResolver.d.ts.map +0 -1
- package/dist/resolvers/EntityRecordNameResolver.js +0 -113
- package/dist/resolvers/EntityRecordNameResolver.js.map +0 -1
- package/dist/resolvers/EntityResolver.d.ts +0 -6
- package/dist/resolvers/EntityResolver.d.ts.map +0 -1
- package/dist/resolvers/EntityResolver.js +0 -60
- package/dist/resolvers/EntityResolver.js.map +0 -1
- package/dist/resolvers/FileCategoryResolver.d.ts +0 -6
- package/dist/resolvers/FileCategoryResolver.d.ts.map +0 -1
- package/dist/resolvers/FileCategoryResolver.js +0 -65
- package/dist/resolvers/FileCategoryResolver.js.map +0 -1
- package/dist/resolvers/FileResolver.d.ts +0 -24
- package/dist/resolvers/FileResolver.d.ts.map +0 -1
- package/dist/resolvers/FileResolver.js +0 -162
- package/dist/resolvers/FileResolver.js.map +0 -1
- package/dist/resolvers/MergeRecordsResolver.d.ts +0 -59
- package/dist/resolvers/MergeRecordsResolver.d.ts.map +0 -1
- package/dist/resolvers/MergeRecordsResolver.js +0 -256
- package/dist/resolvers/MergeRecordsResolver.js.map +0 -1
- package/dist/resolvers/PotentialDuplicateRecordResolver.d.ts +0 -29
- package/dist/resolvers/PotentialDuplicateRecordResolver.d.ts.map +0 -1
- package/dist/resolvers/PotentialDuplicateRecordResolver.js +0 -127
- package/dist/resolvers/PotentialDuplicateRecordResolver.js.map +0 -1
- package/dist/resolvers/QueryResolver.d.ts +0 -13
- package/dist/resolvers/QueryResolver.d.ts.map +0 -1
- package/dist/resolvers/QueryResolver.js +0 -74
- package/dist/resolvers/QueryResolver.js.map +0 -1
- package/dist/resolvers/ReportResolver.d.ts +0 -20
- package/dist/resolvers/ReportResolver.d.ts.map +0 -1
- package/dist/resolvers/ReportResolver.js +0 -175
- package/dist/resolvers/ReportResolver.js.map +0 -1
- package/dist/resolvers/UserFavoriteResolver.d.ts +0 -42
- package/dist/resolvers/UserFavoriteResolver.d.ts.map +0 -1
- package/dist/resolvers/UserFavoriteResolver.js +0 -221
- package/dist/resolvers/UserFavoriteResolver.js.map +0 -1
- package/dist/resolvers/UserResolver.d.ts +0 -10
- package/dist/resolvers/UserResolver.d.ts.map +0 -1
- package/dist/resolvers/UserResolver.js +0 -72
- package/dist/resolvers/UserResolver.js.map +0 -1
- package/dist/resolvers/UserViewResolver.d.ts +0 -13
- package/dist/resolvers/UserViewResolver.d.ts.map +0 -1
- package/dist/resolvers/UserViewResolver.js +0 -102
- package/dist/resolvers/UserViewResolver.js.map +0 -1
- package/dist/types.d.ts +0 -17
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -3
- package/dist/types.js.map +0 -1
- package/dist/util.d.ts +0 -4
- package/dist/util.d.ts.map +0 -1
- package/dist/util.js +0 -89
- package/dist/util.js.map +0 -1
- package/src/entitySubclasses/EntityBehavior.server.ts +0 -241
|
@@ -1,241 +0,0 @@
|
|
|
1
|
-
import { CleanJSON, MJGlobal, RegisterClass } from "@memberjunction/global";
|
|
2
|
-
import { BaseEntity, EntityInfo, EntitySaveOptions, LogError, Metadata } from "@memberjunction/core";
|
|
3
|
-
import { AIModelEntityExtended, EntityBehaviorEntityExtended, EntityBehaviorTypeEntity } from '@memberjunction/core-entities'
|
|
4
|
-
import { BaseLLM, ChatParams, GetAIAPIKey } from "@memberjunction/ai";
|
|
5
|
-
import { AIEngine } from "@memberjunction/aiengine";
|
|
6
|
-
import { LoadOpenAILLM } from "@memberjunction/ai-openai";
|
|
7
|
-
LoadOpenAILLM(); // this is to prevent tree shaking since the openai package is not directly used and rather instantiated dynamically in the LoadOpenAILLM function. Since no static code path exists tree shaking can result in this class being optimized out
|
|
8
|
-
|
|
9
|
-
@RegisterClass(BaseEntity, 'Entity Behaviors', 3) // high priority to ensure this is used ahead of other classes including the custom client-side only sub-class that this derives from
|
|
10
|
-
export class EntityBehaviorEntity_Server extends EntityBehaviorEntityExtended {
|
|
11
|
-
/**
|
|
12
|
-
* Default implementation simply returns 'OpenAI' - override this in your subclass if you are using a different AI vendor.
|
|
13
|
-
* @returns
|
|
14
|
-
*/
|
|
15
|
-
protected get AIVendorName(): string {
|
|
16
|
-
return 'OpenAI';
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Default implementation simply grabs the first AI model that matches GetAIModelName().
|
|
21
|
-
* @returns
|
|
22
|
-
*/
|
|
23
|
-
protected async GetAIModel(): Promise<AIModelEntityExtended> {
|
|
24
|
-
await AIEngine.Instance.Config(false, this.ContextCurrentUser); // most of the time this is already loaded, but just in case it isn't we will load it here
|
|
25
|
-
const models = AIEngine.Models.filter(m => m.AIModelType.trim().toLowerCase() === 'llm' &&
|
|
26
|
-
m.Vendor.trim().toLowerCase() === this.AIVendorName.trim().toLowerCase())
|
|
27
|
-
// next, sort the models by the PowerRank field so that the highest power rank model is the first array element
|
|
28
|
-
models.sort((a, b) => b.PowerRank - a.PowerRank); // highest power rank first
|
|
29
|
-
return models[0];
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Overrides the Save method to implement checking of any changes to the Description field, or a new record condition, and in those cases, will call GenerateCode to generate the code for the new behavior.
|
|
34
|
-
* @param options
|
|
35
|
-
*/
|
|
36
|
-
public override async Save(options?: EntitySaveOptions): Promise<boolean> {
|
|
37
|
-
if (this.CodeGenerated && this.RegenerateCode) {
|
|
38
|
-
const md = new Metadata();
|
|
39
|
-
const ei = md.Entities.find(e => e.ID === this.EntityID);
|
|
40
|
-
const bt = <EntityBehaviorTypeEntity>await md.GetEntityObject("Entity Behavior Types", this.ContextCurrentUser);
|
|
41
|
-
await bt.Load(this.BehaviorTypeID)
|
|
42
|
-
|
|
43
|
-
// next up, we need to determine for this behavior type, which code generator to use
|
|
44
|
-
const codeGen = MJGlobal.Instance.ClassFactory.CreateInstance<EntityBehaviorTypeCodeGeneratorBase>(EntityBehaviorTypeCodeGeneratorBase, bt.Name);
|
|
45
|
-
if (!codeGen)
|
|
46
|
-
throw new Error(`No code generator found for behavior type ${bt.Name}`);
|
|
47
|
-
|
|
48
|
-
// next up, we generate the code
|
|
49
|
-
let result: {code: string, explanation: string};
|
|
50
|
-
if (codeGen.Type == 'Prompt') {
|
|
51
|
-
const btPrompt = await codeGen.GenerateSysPrompt(ei, bt);
|
|
52
|
-
result = await this.GenerateCode(this.Description, btPrompt, bt, ei)
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
// in this scenario, the code generator wants to do all the code gen itself so just let it
|
|
56
|
-
result = await codeGen.GenerateCode(this.Description, bt, ei);
|
|
57
|
-
}
|
|
58
|
-
if (result) {
|
|
59
|
-
this.Code = result.code;
|
|
60
|
-
this.CodeExplanation = result.explanation;
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
63
|
-
this.Code = null;
|
|
64
|
-
this.CodeExplanation = 'No code generated';
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
this.RegenerateCode = false; // reset the flag
|
|
68
|
-
}
|
|
69
|
-
return super.Save(options);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* This method will use AI to generate code that matches the desired behavior.
|
|
74
|
-
* @param prompt
|
|
75
|
-
*/
|
|
76
|
-
public async GenerateCode(behaviorDescription: string, behaviorTypePrompt: string, behaviorType: EntityBehaviorTypeEntity, entityInfo: EntityInfo): Promise<{code: string, explanation: string}> {
|
|
77
|
-
try {
|
|
78
|
-
const model = await this.GetAIModel();
|
|
79
|
-
const llm = MJGlobal.Instance.ClassFactory.CreateInstance<BaseLLM>(BaseLLM, model.DriverClass, GetAIAPIKey(model.DriverClass));
|
|
80
|
-
|
|
81
|
-
const chatParams: ChatParams = {
|
|
82
|
-
model: model.APINameOrName,
|
|
83
|
-
messages: [
|
|
84
|
-
{
|
|
85
|
-
role: 'system',
|
|
86
|
-
content: this.GenerateSysPrompt(entityInfo, behaviorTypePrompt, behaviorType)
|
|
87
|
-
},
|
|
88
|
-
{
|
|
89
|
-
role: 'user',
|
|
90
|
-
content: behaviorDescription,
|
|
91
|
-
},
|
|
92
|
-
],
|
|
93
|
-
}
|
|
94
|
-
const result = await llm.ChatCompletion(chatParams);
|
|
95
|
-
if (result && result.data) {
|
|
96
|
-
const llmResponse = result.data.choices[0].message.content;
|
|
97
|
-
if (llmResponse) {
|
|
98
|
-
// try to parse it as JSON
|
|
99
|
-
try {
|
|
100
|
-
const cleansed = CleanJSON(llmResponse);
|
|
101
|
-
if (!cleansed)
|
|
102
|
-
throw new Error('Invalid JSON response from AI: ' + llmResponse);
|
|
103
|
-
|
|
104
|
-
const parsed = JSON.parse(cleansed);
|
|
105
|
-
if (parsed.code && parsed.code.length > 0) {
|
|
106
|
-
// we have the where clause. Sometimes the LLM prefixes it with WHERE and somtimes not, we need to strip WHERE if it is there
|
|
107
|
-
const trimmed = parsed.code.trim();
|
|
108
|
-
|
|
109
|
-
return {
|
|
110
|
-
code: trimmed,
|
|
111
|
-
explanation: parsed.explanation
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
else if (parsed.code !== undefined && parsed.code !== null) {
|
|
115
|
-
return {
|
|
116
|
-
code: '', // empty string is valid, it means no code generated
|
|
117
|
-
explanation: parsed.explanation
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
else {
|
|
121
|
-
// if we get here, no code was provided by the LLM, that is an error
|
|
122
|
-
throw new Error('Invalid response from AI, no code property found in response: ' + llmResponse);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
catch (e) {
|
|
126
|
-
LogError(e);
|
|
127
|
-
throw new Error('Error parsing JSON response from AI: ' + llmResponse);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
else
|
|
131
|
-
throw new Error('Null response from AI');
|
|
132
|
-
}
|
|
133
|
-
else
|
|
134
|
-
throw new Error('No result returned from AI');
|
|
135
|
-
}
|
|
136
|
-
catch (e) {
|
|
137
|
-
LogError(e);
|
|
138
|
-
throw e;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
public GenerateSysPrompt(entityInfo: EntityInfo, behaviorTypePrompt: string, behaviorType: EntityBehaviorTypeEntity): string {
|
|
143
|
-
const prompt: string = `You are an expert in TypeScript coding and business applications. You take great pride in easy to read, commented, and BEAUTIFULLY formatted code.
|
|
144
|
-
You will be provided a system administrator's request for how to handle a specific type of behavior for the ${entityInfo.Name} entity in our system.
|
|
145
|
-
|
|
146
|
-
The type of behavior is ${behaviorType.Name} and is described as follows:
|
|
147
|
-
<BEHAVIOR_SPECIFIC_INFO>
|
|
148
|
-
${behaviorTypePrompt}
|
|
149
|
-
</BEHAVIOR_SPECIFIC_INFO>
|
|
150
|
-
|
|
151
|
-
The next message, which will be a user message in the conversation, will contain the sys admin's requested behavior for this entity.
|
|
152
|
-
|
|
153
|
-
Here is the entity's schema information. When generating code that use the getter/setter methods for fields inside the object instance make sure to use the CodeName for the related entity field which sometimes
|
|
154
|
-
is different from the SQL Field Name if the SQL Field Name contains characters that are not valid in TypeScript variable names.
|
|
155
|
-
|
|
156
|
-
${entityInfo.Name} (${entityInfo.SchemaName}.${entityInfo.BaseView})
|
|
157
|
-
${
|
|
158
|
-
entityInfo.Description ? `Description: ${entityInfo.Description}` : ''
|
|
159
|
-
}
|
|
160
|
-
Fields:
|
|
161
|
-
${entityInfo.Fields.map(f => {
|
|
162
|
-
let ret: string = `${f.Name} (${f.Type}) (CodeName: ${f.CodeName})`;
|
|
163
|
-
if (f.RelatedEntity) {
|
|
164
|
-
ret += ` (fkey to ${f.RelatedEntityBaseView})`;
|
|
165
|
-
}
|
|
166
|
-
return ret;
|
|
167
|
-
}).join(',')}
|
|
168
|
-
|
|
169
|
-
<CRITICAL>
|
|
170
|
-
I am a bot and can only understand JSON. Your response must be parsable into this type:
|
|
171
|
-
const returnType = {
|
|
172
|
-
code: string, // The typescript code you will create that will work in the context described above. MAKE SURE TO PRETTY FORMAT THIS WITH SPACE INDENTS AND LINE BREAKS IN THE CODE!
|
|
173
|
-
explanation: string // an explanation for the system admin of how the code works and why it was written that way
|
|
174
|
-
};
|
|
175
|
-
</CRITICAL>
|
|
176
|
-
**** REMEMBER **** I am a BOT, do not return anything other than JSON to me or I will choke on your response!
|
|
177
|
-
`
|
|
178
|
-
return prompt;
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
/**
|
|
184
|
-
* This is a simple stub base class that will be sub-classed in order to generate actual code for various scenarios. Build sub-classes and register them with a key that matches the Name of the Entity Behavior Type it relates to.
|
|
185
|
-
*/
|
|
186
|
-
export abstract class EntityBehaviorTypeCodeGeneratorBase {
|
|
187
|
-
public abstract GenerateCode(behaviorDescription: string, behaviorType: EntityBehaviorTypeEntity, entityInfo: EntityInfo): Promise<{code: string, explanation: string}>;
|
|
188
|
-
public abstract GenerateSysPrompt(entityInfo: EntityInfo, behaviorType: EntityBehaviorTypeEntity): Promise<string>;
|
|
189
|
-
public abstract get Type(): 'Prompt' | 'Function';
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
@RegisterClass(EntityBehaviorTypeCodeGeneratorBase, 'Validation', 1)
|
|
193
|
-
export class ValidateEntityBehaviorCodeGenerator extends EntityBehaviorTypeCodeGeneratorBase {
|
|
194
|
-
public get Type(): 'Prompt' | 'Function' {
|
|
195
|
-
return 'Prompt';
|
|
196
|
-
}
|
|
197
|
-
public async GenerateCode(behaviorDescription: string, behaviorType: EntityBehaviorTypeEntity, entityInfo: EntityInfo): Promise<{code: string, explanation: string}> {
|
|
198
|
-
throw new Error('Not implemented');
|
|
199
|
-
}
|
|
200
|
-
public async GenerateSysPrompt(entityInfo: EntityInfo, behaviorType: EntityBehaviorTypeEntity): Promise<string> {
|
|
201
|
-
return `
|
|
202
|
-
Your job is to create TypeScript code that will be executed within a Validate() method in a TypeScript sub-class of BaseEntity.
|
|
203
|
-
BaseEntity is an ORM style model entity that is being sub-classed for this entity specifically and we want to incorporate the logic for
|
|
204
|
-
the Validate method requested into TypeScript code that we will insert into an override of the BaseClass Validate method. It is important that you
|
|
205
|
-
call super.Validate() at some point in your code to incorporate the base class Validation.
|
|
206
|
-
|
|
207
|
-
For example, you might define the Validate() function as follows, and in your generated code you would get rid of the comments I have below and replace with your own relevant comments.
|
|
208
|
-
|
|
209
|
-
public Validate(): ValidationResult {
|
|
210
|
-
const result = super.Validate();
|
|
211
|
-
|
|
212
|
-
// The above super.Validate() may have returned a false or true Success property. Either way, do your custom
|
|
213
|
-
// validation here to add to
|
|
214
|
-
|
|
215
|
-
// ADD YOUR CUSTOM VALIDATION LOGIC HERE and update result.Success to false if anything fails and for each
|
|
216
|
-
// failed valdiation condition add the ValidationErrorInfo to the Errors array of the result variable.
|
|
217
|
-
|
|
218
|
-
return result;
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
Validate must return a ValidationResult as defined below. Make sure your return type code complies with these strong type definitions.
|
|
222
|
-
class ValidationErrorInfo {
|
|
223
|
-
Source: string
|
|
224
|
-
Message: string
|
|
225
|
-
Value: string
|
|
226
|
-
Type: ValidationErrorType
|
|
227
|
-
}
|
|
228
|
-
const ValidationErrorType = {
|
|
229
|
-
Failure: ''Failure'',
|
|
230
|
-
Warning: ''Warning'',
|
|
231
|
-
} as const;
|
|
232
|
-
|
|
233
|
-
class ValidationResult {
|
|
234
|
-
Success: boolean
|
|
235
|
-
Errors: ValidationErrorInfo[] = []
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
<IMPORTANT>The code you must return is ONLY the Validate() function, do not return anything else inside the code property in the JSON object!</IMPORTANT>
|
|
239
|
-
`
|
|
240
|
-
}
|
|
241
|
-
}
|