@memberjunction/graphql-dataprovider 2.91.0 → 2.93.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/index.d.mts CHANGED
@@ -5,6 +5,479 @@ import { UserViewEntityExtended } from '@memberjunction/core-entities';
5
5
  import { Observable } from 'rxjs';
6
6
  import { ActionParam, ActionResult, EntityActionInvocationParams, EntityActionResult } from '@memberjunction/actions-base';
7
7
 
8
+ /**
9
+ * Client for executing AI operations through GraphQL.
10
+ * This class provides an easy way to execute AI prompts and agents from a client application.
11
+ *
12
+ * The GraphQLAIClient follows the same naming convention as other GraphQL clients
13
+ * in the MemberJunction ecosystem, such as GraphQLActionClient and GraphQLSystemUserClient.
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * // Create the client
18
+ * const aiClient = new GraphQLAIClient(graphQLProvider);
19
+ *
20
+ * // Run an AI prompt
21
+ * const promptResult = await aiClient.RunAIPrompt({
22
+ * promptId: "prompt-id",
23
+ * data: { context: "user data" },
24
+ * temperature: 0.7
25
+ * });
26
+ *
27
+ * // Run an AI agent
28
+ * const agentResult = await aiClient.RunAIAgent({
29
+ * agentId: "agent-id",
30
+ * messages: [{ role: "user", content: "Hello" }],
31
+ * sessionId: "session-123"
32
+ * });
33
+ * ```
34
+ */
35
+ declare class GraphQLAIClient {
36
+ /**
37
+ * The GraphQLDataProvider instance used to execute GraphQL requests
38
+ * @private
39
+ */
40
+ private _dataProvider;
41
+ /**
42
+ * Creates a new GraphQLAIClient instance.
43
+ * @param dataProvider The GraphQL data provider to use for queries
44
+ */
45
+ constructor(dataProvider: GraphQLDataProvider);
46
+ /**
47
+ * Run an AI prompt with the specified parameters.
48
+ *
49
+ * This method invokes an AI prompt on the server through GraphQL and returns the result.
50
+ * Parameters are automatically serialized as needed, and results are parsed for consumption.
51
+ *
52
+ * @param params The parameters for running the AI prompt
53
+ * @returns A Promise that resolves to a RunAIPromptResult object
54
+ *
55
+ * @example
56
+ * ```typescript
57
+ * const result = await aiClient.RunAIPrompt({
58
+ * promptId: "prompt-id",
59
+ * data: { key: "value" },
60
+ * temperature: 0.7,
61
+ * topP: 0.9
62
+ * });
63
+ *
64
+ * if (result.success) {
65
+ * console.log('Output:', result.output);
66
+ * console.log('Parsed Result:', result.parsedResult);
67
+ * } else {
68
+ * console.error('Error:', result.error);
69
+ * }
70
+ * ```
71
+ */
72
+ RunAIPrompt(params: RunAIPromptParams): Promise<RunAIPromptResult>;
73
+ /**
74
+ * Prepares variables for the AI prompt mutation
75
+ * @param params The prompt parameters
76
+ * @returns The prepared variables for GraphQL
77
+ * @private
78
+ */
79
+ private preparePromptVariables;
80
+ /**
81
+ * Processes the result from the AI prompt mutation
82
+ * @param result The raw GraphQL result
83
+ * @returns The processed RunAIPromptResult
84
+ * @private
85
+ */
86
+ private processPromptResult;
87
+ /**
88
+ * Handles errors in the AI prompt execution
89
+ * @param e The error
90
+ * @returns An error result
91
+ * @private
92
+ */
93
+ private handlePromptError;
94
+ /**
95
+ * Run an AI agent with the specified parameters.
96
+ *
97
+ * This method invokes an AI agent on the server through GraphQL and returns the result.
98
+ * The agent can maintain conversation context across multiple interactions.
99
+ *
100
+ * @param params The parameters for running the AI agent
101
+ * @returns A Promise that resolves to a RunAIAgentResult object
102
+ *
103
+ * @example
104
+ * ```typescript
105
+ * const result = await aiClient.RunAIAgent({
106
+ * agentId: "agent-id",
107
+ * messages: [
108
+ * { role: "user", content: "What's the weather like?" }
109
+ * ],
110
+ * sessionId: "session-123",
111
+ * data: { location: "New York" }
112
+ * });
113
+ *
114
+ * if (result.success) {
115
+ * console.log('Response:', result.payload);
116
+ * console.log('Execution time:', result.executionTimeMs, 'ms');
117
+ * } else {
118
+ * console.error('Error:', result.errorMessage);
119
+ * }
120
+ * ```
121
+ */
122
+ RunAIAgent(params: RunAIAgentParams): Promise<RunAIAgentResult>;
123
+ /**
124
+ * Prepares variables for the AI agent mutation
125
+ * @param params The agent parameters
126
+ * @returns The prepared variables for GraphQL
127
+ * @private
128
+ */
129
+ private prepareAgentVariables;
130
+ /**
131
+ * Processes the result from the AI agent mutation
132
+ * @param result The raw GraphQL result
133
+ * @returns The processed RunAIAgentResult
134
+ * @private
135
+ */
136
+ private processAgentResult;
137
+ /**
138
+ * Handles errors in the AI agent execution
139
+ * @param e The error
140
+ * @returns An error result
141
+ * @private
142
+ */
143
+ private handleAgentError;
144
+ /**
145
+ * Execute a simple prompt without requiring a stored AI Prompt entity.
146
+ * This method is designed for interactive components that need quick AI responses.
147
+ *
148
+ * @param params The parameters for the simple prompt execution
149
+ * @returns A Promise that resolves to a SimplePromptResult object
150
+ *
151
+ * @example
152
+ * ```typescript
153
+ * const result = await aiClient.ExecuteSimplePrompt({
154
+ * systemPrompt: "You are a helpful assistant",
155
+ * messages: [
156
+ * { message: "What's the weather?", role: "user" }
157
+ * ],
158
+ * modelPower: "medium"
159
+ * });
160
+ *
161
+ * if (result.success) {
162
+ * console.log('Response:', result.result);
163
+ * if (result.resultObject) {
164
+ * console.log('Parsed JSON:', JSON.parse(result.resultObject));
165
+ * }
166
+ * }
167
+ * ```
168
+ */
169
+ ExecuteSimplePrompt(params: ExecuteSimplePromptParams): Promise<SimplePromptResult>;
170
+ /**
171
+ * Generate embeddings for text using local embedding models.
172
+ * This method is designed for interactive components that need fast similarity calculations.
173
+ *
174
+ * @param params The parameters for embedding generation
175
+ * @returns A Promise that resolves to an EmbedTextResult object
176
+ *
177
+ * @example
178
+ * ```typescript
179
+ * const result = await aiClient.EmbedText({
180
+ * textToEmbed: ["Hello world", "How are you?"],
181
+ * modelSize: "small"
182
+ * });
183
+ *
184
+ * console.log('Embeddings:', result.embeddings);
185
+ * console.log('Model used:', result.modelName);
186
+ * console.log('Dimensions:', result.vectorDimensions);
187
+ * ```
188
+ */
189
+ EmbedText(params: EmbedTextParams): Promise<EmbedTextResult>;
190
+ }
191
+ /**
192
+ * Parameters for executing a simple prompt
193
+ */
194
+ interface ExecuteSimplePromptParams {
195
+ /**
196
+ * The system prompt to set context for the model
197
+ */
198
+ systemPrompt: string;
199
+ /**
200
+ * Optional message history
201
+ */
202
+ messages?: Array<{
203
+ message: string;
204
+ role: 'user' | 'assistant';
205
+ }>;
206
+ /**
207
+ * Preferred model names to use
208
+ */
209
+ preferredModels?: string[];
210
+ /**
211
+ * Power level for model selection
212
+ */
213
+ modelPower?: 'lowest' | 'medium' | 'highest';
214
+ /**
215
+ * Response format (e.g., "json")
216
+ */
217
+ responseFormat?: string;
218
+ }
219
+ /**
220
+ * Result from executing a simple prompt
221
+ */
222
+ interface SimplePromptResult {
223
+ /**
224
+ * Whether the execution was successful
225
+ */
226
+ success: boolean;
227
+ /**
228
+ * The text response from the model
229
+ */
230
+ result?: string;
231
+ /**
232
+ * Parsed JSON object if the response contained JSON
233
+ */
234
+ resultObject?: any;
235
+ /**
236
+ * Name of the model used
237
+ */
238
+ modelName: string;
239
+ /**
240
+ * Error message if execution failed
241
+ */
242
+ error?: string;
243
+ /**
244
+ * Execution time in milliseconds
245
+ */
246
+ executionTimeMs?: number;
247
+ }
248
+ /**
249
+ * Parameters for generating text embeddings
250
+ */
251
+ interface EmbedTextParams {
252
+ /**
253
+ * Text or array of texts to embed
254
+ */
255
+ textToEmbed: string | string[];
256
+ /**
257
+ * Size of the embedding model to use
258
+ */
259
+ modelSize: 'small' | 'medium';
260
+ }
261
+ /**
262
+ * Result from generating text embeddings
263
+ */
264
+ interface EmbedTextResult {
265
+ /**
266
+ * Single embedding vector or array of vectors
267
+ */
268
+ embeddings: number[] | number[][];
269
+ /**
270
+ * Name of the model used
271
+ */
272
+ modelName: string;
273
+ /**
274
+ * Number of dimensions in each vector
275
+ */
276
+ vectorDimensions: number;
277
+ /**
278
+ * Error message if generation failed
279
+ */
280
+ error?: string;
281
+ }
282
+ /**
283
+ * Parameters for running an AI prompt
284
+ */
285
+ interface RunAIPromptParams {
286
+ /**
287
+ * The ID of the AI prompt to run
288
+ */
289
+ promptId: string;
290
+ /**
291
+ * Data context to pass to the prompt (will be JSON serialized)
292
+ */
293
+ data?: Record<string, any>;
294
+ /**
295
+ * Override the default model ID
296
+ */
297
+ overrideModelId?: string;
298
+ /**
299
+ * Override the default vendor ID
300
+ */
301
+ overrideVendorId?: string;
302
+ /**
303
+ * Configuration ID to use
304
+ */
305
+ configurationId?: string;
306
+ /**
307
+ * Skip validation of the prompt
308
+ */
309
+ skipValidation?: boolean;
310
+ /**
311
+ * Template data for prompt templating (will be JSON serialized)
312
+ */
313
+ templateData?: Record<string, any>;
314
+ /**
315
+ * Response format (e.g., "json", "text")
316
+ */
317
+ responseFormat?: string;
318
+ /**
319
+ * Temperature parameter for the model (0.0 to 1.0)
320
+ */
321
+ temperature?: number;
322
+ /**
323
+ * Top-p sampling parameter
324
+ */
325
+ topP?: number;
326
+ /**
327
+ * Top-k sampling parameter
328
+ */
329
+ topK?: number;
330
+ /**
331
+ * Min-p sampling parameter
332
+ */
333
+ minP?: number;
334
+ /**
335
+ * Frequency penalty parameter
336
+ */
337
+ frequencyPenalty?: number;
338
+ /**
339
+ * Presence penalty parameter
340
+ */
341
+ presencePenalty?: number;
342
+ /**
343
+ * Random seed for reproducible outputs
344
+ */
345
+ seed?: number;
346
+ /**
347
+ * Stop sequences for the model
348
+ */
349
+ stopSequences?: string[];
350
+ /**
351
+ * Include log probabilities in the response
352
+ */
353
+ includeLogProbs?: boolean;
354
+ /**
355
+ * Number of top log probabilities to include
356
+ */
357
+ topLogProbs?: number;
358
+ /**
359
+ * Conversation messages (will be JSON serialized)
360
+ */
361
+ messages?: Array<{
362
+ role: string;
363
+ content: string;
364
+ }>;
365
+ /**
366
+ * ID of a previous prompt run to rerun from
367
+ */
368
+ rerunFromPromptRunID?: string;
369
+ /**
370
+ * Override the system prompt
371
+ */
372
+ systemPromptOverride?: string;
373
+ }
374
+ /**
375
+ * Result from running an AI prompt
376
+ */
377
+ interface RunAIPromptResult {
378
+ /**
379
+ * Whether the prompt execution was successful
380
+ */
381
+ success: boolean;
382
+ /**
383
+ * The output from the prompt
384
+ */
385
+ output?: string;
386
+ /**
387
+ * Parsed result data (if applicable)
388
+ */
389
+ parsedResult?: any;
390
+ /**
391
+ * Error message if the execution failed
392
+ */
393
+ error?: string;
394
+ /**
395
+ * Execution time in milliseconds
396
+ */
397
+ executionTimeMs?: number;
398
+ /**
399
+ * Number of tokens used
400
+ */
401
+ tokensUsed?: number;
402
+ /**
403
+ * ID of the prompt run record
404
+ */
405
+ promptRunId?: string;
406
+ /**
407
+ * Raw result from the model
408
+ */
409
+ rawResult?: string;
410
+ /**
411
+ * Validation result data
412
+ */
413
+ validationResult?: any;
414
+ /**
415
+ * Chat completion result data
416
+ */
417
+ chatResult?: any;
418
+ }
419
+ /**
420
+ * Parameters for running an AI agent
421
+ */
422
+ interface RunAIAgentParams {
423
+ /**
424
+ * The ID of the AI agent to run
425
+ */
426
+ agentId: string;
427
+ /**
428
+ * Conversation messages
429
+ */
430
+ messages: Array<{
431
+ role: string;
432
+ content: string;
433
+ }>;
434
+ /**
435
+ * Session ID for maintaining conversation context
436
+ */
437
+ sessionId: string;
438
+ /**
439
+ * Data context to pass to the agent (will be JSON serialized)
440
+ */
441
+ data?: Record<string, any>;
442
+ /**
443
+ * Template data for agent templating (will be JSON serialized)
444
+ */
445
+ templateData?: Record<string, any>;
446
+ /**
447
+ * ID of the last agent run for context continuity
448
+ */
449
+ lastRunId?: string;
450
+ /**
451
+ * Auto-populate the last run payload
452
+ */
453
+ autoPopulateLastRunPayload?: boolean;
454
+ /**
455
+ * Configuration ID to use
456
+ */
457
+ configurationId?: string;
458
+ }
459
+ /**
460
+ * Result from running an AI agent
461
+ */
462
+ interface RunAIAgentResult {
463
+ /**
464
+ * Whether the agent execution was successful
465
+ */
466
+ success: boolean;
467
+ /**
468
+ * Error message if the execution failed
469
+ */
470
+ errorMessage?: string;
471
+ /**
472
+ * Execution time in milliseconds
473
+ */
474
+ executionTimeMs?: number;
475
+ /**
476
+ * The agent's response payload (parsed from JSON)
477
+ */
478
+ payload?: any;
479
+ }
480
+
8
481
  /**************************************************************************************************************
9
482
  * The graphQLDataProvider provides a data provider for the entities framework that uses GraphQL to communicate
10
483
  * with the server.
@@ -67,7 +540,14 @@ declare class GraphQLDataProvider extends ProviderBase implements IEntityDataPro
67
540
  private _client;
68
541
  private _configData;
69
542
  private _sessionId;
543
+ private _aiClient;
70
544
  get ConfigData(): GraphQLProviderConfigData;
545
+ /**
546
+ * Gets the AI client for executing AI operations through GraphQL.
547
+ * The client is lazily initialized on first access.
548
+ * @returns The GraphQLAIClient instance
549
+ */
550
+ get AI(): GraphQLAIClient;
71
551
  /**
72
552
  * This getter is not implemented for the GraphQLDataProvider class.
73
553
  */
