@peopl-health/nexus 5.71.4 → 5.71.5
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.
|
@@ -19,11 +19,13 @@ const CONVERSATION_TURNS = 40;
|
|
|
19
19
|
const TRIAGE_LIMIT = 3;
|
|
20
20
|
const CALL_LOG_LIMIT = 10;
|
|
21
21
|
|
|
22
|
+
const TECHNICAL_TOKEN = /\b(urgentIfPositive|blocksDrug|null)\b|\b[a-z]+_\w+|\\n/i;
|
|
23
|
+
|
|
22
24
|
const trimmed = (value) => String(value ?? '').trim();
|
|
23
25
|
|
|
24
26
|
function withholdReason(sections) {
|
|
25
27
|
const { present } = flagsByStatus(sections);
|
|
26
|
-
const modifiers = (Array.isArray(sections?.treatmentModifiers) ? sections.treatmentModifiers : []).map(trimmed).filter(Boolean);
|
|
28
|
+
const modifiers = (Array.isArray(sections?.treatmentModifiers) ? sections.treatmentModifiers : []).map((modifier) => trimmed(modifier).replace(/_/g, ' ')).filter(Boolean);
|
|
27
29
|
const reasons = [];
|
|
28
30
|
if (present.length) reasons.push(present.length === 1 ? 'hay una bandera roja presente' : 'hay banderas rojas presentes');
|
|
29
31
|
if (modifiers.length) reasons.push(`condición que cambia el algoritmo (${modifiers.join(', ')})`);
|
|
@@ -172,16 +174,20 @@ async function generateEscalationDraft({
|
|
|
172
174
|
return { completed: false, attempted: true, reason: `the treatment proposal broke the formulary rules: ${issues.join('; ')}` };
|
|
173
175
|
}
|
|
174
176
|
|
|
175
|
-
const
|
|
176
|
-
alarm: alarms[alarms.length - 1] ?? null,
|
|
177
|
+
const draft = {
|
|
177
178
|
shared: parsed,
|
|
178
179
|
symptoms: settled.map(({ block, proposal, withheldReason, conduct }) => ({ sections: block, proposal, withheldReason, conduct })),
|
|
179
|
-
}
|
|
180
|
+
};
|
|
181
|
+
const doctorText = composeDoctorBody({ ...draft, alarm: alarms[alarms.length - 1] ?? null });
|
|
180
182
|
|
|
181
183
|
if (!doctorText || !patientMessage) {
|
|
182
184
|
logger.warn('[escalationDraft] generation returned no usable text', { reviewId });
|
|
183
185
|
return { completed: false, attempted: true, reason: 'the model returned no usable text' };
|
|
184
186
|
}
|
|
187
|
+
if (TECHNICAL_TOKEN.test(`${composeDoctorBody({ ...draft, alarm: null })}\n${patientMessage}`)) {
|
|
188
|
+
logger.warn('[escalationDraft] generation leaked a technical token into the text', { reviewId });
|
|
189
|
+
return { completed: false, attempted: true, reason: 'the model wrote a field name or technical token into the doctor or patient text' };
|
|
190
|
+
}
|
|
185
191
|
|
|
186
192
|
return {
|
|
187
193
|
completed: true,
|