opencode-cache-engine 0.3.2 → 0.3.3
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/package.json +1 -1
- package/src/cache-engine.ts +8 -7
- package/test/cache-engine.test.mjs +22 -4
package/package.json
CHANGED
package/src/cache-engine.ts
CHANGED
|
@@ -482,17 +482,18 @@ export const CacheEngine: Plugin = async ({ client, directory }) => {
|
|
|
482
482
|
// use a deterministic separate namespace (<root>:compact) so a compaction
|
|
483
483
|
// cache write never interferes with the useful live-session cache.
|
|
484
484
|
//
|
|
485
|
-
// MiMo-V2.6 + OpenRouter session affinity. Gate on the actual
|
|
486
|
-
// provider identity as well as the detected family; a matching
|
|
487
|
-
// on a direct endpoint is not sufficient. The runtime merges
|
|
488
|
-
// before this hook's output, so preserve a case-insensitive
|
|
489
|
-
// earlier-plugin x-session-id rather than silently overwriting
|
|
490
|
-
// add the deterministic ID derived from the logical
|
|
485
|
+
// MiMo-V2.6 / GLM-5.3 + OpenRouter session affinity. Gate on the actual
|
|
486
|
+
// OpenCode provider identity as well as the detected family; a matching
|
|
487
|
+
// model slug on a direct endpoint is not sufficient. The runtime merges
|
|
488
|
+
// model.headers before this hook's output, so preserve a case-insensitive
|
|
489
|
+
// user/model or earlier-plugin x-session-id rather than silently overwriting
|
|
490
|
+
// it. Otherwise add the deterministic ID derived from the logical session.
|
|
491
491
|
"chat.headers": async (input, output) => {
|
|
492
492
|
try {
|
|
493
493
|
const model = input.model as unknown as ChatParamsModel
|
|
494
494
|
const providerID = String(model?.providerID ?? "")
|
|
495
|
-
|
|
495
|
+
const family = detectPolicy(model)
|
|
496
|
+
if (providerID !== "openrouter" || (family !== POLICY_MIMO26 && family !== POLICY_GLM53)) return
|
|
496
497
|
|
|
497
498
|
const hasSessionIDHeader = (headers?: Record<string, string>) =>
|
|
498
499
|
Object.keys(headers ?? {}).some((name) => name.toLowerCase() === "x-session-id")
|
|
@@ -1052,7 +1052,11 @@ async function runMiMoHeaderHookProbe() {
|
|
|
1052
1052
|
const direct = await invoke({ ...mimoOpenRouter, providerID: "xiaomi" }, "ses_direct", { "User-Agent": "preserve-me" })
|
|
1053
1053
|
const unknown = await invoke({ ...mimoOpenRouter, providerID: "unknown-provider" }, "ses_unknown")
|
|
1054
1054
|
const missingProvider = await invoke({ ...mimoOpenRouter, providerID: undefined }, "ses_missing_provider")
|
|
1055
|
-
const
|
|
1055
|
+
const glmOpenRouter = { providerID: "openrouter", id: "z-ai/glm-5.3", api: { id: "z-ai/glm-5.3" }, headers: {} }
|
|
1056
|
+
const glm1 = await invoke(glmOpenRouter, "ses_glm_same")
|
|
1057
|
+
const glm2 = await invoke(glmOpenRouter, "ses_glm_same")
|
|
1058
|
+
const glmDifferent = await invoke(glmOpenRouter, "ses_glm_other")
|
|
1059
|
+
const glmDirect = await invoke({ ...glmOpenRouter, providerID: "zai" }, "ses_glm_direct", { "User-Agent": "preserve-glm" })
|
|
1056
1060
|
const configured = await invoke({
|
|
1057
1061
|
...mimoOpenRouter,
|
|
1058
1062
|
headers: { "X-Session-Id": "user-configured-value" },
|
|
@@ -1065,12 +1069,17 @@ async function runMiMoHeaderHookProbe() {
|
|
|
1065
1069
|
direct,
|
|
1066
1070
|
unknown,
|
|
1067
1071
|
missingProvider,
|
|
1068
|
-
|
|
1072
|
+
glm1,
|
|
1073
|
+
glm2,
|
|
1074
|
+
glmDifferent,
|
|
1075
|
+
glmDirect,
|
|
1069
1076
|
configured,
|
|
1070
1077
|
configuredModelHeaders: configured.modelHeaders,
|
|
1071
1078
|
earlierPlugin,
|
|
1072
1079
|
expectedSame: mimoSessionIdFor("ses_same"),
|
|
1073
1080
|
expectedOther: mimoSessionIdFor("ses_other"),
|
|
1081
|
+
expectedGlm: mimoSessionIdFor("ses_glm_same"),
|
|
1082
|
+
expectedGlmOther: mimoSessionIdFor("ses_glm_other"),
|
|
1074
1083
|
}
|
|
1075
1084
|
assert.equal(configured.headers["x-session-id"], undefined)
|
|
1076
1085
|
assert.equal(earlierPlugin.headers["X-SESSION-ID"], "earlier-plugin-value")
|
|
@@ -1117,7 +1126,16 @@ test("MiMo affinity preserves existing x-session-id values case-insensitively",
|
|
|
1117
1126
|
assert.deepEqual(result.earlierPlugin.headers, { "X-SESSION-ID": "earlier-plugin-value" })
|
|
1118
1127
|
})
|
|
1119
1128
|
|
|
1120
|
-
test("
|
|
1129
|
+
test("GLM/OpenRouter attaches the deterministic session ID", async () => {
|
|
1121
1130
|
const result = await miMoHeaderResults()
|
|
1122
|
-
assert.equal(result.
|
|
1131
|
+
assert.equal(result.glm1.headers["x-session-id"], result.expectedGlm)
|
|
1132
|
+
assert.equal(result.glm2.headers["x-session-id"], result.expectedGlm)
|
|
1133
|
+
assert.equal(result.glmDifferent.headers["x-session-id"], result.expectedGlmOther)
|
|
1134
|
+
assert.notEqual(result.glmDifferent.headers["x-session-id"], result.glm1.headers["x-session-id"])
|
|
1135
|
+
})
|
|
1136
|
+
|
|
1137
|
+
test("GLM direct Z.AI does not receive x-session-id", async () => {
|
|
1138
|
+
const result = await miMoHeaderResults()
|
|
1139
|
+
assert.equal(result.glmDirect.headers["x-session-id"], undefined)
|
|
1140
|
+
assert.deepEqual(result.glmDirect.headers, { "User-Agent": "preserve-glm" })
|
|
1123
1141
|
})
|