qwen-opencode-provider 2.0.1 → 2.0.2
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/index.js +45 -8
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -10,7 +10,8 @@ import fs from 'fs';
|
|
|
10
10
|
import path from 'path';
|
|
11
11
|
import os from 'os';
|
|
12
12
|
|
|
13
|
-
const
|
|
13
|
+
const LOG_DIR = path.join(os.homedir(), '.cache', 'opencode', 'qwen-plugin');
|
|
14
|
+
const LOG_FILE = path.join(LOG_DIR, 'debug.log');
|
|
14
15
|
const PROVIDER_ID = 'qwen';
|
|
15
16
|
const API_BASE_URL = 'https://qwen.aikit.club/v1';
|
|
16
17
|
|
|
@@ -35,8 +36,17 @@ const QWEN_MODELS = {
|
|
|
35
36
|
'qwen-cogview': { name: 'Qwen CogView' }
|
|
36
37
|
};
|
|
37
38
|
|
|
39
|
+
function ensureLogDir() {
|
|
40
|
+
try {
|
|
41
|
+
if (!fs.existsSync(LOG_DIR)) {
|
|
42
|
+
fs.mkdirSync(LOG_DIR, { recursive: true });
|
|
43
|
+
}
|
|
44
|
+
} catch (e) { }
|
|
45
|
+
}
|
|
46
|
+
|
|
38
47
|
function log(msg) {
|
|
39
48
|
try {
|
|
49
|
+
ensureLogDir();
|
|
40
50
|
fs.appendFileSync(LOG_FILE, `[${new Date().toISOString()}] ${msg}\n`);
|
|
41
51
|
} catch (e) { }
|
|
42
52
|
}
|
|
@@ -49,21 +59,37 @@ function getAuthFilePath() {
|
|
|
49
59
|
function readApiKeyFromAuth() {
|
|
50
60
|
try {
|
|
51
61
|
const authPath = getAuthFilePath();
|
|
62
|
+
log(`[Auth] Checking auth file: ${authPath}`);
|
|
63
|
+
|
|
52
64
|
if (fs.existsSync(authPath)) {
|
|
53
65
|
const content = fs.readFileSync(authPath, 'utf-8');
|
|
54
66
|
const auth = JSON.parse(content);
|
|
55
67
|
|
|
68
|
+
log(`[Auth] Auth file contents keys: ${Object.keys(auth).join(', ')}`);
|
|
69
|
+
|
|
56
70
|
if (auth[PROVIDER_ID]?.apiKey) {
|
|
57
|
-
|
|
71
|
+
const keyPreview = auth[PROVIDER_ID].apiKey.substring(0, 20) + '...';
|
|
72
|
+
log(`[Auth] Found API key for ${PROVIDER_ID}: ${keyPreview}`);
|
|
58
73
|
return auth[PROVIDER_ID].apiKey;
|
|
74
|
+
} else {
|
|
75
|
+
log(`[Auth] No apiKey found for ${PROVIDER_ID}`);
|
|
76
|
+
|
|
77
|
+
// Also check other possible keys
|
|
78
|
+
for (const key of Object.keys(auth)) {
|
|
79
|
+
log(`[Auth] Key ${key}: ${JSON.stringify(auth[key])}`);
|
|
80
|
+
}
|
|
59
81
|
}
|
|
82
|
+
} else {
|
|
83
|
+
log(`[Auth] Auth file does not exist`);
|
|
60
84
|
}
|
|
61
85
|
} catch (e) {
|
|
62
|
-
log(`[Auth] Error reading auth: ${e.message}`);
|
|
86
|
+
log(`[Auth] Error reading auth: ${e.message}\n${e.stack}`);
|
|
63
87
|
}
|
|
64
88
|
return null;
|
|
65
89
|
}
|
|
66
90
|
|
|
91
|
+
let serverInstance = null;
|
|
92
|
+
|
|
67
93
|
function startProxy() {
|
|
68
94
|
return new Promise((resolve) => {
|
|
69
95
|
const server = http.createServer(async (req, res) => {
|
|
@@ -91,7 +117,8 @@ function startProxy() {
|
|
|
91
117
|
if (req.url.startsWith('/v1/')) {
|
|
92
118
|
const apiKey = readApiKeyFromAuth();
|
|
93
119
|
|
|
94
|
-
log(`[Proxy] Request: ${req.method} ${req.url}
|
|
120
|
+
log(`[Proxy] Request: ${req.method} ${req.url}`);
|
|
121
|
+
log(`[Proxy] Has API key: ${!!apiKey}`);
|
|
95
122
|
|
|
96
123
|
const options = {
|
|
97
124
|
hostname: 'qwen.aikit.club',
|
|
@@ -100,18 +127,20 @@ function startProxy() {
|
|
|
100
127
|
method: req.method,
|
|
101
128
|
headers: {
|
|
102
129
|
...req.headers,
|
|
103
|
-
'Host': 'qwen.aikit.club'
|
|
130
|
+
'Host': 'qwen.aikit.club',
|
|
131
|
+
'Content-Type': 'application/json'
|
|
104
132
|
}
|
|
105
133
|
};
|
|
106
134
|
|
|
107
135
|
if (apiKey) {
|
|
108
136
|
options.headers['Authorization'] = `Bearer ${apiKey}`;
|
|
109
|
-
log(`[Proxy] Added Authorization
|
|
137
|
+
log(`[Proxy] Added Authorization: Bearer ${apiKey.substring(0, 20)}...`);
|
|
110
138
|
} else {
|
|
111
|
-
log(`[Proxy]
|
|
139
|
+
log(`[Proxy] NO API KEY - this will likely fail!`);
|
|
112
140
|
}
|
|
113
141
|
|
|
114
142
|
const proxyReq = https.request(options, (proxyRes) => {
|
|
143
|
+
log(`[Proxy] Response status: ${proxyRes.statusCode}`);
|
|
115
144
|
res.writeHead(proxyRes.statusCode, proxyRes.headers);
|
|
116
145
|
proxyRes.pipe(res, { end: true });
|
|
117
146
|
});
|
|
@@ -126,6 +155,7 @@ function startProxy() {
|
|
|
126
155
|
return;
|
|
127
156
|
}
|
|
128
157
|
|
|
158
|
+
log(`[Proxy] Unknown request: ${req.method} ${req.url}`);
|
|
129
159
|
res.writeHead(404);
|
|
130
160
|
res.end('Not Found');
|
|
131
161
|
});
|
|
@@ -133,6 +163,7 @@ function startProxy() {
|
|
|
133
163
|
server.listen(0, '127.0.0.1', () => {
|
|
134
164
|
const port = server.address().port;
|
|
135
165
|
log(`[Proxy] Started on port ${port}`);
|
|
166
|
+
serverInstance = server;
|
|
136
167
|
resolve(port);
|
|
137
168
|
});
|
|
138
169
|
|
|
@@ -144,7 +175,13 @@ function startProxy() {
|
|
|
144
175
|
}
|
|
145
176
|
|
|
146
177
|
export const QwenPlugin = async (ctx) => {
|
|
147
|
-
log('[Plugin]
|
|
178
|
+
log('[Plugin] ====== Qwen Plugin Starting ======');
|
|
179
|
+
log(`[Plugin] Home: ${os.homedir()}`);
|
|
180
|
+
log(`[Plugin] Log file: ${LOG_FILE}`);
|
|
181
|
+
|
|
182
|
+
// Check auth immediately
|
|
183
|
+
const existingKey = readApiKeyFromAuth();
|
|
184
|
+
log(`[Plugin] Initial auth check - has key: ${!!existingKey}`);
|
|
148
185
|
|
|
149
186
|
const port = await startProxy();
|
|
150
187
|
const localBaseUrl = `http://127.0.0.1:${port}/v1`;
|