@peopl-health/nexus 6.0.0-dev.683 → 6.0.0-dev.702

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,12 +8,15 @@ const { runClinicalAgent } = require('./clinicalAgentService');
8
8
 
9
9
  async function runDivergence({ request, connection, trace, actualMessage }) {
10
10
  let post;
11
+ const startedAt = Date.now();
11
12
  try {
12
13
  post = await runClinicalAgent(request, connection);
14
+ logger.debug('[divergence] oracle responded', { runId: request.runId, status: post.status, durationMs: Date.now() - startedAt });
13
15
  if (post.status !== 200) {
14
16
  return { ok: false, status: post.status, response: post.body };
15
17
  }
16
18
  } catch (error) {
19
+ logger.debug('[divergence] oracle errored', { runId: request.runId, error: error.message, durationMs: Date.now() - startedAt });
17
20
  return { ok: false, status: 503, response: { error: error.message } };
18
21
  }
19
22
  const expected = post.body?.run?.sessions?.[0]?.turns?.[0] || {};
@@ -30,12 +33,22 @@ async function runDivergence({ request, connection, trace, actualMessage }) {
30
33
  }
31
34
 
32
35
  async function diverge({ shadow, runId }) {
36
+ const code = shadow?.context?.patientCode;
33
37
  const inputs = shadow?.context?.divergenceInputs;
34
- if (!inputs) return null;
35
- if (!shadow.result?.completed) return null;
38
+ if (!inputs) {
39
+ logger.debug('[divergence] skip: no inputs', { runId, code });
40
+ return null;
41
+ }
42
+ if (!shadow.result?.completed) {
43
+ logger.debug('[divergence] skip: shadow incomplete', { runId, code });
44
+ return null;
45
+ }
36
46
 
37
47
  const { enabled, baseUrl, timeoutMs } = await divergenceConfig.getOracleConnection();
38
- if (!enabled || !baseUrl) return null;
48
+ if (!enabled || !baseUrl) {
49
+ logger.debug('[divergence] skip: oracle off', { runId, code });
50
+ return null;
51
+ }
39
52
 
40
53
  const request = {
41
54
  runId,
@@ -45,6 +58,7 @@ async function diverge({ shadow, runId }) {
45
58
  enabledTools: inputs.toolIds || [],
46
59
  additionalInstructions: inputs.additionalInstructions || null,
47
60
  };
61
+ logger.debug('[divergence] oracle request', { runId, code, model: request.model, inputLen: request.input.length, tools: request.enabledTools.length });
48
62
 
49
63
  const connection = {
50
64
  baseUrl,
@@ -57,8 +71,10 @@ async function diverge({ shadow, runId }) {
57
71
  });
58
72
 
59
73
  if (report.ok) {
74
+ logger.debug('[divergence] classified', { runId, code, result: report.result, emergency: !!report.isEmergencyReview });
60
75
  try {
61
76
  await getDivergenceModel().record({ shadow, request, report });
77
+ logger.debug('[divergence] persisted', { runId, code });
62
78
  } catch (error) {
63
79
  logger.warn('[divergence] persist failed', { runId, error: error.message });
64
80
  }
@@ -15,10 +15,14 @@ async function runShadowTurn({
15
15
  resolveAssistant,
16
16
  executeLLM,
17
17
  }) {
18
- if (!shouldContinue()) return null;
18
+ if (!shouldContinue()) {
19
+ logger.debug('[shadow] superseded pre-run', { code: thread?.code, runId });
20
+ return null;
21
+ }
19
22
  if (!runId) throw new Error('runShadowTurn requires a runId');
20
23
 
21
24
  const code = thread.code;
25
+ logger.debug('[shadow] start', { code, runId, sessionId });
22
26
  const shadowThread = cloneShadowThread(thread);
23
27
  const shadowAssistant = resolveAssistant(shadowThread);
24
28
 
@@ -28,9 +32,11 @@ async function runShadowTurn({
28
32
  toolRuntimeContext: context, shadow: true, shouldContinue, additionalInstructions,
29
33
  };
30
34
 
35
+ const startedAt = Date.now();
31
36
  const result = await runInShadowScope(() =>
32
37
  executeLLM(shadowThread, shadowAssistant, runOptions, message),
33
38
  );
39
+ logger.debug('[shadow] done', { code, runId, completed: !!result?.completed, steps: context.trace?.steps?.length || 0, durationMs: Date.now() - startedAt });
34
40
 
35
41
  return { turnId: runId, context, result };
36
42
  }
@@ -40,7 +46,10 @@ function forkShadowTurn({
40
46
  }) {
41
47
  Promise.resolve()
42
48
  .then(() => {
43
- if (!isShadowEnabled()) return null;
49
+ if (!isShadowEnabled()) {
50
+ logger.debug('[shadow] disabled', { code: thread?.code });
51
+ return null;
52
+ }
44
53
  return runShadowTurn({
45
54
  thread,
46
55
  message,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peopl-health/nexus",
3
- "version": "6.0.0-dev.683",
3
+ "version": "6.0.0-dev.702",
4
4
  "description": "Core messaging and assistant library for WhatsApp communication platforms",
5
5
  "keywords": [
6
6
  "whatsapp",