@peopl-health/nexus 5.76.2 → 5.76.4

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.
@@ -8,6 +8,7 @@ const ACTIVE_DAYS = 35;
8
8
  const DEFAULT_CYTOTOXIC_WINDOW_DAYS = 42;
9
9
  const HEADER = 'Quimioterapia (registro de la unidad de quimioterapia; úsalo para contextualizar y priorizar síntomas, nunca para bajar la urgencia; no comuniques dosis ni ajustes de tratamiento; si el paciente dice algo distinto, créele: si es otra fecha de cita, que el paciente la confirme con el área de tratamiento, sin avisar al equipo; si es un dato clínico, o una sesión suspendida o cambiada por un motivo clínico, avisa al equipo)';
10
10
  const ISO_DAY = /^\d{4}-\d{2}-\d{2}$/;
11
+ const CLOCK = /^([01]\d|2[0-3]):[0-5]\d$/;
11
12
  const NO_ALLERGY = /^(ninguna?s?|no|negadas?|desconocidas?|(niega|no refiere|sin|no tiene|no presenta) alergias?( conocidas| a medicamentos)?)$/;
12
13
  const NEGATION = /\b(sin|niega|no|ninguna?)\b/;
13
14
 
@@ -131,7 +132,7 @@ function chemoLines(context, today) {
131
132
  }
132
133
  if (context.proximaSesion && context.proximaSesion.fecha >= today) {
133
134
  lines.push(context.proximaSesion.tipo === 'agendada'
134
- ? `Próxima sesión de quimioterapia: ${dmy(context.proximaSesion.fecha)} (${['agendada', confirmation(context.proximaSesion)].filter(Boolean).join('; ')})`
135
+ ? `Próxima sesión de quimioterapia: ${dmy(context.proximaSesion.fecha)}${CLOCK.test(context.proximaSesion.hora) ? ` a las ${context.proximaSesion.hora}` : ''} (${['agendada', confirmation(context.proximaSesion)].filter(Boolean).join('; ')})`
135
136
  : `Próxima sesión de quimioterapia: ${dmy(context.proximaSesion.fecha)} (estimada; no la confirmes como cita)`);
136
137
  }
137
138
  const support = context.proximaVisitaSoporte;
@@ -0,0 +1,30 @@
1
+ const TRIAGE_RESULT_MARKER = 'acaba de completar el triaje de síntomas PRO-CTCAE';
2
+
3
+ const SCALE_HEADER = 'Escala CTCAE de este síntoma. El grado de arriba es una APROXIMACIÓN calculada a partir del PRO-CTCAE, no una lectura de estas cláusulas: contrasta lo que el paciente describe contra ellas antes de darlo por confirmado. Si la evidencia sostiene otra cláusula, ese es el grado.';
4
+ const DEFINITION_PREFIX = 'Definición del síntoma - ';
5
+ const SCALE_CLAUSE_RX = /^\s+G\d:/;
6
+
7
+ const isTriageResultMessage = (body) => typeof body === 'string' && body.includes(TRIAGE_RESULT_MARKER);
8
+
9
+ const isReferenceLine = (line, next) => line === SCALE_HEADER
10
+ || (line.startsWith(DEFINITION_PREFIX) && next === SCALE_HEADER);
11
+
12
+ // Drops only fixed CTCAE reference text (the scale header leaves with its clauses); every patient-specific line stays verbatim.
13
+ function compactTriageResult(body) {
14
+ if (!isTriageResultMessage(body)) return body;
15
+ const lines = body.split('\n');
16
+ const kept = [];
17
+ let inScale = false;
18
+ let dropped = false;
19
+ lines.forEach((line, i) => {
20
+ if (inScale && SCALE_CLAUSE_RX.test(line)) { dropped = true; return; }
21
+ inScale = line === SCALE_HEADER;
22
+ if (isReferenceLine(line, lines[i + 1])) { dropped = true; return; }
23
+ const isBlank = !line.trim();
24
+ if (isBlank && kept.length && !kept[kept.length - 1].trim()) return;
25
+ kept.push(line);
26
+ });
27
+ return dropped ? kept.join('\n') : body;
28
+ }
29
+
30
+ module.exports = { TRIAGE_RESULT_MARKER, compactTriageResult, isTriageResultMessage };
@@ -1,4 +1,5 @@
1
1
  const { pairTriageSymptoms } = require('../helpers/triageSymptomsHelper');