@@ -498,6 +978,92 @@ declare class GraphQLSystemUserClient {
498
978
  * @returns Promise containing the result of the query deletion
499
979
  */
500
980
  DeleteQuery(ID: string, options?: DeleteQueryOptionsInput): Promise<DeleteQueryResult>;
981
+ /**
982
+ * Run an AI prompt with system user privileges.
983
+ * This method allows system-level execution of AI prompts without user authentication.
984
+ *
985
+ * @param params The parameters for running the AI prompt
986
+ * @returns A Promise that resolves to a RunAIPromptResult object
987
+ *
988
+ * @example
989
+ * ```typescript
990
+ * const result = await systemClient.RunAIPrompt({
991
+ * promptId: "prompt-id",
992
+ * data: { systemData: "value" },
993
+ * skipValidation: true
994
+ * });
995
+ * ```
996
+ */
997
+ RunAIPrompt(params: RunAIPromptParams): Promise<RunAIPromptResult>;
998
+ /**
999
+ * Run an AI agent with system user privileges.
1000
+ * This method allows system-level execution of AI agents without user authentication.
1001
+ *
1002
+ * @param params The parameters for running the AI agent
1003
+ * @returns A Promise that resolves to a RunAIAgentResult object
1004
+ *
1005
+ * @example
1006
+ * ```typescript
1007
+ * const result = await systemClient.RunAIAgent({
1008
+ * agentId: "agent-id",
1009
+ * messages: [{ role: "system", content: "Process data" }],
1010
+ * sessionId: "system-session"
1011
+ * });
1012
+ * ```
1013
+ */
1014
+ RunAIAgent(params: RunAIAgentParams): Promise<RunAIAgentResult>;
1015
+ /**
1016
+ * Helper method to prepare prompt variables for GraphQL
1017
+ * @private
1018
+ */
1019
+ private preparePromptVariables;
1020
+ /**
1021
+ * Helper method to prepare agent variables for GraphQL
1022
+ * @private
1023
+ */
1024
+ private prepareAgentVariables;
1025
+ /**
1026
+ * Helper method to process prompt results
1027
+ * @private
1028
+ */
1029
+ private processPromptResult;
1030
+ /**
1031
+ * Helper method to process agent results
1032
+ * @private
1033
+ */
1034
+ private processAgentResult;
1035
+ /**
1036
+ * Execute a simple prompt without requiring a stored AI Prompt entity.
1037
+ * This method allows system-level execution of simple prompts.
1038
+ *
1039
+ * @param params The parameters for the simple prompt execution
1040
+ * @returns A Promise that resolves to a SimplePromptResult object
1041
+ *
1042
+ * @example
1043
+ * ```typescript
1044
+ * const result = await systemClient.ExecuteSimplePrompt({
1045
+ * systemPrompt: "You are a data analyst",
1046
+ * modelPower: "medium"
1047
+ * });
1048
+ * ```
1049
+ */
1050
+ ExecuteSimplePrompt(params: ExecuteSimplePromptParams): Promise<SimplePromptResult>;
1051
+ /**
1052
+ * Generate embeddings using local embedding models.
1053
+ * This method allows system-level generation of text embeddings.
1054
+ *
1055
+ * @param params The parameters for embedding generation
1056
+ * @returns A Promise that resolves to an EmbedTextResult object
1057
+ *
1058
+ * @example
1059
+ * ```typescript
1060
+ * const result = await systemClient.EmbedText({
1061
+ * textToEmbed: ["System data", "Configuration"],
1062
+ * modelSize: "small"
1063
+ * });
1064
+ * ```
1065
+ */
1066
+ EmbedText(params: EmbedTextParams): Promise<EmbedTextResult>;
501
1067
  }
