@hung319/opencode-qwen 1.1.6 → 1.1.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/qwen/token.js +14 -23
  2. package/package.json +1 -1
@@ -1,9 +1,7 @@
1
1
  import { QWEN_CONSTANTS } from '../constants';
2
2
  export async function validateToken(apiKey) {
3
- // First validate using header-based auth
4
- // Use a minimal fetch that only checks if the token is valid
3
+ // Validate using the validation endpoint to check if the token is valid and get user info
5
4
  try {
6
- // Only try the validation endpoint first to get user info, as it's more efficient
7
5
  const validateController = new AbortController();
8
6
  const validateTimeoutId = setTimeout(() => validateController.abort(), 10000); // 10 second timeout
9
7
  const validateResponse = await fetch(QWEN_CONSTANTS.VALIDATE_URL, {
@@ -27,28 +25,21 @@ export async function validateToken(apiKey) {
27
25
  };
28
26
  }
29
27
  else {
30
- // If validation endpoint failed, try models endpoint as fallback
31
- const modelsController = new AbortController();
32
- const modelsTimeoutId = setTimeout(() => modelsController.abort(), 10000); // 10 second timeout
33
- const modelsResponse = await fetch(`${QWEN_CONSTANTS.BASE_URL}/models`, {
34
- headers: {
35
- Authorization: `Bearer ${apiKey}`,
36
- 'User-Agent': QWEN_CONSTANTS.USER_AGENT
37
- },
38
- signal: modelsController.signal
39
- });
40
- clearTimeout(modelsTimeoutId);
41
- if (modelsResponse.ok) {
42
- return {
43
- apiKey,
44
- email: 'qwen-token-user', // Fallback to default email if models endpoint was used
45
- authMethod: 'token'
46
- };
28
+ // For validation errors, get the error details
29
+ const errorText = await validateResponse.text().catch(() => '');
30
+ let errorMessage = `Token validation failed: ${validateResponse.status}`;
31
+ // Try to parse the error response to get more details
32
+ try {
33
+ const errorJson = JSON.parse(errorText);
34
+ if (errorJson.error && errorJson.error.message) {
35
+ errorMessage = `${errorMessage} - ${errorJson.error.message}`;
36
+ }
47
37
  }
48
- else {
49
- const errorText = await modelsResponse.text().catch(() => '');
50
- throw new Error(`Token validation failed: ${modelsResponse.status} - ${errorText}`);
38
+ catch (e) {
39
+ // If parsing fails, use the raw error text
40
+ errorMessage = `${errorMessage} - ${errorText}`;
51
41
  }
42
+ throw new Error(errorMessage);
52
43
  }
53
44
  }
54
45
  catch (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hung319/opencode-qwen",
3
- "version": "1.1.6",
3
+ "version": "1.1.7",
4
4
  "description": "OpenCode plugin for Qwen API providing access to Qwen AI models with auto-config and token management",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",