@oevortex/opencode-qwen-auth 0.1.2 → 0.1.4

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/dist/index.cjs CHANGED
@@ -30,10 +30,10 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // index.ts
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
- DEFAULT_MODEL: () => DEFAULT_MODEL,
34
33
  MODEL_ALIASES: () => MODEL_ALIASES,
35
34
  QWEN_CODE_MODELS: () => QWEN_CODE_MODELS,
36
35
  QWEN_DEFAULT_BASE_URL: () => QWEN_DEFAULT_BASE_URL,
36
+ QWEN_DEFAULT_MODEL: () => QWEN_DEFAULT_MODEL,
37
37
  QWEN_INTL_BASE_URL: () => QWEN_INTL_BASE_URL,
38
38
  QWEN_OAUTH_BASE_URL: () => QWEN_OAUTH_BASE_URL,
39
39
  QWEN_PORTAL_BASE_URL: () => QWEN_PORTAL_BASE_URL,
@@ -64,6 +64,9 @@ __export(index_exports, {
64
64
  });
65
65
  module.exports = __toCommonJS(index_exports);
66
66
 
67
+ // src/plugin/index.ts
68
+ var import_node_crypto = __toESM(require("crypto"), 1);
69
+
67
70
  // src/constants.ts
68
71
  var QWEN_OAUTH_BASE_URL = "https://chat.qwen.ai";
69
72
  var QWEN_OAUTH_TOKEN_ENDPOINT = `${QWEN_OAUTH_BASE_URL}/api/v1/oauth2/token`;
@@ -846,11 +849,11 @@ function isHeadless() {
846
849
  return false;
847
850
  }
848
851
 
849
- // src/plugin.ts
852
+ // src/plugin/index.ts
850
853
  var log6 = createLogger("plugin");
851
854
  function generateState() {
852
855
  const array = new Uint8Array(32);
853
- crypto.getRandomValues(array);
856
+ import_node_crypto.default.getRandomValues(array);
854
857
  return Array.from(array, (byte) => byte.toString(16).padStart(2, "0")).join(
855
858
  ""
856
859
  );
@@ -1040,9 +1043,8 @@ ${authUrl}
1040
1043
  }
1041
1044
  }
1042
1045
  }
