opencode-qwen-cli-auth 2.2.7 → 2.2.8

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 +68 -12
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -16,6 +16,7 @@ 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
18
  const CHAT_MAX_TOKENS_CAP = 2048;
19
+ const CHAT_DEFAULT_MAX_TOKENS = 2048;
19
20
  const MAX_CONSECUTIVE_POLL_FAILURES = 3;
20
21
  const QUOTA_DEGRADE_MAX_TOKENS = 1024;
21
22
  const CLI_FALLBACK_TIMEOUT_MS = 8000;
@@ -99,6 +100,34 @@ function appendLimitedText(current, chunk) {
99
100
  }
100
101
  return next.slice(next.length - CLI_FALLBACK_MAX_BUFFER_CHARS);
101
102
  }
103
+ function isRequestInstance(value) {
104
+ return typeof Request !== "undefined" && value instanceof Request;
105
+ }
106
+ async function normalizeFetchInvocation(input, init) {
107
+ const requestInit = init ? { ...init } : {};
108
+ let requestInput = input;
109
+ if (!isRequestInstance(input)) {
110
+ return { requestInput, requestInit };
111
+ }
112
+ requestInput = input.url;
113
+ if (!requestInit.method) {
114
+ requestInit.method = input.method;
115
+ }
116
+ if (!requestInit.headers) {
117
+ requestInit.headers = new Headers(input.headers);
118
+ }
119
+ if (requestInit.body === undefined) {
120
+ try {
121
+ requestInit.body = await input.clone().text();
122
+ }
123
+ catch (_error) {
124
+ }
125
+ }
126
+ if (!requestInit.signal) {
127
+ requestInit.signal = input.signal;
128
+ }
129
+ return { requestInput, requestInit };
130
+ }
102
131
  function getHeaderValue(headers, headerName) {
103
132
  if (!headers) {
104
133
  return undefined;
@@ -553,7 +582,9 @@ async function sendWithTimeout(input, requestInit) {
553
582
  }
554
583
  }
555
584
  async function failFastFetch(input, init) {
556
- const requestInit = init ? { ...init } : {};
585
+ const normalized = await normalizeFetchInvocation(input, init);
586
+ const requestInput = normalized.requestInput;
587
+ const requestInit = normalized.requestInit;
557
588
  const sourceSignal = requestInit.signal;
558
589
  const rawPayload = parseJsonRequestBody(requestInit);
559
590
  const sessionID = typeof rawPayload?.sessionID === "string" ? rawPayload.sessionID : undefined;
@@ -575,10 +606,14 @@ async function failFastFetch(input, init) {
575
606
  request_id: context.requestId,
576
607
  sessionID: context.sessionID,
577
608
  modelID: context.modelID,
609
+ max_tokens: typeof payload?.max_tokens === "number" ? payload.max_tokens : undefined,
610
+ max_completion_tokens: typeof payload?.max_completion_tokens === "number" ? payload.max_completion_tokens : undefined,
611
+ message_count: Array.isArray(payload?.messages) ? payload.messages.length : undefined,
612
+ stream: payload?.stream === true,
578
613
  });
579
614
  }
