qwen-opencode-provider 1.0.3 → 1.0.4

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 (3) hide show
  1. package/README.md +37 -115
  2. package/index.js +68 -122
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -1,143 +1,65 @@
1
1
  # OpenCode Qwen Plugin
2
2
 
3
- Plugin cho OpenCode để thêm Qwen AI provider với đầy đủ models.
3
+ OpenCode plugin for Qwen AI - auto adds provider with 28+ models.
4
4
 
5
- ## Tính năng
5
+ ## Features
6
6
 
7
- - **Tự động thêm Qwen provider** vào OpenCode config
8
- - **28+ Qwen models** được tích hợp sẵn
9
- - **Custom tools** để làm việc với Qwen API:
10
- - `qwen-validate-token` - Validate Qwen token
11
- - `qwen-list-models` - Liệt kê models
12
- - `qwen-setup` - Hướng dẫn cài đặt
13
- - `qwen-test` - Test kết nối API
7
+ - **Auto-configure**: Automatically adds Qwen provider to OpenCode
8
+ - **28+ Models**: All Qwen models pre-configured
9
+ - **Native auth**: Uses OpenCode's built-in auth system (`/connect`)
14
10
 
15
- ## Cài đặt
11
+ ## Installation
16
12
 
17
- ### Cách 1: Local Plugin (Khuyến nghị)
18
-
19
- 1. **Tạo thư mục plugins:**
20
- ```bash
21
- mkdir -p ~/.config/opencode/plugins
22
- ```
23
-
24
- 2. **Copy plugin vào thư mục:**
25
- ```bash
26
- cp -r opencode-qwen-plugin/* ~/.config/opencode/plugins/qwen/
27
- ```
28
-
29
- 3. **Tạo package.json trong config directory:**
30
- ```bash
31
- mkdir -p ~/.config/opencode
32
- cp opencode-qwen-plugin/package.json ~/.config/opencode/
33
- ```
34
-
35
- 4. **Khởi động lại OpenCode**
36
-
37
- ### Cách 2: NPM Package
38
-
39
- Thêm vào `opencode.json`:
13
+ Add to `opencode.json`:
40
14
  ```json
41
15
  {
42
16
  "plugin": ["qwen-opencode-provider"]
43
17
  }
44
18
  ```
45
19
 
46
- ## Cách lấy Qwen API Token
47
-
48
- ### Bước 1: Đăng nhập Qwen
49
- Truy cập https://chat.qwen.ai và đăng nhập
50
-
51
- ### Bước 2: Lấy Token
52
- Mở Developer Console (F12) và chạy:
53
- ```javascript
54
- localStorage.getItem('token')
55
- ```
56
-
57
- Hoặc sử dụng bookmarklet:
58
- ```javascript
59
- javascript:(function(){if(window.location.hostname!=="chat.qwen.ai"){alert("🚀 This code is for chat.qwen.ai");window.open("https://chat.qwen.ai","_blank");return;}function getApiKeyData(){const token=localStorage.getItem(!token){alert("token");if("❌ qwen access_token not found !!!");return null;}return token;}async function copyToClipboard(text){try{await navigator.clipboard.writeText(text);return true;}catch(err){console.error("❌ Failed to copy to clipboard:",err);const textarea=document.createElement("textarea");textarea.value=text;textarea.style.position="fixed";textarea.style.opacity="0";document.body.appendChild(textarea);textarea.focus();textarea.select();const success=document.execCommand("copy");document.body.removeChild(textarea);return success;}}const apiKeyData=getApiKeyData();if(!apiKeyData)return;copyToClipboard(apiKeyData).then((success)=>{if(success){alert("🔑 Qwen access_token copied to clipboard !!! 🎉");}else{prompt("🔰 Qwen access_token:",apiKeyData);}});})();
60
- ```
20
+ ## Usage
61
21
 
62
- ### Bước 3: Thêm vào OpenCode
22
+ ### 1. Connect Qwen Account
63
23
  ```bash
64
24
  /connect
65
25
  ```
66
- Tìm "Qwen" nhập token của bạn.
26
+ Search for "qwen" and enter your Qwen access token.
67
27
 
68
- ## Sử dụng
28
+ ### 2. Get Your Token
29
+ 1. Visit https://chat.qwen.ai and login
30
+ 2. Open Developer Console (F12)
31
+ 3. Run: `localStorage.getItem('token')`
69
32
 
