@peopl-health/nexus 2.0.15 → 2.0.16

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.
@@ -47,18 +47,20 @@ const addMsgAssistantController = async (req, res) => {
47
47
  };
48
48
 
49
49
  const createAssistantController = async (req, res) => {
50
- const { assistant_id, codes, instrucciones=[], messages=[], force=false } = req.body;
50
+ let { assistant_id, codes, instrucciones=[], messages=[], force=false } = req.body;
51
51
  if (!Array.isArray(codes) || codes.length === 0) {
52
52
  return res.status(400).send({ error: 'codes must be a non-empty array' });
53
53
  }
54
+ instrucciones = Array.isArray(instrucciones) ? instrucciones : [];
55
+ messages = Array.isArray(messages) ? messages : [];
54
56
 
55
57
  try {
56
- console.log('codes', codes);
58
+ console.log('[createAssistantController] codes', codes);
57
59
  for (const code of codes) {
58
60
  await createAssistant(code, assistant_id, [...instrucciones, ...messages], force);
59
- console.log('messages', messages);
61
+ console.log('[createAssistantController] messages', messages);
60
62
  for (const message of messages) {
61
- console.log('message', message);
63
+ console.log('[createAssistantController] message', message);
62
64
  await sendMessage({code, body: message, fileType: 'text'});
63
65
  }
64
66
  }
@@ -194,13 +194,15 @@ const createAssistant = async (code, assistant_id, messages=[], force=false) =>
194
194
  // If thread already exists, update it
195
195
  const findThread = await Thread.findOne({ code: code });
196
196
  const variant = process.env.VARIANT || 'assistants';
197
+ console.log('[createAssistant] findThread', findThread);
197
198
  if ((findThread?.conversation_id && variant === 'responses') || (findThread?.thread_id && variant === 'assistants')) {
199
+ console.log('[createAssistant] Thread already exists');
198
200
  await Thread.updateOne({ code: code }, { $set: { active: true, stopped: false, assistant_id: assistant_id } });
199
201
  return findThread;
200
202
  }
201
203
 
202
204
  const curRow = await getCurRow(Historial_Clinico_ID, code);
203
- console.log('curRow', curRow[0]);
205
+ console.log('[createAssistant] curRow', curRow[0]);
204
206
  const nombre = curRow?.[0]?.['name'] || null;
205
207
  const patientId = curRow?.[0]?.['record_id'] || null;
206
208
 
@@ -217,7 +219,7 @@ const createAssistant = async (code, assistant_id, messages=[], force=false) =>
217
219
  });
218
220
  }
219
221
 
220
- console.log('initialThread', initialThread);
222
+ console.log('[createAssistant] initialThread', initialThread);
221
223
  // Define new thread data
222
224
  const thread = {
223
225
  code: code,
@@ -233,11 +235,12 @@ const createAssistant = async (code, assistant_id, messages=[], force=false) =>
233
235
  const updateData = Object.fromEntries(
234
236
  Object.entries(thread).filter(([_, v]) => v != null)
235
237
  );
238
+ console.log('[createAssistant] updateData', updateData);
236
239
 
237
- const condition = { $or: [{ thread_id: findThread?.thread_id }, { conversation_id: findThread?.conversation_id }] };
240
+ const condition = { $or: [{ code: code }] };
238
241
  const options = { new: true, upsert: true };
239
242
  const updatedThread = await Thread.findOneAndUpdate(condition, {run_id: null, ...updateData}, options);
240
- console.log('Updated thread:', updatedThread);
243
+ console.log('[createAssistant] Updated thread:', updatedThread);
241
244
 
242
245
  // Delete previous thread
243
246
  if (force) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peopl-health/nexus",
3
- "version": "2.0.15",
3
+ "version": "2.0.16",
4
4
  "description": "Core messaging and assistant library for WhatsApp communication platforms",
5
5
  "keywords": [
6
6
  "whatsapp",