agent-mp 0.4.11 → 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 +22 -3
- package/package.json +1 -1
package/dist/utils/qwen-auth.js
CHANGED
|
@@ -235,7 +235,8 @@ export async function fetchQwenModels() {
|
|
|
235
235
|
if (!token)
|
|
236
236
|
return [];
|
|
237
237
|
try {
|
|
238
|
-
const
|
|
238
|
+
const host = token.resourceUrl ? `https://${token.resourceUrl}` : 'https://chat.qwen.ai';
|
|
239
|
+
const res = await fetch(`${host}/api/models`, {
|
|
239
240
|
headers: { Authorization: `Bearer ${token.accessToken}` },
|
|
240
241
|
});
|
|
241
242
|
if (!res.ok)
|
|
@@ -252,17 +253,35 @@ export async function getQwenAccessToken() {
|
|
|
252
253
|
return token?.accessToken || null;
|
|
253
254
|
}
|
|
254
255
|
async function callQwenAPIWithToken(token, prompt, model, onData) {
|
|
255
|
-
|
|
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`;
|
|
256
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 }];
|
|
257
264
|
const response = await fetch(`${baseUrl}/chat/completions`, {
|
|
258
265
|
method: 'POST',
|
|
259
266
|
headers: {
|
|
260
267
|
'Authorization': `Bearer ${token.accessToken}`,
|
|
261
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',
|
|
262
281
|
},
|
|
263
282
|
body: JSON.stringify({
|
|
264
283
|
model: model || 'coder-model',
|
|
265
|
-
messages: [{ role: 'user', content: prompt }],
|
|
284
|
+
messages: [{ role: 'user', content: toContentParts(prompt) }],
|
|
266
285
|
stream: useStream,
|
|
267
286
|
}),
|
|
268
287
|
});
|