opencode-qwen-cli-auth 2.2.6 → 2.2.7

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.
Files changed (2) hide show
  1. package/dist/index.js +31 -17
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -15,10 +15,12 @@ import { PROVIDER_ID, AUTH_LABELS, DEVICE_FLOW, PORTAL_HEADERS } from "./lib/con
15
15
  import { logError, logInfo, logWarn, LOGGING_ENABLED } from "./lib/logger.js";
16
16
  const CHAT_REQUEST_TIMEOUT_MS = 30000;
17
17
  const CHAT_MAX_RETRIES = 0;
18
+ const CHAT_MAX_TOKENS_CAP = 2048;
18
19
  const MAX_CONSECUTIVE_POLL_FAILURES = 3;
19
20
  const QUOTA_DEGRADE_MAX_TOKENS = 1024;
20
21
  const CLI_FALLBACK_TIMEOUT_MS = 8000;
21
22
  const CLI_FALLBACK_MAX_BUFFER_CHARS = 1024 * 1024;
23
+ const ENABLE_CLI_FALLBACK = process.env.OPENCODE_QWEN_ENABLE_CLI_FALLBACK === "1";
22
24
  const PLUGIN_USER_AGENT = "opencode-qwen-cli-auth/2.2.1";
23
25
  const CLIENT_ONLY_BODY_FIELDS = new Set([
24
26
  "providerID",
@@ -178,6 +180,14 @@ function sanitizeOutgoingPayload(payload) {
178
180
  delete sanitized.stream_options;
179
181
  changed = true;
180
182
  }
183
+ if (typeof sanitized.max_tokens === "number" && sanitized.max_tokens > CHAT_MAX_TOKENS_CAP) {
184
+ sanitized.max_tokens = CHAT_MAX_TOKENS_CAP;
185
+ changed = true;
186
+ }
187
+ if (typeof sanitized.max_completion_tokens === "number" && sanitized.max_completion_tokens > CHAT_MAX_TOKENS_CAP) {
188
+ sanitized.max_completion_tokens = CHAT_MAX_TOKENS_CAP;
189
+ changed = true;
190
+ }
181
191
  return changed ? sanitized : payload;
182
192
  }
183
193
  function createQuotaDegradedPayload(payload) {
@@ -607,6 +617,27 @@ async function failFastFetch(input, init) {
607
617
  return response;
608
618
  }
609
619
  const fallbackBody = await response.text().catch(() => "");
620
+ if (ENABLE_CLI_FALLBACK) {
621
+ const cliFallback = await runQwenCliFallback(payload, context, sourceSignal);
622
+ if (cliFallback.ok) {
623
+ return cliFallback.response;
624
+ }
625
+ if (cliFallback.reason === "cli_aborted") {
626
+ return makeFailFastErrorResponse(400, "request_aborted", "Qwen request was aborted");
627
+ }
628
+ if (LOGGING_ENABLED) {
629
+ logWarn("Qwen CLI fallback failed", {
630
+ request_id: context.requestId,
631
+ sessionID: context.sessionID,
632
+ modelID: context.modelID,
633
+ reason: cliFallback.reason,
634
+ stderr: cliFallback.stderr,
635
+ });
636
+ }
637
+ }
638
+ return makeQuotaFailFastResponse(fallbackBody, response.headers, context);
639
+ }
640
+ if (ENABLE_CLI_FALLBACK) {
610
641
  const cliFallback = await runQwenCliFallback(payload, context, sourceSignal);
611
642
  if (cliFallback.ok) {
612
643
  return cliFallback.response;
@@ -623,23 +654,6 @@ async function failFastFetch(input, init) {
623
654
  stderr: cliFallback.stderr,
624
655
  });
625
656
  }
626
- return makeQuotaFailFastResponse(fallbackBody, response.headers, context);
627
- }
628
- const cliFallback = await runQwenCliFallback(payload, context, sourceSignal);
629
- if (cliFallback.ok) {
630
- return cliFallback.response;
631
- }
632
- if (cliFallback.reason === "cli_aborted") {
633
- return makeFailFastErrorResponse(400, "request_aborted", "Qwen request was aborted");
634
- }
635
- if (LOGGING_ENABLED) {
636
- logWarn("Qwen CLI fallback failed", {
637
- request_id: context.requestId,
638
- sessionID: context.sessionID,
639
- modelID: context.modelID,
640
- reason: cliFallback.reason,
641
- stderr: cliFallback.stderr,
642
- });
643
657
  }
644
658
  }
645
659
  return makeQuotaFailFastResponse(firstBody, response.headers, context);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-qwen-cli-auth",
3
- "version": "2.2.6",
3
+ "version": "2.2.7",
4
4
  "description": "Qwen OAuth authentication plugin for opencode - use your Qwen account instead of API keys",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",