@jaypie/llm 1.3.17 → 1.3.18

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.
@@ -794,21 +794,27 @@ function buildExchangeEnvelope({ duration, initialHistoryLength, input, options,
794
794
  }
795
795
 
796
796
  const CACHE_TTL_DEFAULT = "5m";
797
+ /**
798
+ * Anthropic bills a 1h cache write at 2x input (vs 1.25x for 5m) but reads at
799
+ * the same ~0.1x, so an hour of reuse pays for itself after ~three reads and
800
+ * survives the gaps between turns in a long agentic session.
801
+ */
802
+ const CACHE_TTL_ANTHROPIC_DEFAULT = "1h";
797
803
  /**
798
804
  * Normalize the caller-facing `cache` option into a concrete decision.
799
- * - `undefined` / `true` → enabled at the default TTL
805
+ * - `undefined` / `true` → enabled at `defaultTtl`
800
806
  * - `false` / `0` → disabled
801
807
  * - `"5m"` / `"1h"` → enabled at that TTL
802
808
  */
803
- function resolveCache(cache) {
809
+ function resolveCache(cache, { defaultTtl = CACHE_TTL_DEFAULT } = {}) {
804
810
  if (cache === false || cache === 0) {
805
- return { enabled: false, ttl: CACHE_TTL_DEFAULT };
811
+ return { enabled: false, ttl: defaultTtl };
806
812
  }
807
813
  if (cache === "5m" || cache === "1h") {
808
814
  return { enabled: true, ttl: cache };
809
815
  }
810
816
  // undefined or true
811
- return { enabled: true, ttl: CACHE_TTL_DEFAULT };
817
+ return { enabled: true, ttl: defaultTtl };
812
818
  }
813
819
  /**
814
820
  * Deterministic short key for providers with automatic, prefix-based caching
@@ -2620,7 +2626,9 @@ class AnthropicAdapter extends BaseProviderAdapter {
2620
2626
  PROVIDER.ANTHROPIC.MAX_TOKENS.DEFAULT,
2621
2627
  stream: false,
2622
2628
  };
2623
- const cache = resolveCache(request.cache);
2629
+ const cache = resolveCache(request.cache, {
2630
+ defaultTtl: CACHE_TTL_ANTHROPIC_DEFAULT,
2631
+ });
2624
2632
  const cacheControl = cache.enabled
2625
2633
  ? {
2626
2634
  type: "ephemeral",