@peopl-health/nexus 3.3.0 → 3.3.1-fix
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.
- package/lib/controllers/interactionController.js +3 -3
- package/lib/controllers/qualityMessageController.js +5 -5
- package/lib/models/index.js +6 -4
- package/lib/models/interactionModel.js +3 -2
- package/lib/models/predictionMetricsModel.js +3 -2
- package/lib/models/qualityMessageModel.js +3 -2
- package/lib/services/assistantServiceCore.js +2 -2
- package/lib/storage/MongoStorage.js +0 -3
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const {
|
|
1
|
+
const { getInteraction } = require('../models/interactionModel');
|
|
2
2
|
const { Message } = require('../models/messageModel');
|
|
3
3
|
const { INTERACTION_QUALITY_VALUES } = require('../config/interactionConfig');
|
|
4
4
|
const { addRecord, getRecordByFilter } = require('../services/airtableService');
|
|
@@ -50,7 +50,7 @@ const addInteractionController = async (req, res) => {
|
|
|
50
50
|
if (!quality || !INTERACTION_QUALITY_VALUES.includes(quality)) {
|
|
51
51
|
return res.status(400).json({ success: false, error: `Quality must be one of: ${INTERACTION_QUALITY_VALUES.join(', ')}` });
|
|
52
52
|
}
|
|
53
|
-
const interaction = await
|
|
53
|
+
const interaction = await getInteraction().create({ messages, whatsapp_id, voter_username, quality, description });
|
|
54
54
|
|
|
55
55
|
logInteractionToAirtable(messages, whatsapp_id, voter_username, description).catch(err =>
|
|
56
56
|
logger.error('Background Airtable logging failed:', err)
|
|
@@ -66,7 +66,7 @@ const addInteractionController = async (req, res) => {
|
|
|
66
66
|
const getInteractionsByWhatsappIdController = async (req, res) => {
|
|
67
67
|
try {
|
|
68
68
|
const { whatsapp_id } = req.params;
|
|
69
|
-
const interactions = await
|
|
69
|
+
const interactions = await getInteraction().find({ whatsapp_id }).populate('messages').sort({ createdAt: -1 });
|
|
70
70
|
res.status(200).json({ success: true, whatsappId: whatsapp_id, count: interactions.length, interactions });
|
|
71
71
|
} catch (error) {
|
|
72
72
|
logger.error('Error fetching interactions:', error);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const {
|
|
1
|
+
const { getQualityMessage } = require('../models/qualityMessageModel');
|
|
2
2
|
const { Message } = require('../models/messageModel');
|
|
3
3
|
const { logger } = require('../utils/logger');
|
|
4
4
|
|
|
@@ -15,7 +15,7 @@ const addQualityVoteController = async (req, res) => {
|
|
|
15
15
|
const message = await Message.findById(message_id);
|
|
16
16
|
if (!message) return res.status(404).json({ success: false, error: 'Message not found' });
|
|
17
17
|
|
|
18
|
-
const qualityVote = await
|
|
18
|
+
const qualityVote = await getQualityMessage().findOneAndUpdate(
|
|
19
19
|
{ message_id, voter_username },
|
|
20
20
|
{ quality, notes, context },
|
|
21
21
|
{ upsert: true, new: true }
|
|
@@ -31,7 +31,7 @@ const addQualityVoteController = async (req, res) => {
|
|
|
31
31
|
const getQualityVotesByMessageController = async (req, res) => {
|
|
32
32
|
try {
|
|
33
33
|
const { message_id } = req.params;
|
|
34
|
-
const votes = await
|
|
34
|
+
const votes = await getQualityMessage().find({ message_id }).sort({ createdAt: -1 });
|
|
35
35
|
|
|
36
36
|
const summary = {
|
|
37
37
|
total: votes.length,
|
|
@@ -50,7 +50,7 @@ const getQualityVotesByMessageController = async (req, res) => {
|
|
|
50
50
|
const getQualityVotesByVoterController = async (req, res) => {
|
|
51
51
|
try {
|
|
52
52
|
const { voter_username } = req.params;
|
|
53
|
-
const votes = await
|
|
53
|
+
const votes = await getQualityMessage().find({ voter_username }).populate('message_id').sort({ createdAt: -1 });
|
|
54
54
|
res.status(200).json({ success: true, voterUsername: voter_username, count: votes.length, votes });
|
|
55
55
|
} catch (error) {
|
|
56
56
|
logger.error('Error fetching voter quality votes:', error);
|
|
@@ -61,7 +61,7 @@ const getQualityVotesByVoterController = async (req, res) => {
|
|
|
61
61
|
const getQualityVoteByMessageAndVoterController = async (req, res) => {
|
|
62
62
|
try {
|
|
63
63
|
const { message_id, voter_username } = req.params;
|
|
64
|
-
const vote = await
|
|
64
|
+
const vote = await getQualityMessage().findOne({ message_id, voter_username }).populate('message_id');
|
|
65
65
|
|
|
66
66
|
if (!vote) {
|
|
67
67
|
return res.status(404).json({ success: false, error: 'Vote not found' });
|
package/lib/models/index.js
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
const { Message, getMessageValues, formatTimestamp } = require('./messageModel');
|
|
2
2
|
const { Thread } = require('./threadModel');
|
|
3
|
-
const {
|
|
4
|
-
const {
|
|
3
|
+
const { getInteraction } = require('./interactionModel');
|
|
4
|
+
const { getQualityMessage } = require('./qualityMessageModel');
|
|
5
|
+
const { getPredictionMetrics } = require('./predictionMetricsModel');
|
|
5
6
|
|
|
6
7
|
module.exports = {
|
|
7
8
|
Message,
|
|
8
9
|
Thread,
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
getInteraction,
|
|
11
|
+
getQualityMessage,
|
|
12
|
+
getPredictionMetrics,
|
|
11
13
|
getMessageValues,
|
|
12
14
|
formatTimestamp
|
|
13
15
|
};
|
|
@@ -12,7 +12,8 @@ const interactionSchema = new mongoose.Schema({
|
|
|
12
12
|
enum: INTERACTION_QUALITY_VALUES,
|
|
13
13
|
required: true
|
|
14
14
|
},
|
|
15
|
-
description: { type: String, default: null }
|
|
15
|
+
description: { type: String, default: null },
|
|
16
|
+
source: { type: String, default: () => process.env.USER_DB_MONGO }
|
|
16
17
|
}, { timestamps: true });
|
|
17
18
|
|
|
18
19
|
const getInteraction = () => {
|
|
@@ -22,4 +23,4 @@ const getInteraction = () => {
|
|
|
22
23
|
return db.models.Interaction || db.model('Interaction', interactionSchema);
|
|
23
24
|
};
|
|
24
25
|
|
|
25
|
-
module.exports = { getInteraction, interactionSchema
|
|
26
|
+
module.exports = { getInteraction, interactionSchema };
|
|
@@ -11,7 +11,8 @@ const predictionMetricsSchema = new mongoose.Schema({
|
|
|
11
11
|
retry_count: { type: Number, default: 1 },
|
|
12
12
|
completed: { type: Boolean, default: true },
|
|
13
13
|
error: { type: String, default: null },
|
|
14
|
-
timing_breakdown: { type: Object, default: {} }
|
|
14
|
+
timing_breakdown: { type: Object, default: {} },
|
|
15
|
+
source: { type: String, default: () => process.env.USER_DB_MONGO }
|
|
15
16
|
}, { timestamps: true });
|
|
16
17
|
|
|
17
18
|
predictionMetricsSchema.index({ createdAt: -1 });
|
|
@@ -25,4 +26,4 @@ const getPredictionMetrics = () => {
|
|
|
25
26
|
return db.models.PredictionMetrics || db.model('PredictionMetrics', predictionMetricsSchema);
|
|
26
27
|
};
|
|
27
28
|
|
|
28
|
-
module.exports = { getPredictionMetrics, predictionMetricsSchema
|
|
29
|
+
module.exports = { getPredictionMetrics, predictionMetricsSchema };
|
|
@@ -11,7 +11,8 @@ const qualityMessageSchema = new mongoose.Schema({
|
|
|
11
11
|
required: true
|
|
12
12
|
},
|
|
13
13
|
notes: { type: String, default: null },
|
|
14
|
-
context: { type: String, default: null }
|
|
14
|
+
context: { type: String, default: null },
|
|
15
|
+
source: { type: String, default: () => process.env.USER_DB_MONGO }
|
|
15
16
|
}, { timestamps: true });
|
|
16
17
|
|
|
17
18
|
qualityMessageSchema.index({ message_id: 1, voter_username: 1 }, { unique: true });
|
|
@@ -23,4 +24,4 @@ const getQualityMessage = () => {
|
|
|
23
24
|
return db.models.QualityMessage || db.model('QualityMessage', qualityMessageSchema);
|
|
24
25
|
};
|
|
25
26
|
|
|
26
|
-
module.exports = { getQualityMessage, qualityMessageSchema
|
|
27
|
+
module.exports = { getQualityMessage, qualityMessageSchema };
|
|
@@ -3,7 +3,7 @@ const runtimeConfig = require('../config/runtimeConfig');
|
|
|
3
3
|
const { createProvider } = require('../providers/createProvider');
|
|
4
4
|
|
|
5
5
|
const { Thread } = require('../models/threadModel.js');
|
|
6
|
-
const {
|
|
6
|
+
const { getPredictionMetrics } = require('../models/predictionMetricsModel');
|
|
7
7
|
const { insertMessage } = require('../models/messageModel');
|
|
8
8
|
const { Historial_Clinico_ID } = require('../config/airtableConfig');
|
|
9
9
|
|
|
@@ -267,7 +267,7 @@ const replyAssistantCore = async (code, message_ = null, thread_ = null, runOpti
|
|
|
267
267
|
has_breakdown: !!timings.process_messages_breakdown
|
|
268
268
|
});
|
|
269
269
|
|
|
270
|
-
await
|
|
270
|
+
await getPredictionMetrics().create({
|
|
271
271
|
message_id: `${code}-${Date.now()}`,
|
|
272
272
|
numero: code,
|
|
273
273
|
assistant_id: finalThread.getAssistantId(),
|
|
@@ -2,7 +2,6 @@ const { connect: mongoConnect, disconnect: mongoDisconnect, getDb } = require('.
|
|
|
2
2
|
const runtimeConfig = require('../config/runtimeConfig');
|
|
3
3
|
|
|
4
4
|
const { Message, insertMessage } = require('../models/messageModel');
|
|
5
|
-
const { Interaction } = require('../models/interactionModel');
|
|
6
5
|
const { Thread } = require('../models/threadModel');
|
|
7
6
|
|
|
8
7
|
const { ensureWhatsAppFormat } = require('../helpers/twilioHelper');
|
|
@@ -18,7 +17,6 @@ class MongoStorage {
|
|
|
18
17
|
this.dbName = config.dbName;
|
|
19
18
|
this.collections = config.collections || {
|
|
20
19
|
messages: 'messages',
|
|
21
|
-
interactions: 'interactions',
|
|
22
20
|
threads: 'threads'
|
|
23
21
|
};
|
|
24
22
|
this.schemas = this.createSchemas();
|
|
@@ -27,7 +25,6 @@ class MongoStorage {
|
|
|
27
25
|
createSchemas() {
|
|
28
26
|
return {
|
|
29
27
|
Message,
|
|
30
|
-
Interaction,
|
|
31
28
|
Thread
|
|
32
29
|
};
|
|
33
30
|
}
|