@peopl-health/nexus 2.4.12 → 2.4.13
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.
|
@@ -117,10 +117,8 @@ const getConversationMessagesController = async (req, res) => {
|
|
|
117
117
|
}
|
|
118
118
|
}
|
|
119
119
|
|
|
120
|
-
logger.info('Fetching conversation messages
|
|
121
|
-
logger.info('
|
|
122
|
-
|
|
123
|
-
logger.info('About to execute Message.find with query:', JSON.stringify(query));
|
|
120
|
+
logger.info('Fetching conversation messages', { query, limit });
|
|
121
|
+
logger.info('Executing Message.find', { query });
|
|
124
122
|
let messages = [];
|
|
125
123
|
|
|
126
124
|
try {
|
|
@@ -242,7 +240,7 @@ const getConversationReplyController = async (req, res) => {
|
|
|
242
240
|
messageData.contentSid = contentSid;
|
|
243
241
|
|
|
244
242
|
if (variables && Object.keys(variables).length > 0) {
|
|
245
|
-
logger.info('Template variables
|
|
243
|
+
logger.info('Template variables', { variables });
|
|
246
244
|
messageData.variables = variables;
|
|
247
245
|
}
|
|
248
246
|
|
|
@@ -275,7 +273,7 @@ const getConversationReplyController = async (req, res) => {
|
|
|
275
273
|
messageData.body = message;
|
|
276
274
|
}
|
|
277
275
|
|
|
278
|
-
logger.info('Sending message
|
|
276
|
+
logger.info('Sending message', { messageData });
|
|
279
277
|
await sendMessage(messageData);
|
|
280
278
|
logger.info('Message sent successfully');
|
|
281
279
|
|
|
@@ -285,7 +283,7 @@ const getConversationReplyController = async (req, res) => {
|
|
|
285
283
|
});
|
|
286
284
|
} catch (error) {
|
|
287
285
|
logger.error('Error sending reply:', error);
|
|
288
|
-
logger.info('Request body
|
|
286
|
+
logger.info('Request body', { body: req.body || {} });
|
|
289
287
|
const errorMsg = error.message || 'Failed to send reply';
|
|
290
288
|
logger.error('Responding with error:', errorMsg);
|
|
291
289
|
res.status(500).json({
|
|
@@ -615,7 +613,7 @@ const sendTemplateToNewNumberController = async (req, res) => {
|
|
|
615
613
|
|
|
616
614
|
if (variables && Object.keys(variables).length > 0) {
|
|
617
615
|
messageData.variables = variables;
|
|
618
|
-
logger.info('Template variables
|
|
616
|
+
logger.info('Template variables', { variables });
|
|
619
617
|
}
|
|
620
618
|
|
|
621
619
|
const message = await sendMessage(messageData);
|
|
@@ -71,7 +71,7 @@ async function analyzeImage(imagePath, isSticker = false, contentType = null) {
|
|
|
71
71
|
|
|
72
72
|
// Description of the image (for both stickers and regular images)
|
|
73
73
|
const imageDescription = 'Describe the image in detail.';
|
|
74
|
-
const
|
|
74
|
+
const descriptionPromise = anthropicClient.messages.create({
|
|
75
75
|
model: 'claude-sonnet-4-5',
|
|
76
76
|
max_tokens: 1024,
|
|
77
77
|
messages: [
|
|
@@ -94,11 +94,13 @@ async function analyzeImage(imagePath, isSticker = false, contentType = null) {
|
|
|
94
94
|
},
|
|
95
95
|
],
|
|
96
96
|
});
|
|
97
|
-
logger.info('[analyzeImage] Description received');
|
|
98
|
-
const description = messageDescription.content[0].text;
|
|
99
97
|
|
|
100
98
|
// For stickers, skip medical analysis and table extraction
|
|
101
99
|
if (isSticker) {
|
|
100
|
+
const messageDescription = await descriptionPromise;
|
|
101
|
+
const description = messageDescription.content[0].text;
|
|
102
|
+
logger.info('[analyzeImage] Description received (sticker)');
|
|
103
|
+
|
|
102
104
|
return {
|
|
103
105
|
description: description,
|
|
104
106
|
medical_analysis: 'NOT_MEDICAL',
|
|
@@ -108,7 +110,9 @@ async function analyzeImage(imagePath, isSticker = false, contentType = null) {
|
|
|
108
110
|
};
|
|
109
111
|
}
|
|
110
112
|
|
|
111
|
-
//
|
|
113
|
+
// Run all analysis calls in parallel
|
|
114
|
+
logger.info('[analyzeImage] Starting parallel analysis calls');
|
|
115
|
+
|
|
112
116
|
const tablePrompt = `Please analyze this image and respond in the following format:
|
|
113
117
|
1. First, determine if there is a table in the image.
|
|
114
118
|
2. If there is NO table, respond with exactly "NONE"
|
|
@@ -126,32 +130,6 @@ async function analyzeImage(imagePath, isSticker = false, contentType = null) {
|
|
|
126
130
|
|
|
127
131
|
Only extract tables - ignore any other content in the image.`;
|
|
128
132
|
|
|
129
|
-
// Create the message with the image
|
|
130
|
-
const messageTable = await anthropicClient.messages.create({
|
|
131
|
-
model: 'claude-3-7-sonnet-20250219',
|
|
132
|
-
max_tokens: 1024,
|
|
133
|
-
messages: [
|
|
134
|
-
{
|
|
135
|
-
role: 'user',
|
|
136
|
-
content: [
|
|
137
|
-
{
|
|
138
|
-
type: 'image',
|
|
139
|
-
source: {
|
|
140
|
-
type: 'base64',
|
|
141
|
-
media_type: mimeType,
|
|
142
|
-
data: base64Image,
|
|
143
|
-
},
|
|
144
|
-
},
|
|
145
|
-
{
|
|
146
|
-
type: 'text',
|
|
147
|
-
text: tablePrompt,
|
|
148
|
-
},
|
|
149
|
-
],
|
|
150
|
-
},
|
|
151
|
-
],
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
// Create a more specific prompt for table detection and extraction
|
|
155
133
|
const medImagePrompt = `
|
|
156
134
|
Eres un oncólogo clínico con experiencia. Se te proporcionará una imagen médica o laboratorio. Analízala y responde exactamente en este formato:
|
|
157
135
|
|
|
@@ -193,59 +171,48 @@ Ejemplo 1:
|
|
|
193
171
|
</EJEMPLOS>
|
|
194
172
|
`;
|
|
195
173
|
|
|
196
|
-
// Create the message with the image
|
|
197
|
-
const messageMedImage = await anthropicClient.messages.create({
|
|
198
|
-
model: 'claude-3-7-sonnet-20250219',
|
|
199
|
-
max_tokens: 1024,
|
|
200
|
-
messages: [
|
|
201
|
-
{
|
|
202
|
-
role: 'user',
|
|
203
|
-
content: [
|
|
204
|
-
{
|
|
205
|
-
type: 'image',
|
|
206
|
-
source: {
|
|
207
|
-
type: 'base64',
|
|
208
|
-
media_type: mimeType,
|
|
209
|
-
data: base64Image,
|
|
210
|
-
},
|
|
211
|
-
},
|
|
212
|
-
{
|
|
213
|
-
type: 'text',
|
|
214
|
-
text: medImagePrompt,
|
|
215
|
-
},
|
|
216
|
-
],
|
|
217
|
-
},
|
|
218
|
-
],
|
|
219
|
-
});
|
|
220
|
-
|
|
221
174
|
const relevancePrompt = `Please analyze this image and respond in this format:
|
|
222
175
|
Medical Relevance: [YES/NO]`;
|
|
223
176
|
|
|
224
|
-
//
|
|
225
|
-
const messageRelevance = await
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
177
|
+
// Execute all 4 API calls in parallel
|
|
178
|
+
const [messageDescription, messageTable, messageMedImage, messageRelevance] = await Promise.all([
|
|
179
|
+
descriptionPromise,
|
|
180
|
+
anthropicClient.messages.create({
|
|
181
|
+
model: 'claude-3-7-sonnet-20250219',
|
|
182
|
+
max_tokens: 1024,
|
|
183
|
+
messages: [{
|
|
230
184
|
role: 'user',
|
|
231
185
|
content: [
|
|
232
|
-
{
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
},
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
186
|
+
{ type: 'image', source: { type: 'base64', media_type: mimeType, data: base64Image } },
|
|
187
|
+
{ type: 'text', text: tablePrompt }
|
|
188
|
+
]
|
|
189
|
+
}]
|
|
190
|
+
}),
|
|
191
|
+
anthropicClient.messages.create({
|
|
192
|
+
model: 'claude-3-7-sonnet-20250219',
|
|
193
|
+
max_tokens: 1024,
|
|
194
|
+
messages: [{
|
|
195
|
+
role: 'user',
|
|
196
|
+
content: [
|
|
197
|
+
{ type: 'image', source: { type: 'base64', media_type: mimeType, data: base64Image } },
|
|
198
|
+
{ type: 'text', text: medImagePrompt }
|
|
199
|
+
]
|
|
200
|
+
}]
|
|
201
|
+
}),
|
|
202
|
+
anthropicClient.messages.create({
|
|
203
|
+
model: 'claude-3-7-sonnet-20250219',
|
|
204
|
+
max_tokens: 1024,
|
|
205
|
+
messages: [{
|
|
206
|
+
role: 'user',
|
|
207
|
+
content: [
|
|
208
|
+
{ type: 'image', source: { type: 'base64', media_type: mimeType, data: base64Image } },
|
|
209
|
+
{ type: 'text', text: relevancePrompt }
|
|
210
|
+
]
|
|
211
|
+
}]
|
|
212
|
+
})
|
|
213
|
+
]);
|
|
248
214
|
|
|
215
|
+
const description = messageDescription.content[0].text;
|
|
249
216
|
const messageTableStr = messageTable.content[0].text;
|
|
250
217
|
const messageRelevanceStr = messageRelevance.content[0].text;
|
|
251
218
|
const messageAnalysisStr = messageMedImage.content[0].text;
|
|
@@ -135,8 +135,8 @@ const fetchConversationData = async (filter, skip, limit) => {
|
|
|
135
135
|
}
|
|
136
136
|
return map;
|
|
137
137
|
}, {}) || {};
|
|
138
|
-
logger.info('
|
|
139
|
-
logger.info('
|
|
138
|
+
logger.info('Unread map calculated', { unreadMap });
|
|
139
|
+
logger.info('Conversations found', { count: conversations?.length || 0 });
|
|
140
140
|
|
|
141
141
|
// Calculate total count for pagination
|
|
142
142
|
let totalFilterConditions = { is_group: false };
|