agent-rev 0.4.12 → 0.4.13
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/utils/qwen-auth.js +20 -3
- package/package.json +1 -1
package/dist/utils/qwen-auth.js
CHANGED
|
@@ -253,18 +253,35 @@ export async function getQwenAccessToken() {
|
|
|
253
253
|
return token?.accessToken || null;
|
|
254
254
|
}
|
|
255
255
|
async function callQwenAPIWithToken(token, prompt, model, onData) {
|
|
256
|
-
|
|
257
|
-
const
|
|
256
|
+
// Use resource_url from token (e.g. "portal.qwen.ai"), fallback to DashScope
|
|
257
|
+
const rawHost = token.resourceUrl || 'dashscope.aliyuncs.com/compatible-mode';
|
|
258
|
+
const host = rawHost.startsWith('http') ? rawHost : `https://${rawHost}`;
|
|
259
|
+
const baseUrl = host.endsWith('/v1') ? host : `${host}/v1`;
|
|
258
260
|
const useStream = !!onData;
|
|
261
|
+
const userAgent = `QwenCode/0.14.2 (${process.platform}; ${process.arch})`;
|
|
262
|
+
// portal.qwen.ai requires content parts format (plain strings return 400)
|
|
263
|
+
const toContentParts = (text) => [{ type: 'text', text }];
|
|
259
264
|
const response = await fetch(`${baseUrl}/chat/completions`, {
|
|
260
265
|
method: 'POST',
|
|
261
266
|
headers: {
|
|
262
267
|
'Authorization': `Bearer ${token.accessToken}`,
|
|
263
268
|
'Content-Type': 'application/json',
|
|
269
|
+
'Accept': 'application/json',
|
|
270
|
+
'User-Agent': userAgent,
|
|
271
|
+
'x-dashscope-authtype': 'qwen-oauth',
|
|
272
|
+
'x-dashscope-cachecontrol': 'enable',
|
|
273
|
+
'x-dashscope-useragent': userAgent,
|
|
274
|
+
'x-stainless-lang': 'js',
|
|
275
|
+
'x-stainless-package-version': '5.11.0',
|
|
276
|
+
'x-stainless-os': process.platform,
|
|
277
|
+
'x-stainless-arch': process.arch,
|
|
278
|
+
'x-stainless-runtime': 'node',
|
|
279
|
+
'x-stainless-runtime-version': process.version,
|
|
280
|
+
'x-stainless-retry-count': '0',
|
|
264
281
|
},
|
|
265
282
|
body: JSON.stringify({
|
|
266
283
|
model: model || 'coder-model',
|
|
267
|
-
messages: [{ role: 'user', content: prompt }],
|
|
284
|
+
messages: [{ role: 'user', content: toContentParts(prompt) }],
|
|
268
285
|
stream: useStream,
|
|
269
286
|
}),
|
|
270
287
|
});
|