70
- ### Chọn model:
33
+ ### 3. Select Model
71
34
  ```bash
72
35
  /models
73
36
  ```
74
- Chọn model Qwen bạn muốn sử dụng.
37
+ Choose any Qwen model.
75
38
 
76
- ### Sử dụng custom tools:
77
-
78
- ```bash
79
- # Validate token
80
- qwen-validate-token --token YOUR_TOKEN
81
-
82
- # List models
83
- qwen-list-models --apiKey YOUR_API_KEY
84
-
85
- # Test connection
86
- qwen-test --apiKey YOUR_API_KEY --message "Hello!"
87
-
88
- # Xem hướng dẫn setup
89
- qwen-setup
90
- ```
91
-
92
- ## Models có sẵn
39
+ ## Supported Models
93
40
 
94
41
  | Model | Description |
95
42
  |-------|-------------|
96
- | `qwen-max` | Latest Qwen Max |
97
- | `qwen2.5-max` | Best overall with vision + web search |
98
- | `qwen2.5-turbo` | Fast responses |
99
- | `qwen2.5-plus` | Balanced performance |
100
- | `qwen2.5-coder-32b` | Code generation |
101
- | `qwen3-next-80b-a3b` | Next gen 80B |
102
- | `qwen3-coder` | Code + tool calling |
103
- | `qwen3-max` | Best Qwen3 |
104
- | `qwq-32b` | Reasoning with thinking |
105
- | `qwen-deep-research` | Research + web search |
106
- | `q | Web development |
107
- wen-web-dev`| `qwen-full-stack` | Full-stack apps |
108
-
109
- ## Tính năng Qwen API
110
-
111
- - 👁️ **Vision** - Phân tích hình ảnh
112
- - 🌐 **Web Search** - Tìm kiếm web
113
- - 🧠 **Thinking Mode** - Chế độ suy nghĩ
114
- - 🎨 **Image Generation** - Tạo hình ảnh
115
- - 👨‍💻 **Code Generation** - Viết code
116
-
117
- ## Cấu hình thủ công
118
-
119
- Nếu plugin không tự động thêm provider, thêm vào `~/.config/opencode/opencode.json`:
120
-
121
- ```json
122
- {
123
- "provider": {
124
- "qwen": {
125
- "npm": "@ai-sdk/openai-compatible",
126
- "name": "Qwen AI",
127
- "options": {
128
- "baseURL": "https://qwen.aikit.club/v1",
129
- "headers": {
130
- "Authorization": "Bearer ${QWEN_API_KEY}"
131
- }
132
- },
133
- "models": {
134
- "qwen2.5-max": { "name": "Qwen2.5 Max" },
135
- "qwen2.5-turbo": { "name": "Qwen2.5 Turbo" }
136
- }
137
- }
138
- }
139
- }
140
- ```
43
+ | qwen-max | Latest Qwen Max |
44
+ | qwen2.5-max | Best overall + vision + web search |
45
+ | qwen2.5-turbo | Fast responses |
46
+ | qwen2.5-plus | Balanced performance |
47
+ | qwen2.5-coder-32b | Code generation |
48
+ | qwen3-coder | Code + tool calling |
49
+ | qwen3-max | Best Qwen3 |
50
+ | qwq-32b | Reasoning with thinking |
51
+ | qwen-deep-research | Research + web search |
52
+ | qwen-web-dev | Web development |
53
+ | qwen-full-stack | Full-stack apps |
54
+ | qwen-cogview | Image generation |
55
+
56
+ ## API Features
57
+
58
+ - 👁️ Vision (image analysis)
59
+ - 🌐 Web Search
60
+ - 🧠 Thinking Mode
61
+ - 🎨 Image Generation
62
+ - 👨‍💻 Code Generation
141
63
 
142
64
  ## License
143
65
 
package/index.js CHANGED
@@ -1,154 +1,97 @@
1
1
  /**
2
2
  * OpenCode Qwen API Plugin
3
3
  *
4
- * This plugin automatically adds Qwen AI provider to OpenCode config.
4
+ * Automatically adds Qwen AI provider to OpenCode with 28+ models.
5
+ * Uses OpenCode's built-in auth system (/connect).
5
6
  *
6
7
  * Provider ID: qwen
7
8
  * Base URL: https://qwen.aikit.club/v1
8
9
  */
