@peopl-health/nexus 3.2.5 → 3.2.7

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.
@@ -19,8 +19,8 @@ const runAssistantAndWait = async ({
19
19
  message = null,
20
20
  runConfig = {}
21
21
  }) => {
22
- if (!thread || !thread.getConversationId()) {
23
- throw new Error('runAssistantAndWait requires a thread with a valid thread_id or conversation_id');
22
+ if (!thread) {
23
+ throw new Error('runAssistantAndWait requires a thread');
24
24
  }
25
25
 
26
26
  if (!assistant) {
@@ -37,7 +37,9 @@ class OpenAIResponsesProvider {
37
37
  responseModel: 'gpt-5',
38
38
  chatModel: 'gpt-4o-mini',
39
39
  transcriptionModel: 'whisper-1',
40
- reasoningEffort: 'medium',
40
+ reasoningEffort: 'low',
41
+ temperature: 0.7,
42
+ maxOutputTokens: 600,
41
43
  ...defaultModels,
42
44
  };
43
45
 
@@ -282,9 +284,7 @@ class OpenAIResponsesProvider {
282
284
  promptVersion = null,
283
285
  promptVariables = null
284
286
  } = {}) {
285
- try {
286
- const id = this._ensurethreadId(threadId);
287
-
287
+ try {
288
288
  let input = context || this._convertItemsToApiFormat(additionalMessages);
289
289
  let allToolsExecuted = [];
290
290
  let totalRetries = 0;
@@ -301,10 +301,12 @@ class OpenAIResponsesProvider {
301
301
  prompt: promptConfig,
302
302
  input: inputData,
303
303
  instructions: instructions || additionalInstructions,
304
- truncation: truncationStrategy,
304
+ max_output_tokens: maxOutputTokens ?? this.defaults.maxOutputTokens,
305
+ ...(topP !== undefined && { top_p: topP }),
305
306
  }), { providerName: PROVIDER_NAME });
306
307
 
307
308
  const { result: response, retries } = await makeAPICall(input);
309
+ logger.info('[OpenAIResponsesProvider] Run response', { response });
308
310
  totalRetries += retries;
309
311
  let finalResponse = response;
310
312
 
@@ -313,7 +315,7 @@ class OpenAIResponsesProvider {
313
315
  const functionCalls = response.output.filter(item => item.type === 'function_call');
314
316
 
315
317
  if (functionCalls.length > 0) {
316
- const { outputs, toolsExecuted } = await handleFunctionCallsUtil(functionCalls, assistant, toolMetadata || { thread_id: id, assistant_id: assistantId });
318
+ const { outputs, toolsExecuted } = await handleFunctionCallsUtil(functionCalls, assistant, toolMetadata || { thread_id: threadId, assistant_id: assistantId });
317
319
 
318
320
  input.push(...response.output);
319
321
  input.push(...outputs);
@@ -327,7 +329,7 @@ class OpenAIResponsesProvider {
327
329
 
328
330
  return {
329
331
  ...finalResponse,
330
- thread_id: id,
332
+ thread_id: threadId,
331
333
  assistant_id: assistantId,
332
334
  object: finalResponse.object || 'response',
333
335
  tools_executed: allToolsExecuted,
@@ -161,10 +161,12 @@ const replyAssistantCore = async (code, message_ = null, thread_ = null, runOpti
161
161
  const messagesStart = Date.now();
162
162
  const beforeCheckpoint = message_?.createdAt ?
163
163
  (message_.createdAt.$date ? new Date(message_.createdAt.$date) : message_.createdAt) : null;
164
- const lastMessage = await getLastNMessages(code, 1, beforeCheckpoint);
164
+ const lastMessage = await getLastNMessages(code, 1, beforeCheckpoint, {
165
+ query: { from_me: false }
166
+ });
165
167
  timings.get_messages_ms = Date.now() - messagesStart;
166
168
 
167
- if (!lastMessage || lastMessage.length === 0 || lastMessage[0].from_me) {
169
+ if (!lastMessage || lastMessage.length === 0) {
168
170
  logger.info('[replyAssistantCore] No relevant data found for this assistant.');
169
171
  return null;
170
172
  }
@@ -226,7 +228,10 @@ const replyAssistantCore = async (code, message_ = null, thread_ = null, runOpti
226
228
  }
227
229
  }
228
230
 
229
- if (!patientMsg || finalThread.stopped) return null;
231
+ if (!patientMsg || finalThread.stopped) {
232
+ logger.info('[replyAssistantCore] Skipping AI processing', { patientMsg, stopped: finalThread.stopped, code });
233
+ return null;
234
+ }
230
235
 
231
236
  const assistant = getAssistantById(finalThread.getAssistantId(), finalThread);
232
237
  const runStart = Date.now();
@@ -13,7 +13,7 @@ function formatForWhatsApp(text) {
13
13
  let formatted = text;
14
14
 
15
15
  // Add line breaks after dash items (bullet points)
16
- formatted = formatted.replace(/(\.\s*-\s+)/g, '.\n\n- ');
16
+ formatted = formatted.replace(/(\.\s*-\s+)/g, '.\n- ');
17
17
  formatted = formatted.replace(/(:)\s*(-\s+)/g, '$1\n- ');
18
18
 
19
19
  // Add line breaks after semicolons when they separate items
@@ -22,12 +22,8 @@ function formatForWhatsApp(text) {
22
22
  // Add line breaks after periods that end sentences before dashes
23
23
  formatted = formatted.replace(/(\.\s+)(-\s+)/g, '$1\n$2');
24
24
 
25
- // Convert dashes to bullet points
26
- formatted = formatted.replace(/^-\s+/gm, '• ');
27
- formatted = formatted.replace(/(\n|^)\s*-\s+/g, '$1• ');
28
-
29
25
  // Clean up multiple consecutive line breaks
30
- formatted = formatted.replace(/\n{3,}/g, '\n\n');
26
+ formatted = formatted.replace(/\n{2,}/g, '\n');
31
27
 
32
28
  return formatted.trim();
33
29
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peopl-health/nexus",
3
- "version": "3.2.5",
3
+ "version": "3.2.7",
4
4
  "description": "Core messaging and assistant library for WhatsApp communication platforms",
5
5
  "keywords": [
6
6
  "whatsapp",
@@ -84,7 +84,7 @@
84
84
  "@opentelemetry/sdk-trace-node": "1.28.0",
85
85
  "@opentelemetry/semantic-conventions": "1.28.0",
86
86
  "airtable": "^0.12.2",
87
- "aws-sdk": "2.1674.0",
87
+ "aws-sdk": "2.1693.0",
88
88
  "axios": "^1.5.0",
89
89
  "dotenv": "^16.6.1",
90
90
  "moment-timezone": "^0.5.43",