@memberjunction/server 2.92.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.
@@ -1710,6 +1710,13 @@ each time the agent processes a prompt step.`})
1710
1710
  @Field(() => Int, {nullable: true, description: `Effort level that was actually used during this agent run execution (1-100, where 1=minimal effort, 100=maximum effort). This is the resolved effort level after applying the precedence hierarchy: runtime override > agent default > prompt defaults.`})
1711
1711
  EffortLevel?: number;
1712
1712
 
1713
+ @Field({nullable: true, description: `Optional name for the agent run to help identify and tag runs for easier reference`})
1714
+ @MaxLength(510)
1715
+ RunName?: string;
1716
+
1717
+ @Field({nullable: true, description: `Human-readable notes and comments about this agent run`})
1718
+ Comments?: string;
1719
+
1713
1720
  @Field({nullable: true})
1714
1721
  @MaxLength(510)
1715
1722
  Agent?: string;
@@ -1734,12 +1741,12 @@ each time the agent processes a prompt step.`})
1734
1741
  @MaxLength(100)
1735
1742
  OverrideVendor?: string;
1736
1743
 
1737
- @Field(() => [AIAgentRunStep_])
1738
- MJ_AIAgentRunSteps_AgentRunIDArray: AIAgentRunStep_[]; // Link to MJ_AIAgentRunSteps
1739
-
1740
1744
  @Field(() => [AIAgentRun_])
1741
1745
  MJ_AIAgentRuns_ParentRunIDArray: AIAgentRun_[]; // Link to MJ_AIAgentRuns
1742
1746
 
1747
+ @Field(() => [AIAgentRunStep_])
1748
+ MJ_AIAgentRunSteps_AgentRunIDArray: AIAgentRunStep_[]; // Link to MJ_AIAgentRunSteps
1749
+
1743
1750
  @Field(() => [AIPromptRun_])
1744
1751
  MJ_AIPromptRuns_AgentRunIDArray: AIPromptRun_[]; // Link to MJ_AIPromptRuns
1745
1752
 
@@ -1854,6 +1861,12 @@ export class CreateAIAgentRunInput {
1854
1861
 
1855
1862
  @Field(() => Int, { nullable: true })
1856
1863
  EffortLevel: number | null;
1864
+
1865
+ @Field({ nullable: true })
1866
+ RunName: string | null;
1867
+
1868
+ @Field({ nullable: true })
1869
+ Comments: string | null;
1857
1870
  }
1858
1871
 
1859
1872
 
@@ -1967,6 +1980,12 @@ export class UpdateAIAgentRunInput {
1967
1980
  @Field(() => Int, { nullable: true })
1968
1981
  EffortLevel?: number | null;
1969
1982
 
1983
+ @Field({ nullable: true })
1984
+ RunName?: string | null;
1985
+
1986
+ @Field({ nullable: true })
1987
+ Comments?: string | null;
1988
+
1970
1989
  @Field(() => [KeyValuePairInput], { nullable: true })
1971
1990
  OldValues___?: KeyValuePairInput[];
1972
1991
  }
@@ -2029,25 +2048,25 @@ export class AIAgentRunResolver extends ResolverBase {
2029
2048
  return result;
2030
2049
  }
2031
2050
 
