opencode-anthropic-fix 0.1.29 → 0.1.30
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 +29 -11
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -8293,9 +8293,34 @@ function transformRequestBody(body, signature, runtime, betaHeader, config) {
|
|
|
8293
8293
|
const modelId = parsed.model || "";
|
|
8294
8294
|
// Extract first user message text for billing hash computation (cch)
|
|
8295
8295
|
const firstUserMessage = extractFirstUserMessageText(parsed.messages);
|
|
8296
|
+
// Resolve the prompt-cache TTL ONCE so system blocks, tools, and messages
|
|
8297
|
+
// all share the SAME ttl. Anthropic processes cache_control blocks in the
|
|
8298
|
+
// order tools → system → messages and rejects any ttl='1h' block that comes
|
|
8299
|
+
// AFTER a ttl='5m' block. Before this fix the role-scoped 5m downgrade was
|
|
8300
|
+
// applied only to tools/messages (resolveCacheTtl in the breakpoint loop)
|
|
8301
|
+
// while the system blocks kept the configured 1h — so subagent requests
|
|
8302
|
+
// (5m tools, then 1h system) tripped:
|
|
8303
|
+
// "system.1.cache_control.ttl: a ttl='1h' cache_control block must not
|
|
8304
|
+
// come after a ttl='5m' cache_control block".
|
|
8305
|
+
// Threading it through buildSystemPromptBlocks keeps every cache_control ttl
|
|
8306
|
+
// consistent (real CC derives the ttl uniformly from querySource).
|
|
8307
|
+
const baseCachePolicy = signature.cachePolicy || { ttl: "1h", ttl_supported: true };
|
|
8308
|
+
const cachingEnabledForTtl = baseCachePolicy.ttl !== "off" && baseCachePolicy.ttl_supported !== false;
|
|
8309
|
+
const resolvedCacheTtl = cachingEnabledForTtl
|
|
8310
|
+
? resolveCacheTtl({
|
|
8311
|
+
configuredTtl: baseCachePolicy.ttl || "1h",
|
|
8312
|
+
roleScopedTtl: config?.token_economy?.role_scoped_cache_ttl !== false,
|
|
8313
|
+
isMainForCache: runtime?.requestRole === "main" || runtime?.requestRole == null,
|
|
8314
|
+
isSubagent: runtime?.isSubagent === true,
|
|
8315
|
+
env: process.env,
|
|
8316
|
+
})
|
|
8317
|
+
: baseCachePolicy.ttl;
|
|
8296
8318
|
const signatureWithModel = {
|
|
8297
8319
|
...signature,
|
|
8298
8320
|
modelId,
|
|
8321
|
+
// Override cachePolicy.ttl with the role/subagent-resolved ttl so the
|
|
8322
|
+
// system blocks match the tool/message breakpoint ttl (see comment above).
|
|
8323
|
+
cachePolicy: { ...baseCachePolicy, ttl: resolvedCacheTtl },
|
|
8299
8324
|
firstUserMessage,
|
|
8300
8325
|
antiVerbosity: config?.anti_verbosity,
|
|
8301
8326
|
// Role-aware system-prompt leaning: for non-main-thread requests (title,
|
|
@@ -8393,17 +8418,10 @@ function transformRequestBody(body, signature, runtime, betaHeader, config) {
|
|
|
8393
8418
|
// We map step 4 via classifyRequestRole: main (interactive/auto_mode thread)
|
|
8394
8419
|
// → 1h; side-queries (title-gen, etc.) → 5m. The env vars are honored
|
|
8395
8420
|
// exactly as CC does, giving the user a manual override + mimicry fidelity.
|
|
8396
|
-
|
|
8397
|
-
|
|
8398
|
-
|
|
8399
|
-
const
|
|
8400
|
-
const ccTtl = resolveCacheTtl({
|
|
8401
|
-
configuredTtl,
|
|
8402
|
-
roleScopedTtl,
|
|
8403
|
-
isMainForCache,
|
|
8404
|
-
isSubagent: isSubagentForCache,
|
|
8405
|
-
env: process.env,
|
|
8406
|
-
});
|
|
8421
|
+
// Reuse the request-wide resolved ttl (computed above where
|
|
8422
|
+
// signatureWithModel is built) so tools/messages match the system blocks
|
|
8423
|
+
// and never trip the 1h-after-5m ordering rule on subagent requests.
|
|
8424
|
+
const ccTtl = resolvedCacheTtl;
|
|
8407
8425
|
if (Array.isArray(parsed.tools) && parsed.tools.length > 0) {
|
|
8408
8426
|
for (const tool of parsed.tools) {
|
|
8409
8427
|
if (tool.cache_control) delete tool.cache_control;
|