opencode-anthropic-fix 0.0.38 → 0.0.41

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/lib/backoff.mjs CHANGED
@@ -7,6 +7,12 @@ const AUTH_FAILED_BACKOFF = 5_000;
7
7
  const RATE_LIMIT_EXCEEDED_BACKOFF = 30_000;
8
8
  const MIN_BACKOFF_MS = 2_000;
9
9
 
10
+ /** Cap on cooldowns derived from reset headers. Prevents lock-out from buggy timestamps. */
11
+ const MAX_COOLDOWN_FROM_RESET_MS = 300_000; // 5 minutes
12
+
13
+ /** Threshold below which a 429 retry-after is considered transient (burst throttle). */
14
+ export const TRANSIENT_RETRY_THRESHOLD_MS = 10_000; // 10 seconds
15
+
10
16
  /**
11
17
  * Parse the retry-after-ms header from a response.
12
18
  * Returns milliseconds directly (no conversion needed).
@@ -223,9 +229,9 @@ export function parseRateLimitReason(status, body) {
223
229
  * @returns {number}
224
230
  */
225
231
  export function calculateBackoffMs(reason, consecutiveFailures, retryAfterMs) {
226
- // Retry-After header takes precedence
232
+ // Retry-After header takes precedence, but cap at MAX_COOLDOWN to prevent lock-out
227
233
  if (retryAfterMs && retryAfterMs > 0) {
228
- return Math.max(retryAfterMs, MIN_BACKOFF_MS);
234
+ return Math.min(Math.max(retryAfterMs, MIN_BACKOFF_MS), MAX_COOLDOWN_FROM_RESET_MS);
229
235
  }
230
236
 
231
237
  switch (reason) {
package/lib/config.mjs CHANGED
@@ -86,6 +86,14 @@ import { randomBytes } from "node:crypto";
86
86
  * @property {boolean} usage_toast
87
87
  * @property {CCCredentialReuseConfig} cc_credential_reuse
88
88
  * @property {AdaptiveContextConfig} adaptive_context
89
+ * @property {{ enabled: boolean, default_max_tokens: number, escalated_max_tokens: number }} output_cap
90
+ * @property {{ enabled: boolean, timeout_ms: number }} preconnect
91
+ * @property {{ enabled: boolean, safety_margin: number }} overflow_recovery
92
+ * @property {{ enabled: boolean, alert_threshold: number }} cache_break_detection
93
+ * @property {{ enabled: boolean, background_max_service_retries: number, background_max_should_retries: number }} request_classification
94
+ * @property {{ enabled: boolean, default: number, completion_threshold: number }} token_budget
95
+ * @property {{ enabled: boolean, threshold_percent: number }} microcompact
96
+ * @property {{ enabled: boolean, default_cooldown_ms: number, poll_quota_on_overload: boolean }} overload_recovery
89
97
  */
90
98
 
91
99
  /** @type {AnthropicAuthConfig} */
@@ -168,16 +176,62 @@ export const DEFAULT_CONFIG = {
168
176
  },
169
177
  /** Token economy optimizations. */
170
178
  token_economy: {
171
- /** Enable token-efficient-tools-2026-03-28 beta (~4.5% output token reduction).
172
- * Mutually exclusive with structured-outputs — this flag takes precedence. */
173
- token_efficient_tools: true,
179
+ /** [DEPRECATED] token-efficient-tools-2026-03-28 was removed in CC v2.1.90.
180
+ * This flag is retained for config backward compatibility but has no effect. */
181
+ token_efficient_tools: false,
174
182
  /** Enable redact-thinking-2026-02-12 beta (suppresses thinking summaries
175
- * server-side for lower bandwidth). Off by default — set to true if you
183
+ * server-side for lower bandwidth). Off by default u2014 set to true if you
176
184
  * don't need to inspect thinking blocks. */
177
185
  redact_thinking: false,
178
- /** Enable summarize-connector-text-2026-03-13 beta (API summarizes assistant
179
- * text between tool calls — anti-distillation measure). */
180
- connector_text_summarization: true,
186
+ /** [DEPRECATED] summarize-connector-text-2026-03-13 was removed in CC v2.1.90.
187
+ * This flag is retained for config backward compatibility but has no effect. */
188
+ connector_text_summarization: false,
189
+ },
190
+ /** Output cap: default max_tokens to save context window. */
191
+ output_cap: {
192
+ enabled: true,
193
+ default_max_tokens: 8_000,
194
+ escalated_max_tokens: 64_000,
195
+ },
196
+ /** API preconnect: fire-and-forget HEAD to pre-warm TCP+TLS. */
197
+ preconnect: {
198
+ enabled: true,
199
+ timeout_ms: 10_000,
200
+ },
201
+ /** Context overflow auto-recovery: parse error, reduce max_tokens, retry once. */
202
+ overflow_recovery: {
203
+ enabled: true,
204
+ safety_margin: 1_000,
205
+ },
206
+ /** Cache break detection: alert when cache_read_input_tokens drops significantly. */
207
+ cache_break_detection: {
208
+ enabled: true,
209
+ alert_threshold: 2_000,
210
+ },
211
+ /** Request classification: reduced retry budget for background requests. */
212
+ request_classification: {
213
+ enabled: true,
214
+ background_max_service_retries: 0,
215
+ background_max_should_retries: 1,
216
+ },
217
+ /** Token budget: parse NL budget expressions, track output, enforce limits. */
218
+ token_budget: {
219
+ enabled: false,
220
+ default: 0,
221
+ completion_threshold: 0.9,
222
+ },
223
+ /** Microcompact: inject clear_tool_uses/clear_thinking betas at high context utilization. */
224
+ microcompact: {
225
+ enabled: true,
226
+ threshold_percent: 80,
227
+ },
228
+ /** Overload recovery: quota-aware account switching on 529 exhaustion. */
229
+ overload_recovery: {
230
+ enabled: true,
231
+ /** Cooldown (ms) applied to overloaded accounts when no quota data available. */
232
+ default_cooldown_ms: 60_000,
233
+ /** Whether to poll /api/oauth/usage on 529 exhaustion for smarter cooldowns. */
234
+ poll_quota_on_overload: true,
181
235
  },
182
236
  };
183
237
 
@@ -208,6 +262,14 @@ function createDefaultConfig() {
208
262
  adaptive_context: { ...DEFAULT_CONFIG.adaptive_context },
209
263
  willow_mode: { ...DEFAULT_CONFIG.willow_mode },
210
264
  token_economy: { ...DEFAULT_CONFIG.token_economy },
265
+ output_cap: { ...DEFAULT_CONFIG.output_cap },
266
+ preconnect: { ...DEFAULT_CONFIG.preconnect },
267
+ overflow_recovery: { ...DEFAULT_CONFIG.overflow_recovery },
268
+ cache_break_detection: { ...DEFAULT_CONFIG.cache_break_detection },
269
+ request_classification: { ...DEFAULT_CONFIG.request_classification },
270
+ token_budget: { ...DEFAULT_CONFIG.token_budget },
271
+ microcompact: { ...DEFAULT_CONFIG.microcompact },
272
+ overload_recovery: { ...DEFAULT_CONFIG.overload_recovery },
211
273
  };
212
274
  }
213
275
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-anthropic-fix",
3
- "version": "0.0.38",
3
+ "version": "0.0.41",
4
4
  "license": "GPL-3.0-or-later",
5
5
  "main": "./index.mjs",
6
6
  "files": [