@peopl-health/nexus 5.72.3 → 5.72.5

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.
@@ -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) {
@@ -46,6 +46,25 @@ function resolveMaxFunctionRounds(explicit) {
46
46
  return DEFAULT_MAX_FUNCTION_ROUNDS;
47
47
  }
48
48
 
49
+ const DEFAULT_REQUEST_TIMEOUT_MS = 120000;
50
+ const REQUEST_MAX_RETRIES = 0;
51
+ const STRUCTURED_TIMEOUT_BASE_MS = 30000;
52
+ const STRUCTURED_MS_PER_OUTPUT_TOKEN = 25;
53
+
54
+ function resolveRequestTimeoutMs() {
55
+ const raw = runtimeConfig.get('ANTHROPIC_TIMEOUT_MS');
56
+ const timeoutMs = parseInt(raw, 10);
57
+ if (timeoutMs > 0) return timeoutMs;
58
+ if (raw !== undefined) {
59
+ logger.warn('[AnthropicProvider] Invalid ANTHROPIC_TIMEOUT_MS, falling back to default', { value: raw, default: DEFAULT_REQUEST_TIMEOUT_MS });
60
+ }
61
+ return DEFAULT_REQUEST_TIMEOUT_MS;
62
+ }
63
+
64
+ function structuredTimeoutMs(maxTokens, requestTimeoutMs) {
65
+ return Math.max(requestTimeoutMs, STRUCTURED_TIMEOUT_BASE_MS + maxTokens * STRUCTURED_MS_PER_OUTPUT_TOKEN);
66
+ }
67
+
49
68
  // Iterations that don't count against the tool budget: terminal-only delivery rounds (exempt at the toolRounds check) plus the loop's own end/break passes. Bounds the loop against a misbehaving model.
50
69
  const LOOP_ITERATION_HEADROOM = 3;
51
70
  const CACHE_TTLS = ['5m', '1h'];
@@ -65,7 +84,8 @@ class AnthropicProvider extends BaseLLMProvider {
65
84
  throw new Error('AnthropicProvider requires an API key or a preconfigured client');
66
85
  }
67
86
 
68
- this.client = client || new Anthropic({ apiKey });
87
+ this.requestTimeoutMs = resolveRequestTimeoutMs();
88
+ this.client = client || new Anthropic({ apiKey, timeout: this.requestTimeoutMs, maxRetries: REQUEST_MAX_RETRIES });
69
89
  this.maxFunctionRounds = resolveMaxFunctionRounds(maxFunctionRounds);
70
90
  const cacheTtl = runtimeConfig.get('ANTHROPIC_CACHE_TTL', DEFAULT_CACHE_TTL);
71
91
  if (!CACHE_TTLS.includes(cacheTtl)) {
@@ -373,7 +393,7 @@ class AnthropicProvider extends BaseLLMProvider {
373
393
 
374
394
  const { result: { result }, durationMs } = await withTiming(() =>
375
395
  retryWithBackoff(
376
- () => this.client.messages.create({ messages, ...apiConfig }),
396
+ () => this.client.messages.create({ messages, ...apiConfig }, { timeout: structuredTimeoutMs(apiConfig.max_tokens, this.requestTimeoutMs) }),
377
397
  { providerName: this.constructor.name },
378
398
  )
379
399
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peopl-health/nexus",
3
- "version": "5.72.3",
3
+ "version": "5.72.5",
4
4
  "description": "Core messaging and assistant library for WhatsApp communication platforms",
5
5
  "keywords": [
6
6
  "whatsapp",