@xtruder/opencode-claude-max-plugin 0.1.16 → 0.1.17

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/build/cch.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Compute the 5-char hex CCH hash for a request body containing the
3
+ * `cch=00000` placeholder.
4
+ */
5
+ export declare function computeCch(body: string): Promise<string>;
6
+ /**
7
+ * Replace the `cch=00000` placeholder in the body with the computed hash.
8
+ * Only replaces the first occurrence to avoid mutating user message content.
9
+ */
10
+ export declare function replaceCchPlaceholder(body: string, cch: string): string;
11
+ /** Check whether the body contains the CCH placeholder. */
12
+ export declare function hasCchPlaceholder(body: string): boolean;
13
+ //# sourceMappingURL=cch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cch.d.ts","sourceRoot":"","sources":["../src/cch.ts"],"names":[],"mappings":"AA+BA;;;GAGG;AACH,wBAAsB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAI9D;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAEvE;AAED,2DAA2D;AAC3D,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEvD"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AACvD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAgGjD,MAAM,WAAW,2BAA2B;IAC1C;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;IAEf;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;IAEhB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,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,eAAe,CAAA;CAChD;AA4BD;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,GAAE,2BAAgC,GACxC,oBAAoB,CAkItB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,kBAAkB,EAAE,MAoBhC,CAAA;AAID,eAAe,kBAAkB,CAAA"}
package/build/index.js CHANGED
@@ -1078,6 +1078,30 @@ class AnthropicSDKModel {
1078
1078
  }
1079
1079
  }
1080
1080
 
1081
+ // src/cch.ts
1082
+ import xxhashInit from "xxhash-wasm";
1083
+ var CCH_SEED = 0x6e52736ac806831en;
1084
+ var CCH_PLACEHOLDER = "cch=00000";
1085
+ var CCH_MASK = 0xfffffn;
1086
+ var hasherPromise = null;
1087
+ function getHasher() {
1088
+ if (!hasherPromise) {
1089
+ hasherPromise = xxhashInit();
1090
+ }
1091
+ return hasherPromise;
1092
+ }
1093
+ async function computeCch(body) {
1094
+ const hasher = await getHasher();
1095
+ const hash = hasher.h64Raw(new TextEncoder().encode(body), CCH_SEED);
1096
+ return (hash & CCH_MASK).toString(16).padStart(5, "0");
1097
+ }
1098
+ function replaceCchPlaceholder(body, cch) {
1099
+ return body.replace(CCH_PLACEHOLDER, `cch=${cch}`);
1100
+ }
1101
+ function hasCchPlaceholder(body) {
1102
+ return body.includes(CCH_PLACEHOLDER);
1103
+ }
1104
+
1081
1105
  // src/index.ts
1082
1106
  var CLAUDE_CODE_VERSION = "2.1.81";
1083
1107
  var OAUTH_BETAS = [
@@ -1192,6 +1216,12 @@ function createAnthropicSDK(options = {}) {
1192
1216
  init = { ...init, headers: betaHeaders };
1193
1217
  }
1194
1218
  }
1219
+ if (auth.isOAuth && init?.body && typeof init.body === "string" && hasCchPlaceholder(init.body)) {
1220
+ try {
1221
+ const cch = await computeCch(init.body);
1222
+ init = { ...init, body: replaceCchPlaceholder(init.body, cch) };
1223
+ } catch {}
1224
+ }
1195
1225
  const resp = await baseFetch(url, init);
1196
1226
  const h5 = resp.headers.get("anthropic-ratelimit-unified-5h-utilization");
1197
1227
  if (h5 != null) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xtruder/opencode-claude-max-plugin",
3
- "version": "0.1.16",
3
+ "version": "0.1.17",
4
4
  "description": "OpenCode plugin for Claude Max/Pro subscription via @anthropic-ai/sdk - uses Claude Code OAuth credentials",
5
5
  "keywords": [
6
6
  "ai-sdk",
@@ -34,7 +34,8 @@
34
34
  "prepare": "simple-git-hooks"
35
35
  },
36
36
  "dependencies": {
37
- "@anthropic-ai/sdk": "0.74.0"
37
+ "@anthropic-ai/sdk": "0.74.0",
38
+ "xxhash-wasm": "^1.1.0"
38
39
  },
39
40
  "devDependencies": {
40
41
  "@ai-sdk/provider": "3.0.8",