@peopl-health/nexus 5.72.4 → 5.72.6

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.
@@ -1,4 +1,5 @@
1
1
  const { createLLMProvider } = require('../providers/createLLMProvider');
2
+ const { REQUEST_MAX_RETRIES, resolveRequestTimeoutMs } = require('../providers/AnthropicProvider');
2
3
  const runtimeConfig = require('../../config/runtimeConfig');
3
4
 
4
5
  const { logger } = require('../../utils/logger');
@@ -50,7 +51,7 @@ const getAnthropicClient = () => {
50
51
  if (!apiKey) return null;
51
52
  try {
52
53
  const { Anthropic } = require('@anthropic-ai/sdk');
53
- state.anthropicClient = new Anthropic({ apiKey });
54
+ state.anthropicClient = new Anthropic({ apiKey, timeout: resolveRequestTimeoutMs(), maxRetries: REQUEST_MAX_RETRIES });
54
55
  logger.info('[llmConfig] Anthropic client initialised');
55
56
  } catch (error) {
56
57
  logger.warn('[llmConfig] Failed to initialise Anthropic client', { error: error?.message });
@@ -2,6 +2,7 @@ const fs = require('fs');
2
2
  const path = require('path');
3
3
 
4
4
  const llmConfig = require('../config/llmConfig.js');
5
+ const { resolveRequestTimeoutMs, structuredTimeoutMs } = require('../providers/AnthropicProvider');
5
6
 
6
7
  const { composePrompt } = require('../services/promptComposerService');
7
8
 
@@ -30,6 +31,7 @@ const DISPLAYED_NUMBER = /^-?\d+(?:[.,]\d+)?$/;
30
31
 
31
32
  const ANALYSIS_MODEL = 'claude-sonnet-5';
32
33
  const MAX_ANALYSIS_TOKENS = 4096;
34
+ const IMAGE_MAX_RETRIES = 1;
33
35
 
34
36
  const ANALYSIS_PROMPT = `Eres un oncólogo clínico con experiencia. Recibirás una imagen que un paciente envió por WhatsApp. Puede ser una receta, un resultado de laboratorio, un estudio de imagen, una nota clínica, la pantalla de un aparato de medición casero, la caja de un medicamento, o algo sin relación médica.
35
37
 
@@ -199,7 +201,7 @@ async function analyzeImage(imagePath, isSticker = false, contentType = null) {
199
201
  { type: 'image', source: { type: 'base64', media_type: mimeType, data: base64Image } },
200
202
  { type: 'text', text: prompt }
201
203
  ]}]
202
- });
204
+ }, { timeout: structuredTimeoutMs(maxTokens, resolveRequestTimeoutMs()), maxRetries: IMAGE_MAX_RETRIES });
203
205
 
204
206
  if (isSticker) {
205
207
  const result = await createImageMessage('Describe the image in detail.', ANALYSIS_MODEL, MAX_ANALYSIS_TOKENS);
@@ -105,8 +105,11 @@ const CHANGE_ES = {
105
105
  unchanged: 'sigue igual',
106
106
  worsened: 'empeoró',
107
107
  mixed: 'mixto',
108
+ absent: 'no tuvo el síntoma',
108
109
  };
109
110
 
111
+ const ABSENT_CHANGE_RX = /^absent_(.+)_cluster$/;
112
+
110
113
  const GRADE_BASIS_ES = {
111
114
  composite: 'la tabla compuesta del PRO-CTCAE resolvió el grado con las respuestas de arriba',
112
115
  presence: 'sólo se preguntó si el síntoma estaba presente; el grado no sale de una escala de severidad',
@@ -294,7 +297,13 @@ function buildAdherenceBlock(priorResolutions = []) {
294
297
 
295
298
  function buildSymptomChangeBlock(symptomsChange = []) {
296
299
  if (!symptomsChange.length) return 'Sin cambio de síntomas reportado.';
297
- return symptomsChange.map((entry) => `- ${entry}`).join('\n');
300
+ return symptomsChange
301
+ .map((entry) => {
302
+ const absent = ABSENT_CHANGE_RX.exec(entry);
303
+ if (!absent) return `- ${entry}`;
304
+ return `- ${entry} → el paciente marcó «Nunca tuve este síntoma» para "${absent[1]}". Si este triaje le da grado a ese síntoma, la respuesta se contradice y vale el grado`;
305
+ })
306
+ .join('\n');
298
307
  }
299
308
 
300
309
  function buildSymptomSignalsBlock(symptomSignals) {
@@ -627,4 +627,7 @@ class AnthropicProvider extends BaseLLMProvider {
627
627
 
628
628
  module.exports = {
629
629
  AnthropicProvider,
630
+ REQUEST_MAX_RETRIES,
631
+ resolveRequestTimeoutMs,
632
+ structuredTimeoutMs,
630
633
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peopl-health/nexus",
3
- "version": "5.72.4",
3
+ "version": "5.72.6",
4
4
  "description": "Core messaging and assistant library for WhatsApp communication platforms",
5
5
  "keywords": [
6
6
  "whatsapp",