@peopl-health/nexus 6.0.21 → 6.0.22

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.
@@ -5,6 +5,7 @@ const { getSupportLightEvaluator } = require('../config/subAgentsConfig');
5
5
  const { getSupportLightSweepModel } = require('../models/supportLightModel');
6
6
  const { readStructuredText } = require('../helpers/structuredTextHelper');
7
7
  const { getMessages, aggregateMessages } = require('../../services/messageService');
8
+ const { INTERNAL_ORIGINS } = require('../../models/messageModel');
8
9
  const { safeParse } = require('../../utils/jsonUtils');
9
10
  const { logger } = require('../../utils/logger');
10
11
  const { LIGHT_SCALE } = require('./supportInvitability');
@@ -23,7 +24,7 @@ const CLAIM_MINUTES = 15;
23
24
  const SETTLED_OUTCOMES = ['evaluated', 'no_messages'];
24
25
  const MAX_REASON_CHARS = 500;
25
26
  const MAX_EVIDENCE = 5;
26
- const INTERNAL_ORIGINS = ['system', 'instruction'];
27
+ const HIDDEN_ORIGINS = [...INTERNAL_ORIGINS];
27
28
  const UNDELIVERED_STATUSES = ['failed', 'undelivered'];
28
29
  const DUPLICATE_KEY_ERROR = 11000;
29
30
  const MINUTE_MS = 60 * 1000;
@@ -56,7 +57,7 @@ async function readRecentMessages(patientId, { now, windowDays, readMessages })
56
57
  const query = {
57
58
  numero: patientId,
58
59
  createdAt: { $gte: new Date(now.getTime() - windowDays * DAY_MS) },
59
- origin: { $nin: INTERNAL_ORIGINS },
60
+ origin: { $nin: HIDDEN_ORIGINS },
60
61
  'statusInfo.status': { $nin: UNDELIVERED_STATUSES },
61
62
  body: { $regex: '\\S' },
62
63
  };
@@ -113,7 +114,7 @@ async function patientsToEvaluate({
113
114
  const selected = [];
114
115
  for (let page = 0; selected.length < limit && page < MAX_CANDIDATE_PAGES; page += 1) {
115
116
  const active = await aggregateMessages([
116
- { $match: { from_me: false, createdAt: { $gte: activeSince }, numero, origin: { $nin: INTERNAL_ORIGINS }, body: { $regex: '\\S' } } },
117
+ { $match: { from_me: false, createdAt: { $gte: activeSince }, numero, origin: { $nin: HIDDEN_ORIGINS }, body: { $regex: '\\S' } } },
117
118
  { $group: { _id: '$numero', lastInboundAt: { $max: '$createdAt' } } },
118
119
  { $sort: { lastInboundAt: -1, _id: 1 } },
119
120
  { $skip: page * CANDIDATE_PAGE },
@@ -2,6 +2,7 @@ const { oneLineOf } = require('../utils/coercionUtils');
2
2
  const { logger } = require('../utils/logger');
3
3
  const { redactDirectIdentifiers } = require('../utils/sanitizerUtils');
4
4
  const { getEscalationReview } = require('../models/escalationReviewModel');
5
+ const { INTERNAL_ORIGINS } = require('../models/messageModel');
5
6
  const { isWithin24HourWindow } = require('../helpers/conversationWindowHelper');
6
7
  const { readGroupMessageId } = require('../clinical/services/clinicalAirtableService');
7
8
 
@@ -254,7 +255,7 @@ async function skipGraveAlerts(review, clock, now) {
254
255
  // The last message the patient saw: the quiet reminder itself and a send that never arrived are no question of the bot's.
255
256
  async function lastChatMessage(code) {
256
257
  const [last] = await getMessages({
257
- numero: code, origin: { $nin: ['system', 'instruction'] }, body: { $ne: QUIET_REMINDER_TEXT }, 'statusInfo.status': { $nin: UNDELIVERED_STATUSES },
258
+ numero: code, origin: { $nin: [...INTERNAL_ORIGINS] }, body: { $ne: QUIET_REMINDER_TEXT }, 'statusInfo.status': { $nin: UNDELIVERED_STATUSES },
258
259
  }, { sort: { createdAt: -1 }, limit: 1, select: 'from_me body' });
259
260
  return last;
260
261
  }
@@ -7,6 +7,7 @@ const { escapeRegExp } = require('../utils/textMatchUtils');
7
7
  const { logger } = require('../utils/logger');
8
8
  const { PATIENT_CODE, redactDirectIdentifiers } = require('../utils/sanitizerUtils');
9
9
  const { OfficeReadMarker } = require('../models/officeReadMarkerModel');
10
+ const { INTERNAL_ORIGINS } = require('../models/messageModel');
10
11
  const { escapeFormulaValue, fieldEquals } = require('../helpers/airtableFormulaHelper');
11
12
  const { isWithin24HourWindow } = require('../helpers/conversationWindowHelper');
12
13
  const { prepareMessageMedia } = require('../helpers/mediaHelper');
@@ -18,7 +19,7 @@ const { aggregateMessages, getMessages } = require('./messageService');
18
19
  const { getPatientInformation } = require('./patientService');
19
20
 
20
21
  const PATIENT_FIELDS = ['whatsapp_id', 'name', 'doctor'];
21
- const HIDDEN_ORIGINS = ['system', 'instruction'];
22
+ const HIDDEN_ORIGINS = [...INTERNAL_ORIGINS];
22
23
  const DEFAULT_MESSAGE_LIMIT = 30;
23
24
  const MAX_MESSAGE_LIMIT = 50;
24
25
  const MAX_TEXT_LENGTH = 1500;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peopl-health/nexus",
3
- "version": "6.0.21",
3
+ "version": "6.0.22",
4
4
  "description": "Core messaging and assistant library for WhatsApp communication platforms",
5
5
  "keywords": [
6
6
  "whatsapp",