@peopl-health/nexus 5.56.2 → 5.56.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 { 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 =>
|
package/lib/eval/EvalProvider.js
CHANGED
|
@@ -36,7 +36,7 @@ class EvalProvider {
|
|
|
36
36
|
this.memoryManager = config.memoryManager || (
|
|
37
37
|
config.memoryStrategy === 'enhanced' ? new EnhancedMemoryManager() : new DefaultMemoryManager()
|
|
38
38
|
);
|
|
39
|
-
const variant = (config.variant || '
|
|
39
|
+
const variant = (config.variant || 'gateway').toString().toLowerCase();
|
|
40
40
|
this.provider = createLLMProvider({
|
|
41
41
|
variant,
|
|
42
42
|
defaultModels: { responseModel: this.model },
|
|
@@ -47,6 +47,11 @@ class EvalProvider {
|
|
|
47
47
|
encode: config.phi?.encode || false,
|
|
48
48
|
ner: config.phi?.ner || null,
|
|
49
49
|
});
|
|
50
|
+
this.configModelConfig = {
|
|
51
|
+
...(config.model ? { model: config.model } : {}),
|
|
52
|
+
...(config.temperature != null ? { temperature: config.temperature } : {}),
|
|
53
|
+
...(config.maxOutputTokens != null ? { max_output_tokens: config.maxOutputTokens } : {}),
|
|
54
|
+
};
|
|
50
55
|
}
|
|
51
56
|
|
|
52
57
|
id() {
|
|
@@ -69,12 +74,15 @@ class EvalProvider {
|
|
|
69
74
|
|
|
70
75
|
const { messages, promptVariables, lastUserMessage, contextSource } = await this._buildContext(numero, beforeCheckpoint);
|
|
71
76
|
|
|
72
|
-
const {
|
|
77
|
+
const {
|
|
78
|
+
devContent, assistant, toolSchemas, resolvedPromptId, presetModelConfig, resolvedPresetId,
|
|
79
|
+
} = await this._resolvePrompt(prompt, assistantId, thread, promptVariables);
|
|
73
80
|
|
|
74
81
|
const request = this._buildRequest({
|
|
75
82
|
devContent, messages, promptVariables, toolSchemas, assistant,
|
|
76
83
|
assistantId: resolvedPromptId || assistantId,
|
|
77
|
-
presetId:
|
|
84
|
+
presetId: resolvedPresetId,
|
|
85
|
+
presetModelConfig,
|
|
78
86
|
});
|
|
79
87
|
|
|
80
88
|
const startTime = Date.now();
|
|
@@ -126,11 +134,15 @@ class EvalProvider {
|
|
|
126
134
|
let devContent;
|
|
127
135
|
let resolvedPromptId = assistantId;
|
|
128
136
|
let presetToolIds = null;
|
|
137
|
+
let presetModelConfig = null;
|
|
138
|
+
let resolvedPresetId = this.presetId || thread?.preset_id || null;
|
|
129
139
|
|
|
130
|
-
const presetId =
|
|
140
|
+
const presetId = resolvedPresetId;
|
|
131
141
|
|
|
132
142
|
if (this.promptSource === 'airtable' && (presetId || assistantId)) {
|
|
133
|
-
const {
|
|
143
|
+
const {
|
|
144
|
+
resolvedPrompt, promptId, presetToolIds: toolIds, modelConfig, presetId: composedPresetId,
|
|
145
|
+
} = await composePrompt({
|
|
134
146
|
presetId,
|
|
135
147
|
promptId: assistantId,
|
|
136
148
|
variables: promptVariables,
|
|
@@ -138,6 +150,8 @@ class EvalProvider {
|
|
|
138
150
|
devContent = resolvedPrompt;
|
|
139
151
|
resolvedPromptId = promptId || assistantId;
|
|
140
152
|
presetToolIds = toolIds;
|
|
153
|
+
presetModelConfig = modelConfig || null;
|
|
154
|
+
resolvedPresetId = composedPresetId || resolvedPresetId;
|
|
141
155
|
} else {
|
|
142
156
|
devContent = fallbackPrompt;
|
|
143
157
|
devContent = devContent.replace(/\{\{(\w+)\}\}/g, (_, key) => promptVariables[key] ?? '');
|
|
@@ -176,10 +190,21 @@ class EvalProvider {
|
|
|
176
190
|
}
|
|
177
191
|
}
|
|
178
192
|
|
|
179
|
-
return { devContent, assistant, toolSchemas, resolvedPromptId };
|
|
193
|
+
return { devContent, assistant, toolSchemas, resolvedPromptId, presetModelConfig, resolvedPresetId };
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
_modelConfig(presetModelConfig) {
|
|
197
|
+
const base = presetModelConfig
|
|
198
|
+
|| { temperature: this.temperature, max_output_tokens: this.maxOutputTokens };
|
|
199
|
+
const merged = { model: this.model, ...base, ...this.configModelConfig };
|
|
200
|
+
if (typeof merged.model !== 'string' || !merged.model.trim()) merged.model = this.model;
|
|
201
|
+
return merged;
|
|
180
202
|
}
|
|
181
203
|
|
|
182
|
-
_buildRequest({
|
|
204
|
+
_buildRequest({
|
|
205
|
+
devContent, messages, promptVariables, toolSchemas, assistant, assistantId, presetId,
|
|
206
|
+
presetModelConfig = null,
|
|
207
|
+
}) {
|
|
183
208
|
const convertedMessages = this.provider._convertItemsToApiFormat(messages);
|
|
184
209
|
|
|
185
210
|
const memoryParts = [];
|
|
@@ -199,9 +224,7 @@ class EvalProvider {
|
|
|
199
224
|
input,
|
|
200
225
|
toolSchemas: isContextOnly ? [] : toolSchemas,
|
|
201
226
|
toolChoice: isContextOnly ? 'none' : this.toolChoice,
|
|
202
|
-
modelConfig: shouldUsePromptRegistry
|
|
203
|
-
? {}
|
|
204
|
-
: { model: this.model, temperature: this.temperature, max_output_tokens: this.maxOutputTokens },
|
|
227
|
+
modelConfig: shouldUsePromptRegistry ? {} : this._modelConfig(presetModelConfig),
|
|
205
228
|
assistant: isContextOnly ? null : assistant,
|
|
206
229
|
phiProcessor: this.phiProcessor,
|
|
207
230
|
promptVariables,
|