502
1068
  /**
503
1069
  * Output type for GetData calls - contains results from executing multiple SQL queries
@@ -1469,4 +2035,4 @@ declare class GraphQLActionClient {
1469
2035
  private handleEntityActionError;
1470
2036
  }
1471
2037
 
1472
- export { ActionItemInput, ActionItemOutput, type CreateQueryInput, type CreateQueryResult, type DeleteQueryOptionsInput, type DeleteQueryResult, FieldMapper, GetDataOutput, type GetQueryDataByNameSystemUserInput, type GetQueryDataSystemUserInput, GraphQLActionClient, GraphQLDataProvider, GraphQLProviderConfigData, GraphQLSystemUserClient, GraphQLTransactionGroup, type QueryEntity, type QueryField, type QueryParameter, type QueryPermission, type QueryPermissionInput, RoleInput, RolesAndUsersInput, type RunDynamicViewSystemUserInput, type RunQuerySystemUserResult, type RunViewByIDSystemUserInput, type RunViewByNameSystemUserInput, type RunViewSystemUserInput, type RunViewSystemUserResult, type RunViewSystemUserResultRow, SimpleRemoteEntity, SimpleRemoteEntityField, SimpleRemoteEntityOutput, SyncDataAction, SyncDataResult, SyncRolesAndUsersResult, type UpdateQueryInput, type UpdateQueryResult, UserInput, setupGraphQLClient };
2038
+ export { ActionItemInput, ActionItemOutput, type CreateQueryInput, type CreateQueryResult, type DeleteQueryOptionsInput, type DeleteQueryResult, type EmbedTextParams, type EmbedTextResult, type ExecuteSimplePromptParams, FieldMapper, GetDataOutput, type GetQueryDataByNameSystemUserInput, type GetQueryDataSystemUserInput, GraphQLAIClient, GraphQLActionClient, GraphQLDataProvider, GraphQLProviderConfigData, GraphQLSystemUserClient, GraphQLTransactionGroup, type QueryEntity, type QueryField, type QueryParameter, type QueryPermission, type QueryPermissionInput, RoleInput, RolesAndUsersInput, type RunAIAgentParams, type RunAIAgentResult, type RunAIPromptParams, type RunAIPromptResult, type RunDynamicViewSystemUserInput, type RunQuerySystemUserResult, type RunViewByIDSystemUserInput, type RunViewByNameSystemUserInput, type RunViewSystemUserInput, type RunViewSystemUserResult, type RunViewSystemUserResultRow, type SimplePromptResult, SimpleRemoteEntity, SimpleRemoteEntityField, SimpleRemoteEntityOutput, SyncDataAction, SyncDataResult, SyncRolesAndUsersResult, type UpdateQueryInput, type UpdateQueryResult, UserInput, setupGraphQLClient };