opencode-anthropic-fix 0.1.13 → 0.1.14
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/index.mjs +25 -1
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -3721,7 +3721,7 @@ export async function AnthropicAuthPlugin({ client, project, directory, worktree
|
|
|
3721
3721
|
cacheBreakState.lastAlertTurn !== sessionMetrics.turns
|
|
3722
3722
|
) {
|
|
3723
3723
|
const drop = cacheBreakState.prevCacheRead - cacheRead;
|
|
3724
|
-
let alertMsg = `Cache break detected (
|
|
3724
|
+
let alertMsg = `Cache break detected (−${drop.toLocaleString()} tokens)`;
|
|
3725
3725
|
|
|
3726
3726
|
// Identify changed sources if we have pending hashes
|
|
3727
3727
|
if (cacheBreakState._pendingHashes && cacheBreakState.sourceHashes.size > 0) {
|
|
@@ -4327,6 +4327,30 @@ function extractCacheSourceHashes(bodyStr, parsedBody = undefined) {
|
|
|
4327
4327
|
}
|
|
4328
4328
|
}
|
|
4329
4329
|
}
|
|
4330
|
+
|
|
4331
|
+
// Hash messages prefix (everything except the last message) so we can
|
|
4332
|
+
// detect when the conversation history prefix changes byte-for-byte
|
|
4333
|
+
// between turns — a common cause of prompt-cache invalidation that
|
|
4334
|
+
// system_prompt/tool hashes alone don't explain.
|
|
4335
|
+
if (Array.isArray(parsed.messages) && parsed.messages.length > 1) {
|
|
4336
|
+
const prefix = parsed.messages.slice(0, -1);
|
|
4337
|
+
// Strip cache_control markers before hashing — they're legitimately
|
|
4338
|
+
// re-stamped each turn and shouldn't trigger a false positive.
|
|
4339
|
+
const normalized = prefix.map((m) => {
|
|
4340
|
+
if (!Array.isArray(m.content)) return m;
|
|
4341
|
+
return {
|
|
4342
|
+
...m,
|
|
4343
|
+
content: m.content.map((b) => {
|
|
4344
|
+
if (b && typeof b === "object" && b.cache_control) {
|
|
4345
|
+
const { cache_control: _cc, ...rest } = b;
|
|
4346
|
+
return rest;
|
|
4347
|
+
}
|
|
4348
|
+
return b;
|
|
4349
|
+
}),
|
|
4350
|
+
};
|
|
4351
|
+
});
|
|
4352
|
+
hashes.set("messages_prefix", hashCacheSource(JSON.stringify(normalized)));
|
|
4353
|
+
}
|
|
4330
4354
|
} catch {
|
|
4331
4355
|
// Ignore parse errors
|
|
4332
4356
|
}
|