@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.
- package/dist/qwen/token.js +23 -54
- package/package.json +1 -1
package/dist/qwen/token.js
CHANGED
|
@@ -1,36 +1,20 @@
|
|
|
1
1
|
import { QWEN_CONSTANTS } from '../constants';
|
|
2
2
|
export async function validateToken(apiKey) {
|
|
3
|
-
//
|
|
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
|
|
7
|
-
const
|
|
8
|
-
const
|
|
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
|
-
|
|
10
|
+
'Content-Type': 'application/json',
|
|
11
11
|
'User-Agent': QWEN_CONSTANTS.USER_AGENT
|
|
12
12
|
},
|
|
13
|
-
|
|
13
|
+
body: JSON.stringify({ token: apiKey }),
|
|
14
|
+
signal: validateController.signal
|
|
14
15
|
});
|
|
15
|
-
clearTimeout(
|
|
16
|
-
if (
|
|
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
|
-
//
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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