@peopl-health/nexus 3.8.10 → 3.8.11

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.
@@ -40,6 +40,15 @@ const switchThreadStoppedStatus = async (code, stopped) => {
40
40
  .catch(err => logger.error('[switchThreadStoppedStatus] Failed to update message_monitor', { code, error: err.message }));
41
41
  };
42
42
 
43
+ const setThreadPromptId = async (code, promptId) => {
44
+ const updateFields = {};
45
+ Thread.setAssistantId(updateFields, promptId);
46
+ await Thread.updateOne({ code: code }, { $set: updateFields });
47
+
48
+ updateRecordByFilter(Monitoreo_ID, 'message_monitor', `{whatsapp_id} = "${code}"`, { prompt_id: promptId })
49
+ .catch(err => logger.error('[setThreadPromptId] Failed to update message_monitor', { code, error: err.message }));
50
+ };
51
+
43
52
  const createPlaceholderThread = async (code) => {
44
53
  try {
45
54
  const existing = await Thread.findOne({ code });
@@ -50,9 +59,10 @@ const createPlaceholderThread = async (code) => {
50
59
  const record = await getRecordByFilter(Config_ID, 'responses', `AND({code}="PIPO_ASST", {status}="${assistantStatus}")`, undefined, ['prompt_id']);
51
60
  const prompt_id = record?.[0]?.['prompt_id'] || null;
52
61
 
53
- const thread = new Thread({ code, assistant_id: null, prompt_id, conversation_id: null });
62
+ const thread = new Thread({ code, assistant_id: null, conversation_id: null });
54
63
  await thread.save();
55
64
  await switchThreadStoppedStatus(code, true);
65
+ await setThreadPromptId(code, prompt_id);
56
66
  logger.info('[createPlaceholderThread] Created', { code, prompt_id });
57
67
 
58
68
  if (prompt_id) {
@@ -80,5 +90,6 @@ module.exports = {
80
90
  getThreadInfo,
81
91
  createPlaceholderThread,
82
92
  ensureThreadExists,
83
- switchThreadStoppedStatus
93
+ switchThreadStoppedStatus,
94
+ setThreadPromptId
84
95
  };
@@ -11,7 +11,7 @@ const { getPredictionMetrics } = require('../models/predictionMetricsModel');
11
11
  const { insertMessage } = require('../models/messageModel');
12
12
 
13
13
  const { getCurRow, runAssistantWithRetries } = require('../helpers/assistantHelper.js');
14
- const { getThread, switchThreadStoppedStatus } = require('../helpers/threadHelper.js');
14
+ const { getThread, switchThreadStoppedStatus, setThreadPromptId } = require('../helpers/threadHelper.js');
15
15
  const { processThreadMessage } = require('../helpers/processHelper.js');
16
16
  const { getLastNMessages, storeProcessedContent } = require('../helpers/messageHelper.js');
17
17
  const { combineImagesToPDF, cleanupFiles } = require('../helpers/filesHelper.js');
@@ -26,9 +26,7 @@ const createAssistantCore = async (code, assistant_id, _messages = [], force = f
26
26
  if (findThread && findThread.getConversationId() && !force) {
27
27
  logger.info('[createAssistant] Thread already exists');
28
28
  await switchThreadStoppedStatus(code, false);
29
- const updateFields = {};
30
- Thread.setAssistantId(updateFields, assistant_id);
31
- await Thread.updateOne({ code: code }, { $set: updateFields });
29
+ await setThreadPromptId(code, assistant_id);
32
30
  return { success: true, assistant_id, thread: findThread };
33
31
  }
34
32
 
@@ -53,12 +51,12 @@ const createAssistantCore = async (code, assistant_id, _messages = [], force = f
53
51
  nombre: nombre,
54
52
  active: true
55
53
  };
56
- Thread.setAssistantId(thread, assistant_id);
57
54
  Thread.setConversationId(thread, initialThread.id);
58
55
 
59
56
  const condition = { $or: [{ code: code }] };
60
57
  const options = { new: true, upsert: true };
61
58
  const updatedThread = await Thread.findOneAndUpdate(condition, { ...thread }, options);
59
+ await setThreadPromptId(code, assistant_id);
62
60
  logger.info('[createAssistant] Updated thread', { updatedThread });
63
61
 
64
62
  return { success: true, assistant_id, thread: updatedThread };
@@ -340,7 +338,7 @@ const switchAssistantCore = async (code, assistant_id) => {
340
338
  updatedAt: new Date()
341
339
  };
342
340
  await switchThreadStoppedStatus(code, false);
343
- Thread.setAssistantId(updateFields, assistant_id);
341
+ await setThreadPromptId(code, assistant_id);
344
342
 
345
343
  await Thread.updateOne({ code }, { $set: updateFields });
346
344
  logger.info('[switchAssistant] Assistant switched', { code, assistant_id });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peopl-health/nexus",
3
- "version": "3.8.10",
3
+ "version": "3.8.11",
4
4
  "description": "Core messaging and assistant library for WhatsApp communication platforms",
5
5
  "keywords": [
6
6
  "whatsapp",