2
+ const { compactTriageResult, isTriageResultMessage } = require('../helpers/triageResultMessageHelper');
2
3
  const { parseChemoContext, renderChemoContext, withChemoContext } = require('../helpers/chemoContextHelper');
3
4
  const { handlePendingFunctionCalls: handlePendingFunctionCallsUtil } = require('../providers/OpenAIResponsesProviderTools');
4
5
 
@@ -99,13 +100,15 @@ class DefaultMemoryManager extends MemoryManager {
99
100
 
100
101
  const skipTools = new Set(getTurnScopedToolNames());
101
102
  const replayArgs = getReplayArgsByTool();
103
+ const latestTriage = config.compactOlderTriage ? ordered.findLastIndex(msg => isTriageResultMessage(msg.body)) : -1;
102
104
 
103
105
  const context = ordered.flatMap((msg, index) => {
104
106
  const toolItems = getMessageTools(msg, { skipTools, replayArgs });
105
107
  if (index >= turnStart) return toolItems;
106
108
  const role = this._resolveContextRole(msg);
107
109
  const prefix = this._speakerPrefix(msg, role);
108
- const contentItems = formatMessage(msg)
110
+ const shown = index < latestTriage ? { ...msg, body: compactTriageResult(msg.body) } : msg;
111
+ const contentItems = formatMessage(shown)
109
112
  .filter(Boolean)
110
113
  .map(content => ({
111
114
  role,
@@ -621,6 +621,7 @@ class BaseLLMProvider {
621
621
  ...config,
622
622
  threadId: conversationId,
623
623
  assistantId,
624
+ compactOlderTriage: true,
624
625
  }
625
626
  });
626
627
 
@@ -155,11 +155,17 @@ const MODE_PROPERTY = {
155
155
 
156
156
  const MODE_DESCRIPTION = '\n\n**mode:** `new` abre un aviso; `update` actualiza la escalación abierta y nunca baja su nivel. Lo que el paciente responde después de escalar va con `update`. El `urgency_level` del recibo es el nivel aplicado: puede ser mayor que el que pediste, nunca menor.';
157
157
 
158
- const FEVER_RULE_TIMER = 'Fever within 6 weeks (42 days) of cytotoxic chemotherapy (or with a hematologic cancer, transplant, known neutropenia) — ≥38.0 °C, ≤36.0 °C, feeling feverish or chills with no thermometer, or malaise while on an antipyretic or steroid — is `asap` with `category: febrile_neutropenia`. It is `stat` only with a clear, confirmed red flag (clear shortness of breath, clear confusion, strong rigors, mottled skin, bleeding), or any fever within 4 weeks of CAR-T or during bispecific step-up dosing — say it calmly: "ve a urgencias ahora y di que estás en tratamiento oncológico" (CAR-T / bispecific: call the treating center first). If you don\'t know the treatment or the last dose date, ask in the same message. 37.5–37.9 °C in that window is `urgent`: remeasure in 30–60 min. ';
158
+ // with the timer the fever rule sends to urgencias only from `stat`, like every other case
159
+ const FEVER_SIGNS = 'Outside `stat` and the fever rule, no warning signs';
160
+ const FEVER_SIGNS_TIMER = 'Outside `stat`, no warning signs';
161
+ const FEVER_URGENCIAS = '(two exceptions: the fever rule, and chest pain';
162
+ const FEVER_URGENCIAS_TIMER = '(one exception: chest pain';
163
+
164
+ const FEVER_RULE_TIMER = 'Fever within 6 weeks (42 days) of cytotoxic chemotherapy (or with a hematologic cancer, transplant, known neutropenia) — ≥38.0 °C, feeling feverish or chills with no thermometer, malaise while on an antipyretic or steroid, or ≤36.0 °C with malaise, chills or shivering — is `asap` with `category: febrile_neutropenia`. A low reading (≤36.0 °C) on its own is not fever: ask for an oral re-measure before escalating; still ≤36.0 °C with no other symptom is `urgent`, confirmed ≤35.0 °C is `asap`. Chills or rigors, even strong, are `asap`. It is `stat` only with a very obvious, confirmed red flag (clear shortness of breath at rest, clear confusion, fainting or unable to stand, mottled or cold skin, bleeding that does not stop), or any fever within 4 weeks of CAR-T or during bispecific step-up dosing — say it calmly: "ve a urgencias ahora y di que estás en tratamiento oncológico" (CAR-T / bispecific: call the treating center first). If you don\'t know the treatment or the last dose date, ask in the same message. 37.5–37.9 °C in that window is `urgent`: remeasure in 30–60 min. ';
159
165
 
160
166
  const FEVER_RUBRIC_STAT_TIMER = 'fiebre en la ventana de quimioterapia con una bandera roja confirmada (regla de fiebre),';
161
167
 
162
- const FEVER_RUBRIC_ASAP_TIMER = 'fiebre ≥38.0 °C o ≤36.0 °C en la ventana de quimioterapia sin bandera roja (regla de fiebre),';
168
+ const FEVER_RUBRIC_ASAP_TIMER = 'fiebre ≥38.0 °C, o ≤36.0 °C con malestar o escalofríos, o ≤35.0 °C confirmado, en la ventana de quimioterapia sin bandera roja (regla de fiebre),';
163
169
 
164
170
  const CLINICAL_ASSESSMENT_PROPERTY = nullable({
165
171
  'type': 'object',
@@ -217,7 +223,7 @@ function liveDefinition() {
217
223
  properties.details.required.push('clinical_assessment');
218
224
  }
219
225
  if (feverTimer) {
220
- live.description = live.description.replace(FEVER_RULE, FEVER_RULE_TIMER);
226
+ live.description = live.description.replace(FEVER_RULE, FEVER_RULE_TIMER).replace(FEVER_SIGNS, FEVER_SIGNS_TIMER).replace(FEVER_URGENCIAS, FEVER_URGENCIAS_TIMER);
221
227
  properties.urgency_level.description = properties.urgency_level.description
222
228
  .replace(FEVER_RUBRIC_STAT, FEVER_RUBRIC_STAT_TIMER)
223
229
  .replace(FEVER_RUBRIC_ASAP, FEVER_RUBRIC_ASAP_TIMER);
@@ -106,7 +106,7 @@ class EvalProvider {
106
106
  async _buildContext(numero, beforeCheckpoint) {
107
107
  const messages = await this.memoryManager.buildContext({
108
108
  thread: { code: numero },
109
- config: { beforeCheckpoint, beforeOperator: '$lt' },
109
+ config: { beforeCheckpoint, beforeOperator: '$lt', compactOlderTriage: true },
110
110
  });
111
111
 
112
112
  const lastUserMsg = [...messages].reverse().find(m => m.role === 'user');
package/lib/index.d.ts CHANGED
@@ -565,7 +565,7 @@ declare module '@peopl-health/nexus' {
565
565
  ultimaAplicacion: { fecha: string; ciclo?: number; sesion?: number; total?: number } | null;
566
566
  esquema: Array<{ farmaco: string; via?: string; tiempo?: string }>;
567
567
  inicioEsquema: { fecha: string; anteriorAlRegistro: boolean } | null;
568
- proximaSesion: { fecha: string; tipo: string; confirmada?: boolean } | null;
568
+ proximaSesion: { fecha: string; tipo: string; confirmada?: boolean; hora?: string | null } | null;
569
569
  esquemaPrevio: { farmacos: string[]; hasta: string } | null;
570
570
  [key: string]: any;
571
571
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peopl-health/nexus",
3
- "version": "5.76.2",
3
+ "version": "5.76.4",
4
4
  "description": "Core messaging and assistant library for WhatsApp communication platforms",
5
5
  "keywords": [
6
6
  "whatsapp",