@hung319/opencode-qwen 1.1.8 → 1.1.10

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.d.ts CHANGED
@@ -1,11 +1,22 @@
1
1
  export declare const QWEN_PROVIDER_ID = "qwen";
2
- export declare const createQwenPlugin: (id: string) => ({ client, directory }: any) => Promise<{
2
+ export declare const createQwenPlugin: (id: string) => ({ client, directory, providerConfig }: any) => Promise<{
3
3
  config: (config: any) => Promise<void>;
4
4
  auth: {
5
5
  provider: string;
6
6
  loader: (getAuth: any, provider: any) => Promise<{
7
- apiKey: string;
8
- baseURL: string;
7
+ apiKey: any;
8
+ baseURL: any;
9
+ headers: {
10
+ Authorization: string;
11
+ 'Content-Type': string;
12
+ };
13
+ options: {
14
+ baseURL: any;
15
+ headers: {
16
+ Authorization: string;
17
+ 'Content-Type': string;
18
+ };
19
+ };
9
20
  models: any;
10
21
  fetch(input: any, init?: any): Promise<Response>;
11
22
  }>;
@@ -17,13 +28,24 @@ export declare const createQwenPlugin: (id: string) => ({ client, directory }: a
17
28
  }[];
18
29
  };
19
30
  }>;
20
- export declare const QwenOAuthPlugin: ({ client, directory }: any) => Promise<{
31
+ export declare const QwenOAuthPlugin: ({ client, directory, providerConfig }: any) => Promise<{
21
32
  config: (config: any) => Promise<void>;
22
33
  auth: {
23
34
  provider: string;
24
35
  loader: (getAuth: any, provider: any) => Promise<{
25
- apiKey: string;
26
- baseURL: string;
36
+ apiKey: any;
37
+ baseURL: any;
38
+ headers: {
39
+ Authorization: string;
40
+ 'Content-Type': string;
41
+ };
42
+ options: {
43
+ baseURL: any;
44
+ headers: {
45
+ Authorization: string;
46
+ 'Content-Type': string;
47
+ };
48
+ };
27
49
  models: any;
28
50
  fetch(input: any, init?: any): Promise<Response>;
29
51
  }>;
package/dist/plugin.js CHANGED
@@ -3,7 +3,7 @@ import { exec } from 'node:child_process';
3
3
  import { AccountManager, generateAccountId } from './plugin/accounts';
4
4
  import { accessTokenExpired } from './plugin/token';
5
5
  import { refreshAccessToken } from './plugin/token';
6
- import { validateToken, refreshToken } from './qwen/token';
6
+ import { refreshToken } from './qwen/token';
7
7
  import { getModels } from './qwen/models';
8
8
  import { promptAddAnotherAccount, promptLoginMode, promptToken, promptEmail, } from './plugin/cli';
9
9
  import { QWEN_CONSTANTS, applyThinkingConfig } from './constants';
@@ -90,17 +90,19 @@ const DEFAULT_MODELS = {
90
90
  modalities: { input: ['text'], output: ['text'] }
91
91
  }
92
92
  };
93
- export const createQwenPlugin = (id) => async ({ client, directory }) => {
93
+ export const createQwenPlugin = (id) => async ({ client, directory, providerConfig }) => {
94
94
  const config = loadConfig();
95
95
  const showToast = (message, variant) => {
96
96
  client.tui.showToast({ body: { message, variant } }).catch(() => { });
97
97
  };
98
+ // Use baseURL from providerConfig if available
99
+ const baseURL = providerConfig?.options?.baseURL || config.base_url;
98
100
  return {
99
101
  config: async (config) => {
100
102
  // Register qwen provider with models
101
103
  config.provider = config.provider || {};
102
104
  config.provider[id] = config.provider[id] || {};
103
- // Try to fetch models from API
105
+ // Try to fetch models from API but with timeout to prevent hanging
104
106
  let fetchedModels = {};
105
107
  try {
106
108
  const am = await AccountManager.loadFromDisk(config.account_selection_strategy);
@@ -112,8 +114,24 @@ export const createQwenPlugin = (id) => async ({ client, directory }) => {
112
114
  const token = firstAccount.apiKey;
113
115
  if (token) {
114
116
  logger.log('Fetching models from Qwen API...');
115
- fetchedModels = await getModels(token);
116
- logger.log(`Fetched ${Object.keys(fetchedModels).length} models from API`);
117
+ // Use a timeout to prevent hanging during model fetching
118
+ const controller = new AbortController();
119
+ const timeoutId = setTimeout(() => controller.abort(), 15000); // 15 second timeout
120
+ try {
121
+ fetchedModels = await getModels(token, controller.signal);
122
+ logger.log(`Fetched ${Object.keys(fetchedModels).length} models from API`);
123
+ }
124
+ catch (fetchError) {
125
+ if (fetchError.name === 'AbortError') {
126
+ logger.warn('Model fetching timed out, using default models');
127
+ }
128
+ else {
129
+ logger.warn(`Model fetching failed: ${fetchError.message}`);
130
+ }
131
+ }
132
+ finally {
133
+ clearTimeout(timeoutId);
134
+ }
117
135
  }
118
136
  }
119
137
  }
@@ -162,8 +180,19 @@ export const createQwenPlugin = (id) => async ({ client, directory }) => {
162
180
  const configuredModels = provider?.models || {};
163
181
  const mergedModels = { ...DEFAULT_MODELS, ...configuredModels };
164
182
  return {
165
- apiKey: '',
166
- baseURL: config.base_url,
183
+ apiKey: providerConfig?.options?.apiKey || '',
184
+ baseURL: baseURL,
185
+ headers: {
186
+ 'Authorization': `Bearer ${providerConfig?.options?.apiKey || ''}`,
187
+ 'Content-Type': 'application/json'
188
+ },
189
+ options: {
190
+ baseURL: baseURL,
191
+ headers: {
192
+ 'Authorization': `Bearer ${providerConfig?.options?.apiKey || ''}`,
193
+ 'Content-Type': 'application/json'
194
+ }
195
+ },
167
196
  models: mergedModels,
168
197
  async fetch(input, init) {
169
198
  const url = typeof input === 'string' ? input : input.url;
@@ -395,11 +424,9 @@ export const createQwenPlugin = (id) => async ({ client, directory }) => {
395
424
  break;
396
425
  }
397
426
  try {
398
- // Add timeout to prevent hanging during validation
399
- const validationPromise = validateToken(token);
400
- const timeoutPromise = new Promise((_, reject) => setTimeout(() => reject(new Error('Token validation timed out after 15 seconds')), 15000));
401
- const validation = await Promise.race([validationPromise, timeoutPromise]);
402
- const email = validation.email || await promptEmail();
427
+ // Skip token validation and save the token directly
428
+ // Token will be validated later during actual API calls
429
+ const email = await promptEmail();
403
430
  accounts.push({ apiKey: token, email });
404
431
  const isFirstAccount = accounts.length === 1;
405
432
  const am = await AccountManager.loadFromDisk(config.account_selection_strategy);
@@ -431,11 +458,11 @@ export const createQwenPlugin = (id) => async ({ client, directory }) => {
431
458
  }
432
459
  }
433
460
  catch (error) {
434
- console.error(`API token validation failed: ${error.message}`);
461
+ console.error(`Error during token setup: ${error.message}`);
435
462
  if (accounts.length === 0) {
436
463
  return resolve({
437
464
  url: '',
438
- instructions: `API token validation failed: ${error.message}`,
465
+ instructions: `Error during token setup: ${error.message}`,
439
466
  method: 'auto',
440
467
  callback: async () => ({ type: 'failed' })
441
468
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hung319/opencode-qwen",
3
- "version": "1.1.8",
3
+ "version": "1.1.10",
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",