@memberjunction/server 2.17.0 → 2.18.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.
@@ -38,6 +38,7 @@ import { MJGlobal, CopyScalarsAndArrays } from '@memberjunction/global';
38
38
  import { sendPostRequest } from '../util.js';
39
39
  import { GetAIAPIKey } from '@memberjunction/ai';
40
40
  import { CompositeKeyInputType } from '../generic/KeyInputOutputTypes.js';
41
+ import { AIAgentEntityExtended, AIEngine } from '@memberjunction/aiengine';
41
42
 
42
43
  enum SkipResponsePhase {
43
44
  ClarifyingQuestion = 'clarifying_question',
@@ -345,9 +346,14 @@ export class AskSkipResolver {
345
346
  );
346
347
  }
347
348
 
348
- protected BuildSkipQueries(): SkipQueryInfo[] {
349
+ /**
350
+ * Packages up the Approved queries from the metadata
351
+ * @returns
352
+ */
353
+ protected BuildSkipQueries(status: "Pending" | "In-Review" | "Approved" | "Rejected" | "Obsolete" = 'Approved'): SkipQueryInfo[] {
349
354
  const md = new Metadata();
350
- return md.Queries.map((q) => {
355
+ const approvedQueries = md.Queries.filter((q) => q.Status === status);
356
+ return approvedQueries.map((q) => {
351
357
  return {
352
358
  id: q.ID,
353
359
  name: q.Name,
@@ -390,51 +396,43 @@ export class AskSkipResolver {
390
396
  */
391
397
  protected async BuildSkipAgentNotes(contextUser: UserInfo): Promise<{notes: SkipAPIAgentNote[], noteTypes: SkipAPIAgentNoteType[]}> {
392
398
  try {
393
- const md = new Metadata();
394
- let notes: SkipAPIAgentNote[] = [];
395
- let noteTypes: SkipAPIAgentNoteType[] = [];
396
-
397
- if (md.EntityByName('AI Agent Notes')) {
398
- const rv = new RunView();
399
- const result = await rv.RunView({
400
- EntityName: "AI Agent Notes",
401
- ExtraFilter: "Agent='Skip'"
402
- }, contextUser)
403
- if (result && result.Success) {
404
- notes = result.Results.map((r) => {
405
- return {
406
- id: r.ID,
407
- typeId: r.TypeID,
408
- type: r.Type,
409
- note: r.Note,
410
- createdAt: r.__mj_CreatedAt,
411
- updatedAt: r.__mj_UpdatedAt,
412
- }
413
- });
414
- }
399
+ // if already configured this does nothing, just makes sure we're configured
400
+ await AIEngine.Instance.Config(false, contextUser);
401
+
402
+ const agent: AIAgentEntityExtended = AIEngine.Instance.GetAgentByName('Skip');
403
+ if (agent) {
404
+ let notes: SkipAPIAgentNote[] = [];
405
+ let noteTypes: SkipAPIAgentNoteType[] = [];
406
+
407
+ notes = agent.Notes.map((r) => {
408
+ return {
409
+ id: r.ID,
410
+ agentNoteTypeId: r.AgentNoteTypeID,
411
+ agentNoteType: r.AgentNoteType,
412
+ note: r.Note,
413
+ type: r.Type,
414
+ userId: r.UserID,
415
+ user: r.User,
416
+ createdAt: r.__mj_CreatedAt,
417
+ updatedAt: r.__mj_UpdatedAt,
418
+ }
419
+ });
420
+
421
+ noteTypes = AIEngine.Instance.AgentNoteTypes.map((r) => {
422
+ return {
423
+ id: r.ID,
424
+ name: r.Name,
425
+ description: r.Description
426
+ }
427
+ });
428
+
429
+ // now return the notes and note types
430
+ return {notes, noteTypes};
415
431
  }
416
432
  else {
417
- console.warn(`No AI Agent Notes entity found in the metadata, so no notes will be sent to Skip`);
433
+ console.warn(`No AI Agent found with the name 'Skip' in the AI Engine, so no notes will be sent to Skip`);
434
+ return {notes: [], noteTypes: []}; // no agent found, so nothing to do
418
435
  }
419
-
420
- if (md.EntityByName('AI Agent Note Types')) {
421
- const rv = new RunView();
422
- const result = await rv.RunView({
423
- EntityName: "AI Agent Note Types"
424
- }, contextUser);
425
- if (result && result.Success) {
426
- noteTypes = result.Results.map((r) => {
427
- return {
428
- id: r.ID,
429
- name: r.Name,
430
- description: r.Description
431
- }
432
- });
433
- }
434
- }
435
-
436
- // now return the notes and note types
437
- return {notes, noteTypes};
438
436
  }
439
437
  catch (e) {
440
438
  LogError(e);