@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.
- package/dist/cjs/index.cjs +21 -6
- 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 +21 -6
- 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.cjs
CHANGED
|
@@ -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
|
|
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:
|
|
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:
|
|
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",
|
|
@@ -10648,7 +10656,14 @@ const getLogger$3 = () => log$1.log.lib({ lib: kit.JAYPIE.LIB.LLM });
|
|
|
10648
10656
|
// Client initialization
|
|
10649
10657
|
async function initializeClient$3({ apiKey, } = {}) {
|
|
10650
10658
|
const logger = getLogger$3();
|
|
10651
|
-
|
|
10659
|
+
let resolvedApiKey = apiKey || (await aws.getEnvSecret("GOOGLE_API_KEY"));
|
|
10660
|
+
if (!resolvedApiKey) {
|
|
10661
|
+
const geminiApiKey = await aws.getEnvSecret("GEMINI_API_KEY");
|
|
10662
|
+
if (geminiApiKey) {
|
|
10663
|
+
logger.warn("GEMINI_API_KEY is a deprecated fallback; set GOOGLE_API_KEY instead");
|
|
10664
|
+
resolvedApiKey = geminiApiKey;
|
|
10665
|
+
}
|
|
10666
|
+
}
|
|
10652
10667
|
if (!resolvedApiKey) {
|
|
10653
10668
|
throw new errors.ConfigurationError("The application could not resolve the requested keys");
|
|
10654
10669
|
}
|