@memberjunction/server 2.51.0 → 2.53.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.
@@ -72,7 +72,7 @@ export class FileResolver extends FileResolverBase {
72
72
 
73
73
  // Save the file record with the updated input
74
74
  const mapper = new FieldMapper();
75
- fileEntity.LoadFromData(mapper.ReverseMapFields({ ...input }));
75
+ await fileEntity.LoadFromData(mapper.ReverseMapFields({ ...input }));
76
76
  fileEntity.SetMany(mapper.ReverseMapFields({ ...updatedInput }));
77
77
  await fileEntity.Save();
78
78
  const File = mapper.MapFields({ ...fileEntity.GetAll() });
@@ -1,81 +1,134 @@
1
- // Queries are MemberJunction primitive operations that are used to retrieve data from the server from any stored query
2
- import { RunQuery } from '@memberjunction/core';
3
- import { Arg, Ctx, Field, Int, ObjectType, Query, Resolver } from 'type-graphql';
4
- import { AppContext } from '../types.js';
5
-
6
- @ObjectType()
7
- export class RunQueryResultType {
8
- @Field()
9
- QueryID: string;
10
-
11
- @Field()
12
- QueryName: string;
13
-
14
- @Field()
15
- Success: boolean;
16
-
17
- @Field()
18
- Results: string;
19
-
20
- @Field()
21
- RowCount: number;
22
-
23
- @Field()
24
- ExecutionTime: number;
25
-
26
- @Field()
27
- ErrorMessage: string;
28
- }
29
-
30
- @Resolver(RunQueryResultType)
31
- export class ReportResolver {
32
- @Query(() => RunQueryResultType)
33
- async GetQueryData(@Arg('QueryID', () => String) QueryID: string,
34
- @Ctx() context: AppContext,
35
- @Arg('CategoryID', () => String, {nullable: true}) CategoryID?: string,
36
- @Arg('CategoryName', () => String, {nullable: true}) CategoryName?: string): Promise<RunQueryResultType> {
37
- const runQuery = new RunQuery();
38
- const result = await runQuery.RunQuery(
39
- {
40
- QueryID: QueryID,
41
- CategoryID: CategoryID,
42
- CategoryName: CategoryName
43
- },
44
- context.userPayload.userRecord);
45
-
46
- return {
47
- QueryID: QueryID,
48
- QueryName: result.QueryName,
49
- Success: result.Success,
50
- Results: JSON.stringify(result.Results),
51
- RowCount: result.RowCount,
52
- ExecutionTime: result.ExecutionTime,
53
- ErrorMessage: result.ErrorMessage,
54
- };
55
- }
56
-
57
- @Query(() => RunQueryResultType)
58
- async GetQueryDataByName(@Arg('QueryName', () => String) QueryName: string,
59
- @Ctx() context: AppContext,
60
- @Arg('CategoryID', () => String, {nullable: true}) CategoryID?: string,
61
- @Arg('CategoryName', () => String, {nullable: true}) CategoryName?: string): Promise<RunQueryResultType> {
62
- const runQuery = new RunQuery();
63
- const result = await runQuery.RunQuery(
64
- {
65
- QueryName: QueryName,
66
- CategoryID: CategoryID,
67
- CategoryName: CategoryName
68
- },
69
- context.userPayload.userRecord);
70
-
71
- return {
72
- QueryID: result.QueryID,
73
- QueryName: QueryName,
74
- Success: result.Success,
75
- Results: JSON.stringify(result.Results),
76
- RowCount: result.RowCount,
77
- ExecutionTime: result.ExecutionTime,
78
- ErrorMessage: result.ErrorMessage,
79
- };
80
- }
81
- }
1
+ // Queries are MemberJunction primitive operations that are used to retrieve data from the server from any stored query
2
+ import { RunQuery } from '@memberjunction/core';
3
+ import { Arg, Ctx, Field, Int, ObjectType, Query, Resolver } from 'type-graphql';
4
+ import { AppContext } from '../types.js';
5
+ import { RequireSystemUser } from '../directives/RequireSystemUser.js';
6
+
7
+ @ObjectType()
8
+ export class RunQueryResultType {
9
+ @Field()
10
+ QueryID: string;
11
+
12
+ @Field()
13
+ QueryName: string;
14
+
15
+ @Field()
16
+ Success: boolean;
17
+
18
+ @Field()
19
+ Results: string;
20
+
21
+ @Field()
22
+ RowCount: number;
23
+
24
+ @Field()
25
+ ExecutionTime: number;
26
+
27
+ @Field()
28
+ ErrorMessage: string;
29
+ }
30
+
31
+ @Resolver(RunQueryResultType)
32
+ export class ReportResolver {
33
+ @Query(() => RunQueryResultType)
34
+ async GetQueryData(@Arg('QueryID', () => String) QueryID: string,
35
+ @Ctx() context: AppContext,
36
+ @Arg('CategoryID', () => String, {nullable: true}) CategoryID?: string,
37
+ @Arg('CategoryName', () => String, {nullable: true}) CategoryName?: string): Promise<RunQueryResultType> {
38
+ const runQuery = new RunQuery();
39
+ const result = await runQuery.RunQuery(
40
+ {
41
+ QueryID: QueryID,
42
+ CategoryID: CategoryID,
43
+ CategoryName: CategoryName
44
+ },
45
+ context.userPayload.userRecord);
46
+
47
+ return {
48
+ QueryID: QueryID,
49
+ QueryName: result.QueryName,
50
+ Success: result.Success,
51
+ Results: JSON.stringify(result.Results),
52
+ RowCount: result.RowCount,
53
+ ExecutionTime: result.ExecutionTime,
54
+ ErrorMessage: result.ErrorMessage,
55
+ };
56
+ }
57
+
58
+ @Query(() => RunQueryResultType)
59
+ async GetQueryDataByName(@Arg('QueryName', () => String) QueryName: string,
60
+ @Ctx() context: AppContext,
61
+ @Arg('CategoryID', () => String, {nullable: true}) CategoryID?: string,
62
+ @Arg('CategoryName', () => String, {nullable: true}) CategoryName?: string): Promise<RunQueryResultType> {
63
+ const runQuery = new RunQuery();
64
+ const result = await runQuery.RunQuery(
65
+ {
66
+ QueryName: QueryName,
67
+ CategoryID: CategoryID,
68
+ CategoryName: CategoryName
69
+ },
70
+ context.userPayload.userRecord);
71
+
72
+ return {
73
+ QueryID: result.QueryID,
74
+ QueryName: QueryName,
75
+ Success: result.Success,
76
+ Results: JSON.stringify(result.Results),
77
+ RowCount: result.RowCount,
78
+ ExecutionTime: result.ExecutionTime,
79
+ ErrorMessage: result.ErrorMessage,
80
+ };
81
+ }
82
+
83
+ @RequireSystemUser()
84
+ @Query(() => RunQueryResultType)
85
+ async GetQueryDataSystemUser(@Arg('QueryID', () => String) QueryID: string,
86
+ @Ctx() context: AppContext,
87
+ @Arg('CategoryID', () => String, {nullable: true}) CategoryID?: string,
88
+ @Arg('CategoryName', () => String, {nullable: true}) CategoryName?: string): Promise<RunQueryResultType> {
89
+ const runQuery = new RunQuery();
90
+ const result = await runQuery.RunQuery(
91
+ {
92
+ QueryID: QueryID,
93
+ CategoryID: CategoryID,
94
+ CategoryName: CategoryName
95
+ },
96
+ context.userPayload.userRecord);
97
+
98
+ return {
99
+ QueryID: QueryID,
100
+ QueryName: result.QueryName,
101
+ Success: result.Success,
102
+ Results: JSON.stringify(result.Results),
103
+ RowCount: result.RowCount,
104
+ ExecutionTime: result.ExecutionTime,
105
+ ErrorMessage: result.ErrorMessage,
106
+ };
107
+ }
108
+
109
+ @RequireSystemUser()
110
+ @Query(() => RunQueryResultType)
111
+ async GetQueryDataByNameSystemUser(@Arg('QueryName', () => String) QueryName: string,
112
+ @Ctx() context: AppContext,
113
+ @Arg('CategoryID', () => String, {nullable: true}) CategoryID?: string,
114
+ @Arg('CategoryName', () => String, {nullable: true}) CategoryName?: string): Promise<RunQueryResultType> {
115
+ const runQuery = new RunQuery();
116
+ const result = await runQuery.RunQuery(
117
+ {
118
+ QueryName: QueryName,
119
+ CategoryID: CategoryID,
120
+ CategoryName: CategoryName
121
+ },
122
+ context.userPayload.userRecord);
123
+
124
+ return {
125
+ QueryID: result.QueryID,
126
+ QueryName: QueryName,
127
+ Success: result.Success,
128
+ Results: JSON.stringify(result.Results),
129
+ RowCount: result.RowCount,
130
+ ExecutionTime: result.ExecutionTime,
131
+ ErrorMessage: result.ErrorMessage,
132
+ };
133
+ }
134
+ }
@@ -1,4 +1,4 @@
1
- import { Resolver, Mutation, Arg, Ctx, ObjectType, Field } from 'type-graphql';
1
+ import { Resolver, Mutation, Arg, Ctx, ObjectType, Field, Int } from 'type-graphql';
2
2
  import { UserPayload } from '../types.js';
3
3
  import { LogError, LogStatus, Metadata } from '@memberjunction/core';
4
4
  import { AIPromptEntity } from '@memberjunction/core-entities';
@@ -46,7 +46,19 @@ export class RunAIPromptResolver extends ResolverBase {
46
46
  @Arg('vendorId', { nullable: true }) vendorId?: string,
47
47
  @Arg('configurationId', { nullable: true }) configurationId?: string,
48
48
  @Arg('skipValidation', { nullable: true }) skipValidation?: boolean,
49
- @Arg('templateData', { nullable: true }) templateData?: string
49
+ @Arg('templateData', { nullable: true }) templateData?: string,
50
+ @Arg('responseFormat', { nullable: true }) responseFormat?: string,
51
+ @Arg('temperature', { nullable: true }) temperature?: number,
52
+ @Arg('topP', { nullable: true }) topP?: number,
53
+ @Arg('topK', () => Int, { nullable: true }) topK?: number,
54
+ @Arg('minP', { nullable: true }) minP?: number,
55
+ @Arg('frequencyPenalty', { nullable: true }) frequencyPenalty?: number,
56
+ @Arg('presencePenalty', { nullable: true }) presencePenalty?: number,
57
+ @Arg('seed', () => Int, { nullable: true }) seed?: number,
58
+ @Arg('stopSequences', () => [String], { nullable: true }) stopSequences?: string[],
59
+ @Arg('includeLogProbs', { nullable: true }) includeLogProbs?: boolean,
60
+ @Arg('topLogProbs', () => Int, { nullable: true }) topLogProbs?: number,
61
+ @Arg('messages', { nullable: true }) messages?: string
50
62
  ): Promise<AIPromptRunResult> {
51
63
  const startTime = Date.now();
52
64
 
@@ -127,6 +139,44 @@ export class RunAIPromptResolver extends ResolverBase {
127
139
  promptParams.configurationId = configurationId;
128
140
  promptParams.contextUser = currentUser;
129
141
  promptParams.skipValidation = skipValidation || false;
142
+
143
+ // Parse and set conversation messages if provided
144
+ if (messages) {
145
+ try {
146
+ promptParams.conversationMessages = JSON.parse(messages);
147
+ } catch (parseError) {
148
+ // If parsing fails, treat as a simple user message
149
+ promptParams.conversationMessages = [{
150
+ role: 'user',
151
+ content: messages
152
+ }];
153
+ }
154
+ }
155
+
156
+ // If responseFormat is provided, override the prompt's default response format
157
+ if (responseFormat) {
158
+ // We'll need to override the prompt's response format setting
159
+ // This will be handled in the AIPromptRunner when it builds the ChatParams
160
+ promptEntity.ResponseFormat = responseFormat as any;
161
+ }
162
+
163
+ // Build additional parameters for chat-specific settings
164
+ const additionalParams: Record<string, any> = {};
165
+ if (temperature != null) additionalParams.temperature = temperature;
166
+ if (topP != null) additionalParams.topP = topP;
167
+ if (topK != null) additionalParams.topK = topK;
168
+ if (minP != null) additionalParams.minP = minP;
169
+ if (frequencyPenalty != null) additionalParams.frequencyPenalty = frequencyPenalty;
170
+ if (presencePenalty != null) additionalParams.presencePenalty = presencePenalty;
171
+ if (seed != null) additionalParams.seed = seed;
172
+ if (stopSequences != null) additionalParams.stopSequences = stopSequences;
173
+ if (includeLogProbs != null) additionalParams.includeLogProbs = includeLogProbs;
174
+ if (topLogProbs != null) additionalParams.topLogProbs = topLogProbs;
175
+
176
+ // Only set additionalParameters if we have any
177
+ if (Object.keys(additionalParams).length > 0) {
178
+ promptParams.additionalParameters = additionalParams;
179
+ }
130
180
 
131
181
  // Execute the prompt
132
182
  const result = await promptRunner.ExecutePrompt(promptParams);