@peopl-health/nexus 2.4.7 → 2.4.9
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/examples/assistants/DoctorScheduleAssistant.js +3 -2
- package/lib/adapters/BaileysProvider.js +5 -4
- package/lib/adapters/TwilioProvider.js +20 -19
- package/lib/assistants/BaseAssistant.js +7 -6
- package/lib/config/awsConfig.js +14 -12
- package/lib/config/llmConfig.js +3 -2
- package/lib/config/mongoAuthConfig.js +5 -5
- package/lib/controllers/assistantController.js +12 -11
- package/lib/controllers/bugReportController.js +6 -5
- package/lib/controllers/conversationController.js +72 -71
- package/lib/controllers/interactionController.js +7 -6
- package/lib/controllers/mediaController.js +15 -13
- package/lib/controllers/messageController.js +7 -6
- package/lib/controllers/patientController.js +2 -1
- package/lib/controllers/qualityMessageController.js +5 -4
- package/lib/controllers/templateController.js +11 -9
- package/lib/controllers/uploadController.js +3 -1
- package/lib/core/NexusMessaging.js +18 -18
- package/lib/helpers/assistantHelper.js +8 -9
- package/lib/helpers/baileysHelper.js +4 -3
- package/lib/helpers/filesHelper.js +9 -8
- package/lib/helpers/llmsHelper.js +17 -10
- package/lib/helpers/mediaHelper.js +3 -2
- package/lib/helpers/messageHelper.js +12 -11
- package/lib/helpers/processHelper.js +2 -2
- package/lib/helpers/qrHelper.js +2 -1
- package/lib/helpers/twilioMediaProcessor.js +19 -29
- package/lib/helpers/whatsappHelper.js +3 -2
- package/lib/index.js +11 -14
- package/lib/interactive/index.js +11 -11
- package/lib/middleware/requestId.js +9 -14
- package/lib/models/messageModel.js +5 -4
- package/lib/providers/OpenAIAssistantsProvider.js +10 -9
- package/lib/providers/OpenAIResponsesProvider.js +24 -17
- package/lib/providers/OpenAIResponsesProviderTools.js +3 -5
- package/lib/providers/createProvider.js +2 -1
- package/lib/services/airtableService.js +6 -5
- package/lib/services/assistantService.js +73 -57
- package/lib/services/conversationService.js +16 -16
- package/lib/services/preprocessingHooks.js +3 -1
- package/lib/storage/MongoStorage.js +14 -14
- package/lib/utils/errorHandler.js +3 -1
- package/lib/utils/logger.js +35 -3
- package/lib/utils/mediaValidator.js +18 -14
- package/lib/utils/sanitizer.js +0 -6
- package/lib/utils/tracingDecorator.js +7 -1
- package/package.json +1 -1
|
@@ -65,23 +65,27 @@ function getMediaType(contentType) {
|
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
function validateMedia(media, contentType) {
|
|
68
|
+
const fileSize = Buffer.isBuffer(media) ? media.length : media;
|
|
69
|
+
|
|
70
|
+
if (contentType === 'image/webp') {
|
|
71
|
+
const mediaType = fileSize <= MEDIA_LIMITS.sticker ? 'sticker' : 'image';
|
|
72
|
+
const formatValidation = validateMediaFormat(contentType, mediaType);
|
|
73
|
+
if (!formatValidation.valid) return formatValidation;
|
|
74
|
+
|
|
75
|
+
const sizeValidation = validateMediaSize(media, mediaType);
|
|
76
|
+
if (!sizeValidation.valid) return sizeValidation;
|
|
77
|
+
|
|
78
|
+
return { valid: true, mediaType, message: `Media validated successfully as ${mediaType}` };
|
|
79
|
+
}
|
|
80
|
+
|
|
68
81
|
const mediaType = getMediaType(contentType);
|
|
69
82
|
const formatValidation = validateMediaFormat(contentType, mediaType);
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
return formatValidation;
|
|
73
|
-
}
|
|
74
|
-
|
|
83
|
+
if (!formatValidation.valid) return formatValidation;
|
|
84
|
+
|
|
75
85
|
const sizeValidation = validateMediaSize(media, mediaType);
|
|
76
|
-
if (!sizeValidation.valid)
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
return {
|
|
81
|
-
valid: true,
|
|
82
|
-
mediaType,
|
|
83
|
-
message: `Media validated successfully as ${mediaType}`
|
|
84
|
-
};
|
|
86
|
+
if (!sizeValidation.valid) return sizeValidation;
|
|
87
|
+
|
|
88
|
+
return { valid: true, mediaType, message: `Media validated successfully as ${mediaType}` };
|
|
85
89
|
}
|
|
86
90
|
|
|
87
91
|
module.exports = {
|
package/lib/utils/sanitizer.js
CHANGED
|
@@ -39,8 +39,6 @@ function sanitizeLogMetadata(metadata) {
|
|
|
39
39
|
delete safe.text;
|
|
40
40
|
delete safe.content;
|
|
41
41
|
delete safe.body;
|
|
42
|
-
delete safe.phone;
|
|
43
|
-
delete safe.numero;
|
|
44
42
|
|
|
45
43
|
if (safe.message_id) {
|
|
46
44
|
safe.message_id = safe.message_id.length > 8
|
|
@@ -48,10 +46,6 @@ function sanitizeLogMetadata(metadata) {
|
|
|
48
46
|
: '***';
|
|
49
47
|
}
|
|
50
48
|
|
|
51
|
-
if (safe.code && safe.code.length > 8) {
|
|
52
|
-
safe.code = `${safe.code.substring(0, 3)}***${safe.code.slice(-4)}`;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
49
|
return safe;
|
|
56
50
|
}
|
|
57
51
|
|
|
@@ -4,9 +4,10 @@ const { SpanStatusCode } = require('@opentelemetry/api');
|
|
|
4
4
|
/**
|
|
5
5
|
* Usage: const tracedFunction = withTracing(originalFunction, 'operation_name');
|
|
6
6
|
*/
|
|
7
|
-
const withTracing = (fn, spanName, attributeMapper = null) => {
|
|
7
|
+
const withTracing = (fn, spanName, attributeMapper = null, options = {}) => {
|
|
8
8
|
return async function (...args) {
|
|
9
9
|
const span = createSpan(spanName);
|
|
10
|
+
const startTime = Date.now();
|
|
10
11
|
|
|
11
12
|
try {
|
|
12
13
|
if (attributeMapper && typeof attributeMapper === 'function') {
|
|
@@ -16,6 +17,11 @@ const withTracing = (fn, spanName, attributeMapper = null) => {
|
|
|
16
17
|
const result = await fn.apply(this, args);
|
|
17
18
|
|
|
18
19
|
span.setStatus({ code: SpanStatusCode.OK });
|
|
20
|
+
|
|
21
|
+
if (options.returnTiming) {
|
|
22
|
+
const duration = Date.now() - startTime;
|
|
23
|
+
return { result, duration };
|
|
24
|
+
}
|
|
19
25
|
return result;
|
|
20
26
|
|
|
21
27
|
} catch (error) {
|