@peopl-health/nexus 5.71.36 → 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');
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peopl-health/nexus",
3
- "version": "5.71.36",
3
+ "version": "5.71.37",
4
4
  "description": "Core messaging and assistant library for WhatsApp communication platforms",
5
5
  "keywords": [
6
6
  "whatsapp",