@hung319/opencode-qwen 1.1.5 → 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 +23 -54
  2. package/package.json +1 -1
@@ -1,36 +1,20 @@
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
- const controller = new AbortController();
7
- const timeoutId = setTimeout(() => controller.abort(), 10000); // 10 second timeout
8
- const response = await fetch(`${QWEN_CONSTANTS.BASE_URL}/models`, {
5
+ const validateController = new AbortController();
6
+ const validateTimeoutId = setTimeout(() => validateController.abort(), 10000); // 10 second timeout
7
+ const validateResponse = await fetch(QWEN_CONSTANTS.VALIDATE_URL, {
8
+ method: 'POST',
9
9
  headers: {
10
- Authorization: `Bearer ${apiKey}`,
10
+ 'Content-Type': 'application/json',
11
11
  'User-Agent': QWEN_CONSTANTS.USER_AGENT
12
12
  },
13
- signal: controller.signal
13
+ body: JSON.stringify({ token: apiKey }),
14
+ signal: validateController.signal
14
15
  });
15
- clearTimeout(timeoutId);
16
- if (!response.ok) {
17
- // Try validation endpoint with token in request body as fallback
18
- const validateController = new AbortController();
19
- const validateTimeoutId = setTimeout(() => validateController.abort(), 10000); // 10 second timeout
20
- const validateResponse = await fetch(QWEN_CONSTANTS.VALIDATE_URL, {
21
- method: 'POST',
22
- headers: {
23
- 'Content-Type': 'application/json',
24
- 'User-Agent': QWEN_CONSTANTS.USER_AGENT
25
- },
26
- body: JSON.stringify({ token: apiKey }),
27
- signal: validateController.signal
28
- });
29
- clearTimeout(validateTimeoutId);
30
- if (!validateResponse.ok) {
31
- const errorText = await validateResponse.text().catch(() => '');
32
- throw new Error(`Token validation failed: ${validateResponse.status} - ${errorText}`);
33
- }
16
+ clearTimeout(validateTimeoutId);
17
+ if (validateResponse.ok) {
34
18
  // Extract email from the validation response
35
19
  const validationData = await validateResponse.json();
36
20
  const email = validationData.email || 'qwen-token-user';
@@ -41,36 +25,21 @@ export async function validateToken(apiKey) {
41
25
  };
42
26
  }
43
27
  else {
44
- // If the models endpoint worked, try to get user info from validation endpoint anyway
45
- const validateController = new AbortController();
46
- const validateTimeoutId = setTimeout(() => validateController.abort(), 10000); // 10 second timeout
47
- const validateResponse = await fetch(QWEN_CONSTANTS.VALIDATE_URL, {
48
- method: 'POST',
49
- headers: {
50
- 'Content-Type': 'application/json',
51
- 'User-Agent': QWEN_CONSTANTS.USER_AGENT
52
- },
53
- body: JSON.stringify({ token: apiKey }),
54
- signal: validateController.signal
55
- });
56
- clearTimeout(validateTimeoutId);
57
- if (validateResponse.ok) {
58
- // Extract email from the validation response
59
- const validationData = await validateResponse.json();
60
- const email = validationData.email || 'qwen-token-user';
61
- return {
62
- apiKey,
63
- email,
64
- authMethod: 'token'
65
- };
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
+ }
66
37
  }
67
- else {
68
- return {
69
- apiKey,
70
- email: 'qwen-token-user',
71
- authMethod: 'token'
72
- };
38
+ catch (e) {
39
+ // If parsing fails, use the raw error text
40
+ errorMessage = `${errorMessage} - ${errorText}`;
73
41
  }
42
+ throw new Error(errorMessage);
74
43
  }
75
44
  }
76
45
  catch (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hung319/opencode-qwen",
3
- "version": "1.1.5",
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",