580
615
  try {
581
- let response = await sendWithTimeout(input, requestInit);
616
+ let response = await sendWithTimeout(requestInput, requestInit);
582
617
  if (LOGGING_ENABLED) {
583
618
  logInfo("Qwen request response", {
584
619
  request_id: context.requestId,
@@ -603,7 +638,7 @@ async function failFastFetch(input, init) {
603
638
  attempt: 2,
604
639
  });
605
640
  }
606
- response = await sendWithTimeout(input, fallbackInit);
641
+ response = await sendWithTimeout(requestInput, fallbackInit);
607
642
  if (LOGGING_ENABLED) {
608
643
  logInfo("Qwen request response", {
609
644
  request_id: context.requestId,
@@ -886,21 +921,21 @@ export const QwenAuthPlugin = async (_input) => {
886
921
  maxRetries: CHAT_MAX_RETRIES,
887
922
  },
888
923
  models: {
889
- "coder-model": {
890
- id: "coder-model",
891
- name: "Qwen Coder (Qwen 3.5 Plus)",
924
+ "coder-model": {
925
+ id: "coder-model",
926
+ name: "Qwen Coder (Qwen 3.5 Plus)",
892
927
  // Qwen does not support reasoning_effort from OpenCode UI
893
928
  // Thinking is always enabled by default on server side (qwen3.5-plus)
894
929
  reasoning: false,
895
- limit: { context: 1048576, output: 65536 },
930
+ limit: { context: 1048576, output: CHAT_MAX_TOKENS_CAP },
896
931
  cost: { input: 0, output: 0 },
897
932
  modalities: { input: ["text"], output: ["text"] },
898
933
  },
899
- "vision-model": {
900
- id: "vision-model",
901
- name: "Qwen VL Plus (vision)",
902
- reasoning: false,
903
- limit: { context: 131072, output: 8192 },
934
+ "vision-model": {
935
+ id: "vision-model",
936
+ name: "Qwen VL Plus (vision)",
937
+ reasoning: false,
938
+ limit: { context: 131072, output: CHAT_MAX_TOKENS_CAP },
904
939
  cost: { input: 0, output: 0 },
905
940
  modalities: { input: ["text"], output: ["text"] },
906
941
  },
@@ -915,12 +950,33 @@ export const QwenAuthPlugin = async (_input) => {
915
950
  if (typeof output.options.timeout !== "number" || output.options.timeout > CHAT_REQUEST_TIMEOUT_MS) {
916
951
  output.options.timeout = CHAT_REQUEST_TIMEOUT_MS;
917
952
  }
953
+ if (typeof output.max_tokens !== "number" || output.max_tokens > CHAT_MAX_TOKENS_CAP) {
954
+ output.max_tokens = CHAT_DEFAULT_MAX_TOKENS;
955
+ }
956
+ if (typeof output.max_completion_tokens !== "number" || output.max_completion_tokens > CHAT_MAX_TOKENS_CAP) {
957
+ output.max_completion_tokens = CHAT_DEFAULT_MAX_TOKENS;
958
+ }
959
+ if (typeof output.maxTokens !== "number" || output.maxTokens > CHAT_MAX_TOKENS_CAP) {
960
+ output.maxTokens = CHAT_DEFAULT_MAX_TOKENS;
961
+ }
962
+ if (typeof output.options.max_tokens !== "number" || output.options.max_tokens > CHAT_MAX_TOKENS_CAP) {
963
+ output.options.max_tokens = CHAT_DEFAULT_MAX_TOKENS;
964
+ }
965
+ if (typeof output.options.max_completion_tokens !== "number" || output.options.max_completion_tokens > CHAT_MAX_TOKENS_CAP) {
966
+ output.options.max_completion_tokens = CHAT_DEFAULT_MAX_TOKENS;
967
+ }
968
+ if (typeof output.options.maxTokens !== "number" || output.options.maxTokens > CHAT_MAX_TOKENS_CAP) {
969
+ output.options.maxTokens = CHAT_DEFAULT_MAX_TOKENS;
970
+ }
918
971
  if (LOGGING_ENABLED) {
919
972
  logInfo("Applied chat.params hotfix", {
920
973
  sessionID: input?.sessionID,
921
974
  modelID: input?.model?.id,
922
975
  timeout: output.options.timeout,
923
976
  maxRetries: output.options.maxRetries,
977
+ max_tokens: output.max_tokens,
978
+ max_completion_tokens: output.max_completion_tokens,
979
+ maxTokens: output.maxTokens,
924
980
  });
925
981
  }
926
982
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-qwen-cli-auth",
3
- "version": "2.2.7",
3
+ "version": "2.2.8",
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",