@peopl-health/nexus 5.71.35 → 5.71.37
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.
|
@@ -45,6 +45,12 @@ const deliveryOutcome = (result) => {
|
|
|
45
45
|
return 'unknown';
|
|
46
46
|
};
|
|
47
47
|
|
|
48
|
+
const NO_ASSISTANT = 'no_assistant';
|
|
49
|
+
|
|
50
|
+
// The model call is built from the preset or the prompt id; with neither the provider rejects it
|
|
51
|
+
// (`prompt.id` null). These threads are human-run (onboarding, office contacts) and ops is alerted upstream.
|
|
52
|
+
const hasPromptSource = (thread) => Boolean(thread?.preset_id || thread?.getAssistantId?.() || thread?.prompt_id);
|
|
53
|
+
|
|
48
54
|
class AssistantProcessor {
|
|
49
55
|
constructor({ mode = 'local', queueAdapter = null, sendMessage = null, phiProcessor = null, storeRunMetrics = null, llmMonitor = null, toolRuntimeRepos = {} }) {
|
|
50
56
|
Object.assign(this, { mode, queueAdapter, sendMessage, phiProcessor, storeRunMetrics, llmMonitor, toolRuntimeRepos });
|
|
@@ -64,6 +70,8 @@ class AssistantProcessor {
|
|
|
64
70
|
}
|
|
65
71
|
|
|
66
72
|
async executeLLM(thread, assistant, runOptions = {}, message = null) {
|
|
73
|
+
if (!hasPromptSource(thread)) return this._skipUnassignedTurn(thread, runOptions, message);
|
|
74
|
+
|
|
67
75
|
// Proactive outreach is not shadowed: the fork carries turnKind but not the outreach brief, so
|
|
68
76
|
// the shadow would answer a different question than production and any comparison would be an
|
|
69
77
|
// artefact of the missing block.
|
|
@@ -298,6 +306,42 @@ class AssistantProcessor {
|
|
|
298
306
|
};
|
|
299
307
|
}
|
|
300
308
|
|
|
309
|
+
async _skipUnassignedTurn(thread, runOptions, message) {
|
|
310
|
+
logger.info('[AssistantProcessor] thread has no preset or prompt; skipping the model call', {
|
|
311
|
+
code: thread?.code, turnId: runOptions.runId || null,
|
|
312
|
+
});
|
|
313
|
+
let ctx = runOptions.toolRuntimeContext || null;
|
|
314
|
+
if (!ctx && !runOptions.shadow && runOptions.runId && thread?.code) {
|
|
315
|
+
try {
|
|
316
|
+
ctx = new ToolRuntimeContext({
|
|
317
|
+
patientCode: thread.code,
|
|
318
|
+
turnId: runOptions.runId,
|
|
319
|
+
shouldContinue: runOptions.shouldContinue,
|
|
320
|
+
repos: this.toolRuntimeRepos,
|
|
321
|
+
shadow: false,
|
|
322
|
+
...resolveTurnContext({ turnKind: runOptions.turnKind, message }),
|
|
323
|
+
});
|
|
324
|
+
} catch (error) {
|
|
325
|
+
logger.warn('[AssistantProcessor] skipped turn will run untraced', { code: thread.code, error: error.message });
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
try {
|
|
329
|
+
await ctx?.storeSkipped?.(NO_ASSISTANT);
|
|
330
|
+
} catch (error) {
|
|
331
|
+
logger.warn('[AssistantProcessor] skipped turn left no trace', { turnId: runOptions.runId, error: error.message });
|
|
332
|
+
}
|
|
333
|
+
return {
|
|
334
|
+
output: null,
|
|
335
|
+
tools_executed: [],
|
|
336
|
+
turnId: runOptions.runId || null,
|
|
337
|
+
traceId: ctx?.trace?._id ? String(ctx.trace._id) : null,
|
|
338
|
+
completed: false,
|
|
339
|
+
skipped: NO_ASSISTANT,
|
|
340
|
+
retries: 0,
|
|
341
|
+
predictionTimeMs: 0,
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
|
|
301
345
|
async process({ code, runOptions = {}, message = null }) {
|
|
302
346
|
if (!code) throw new Error('code is required for assistant processing');
|
|
303
347
|
|
|
@@ -127,6 +127,11 @@ class ToolRuntimeContext {
|
|
|
127
127
|
await this.trace.save();
|
|
128
128
|
}
|
|
129
129
|
|
|
130
|
+
async storeSkipped(reason) {
|
|
131
|
+
this.trace.setStatus('skipped', { reason });
|
|
132
|
+
await this.trace.save();
|
|
133
|
+
}
|
|
134
|
+
|
|
130
135
|
setSafetyArtifact(artifact) {
|
|
131
136
|
this.safetyArtifact = this._requireArtifact('safetyArtifact', artifact);
|
|
132
137
|
}
|
|
@@ -1058,6 +1058,9 @@ class NexusMessaging {
|
|
|
1058
1058
|
if (!runResult) {
|
|
1059
1059
|
return { decision: 'skipped', rationale: '', holdReason: 'turn_not_run', nextCheckAt: null, delivered: false, turnId: null, traceId: null };
|
|
1060
1060
|
}
|
|
1061
|
+
if (runResult.skipped) {
|
|
1062
|
+
return { decision: 'skipped', rationale: '', holdReason: runResult.skipped, nextCheckAt: null, delivered: false, turnId: runResult.turnId || null, traceId: runResult.traceId || null };
|
|
1063
|
+
}
|
|
1061
1064
|
|
|
1062
1065
|
const decision = runResult.signals?.outreachDecision || null;
|
|
1063
1066
|
if (!decision) throw new Error('OUTREACH_DECISION_MISSING');
|
|
@@ -3,12 +3,17 @@ const { Config_ID } = require('../../config/airtableConfig');
|
|
|
3
3
|
const { getRecordByFilter } = require('../../services/airtableService');
|
|
4
4
|
|
|
5
5
|
const { safeParse, safeParseArray } = require('../../utils/jsonUtils');
|
|
6
|
+
const { logger } = require('../../utils/logger');
|
|
6
7
|
|
|
7
8
|
const FHIR_CONFIG_TABLE = 'fhir';
|
|
9
|
+
// Every stored resource key, extension url and code system is built on these. They are identity, not
|
|
10
|
+
// configuration: an edited base would fork the corpus into duplicates and orphan every stored extension.
|
|
11
|
+
const BASES = {
|
|
12
|
+
IDENT_BASE: 'https://peopl.health/fhir/identifier',
|
|
13
|
+
EXT_BASE: 'https://peopl.health/fhir/StructureDefinition',
|
|
14
|
+
CODESYSTEM_BASE: 'https://peopl.health/fhir/CodeSystem',
|
|
15
|
+
};
|
|
8
16
|
const REQUIRED_KEYS = [
|
|
9
|
-
'IDENT_BASE',
|
|
10
|
-
'EXT_BASE',
|
|
11
|
-
'CODESYSTEM_BASE',
|
|
12
17
|
'SYSTEMS',
|
|
13
18
|
'SUSPECTED_GRADE_DISPLAYS',
|
|
14
19
|
'QUESTIONNAIRE_CANONICAL_URL',
|
|
@@ -18,9 +23,6 @@ const REQUIRED_KEYS = [
|
|
|
18
23
|
];
|
|
19
24
|
|
|
20
25
|
const state = {
|
|
21
|
-
identBase: null,
|
|
22
|
-
extBase: null,
|
|
23
|
-
codesystemBase: null,
|
|
24
26
|
systems: null,
|
|
25
27
|
suspectedGradeDisplays: null,
|
|
26
28
|
questionnaireCanonicalUrl: null,
|
|
@@ -43,9 +45,11 @@ async function initialize() {
|
|
|
43
45
|
const suspectedGradeDisplays = safeParseArray(byKey.SUSPECTED_GRADE_DISPLAYS, null);
|
|
44
46
|
if (!suspectedGradeDisplays) throw new Error('fhir config SUSPECTED_GRADE_DISPLAYS is not a JSON array');
|
|
45
47
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
48
|
+
for (const [key, value] of Object.entries(BASES)) {
|
|
49
|
+
if (byKey[key] && byKey[key] !== value) {
|
|
50
|
+
logger.error('[fhirConfig] Config base value ignored: FHIR identity bases are fixed in code', { key, configured: byKey[key], used: value });
|
|
51
|
+
}
|
|
52
|
+
}
|
|
49
53
|
state.systems = systems;
|
|
50
54
|
state.suspectedGradeDisplays = suspectedGradeDisplays;
|
|
51
55
|
state.questionnaireCanonicalUrl = byKey.QUESTIONNAIRE_CANONICAL_URL;
|
|
@@ -60,9 +64,9 @@ function assertLoaded() {
|
|
|
60
64
|
|
|
61
65
|
module.exports = {
|
|
62
66
|
initialize,
|
|
63
|
-
getIdentBase: () =>
|
|
64
|
-
getExtBase: () =>
|
|
65
|
-
getCodesystemBase: () =>
|
|
67
|
+
getIdentBase: () => BASES.IDENT_BASE,
|
|
68
|
+
getExtBase: () => BASES.EXT_BASE,
|
|
69
|
+
getCodesystemBase: () => BASES.CODESYSTEM_BASE,
|
|
66
70
|
getSystems: () => { assertLoaded(); return state.systems; },
|
|
67
71
|
getSuspectedGradeDisplays: () => { assertLoaded(); return state.suspectedGradeDisplays; },
|
|
68
72
|
getQuestionnaireCanonicalUrl: () => { assertLoaded(); return state.questionnaireCanonicalUrl; },
|
package/lib/index.d.ts
CHANGED
|
@@ -1399,6 +1399,8 @@ declare module '@peopl-health/nexus' {
|
|
|
1399
1399
|
predictionTimeMs?: number;
|
|
1400
1400
|
retries?: number;
|
|
1401
1401
|
completed?: boolean;
|
|
1402
|
+
/** Set when the turn never reached the model, e.g. a thread with no preset or prompt. */
|
|
1403
|
+
skipped?: 'no_assistant';
|
|
1402
1404
|
/** Internal delivery ownership receipt; never contains the directive body. */
|
|
1403
1405
|
deliveryDirective?: { operationId: string; claimed: boolean; settled: boolean };
|
|
1404
1406
|
}
|