@jaypie/llm 1.3.17 → 1.3.19

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.
@@ -669,7 +669,8 @@ interface LlmExchangeEnvelope {
669
669
  type LlmExchangeCallback = (envelope: LlmExchangeEnvelope) => unknown | Promise<unknown>;
670
670
  /**
671
671
  * Prompt-caching control for operate()/stream().
672
- * - `true` / omitted → caching enabled at the default `"5m"` TTL
672
+ * - `true` / omitted → caching enabled at the adapter's default TTL: `"1h"` on
673
+ * Anthropic, `"5m"` everywhere else
673
674
  * - `false` / `0` → caching disabled
674
675
  * - `"5m"` / `"1h"` → enabled at that TTL (TTL honored by Anthropic/OpenRouter;
675
676
  * other providers ignore it and cache with their own defaults)
@@ -290,7 +290,8 @@ export interface LlmExchangeEnvelope {
290
290
  export type LlmExchangeCallback = (envelope: LlmExchangeEnvelope) => unknown | Promise<unknown>;
291
291
  /**
292
292
  * Prompt-caching control for operate()/stream().
293
- * - `true` / omitted → caching enabled at the default `"5m"` TTL
293
+ * - `true` / omitted → caching enabled at the adapter's default TTL: `"1h"` on
294
+ * Anthropic, `"5m"` everywhere else
294
295
  * - `false` / `0` → caching disabled
295
296
  * - `"5m"` / `"1h"` → enabled at that TTL (TTL honored by Anthropic/OpenRouter;
296
297
  * other providers ignore it and cache with their own defaults)
@@ -1,5 +1,11 @@
1
1
  import { type LlmCache } from "../types/LlmProvider.interface.js";
2
2
  export declare const CACHE_TTL_DEFAULT: "5m";
3
+ /**
4
+ * Anthropic bills a 1h cache write at 2x input (vs 1.25x for 5m) but reads at
5
+ * the same ~0.1x, so an hour of reuse pays for itself after ~three reads and
6
+ * survives the gaps between turns in a long agentic session.
7
+ */
8
+ export declare const CACHE_TTL_ANTHROPIC_DEFAULT: "1h";
3
9
  export type CacheTtl = "5m" | "1h";
4
10
  export interface ResolvedCache {
5
11
  enabled: boolean;
@@ -7,11 +13,13 @@ export interface ResolvedCache {
7
13
  }
8
14
  /**
9
15
  * Normalize the caller-facing `cache` option into a concrete decision.
10
- * - `undefined` / `true` → enabled at the default TTL
16
+ * - `undefined` / `true` → enabled at `defaultTtl`
11
17
  * - `false` / `0` → disabled
12
18
  * - `"5m"` / `"1h"` → enabled at that TTL
13
19
  */
14
- export declare function resolveCache(cache: LlmCache | undefined): ResolvedCache;
20
+ export declare function resolveCache(cache: LlmCache | undefined, { defaultTtl }?: {
21
+ defaultTtl?: CacheTtl;
22
+ }): ResolvedCache;
15
23
  /**
16
24
  * Deterministic short key for providers with automatic, prefix-based caching
17
25
  * (e.g. OpenAI `prompt_cache_key`). Derived from the stable prefix so the same
@@ -669,7 +669,8 @@ interface LlmExchangeEnvelope {
669
669
  type LlmExchangeCallback = (envelope: LlmExchangeEnvelope) => unknown | Promise<unknown>;
670
670
  /**
671
671
  * Prompt-caching control for operate()/stream().
672
- * - `true` / omitted → caching enabled at the default `"5m"` TTL
672
+ * - `true` / omitted → caching enabled at the adapter's default TTL: `"1h"` on
673
+ * Anthropic, `"5m"` everywhere else
673
674
  * - `false` / `0` → caching disabled
674
675
  * - `"5m"` / `"1h"` → enabled at that TTL (TTL honored by Anthropic/OpenRouter;
675
676
  * other providers ignore it and cache with their own defaults)
package/dist/esm/index.js CHANGED
@@ -791,21 +791,27 @@ function buildExchangeEnvelope({ duration, initialHistoryLength, input, options,
791
791
  }
792
792
 
793
793
  const CACHE_TTL_DEFAULT = "5m";
794
+ /**
795
+ * Anthropic bills a 1h cache write at 2x input (vs 1.25x for 5m) but reads at
796
+ * the same ~0.1x, so an hour of reuse pays for itself after ~three reads and
797
+ * survives the gaps between turns in a long agentic session.
798
+ */
799
+ const CACHE_TTL_ANTHROPIC_DEFAULT = "1h";
794
800
  /**
795
801
  * Normalize the caller-facing `cache` option into a concrete decision.
796
- * - `undefined` / `true` → enabled at the default TTL
802
+ * - `undefined` / `true` → enabled at `defaultTtl`
797
803
  * - `false` / `0` → disabled
798
804
  * - `"5m"` / `"1h"` → enabled at that TTL
799
805
  */
800
- function resolveCache(cache) {
806
+ function resolveCache(cache, { defaultTtl = CACHE_TTL_DEFAULT } = {}) {
801
807
  if (cache === false || cache === 0) {
802
- return { enabled: false, ttl: CACHE_TTL_DEFAULT };
808
+ return { enabled: false, ttl: defaultTtl };
803
809
  }
804
810
  if (cache === "5m" || cache === "1h") {
805
811
  return { enabled: true, ttl: cache };
806
812
  }
807
813
  // undefined or true
808
- return { enabled: true, ttl: CACHE_TTL_DEFAULT };
814
+ return { enabled: true, ttl: defaultTtl };
809
815
  }
810
816
  /**
811
817
  * Deterministic short key for providers with automatic, prefix-based caching
@@ -2617,7 +2623,9 @@ class AnthropicAdapter extends BaseProviderAdapter {
2617
2623
  PROVIDER.ANTHROPIC.MAX_TOKENS.DEFAULT,
2618
2624
  stream: false,
2619
2625
  };
2620
- const cache = resolveCache(request.cache);
2626
+ const cache = resolveCache(request.cache, {
2627
+ defaultTtl: CACHE_TTL_ANTHROPIC_DEFAULT,
2628
+ });
2621
2629
  const cacheControl = cache.enabled
2622
2630
  ? {
2623
2631
  type: "ephemeral",
@@ -10645,7 +10653,14 @@ const getLogger$3 = () => log$2.lib({ lib: JAYPIE.LIB.LLM });
10645
10653
  // Client initialization
10646
10654
  async function initializeClient$3({ apiKey, } = {}) {
10647
10655
  const logger = getLogger$3();
10648
- const resolvedApiKey = apiKey || (await getEnvSecret("GEMINI_API_KEY"));
10656
+ let resolvedApiKey = apiKey || (await getEnvSecret("GOOGLE_API_KEY"));
10657
+ if (!resolvedApiKey) {
10658
+ const geminiApiKey = await getEnvSecret("GEMINI_API_KEY");
10659
+ if (geminiApiKey) {
10660
+ logger.warn("GEMINI_API_KEY is a deprecated fallback; set GOOGLE_API_KEY instead");
10661
+ resolvedApiKey = geminiApiKey;
10662
+ }
10663
+ }
10649
10664
  if (!resolvedApiKey) {
10650
10665
  throw new ConfigurationError("The application could not resolve the requested keys");
10651
10666
  }