opencode-anthropic-fix 2.1.0 → 2.1.1

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 CHANGED
@@ -97,8 +97,13 @@ import {
97
97
  isOpus47Model,
98
98
  isOpus48Model,
99
99
  } from "./lib/mimicry/wire-compat.mjs";
100
-
101
- export { isFable5Model, isMythos5Model, isAdaptiveThinkingModel } from "./lib/mimicry/wire-compat.mjs";
100
+ import {
101
+ createDebugCorrelationId,
102
+ isDebugSinkEnabled,
103
+ createDebugRequestDump,
104
+ createDebugOutgoingHeadersEntry,
105
+ createDebugResponseHeadersEntry,
106
+ } from "./lib/debug-dump.mjs";
102
107
 
103
108
  // Max times a single logical request may fall back from fast->standard speed on
104
109
  // the same account before giving up the fast attempt entirely. 1 is enough: one
@@ -4718,24 +4723,6 @@ export async function AnthropicAuthPlugin({ client }) {
4718
4723
  /** Module-level config ref for functions outside AnthropicAuthPlugin closure. */
4719
4724
  let _pluginConfig = null;
4720
4725
 
4721
- const _debugSessionId = randomUUID().slice(0, 8);
4722
- let _debugReqSeq = 0;
4723
-
4724
- export function createDebugCorrelationId() {
4725
- return `${_debugSessionId}-${(++_debugReqSeq).toString(36).padStart(4, "0")}`;
4726
- }
4727
-
4728
- export function isDebugSinkEnabled(config, sink) {
4729
- return sink === "body" ? config.token_economy?.debug_dump_bodies === true : Boolean(config.debug);
4730
- }
4731
-
4732
- export function createDebugRequestDump(correlationId, timestamp, finalBody) {
4733
- return {
4734
- filename: `req-${timestamp}-${correlationId}.json`,
4735
- content: JSON.stringify({ correlationId, timestamp, bodyRedacted: redactString(finalBody) }),
4736
- };
4737
- }
4738
-
4739
4726
  async function writeSseCapture(correlationId, buf, truncated) {
4740
4727
  const fs = await import("node:fs");
4741
4728
  const path = await import("node:path");
@@ -4756,23 +4743,6 @@ async function writeSseCapture(correlationId, buf, truncated) {
4756
4743
  );
4757
4744
  }
4758
4745
 
4759
- export function createDebugOutgoingHeadersEntry(correlationId, timestamp, requestHeaders) {
4760
- return [
4761
- `\n=== ${timestamp} | corr=${correlationId} | OUTGOING request headers ===`,
4762
- JSON.stringify(redactSecrets(requestHeaders), null, 2),
4763
- "",
4764
- ].join("\n");
4765
- }
4766
-
4767
- export function createDebugResponseHeadersEntry(correlationId, timestamp, response, debugHeaders) {
4768
- return [
4769
- `\n=== ${timestamp} | corr=${correlationId} | status=${response.status} ok=${response.ok} account=${debugHeaders.account} mgr=${debugHeaders.accountManager} ===`,
4770
- `Rate-limit headers: ${JSON.stringify(debugHeaders.rateLimitHeaders, null, 2)}`,
4771
- `All headers: ${JSON.stringify(debugHeaders.allHeaders, null, 2)}`,
4772
- "",
4773
- ].join("\n");
4774
- }
4775
-
4776
4746
  // ---------------------------------------------------------------------------
4777
4747
  // Adaptive 1M context state
4778
4748
  // ---------------------------------------------------------------------------
@@ -0,0 +1,87 @@
1
+ /**
2
+ * Debug-dump helpers for the request/response debug sinks (`config.debug`,
3
+ * `token_economy.debug_dump_bodies`).
4
+ *
5
+ * These are plain helper functions, NOT plugin factories. They must never be
6
+ * re-exported from `index.mjs`: opencode's plugin loader iterates
7
+ * `Object.values(mod)` of the plugin entry module and calls every export as a
8
+ * plugin factory with the plugin input object (`{ client, ... }`, no
9
+ * `response`), then throws "Plugin export is not a function" / crashes on
10
+ * `response.status` for any export that isn't one. See
11
+ * `test/conformance/plugin-entry-exports.test.mjs`.
12
+ */
13
+ import { randomUUID } from "node:crypto";
14
+ import { redactSecrets, redactString } from "./redact.mjs";
15
+
16
+ const _debugSessionId = randomUUID().slice(0, 8);
17
+ let _debugReqSeq = 0;
18
+
19
+ /**
20
+ * Create a short, human-scannable id correlating the outgoing request debug
21
+ * dump with its response debug dump.
22
+ *
23
+ * @returns {string}
24
+ */
25
+ export function createDebugCorrelationId() {
26
+ return `${_debugSessionId}-${(++_debugReqSeq).toString(36).padStart(4, "0")}`;
27
+ }
28
+
29
+ /**
30
+ * Whether a given debug sink is enabled for the current config.
31
+ *
32
+ * @param {any} config
33
+ * @param {"body"|"headers"} sink
34
+ * @returns {boolean}
35
+ */
36
+ export function isDebugSinkEnabled(config, sink) {
37
+ return sink === "body" ? config.token_economy?.debug_dump_bodies === true : Boolean(config.debug);
38
+ }
39
+
40
+ /**
41
+ * Build the {filename, content} pair for a request-body debug dump.
42
+ *
43
+ * @param {string} correlationId
44
+ * @param {string} timestamp
45
+ * @param {string} finalBody
46
+ * @returns {{filename: string, content: string}}
47
+ */
48
+ export function createDebugRequestDump(correlationId, timestamp, finalBody) {
49
+ return {
50
+ filename: `req-${timestamp}-${correlationId}.json`,
51
+ content: JSON.stringify({ correlationId, timestamp, bodyRedacted: redactString(finalBody) }),
52
+ };
53
+ }
54
+
55
+ /**
56
+ * Build a log-file entry describing the outgoing request headers.
57
+ *
58
+ * @param {string} correlationId
59
+ * @param {string} timestamp
60
+ * @param {any} requestHeaders
61
+ * @returns {string}
62
+ */
63
+ export function createDebugOutgoingHeadersEntry(correlationId, timestamp, requestHeaders) {
64
+ return [
65
+ `\n=== ${timestamp} | corr=${correlationId} | OUTGOING request headers ===`,
66
+ JSON.stringify(redactSecrets(requestHeaders), null, 2),
67
+ "",
68
+ ].join("\n");
69
+ }
70
+
71
+ /**
72
+ * Build a log-file entry describing the response status/headers.
73
+ *
74
+ * @param {string} correlationId
75
+ * @param {string} timestamp
76
+ * @param {Response} response
77
+ * @param {{account: boolean, accountManager: boolean, rateLimitHeaders: any, allHeaders: any}} debugHeaders
78
+ * @returns {string}
79
+ */
80
+ export function createDebugResponseHeadersEntry(correlationId, timestamp, response, debugHeaders) {
81
+ return [
82
+ `\n=== ${timestamp} | corr=${correlationId} | status=${response.status} ok=${response.ok} account=${debugHeaders.account} mgr=${debugHeaders.accountManager} ===`,
83
+ `Rate-limit headers: ${JSON.stringify(debugHeaders.rateLimitHeaders, null, 2)}`,
84
+ `All headers: ${JSON.stringify(debugHeaders.allHeaders, null, 2)}`,
85
+ "",
86
+ ].join("\n");
87
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-anthropic-fix",
3
- "version": "2.1.0",
3
+ "version": "2.1.1",
4
4
  "license": "GPL-3.0-or-later",
5
5
  "repository": {
6
6
  "type": "git",