9
10
 
10
11
  import { readFileSync, writeFileSync, existsSync } from 'fs';
11
- import { join, dirname } from 'path';
12
+ import { join } from 'path';
12
13
  import { homedir } from 'os';
13
14
 
14
- // Qwen API Configuration
15
15
  const QWEN_BASE_URL = 'https://qwen.aikit.club/v1';
16
16
  const QWEN_PROVIDER_ID = 'qwen';
17
17
 
18
- /**
19
- * Get the OpenCode config file path
20
- */
18
+ const QWEN_MODELS = {
19
+ "qwen-max": { name: "Qwen Max", description: "Latest Qwen Max model" },
20
+ "qwen-max-latest": { name: "Qwen Max Latest", description: "Latest version of Qwen Max" },
21
+ "qwen2.5-max": { name: "Qwen2.5 Max", description: "Best overall with vision + web search" },
22
+ "qwen2.5-plus": { name: "Qwen2.5 Plus", description: "Balanced performance" },
23
+ "qwen2.5-turbo": { name: "Qwen2.5 Turbo", description: "Fast responses" },
24
+ "qwen2.5-14b-instruct-1m": { name: "Qwen2.5 14B Instruct 1M", description: "1M context" },
25
+ "qwen2.5-72b-instruct": { name: "Qwen2.5 72B Instruct", description: "72B parameters" },
26
+ "qwen2.5-coder-32b-instruct": { name: "Qwen2.5 Coder 32B", description: "Code generation" },
27
+ "qwen2.5-omni-7b": { name: "Qwen2.5 Omni 7B", description: "Multimodal" },
28
+ "qwen2.5-vl-32b-instruct": { name: "Qwen2.5 VL 32B", description: "Vision-language" },
29
+ "qwen3-next-80b-a3b": { name: "Qwen3 Next 80B A3B", description: "Next gen" },
30
+ "qwen3-235b-a22b-2507": { name: "Qwen3 235B A22B", description: "Large model" },
31
+ "qwen3-30b-a3b-2507": { name: "Qwen3 30B A3B", description: "Compact high-perf" },
32
+ "qwen3-coder": { name: "Qwen3 Coder", description: "Code + tool calling" },
33
+ "qwen3-coder-flash": { name: "Qwen3 Coder Flash", description: "Fast code" },
34
+ "qwen3-max": { name: "Qwen3 Max", description: "Best Qwen3" },
35
+ "qwen3-omni-flash": { name: "Qwen3 Omni Flash", description: "Fast multimodal" },
36
+ "qwen3-vl-235b-a22b": { name: "Qwen3 VL 235B", description: "Large vision" },
37
+ "qwen3-vl-32b": { name: "Qwen3 VL 32B", description: "Vision 32B" },
38
+ "qwen3-vl-30b-a3b": { name: "Qwen3 VL 30B A3B", description: "Compact vision" },
39
+ "qvq-max": { name: "QVQ Max", description: "Vision reasoning" },
40
+ "qwq-32b": { name: "QWQ 32B", description: "Reasoning with thinking" },
41
+ "qwen-deep-research": { name: "Qwen Deep Research", description: "Research + web search" },
42
+ "qwen-web-dev": { name: "Qwen Web Dev", description: "Web development" },
43
+ "qwen-full-stack": { name: "Qwen Full Stack", description: "Full-stack apps" },
44
+ "qwen-cogview": { name: "Qwen CogView", description: "Image generation" }
45
+ };
46
+
21
47
  function getConfigPath() {
22
- const homeDir = homedir();
23
- return join(homeDir, '.config', 'opencode', 'opencode.json');
48
+ return join(homedir(), '.config', 'opencode', 'opencode.json');
24
49
  }
25
50
 
26
- /**
27
- * Read and parse OpenCode config
28
- */
29
51
  function readConfig() {
30
52
  const configPath = getConfigPath();
31
- if (!existsSync(configPath)) {
32
- return null;
33
- }
53
+ if (!existsSync(configPath)) return null;
34
54
  try {
35
- const content = readFileSync(configPath, 'utf-8');
36
- return JSON.parse(content);
55
+ return JSON.parse(readFileSync(configPath, 'utf-8'));
37
56
  } catch {
38
57
  return null;
39
58
  }
40
59
  }
41
60
 
