@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.
- package/dist/cjs/index.cjs +13 -5
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +2 -1
- package/dist/cjs/types/LlmProvider.interface.d.ts +2 -1
- package/dist/cjs/util/cacheControl.d.ts +10 -2
- package/dist/esm/index.d.ts +2 -1
- package/dist/esm/index.js +13 -5
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/LlmProvider.interface.d.ts +2 -1
- package/dist/esm/util/cacheControl.d.ts +10 -2
- package/package.json +1 -1
package/dist/cjs/index.d.cts
CHANGED
|
@@ -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 `"
|
|
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 `"
|
|
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
|
|
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
|
|
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
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -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 `"
|
|
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
|
|
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:
|
|
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:
|
|
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",
|