1043
- async function QwenOAuthPlugin({
1044
- client
1045
- }) {
1046
+ async function QwenOAuthPlugin(context) {
1047
+ const { client } = context;
1046
1048
  initLogger(client);
1047
1049
  log6.info("Qwen OAuth Plugin initialized");
1048
1050
  let cachedGetAuth = null;
@@ -1061,10 +1063,21 @@ async function QwenOAuthPlugin({
1061
1063
  }
1062
1064
  log6.debug("Loading Qwen provider configuration");
1063
1065
  if (provider && provider.models) {
1064
- for (const model of Object.values(provider.models)) {
1065
- if (model && typeof model === "object" && "cost" in model) {
1066
- model.cost = { input: 0, output: 0, cache: { read: 0, write: 0 } };
1066
+ try {
1067
+ const modelEntries = Object.entries(provider.models);
1068
+ for (const [id, model] of modelEntries) {
1069
+ if (model && typeof model === "object") {
1070
+ model.cost = {
1071
+ input: 0,
1072
+ output: 0,
1073
+ cache: { read: 0, write: 0 }
1074
+ };
1075
+ }
1067
1076
  }
1077
+ } catch (err) {
1078
+ log6.warn("Failed to update model costs", {
1079
+ error: err instanceof Error ? err.message : String(err)
1080
+ });
1068
1081
  }
1069
1082
  }
1070
1083
  let currentAuth = auth;
@@ -1096,12 +1109,13 @@ async function QwenOAuthPlugin({
1096
1109
  baseUrl = baseUrl.replace(/\/+$/, "") + "/v1";
1097
1110
  }
1098
1111
  const qwenFetch = createQwenFetch(getAuth, client);
1099
- return {
1112
+ const loaderResult = {
1100
1113
  apiKey: "",
1101
1114
  // Empty - using OAuth
1102
1115
  baseUrl,
1103
1116
  fetch: qwenFetch
1104
1117
  };
1118
+ return loaderResult;
1105
1119
  },
1106
1120
  /**
1107
1121
  * Authentication methods available to the user.
@@ -1110,7 +1124,7 @@ async function QwenOAuthPlugin({
1110
1124
  {
1111
1125
  label: "OAuth with Qwen (Alibaba Cloud)",
1112
1126
  type: "oauth",
1113
- authorize: async () => {
1127
+ authorize: async (inputs) => {
1114
1128
  const result = await authenticateWithOAuth(client);
1115
1129
  if (result.type === "failed") {
1116
1130
  await client.tui.showToast({
@@ -1131,7 +1145,7 @@ async function QwenOAuthPlugin({
1131
1145
  url: "",
1132
1146
  instructions: result.type === "success" ? "Authentication complete!" : result.error || "Authentication failed",
1133
1147
  method: "auto",
1134
- callback: async () => result
1148
+ callback: async (callbackUrl) => result
1135
1149
  };
1136
1150
  }
1137
1151
  },
@@ -1499,7 +1513,7 @@ var MODEL_ALIASES = {
1499
1513
  "qwen-coder-plus": "qwen3-coder-plus",
1500
1514
  "qwen-coder-flash": "qwen3-coder-flash"
1501
1515
  };
1502
- var DEFAULT_MODEL = "qwen3-coder-plus";
1516
+ var QWEN_DEFAULT_MODEL = "qwen3-coder-plus";
1503
1517
  function getModelInfo(modelIdOrAlias) {
1504
1518
  if (modelIdOrAlias in QWEN_CODE_MODELS) {
1505
1519
  return QWEN_CODE_MODELS[modelIdOrAlias];
@@ -1567,10 +1581,10 @@ function generateProviderConfig() {
1567
1581
  }
1568
1582
  // Annotate the CommonJS export names for ESM import in node:
1569
1583
  0 && (module.exports = {
1570
- DEFAULT_MODEL,
1571
1584
  MODEL_ALIASES,
1572
1585
  QWEN_CODE_MODELS,
1573
1586
  QWEN_DEFAULT_BASE_URL,
1587
+ QWEN_DEFAULT_MODEL,
1574
1588
  QWEN_INTL_BASE_URL,
1575
1589
  QWEN_OAUTH_BASE_URL,
1576
1590
  QWEN_PORTAL_BASE_URL,
package/dist/index.d.cts CHANGED
@@ -189,7 +189,7 @@ interface PluginResult {
189
189
  * - Automatic token refresh
190
190
  * - Request handling with proper authentication headers
191
191
  */
192
- declare function QwenOAuthPlugin({ client, }: PluginContext): Promise<PluginResult>;
192
+ declare function QwenOAuthPlugin(context: PluginContext): Promise<PluginResult>;
193
193
 
194
194
  /**
195
195
  * Qwen OAuth Manager
@@ -407,7 +407,7 @@ declare const MODEL_ALIASES: Record<string, string>;
407
407
  /**
408
408
  * Default model to use when none specified.
409
409
  */
410
- declare const DEFAULT_MODEL = "qwen3-coder-plus";
410
+ declare const QWEN_DEFAULT_MODEL = "qwen3-coder-plus";
411
411
  /**
412
412
  * Get model info by ID or alias.
413
413
  *
@@ -442,4 +442,4 @@ declare const QWEN_INTL_BASE_URL = "https://dashscope-intl.aliyuncs.com/compatib
442
442
  declare const QWEN_PORTAL_BASE_URL = "https://portal.qwen.ai/v1";
443
443
  declare const QWEN_PROVIDER_ID = "qwencode";
444
444
 
445
- export { type AuthDetails, type ChatCompletionRequest, type ChatCompletionResponse, type ChatMessage, DEFAULT_MODEL, MODEL_ALIASES, type OAuthAuthDetails, type PluginContext, type PluginResult, QWEN_CODE_MODELS, QWEN_DEFAULT_BASE_URL, QWEN_INTL_BASE_URL, QWEN_OAUTH_BASE_URL, QWEN_PORTAL_BASE_URL, QWEN_PROVIDER_ID, type QwenModelInfo, type QwenOAuthCredentials, QwenOAuthManager, QwenOAuthPlugin, type QwenTokenResponse, ThinkingBlockParser, type TokenExchangeResult, type Tool, type ToolCall, type ToolChoice, accessTokenExpired, createAuthDetails, QwenOAuthPlugin as default, ensureValidToken, extractThinkingContent, formatRefreshParts, generateProviderConfig, getAllModelIds, getModelInfo, getQwenCachedCredentialPath, hasQwenCredentials, hasThinkingBlocks, isOAuthAuth, isValidModel, needsTokenRefresh, parseRefreshParts, parseThinkingBlocks, refreshAccessToken, resolveModelId, stripThinkingBlocks };
445
+ export { type AuthDetails, type ChatCompletionRequest, type ChatCompletionResponse, type ChatMessage, MODEL_ALIASES, type OAuthAuthDetails, type PluginContext, type PluginResult, QWEN_CODE_MODELS, QWEN_DEFAULT_BASE_URL, QWEN_DEFAULT_MODEL, QWEN_INTL_BASE_URL, QWEN_OAUTH_BASE_URL, QWEN_PORTAL_BASE_URL, QWEN_PROVIDER_ID, type QwenModelInfo, type QwenOAuthCredentials, QwenOAuthManager, QwenOAuthPlugin, type QwenTokenResponse, ThinkingBlockParser, type TokenExchangeResult, type Tool, type ToolCall, type ToolChoice, accessTokenExpired, createAuthDetails, QwenOAuthPlugin as default, ensureValidToken, extractThinkingContent, formatRefreshParts, generateProviderConfig, getAllModelIds, getModelInfo, getQwenCachedCredentialPath, hasQwenCredentials, hasThinkingBlocks, isOAuthAuth, isValidModel, needsTokenRefresh, parseRefreshParts, parseThinkingBlocks, refreshAccessToken, resolveModelId, stripThinkingBlocks };
package/dist/index.d.ts CHANGED
@@ -189,7 +189,7 @@ interface PluginResult {
189
189
  * - Automatic token refresh
190
190
  * - Request handling with proper authentication headers
191
191
  */
192
- declare function QwenOAuthPlugin({ client, }: PluginContext): Promise<PluginResult>;
192
+ declare function QwenOAuthPlugin(context: PluginContext): Promise<PluginResult>;
193
193
 
194
194
  /**
195
195
  * Qwen OAuth Manager
@@ -407,7 +407,7 @@ declare const MODEL_ALIASES: Record<string, string>;
407
407
  /**
408
408
  * Default model to use when none specified.
409
409
  */
410
- declare const DEFAULT_MODEL = "qwen3-coder-plus";
410
+ declare const QWEN_DEFAULT_MODEL = "qwen3-coder-plus";
411
411
  /**
412
412
  * Get model info by ID or alias.
413
413
  *
@@ -442,4 +442,4 @@ declare const QWEN_INTL_BASE_URL = "https://dashscope-intl.aliyuncs.com/compatib
442
442
  declare const QWEN_PORTAL_BASE_URL = "https://portal.qwen.ai/v1";
443
443
  declare const QWEN_PROVIDER_ID = "qwencode";
444
444
 
445
- export { type AuthDetails, type ChatCompletionRequest, type ChatCompletionResponse, type ChatMessage, DEFAULT_MODEL, MODEL_ALIASES, type OAuthAuthDetails, type PluginContext, type PluginResult, QWEN_CODE_MODELS, QWEN_DEFAULT_BASE_URL, QWEN_INTL_BASE_URL, QWEN_OAUTH_BASE_URL, QWEN_PORTAL_BASE_URL, QWEN_PROVIDER_ID, type QwenModelInfo, type QwenOAuthCredentials, QwenOAuthManager, QwenOAuthPlugin, type QwenTokenResponse, ThinkingBlockParser, type TokenExchangeResult, type Tool, type ToolCall, type ToolChoice, accessTokenExpired, createAuthDetails, QwenOAuthPlugin as default, ensureValidToken, extractThinkingContent, formatRefreshParts, generateProviderConfig, getAllModelIds, getModelInfo, getQwenCachedCredentialPath, hasQwenCredentials, hasThinkingBlocks, isOAuthAuth, isValidModel, needsTokenRefresh, parseRefreshParts, parseThinkingBlocks, refreshAccessToken, resolveModelId, stripThinkingBlocks };
445
+ export { type AuthDetails, type ChatCompletionRequest, type ChatCompletionResponse, type ChatMessage, MODEL_ALIASES, type OAuthAuthDetails, type PluginContext, type PluginResult, QWEN_CODE_MODELS, QWEN_DEFAULT_BASE_URL, QWEN_DEFAULT_MODEL, QWEN_INTL_BASE_URL, QWEN_OAUTH_BASE_URL, QWEN_PORTAL_BASE_URL, QWEN_PROVIDER_ID, type QwenModelInfo, type QwenOAuthCredentials, QwenOAuthManager, QwenOAuthPlugin, type QwenTokenResponse, ThinkingBlockParser, type TokenExchangeResult, type Tool, type ToolCall, type ToolChoice, accessTokenExpired, createAuthDetails, QwenOAuthPlugin as default, ensureValidToken, extractThinkingContent, formatRefreshParts, generateProviderConfig, getAllModelIds, getModelInfo, getQwenCachedCredentialPath, hasQwenCredentials, hasThinkingBlocks, isOAuthAuth, isValidModel, needsTokenRefresh, parseRefreshParts, parseThinkingBlocks, refreshAccessToken, resolveModelId, stripThinkingBlocks };
package/dist/index.js CHANGED
@@ -1,3 +1,6 @@
1
+ // src/plugin/index.ts
2
+ import crypto from "crypto";
3
+
1
4
  // src/constants.ts
2
5
  var QWEN_OAUTH_BASE_URL = "https://chat.qwen.ai";
3
6
  var QWEN_OAUTH_TOKEN_ENDPOINT = `${QWEN_OAUTH_BASE_URL}/api/v1/oauth2/token`;
@@ -780,7 +783,7 @@ function isHeadless() {
780
783
  return false;
781
784
  }
782
785
 
783
- // src/plugin.ts
786
+ // src/plugin/index.ts
784
787
  var log6 = createLogger("plugin");
785
788
  function generateState() {
786
789
  const array = new Uint8Array(32);
@@ -974,9 +977,8 @@ ${authUrl}
974
977
  }
975
978
  }
976
979
  }
977
- async function QwenOAuthPlugin({
978
- client
979
- }) {
980
+ async function QwenOAuthPlugin(context) {
981
+ const { client } = context;
980
982
  initLogger(client);
981
983
  log6.info("Qwen OAuth Plugin initialized");
982
984
  let cachedGetAuth = null;
@@ -995,10 +997,21 @@ async function QwenOAuthPlugin({
995
997
  }
996
998
  log6.debug("Loading Qwen provider configuration");
997
999
  if (provider && provider.models) {
998
- for (const model of Object.values(provider.models)) {
999
- if (model && typeof model === "object" && "cost" in model) {
1000
- model.cost = { input: 0, output: 0, cache: { read: 0, write: 0 } };
1000
+ try {
1001
+ const modelEntries = Object.entries(provider.models);
1002
+ for (const [id, model] of modelEntries) {
1003
+ if (model && typeof model === "object") {
1004
+ model.cost = {
1005
+ input: 0,
1006
+ output: 0,
1007
+ cache: { read: 0, write: 0 }
1008
+ };
1009
+ }
1001
1010
  }
1011
+ } catch (err) {
1012
+ log6.warn("Failed to update model costs", {
1013
+ error: err instanceof Error ? err.message : String(err)
1014
+ });
1002
1015
  }
1003
1016
  }
1004
1017
  let currentAuth = auth;
@@ -1030,12 +1043,13 @@ async function QwenOAuthPlugin({
1030
1043
  baseUrl = baseUrl.replace(/\/+$/, "") + "/v1";
1031
1044
  }
1032
1045
  const qwenFetch = createQwenFetch(getAuth, client);
1033
- return {
1046
+ const loaderResult = {
1034
1047
  apiKey: "",
1035
1048
  // Empty - using OAuth
1036
1049
  baseUrl,
1037
1050
  fetch: qwenFetch
1038
1051
  };
1052
+ return loaderResult;
1039
1053
  },
1040
1054
  /**
1041
1055
  * Authentication methods available to the user.
@@ -1044,7 +1058,7 @@ async function QwenOAuthPlugin({
1044
1058
  {
1045
1059
  label: "OAuth with Qwen (Alibaba Cloud)",
1046
1060
  type: "oauth",
1047
- authorize: async () => {
1061
+ authorize: async (inputs) => {
1048
1062
  const result = await authenticateWithOAuth(client);
1049
1063
  if (result.type === "failed") {
1050
1064
  await client.tui.showToast({
@@ -1065,7 +1079,7 @@ async function QwenOAuthPlugin({
1065
1079
  url: "",
1066
1080
  instructions: result.type === "success" ? "Authentication complete!" : result.error || "Authentication failed",
1067
1081
  method: "auto",
1068
- callback: async () => result
1082
+ callback: async (callbackUrl) => result
1069
1083
  };
1070
1084
  }
1071
1085
  },
@@ -1433,7 +1447,7 @@ var MODEL_ALIASES = {
1433
1447
  "qwen-coder-plus": "qwen3-coder-plus",
1434
1448
  "qwen-coder-flash": "qwen3-coder-flash"
1435
1449
  };
1436
- var DEFAULT_MODEL = "qwen3-coder-plus";
1450
+ var QWEN_DEFAULT_MODEL = "qwen3-coder-plus";
1437
1451
  function getModelInfo(modelIdOrAlias) {
1438
1452
  if (modelIdOrAlias in QWEN_CODE_MODELS) {
1439
1453
  return QWEN_CODE_MODELS[modelIdOrAlias];
@@ -1500,10 +1514,10 @@ function generateProviderConfig() {
1500
1514
  };
1501
1515
  }
1502
1516
  export {
1503
- DEFAULT_MODEL,
1504
1517
  MODEL_ALIASES,
1505
1518
  QWEN_CODE_MODELS,
1506
1519
  QWEN_DEFAULT_BASE_URL,
1520
+ QWEN_DEFAULT_MODEL,
1507
1521
  QWEN_INTL_BASE_URL,
1508
1522
  QWEN_OAUTH_BASE_URL,
1509
1523
  QWEN_PORTAL_BASE_URL,
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "main": "./dist/index.cjs",
4
4
  "module": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
- "version": "0.1.2",
6
+ "version": "0.1.4",
7
7
  "scripts": {
8
8
  "build": "tsup index.ts --format cjs,esm --dts --clean",
9
9
  "dev": "tsup index.ts --format cjs,esm --watch --dts",
@@ -32,7 +32,7 @@
32
32
  "license": "MIT",
33
33
  "type": "module",
34
34
  "devDependencies": {
35
- "@opencode-ai/sdk": "^1.0.182",
35
+ "@opencode-ai/sdk": "1.0.204",
36
36
  "@types/bun": "latest",
37
37
  "@types/node": "^22.0.0",
38
38
  "tsup": "^8.0.0",
@@ -42,7 +42,7 @@
42
42
  "typescript": "^5.9.3"
43
43
  },
44
44
  "dependencies": {
45
- "@opencode-ai/plugin": "^1.0.182",
45
+ "@opencode-ai/plugin": "1.0.204",
46
46
  "open": "^11.0.0"
47
47
  }
48
48
  }