2032
- @FieldResolver(() => [AIAgentRunStep_])
2033
- async MJ_AIAgentRunSteps_AgentRunIDArray(@Root() aiagentrun_: AIAgentRun_, @Ctx() { dataSources, userPayload, providers }: AppContext, @PubSub() pubSub: PubSubEngine) {
2034
- this.CheckUserReadPermissions('MJ: AI Agent Run Steps', userPayload);
2051
+ @FieldResolver(() => [AIAgentRun_])
2052
+ async MJ_AIAgentRuns_ParentRunIDArray(@Root() aiagentrun_: AIAgentRun_, @Ctx() { dataSources, userPayload, providers }: AppContext, @PubSub() pubSub: PubSubEngine) {
2053
+ this.CheckUserReadPermissions('MJ: AI Agent Runs', userPayload);
2035
2054
  const provider = GetReadOnlyProvider(providers, { allowFallbackToReadWrite: true });
2036
2055
  const connPool = GetReadOnlyDataSource(dataSources, { allowFallbackToReadWrite: true });
2037
- const sSQL = `SELECT * FROM [${Metadata.Provider.ConfigData.MJCoreSchemaName}].[vwAIAgentRunSteps] WHERE [AgentRunID]='${aiagentrun_.ID}' ` + this.getRowLevelSecurityWhereClause(provider, 'MJ: AI Agent Run Steps', userPayload, EntityPermissionType.Read, 'AND');
2056
+ const sSQL = `SELECT * FROM [${Metadata.Provider.ConfigData.MJCoreSchemaName}].[vwAIAgentRuns] WHERE [ParentRunID]='${aiagentrun_.ID}' ` + this.getRowLevelSecurityWhereClause(provider, 'MJ: AI Agent Runs', userPayload, EntityPermissionType.Read, 'AND');
2038
2057
  const rows = await SQLServerDataProvider.ExecuteSQLWithPool(connPool, sSQL, undefined, this.GetUserFromPayload(userPayload));
2039
- const result = this.ArrayMapFieldNamesToCodeNames('MJ: AI Agent Run Steps', rows);
2058
+ const result = this.ArrayMapFieldNamesToCodeNames('MJ: AI Agent Runs', rows);
2040
2059
  return result;
2041
2060
  }
2042
2061
 
2043
- @FieldResolver(() => [AIAgentRun_])
2044
- async MJ_AIAgentRuns_ParentRunIDArray(@Root() aiagentrun_: AIAgentRun_, @Ctx() { dataSources, userPayload, providers }: AppContext, @PubSub() pubSub: PubSubEngine) {
2045
- this.CheckUserReadPermissions('MJ: AI Agent Runs', userPayload);
2062
+ @FieldResolver(() => [AIAgentRunStep_])
2063
+ async MJ_AIAgentRunSteps_AgentRunIDArray(@Root() aiagentrun_: AIAgentRun_, @Ctx() { dataSources, userPayload, providers }: AppContext, @PubSub() pubSub: PubSubEngine) {
2064
+ this.CheckUserReadPermissions('MJ: AI Agent Run Steps', userPayload);
2046
2065
  const provider = GetReadOnlyProvider(providers, { allowFallbackToReadWrite: true });
2047
2066
  const connPool = GetReadOnlyDataSource(dataSources, { allowFallbackToReadWrite: true });
2048
- const sSQL = `SELECT * FROM [${Metadata.Provider.ConfigData.MJCoreSchemaName}].[vwAIAgentRuns] WHERE [ParentRunID]='${aiagentrun_.ID}' ` + this.getRowLevelSecurityWhereClause(provider, 'MJ: AI Agent Runs', userPayload, EntityPermissionType.Read, 'AND');
2067
+ const sSQL = `SELECT * FROM [${Metadata.Provider.ConfigData.MJCoreSchemaName}].[vwAIAgentRunSteps] WHERE [AgentRunID]='${aiagentrun_.ID}' ` + this.getRowLevelSecurityWhereClause(provider, 'MJ: AI Agent Run Steps', userPayload, EntityPermissionType.Read, 'AND');
2049
2068
  const rows = await SQLServerDataProvider.ExecuteSQLWithPool(connPool, sSQL, undefined, this.GetUserFromPayload(userPayload));
2050
- const result = this.ArrayMapFieldNamesToCodeNames('MJ: AI Agent Runs', rows);
2069
+ const result = this.ArrayMapFieldNamesToCodeNames('MJ: AI Agent Run Steps', rows);
2051
2070
  return result;
2052
2071
  }
2053
2072
 
@@ -2389,15 +2408,15 @@ export class AIConfiguration_ {
2389
2408
  @Field(() => [AIAgentPrompt_])
2390
2409
  MJ_AIAgentPrompts_ConfigurationIDArray: AIAgentPrompt_[]; // Link to MJ_AIAgentPrompts
2391
2410
 
2411
+ @Field(() => [AIPromptRun_])
2412
+ MJ_AIPromptRuns_ConfigurationIDArray: AIPromptRun_[]; // Link to MJ_AIPromptRuns
2413
+
2392
2414
  @Field(() => [AIPromptModel_])
2393
2415
  MJ_AIPromptModels_ConfigurationIDArray: AIPromptModel_[]; // Link to MJ_AIPromptModels
2394
2416
 
2395
2417
  @Field(() => [AIResultCache_])
2396
2418
  AIResultCache_ConfigurationIDArray: AIResultCache_[]; // Link to AIResultCache
2397
2419
 
2398
- @Field(() => [AIPromptRun_])
2399
- MJ_AIPromptRuns_ConfigurationIDArray: AIPromptRun_[]; // Link to MJ_AIPromptRuns
2400
-
2401
2420
  @Field(() => [AIAgentRun_])
2402
2421
  MJ_AIAgentRuns_ConfigurationIDArray: AIAgentRun_[]; // Link to MJ_AIAgentRuns
2403
2422
 
@@ -2541,6 +2560,17 @@ export class AIConfigurationResolver extends ResolverBase {
2541
2560
  return result;
2542
2561
  }
2543
2562
 
2563
+ @FieldResolver(() => [AIPromptRun_])
2564
+ async MJ_AIPromptRuns_ConfigurationIDArray(@Root() aiconfiguration_: AIConfiguration_, @Ctx() { dataSources, userPayload, providers }: AppContext, @PubSub() pubSub: PubSubEngine) {
2565
+ this.CheckUserReadPermissions('MJ: AI Prompt Runs', userPayload);
2566
+ const provider = GetReadOnlyProvider(providers, { allowFallbackToReadWrite: true });
2567
+ const connPool = GetReadOnlyDataSource(dataSources, { allowFallbackToReadWrite: true });
2568
+ const sSQL = `SELECT * FROM [${Metadata.Provider.ConfigData.MJCoreSchemaName}].[vwAIPromptRuns] WHERE [ConfigurationID]='${aiconfiguration_.ID}' ` + this.getRowLevelSecurityWhereClause(provider, 'MJ: AI Prompt Runs', userPayload, EntityPermissionType.Read, 'AND');
2569
+ const rows = await SQLServerDataProvider.ExecuteSQLWithPool(connPool, sSQL, undefined, this.GetUserFromPayload(userPayload));
2570
+ const result = this.ArrayMapFieldNamesToCodeNames('MJ: AI Prompt Runs', rows);
2571
+ return result;
2572
+ }
2573
+
2544
2574
  @FieldResolver(() => [AIPromptModel_])
2545
2575
  async MJ_AIPromptModels_ConfigurationIDArray(@Root() aiconfiguration_: AIConfiguration_, @Ctx() { dataSources, userPayload, providers }: AppContext, @PubSub() pubSub: PubSubEngine) {
2546
2576
  this.CheckUserReadPermissions('MJ: AI Prompt Models', userPayload);
@@ -2563,17 +2593,6 @@ export class AIConfigurationResolver extends ResolverBase {
2563
2593
  return result;
2564
2594
  }
2565
2595
 
2566
- @FieldResolver(() => [AIPromptRun_])
2567
- async MJ_AIPromptRuns_ConfigurationIDArray(@Root() aiconfiguration_: AIConfiguration_, @Ctx() { dataSources, userPayload, providers }: AppContext, @PubSub() pubSub: PubSubEngine) {
2568
- this.CheckUserReadPermissions('MJ: AI Prompt Runs', userPayload);
2569
- const provider = GetReadOnlyProvider(providers, { allowFallbackToReadWrite: true });
2570
- const connPool = GetReadOnlyDataSource(dataSources, { allowFallbackToReadWrite: true });
2571
- const sSQL = `SELECT * FROM [${Metadata.Provider.ConfigData.MJCoreSchemaName}].[vwAIPromptRuns] WHERE [ConfigurationID]='${aiconfiguration_.ID}' ` + this.getRowLevelSecurityWhereClause(provider, 'MJ: AI Prompt Runs', userPayload, EntityPermissionType.Read, 'AND');
2572
- const rows = await SQLServerDataProvider.ExecuteSQLWithPool(connPool, sSQL, undefined, this.GetUserFromPayload(userPayload));
2573
- const result = this.ArrayMapFieldNamesToCodeNames('MJ: AI Prompt Runs', rows);
2574
- return result;
2575
- }
2576
-
2577
2596
  @FieldResolver(() => [AIAgentRun_])
2578
2597
  async MJ_AIAgentRuns_ConfigurationIDArray(@Root() aiconfiguration_: AIConfiguration_, @Ctx() { dataSources, userPayload, providers }: AppContext, @PubSub() pubSub: PubSubEngine) {
2579
2598
  this.CheckUserReadPermissions('MJ: AI Agent Runs', userPayload);
@@ -5104,12 +5123,12 @@ export class AIPrompt_ {
5104
5123
  @Field(() => [AIPrompt_])
5105
5124
  AIPrompts_ResultSelectorPromptIDArray: AIPrompt_[]; // Link to AIPrompts
5106
5125
 
5107
- @Field(() => [AIPromptModel_])
5108
- MJ_AIPromptModels_PromptIDArray: AIPromptModel_[]; // Link to MJ_AIPromptModels
5109
-
5110
5126
  @Field(() => [AIAgentPrompt_])
5111
5127
  MJ_AIAgentPrompts_PromptIDArray: AIAgentPrompt_[]; // Link to MJ_AIAgentPrompts
5112
5128
 
5129
+ @Field(() => [AIPromptModel_])
5130
+ MJ_AIPromptModels_PromptIDArray: AIPromptModel_[]; // Link to MJ_AIPromptModels
5131
+
5113
5132
  @Field(() => [AIAgentStep_])
5114
5133
  MJ_AIAgentSteps_PromptIDArray: AIAgentStep_[]; // Link to MJ_AIAgentSteps
5115
5134
 
@@ -5544,25 +5563,25 @@ export class AIPromptResolver extends ResolverBase {
5544
5563
  return result;
5545
5564
  }
5546
5565
 
5547
- @FieldResolver(() => [AIPromptModel_])
5548
- async MJ_AIPromptModels_PromptIDArray(@Root() aiprompt_: AIPrompt_, @Ctx() { dataSources, userPayload, providers }: AppContext, @PubSub() pubSub: PubSubEngine) {
5549
- this.CheckUserReadPermissions('MJ: AI Prompt Models', userPayload);
5566
+ @FieldResolver(() => [AIAgentPrompt_])
5567
+ async MJ_AIAgentPrompts_PromptIDArray(@Root() aiprompt_: AIPrompt_, @Ctx() { dataSources, userPayload, providers }: AppContext, @PubSub() pubSub: PubSubEngine) {
5568
+ this.CheckUserReadPermissions('MJ: AI Agent Prompts', userPayload);
5550
5569
  const provider = GetReadOnlyProvider(providers, { allowFallbackToReadWrite: true });
5551
5570
  const connPool = GetReadOnlyDataSource(dataSources, { allowFallbackToReadWrite: true });
5552
- const sSQL = `SELECT * FROM [${Metadata.Provider.ConfigData.MJCoreSchemaName}].[vwAIPromptModels] WHERE [PromptID]='${aiprompt_.ID}' ` + this.getRowLevelSecurityWhereClause(provider, 'MJ: AI Prompt Models', userPayload, EntityPermissionType.Read, 'AND');
5571
+ const sSQL = `SELECT * FROM [${Metadata.Provider.ConfigData.MJCoreSchemaName}].[vwAIAgentPrompts] WHERE [PromptID]='${aiprompt_.ID}' ` + this.getRowLevelSecurityWhereClause(provider, 'MJ: AI Agent Prompts', userPayload, EntityPermissionType.Read, 'AND');
5553
5572
  const rows = await SQLServerDataProvider.ExecuteSQLWithPool(connPool, sSQL, undefined, this.GetUserFromPayload(userPayload));
5554
- const result = this.ArrayMapFieldNamesToCodeNames('MJ: AI Prompt Models', rows);
5573
+ const result = this.ArrayMapFieldNamesToCodeNames('MJ: AI Agent Prompts', rows);
5555
5574
  return result;
5556
5575
  }
5557
5576
 
5558
- @FieldResolver(() => [AIAgentPrompt_])
5559
- async MJ_AIAgentPrompts_PromptIDArray(@Root() aiprompt_: AIPrompt_, @Ctx() { dataSources, userPayload, providers }: AppContext, @PubSub() pubSub: PubSubEngine) {
5560
- this.CheckUserReadPermissions('MJ: AI Agent Prompts', userPayload);
5577
+ @FieldResolver(() => [AIPromptModel_])
5578
+ async MJ_AIPromptModels_PromptIDArray(@Root() aiprompt_: AIPrompt_, @Ctx() { dataSources, userPayload, providers }: AppContext, @PubSub() pubSub: PubSubEngine) {
5579
+ this.CheckUserReadPermissions('MJ: AI Prompt Models', userPayload);
5561
5580
  const provider = GetReadOnlyProvider(providers, { allowFallbackToReadWrite: true });
5562
5581
  const connPool = GetReadOnlyDataSource(dataSources, { allowFallbackToReadWrite: true });
5563
- const sSQL = `SELECT * FROM [${Metadata.Provider.ConfigData.MJCoreSchemaName}].[vwAIAgentPrompts] WHERE [PromptID]='${aiprompt_.ID}' ` + this.getRowLevelSecurityWhereClause(provider, 'MJ: AI Agent Prompts', userPayload, EntityPermissionType.Read, 'AND');
5582
+ const sSQL = `SELECT * FROM [${Metadata.Provider.ConfigData.MJCoreSchemaName}].[vwAIPromptModels] WHERE [PromptID]='${aiprompt_.ID}' ` + this.getRowLevelSecurityWhereClause(provider, 'MJ: AI Prompt Models', userPayload, EntityPermissionType.Read, 'AND');
5564
5583
  const rows = await SQLServerDataProvider.ExecuteSQLWithPool(connPool, sSQL, undefined, this.GetUserFromPayload(userPayload));
5565
- const result = this.ArrayMapFieldNamesToCodeNames('MJ: AI Agent Prompts', rows);
5584
+ const result = this.ArrayMapFieldNamesToCodeNames('MJ: AI Prompt Models', rows);
5566
5585
  return result;
5567
5586
  }
5568
5587
 
@@ -42644,6 +42663,13 @@ export class AIPromptRun_ {
42644
42663
  @Field(() => Int, {nullable: true, description: `Effort level that was actually used during this prompt run execution (1-100, where 1=minimal effort, 100=maximum effort). This is the resolved effort level after applying the precedence hierarchy: runtime override > agent default > prompt default > provider default.`})
42645
42664
  EffortLevel?: number;
42646
42665
 
42666
+ @Field({nullable: true, description: `Optional name for the prompt run to help identify and tag runs for easier reference`})
42667
+ @MaxLength(510)
42668
+ RunName?: string;
42669
+
42670
+ @Field({nullable: true, description: `Human-readable notes and comments about this prompt run`})
42671
+ Comments?: string;
42672
+
42647
42673
  @Field()
42648
42674
  @MaxLength(510)
42649
42675
  Prompt: string;
@@ -42925,6 +42951,12 @@ export class CreateAIPromptRunInput {
42925
42951
 
42926
42952
  @Field(() => Int, { nullable: true })
42927
42953
  EffortLevel: number | null;
42954
+
42955
+ @Field({ nullable: true })
42956
+ RunName: string | null;
42957
+
42958
+ @Field({ nullable: true })
42959
+ Comments: string | null;
42928
42960
  }
42929
42961
 
42930
42962
 
@@ -43170,6 +43202,12 @@ export class UpdateAIPromptRunInput {
43170
43202
  @Field(() => Int, { nullable: true })
43171
43203
  EffortLevel?: number | null;
43172
43204
 
43205
+ @Field({ nullable: true })
43206
+ RunName?: string | null;
43207
+
43208
+ @Field({ nullable: true })
43209
+ Comments?: string | null;
43210
+
43173
43211
  @Field(() => [KeyValuePairInput], { nullable: true })
43174
43212
  OldValues___?: KeyValuePairInput[];
43175
43213
  }
@@ -43363,6 +43401,16 @@ permanently, Warn means validation failed but execution continues.`})
43363
43401
  detailed information about what validation rules failed.`})
43364
43402
  FinalPayloadValidationMessages?: string;
43365
43403
 
43404
+ @Field({nullable: true, description: `Optional reference to parent step for tracking hierarchical relationships like code->test->fix->code cycles`})
43405
+ @MaxLength(16)
43406
+ ParentID?: string;
43407
+
43408
+ @Field({nullable: true, description: `Human-readable notes and comments about this agent run step`})
43409
+ Comments?: string;
43410
+
43411
+ @Field(() => [AIAgentRunStep_])
43412
+ MJ_AIAgentRunSteps_ParentIDArray: AIAgentRunStep_[]; // Link to MJ_AIAgentRunSteps
43413
+
43366
43414
  }
43367
43415
 
43368
43416
  //****************************************************************************
@@ -43423,6 +43471,12 @@ export class CreateAIAgentRunStepInput {
43423
43471
 
43424
43472
  @Field({ nullable: true })
43425
43473
  FinalPayloadValidationMessages: string | null;
43474
+
43475
+ @Field({ nullable: true })
43476
+ ParentID: string | null;
43477
+
43478
+ @Field({ nullable: true })
43479
+ Comments: string | null;
43426
43480
  }
43427
43481
 
43428
43482
 
@@ -43485,6 +43539,12 @@ export class UpdateAIAgentRunStepInput {
43485
43539
  @Field({ nullable: true })
43486
43540
  FinalPayloadValidationMessages?: string | null;
43487
43541
 
43542
+ @Field({ nullable: true })
43543
+ ParentID?: string | null;
43544
+
43545
+ @Field({ nullable: true })
43546
+ Comments?: string | null;
43547
+
43488
43548
  @Field(() => [KeyValuePairInput], { nullable: true })
43489
43549
  OldValues___?: KeyValuePairInput[];
43490
43550
  }
@@ -43547,6 +43607,17 @@ export class AIAgentRunStepResolver extends ResolverBase {
43547
43607
  return result;
43548
43608
  }
43549
43609
 
43610
+ @FieldResolver(() => [AIAgentRunStep_])
43611
+ async MJ_AIAgentRunSteps_ParentIDArray(@Root() aiagentrunstep_: AIAgentRunStep_, @Ctx() { dataSources, userPayload, providers }: AppContext, @PubSub() pubSub: PubSubEngine) {
43612
+ this.CheckUserReadPermissions('MJ: AI Agent Run Steps', userPayload);
43613
+ const provider = GetReadOnlyProvider(providers, { allowFallbackToReadWrite: true });
43614
+ const connPool = GetReadOnlyDataSource(dataSources, { allowFallbackToReadWrite: true });
43615
+ const sSQL = `SELECT * FROM [${Metadata.Provider.ConfigData.MJCoreSchemaName}].[vwAIAgentRunSteps] WHERE [ParentID]='${aiagentrunstep_.ID}' ` + this.getRowLevelSecurityWhereClause(provider, 'MJ: AI Agent Run Steps', userPayload, EntityPermissionType.Read, 'AND');
43616
+ const rows = await SQLServerDataProvider.ExecuteSQLWithPool(connPool, sSQL, undefined, this.GetUserFromPayload(userPayload));
43617
+ const result = this.ArrayMapFieldNamesToCodeNames('MJ: AI Agent Run Steps', rows);
43618
+ return result;
43619
+ }
43620
+
43550
43621
  @Mutation(() => AIAgentRunStep_)
43551
43622
  async CreateAIAgentRunStep(
43552
43623
  @Arg('input', () => CreateAIAgentRunStepInput) input: CreateAIAgentRunStepInput,
@@ -103,20 +103,19 @@ export class ReportResolverExtended {
103
103
  const title = skipData.title ? skipData.title : skipData.reportTitle ? skipData.reportTitle : 'Untitled Report';
104
104
  report.Name = title;
105
105
  report.Description = skipData.userExplanation ? skipData.userExplanation : '';
106
- report.ConversationID = result[0].ConversationID;
106
+ report.ConversationID = result.recordset[0].ConversationID;
107
107
  report.ConversationDetailID = ConversationDetailID;
108
108
 
109
109
  const dc: DataContext = new DataContext();
110
- await dc.LoadMetadata(result[0].DataContextID, u);
110
+ await dc.LoadMetadata(result.recordset[0].DataContextID, u);
111
111
  const newDataContext = await DataContext.Clone(dc, false, u);
112
112
  if (!newDataContext) throw new Error('Error cloning data context');
113
113
  report.DataContextID = newDataContext.ID;
114
114
 
115
115
  // next, strip out the messags from the SkipData object to put them into our Report Configuration as we dont need to store that information as we have a
116
- // link back to the conversation and conversation detail
117
- const newSkipData: SkipAPIAnalysisCompleteResponse = JSON.parse(JSON.stringify(skipData));
118
- newSkipData.messages = [];
119
- report.Configuration = JSON.stringify(newSkipData);
116
+ // link back to the conversation and conversation detail, skipData can be modified as it is a copy of the data doesn't affect the original source
117
+ skipData.messages = [];
118
+ report.Configuration = JSON.stringify(skipData);
120
119
 
121
120
  report.SharingScope = 'None';
122
121
  report.UserID = u.ID;
@@ -1,4 +1,4 @@
1
- import { Resolver, Mutation, Arg, Ctx, ObjectType, Field, PubSub, PubSubEngine, Subscription, Root, ResolverFilterData, ID } from 'type-graphql';
1
+ import { Resolver, Mutation, Query, Arg, Ctx, ObjectType, Field, PubSub, PubSubEngine, Subscription, Root, ResolverFilterData, ID } from 'type-graphql';
2
2
  import { UserPayload } from '../types.js';
3
3
  import { LogError, LogStatus } from '@memberjunction/core';
4
4
  import { AIAgentEntityExtended } from '@memberjunction/core-entities';
@@ -7,6 +7,7 @@ import { ExecuteAgentResult } from '@memberjunction/ai-core-plus';
7
7
  import { AIEngine } from '@memberjunction/aiengine';
8
8
  import { ResolverBase } from '../generic/ResolverBase.js';
9
9
  import { PUSH_STATUS_UPDATES_TOPIC } from '../generic/PushStatusResolver.js';
10
+ import { RequireSystemUser } from '../directives/RequireSystemUser.js';
10
11
 
11
12
  @ObjectType()
12
13
  export class AIAgentRunResult {
@@ -297,18 +298,22 @@ export class RunAIAgentResolver extends ResolverBase {
297
298
  };
298
299
  }
299
300
 
300
- @Mutation(() => AIAgentRunResult)
301
- async RunAIAgent(
302
- @Arg('agentId') agentId: string,
303
- @Ctx() { userPayload }: { userPayload: UserPayload },
304
- @Arg('messages') messagesJson: string,
305
- @Arg('sessionId') sessionId: string,
306
- @PubSub() pubSub: PubSubEngine,
307
- @Arg('data', { nullable: true }) data?: string,
308
- @Arg('templateData', { nullable: true }) templateData?: string,
309
- @Arg('lastRunId', { nullable: true }) lastRunId?: string,
310
- @Arg('autoPopulateLastRunPayload', { nullable: true }) autoPopulateLastRunPayload?: boolean,
311
- @Arg('configurationId', { nullable: true }) configurationId?: string
301
+ /**
302
+ * Internal method that handles the core AI agent execution logic.
303
+ * This method is called by both the regular and system user resolvers.
304
+ * @private
305
+ */
306
+ private async executeAIAgent(
307
+ agentId: string,
308
+ userPayload: UserPayload,
309
+ messagesJson: string,
310
+ sessionId: string,
311
+ pubSub: PubSubEngine,
312
+ data?: string,
313
+ templateData?: string,
314
+ lastRunId?: string,
315
+ autoPopulateLastRunPayload?: boolean,
316
+ configurationId?: string
312
317
  ): Promise<AIAgentRunResult> {
313
318
  const startTime = Date.now();
314
319
 
@@ -441,5 +446,67 @@ export class RunAIAgentResolver extends ResolverBase {
441
446
  };
442
447
  this.PublishStreamingUpdate(pubSub, completeMsg, userPayload);
443
448
  }
449
+
450
+ /**
451
+ * Public mutation for regular users to run AI agents with authentication.
452
+ */
453
+ @Mutation(() => AIAgentRunResult)
454
+ async RunAIAgent(
455
+ @Arg('agentId') agentId: string,
456
+ @Ctx() { userPayload }: { userPayload: UserPayload },
457
+ @Arg('messages') messagesJson: string,
458
+ @Arg('sessionId') sessionId: string,
459
+ @PubSub() pubSub: PubSubEngine,
460
+ @Arg('data', { nullable: true }) data?: string,
461
+ @Arg('templateData', { nullable: true }) templateData?: string,
462
+ @Arg('lastRunId', { nullable: true }) lastRunId?: string,
463
+ @Arg('autoPopulateLastRunPayload', { nullable: true }) autoPopulateLastRunPayload?: boolean,
464
+ @Arg('configurationId', { nullable: true }) configurationId?: string
465
+ ): Promise<AIAgentRunResult> {
466
+ return this.executeAIAgent(
467
+ agentId,
468
+ userPayload,
469
+ messagesJson,
470
+ sessionId,
471
+ pubSub,
472
+ data,
473
+ templateData,
474
+ lastRunId,
475
+ autoPopulateLastRunPayload,
476
+ configurationId
477
+ );
478
+ }
479
+
480
+ /**
481
+ * System user query for running AI agents with elevated privileges.
482
+ * Requires the @RequireSystemUser decorator to ensure only system users can access.
483
+ */
484
+ @RequireSystemUser()
485
+ @Query(() => AIAgentRunResult)
486
+ async RunAIAgentSystemUser(
487
+ @Arg('agentId') agentId: string,
488
+ @Ctx() { userPayload }: { userPayload: UserPayload },
489
+ @Arg('messages') messagesJson: string,
490
+ @Arg('sessionId') sessionId: string,
491
+ @PubSub() pubSub: PubSubEngine,
492
+ @Arg('data', { nullable: true }) data?: string,
493
+ @Arg('templateData', { nullable: true }) templateData?: string,
494
+ @Arg('lastRunId', { nullable: true }) lastRunId?: string,
495
+ @Arg('autoPopulateLastRunPayload', { nullable: true }) autoPopulateLastRunPayload?: boolean,
496
+ @Arg('configurationId', { nullable: true }) configurationId?: string
497
+ ): Promise<AIAgentRunResult> {
498
+ return this.executeAIAgent(
499
+ agentId,
500
+ userPayload,
501
+ messagesJson,
502
+ sessionId,
503
+ pubSub,
504
+ data,
505
+ templateData,
506
+ lastRunId,
507
+ autoPopulateLastRunPayload,
508
+ configurationId
509
+ );
510
+ }
444
511
 
445
512
  }