qwen-opencode-provider 3.2.0 → 3.2.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 +19 -31
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -92,40 +92,34 @@ async function validateToken(apiKey) {
|
|
|
92
92
|
}
|
|
93
93
|
};
|
|
94
94
|
|
|
95
|
-
if (apiKey) {
|
|
96
|
-
options.headers['Authorization'] = `Bearer ${apiKey}`;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
95
|
const req = https.request(options, (res) => {
|
|
100
96
|
let data = '';
|
|
101
97
|
res.on('data', chunk => data += chunk);
|
|
102
98
|
res.on('end', () => {
|
|
103
99
|
try {
|
|
104
100
|
const json = JSON.parse(data);
|
|
105
|
-
log(`[Validate]
|
|
106
|
-
|
|
101
|
+
log(`[Validate] Status: ${res.statusCode}`);
|
|
102
|
+
|
|
103
|
+
if (res.statusCode === 200 && json.id) {
|
|
104
|
+
resolve({ valid: true, data: json });
|
|
105
|
+
} else {
|
|
106
|
+
resolve({ valid: false, error: json.error || 'Unknown error' });
|
|
107
|
+
}
|
|
107
108
|
} catch (e) {
|
|
108
|
-
log(`[Validate] Parse error: ${e.message}`);
|
|
109
109
|
resolve({ valid: false, error: e.message });
|
|
110
110
|
}
|
|
111
111
|
});
|
|
112
112
|
});
|
|
113
113
|
|
|
114
|
-
req.on('error', (e) => {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
req.end(JSON.stringify({ token: apiKey }));
|
|
114
|
+
req.on('error', (e) => resolve({ valid: false, error: e.message }));
|
|
115
|
+
req.write(JSON.stringify({ token: apiKey }));
|
|
116
|
+
req.end();
|
|
120
117
|
});
|
|
121
118
|
}
|
|
122
119
|
|
|
123
120
|
async function refreshToken() {
|
|
124
121
|
const currentKey = readApiKeyFromAuth();
|
|
125
|
-
if (!currentKey)
|
|
126
|
-
log(`[Refresh] No current token to refresh`);
|
|
127
|
-
return null;
|
|
128
|
-
}
|
|
122
|
+
if (!currentKey) return null;
|
|
129
123
|
|
|
130
124
|
return new Promise((resolve) => {
|
|
131
125
|
const options = {
|
|
@@ -139,36 +133,30 @@ async function refreshToken() {
|
|
|
139
133
|
}
|
|
140
134
|
};
|
|
141
135
|
|
|
142
|
-
if (currentKey) {
|
|
143
|
-
options.headers['Authorization'] = `Bearer ${currentKey}`;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
136
|
const req = https.request(options, (res) => {
|
|
147
137
|
let data = '';
|
|
148
138
|
res.on('data', chunk => data += chunk);
|
|
149
139
|
res.on('end', () => {
|
|
150
140
|
try {
|
|
151
141
|
const json = JSON.parse(data);
|
|
152
|
-
log(`[Refresh]
|
|
142
|
+
log(`[Refresh] Status: ${res.statusCode}`);
|
|
153
143
|
|
|
154
|
-
if (json.
|
|
155
|
-
saveApiKeyToAuth(json.
|
|
156
|
-
resolve(json.
|
|
144
|
+
if (res.statusCode === 200 && json.access_token) {
|
|
145
|
+
saveApiKeyToAuth(json.access_token);
|
|
146
|
+
resolve(json.access_token);
|
|
147
|
+
} else if (res.statusCode === 200 && json.id) {
|
|
148
|
+
resolve(currentKey);
|
|
157
149
|
} else {
|
|
158
150
|
resolve(null);
|
|
159
151
|
}
|
|
160
152
|
} catch (e) {
|
|
161
|
-
log(`[Refresh] Parse error: ${e.message}`);
|
|
162
153
|
resolve(null);
|
|
163
154
|
}
|
|
164
155
|
});
|
|
165
156
|
});
|
|
166
157
|
|
|
167
|
-
req.on('error', (e) =>
|
|
168
|
-
|
|
169
|
-
resolve(null);
|
|
170
|
-
});
|
|
171
|
-
|
|
158
|
+
req.on('error', (e) => resolve(null));
|
|
159
|
+
req.write(JSON.stringify({ token: currentKey }));
|
|
172
160
|
req.end();
|
|
173
161
|
});
|
|
174
162
|
}
|