johns-harness 2026.10.20 → 2026.10.21
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/CHANGELOG.md +8 -0
- package/dist/auth-profiles-5CHn7vq1.js +7 -5
- package/dist/compact-B247y5Qt.js +5 -3
- package/dist/config-koj5M_EO.js +7 -5
- package/dist/daemon-cli.js +7 -5
- package/dist/model-selection-BGlGpPgM.js +7 -5
- package/dist/model-selection-BU6wl1le.js +7 -5
- package/dist/model-selection-L7RMwsG-.js +7 -5
- package/dist/pi-embedded-C6ITuRXf.js +5 -3
- package/dist/pi-embedded-DoQsYfIY.js +5 -3
- package/dist/plugin-sdk/config-4Fgm-yEH.js +7 -5
- package/dist/plugin-sdk/config-Di-lyCdh.js +7 -5
- package/dist/plugin-sdk/discord.js +7 -5
- package/dist/plugin-sdk/dispatch-BP0viZiL.js +5 -3
- package/dist/plugin-sdk/dispatch-CQsjmw7g.js +5 -3
- package/dist/plugin-sdk/dispatch-Cerq29sy.js +5 -3
- package/dist/plugin-sdk/dispatch-Cndjtt0g.js +5 -3
- package/dist/plugin-sdk/dispatch-UogiJYul.js +5 -3
- package/dist/plugin-sdk/model-auth-CX9cPHdC.js +7 -5
- package/dist/plugin-sdk/model-auth-Ciehz0x5.js +7 -5
- package/dist/plugin-sdk/model-auth-DVyo6JSX.js +7 -5
- package/dist/plugin-sdk/model-auth-kiHYHGrs.js +7 -5
- package/dist/plugin-sdk/model-selection-Dbj4jDYM.js +7 -5
- package/dist/plugin-sdk/reply-DbZnH8-h.js +5 -3
- package/dist/reply-C5LKjXcC.js +5 -3
- package/docs/PATCHES.md +46 -0
- package/docs/concepts/session-pruning.md +1 -1
- package/docs/providers/anthropic.md +7 -4
- package/node_modules/@mariozechner/pi-ai/dist/providers/anthropic.js +24 -12
- package/package.json +1 -1
- package/vendor/patched-deps/@mariozechner/pi-ai/dist/providers/anthropic.js +24 -12
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 2026.10.21
|
|
4
|
+
|
|
5
|
+
- **One-hour prompt caching is the Anthropic default**, for both API keys and Claude subscriptions, including models with no params configured. This avoids rewriting a large cached prompt after gaps longer than five minutes. Explicit `none`, `short`, `long` and legacy `cacheControlTtl` settings still win; Bedrock behavior is unchanged.
|
|
6
|
+
- **The wire request matches the policy:** the adapter sends `cache_control: { type: "ephemeral", ttl: "1h" }` on the existing Anthropic cache breakpoints and adds the extended-cache beta on both auth paths, even with custom beta headers. Stable system content stays cached, changing memory stays outside that breakpoint, and subscription attribution and plan-limit routing are preserved.
|
|
7
|
+
- **Live proof, after gaps over six minutes:** API cache read/write went from 0/31,332 to 31,332/61; subscription from 0/31,407 to 31,407/61. Both subscription responses returned `anthropic-ratelimit-unified-5h-status: allowed`, with Extra usage still disabled. All cache writes were one-hour writes.
|
|
8
|
+
- **Validation:** 36 new Family 90 tests cover all ten runtime and fourteen config copies, actual adapter SSE requests for both auth modes, explicit/legacy settings, empty params, header merging and replay safety. Verifier 564/564; full suite 1,249 pass and 5 existing skips. Clean 2026.10.20 replay matches all 25 changed runtime/adapter files byte for byte.
|
|
9
|
+
- **Rollback:** `npm i -g johns-harness@2026.10.20`.
|
|
10
|
+
|
|
3
11
|
## 2026.10.20
|
|
4
12
|
|
|
5
13
|
- **A subscription login takes effect on the very next turn.** After `/login claude` or `/login chatgpt` (chat or CLI), the matching subscription serves the next turn of every existing session with no `johnness secrets reload`, no `/new` and no restart. Root cause: the gateway serves turns from an in-memory auth snapshot taken at start, and a login wrote `auth-profiles.json` without replacing it, so the picker never saw the new profile until a reload. The login now refreshes that snapshot: in process when the login runs inside the gateway, over the `secrets.reload` RPC when it runs from the CLI; no gateway running is fine.
|
|
@@ -5520,16 +5520,18 @@ function applyContextPruningDefaults(cfg) {
|
|
|
5520
5520
|
const nextModels = defaults.models ? { ...defaults.models } : {};
|
|
5521
5521
|
let modelsMutated = false;
|
|
5522
5522
|
const isAnthropicCacheRetentionTarget = (parsed) => Boolean(parsed && (parsed.provider === "anthropic" || parsed.provider === "amazon-bedrock" && parsed.model.toLowerCase().includes("anthropic.claude")));
|
|
5523
|
+
// JOHNNESS_PATCH_ANTHROPIC_CACHE_LONG_90: direct Anthropic uses 1h; Bedrock keeps its existing default.
|
|
5523
5524
|
for (const [key, entry] of Object.entries(nextModels)) {
|
|
5524
|
-
|
|
5525
|
+
const parsed = parseModelRef(key, "anthropic");
|
|
5526
|
+
if (!isAnthropicCacheRetentionTarget(parsed)) continue;
|
|
5525
5527
|
const current = entry ?? {};
|
|
5526
5528
|
const params = current.params ?? {};
|
|
5527
|
-
if (typeof params.cacheRetention === "string") continue;
|
|
5529
|
+
if (typeof params.cacheRetention === "string" || parsed.provider === "anthropic" && params.cacheControlTtl !== void 0) continue;
|
|
5528
5530
|
nextModels[key] = {
|
|
5529
5531
|
...current,
|
|
5530
5532
|
params: {
|
|
5531
5533
|
...params,
|
|
5532
|
-
cacheRetention: "short"
|
|
5534
|
+
cacheRetention: parsed.provider === "anthropic" ? "long" : "short"
|
|
5533
5535
|
}
|
|
5534
5536
|
};
|
|
5535
5537
|
modelsMutated = true;
|
|
@@ -5541,12 +5543,12 @@ function applyContextPruningDefaults(cfg) {
|
|
|
5541
5543
|
const key = `${parsedPrimary.provider}/${parsedPrimary.model}`;
|
|
5542
5544
|
const current = nextModels[key] ?? {};
|
|
5543
5545
|
const params = current.params ?? {};
|
|
5544
|
-
if (typeof params.cacheRetention !== "string") {
|
|
5546
|
+
if (typeof params.cacheRetention !== "string" && !(parsedPrimary.provider === "anthropic" && params.cacheControlTtl !== void 0)) {
|
|
5545
5547
|
nextModels[key] = {
|
|
5546
5548
|
...current,
|
|
5547
5549
|
params: {
|
|
5548
5550
|
...params,
|
|
5549
|
-
cacheRetention: "short"
|
|
5551
|
+
cacheRetention: parsedPrimary.provider === "anthropic" ? "long" : "short"
|
|
5550
5552
|
}
|
|
5551
5553
|
};
|
|
5552
5554
|
modelsMutated = true;
|
package/dist/compact-B247y5Qt.js
CHANGED
|
@@ -6430,7 +6430,7 @@ function resolveExtraParams(params) {
|
|
|
6430
6430
|
* OpenRouter uses openai-completions API with hardcoded cache_control instead
|
|
6431
6431
|
* of the cacheRetention stream option.
|
|
6432
6432
|
*
|
|
6433
|
-
*
|
|
6433
|
+
* JOHNNESS_PATCH_ANTHROPIC_CACHE_LONG_90: defaults to "long" for direct Anthropic (both auth modes).
|
|
6434
6434
|
*/
|
|
6435
6435
|
function resolveCacheRetention(extraParams, provider) {
|
|
6436
6436
|
const isAnthropicDirect = provider === "anthropic";
|
|
@@ -6442,10 +6442,12 @@ function resolveCacheRetention(extraParams, provider) {
|
|
|
6442
6442
|
if (legacy === "5m") return "short";
|
|
6443
6443
|
if (legacy === "1h") return "long";
|
|
6444
6444
|
if (!isAnthropicDirect) return;
|
|
6445
|
-
return "
|
|
6445
|
+
return "long";
|
|
6446
6446
|
}
|
|
6447
6447
|
function createStreamFnWithExtraParams(baseStreamFn, extraParams, provider) {
|
|
6448
|
-
|
|
6448
|
+
// JOHNNESS_PATCH_ANTHROPIC_CACHE_LONG_90: apply the Anthropic default even with no model params.
|
|
6449
|
+
if ((!extraParams || Object.keys(extraParams).length === 0) && provider !== "anthropic") return;
|
|
6450
|
+
extraParams ??= {};
|
|
6449
6451
|
const streamParams = {};
|
|
6450
6452
|
if (typeof extraParams.temperature === "number") streamParams.temperature = extraParams.temperature;
|
|
6451
6453
|
if (typeof extraParams.maxTokens === "number") streamParams.maxTokens = extraParams.maxTokens;
|
package/dist/config-koj5M_EO.js
CHANGED
|
@@ -2214,16 +2214,18 @@ function applyContextPruningDefaults(cfg) {
|
|
|
2214
2214
|
const nextModels = defaults.models ? { ...defaults.models } : {};
|
|
2215
2215
|
let modelsMutated = false;
|
|
2216
2216
|
const isAnthropicCacheRetentionTarget = (parsed) => Boolean(parsed && (parsed.provider === "anthropic" || parsed.provider === "amazon-bedrock" && parsed.model.toLowerCase().includes("anthropic.claude")));
|
|
2217
|
+
// JOHNNESS_PATCH_ANTHROPIC_CACHE_LONG_90: direct Anthropic uses 1h; Bedrock keeps its existing default.
|
|
2217
2218
|
for (const [key, entry] of Object.entries(nextModels)) {
|
|
2218
|
-
|
|
2219
|
+
const parsed = parseModelRef(key, "anthropic");
|
|
2220
|
+
if (!isAnthropicCacheRetentionTarget(parsed)) continue;
|
|
2219
2221
|
const current = entry ?? {};
|
|
2220
2222
|
const params = current.params ?? {};
|
|
2221
|
-
if (typeof params.cacheRetention === "string") continue;
|
|
2223
|
+
if (typeof params.cacheRetention === "string" || parsed.provider === "anthropic" && params.cacheControlTtl !== void 0) continue;
|
|
2222
2224
|
nextModels[key] = {
|
|
2223
2225
|
...current,
|
|
2224
2226
|
params: {
|
|
2225
2227
|
...params,
|
|
2226
|
-
cacheRetention: "short"
|
|
2228
|
+
cacheRetention: parsed.provider === "anthropic" ? "long" : "short"
|
|
2227
2229
|
}
|
|
2228
2230
|
};
|
|
2229
2231
|
modelsMutated = true;
|
|
@@ -2235,12 +2237,12 @@ function applyContextPruningDefaults(cfg) {
|
|
|
2235
2237
|
const key = `${parsedPrimary.provider}/${parsedPrimary.model}`;
|
|
2236
2238
|
const current = nextModels[key] ?? {};
|
|
2237
2239
|
const params = current.params ?? {};
|
|
2238
|
-
if (typeof params.cacheRetention !== "string") {
|
|
2240
|
+
if (typeof params.cacheRetention !== "string" && !(parsedPrimary.provider === "anthropic" && params.cacheControlTtl !== void 0)) {
|
|
2239
2241
|
nextModels[key] = {
|
|
2240
2242
|
...current,
|
|
2241
2243
|
params: {
|
|
2242
2244
|
...params,
|
|
2243
|
-
cacheRetention: "short"
|
|
2245
|
+
cacheRetention: parsedPrimary.provider === "anthropic" ? "long" : "short"
|
|
2244
2246
|
}
|
|
2245
2247
|
};
|
|
2246
2248
|
modelsMutated = true;
|
package/dist/daemon-cli.js
CHANGED
|
@@ -5366,16 +5366,18 @@ function applyContextPruningDefaults(cfg) {
|
|
|
5366
5366
|
const nextModels = defaults.models ? { ...defaults.models } : {};
|
|
5367
5367
|
let modelsMutated = false;
|
|
5368
5368
|
const isAnthropicCacheRetentionTarget = (parsed) => Boolean(parsed && (parsed.provider === "anthropic" || parsed.provider === "amazon-bedrock" && parsed.model.toLowerCase().includes("anthropic.claude")));
|
|
5369
|
+
// JOHNNESS_PATCH_ANTHROPIC_CACHE_LONG_90: direct Anthropic uses 1h; Bedrock keeps its existing default.
|
|
5369
5370
|
for (const [key, entry] of Object.entries(nextModels)) {
|
|
5370
|
-
|
|
5371
|
+
const parsed = parseModelRef(key, "anthropic");
|
|
5372
|
+
if (!isAnthropicCacheRetentionTarget(parsed)) continue;
|
|
5371
5373
|
const current = entry ?? {};
|
|
5372
5374
|
const params = current.params ?? {};
|
|
5373
|
-
if (typeof params.cacheRetention === "string") continue;
|
|
5375
|
+
if (typeof params.cacheRetention === "string" || parsed.provider === "anthropic" && params.cacheControlTtl !== void 0) continue;
|
|
5374
5376
|
nextModels[key] = {
|
|
5375
5377
|
...current,
|
|
5376
5378
|
params: {
|
|
5377
5379
|
...params,
|
|
5378
|
-
cacheRetention: "short"
|
|
5380
|
+
cacheRetention: parsed.provider === "anthropic" ? "long" : "short"
|
|
5379
5381
|
}
|
|
5380
5382
|
};
|
|
5381
5383
|
modelsMutated = true;
|
|
@@ -5387,12 +5389,12 @@ function applyContextPruningDefaults(cfg) {
|
|
|
5387
5389
|
const key = `${parsedPrimary.provider}/${parsedPrimary.model}`;
|
|
5388
5390
|
const current = nextModels[key] ?? {};
|
|
5389
5391
|
const params = current.params ?? {};
|
|
5390
|
-
if (typeof params.cacheRetention !== "string") {
|
|
5392
|
+
if (typeof params.cacheRetention !== "string" && !(parsedPrimary.provider === "anthropic" && params.cacheControlTtl !== void 0)) {
|
|
5391
5393
|
nextModels[key] = {
|
|
5392
5394
|
...current,
|
|
5393
5395
|
params: {
|
|
5394
5396
|
...params,
|
|
5395
|
-
cacheRetention: "short"
|
|
5397
|
+
cacheRetention: parsedPrimary.provider === "anthropic" ? "long" : "short"
|
|
5396
5398
|
}
|
|
5397
5399
|
};
|
|
5398
5400
|
modelsMutated = true;
|
|
@@ -2091,16 +2091,18 @@ function applyContextPruningDefaults(cfg) {
|
|
|
2091
2091
|
const nextModels = defaults.models ? { ...defaults.models } : {};
|
|
2092
2092
|
let modelsMutated = false;
|
|
2093
2093
|
const isAnthropicCacheRetentionTarget = (parsed) => Boolean(parsed && (parsed.provider === "anthropic" || parsed.provider === "amazon-bedrock" && parsed.model.toLowerCase().includes("anthropic.claude")));
|
|
2094
|
+
// JOHNNESS_PATCH_ANTHROPIC_CACHE_LONG_90: direct Anthropic uses 1h; Bedrock keeps its existing default.
|
|
2094
2095
|
for (const [key, entry] of Object.entries(nextModels)) {
|
|
2095
|
-
|
|
2096
|
+
const parsed = parseModelRef(key, "anthropic");
|
|
2097
|
+
if (!isAnthropicCacheRetentionTarget(parsed)) continue;
|
|
2096
2098
|
const current = entry ?? {};
|
|
2097
2099
|
const params = current.params ?? {};
|
|
2098
|
-
if (typeof params.cacheRetention === "string") continue;
|
|
2100
|
+
if (typeof params.cacheRetention === "string" || parsed.provider === "anthropic" && params.cacheControlTtl !== void 0) continue;
|
|
2099
2101
|
nextModels[key] = {
|
|
2100
2102
|
...current,
|
|
2101
2103
|
params: {
|
|
2102
2104
|
...params,
|
|
2103
|
-
cacheRetention: "short"
|
|
2105
|
+
cacheRetention: parsed.provider === "anthropic" ? "long" : "short"
|
|
2104
2106
|
}
|
|
2105
2107
|
};
|
|
2106
2108
|
modelsMutated = true;
|
|
@@ -2112,12 +2114,12 @@ function applyContextPruningDefaults(cfg) {
|
|
|
2112
2114
|
const key = `${parsedPrimary.provider}/${parsedPrimary.model}`;
|
|
2113
2115
|
const current = nextModels[key] ?? {};
|
|
2114
2116
|
const params = current.params ?? {};
|
|
2115
|
-
if (typeof params.cacheRetention !== "string") {
|
|
2117
|
+
if (typeof params.cacheRetention !== "string" && !(parsedPrimary.provider === "anthropic" && params.cacheControlTtl !== void 0)) {
|
|
2116
2118
|
nextModels[key] = {
|
|
2117
2119
|
...current,
|
|
2118
2120
|
params: {
|
|
2119
2121
|
...params,
|
|
2120
|
-
cacheRetention: "short"
|
|
2122
|
+
cacheRetention: parsedPrimary.provider === "anthropic" ? "long" : "short"
|
|
2121
2123
|
}
|
|
2122
2124
|
};
|
|
2123
2125
|
modelsMutated = true;
|
|
@@ -2066,16 +2066,18 @@ function applyContextPruningDefaults(cfg) {
|
|
|
2066
2066
|
const nextModels = defaults.models ? { ...defaults.models } : {};
|
|
2067
2067
|
let modelsMutated = false;
|
|
2068
2068
|
const isAnthropicCacheRetentionTarget = (parsed) => Boolean(parsed && (parsed.provider === "anthropic" || parsed.provider === "amazon-bedrock" && parsed.model.toLowerCase().includes("anthropic.claude")));
|
|
2069
|
+
// JOHNNESS_PATCH_ANTHROPIC_CACHE_LONG_90: direct Anthropic uses 1h; Bedrock keeps its existing default.
|
|
2069
2070
|
for (const [key, entry] of Object.entries(nextModels)) {
|
|
2070
|
-
|
|
2071
|
+
const parsed = parseModelRef(key, "anthropic");
|
|
2072
|
+
if (!isAnthropicCacheRetentionTarget(parsed)) continue;
|
|
2071
2073
|
const current = entry ?? {};
|
|
2072
2074
|
const params = current.params ?? {};
|
|
2073
|
-
if (typeof params.cacheRetention === "string") continue;
|
|
2075
|
+
if (typeof params.cacheRetention === "string" || parsed.provider === "anthropic" && params.cacheControlTtl !== void 0) continue;
|
|
2074
2076
|
nextModels[key] = {
|
|
2075
2077
|
...current,
|
|
2076
2078
|
params: {
|
|
2077
2079
|
...params,
|
|
2078
|
-
cacheRetention: "short"
|
|
2080
|
+
cacheRetention: parsed.provider === "anthropic" ? "long" : "short"
|
|
2079
2081
|
}
|
|
2080
2082
|
};
|
|
2081
2083
|
modelsMutated = true;
|
|
@@ -2087,12 +2089,12 @@ function applyContextPruningDefaults(cfg) {
|
|
|
2087
2089
|
const key = `${parsedPrimary.provider}/${parsedPrimary.model}`;
|
|
2088
2090
|
const current = nextModels[key] ?? {};
|
|
2089
2091
|
const params = current.params ?? {};
|
|
2090
|
-
if (typeof params.cacheRetention !== "string") {
|
|
2092
|
+
if (typeof params.cacheRetention !== "string" && !(parsedPrimary.provider === "anthropic" && params.cacheControlTtl !== void 0)) {
|
|
2091
2093
|
nextModels[key] = {
|
|
2092
2094
|
...current,
|
|
2093
2095
|
params: {
|
|
2094
2096
|
...params,
|
|
2095
|
-
cacheRetention: "short"
|
|
2097
|
+
cacheRetention: parsedPrimary.provider === "anthropic" ? "long" : "short"
|
|
2096
2098
|
}
|
|
2097
2099
|
};
|
|
2098
2100
|
modelsMutated = true;
|
|
@@ -1997,16 +1997,18 @@ function applyContextPruningDefaults(cfg) {
|
|
|
1997
1997
|
const nextModels = defaults.models ? { ...defaults.models } : {};
|
|
1998
1998
|
let modelsMutated = false;
|
|
1999
1999
|
const isAnthropicCacheRetentionTarget = (parsed) => Boolean(parsed && (parsed.provider === "anthropic" || parsed.provider === "amazon-bedrock" && parsed.model.toLowerCase().includes("anthropic.claude")));
|
|
2000
|
+
// JOHNNESS_PATCH_ANTHROPIC_CACHE_LONG_90: direct Anthropic uses 1h; Bedrock keeps its existing default.
|
|
2000
2001
|
for (const [key, entry] of Object.entries(nextModels)) {
|
|
2001
|
-
|
|
2002
|
+
const parsed = parseModelRef(key, "anthropic");
|
|
2003
|
+
if (!isAnthropicCacheRetentionTarget(parsed)) continue;
|
|
2002
2004
|
const current = entry ?? {};
|
|
2003
2005
|
const params = current.params ?? {};
|
|
2004
|
-
if (typeof params.cacheRetention === "string") continue;
|
|
2006
|
+
if (typeof params.cacheRetention === "string" || parsed.provider === "anthropic" && params.cacheControlTtl !== void 0) continue;
|
|
2005
2007
|
nextModels[key] = {
|
|
2006
2008
|
...current,
|
|
2007
2009
|
params: {
|
|
2008
2010
|
...params,
|
|
2009
|
-
cacheRetention: "short"
|
|
2011
|
+
cacheRetention: parsed.provider === "anthropic" ? "long" : "short"
|
|
2010
2012
|
}
|
|
2011
2013
|
};
|
|
2012
2014
|
modelsMutated = true;
|
|
@@ -2018,12 +2020,12 @@ function applyContextPruningDefaults(cfg) {
|
|
|
2018
2020
|
const key = `${parsedPrimary.provider}/${parsedPrimary.model}`;
|
|
2019
2021
|
const current = nextModels[key] ?? {};
|
|
2020
2022
|
const params = current.params ?? {};
|
|
2021
|
-
if (typeof params.cacheRetention !== "string") {
|
|
2023
|
+
if (typeof params.cacheRetention !== "string" && !(parsedPrimary.provider === "anthropic" && params.cacheControlTtl !== void 0)) {
|
|
2022
2024
|
nextModels[key] = {
|
|
2023
2025
|
...current,
|
|
2024
2026
|
params: {
|
|
2025
2027
|
...params,
|
|
2026
|
-
cacheRetention: "short"
|
|
2028
|
+
cacheRetention: parsedPrimary.provider === "anthropic" ? "long" : "short"
|
|
2027
2029
|
}
|
|
2028
2030
|
};
|
|
2029
2031
|
modelsMutated = true;
|
|
@@ -97967,7 +97967,7 @@ function resolveExtraParams(params) {
|
|
|
97967
97967
|
* OpenRouter uses openai-completions API with hardcoded cache_control instead
|
|
97968
97968
|
* of the cacheRetention stream option.
|
|
97969
97969
|
*
|
|
97970
|
-
*
|
|
97970
|
+
* JOHNNESS_PATCH_ANTHROPIC_CACHE_LONG_90: defaults to "long" for direct Anthropic (both auth modes).
|
|
97971
97971
|
*/
|
|
97972
97972
|
function resolveCacheRetention(extraParams, provider) {
|
|
97973
97973
|
const isAnthropicDirect = provider === "anthropic";
|
|
@@ -97979,10 +97979,12 @@ function resolveCacheRetention(extraParams, provider) {
|
|
|
97979
97979
|
if (legacy === "5m") return "short";
|
|
97980
97980
|
if (legacy === "1h") return "long";
|
|
97981
97981
|
if (!isAnthropicDirect) return;
|
|
97982
|
-
return "
|
|
97982
|
+
return "long";
|
|
97983
97983
|
}
|
|
97984
97984
|
function createStreamFnWithExtraParams(baseStreamFn, extraParams, provider) {
|
|
97985
|
-
|
|
97985
|
+
// JOHNNESS_PATCH_ANTHROPIC_CACHE_LONG_90: apply the Anthropic default even with no model params.
|
|
97986
|
+
if ((!extraParams || Object.keys(extraParams).length === 0) && provider !== "anthropic") return;
|
|
97987
|
+
extraParams ??= {};
|
|
97986
97988
|
const streamParams = {};
|
|
97987
97989
|
if (typeof extraParams.temperature === "number") streamParams.temperature = extraParams.temperature;
|
|
97988
97990
|
if (typeof extraParams.maxTokens === "number") streamParams.maxTokens = extraParams.maxTokens;
|
|
@@ -97957,7 +97957,7 @@ function resolveExtraParams(params) {
|
|
|
97957
97957
|
* OpenRouter uses openai-completions API with hardcoded cache_control instead
|
|
97958
97958
|
* of the cacheRetention stream option.
|
|
97959
97959
|
*
|
|
97960
|
-
*
|
|
97960
|
+
* JOHNNESS_PATCH_ANTHROPIC_CACHE_LONG_90: defaults to "long" for direct Anthropic (both auth modes).
|
|
97961
97961
|
*/
|
|
97962
97962
|
function resolveCacheRetention(extraParams, provider) {
|
|
97963
97963
|
const isAnthropicDirect = provider === "anthropic";
|
|
@@ -97969,10 +97969,12 @@ function resolveCacheRetention(extraParams, provider) {
|
|
|
97969
97969
|
if (legacy === "5m") return "short";
|
|
97970
97970
|
if (legacy === "1h") return "long";
|
|
97971
97971
|
if (!isAnthropicDirect) return;
|
|
97972
|
-
return "
|
|
97972
|
+
return "long";
|
|
97973
97973
|
}
|
|
97974
97974
|
function createStreamFnWithExtraParams(baseStreamFn, extraParams, provider) {
|
|
97975
|
-
|
|
97975
|
+
// JOHNNESS_PATCH_ANTHROPIC_CACHE_LONG_90: apply the Anthropic default even with no model params.
|
|
97976
|
+
if ((!extraParams || Object.keys(extraParams).length === 0) && provider !== "anthropic") return;
|
|
97977
|
+
extraParams ??= {};
|
|
97976
97978
|
const streamParams = {};
|
|
97977
97979
|
if (typeof extraParams.temperature === "number") streamParams.temperature = extraParams.temperature;
|
|
97978
97980
|
if (typeof extraParams.maxTokens === "number") streamParams.maxTokens = extraParams.maxTokens;
|
|
@@ -7468,16 +7468,18 @@ function applyContextPruningDefaults(cfg) {
|
|
|
7468
7468
|
const nextModels = defaults.models ? { ...defaults.models } : {};
|
|
7469
7469
|
let modelsMutated = false;
|
|
7470
7470
|
const isAnthropicCacheRetentionTarget = (parsed) => Boolean(parsed && (parsed.provider === "anthropic" || parsed.provider === "amazon-bedrock" && parsed.model.toLowerCase().includes("anthropic.claude")));
|
|
7471
|
+
// JOHNNESS_PATCH_ANTHROPIC_CACHE_LONG_90: direct Anthropic uses 1h; Bedrock keeps its existing default.
|
|
7471
7472
|
for (const [key, entry] of Object.entries(nextModels)) {
|
|
7472
|
-
|
|
7473
|
+
const parsed = parseModelRef(key, "anthropic");
|
|
7474
|
+
if (!isAnthropicCacheRetentionTarget(parsed)) continue;
|
|
7473
7475
|
const current = entry ?? {};
|
|
7474
7476
|
const params = current.params ?? {};
|
|
7475
|
-
if (typeof params.cacheRetention === "string") continue;
|
|
7477
|
+
if (typeof params.cacheRetention === "string" || parsed.provider === "anthropic" && params.cacheControlTtl !== void 0) continue;
|
|
7476
7478
|
nextModels[key] = {
|
|
7477
7479
|
...current,
|
|
7478
7480
|
params: {
|
|
7479
7481
|
...params,
|
|
7480
|
-
cacheRetention: "short"
|
|
7482
|
+
cacheRetention: parsed.provider === "anthropic" ? "long" : "short"
|
|
7481
7483
|
}
|
|
7482
7484
|
};
|
|
7483
7485
|
modelsMutated = true;
|
|
@@ -7489,12 +7491,12 @@ function applyContextPruningDefaults(cfg) {
|
|
|
7489
7491
|
const key = `${parsedPrimary.provider}/${parsedPrimary.model}`;
|
|
7490
7492
|
const current = nextModels[key] ?? {};
|
|
7491
7493
|
const params = current.params ?? {};
|
|
7492
|
-
if (typeof params.cacheRetention !== "string") {
|
|
7494
|
+
if (typeof params.cacheRetention !== "string" && !(parsedPrimary.provider === "anthropic" && params.cacheControlTtl !== void 0)) {
|
|
7493
7495
|
nextModels[key] = {
|
|
7494
7496
|
...current,
|
|
7495
7497
|
params: {
|
|
7496
7498
|
...params,
|
|
7497
|
-
cacheRetention: "short"
|
|
7499
|
+
cacheRetention: parsedPrimary.provider === "anthropic" ? "long" : "short"
|
|
7498
7500
|
}
|
|
7499
7501
|
};
|
|
7500
7502
|
modelsMutated = true;
|
|
@@ -8469,16 +8469,18 @@ function applyContextPruningDefaults(cfg) {
|
|
|
8469
8469
|
const nextModels = defaults.models ? { ...defaults.models } : {};
|
|
8470
8470
|
let modelsMutated = false;
|
|
8471
8471
|
const isAnthropicCacheRetentionTarget = (parsed) => Boolean(parsed && (parsed.provider === "anthropic" || parsed.provider === "amazon-bedrock" && parsed.model.toLowerCase().includes("anthropic.claude")));
|
|
8472
|
+
// JOHNNESS_PATCH_ANTHROPIC_CACHE_LONG_90: direct Anthropic uses 1h; Bedrock keeps its existing default.
|
|
8472
8473
|
for (const [key, entry] of Object.entries(nextModels)) {
|
|
8473
|
-
|
|
8474
|
+
const parsed = parseModelRef(key, "anthropic");
|
|
8475
|
+
if (!isAnthropicCacheRetentionTarget(parsed)) continue;
|
|
8474
8476
|
const current = entry ?? {};
|
|
8475
8477
|
const params = current.params ?? {};
|
|
8476
|
-
if (typeof params.cacheRetention === "string") continue;
|
|
8478
|
+
if (typeof params.cacheRetention === "string" || parsed.provider === "anthropic" && params.cacheControlTtl !== void 0) continue;
|
|
8477
8479
|
nextModels[key] = {
|
|
8478
8480
|
...current,
|
|
8479
8481
|
params: {
|
|
8480
8482
|
...params,
|
|
8481
|
-
cacheRetention: "short"
|
|
8483
|
+
cacheRetention: parsed.provider === "anthropic" ? "long" : "short"
|
|
8482
8484
|
}
|
|
8483
8485
|
};
|
|
8484
8486
|
modelsMutated = true;
|
|
@@ -8490,12 +8492,12 @@ function applyContextPruningDefaults(cfg) {
|
|
|
8490
8492
|
const key = `${parsedPrimary.provider}/${parsedPrimary.model}`;
|
|
8491
8493
|
const current = nextModels[key] ?? {};
|
|
8492
8494
|
const params = current.params ?? {};
|
|
8493
|
-
if (typeof params.cacheRetention !== "string") {
|
|
8495
|
+
if (typeof params.cacheRetention !== "string" && !(parsedPrimary.provider === "anthropic" && params.cacheControlTtl !== void 0)) {
|
|
8494
8496
|
nextModels[key] = {
|
|
8495
8497
|
...current,
|
|
8496
8498
|
params: {
|
|
8497
8499
|
...params,
|
|
8498
|
-
cacheRetention: "short"
|
|
8500
|
+
cacheRetention: parsedPrimary.provider === "anthropic" ? "long" : "short"
|
|
8499
8501
|
}
|
|
8500
8502
|
};
|
|
8501
8503
|
modelsMutated = true;
|
|
@@ -5594,16 +5594,18 @@ function applyContextPruningDefaults(cfg) {
|
|
|
5594
5594
|
const nextModels = defaults.models ? { ...defaults.models } : {};
|
|
5595
5595
|
let modelsMutated = false;
|
|
5596
5596
|
const isAnthropicCacheRetentionTarget = (parsed) => Boolean(parsed && (parsed.provider === "anthropic" || parsed.provider === "amazon-bedrock" && parsed.model.toLowerCase().includes("anthropic.claude")));
|
|
5597
|
+
// JOHNNESS_PATCH_ANTHROPIC_CACHE_LONG_90: direct Anthropic uses 1h; Bedrock keeps its existing default.
|
|
5597
5598
|
for (const [key, entry] of Object.entries(nextModels)) {
|
|
5598
|
-
|
|
5599
|
+
const parsed = parseModelRef(key, "anthropic");
|
|
5600
|
+
if (!isAnthropicCacheRetentionTarget(parsed)) continue;
|
|
5599
5601
|
const current = entry ?? {};
|
|
5600
5602
|
const params = current.params ?? {};
|
|
5601
|
-
if (typeof params.cacheRetention === "string") continue;
|
|
5603
|
+
if (typeof params.cacheRetention === "string" || parsed.provider === "anthropic" && params.cacheControlTtl !== void 0) continue;
|
|
5602
5604
|
nextModels[key] = {
|
|
5603
5605
|
...current,
|
|
5604
5606
|
params: {
|
|
5605
5607
|
...params,
|
|
5606
|
-
cacheRetention: "short"
|
|
5608
|
+
cacheRetention: parsed.provider === "anthropic" ? "long" : "short"
|
|
5607
5609
|
}
|
|
5608
5610
|
};
|
|
5609
5611
|
modelsMutated = true;
|
|
@@ -5615,12 +5617,12 @@ function applyContextPruningDefaults(cfg) {
|
|
|
5615
5617
|
const key = `${parsedPrimary.provider}/${parsedPrimary.model}`;
|
|
5616
5618
|
const current = nextModels[key] ?? {};
|
|
5617
5619
|
const params = current.params ?? {};
|
|
5618
|
-
if (typeof params.cacheRetention !== "string") {
|
|
5620
|
+
if (typeof params.cacheRetention !== "string" && !(parsedPrimary.provider === "anthropic" && params.cacheControlTtl !== void 0)) {
|
|
5619
5621
|
nextModels[key] = {
|
|
5620
5622
|
...current,
|
|
5621
5623
|
params: {
|
|
5622
5624
|
...params,
|
|
5623
|
-
cacheRetention: "short"
|
|
5625
|
+
cacheRetention: parsedPrimary.provider === "anthropic" ? "long" : "short"
|
|
5624
5626
|
}
|
|
5625
5627
|
};
|
|
5626
5628
|
modelsMutated = true;
|
|
@@ -82353,7 +82353,7 @@ function resolveExtraParams(params) {
|
|
|
82353
82353
|
* OpenRouter uses openai-completions API with hardcoded cache_control instead
|
|
82354
82354
|
* of the cacheRetention stream option.
|
|
82355
82355
|
*
|
|
82356
|
-
*
|
|
82356
|
+
* JOHNNESS_PATCH_ANTHROPIC_CACHE_LONG_90: defaults to "long" for direct Anthropic (both auth modes).
|
|
82357
82357
|
*/
|
|
82358
82358
|
function resolveCacheRetention(extraParams, provider) {
|
|
82359
82359
|
const isAnthropicDirect = provider === "anthropic";
|
|
@@ -82365,10 +82365,12 @@ function resolveCacheRetention(extraParams, provider) {
|
|
|
82365
82365
|
if (legacy === "5m") return "short";
|
|
82366
82366
|
if (legacy === "1h") return "long";
|
|
82367
82367
|
if (!isAnthropicDirect) return;
|
|
82368
|
-
return "
|
|
82368
|
+
return "long";
|
|
82369
82369
|
}
|
|
82370
82370
|
function createStreamFnWithExtraParams(baseStreamFn, extraParams, provider) {
|
|
82371
|
-
|
|
82371
|
+
// JOHNNESS_PATCH_ANTHROPIC_CACHE_LONG_90: apply the Anthropic default even with no model params.
|
|
82372
|
+
if ((!extraParams || Object.keys(extraParams).length === 0) && provider !== "anthropic") return;
|
|
82373
|
+
extraParams ??= {};
|
|
82372
82374
|
const streamParams = {};
|
|
82373
82375
|
if (typeof extraParams.temperature === "number") streamParams.temperature = extraParams.temperature;
|
|
82374
82376
|
if (typeof extraParams.maxTokens === "number") streamParams.maxTokens = extraParams.maxTokens;
|
|
@@ -82353,7 +82353,7 @@ function resolveExtraParams(params) {
|
|
|
82353
82353
|
* OpenRouter uses openai-completions API with hardcoded cache_control instead
|
|
82354
82354
|
* of the cacheRetention stream option.
|
|
82355
82355
|
*
|
|
82356
|
-
*
|
|
82356
|
+
* JOHNNESS_PATCH_ANTHROPIC_CACHE_LONG_90: defaults to "long" for direct Anthropic (both auth modes).
|
|
82357
82357
|
*/
|
|
82358
82358
|
function resolveCacheRetention(extraParams, provider) {
|
|
82359
82359
|
const isAnthropicDirect = provider === "anthropic";
|
|
@@ -82365,10 +82365,12 @@ function resolveCacheRetention(extraParams, provider) {
|
|
|
82365
82365
|
if (legacy === "5m") return "short";
|
|
82366
82366
|
if (legacy === "1h") return "long";
|
|
82367
82367
|
if (!isAnthropicDirect) return;
|
|
82368
|
-
return "
|
|
82368
|
+
return "long";
|
|
82369
82369
|
}
|
|
82370
82370
|
function createStreamFnWithExtraParams(baseStreamFn, extraParams, provider) {
|
|
82371
|
-
|
|
82371
|
+
// JOHNNESS_PATCH_ANTHROPIC_CACHE_LONG_90: apply the Anthropic default even with no model params.
|
|
82372
|
+
if ((!extraParams || Object.keys(extraParams).length === 0) && provider !== "anthropic") return;
|
|
82373
|
+
extraParams ??= {};
|
|
82372
82374
|
const streamParams = {};
|
|
82373
82375
|
if (typeof extraParams.temperature === "number") streamParams.temperature = extraParams.temperature;
|
|
82374
82376
|
if (typeof extraParams.maxTokens === "number") streamParams.maxTokens = extraParams.maxTokens;
|
|
@@ -82667,7 +82667,7 @@ function resolveExtraParams(params) {
|
|
|
82667
82667
|
* OpenRouter uses openai-completions API with hardcoded cache_control instead
|
|
82668
82668
|
* of the cacheRetention stream option.
|
|
82669
82669
|
*
|
|
82670
|
-
*
|
|
82670
|
+
* JOHNNESS_PATCH_ANTHROPIC_CACHE_LONG_90: defaults to "long" for direct Anthropic (both auth modes).
|
|
82671
82671
|
*/
|
|
82672
82672
|
function resolveCacheRetention(extraParams, provider) {
|
|
82673
82673
|
const isAnthropicDirect = provider === "anthropic";
|
|
@@ -82679,10 +82679,12 @@ function resolveCacheRetention(extraParams, provider) {
|
|
|
82679
82679
|
if (legacy === "5m") return "short";
|
|
82680
82680
|
if (legacy === "1h") return "long";
|
|
82681
82681
|
if (!isAnthropicDirect) return;
|
|
82682
|
-
return "
|
|
82682
|
+
return "long";
|
|
82683
82683
|
}
|
|
82684
82684
|
function createStreamFnWithExtraParams(baseStreamFn, extraParams, provider) {
|
|
82685
|
-
|
|
82685
|
+
// JOHNNESS_PATCH_ANTHROPIC_CACHE_LONG_90: apply the Anthropic default even with no model params.
|
|
82686
|
+
if ((!extraParams || Object.keys(extraParams).length === 0) && provider !== "anthropic") return;
|
|
82687
|
+
extraParams ??= {};
|
|
82686
82688
|
const streamParams = {};
|
|
82687
82689
|
if (typeof extraParams.temperature === "number") streamParams.temperature = extraParams.temperature;
|
|
82688
82690
|
if (typeof extraParams.maxTokens === "number") streamParams.maxTokens = extraParams.maxTokens;
|
|
@@ -82394,7 +82394,7 @@ function resolveExtraParams(params) {
|
|
|
82394
82394
|
* OpenRouter uses openai-completions API with hardcoded cache_control instead
|
|
82395
82395
|
* of the cacheRetention stream option.
|
|
82396
82396
|
*
|
|
82397
|
-
*
|
|
82397
|
+
* JOHNNESS_PATCH_ANTHROPIC_CACHE_LONG_90: defaults to "long" for direct Anthropic (both auth modes).
|
|
82398
82398
|
*/
|
|
82399
82399
|
function resolveCacheRetention(extraParams, provider) {
|
|
82400
82400
|
const isAnthropicDirect = provider === "anthropic";
|
|
@@ -82406,10 +82406,12 @@ function resolveCacheRetention(extraParams, provider) {
|
|
|
82406
82406
|
if (legacy === "5m") return "short";
|
|
82407
82407
|
if (legacy === "1h") return "long";
|
|
82408
82408
|
if (!isAnthropicDirect) return;
|
|
82409
|
-
return "
|
|
82409
|
+
return "long";
|
|
82410
82410
|
}
|
|
82411
82411
|
function createStreamFnWithExtraParams(baseStreamFn, extraParams, provider) {
|
|
82412
|
-
|
|
82412
|
+
// JOHNNESS_PATCH_ANTHROPIC_CACHE_LONG_90: apply the Anthropic default even with no model params.
|
|
82413
|
+
if ((!extraParams || Object.keys(extraParams).length === 0) && provider !== "anthropic") return;
|
|
82414
|
+
extraParams ??= {};
|
|
82413
82415
|
const streamParams = {};
|
|
82414
82416
|
if (typeof extraParams.temperature === "number") streamParams.temperature = extraParams.temperature;
|
|
82415
82417
|
if (typeof extraParams.maxTokens === "number") streamParams.maxTokens = extraParams.maxTokens;
|
|
@@ -82353,7 +82353,7 @@ function resolveExtraParams(params) {
|
|
|
82353
82353
|
* OpenRouter uses openai-completions API with hardcoded cache_control instead
|
|
82354
82354
|
* of the cacheRetention stream option.
|
|
82355
82355
|
*
|
|
82356
|
-
*
|
|
82356
|
+
* JOHNNESS_PATCH_ANTHROPIC_CACHE_LONG_90: defaults to "long" for direct Anthropic (both auth modes).
|
|
82357
82357
|
*/
|
|
82358
82358
|
function resolveCacheRetention(extraParams, provider) {
|
|
82359
82359
|
const isAnthropicDirect = provider === "anthropic";
|
|
@@ -82365,10 +82365,12 @@ function resolveCacheRetention(extraParams, provider) {
|
|
|
82365
82365
|
if (legacy === "5m") return "short";
|
|
82366
82366
|
if (legacy === "1h") return "long";
|
|
82367
82367
|
if (!isAnthropicDirect) return;
|
|
82368
|
-
return "
|
|
82368
|
+
return "long";
|
|
82369
82369
|
}
|
|
82370
82370
|
function createStreamFnWithExtraParams(baseStreamFn, extraParams, provider) {
|
|
82371
|
-
|
|
82371
|
+
// JOHNNESS_PATCH_ANTHROPIC_CACHE_LONG_90: apply the Anthropic default even with no model params.
|
|
82372
|
+
if ((!extraParams || Object.keys(extraParams).length === 0) && provider !== "anthropic") return;
|
|
82373
|
+
extraParams ??= {};
|
|
82372
82374
|
const streamParams = {};
|
|
82373
82375
|
if (typeof extraParams.temperature === "number") streamParams.temperature = extraParams.temperature;
|
|
82374
82376
|
if (typeof extraParams.maxTokens === "number") streamParams.maxTokens = extraParams.maxTokens;
|
|
@@ -6386,16 +6386,18 @@ function applyContextPruningDefaults(cfg) {
|
|
|
6386
6386
|
const nextModels = defaults.models ? { ...defaults.models } : {};
|
|
6387
6387
|
let modelsMutated = false;
|
|
6388
6388
|
const isAnthropicCacheRetentionTarget = (parsed) => Boolean(parsed && (parsed.provider === "anthropic" || parsed.provider === "amazon-bedrock" && parsed.model.toLowerCase().includes("anthropic.claude")));
|
|
6389
|
+
// JOHNNESS_PATCH_ANTHROPIC_CACHE_LONG_90: direct Anthropic uses 1h; Bedrock keeps its existing default.
|
|
6389
6390
|
for (const [key, entry] of Object.entries(nextModels)) {
|
|
6390
|
-
|
|
6391
|
+
const parsed = parseModelRef(key, "anthropic");
|
|
6392
|
+
if (!isAnthropicCacheRetentionTarget(parsed)) continue;
|
|
6391
6393
|
const current = entry ?? {};
|
|
6392
6394
|
const params = current.params ?? {};
|
|
6393
|
-
if (typeof params.cacheRetention === "string") continue;
|
|
6395
|
+
if (typeof params.cacheRetention === "string" || parsed.provider === "anthropic" && params.cacheControlTtl !== void 0) continue;
|
|
6394
6396
|
nextModels[key] = {
|
|
6395
6397
|
...current,
|
|
6396
6398
|
params: {
|
|
6397
6399
|
...params,
|
|
6398
|
-
cacheRetention: "short"
|
|
6400
|
+
cacheRetention: parsed.provider === "anthropic" ? "long" : "short"
|
|
6399
6401
|
}
|
|
6400
6402
|
};
|
|
6401
6403
|
modelsMutated = true;
|
|
@@ -6407,12 +6409,12 @@ function applyContextPruningDefaults(cfg) {
|
|
|
6407
6409
|
const key = `${parsedPrimary.provider}/${parsedPrimary.model}`;
|
|
6408
6410
|
const current = nextModels[key] ?? {};
|
|
6409
6411
|
const params = current.params ?? {};
|
|
6410
|
-
if (typeof params.cacheRetention !== "string") {
|
|
6412
|
+
if (typeof params.cacheRetention !== "string" && !(parsedPrimary.provider === "anthropic" && params.cacheControlTtl !== void 0)) {
|
|
6411
6413
|
nextModels[key] = {
|
|
6412
6414
|
...current,
|
|
6413
6415
|
params: {
|
|
6414
6416
|
...params,
|
|
6415
|
-
cacheRetention: "short"
|
|
6417
|
+
cacheRetention: parsedPrimary.provider === "anthropic" ? "long" : "short"
|
|
6416
6418
|
}
|
|
6417
6419
|
};
|
|
6418
6420
|
modelsMutated = true;
|
|
@@ -5355,16 +5355,18 @@ function applyContextPruningDefaults(cfg) {
|
|
|
5355
5355
|
const nextModels = defaults.models ? { ...defaults.models } : {};
|
|
5356
5356
|
let modelsMutated = false;
|
|
5357
5357
|
const isAnthropicCacheRetentionTarget = (parsed) => Boolean(parsed && (parsed.provider === "anthropic" || parsed.provider === "amazon-bedrock" && parsed.model.toLowerCase().includes("anthropic.claude")));
|
|
5358
|
+
// JOHNNESS_PATCH_ANTHROPIC_CACHE_LONG_90: direct Anthropic uses 1h; Bedrock keeps its existing default.
|
|
5358
5359
|
for (const [key, entry] of Object.entries(nextModels)) {
|
|
5359
|
-
|
|
5360
|
+
const parsed = parseModelRef(key, "anthropic");
|
|
5361
|
+
if (!isAnthropicCacheRetentionTarget(parsed)) continue;
|
|
5360
5362
|
const current = entry ?? {};
|
|
5361
5363
|
const params = current.params ?? {};
|
|
5362
|
-
if (typeof params.cacheRetention === "string") continue;
|
|
5364
|
+
if (typeof params.cacheRetention === "string" || parsed.provider === "anthropic" && params.cacheControlTtl !== void 0) continue;
|
|
5363
5365
|
nextModels[key] = {
|
|
5364
5366
|
...current,
|
|
5365
5367
|
params: {
|
|
5366
5368
|
...params,
|
|
5367
|
-
cacheRetention: "short"
|
|
5369
|
+
cacheRetention: parsed.provider === "anthropic" ? "long" : "short"
|
|
5368
5370
|
}
|
|
5369
5371
|
};
|
|
5370
5372
|
modelsMutated = true;
|
|
@@ -5376,12 +5378,12 @@ function applyContextPruningDefaults(cfg) {
|
|
|
5376
5378
|
const key = `${parsedPrimary.provider}/${parsedPrimary.model}`;
|
|
5377
5379
|
const current = nextModels[key] ?? {};
|
|
5378
5380
|
const params = current.params ?? {};
|
|
5379
|
-
if (typeof params.cacheRetention !== "string") {
|
|
5381
|
+
if (typeof params.cacheRetention !== "string" && !(parsedPrimary.provider === "anthropic" && params.cacheControlTtl !== void 0)) {
|
|
5380
5382
|
nextModels[key] = {
|
|
5381
5383
|
...current,
|
|
5382
5384
|
params: {
|
|
5383
5385
|
...params,
|
|
5384
|
-
cacheRetention: "short"
|
|
5386
|
+
cacheRetention: parsedPrimary.provider === "anthropic" ? "long" : "short"
|
|
5385
5387
|
}
|
|
5386
5388
|
};
|
|
5387
5389
|
modelsMutated = true;
|
|
@@ -5359,16 +5359,18 @@ function applyContextPruningDefaults(cfg) {
|
|
|
5359
5359
|
const nextModels = defaults.models ? { ...defaults.models } : {};
|
|
5360
5360
|
let modelsMutated = false;
|
|
5361
5361
|
const isAnthropicCacheRetentionTarget = (parsed) => Boolean(parsed && (parsed.provider === "anthropic" || parsed.provider === "amazon-bedrock" && parsed.model.toLowerCase().includes("anthropic.claude")));
|
|
5362
|
+
// JOHNNESS_PATCH_ANTHROPIC_CACHE_LONG_90: direct Anthropic uses 1h; Bedrock keeps its existing default.
|
|
5362
5363
|
for (const [key, entry] of Object.entries(nextModels)) {
|
|
5363
|
-
|
|
5364
|
+
const parsed = parseModelRef(key, "anthropic");
|
|
5365
|
+
if (!isAnthropicCacheRetentionTarget(parsed)) continue;
|
|
5364
5366
|
const current = entry ?? {};
|
|
5365
5367
|
const params = current.params ?? {};
|
|
5366
|
-
if (typeof params.cacheRetention === "string") continue;
|
|
5368
|
+
if (typeof params.cacheRetention === "string" || parsed.provider === "anthropic" && params.cacheControlTtl !== void 0) continue;
|
|
5367
5369
|
nextModels[key] = {
|
|
5368
5370
|
...current,
|
|
5369
5371
|
params: {
|
|
5370
5372
|
...params,
|
|
5371
|
-
cacheRetention: "short"
|
|
5373
|
+
cacheRetention: parsed.provider === "anthropic" ? "long" : "short"
|
|
5372
5374
|
}
|
|
5373
5375
|
};
|
|
5374
5376
|
modelsMutated = true;
|
|
@@ -5380,12 +5382,12 @@ function applyContextPruningDefaults(cfg) {
|
|
|
5380
5382
|
const key = `${parsedPrimary.provider}/${parsedPrimary.model}`;
|
|
5381
5383
|
const current = nextModels[key] ?? {};
|
|
5382
5384
|
const params = current.params ?? {};
|
|
5383
|
-
if (typeof params.cacheRetention !== "string") {
|
|
5385
|
+
if (typeof params.cacheRetention !== "string" && !(parsedPrimary.provider === "anthropic" && params.cacheControlTtl !== void 0)) {
|
|
5384
5386
|
nextModels[key] = {
|
|
5385
5387
|
...current,
|
|
5386
5388
|
params: {
|
|
5387
5389
|
...params,
|
|
5388
|
-
cacheRetention: "short"
|
|
5390
|
+
cacheRetention: parsedPrimary.provider === "anthropic" ? "long" : "short"
|
|
5389
5391
|
}
|
|
5390
5392
|
};
|
|
5391
5393
|
modelsMutated = true;
|
|
@@ -5359,16 +5359,18 @@ function applyContextPruningDefaults(cfg) {
|
|
|
5359
5359
|
const nextModels = defaults.models ? { ...defaults.models } : {};
|
|
5360
5360
|
let modelsMutated = false;
|
|
5361
5361
|
const isAnthropicCacheRetentionTarget = (parsed) => Boolean(parsed && (parsed.provider === "anthropic" || parsed.provider === "amazon-bedrock" && parsed.model.toLowerCase().includes("anthropic.claude")));
|
|
5362
|
+
// JOHNNESS_PATCH_ANTHROPIC_CACHE_LONG_90: direct Anthropic uses 1h; Bedrock keeps its existing default.
|
|
5362
5363
|
for (const [key, entry] of Object.entries(nextModels)) {
|
|
5363
|
-
|
|
5364
|
+
const parsed = parseModelRef(key, "anthropic");
|
|
5365
|
+
if (!isAnthropicCacheRetentionTarget(parsed)) continue;
|
|
5364
5366
|
const current = entry ?? {};
|
|
5365
5367
|
const params = current.params ?? {};
|
|
5366
|
-
if (typeof params.cacheRetention === "string") continue;
|
|
5368
|
+
if (typeof params.cacheRetention === "string" || parsed.provider === "anthropic" && params.cacheControlTtl !== void 0) continue;
|
|
5367
5369
|
nextModels[key] = {
|
|
5368
5370
|
...current,
|
|
5369
5371
|
params: {
|
|
5370
5372
|
...params,
|
|
5371
|
-
cacheRetention: "short"
|
|
5373
|
+
cacheRetention: parsed.provider === "anthropic" ? "long" : "short"
|
|
5372
5374
|
}
|
|
5373
5375
|
};
|
|
5374
5376
|
modelsMutated = true;
|
|
@@ -5380,12 +5382,12 @@ function applyContextPruningDefaults(cfg) {
|
|
|
5380
5382
|
const key = `${parsedPrimary.provider}/${parsedPrimary.model}`;
|
|
5381
5383
|
const current = nextModels[key] ?? {};
|
|
5382
5384
|
const params = current.params ?? {};
|
|
5383
|
-
if (typeof params.cacheRetention !== "string") {
|
|
5385
|
+
if (typeof params.cacheRetention !== "string" && !(parsedPrimary.provider === "anthropic" && params.cacheControlTtl !== void 0)) {
|
|
5384
5386
|
nextModels[key] = {
|
|
5385
5387
|
...current,
|
|
5386
5388
|
params: {
|
|
5387
5389
|
...params,
|
|
5388
|
-
cacheRetention: "short"
|
|
5390
|
+
cacheRetention: parsedPrimary.provider === "anthropic" ? "long" : "short"
|
|
5389
5391
|
}
|
|
5390
5392
|
};
|
|
5391
5393
|
modelsMutated = true;
|
|
@@ -5167,16 +5167,18 @@ function applyContextPruningDefaults(cfg) {
|
|
|
5167
5167
|
const nextModels = defaults.models ? { ...defaults.models } : {};
|
|
5168
5168
|
let modelsMutated = false;
|
|
5169
5169
|
const isAnthropicCacheRetentionTarget = (parsed) => Boolean(parsed && (parsed.provider === "anthropic" || parsed.provider === "amazon-bedrock" && parsed.model.toLowerCase().includes("anthropic.claude")));
|
|
5170
|
+
// JOHNNESS_PATCH_ANTHROPIC_CACHE_LONG_90: direct Anthropic uses 1h; Bedrock keeps its existing default.
|
|
5170
5171
|
for (const [key, entry] of Object.entries(nextModels)) {
|
|
5171
|
-
|
|
5172
|
+
const parsed = parseModelRef(key, "anthropic");
|
|
5173
|
+
if (!isAnthropicCacheRetentionTarget(parsed)) continue;
|
|
5172
5174
|
const current = entry ?? {};
|
|
5173
5175
|
const params = current.params ?? {};
|
|
5174
|
-
if (typeof params.cacheRetention === "string") continue;
|
|
5176
|
+
if (typeof params.cacheRetention === "string" || parsed.provider === "anthropic" && params.cacheControlTtl !== void 0) continue;
|
|
5175
5177
|
nextModels[key] = {
|
|
5176
5178
|
...current,
|
|
5177
5179
|
params: {
|
|
5178
5180
|
...params,
|
|
5179
|
-
cacheRetention: "short"
|
|
5181
|
+
cacheRetention: parsed.provider === "anthropic" ? "long" : "short"
|
|
5180
5182
|
}
|
|
5181
5183
|
};
|
|
5182
5184
|
modelsMutated = true;
|
|
@@ -5188,12 +5190,12 @@ function applyContextPruningDefaults(cfg) {
|
|
|
5188
5190
|
const key = `${parsedPrimary.provider}/${parsedPrimary.model}`;
|
|
5189
5191
|
const current = nextModels[key] ?? {};
|
|
5190
5192
|
const params = current.params ?? {};
|
|
5191
|
-
if (typeof params.cacheRetention !== "string") {
|
|
5193
|
+
if (typeof params.cacheRetention !== "string" && !(parsedPrimary.provider === "anthropic" && params.cacheControlTtl !== void 0)) {
|
|
5192
5194
|
nextModels[key] = {
|
|
5193
5195
|
...current,
|
|
5194
5196
|
params: {
|
|
5195
5197
|
...params,
|
|
5196
|
-
cacheRetention: "short"
|
|
5198
|
+
cacheRetention: parsedPrimary.provider === "anthropic" ? "long" : "short"
|
|
5197
5199
|
}
|
|
5198
5200
|
};
|
|
5199
5201
|
modelsMutated = true;
|
|
@@ -83943,7 +83943,7 @@ function resolveExtraParams(params) {
|
|
|
83943
83943
|
* OpenRouter uses openai-completions API with hardcoded cache_control instead
|
|
83944
83944
|
* of the cacheRetention stream option.
|
|
83945
83945
|
*
|
|
83946
|
-
*
|
|
83946
|
+
* JOHNNESS_PATCH_ANTHROPIC_CACHE_LONG_90: defaults to "long" for direct Anthropic (both auth modes).
|
|
83947
83947
|
*/
|
|
83948
83948
|
function resolveCacheRetention(extraParams, provider) {
|
|
83949
83949
|
const isAnthropicDirect = provider === "anthropic";
|
|
@@ -83955,10 +83955,12 @@ function resolveCacheRetention(extraParams, provider) {
|
|
|
83955
83955
|
if (legacy === "5m") return "short";
|
|
83956
83956
|
if (legacy === "1h") return "long";
|
|
83957
83957
|
if (!isAnthropicDirect) return;
|
|
83958
|
-
return "
|
|
83958
|
+
return "long";
|
|
83959
83959
|
}
|
|
83960
83960
|
function createStreamFnWithExtraParams(baseStreamFn, extraParams, provider) {
|
|
83961
|
-
|
|
83961
|
+
// JOHNNESS_PATCH_ANTHROPIC_CACHE_LONG_90: apply the Anthropic default even with no model params.
|
|
83962
|
+
if ((!extraParams || Object.keys(extraParams).length === 0) && provider !== "anthropic") return;
|
|
83963
|
+
extraParams ??= {};
|
|
83962
83964
|
const streamParams = {};
|
|
83963
83965
|
if (typeof extraParams.temperature === "number") streamParams.temperature = extraParams.temperature;
|
|
83964
83966
|
if (typeof extraParams.maxTokens === "number") streamParams.maxTokens = extraParams.maxTokens;
|
package/dist/reply-C5LKjXcC.js
CHANGED
|
@@ -75962,7 +75962,7 @@ function resolveExtraParams(params) {
|
|
|
75962
75962
|
* OpenRouter uses openai-completions API with hardcoded cache_control instead
|
|
75963
75963
|
* of the cacheRetention stream option.
|
|
75964
75964
|
*
|
|
75965
|
-
*
|
|
75965
|
+
* JOHNNESS_PATCH_ANTHROPIC_CACHE_LONG_90: defaults to "long" for direct Anthropic (both auth modes).
|
|
75966
75966
|
*/
|
|
75967
75967
|
function resolveCacheRetention(extraParams, provider) {
|
|
75968
75968
|
const isAnthropicDirect = provider === "anthropic";
|
|
@@ -75974,10 +75974,12 @@ function resolveCacheRetention(extraParams, provider) {
|
|
|
75974
75974
|
if (legacy === "5m") return "short";
|
|
75975
75975
|
if (legacy === "1h") return "long";
|
|
75976
75976
|
if (!isAnthropicDirect) return;
|
|
75977
|
-
return "
|
|
75977
|
+
return "long";
|
|
75978
75978
|
}
|
|
75979
75979
|
function createStreamFnWithExtraParams(baseStreamFn, extraParams, provider) {
|
|
75980
|
-
|
|
75980
|
+
// JOHNNESS_PATCH_ANTHROPIC_CACHE_LONG_90: apply the Anthropic default even with no model params.
|
|
75981
|
+
if ((!extraParams || Object.keys(extraParams).length === 0) && provider !== "anthropic") return;
|
|
75982
|
+
extraParams ??= {};
|
|
75981
75983
|
const streamParams = {};
|
|
75982
75984
|
if (typeof extraParams.temperature === "number") streamParams.temperature = extraParams.temperature;
|
|
75983
75985
|
if (typeof extraParams.maxTokens === "number") streamParams.maxTokens = extraParams.maxTokens;
|
package/docs/PATCHES.md
CHANGED
|
@@ -3017,3 +3017,49 @@ NO_REPLY, failed sends, block streaming, exact replay, idempotence and drift ref
|
|
|
3017
3017
|
**Replay:** `patches/subscription-activate-89/changes.json`, `scripts/patch-subscription-activate-89.py` (`--check` read-only, `--present-only`, `--record`), 13 files: login module (4 hunks), 2 gateway bundles (2 hunks each, identical), 10 reply bundles (6 hunks each, identical). Replayed from a clean checkout of c4c017b in a scratch worktree: all 13 files byte-identical to the shipped tree. `scripts/subscription_login_layer.py` and `tests/helpers/subscription-login-layer.mjs` strip and re-layer Family 89 with 86, 87 and 88; `scripts/patch-subscription-login-86.py` strips the 89 layer before comparing its pinned `dist/subscription-login.js` content and re-layers after a write, so 86 `--check` keeps passing; `tests/helpers/replay-family-67.mjs` replays 89 after 86, and the 65.1 historical reconstruction of the two gateway bundles replays 89 after 76 and 79. Verifier checks 89.1 to 89.8 (557 checks).
|
|
3018
3018
|
|
|
3019
3019
|
**Tests:** `tests/subscription-activate-89.test.mjs` (19 tests): manifest coverage and uniform hunks; picker trigger in all ten copies (auto override re-picks the subscription once the snapshot has it, user override never does); in-process, RPC and unavailable refresh paths never throw; Claude save refreshes after commit; both ChatGPT paths hand `hooks.publish` to the owner; status label prefers the served profile across all ten copies; idempotent replay, drift refusal before any writes, read-only check; strip and re-layer with 86, 87, 88; and an end-to-end run: an isolated gateway on a free port (never 18789) in a `/tmp` state dir with a mock Anthropic SSE endpoint, turn one on `agent:main:main` served with `x-api-key`, then a control save with the refresh off (next turn still `x-api-key`, the live bug), then the real save in a separate process (the CLI shape), and the very next turn of the same session id served with `Authorization: Bearer sk-ant-oat-...` and `authProfileServed: anthropic:subscription` in `sessions.json`. Rollback: `npm i -g johns-harness@2026.10.19`.
|
|
3020
|
+
|
|
3021
|
+
## 90. Direct Anthropic defaults to a one-hour prompt cache (2026-10-20)
|
|
3022
|
+
|
|
3023
|
+
**Why:** the five-minute default rewrote a large stable prompt after normal gaps between turns. A
|
|
3024
|
+
250k-token context repeatedly incurred cold cache writes instead of cheap reads. Make the useful
|
|
3025
|
+
cache lifetime the default, without requiring per-model configuration, for API keys and subscriptions.
|
|
3026
|
+
|
|
3027
|
+
**Changes:**
|
|
3028
|
+
- All ten `resolveCacheRetention` copies default direct `anthropic` to `long`. Explicit
|
|
3029
|
+
`none`/`short`/`long` and legacy `cacheControlTtl` mappings still win. The stream wrapper applies
|
|
3030
|
+
the default even if model params are absent or empty.
|
|
3031
|
+
- All fourteen smart-default config loaders seed `long` for direct Anthropic instead of masking
|
|
3032
|
+
the runtime default with `short`. Legacy direct Anthropic TTLs are not overwritten. Claude on
|
|
3033
|
+
Bedrock retains its `short` smart default, and non-Anthropic Bedrock behavior is unchanged.
|
|
3034
|
+
- The vendored and installed pi-ai adapter defaults direct Anthropic to `long` and sends the
|
|
3035
|
+
existing `{ type: "ephemeral", ttl: "1h" }` breakpoints on the Anthropic API endpoint for both
|
|
3036
|
+
auth paths. It adds `extended-cache-ttl-2025-04-11` after header merging, so an explicit beta header
|
|
3037
|
+
cannot accidentally drop it. Other providers, explicit cache choices and custom-endpoint TTL
|
|
3038
|
+
behavior stay unchanged.
|
|
3039
|
+
- Family 36 system splitting and Family 88 attribution are intact: stable prefix cached, volatile
|
|
3040
|
+
memory tail uncached, subscription attribution first and uncached. Subscription accounting is $0.
|
|
3041
|
+
|
|
3042
|
+
**Claude Code evidence:** the Family 88 capture from 2.1.292 used ephemeral controls (one optional
|
|
3043
|
+
`scope: "global"`), without a TTL on that API-key request. The 2.1.304 binary's `Obe` selector returns
|
|
3044
|
+
`{ttl:"1h", reason:"subscriber"}` for eligible subscriber turns; `e5` emits `type:"ephemeral"`,
|
|
3045
|
+
optional `ttl`, and optional global scope. The harness uses the same one-hour shape without claiming
|
|
3046
|
+
that its private instructions are globally shareable. No Family 88 attribution changes are needed.
|
|
3047
|
+
|
|
3048
|
+
**Replay:** `scripts/patch-anthropic-cache-long-90.py [root] [--check|--present-only|--dependency-only]`,
|
|
3049
|
+
exact reviewed manifest `patches/anthropic-cache-long-90/changes.json`. All targets preflight before
|
|
3050
|
+
writes. Historical hash-pinned families strip/re-layer 90 with 86 to 89; fixture replay adds it last.
|
|
3051
|
+
|
|
3052
|
+
**Tests:** `tests/anthropic-cache-long-90.test.mjs`, 36 tests across every runtime and config copy,
|
|
3053
|
+
real-adapter SSE wire assertions for both auth paths and each retention mode, legacy mappings,
|
|
3054
|
+
empty params, header merging, stable/volatile breakpoints, Bedrock unchanged, drift rejection and
|
|
3055
|
+
historical layer round trips. Verifier checks 90.1 to 90.7.
|
|
3056
|
+
|
|
3057
|
+
**Live proof:** `plans/archive/2026-10-20-anthropic-cache-long-90.md`. Real isolated Sonnet 5.5
|
|
3058
|
+
gateway sessions with no cache configuration: API read/write 0/31,332 then 31,332/61 after 387s;
|
|
3059
|
+
subscription 0/31,407 then 31,407/61 after 369s. Both subscription responses HTTP 200,
|
|
3060
|
+
`anthropic-ratelimit-unified-5h-status: allowed`, overage rejected (extra usage disabled). Both
|
|
3061
|
+
paths report cache creation exclusively under `ephemeral_1h`. The initial subscription attempt hit
|
|
3062
|
+
the already-exhausted five-hour limit; the successful proof waited for its reset header. No live
|
|
3063
|
+
gateway restart, live state access or new login. Verifier 564/564; full suite 1,249 pass, 5 existing skips.
|
|
3064
|
+
|
|
3065
|
+
**Rollback:** `npm i -g johns-harness@2026.10.20`.
|
|
@@ -21,7 +21,7 @@ Session pruning trims **old tool results** from the in-memory context right befo
|
|
|
21
21
|
## Smart defaults (Anthropic)
|
|
22
22
|
|
|
23
23
|
- **OAuth or setup-token** profiles: enable `cache-ttl` pruning and set heartbeat to `1h`.
|
|
24
|
-
- **API key** profiles: enable `cache-ttl` pruning, set heartbeat to `30m`, and default `cacheRetention: "
|
|
24
|
+
- **API key** profiles: enable `cache-ttl` pruning, set heartbeat to `30m`, and default `cacheRetention: "long"` on direct Anthropic models (Claude-on-Bedrock keeps `short`).
|
|
25
25
|
- If you set any of these values explicitly, Johnness does **not** override them.
|
|
26
26
|
|
|
27
27
|
## What this improves (cost + cache behavior)
|
|
@@ -46,7 +46,7 @@ johnness onboard --anthropic-api-key "$ANTHROPIC_API_KEY"
|
|
|
46
46
|
|
|
47
47
|
## Prompt caching (Anthropic API)
|
|
48
48
|
|
|
49
|
-
Johnness supports Anthropic
|
|
49
|
+
Johnness supports Anthropic prompt caching with **both API-key and Claude subscription authentication**. Direct Anthropic requests default to a one-hour cache; no model configuration is required.
|
|
50
50
|
|
|
51
51
|
### Configuration
|
|
52
52
|
|
|
@@ -74,7 +74,11 @@ Use the `cacheRetention` parameter in your model config:
|
|
|
74
74
|
|
|
75
75
|
### Defaults
|
|
76
76
|
|
|
77
|
-
|
|
77
|
+
For the direct `anthropic` provider, Johnness defaults to `cacheRetention: "long"` (1 hour) for both API-key and subscription requests, including models with no `params` entry. Explicit `none`, `short` and `long` values take priority, as does the legacy `cacheControlTtl` mapping when `cacheRetention` is absent.
|
|
78
|
+
|
|
79
|
+
On the Anthropic API endpoint, long retention sends `cache_control: { type: "ephemeral", ttl: "1h" }` at the existing cache breakpoints and adds `extended-cache-ttl-2025-04-11` to the beta header. The subscription envelope stays intact: the attribution block remains first and uncached, and changing memory context stays outside the stable system breakpoint. Custom proxy endpoints retain the adapter's existing TTL behavior.
|
|
80
|
+
|
|
81
|
+
One-hour API cache writes cost more than five-minute writes, but avoid rewriting the entire cached prefix after gaps longer than five minutes. Set `short` or `none` explicitly if that better fits your workload. Subscription requests keep subscription accounting and plan-limit routing; cache retention does not turn on extra usage.
|
|
78
82
|
|
|
79
83
|
### Per-agent cacheRetention overrides
|
|
80
84
|
|
|
@@ -121,8 +125,7 @@ The older `cacheControlTtl` parameter is still supported for backwards compatibi
|
|
|
121
125
|
|
|
122
126
|
We recommend migrating to the new `cacheRetention` parameter.
|
|
123
127
|
|
|
124
|
-
Johnness
|
|
125
|
-
requests; keep it if you override provider headers (see [/gateway/configuration](/gateway/configuration)).
|
|
128
|
+
Johnness adds the `extended-cache-ttl-2025-04-11` beta flag whenever it sends a one-hour TTL, for both API-key and subscription requests. The adapter preserves this flag even when provider or request headers supply additional betas (see [/gateway/configuration](/gateway/configuration)).
|
|
126
129
|
|
|
127
130
|
## 1M context window (Anthropic beta)
|
|
128
131
|
|
|
@@ -41,19 +41,20 @@ buildParams = function johnnessMasterAnthropicBuildParams(model, context, isOAut
|
|
|
41
41
|
/* JOHNNESS_MODELS_MASTER:END */
|
|
42
42
|
/**
|
|
43
43
|
* Resolve cache retention preference.
|
|
44
|
-
*
|
|
44
|
+
* JOHNNESS_PATCH_ANTHROPIC_CACHE_LONG_90: direct Anthropic defaults to 1h for API keys and subscriptions.
|
|
45
|
+
* Other providers and the legacy PI_CACHE_RETENTION override keep their behavior.
|
|
45
46
|
*/
|
|
46
|
-
function resolveCacheRetention(cacheRetention) {
|
|
47
|
+
function resolveCacheRetention(cacheRetention, provider) {
|
|
47
48
|
if (cacheRetention) {
|
|
48
49
|
return cacheRetention;
|
|
49
50
|
}
|
|
50
51
|
if (typeof process !== "undefined" && process.env.PI_CACHE_RETENTION === "long") {
|
|
51
52
|
return "long";
|
|
52
53
|
}
|
|
53
|
-
return "short";
|
|
54
|
+
return provider === "anthropic" ? "long" : "short";
|
|
54
55
|
}
|
|
55
|
-
function getCacheControl(baseUrl, cacheRetention) {
|
|
56
|
-
const retention = resolveCacheRetention(cacheRetention);
|
|
56
|
+
function getCacheControl(baseUrl, cacheRetention, provider) {
|
|
57
|
+
const retention = resolveCacheRetention(cacheRetention, provider);
|
|
57
58
|
if (retention === "none") {
|
|
58
59
|
return { retention };
|
|
59
60
|
}
|
|
@@ -221,7 +222,7 @@ export const streamAnthropic = (model, context, options) => {
|
|
|
221
222
|
hasImages,
|
|
222
223
|
});
|
|
223
224
|
}
|
|
224
|
-
const { client, isOAuthToken } = createClient(model, apiKey, options?.interleavedThinking ?? true, options?.headers, copilotDynamicHeaders);
|
|
225
|
+
const { client, isOAuthToken } = createClient(model, apiKey, options?.interleavedThinking ?? true, options?.headers, copilotDynamicHeaders, options?.cacheRetention);
|
|
225
226
|
// JOHNNESS_PATCH_SUBSCRIPTION_LOGIN_86: zero cost on subscription attempts only.
|
|
226
227
|
const billingModel = isOAuthToken ? { ...model, cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 } } : model;
|
|
227
228
|
const params = buildParams(model, context, isOAuthToken, options);
|
|
@@ -483,7 +484,18 @@ export const streamSimpleAnthropic = (model, context, options) => {
|
|
|
483
484
|
function isOAuthToken(apiKey) {
|
|
484
485
|
return apiKey.includes("sk-ant-oat");
|
|
485
486
|
}
|
|
486
|
-
|
|
487
|
+
// JOHNNESS_PATCH_ANTHROPIC_CACHE_LONG_90: keep the extended-cache beta on both auth paths, including
|
|
488
|
+
// explicit provider/request beta overrides. Claude Code 2.1.304 uses this same ephemeral ttl shape.
|
|
489
|
+
function withAnthropicCacheBeta(headers, model, cacheRetention) {
|
|
490
|
+
if (getCacheControl(model.baseUrl, cacheRetention, model.provider).cacheControl?.ttl !== "1h") return headers;
|
|
491
|
+
const merged = { ...headers };
|
|
492
|
+
const keys = Object.keys(merged).filter((key) => key.toLowerCase() === "anthropic-beta");
|
|
493
|
+
const betas = keys.flatMap((key) => String(merged[key] ?? "").split(",").map((value) => value.trim()).filter(Boolean));
|
|
494
|
+
for (const key of keys) delete merged[key];
|
|
495
|
+
merged["anthropic-beta"] = [...new Set([...betas, "extended-cache-ttl-2025-04-11"])].join(",");
|
|
496
|
+
return merged;
|
|
497
|
+
}
|
|
498
|
+
function createClient(model, apiKey, interleavedThinking, optionsHeaders, dynamicHeaders, cacheRetention) {
|
|
487
499
|
// Adaptive thinking models (Opus 4.6, Sonnet 4.6) have interleaved thinking built-in.
|
|
488
500
|
// The beta header is deprecated on Opus 4.6 and redundant on Sonnet 4.6, so skip it.
|
|
489
501
|
const needsInterleavedBeta = interleavedThinking && !supportsAdaptiveThinking(model.id);
|
|
@@ -519,13 +531,13 @@ function createClient(model, apiKey, interleavedThinking, optionsHeaders, dynami
|
|
|
519
531
|
baseURL: model.baseUrl,
|
|
520
532
|
maxRetries: 0,
|
|
521
533
|
dangerouslyAllowBrowser: true,
|
|
522
|
-
defaultHeaders: mergeHeaders({
|
|
534
|
+
defaultHeaders: withAnthropicCacheBeta(mergeHeaders({
|
|
523
535
|
accept: "application/json",
|
|
524
536
|
"anthropic-dangerous-direct-browser-access": "true",
|
|
525
537
|
"anthropic-beta": `claude-code-20250219,oauth-2025-04-20,${betaFeatures.join(",")}`,
|
|
526
538
|
"user-agent": claudeCodeUserAgent(), // JOHNNESS_PATCH_SUBSCRIPTION_PLAN_LIMITS_88
|
|
527
539
|
"x-app": "cli",
|
|
528
|
-
}, model.headers, optionsHeaders),
|
|
540
|
+
}, model.headers, optionsHeaders), model, cacheRetention),
|
|
529
541
|
});
|
|
530
542
|
return { client, isOAuthToken: true };
|
|
531
543
|
}
|
|
@@ -535,11 +547,11 @@ function createClient(model, apiKey, interleavedThinking, optionsHeaders, dynami
|
|
|
535
547
|
baseURL: model.baseUrl,
|
|
536
548
|
maxRetries: 0,
|
|
537
549
|
dangerouslyAllowBrowser: true,
|
|
538
|
-
defaultHeaders: mergeHeaders({
|
|
550
|
+
defaultHeaders: withAnthropicCacheBeta(mergeHeaders({
|
|
539
551
|
accept: "application/json",
|
|
540
552
|
"anthropic-dangerous-direct-browser-access": "true",
|
|
541
553
|
"anthropic-beta": betaFeatures.join(","),
|
|
542
|
-
}, model.headers, optionsHeaders),
|
|
554
|
+
}, model.headers, optionsHeaders), model, cacheRetention),
|
|
543
555
|
});
|
|
544
556
|
return { client, isOAuthToken: false };
|
|
545
557
|
}
|
|
@@ -586,7 +598,7 @@ function buildAnthropicSystemBlocks(systemPrompt, cacheControl) {
|
|
|
586
598
|
];
|
|
587
599
|
}
|
|
588
600
|
function buildParams(model, context, isOAuthToken, options) {
|
|
589
|
-
const { cacheControl } = getCacheControl(model.baseUrl, options?.cacheRetention);
|
|
601
|
+
const { cacheControl } = getCacheControl(model.baseUrl, options?.cacheRetention, model.provider);
|
|
590
602
|
const params = {
|
|
591
603
|
model: model.id,
|
|
592
604
|
messages: convertMessages(context.messages, model, isOAuthToken, cacheControl),
|
package/package.json
CHANGED
|
@@ -41,19 +41,20 @@ buildParams = function johnnessMasterAnthropicBuildParams(model, context, isOAut
|
|
|
41
41
|
/* JOHNNESS_MODELS_MASTER:END */
|
|
42
42
|
/**
|
|
43
43
|
* Resolve cache retention preference.
|
|
44
|
-
*
|
|
44
|
+
* JOHNNESS_PATCH_ANTHROPIC_CACHE_LONG_90: direct Anthropic defaults to 1h for API keys and subscriptions.
|
|
45
|
+
* Other providers and the legacy PI_CACHE_RETENTION override keep their behavior.
|
|
45
46
|
*/
|
|
46
|
-
function resolveCacheRetention(cacheRetention) {
|
|
47
|
+
function resolveCacheRetention(cacheRetention, provider) {
|
|
47
48
|
if (cacheRetention) {
|
|
48
49
|
return cacheRetention;
|
|
49
50
|
}
|
|
50
51
|
if (typeof process !== "undefined" && process.env.PI_CACHE_RETENTION === "long") {
|
|
51
52
|
return "long";
|
|
52
53
|
}
|
|
53
|
-
return "short";
|
|
54
|
+
return provider === "anthropic" ? "long" : "short";
|
|
54
55
|
}
|
|
55
|
-
function getCacheControl(baseUrl, cacheRetention) {
|
|
56
|
-
const retention = resolveCacheRetention(cacheRetention);
|
|
56
|
+
function getCacheControl(baseUrl, cacheRetention, provider) {
|
|
57
|
+
const retention = resolveCacheRetention(cacheRetention, provider);
|
|
57
58
|
if (retention === "none") {
|
|
58
59
|
return { retention };
|
|
59
60
|
}
|
|
@@ -221,7 +222,7 @@ export const streamAnthropic = (model, context, options) => {
|
|
|
221
222
|
hasImages,
|
|
222
223
|
});
|
|
223
224
|
}
|
|
224
|
-
const { client, isOAuthToken } = createClient(model, apiKey, options?.interleavedThinking ?? true, options?.headers, copilotDynamicHeaders);
|
|
225
|
+
const { client, isOAuthToken } = createClient(model, apiKey, options?.interleavedThinking ?? true, options?.headers, copilotDynamicHeaders, options?.cacheRetention);
|
|
225
226
|
// JOHNNESS_PATCH_SUBSCRIPTION_LOGIN_86: zero cost on subscription attempts only.
|
|
226
227
|
const billingModel = isOAuthToken ? { ...model, cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 } } : model;
|
|
227
228
|
const params = buildParams(model, context, isOAuthToken, options);
|
|
@@ -483,7 +484,18 @@ export const streamSimpleAnthropic = (model, context, options) => {
|
|
|
483
484
|
function isOAuthToken(apiKey) {
|
|
484
485
|
return apiKey.includes("sk-ant-oat");
|
|
485
486
|
}
|
|
486
|
-
|
|
487
|
+
// JOHNNESS_PATCH_ANTHROPIC_CACHE_LONG_90: keep the extended-cache beta on both auth paths, including
|
|
488
|
+
// explicit provider/request beta overrides. Claude Code 2.1.304 uses this same ephemeral ttl shape.
|
|
489
|
+
function withAnthropicCacheBeta(headers, model, cacheRetention) {
|
|
490
|
+
if (getCacheControl(model.baseUrl, cacheRetention, model.provider).cacheControl?.ttl !== "1h") return headers;
|
|
491
|
+
const merged = { ...headers };
|
|
492
|
+
const keys = Object.keys(merged).filter((key) => key.toLowerCase() === "anthropic-beta");
|
|
493
|
+
const betas = keys.flatMap((key) => String(merged[key] ?? "").split(",").map((value) => value.trim()).filter(Boolean));
|
|
494
|
+
for (const key of keys) delete merged[key];
|
|
495
|
+
merged["anthropic-beta"] = [...new Set([...betas, "extended-cache-ttl-2025-04-11"])].join(",");
|
|
496
|
+
return merged;
|
|
497
|
+
}
|
|
498
|
+
function createClient(model, apiKey, interleavedThinking, optionsHeaders, dynamicHeaders, cacheRetention) {
|
|
487
499
|
// Adaptive thinking models (Opus 4.6, Sonnet 4.6) have interleaved thinking built-in.
|
|
488
500
|
// The beta header is deprecated on Opus 4.6 and redundant on Sonnet 4.6, so skip it.
|
|
489
501
|
const needsInterleavedBeta = interleavedThinking && !supportsAdaptiveThinking(model.id);
|
|
@@ -519,13 +531,13 @@ function createClient(model, apiKey, interleavedThinking, optionsHeaders, dynami
|
|
|
519
531
|
baseURL: model.baseUrl,
|
|
520
532
|
maxRetries: 0,
|
|
521
533
|
dangerouslyAllowBrowser: true,
|
|
522
|
-
defaultHeaders: mergeHeaders({
|
|
534
|
+
defaultHeaders: withAnthropicCacheBeta(mergeHeaders({
|
|
523
535
|
accept: "application/json",
|
|
524
536
|
"anthropic-dangerous-direct-browser-access": "true",
|
|
525
537
|
"anthropic-beta": `claude-code-20250219,oauth-2025-04-20,${betaFeatures.join(",")}`,
|
|
526
538
|
"user-agent": claudeCodeUserAgent(), // JOHNNESS_PATCH_SUBSCRIPTION_PLAN_LIMITS_88
|
|
527
539
|
"x-app": "cli",
|
|
528
|
-
}, model.headers, optionsHeaders),
|
|
540
|
+
}, model.headers, optionsHeaders), model, cacheRetention),
|
|
529
541
|
});
|
|
530
542
|
return { client, isOAuthToken: true };
|
|
531
543
|
}
|
|
@@ -535,11 +547,11 @@ function createClient(model, apiKey, interleavedThinking, optionsHeaders, dynami
|
|
|
535
547
|
baseURL: model.baseUrl,
|
|
536
548
|
maxRetries: 0,
|
|
537
549
|
dangerouslyAllowBrowser: true,
|
|
538
|
-
defaultHeaders: mergeHeaders({
|
|
550
|
+
defaultHeaders: withAnthropicCacheBeta(mergeHeaders({
|
|
539
551
|
accept: "application/json",
|
|
540
552
|
"anthropic-dangerous-direct-browser-access": "true",
|
|
541
553
|
"anthropic-beta": betaFeatures.join(","),
|
|
542
|
-
}, model.headers, optionsHeaders),
|
|
554
|
+
}, model.headers, optionsHeaders), model, cacheRetention),
|
|
543
555
|
});
|
|
544
556
|
return { client, isOAuthToken: false };
|
|
545
557
|
}
|
|
@@ -586,7 +598,7 @@ function buildAnthropicSystemBlocks(systemPrompt, cacheControl) {
|
|
|
586
598
|
];
|
|
587
599
|
}
|
|
588
600
|
function buildParams(model, context, isOAuthToken, options) {
|
|
589
|
-
const { cacheControl } = getCacheControl(model.baseUrl, options?.cacheRetention);
|
|
601
|
+
const { cacheControl } = getCacheControl(model.baseUrl, options?.cacheRetention, model.provider);
|
|
590
602
|
const params = {
|
|
591
603
|
model: model.id,
|
|
592
604
|
messages: convertMessages(context.messages, model, isOAuthToken, cacheControl),
|