@peopl-health/nexus 5.57.0-dev.8711 → 5.57.0-dev.8733
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 { overlayCohortPreset } = require('./helpers/cohortHelper');
|
|
|
8
8
|
const { forkShadowTurn } = require('./services/shadowService');
|
|
9
9
|
const { diverge } = require('./services/divergenceService');
|
|
10
10
|
const { getAssistantById } = require('./services/assistantResolver');
|
|
11
|
+
const { coverIfUnassigned } = require('./services/pausedSafetyNetService');
|
|
11
12
|
const { maybeSendBridge, clearBridgeState } = require('./services/bridgeService');
|
|
12
13
|
const { cancelContingencies, snapshotContingencies } = require('./services/contingencyDispatchService');
|
|
13
14
|
const { readPendingFollowUpsForPatient, cancelPendingFollowUps } = require('./services/clinicalAirtableService');
|
|
@@ -297,6 +298,7 @@ class AssistantProcessor {
|
|
|
297
298
|
async _executeLocal({ code, runOptions = {}, message = null }) {
|
|
298
299
|
const resolved = await this.resolveThread(code);
|
|
299
300
|
if (!resolved) return null;
|
|
301
|
+
if (runOptions.patientTurn === true) await coverIfUnassigned({ code, thread: resolved.thread });
|
|
300
302
|
|
|
301
303
|
const result = await this.executeLLM(resolved.thread, resolved.assistant, runOptions, message);
|
|
302
304
|
await this._storeMetricsOrDiscard(code, resolved.thread, result);
|
|
@@ -156,6 +156,17 @@ async function unansweredText(code) {
|
|
|
156
156
|
return written ? written.plainBody || written.body : null;
|
|
157
157
|
}
|
|
158
158
|
|
|
159
|
+
const assistantNamedOn = (thread) => Boolean(thread?.getAssistantId?.() || thread?.assistant_id);
|
|
160
|
+
|
|
161
|
+
async function coverIfUnassigned({ code, thread }) {
|
|
162
|
+
if (!code || assistantNamedOn(thread)) return;
|
|
163
|
+
try {
|
|
164
|
+
await coverUnansweredPatient({ code, reason: UNASSIGNED });
|
|
165
|
+
} catch (error) {
|
|
166
|
+
logger.warn('[PausedSafetyNet] Could not cover an unassigned patient', { code, error: error.message });
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
159
170
|
async function coverUnansweredPatient({ code, reason = PAUSED }) {
|
|
160
171
|
if (!code) return;
|
|
161
172
|
|
|
@@ -305,6 +316,7 @@ function registerSafetyNetRoutes() {
|
|
|
305
316
|
module.exports = {
|
|
306
317
|
alertOpsForClaimedMessage,
|
|
307
318
|
coverUnansweredPatient,
|
|
319
|
+
coverIfUnassigned,
|
|
308
320
|
disarmSafetyNet,
|
|
309
321
|
offerSafetyNet,
|
|
310
322
|
PAUSED,
|
|
@@ -31,7 +31,7 @@ const { releaseHeldMessages, sweepHeldMessages } = require('../services/heldMess
|
|
|
31
31
|
const { BatchingManager } = require('../core/BatchingManager');
|
|
32
32
|
const { ProcessingPipeline } = require('../core/ProcessingPipeline');
|
|
33
33
|
const { preProcessMessages, configureOpenAIProvider, AssistantProcessor, TURN_KIND } = require('../clinical');
|
|
34
|
-
const { UNASSIGNED, alertOpsForClaimedMessage, coverUnansweredPatient } = require('../clinical/services/pausedSafetyNetService');
|
|
34
|
+
const { UNASSIGNED, alertOpsForClaimedMessage, coverIfUnassigned, coverUnansweredPatient } = require('../clinical/services/pausedSafetyNetService');
|
|
35
35
|
const { buildOutreachCarrier } = require('../clinical/services/outreachCarrierService');
|
|
36
36
|
const { routineOutreachCollisionReason } = require('../clinical/services/outreachSweepService');
|
|
37
37
|
const {
|
|
@@ -655,7 +655,7 @@ class NexusMessaging {
|
|
|
655
655
|
if (this.batchingManager.isDraining()) return { deferred: true, reason: 'draining' };
|
|
656
656
|
|
|
657
657
|
try {
|
|
658
|
-
const result = await this._processMessages(from, () => this.assistantProcessor.process({ code: from }));
|
|
658
|
+
const result = await this._processMessages(from, () => this.assistantProcessor.process({ code: from, runOptions: { patientTurn: true } }));
|
|
659
659
|
await this.assistantProcessor.sendResponse(from, result);
|
|
660
660
|
} catch (error) {
|
|
661
661
|
logger.error('Error in handleMessageWithAssistant', { error: error.message });
|
|
@@ -668,7 +668,7 @@ class NexusMessaging {
|
|
|
668
668
|
if (this.batchingManager.isDraining()) return { deferred: true, reason: 'draining' };
|
|
669
669
|
|
|
670
670
|
try {
|
|
671
|
-
const result = await this._processMessages(from, () => this.assistantProcessor.process({ code: from }));
|
|
671
|
+
const result = await this._processMessages(from, () => this.assistantProcessor.process({ code: from, runOptions: { patientTurn: true } }));
|
|
672
672
|
await this.assistantProcessor.sendResponse(from, result);
|
|
673
673
|
} catch (error) {
|
|
674
674
|
logger.error('Error in handleMediaWithAssistant', { error: error.message });
|
|
@@ -739,6 +739,8 @@ class NexusMessaging {
|
|
|
739
739
|
return null;
|
|
740
740
|
}
|
|
741
741
|
|
|
742
|
+
await coverIfUnassigned({ code: chatId, thread: resolved.thread });
|
|
743
|
+
|
|
742
744
|
const preProcessed = await preProcessMessages(chatId, null, resolved.thread);
|
|
743
745
|
|
|
744
746
|
await Promise.all((preProcessed.pendingMediaUpdates ?? []).map(u =>
|