@peopl-health/nexus 5.72.3 → 5.72.4

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.
@@ -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.4",
4
4
  "description": "Core messaging and assistant library for WhatsApp communication platforms",
5
5
  "keywords": [
6
6
  "whatsapp",