@peopl-health/nexus 5.76.3 → 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
 
@@ -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.3",
3
+ "version": "5.76.4",
4
4
  "description": "Core messaging and assistant library for WhatsApp communication platforms",
5
5
  "keywords": [
6
6
  "whatsapp",