@hung319/opencode-qwen 1.1.6 → 1.1.8

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/plugin.js CHANGED
@@ -397,7 +397,7 @@ export const createQwenPlugin = (id) => async ({ client, directory }) => {
397
397
  try {
398
398
  // Add timeout to prevent hanging during validation
399
399
  const validationPromise = validateToken(token);
400
- const timeoutPromise = new Promise((_, reject) => setTimeout(() => reject(new Error('Token validation timed out')), 15000));
400
+ const timeoutPromise = new Promise((_, reject) => setTimeout(() => reject(new Error('Token validation timed out after 15 seconds')), 15000));
401
401
  const validation = await Promise.race([validationPromise, timeoutPromise]);
402
402
  const email = validation.email || await promptEmail();
403
403
  accounts.push({ apiKey: token, email });
@@ -1,11 +1,10 @@
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
5
+ // Use a shorter timeout as token validation should be fast
7
6
  const validateController = new AbortController();
8
- const validateTimeoutId = setTimeout(() => validateController.abort(), 10000); // 10 second timeout
7
+ const validateTimeoutId = setTimeout(() => validateController.abort(), 8000); // 8 second timeout
9
8
  const validateResponse = await fetch(QWEN_CONSTANTS.VALIDATE_URL, {
10
9
  method: 'POST',
11
10
  headers: {
@@ -27,28 +26,21 @@ export async function validateToken(apiKey) {
27
26
  };
28
27
  }
29
28
  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
- };
29
+ // For validation errors, get the error details
30
+ const errorText = await validateResponse.text().catch(() => '');
31
+ let errorMessage = `Token validation failed: ${validateResponse.status}`;
32
+ // Try to parse the error response to get more details
33
+ try {
34
+ const errorJson = JSON.parse(errorText);
35
+ if (errorJson.error && errorJson.error.message) {
36
+ errorMessage = `${errorMessage} - ${errorJson.error.message}`;
37
+ }
47
38
  }
48
- else {
49
- const errorText = await modelsResponse.text().catch(() => '');
50
- throw new Error(`Token validation failed: ${modelsResponse.status} - ${errorText}`);
39
+ catch (e) {
40
+ // If parsing fails, use the raw error text
41
+ errorMessage = `${errorMessage} - ${errorText}`;
51
42
  }
43
+ throw new Error(errorMessage);
52
44
  }
53
45
  }
54
46
  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.8",
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",