@peopl-health/nexus 3.8.9 → 3.8.10
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.
|
@@ -2,9 +2,7 @@ const { Config_ID } = require('../config/airtableConfig');
|
|
|
2
2
|
|
|
3
3
|
const { logger } = require('../utils/logger');
|
|
4
4
|
|
|
5
|
-
const {
|
|
6
|
-
|
|
7
|
-
const { getThreadInfo } = require('../helpers/threadHelper');
|
|
5
|
+
const { getThreadInfo, switchThreadStoppedStatus } = require('../helpers/threadHelper');
|
|
8
6
|
|
|
9
7
|
const { getRecordByFilter } = require('../services/airtableService');
|
|
10
8
|
const { createAssistant, addMsgAssistant, addInsAssistant, switchAssistant } = require('../services/assistantService');
|
|
@@ -17,7 +15,9 @@ const _updateThreadFlag = async (req, res, field, successMsg, errorMsg) => {
|
|
|
17
15
|
if (!code) return res.status(400).json({ success: false, error: 'Code is required' });
|
|
18
16
|
|
|
19
17
|
try {
|
|
20
|
-
|
|
18
|
+
if (field === 'stop') {
|
|
19
|
+
await switchThreadStoppedStatus(code, !!value);
|
|
20
|
+
}
|
|
21
21
|
return res.status(200).json({ success: true, message: successMsg });
|
|
22
22
|
} catch (error) {
|
|
23
23
|
logger.error(`[AssistantController] ${errorMsg}`, { error: error.message, code });
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
const { Config_ID } = require('../config/airtableConfig.js');
|
|
1
|
+
const { Config_ID, Monitoreo_ID } = require('../config/airtableConfig.js');
|
|
2
2
|
const runtimeConfig = require('../config/runtimeConfig.js');
|
|
3
3
|
|
|
4
4
|
const { logger } = require('../utils/logger');
|
|
5
5
|
|
|
6
6
|
const { Thread } = require('../models/threadModel.js');
|
|
7
7
|
|
|
8
|
-
const { getRecordByFilter } = require('../services/airtableService.js');
|
|
8
|
+
const { getRecordByFilter, updateRecordByFilter } = require('../services/airtableService.js');
|
|
9
9
|
|
|
10
10
|
const getThread = async (code, message = null) => {
|
|
11
11
|
try {
|
|
@@ -33,6 +33,13 @@ const getThreadInfo = async (code) => {
|
|
|
33
33
|
}
|
|
34
34
|
};
|
|
35
35
|
|
|
36
|
+
const switchThreadStoppedStatus = async (code, stopped) => {
|
|
37
|
+
await Thread.updateOne({ code }, { active: true, stopped });
|
|
38
|
+
|
|
39
|
+
updateRecordByFilter(Monitoreo_ID, 'message_monitor', `{whatsapp_id} = "${code}"`, { stopped })
|
|
40
|
+
.catch(err => logger.error('[switchThreadStoppedStatus] Failed to update message_monitor', { code, error: err.message }));
|
|
41
|
+
};
|
|
42
|
+
|
|
36
43
|
const createPlaceholderThread = async (code) => {
|
|
37
44
|
try {
|
|
38
45
|
const existing = await Thread.findOne({ code });
|
|
@@ -43,8 +50,9 @@ const createPlaceholderThread = async (code) => {
|
|
|
43
50
|
const record = await getRecordByFilter(Config_ID, 'responses', `AND({code}="PIPO_ASST", {status}="${assistantStatus}")`, undefined, ['prompt_id']);
|
|
44
51
|
const prompt_id = record?.[0]?.['prompt_id'] || null;
|
|
45
52
|
|
|
46
|
-
const thread = new Thread({ code, assistant_id: null, prompt_id, conversation_id: null
|
|
53
|
+
const thread = new Thread({ code, assistant_id: null, prompt_id, conversation_id: null });
|
|
47
54
|
await thread.save();
|
|
55
|
+
await switchThreadStoppedStatus(code, true);
|
|
48
56
|
logger.info('[createPlaceholderThread] Created', { code, prompt_id });
|
|
49
57
|
|
|
50
58
|
if (prompt_id) {
|
|
@@ -71,5 +79,6 @@ module.exports = {
|
|
|
71
79
|
getThread,
|
|
72
80
|
getThreadInfo,
|
|
73
81
|
createPlaceholderThread,
|
|
74
|
-
ensureThreadExists
|
|
82
|
+
ensureThreadExists,
|
|
83
|
+
switchThreadStoppedStatus
|
|
75
84
|
};
|
|
@@ -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 } = require('../helpers/threadHelper.js');
|
|
14
|
+
const { getThread, switchThreadStoppedStatus } = 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');
|
|
@@ -25,8 +25,9 @@ const createAssistantCore = async (code, assistant_id, _messages = [], force = f
|
|
|
25
25
|
|
|
26
26
|
if (findThread && findThread.getConversationId() && !force) {
|
|
27
27
|
logger.info('[createAssistant] Thread already exists');
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
await switchThreadStoppedStatus(code, false);
|
|
29
|
+
const updateFields = {};
|
|
30
|
+
Thread.setAssistantId(updateFields, assistant_id);
|
|
30
31
|
await Thread.updateOne({ code: code }, { $set: updateFields });
|
|
31
32
|
return { success: true, assistant_id, thread: findThread };
|
|
32
33
|
}
|
|
@@ -336,9 +337,9 @@ const switchAssistantCore = async (code, assistant_id) => {
|
|
|
336
337
|
}
|
|
337
338
|
|
|
338
339
|
const updateFields = {
|
|
339
|
-
stopped: false,
|
|
340
340
|
updatedAt: new Date()
|
|
341
341
|
};
|
|
342
|
+
await switchThreadStoppedStatus(code, false);
|
|
342
343
|
Thread.setAssistantId(updateFields, assistant_id);
|
|
343
344
|
|
|
344
345
|
await Thread.updateOne({ code }, { $set: updateFields });
|