qwen-opencode-provider 1.0.6 → 1.0.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.
Files changed (2) hide show
  1. package/index.js +86 -39
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -11,60 +11,107 @@
11
11
 
12
12
  const QWEN_PROVIDER_ID = 'qwen';
13
13
 
14
+ const QWEN_MODELS = {
15
+ 'qwen-max': { name: 'Qwen Max' },
16
+ 'qwen-max-latest': { name: 'Qwen Max Latest' },
17
+ 'qwen2.5-max': { name: 'Qwen2.5 Max' },
18
+ 'qwen2.5-plus': { name: 'Qwen2.5 Plus' },
19
+ 'qwen2.5-turbo': { name: 'Qwen2.5 Turbo' },
20
+ 'qwen2.5-14b-instruct-1m': { name: 'Qwen2.5 14B Instruct 1M' },
21
+ 'qwen2.5-72b-instruct': { name: 'Qwen2.5 72B Instruct' },
22
+ 'qwen2.5-coder-32b-instruct': { name: 'Qwen2.5 Coder 32B' },
23
+ 'qwen2.5-omni-7b': { name: 'Qwen2.5 Omni 7B' },
24
+ 'qwen2.5-vl-32b-instruct': { name: 'Qwen2.5 VL 32B' },
25
+ 'qwen3-next-80b-a3b': { name: 'Qwen3 Next 80B A3B' },
26
+ 'qwen3-235b-a22b-2507': { name: 'Qwen3 235B A22B' },
27
+ 'qwen3-30b-a3b-2507': { name: 'Qwen3 30B A3B' },
28
+ 'qwen3-coder': { name: 'Qwen3 Coder' },
29
+ 'qwen3-coder-flash': { name: 'Qwen3 Coder Flash' },
30
+ 'qwen3-max': { name: 'Qwen3 Max' },
31
+ 'qwen3-omni-flash': { name: 'Qwen3 Omni Flash' },
32
+ 'qwen3-vl-235b-a22b': { name: 'Qwen3 VL 235B' },
33
+ 'qwen3-vl-32b': { name: 'Qwen3 VL 32B' },
34
+ 'qwen3-vl-30b-a3b': { name: 'Qwen3 VL 30B A3B' },
35
+ 'qvq-max': { name: 'QVQ Max' },
36
+ 'qwq-32b': { name: 'QWQ 32B' },
37
+ 'qwen-deep-research': { name: 'Qwen Deep Research' },
38
+ 'qwen-web-dev': { name: 'Qwen Web Dev' },
39
+ 'qwen-full-stack': { name: 'Qwen Full Stack' },
40
+ 'qwen-cogview': { name: 'Qwen CogView' }
41
+ };
42
+
43
+ function getProviderConfig(apiKey = null) {
44
+ const options = {
45
+ baseURL: 'https://qwen.aikit.club/v1',
46
+ headers: {
47
+ 'Authorization': `Bearer ${apiKey || ''}`
48
+ }
49
+ };
50
+
51
+ if (apiKey) {
52
+ options.apiKey = apiKey;
53
+ }
54
+
55
+ return {
56
+ npm: '@ai-sdk/openai-compatible',
57
+ name: 'Qwen AI',
58
+ options,
59
+ models: QWEN_MODELS
60
+ };
61
+ }
62
+
14
63
  export const QwenPlugin = async (ctx) => {
64
+ let cachedApiKey = null;
65
+
15
66
  return {
16
67
  config: async (config) => {
17
- // Auto-add Qwen provider to config
18
68
  if (!config.provider) {
19
69
  config.provider = {};
20
70
  }
21
71
 
22
72
  if (!config.provider[QWEN_PROVIDER_ID]) {
23
- config.provider[QWEN_PROVIDER_ID] = {
24
- npm: '@ai-sdk/openai-compatible',
25
- name: 'Qwen AI',
26
- options: {
27
- baseURL: 'https://qwen.aikit.club/v1'
28
- },
29
- models: {
30
- 'qwen-max': { name: 'Qwen Max' },
31
- 'qwen-max-latest': { name: 'Qwen Max Latest' },
32
- 'qwen2.5-max': { name: 'Qwen2.5 Max' },
33
- 'qwen2.5-plus': { name: 'Qwen2.5 Plus' },
34
- 'qwen2.5-turbo': { name: 'Qwen2.5 Turbo' },
35
- 'qwen2.5-14b-instruct-1m': { name: 'Qwen2.5 14B Instruct 1M' },
36
- 'qwen2.5-72b-instruct': { name: 'Qwen2.5 72B Instruct' },
37
- 'qwen2.5-coder-32b-instruct': { name: 'Qwen2.5 Coder 32B' },
38
- 'qwen2.5-omni-7b': { name: 'Qwen2.5 Omni 7B' },
39
- 'qwen2.5-vl-32b-instruct': { name: 'Qwen2.5 VL 32B' },
40
- 'qwen3-next-80b-a3b': { name: 'Qwen3 Next 80B A3B' },
41
- 'qwen3-235b-a22b-2507': { name: 'Qwen3 235B A22B' },
42
- 'qwen3-30b-a3b-2507': { name: 'Qwen3 30B A3B' },
43
- 'qwen3-coder': { name: 'Qwen3 Coder' },
44
- 'qwen3-coder-flash': { name: 'Qwen3 Coder Flash' },
45
- 'qwen3-max': { name: 'Qwen3 Max' },
46
- 'qwen3-omni-flash': { name: 'Qwen3 Omni Flash' },
47
- 'qwen3-vl-235b-a22b': { name: 'Qwen3 VL 235B' },
48
- 'qwen3-vl-32b': { name: 'Qwen3 VL 32B' },
49
- 'qwen3-vl-30b-a3b': { name: 'Qwen3 VL 30B A3B' },
50
- 'qvq-max': { name: 'QVQ Max' },
51
- 'qwq-32b': { name: 'QWQ 32B' },
52
- 'qwen-deep-research': { name: 'Qwen Deep Research' },
53
- 'qwen-web-dev': { name: 'Qwen Web Dev' },
54
- 'qwen-full-stack': { name: 'Qwen Full Stack' },
55
- 'qwen-cogview': { name: 'Qwen CogView' }
73
+ config.provider[QWEN_PROVIDER_ID] = getProviderConfig(cachedApiKey);
74
+ }
75
+ },
76
+
77
+ 'installation.updated': async ({ installation }) => {
78
+ // Try to get API key from auth config
79
+ if (installation?.auth?.[QWEN_PROVIDER_ID]?.apiKey) {
80
+ cachedApiKey = installation.auth[QWEN_PROVIDER_ID].apiKey;
81
+
82
+ // Update config with API key
83
+ try {
84
+ const configPath = ctx.project?.id
85
+ ? `${ctx.directory}/opencode.json`
86
+ : `${process.env.HOME}/.config/opencode/opencode.json`;
87
+
88
+ const { exists } = await import('fs');
89
+ if (exists(configPath)) {
90
+ const { readFile, writeFile } = await import('fs/promises');
91
+ try {
92
+ const configContent = await readFile(configPath, 'utf-8');
93
+ const config = JSON.parse(configContent);
94
+
95
+ if (config.provider && config.provider[QWEN_PROVIDER_ID]) {
96
+ config.provider[QWEN_PROVIDER_ID].options.apiKey = cachedApiKey;
97
+ await writeFile(configPath, JSON.stringify(config, null, 2));
98
+ }
99
+ } catch (e) {
100
+ // Ignore config read/write errors
101
+ }
56
102
  }
57
- };
103
+ } catch (e) {
104
+ // Ignore errors
105
+ }
58
106
  }
59
107
  },
60
108
 
61
109
  auth: {
62
110
  provider: QWEN_PROVIDER_ID,
63
111
  loader: async (auth, provider) => {
64
- // Load and return the API key
65
- return {
66
- apiKey: auth?.apiKey || ''
67
- };
112
+ const apiKey = auth?.apiKey || cachedApiKey || '';
113
+ cachedApiKey = apiKey;
114
+ return { apiKey };
68
115
  },
69
116
  methods: [
70
117
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qwen-opencode-provider",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "description": "OpenCode plugin for Qwen API - auto adds provider with 28+ models",
5
5
  "main": "index.js",
6
6
  "type": "module",