@peopl-health/nexus 5.66.1 → 5.66.2
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.
|
@@ -10,7 +10,7 @@ const { readStructuredText } = require('../helpers/structuredTextHelper');
|
|
|
10
10
|
const { getEscalationContext } = require('../../services/escalationContextService');
|
|
11
11
|
|
|
12
12
|
const { logger } = require('../../utils/logger');
|
|
13
|
-
const { safeParse } = require('../../utils/jsonUtils');
|
|
13
|
+
const { arrayArg, safeParse } = require('../../utils/jsonUtils');
|
|
14
14
|
const { withTiming } = require('../../utils/tracingDecorator');
|
|
15
15
|
|
|
16
16
|
const { crossSymptomIssues, unproposedDrugsIn, validateProposal } = require('./treatmentProposalService');
|
|
@@ -130,9 +130,15 @@ async function generateEscalationDraft({
|
|
|
130
130
|
|
|
131
131
|
const parsed = safeParse(readStructuredText(result), null);
|
|
132
132
|
const patientMessage = trimmed(parsed?.patientMessage);
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
133
|
+
// The schema is not strict, so the model sometimes sends the list JSON-encoded as a string.
|
|
134
|
+
const blocks = parsed?.symptoms === undefined ? [parsed] : arrayArg(parsed.symptoms);
|
|
135
|
+
if (!blocks.length) {
|
|
136
|
+
const shape = parsed.symptoms;
|
|
137
|
+
logger.warn('[escalationDraft] generation returned a malformed symptom list', {
|
|
138
|
+
reviewId,
|
|
139
|
+
symptomsType: Array.isArray(shape) ? 'array' : typeof shape,
|
|
140
|
+
symptomsLength: Array.isArray(shape) || typeof shape === 'string' ? shape.length : null,
|
|
141
|
+
});
|
|
136
142
|
return { completed: false, attempted: true, reason: 'the model returned a malformed symptoms list' };
|
|
137
143
|
}
|
|
138
144
|
if (parsed?.symptoms !== undefined && blocks.some((block) => !trimmed(block?.symptom))) {
|