@hung319/opencode-qwen 1.1.9 → 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
@@ -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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hung319/opencode-qwen",
3
- "version": "1.1.9",
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",