@oevortex/opencode-qwen-auth 0.1.2 → 0.1.3

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;
@@ -1110,7 +1123,7 @@ async function QwenOAuthPlugin({
1110
1123
  {
1111
1124
  label: "OAuth with Qwen (Alibaba Cloud)",
1112
1125
  type: "oauth",
1113
- authorize: async () => {
1126
+ authorize: async (inputs) => {
1114
1127
  const result = await authenticateWithOAuth(client);
1115
1128
  if (result.type === "failed") {
1116
1129
  await client.tui.showToast({
@@ -1499,7 +1512,7 @@ var MODEL_ALIASES = {
1499
1512
  "qwen-coder-plus": "qwen3-coder-plus",
1500
1513
  "qwen-coder-flash": "qwen3-coder-flash"
1501
1514
  };
1502
- var DEFAULT_MODEL = "qwen3-coder-plus";
1515
+ var QWEN_DEFAULT_MODEL = "qwen3-coder-plus";
1503
1516
  function getModelInfo(modelIdOrAlias) {
1504
1517
  if (modelIdOrAlias in QWEN_CODE_MODELS) {
1505
1518
  return QWEN_CODE_MODELS[modelIdOrAlias];
@@ -1567,10 +1580,10 @@ function generateProviderConfig() {
1567
1580
  }
1568
1581
  // Annotate the CommonJS export names for ESM import in node:
1569
1582
  0 && (module.exports = {
1570
- DEFAULT_MODEL,
1571
1583
  MODEL_ALIASES,
1572
1584
  QWEN_CODE_MODELS,
1573
1585
  QWEN_DEFAULT_BASE_URL,
1586
+ QWEN_DEFAULT_MODEL,
1574
1587
  QWEN_INTL_BASE_URL,
1575
1588
  QWEN_OAUTH_BASE_URL,
1576
1589
  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;
@@ -1044,7 +1057,7 @@ async function QwenOAuthPlugin({
1044
1057
  {
1045
1058
  label: "OAuth with Qwen (Alibaba Cloud)",
1046
1059
  type: "oauth",
1047
- authorize: async () => {
1060
+ authorize: async (inputs) => {
1048
1061
  const result = await authenticateWithOAuth(client);
1049
1062
  if (result.type === "failed") {
1050
1063
  await client.tui.showToast({
@@ -1433,7 +1446,7 @@ var MODEL_ALIASES = {
1433
1446
  "qwen-coder-plus": "qwen3-coder-plus",
1434
1447
  "qwen-coder-flash": "qwen3-coder-flash"
1435
1448
  };
1436
- var DEFAULT_MODEL = "qwen3-coder-plus";
1449
+ var QWEN_DEFAULT_MODEL = "qwen3-coder-plus";
1437
1450
  function getModelInfo(modelIdOrAlias) {
1438
1451
  if (modelIdOrAlias in QWEN_CODE_MODELS) {
1439
1452
  return QWEN_CODE_MODELS[modelIdOrAlias];
@@ -1500,10 +1513,10 @@ function generateProviderConfig() {
1500
1513
  };
1501
1514
  }
1502
1515
  export {
1503
- DEFAULT_MODEL,
1504
1516
  MODEL_ALIASES,
1505
1517
  QWEN_CODE_MODELS,
1506
1518
  QWEN_DEFAULT_BASE_URL,
1519
+ QWEN_DEFAULT_MODEL,
1507
1520
  QWEN_INTL_BASE_URL,
1508
1521
  QWEN_OAUTH_BASE_URL,
1509
1522
  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.3",
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
  }