@memberjunction/server 2.122.1 → 2.123.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.
@@ -170,7 +170,7 @@ export class RunAIAgentResolver extends ResolverBase {
170
170
  */
171
171
  private parseJsonInput(jsonString: string | undefined, fieldName: string): any {
172
172
  if (!jsonString) return {};
173
-
173
+
174
174
  try {
175
175
  return JSON.parse(jsonString);
176
176
  } catch (parseError) {
@@ -178,6 +178,26 @@ export class RunAIAgentResolver extends ResolverBase {
178
178
  }
179
179
  }
180
180
 
181
+ /**
182
+ * Extract the user message from the messages array
183
+ * Looks for the last user message in the conversation
184
+ */
185
+ private extractUserMessage(messages: any[]): string | undefined {
186
+ if (!Array.isArray(messages) || messages.length === 0) {
187
+ return undefined;
188
+ }
189
+
190
+ // Find the last user message in the array
191
+ for (let i = messages.length - 1; i >= 0; i--) {
192
+ const msg = messages[i];
193
+ if (msg && msg.role === 'user' && msg.content) {
194
+ return msg.content;
195
+ }
196
+ }
197
+
198
+ return undefined;
199
+ }
200
+
181
201
  /**
182
202
  * Validate the agent entity
183
203
  */
@@ -347,6 +367,9 @@ export class RunAIAgentResolver extends ResolverBase {
347
367
  throw new Error('Messages must be an array');
348
368
  }
349
369
 
370
+ // Extract user message from messages array (needed when conversationDetailId not provided)
371
+ const userMessage = this.extractUserMessage(parsedMessages);
372
+
350
373
  // Parse data contexts
351
374
  const parsedData = this.parseJsonInput(data, 'data');
352
375
  const parsedTemplateData = this.parseJsonInput(templateData, 'templateData');
@@ -356,7 +379,7 @@ export class RunAIAgentResolver extends ResolverBase {
356
379
  if (!currentUser) {
357
380
  throw new Error('Unable to determine current user');
358
381
  }
359
-
382
+
360
383
  // Validate agent
361
384
  const agentEntity = await this.validateAgent(agentId, currentUser);
362
385
 
@@ -387,6 +410,7 @@ export class RunAIAgentResolver extends ResolverBase {
387
410
  }
388
411
  }, {
389
412
  conversationDetailId: conversationDetailId, // Use existing if provided
413
+ userMessage: userMessage, // Provide user message when conversationDetailId not provided
390
414
  createArtifacts: createArtifacts || false,
391
415
  sourceArtifactId: sourceArtifactId
392
416
  });