42
- /**
43
- * Write OpenCode config
44
- */
45
61
  function writeConfig(config) {
46
- const configPath = getConfigPath();
47
- writeFileSync(configPath, JSON.stringify(config, null, 2));
62
+ writeFileSync(getConfigPath(), JSON.stringify(config, null, 2));
48
63
  }
49
64
 
50
- /**
51
- * Check if Qwen provider is already configured
52
- */
53
65
  function isQwenProviderConfigured(config) {
54
- return config?.provider?.qwen !== undefined;
66
+ return config?.provider?.[QWEN_PROVIDER_ID] !== undefined;
55
67
  }
56
68
 
57
- /**
58
- * Add Qwen provider to OpenCode config
59
- */
60
69
  function addQwenProvider() {
61
- const configPath = getConfigPath();
62
70
  let config = readConfig();
63
71
 
72
+ const qwenConfig = {
73
+ npm: "@ai-sdk/openai-compatible",
74
+ name: "Qwen AI",
75
+ options: {
76
+ baseURL: QWEN_BASE_URL,
77
+ headers: {
78
+ "Authorization": "Bearer ${QWEN_API_KEY}"
79
+ }
80
+ },
81
+ models: QWEN_MODELS
82
+ };
83
+
64
84
  if (!config) {
65
85
  config = {
66
86
  $schema: "https://opencode.ai/config.json",
67
87
  provider: {
68
- [QWEN_PROVIDER_ID]: {
69
- npm: "@ai-sdk/openai-compatible",
70
- name: "Qwen AI",
71
- options: {
72
- baseURL: QWEN_BASE_URL,
73
- headers: {
74
- "Authorization": "Bearer ${QWEN_API_KEY}"
75
- }
76
- },
77
- models: {
78
- "qwen-max": { name: "Qwen Max" },
79
- "qwen-max-latest": { name: "Qwen Max Latest" },
80
- "qwen2.5-max": { name: "Qwen2.5 Max" },
81
- "qwen2.5-plus": { name: "Qwen2.5 Plus" },
82
- "qwen2.5-turbo": { name: "Qwen2.5 Turbo" },
83
- "qwen2.5-14b-instruct-1m": { name: "Qwen2.5 14B Instruct 1M" },
84
- "qwen2.5-72b-instruct": { name: "Qwen2.5 72B Instruct" },
85
- "qwen2.5-coder-32b-instruct": { name: "Qwen2.5 Coder 32B" },
86
- "qwen2.5-omni-7b": { name: "Qwen2.5 Omni 7B" },
87
- "qwen2.5-vl-32b-instruct": { name: "Qwen2.5 VL 32B" },
88
- "qwen3-next-80b-a3b": { name: "Qwen3 Next 80B A3B" },
89
- "qwen3-235b-a22b-2507": { name: "Qwen3 235B A22B" },
90
- "qwen3-30b-a3b-2507": { name: "Qwen3 30B A3B" },
91
- "qwen3-coder": { name: "Qwen3 Coder" },
92
- "qwen3-coder-flash": { name: "Qwen3 Coder Flash" },
93
- "qwen3-max": { name: "Qwen3 Max" },
94
- "qwen3-omni-flash": { name: "Qwen3 Omni Flash" },
95
- "qwen3-vl-235b-a22b": { name: "Qwen3 VL 235B A22B" },
96
- "qwen3-vl-32b": { name: "Qwen3 VL 32B" },
97
- "qwen3-vl-30b-a3b": { name: "Qwen3 VL 30B A3B" },
98
- "qvq-max": { name: "QVQ Max" },
99
- "qwq-32b": { name: "QWQ 32B" },
100
- "qwen-deep-research": { name: "Qwen Deep Research" },
101
- "qwen-web-dev": { name: "Qwen Web Dev" },
102
- "qwen-full-stack": { name: "Qwen Full Stack" },
103
- "qwen-cogview": { name: "Qwen CogView" }
104
- }
105
- }
88
+ [QWEN_PROVIDER_ID]: qwenConfig
106
89
  }
107
90
  };
108
91
  } else {
109
- if (!config.provider) {
110
- config.provider = {};
111
- }
112
-
92
+ if (!config.provider) config.provider = {};
113
93
  if (!isQwenProviderConfigured(config)) {
114
- config.provider[QWEN_PROVIDER_ID] = {
115
- npm: "@ai-sdk/openai-compatible",
116
- name: "Qwen AI",
117
- options: {
118
- baseURL: QWEN_BASE_URL,
119
- headers: {
120
- "Authorization": "Bearer ${QWEN_API_KEY}"
121
- }
122
- },
123
- models: {
124
- "qwen-max": { name: "Qwen Max" },
125
- "qwen-max-latest": { name: "Qwen Max Latest" },
126
- "qwen2.5-max": { name: "Qwen2.5 Max" },
127
- "qwen2.5-plus": { name: "Qwen2.5 Plus" },
128
- "qwen2.5-turbo": { name: "Qwen2.5 Turbo" },
129
- "qwen2.5-14b-instruct-1m": { name: "Qwen2.5 14B Instruct 1M" },
130
- "qwen2.5-72b-instruct": { name: "Qwen2.5 72B Instruct" },
131
- "qwen2.5-coder-32b-instruct": { name: "Qwen2.5 Coder 32B" },
132
- "qwen2.5-omni-7b": { name: "Qwen2.5 Omni 7B" },
133
- "qwen2.5-vl-32b-instruct": { name: "Qwen2.5 VL 32B" },
134
- "qwen3-next-80b-a3b": { name: "Qwen3 Next 80B A3B" },
135
- "qwen3-235b-a22b-2507": { name: "Qwen3 235B A22B" },
136
- "qwen3-30b-a3b-2507": { name: "Qwen3 30B A3B" },
137
- "qwen3-coder": { name: "Qwen3 Coder" },
138
- "qwen3-coder-flash": { name: "Qwen3 Coder Flash" },
139
- "qwen3-max": { name: "Qwen3 Max" },
140
- "qwen3-omni-flash": { name: "Qwen3 Omni Flash" },
141
- "qwen3-vl-235b-a22b": { name: "Qwen3 VL 235B A22B" },
142
- "qwen3-vl-32b": { name: "Qwen3 VL 32B" },
143
- "qwen3-vl-30b-a3b": { name: "Qwen3 VL 30B A3B" },
144
- "qvq-max": { name: "QVQ Max" },
145
- "qwq-32b": { name: "QWQ 32B" },
146
- "qwen-deep-research": { name: "Qwen Deep Research" },
147
- "qwen-web-dev": { name: "Qwen Web Dev" },
148
- "qwen-full-stack": { name: "Qwen Full Stack" },
149
- "qwen-cogview": { name: "Qwen CogView" }
150
- }
151
- };
94
+ config.provider[QWEN_PROVIDER_ID] = qwenConfig;
152
95
  }
153
96
  }
154
97
 
@@ -156,33 +99,36 @@ function addQwenProvider() {
156
99
  return true;
157
100
  }
158
101
 
159
- /**
160
- * OpenCode Plugin
161
- */
162
102
  export const QwenPlugin = async ({ client }) => {
163
- // Automatically add Qwen provider on first load
164
103
  try {
165
- const configPath = getConfigPath();
166
- if (!existsSync(dirname(configPath))) {
167
- return {};
168
- }
169
-
170
104
  const config = readConfig();
171
105
  if (!isQwenProviderConfigured(config)) {
172
106
  addQwenProvider();
173
- await client?.app?.log?.({
107
+ await client.app.log({
174
108
  body: {
175
109
  service: "qwen-plugin",
176
110
  level: "info",
177
- message: "Qwen provider added to OpenCode config",
111
+ message: "Qwen provider added to OpenCode config"
178
112
  }
179
113
  });
180
114
  }
181
115
  } catch (error) {
182
- // Silently fail - provider can be added manually
116
+ // Silent fail
183
117
  }
184
118
 
185
- return {};
119
+ return {
120
+ "installation.updated": async ({ installation }) {
121
+ try {
122
+ const config = readConfig();
123
+ if (config?.provider?.[QWEN_PROVIDER_ID]) {
124
+ config.provider[QWEN_PROVIDER_ID].models = QWEN_MODELS;
125
+ writeConfig(config);
126
+ }
127
+ } catch (error) {
128
+ // Silent fail
129
+ }
130
+ }
131
+ };
186
132
  };
187
133
 
188
134
  export default QwenPlugin;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qwen-opencode-provider",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "OpenCode plugin for Qwen API - auto adds provider with 28+ models",
5
5
  "main": "index.js",
6
6
  "type": "module",