@zhivex-ai/qwen 0.18.1 → 0.20.1
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/README.md +65 -1
- package/dist/capabilities.d.ts.map +1 -1
- package/dist/capabilities.js +2 -0
- package/dist/capabilities.js.map +1 -1
- package/dist/cloud-realtime.d.ts +6 -0
- package/dist/cloud-realtime.d.ts.map +1 -1
- package/dist/cloud-realtime.js +41 -3
- package/dist/cloud-realtime.js.map +1 -1
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +165 -94
- package/dist/index.js.map +1 -1
- package/dist/qwen4.d.ts +9 -0
- package/dist/qwen4.d.ts.map +1 -0
- package/dist/qwen4.js +97 -0
- package/dist/qwen4.js.map +1 -0
- package/dist/third-party.js +1 -1
- package/dist/third-party.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isQwen4, isQwen4Max, isQwen4Preview, validateQwen4, qwen4PartOptions, encryptedReasoningFromMessage } from "./qwen4.js";
|
|
1
2
|
import { withManualRedirect } from "./manual-redirect.js";
|
|
2
3
|
import { createPortableQwenDecisionModel } from "./portable-decision.js";
|
|
3
4
|
import { qwenSearchUsage } from "./search-usage.js";
|
|
@@ -10,7 +11,7 @@ export { createQwenWorldRTC } from "./world-rtc.js";
|
|
|
10
11
|
import { createQwenImageTranslationModel, validateWan30, validateQwenImage21, validateQwenImage30, validateHappyHorse, prepareViduVideo, preparePixVerseVideo, assertPixVerseRegion, validateViduImage } from "./cloud-media.js";
|
|
11
12
|
import { createQwenWorldsClient } from "./worlds.js";
|
|
12
13
|
import { QwenCloudSpeechModel, QwenCloudStreamingASRModel, isQwenCloudSpeech, isQwenCloudStreamingASR } from "./inference-audio.js";
|
|
13
|
-
import { isQwenCloudRealtime, isQwenAudioRealtime, isQwenOmni38Realtime, mapQwenCloudRealtimeSession, validateQwenCloudAudioFrame, qwenCloudAudioEvent, extendQwenCloudRealtimeSession } from "./cloud-realtime.js";
|
|
14
|
+
import { isQwenCloudRealtime, isQwenAudioRealtime, isQwenAudio31RealtimeFlash, isQwenOmni38Realtime, mapQwenCloudRealtimeSession, validateQwenCloudAudioFrame, qwenCloudAudioEvent, extendQwenCloudRealtimeSession } from "./cloud-realtime.js";
|
|
14
15
|
import { createQwenDecisionModel } from "./decision.js";
|
|
15
16
|
import { assertQwenLanguageModel, isQwenTranslation, isQwenCharacter, isQwen38Open, validateQwenSpecializedText } from "./text-profiles.js";
|
|
16
17
|
import { createQwenTextEmbeddingModel } from "./embeddings.js";
|
|
@@ -219,8 +220,8 @@ const isQwen38OmniFlash = (modelId) => modelId.toLowerCase() === "qwen3.8-omni-f
|
|
|
219
220
|
const isQwen38Max = (modelId) => modelFamily(modelId) === "qwen3.8-max";
|
|
220
221
|
const isQwen38Flash = (modelId) => modelFamily(modelId) === "qwen3.8-flash";
|
|
221
222
|
const isQwen38MaxPreview = (modelId) => modelFamily(modelId) === "qwen3.8-max-preview";
|
|
222
|
-
const
|
|
223
|
-
const
|
|
223
|
+
const isModernHybridModel = (modelId) => isQwen38Max(modelId) || isQwen38Flash(modelId) || isQwen38OmniFlash(modelId) || isQwen4(modelId);
|
|
224
|
+
const isModernReasoningModel = (modelId) => isModernHybridModel(modelId) || isQwen38MaxPreview(modelId);
|
|
224
225
|
const isQwenTokenPlanURL = (url) => {
|
|
225
226
|
const path = url.pathname.replace(/\/+$/, "");
|
|
226
227
|
return (QWEN_TOKEN_PLAN_ORIGINS.has(url.origin) &&
|
|
@@ -230,16 +231,16 @@ const isQwenTokenPlanURL = (url) => {
|
|
|
230
231
|
!url.hash &&
|
|
231
232
|
path === "/compatible-mode/v1");
|
|
232
233
|
};
|
|
233
|
-
const
|
|
234
|
+
const validateQwenPreviewBaseURL = (baseURL, modelId) => {
|
|
234
235
|
let url;
|
|
235
236
|
try {
|
|
236
237
|
url = new URL(baseURL);
|
|
237
238
|
}
|
|
238
239
|
catch {
|
|
239
|
-
throw new ConfigurationError(
|
|
240
|
+
throw new ConfigurationError(`Qwen ${modelId} requires a valid QwenCloud Token Plan baseURL.`);
|
|
240
241
|
}
|
|
241
242
|
if (!isQwenTokenPlanURL(url)) {
|
|
242
|
-
throw new ConfigurationError(`Qwen
|
|
243
|
+
throw new ConfigurationError(`Qwen ${modelId} is Token Plan only. Configure baseURL with QWEN_TOKEN_PLAN_BASE_URL (${QWEN_TOKEN_PLAN_BASE_URL}); pay-as-you-go and workspace endpoints cannot serve this model.`);
|
|
243
244
|
}
|
|
244
245
|
};
|
|
245
246
|
const validateQwen38ProductionBaseURL = (modelId, baseURL) => {
|
|
@@ -255,24 +256,26 @@ const validateQwen38ProductionBaseURL = (modelId, baseURL) => {
|
|
|
255
256
|
throw new ConfigurationError(`Qwen ${modelId} requires standard Model Studio credentials and endpoints; use an explicitly supported model such as qwen3.8-max or qwen3.8-flash with Token Plan.`);
|
|
256
257
|
}
|
|
257
258
|
};
|
|
258
|
-
const
|
|
259
|
+
const stripModernReasoningOptions = (providerOptions) => {
|
|
259
260
|
const next = { ...providerOptions };
|
|
260
261
|
delete next.enable_thinking;
|
|
261
262
|
delete next.thinking_budget;
|
|
262
263
|
delete next.preserve_thinking;
|
|
263
264
|
delete next.reasoning_effort;
|
|
265
|
+
delete next.reasoning;
|
|
266
|
+
delete next.thinking_display;
|
|
264
267
|
return next;
|
|
265
268
|
};
|
|
266
269
|
const supportsQwenReasoning = (modelId) => !isQwenOmniLanguageModel(modelId) &&
|
|
267
270
|
supportsQwenTools(modelId) &&
|
|
268
|
-
/^(qwen-(plus|turbo|max|flash)|qwq|qwen3|qwen3\.)/i.test(modelId);
|
|
271
|
+
(/^(qwen-(plus|turbo|max|flash)|qwq|qwen3|qwen3\.)/i.test(modelId) || isQwen4(modelId));
|
|
269
272
|
const supportsQwenVision = (modelId) => {
|
|
270
273
|
const model = modelFamily(modelId);
|
|
271
274
|
return (model.includes("vl") ||
|
|
272
275
|
model.includes("omni") ||
|
|
273
276
|
model.includes("ocr") ||
|
|
274
277
|
model.includes("vision") ||
|
|
275
|
-
|
|
278
|
+
isModernHybridModel(modelId) ||
|
|
276
279
|
isQwen38MaxPreview(modelId) ||
|
|
277
280
|
isQwen38Open(modelId) ||
|
|
278
281
|
/^qwen3\.7-(?:plus|flash)(?:$|-)/.test(model) ||
|
|
@@ -289,22 +292,22 @@ const qwenLanguageCapabilities = (modelId) => {
|
|
|
289
292
|
const omni = isQwenOmniLanguageModel(modelId);
|
|
290
293
|
const omni38 = isQwen38OmniFlash(modelId);
|
|
291
294
|
const reasoning = supportsQwenReasoning(modelId);
|
|
292
|
-
const
|
|
295
|
+
const modernHybrid = isModernHybridModel(modelId);
|
|
293
296
|
const qwen38MaxPreview = isQwen38MaxPreview(modelId);
|
|
294
297
|
return {
|
|
295
298
|
...capabilities,
|
|
296
299
|
vision: supportsQwenVision(modelId),
|
|
297
300
|
tools,
|
|
298
|
-
...(omni38 ? { inputMediaTypes: ["image/*", "audio/*", "video/*"] } : {}),
|
|
301
|
+
...(omni38 ? { inputMediaTypes: ["image/*", "audio/*", "video/*"] } : isQwen4(modelId) ? { inputMediaTypes: ["image/*", "video/*"] } : {}),
|
|
299
302
|
structuredOutput: tools && !omni && !omni38 && !qwen38MaxPreview,
|
|
300
303
|
jsonMode: tools && !omni && !omni38 && !qwen38MaxPreview,
|
|
301
304
|
toolChoice: tools,
|
|
302
|
-
parallelToolCalls:
|
|
305
|
+
parallelToolCalls: modernHybrid && !omni38,
|
|
303
306
|
webSearch: tools && !omni || ["qwen-plus-character", "qwen-flash-character"].includes(modelId),
|
|
304
|
-
files: supportsQwenFiles(modelId) ||
|
|
307
|
+
files: supportsQwenFiles(modelId) || modernHybrid || isQwen38Open(modelId),
|
|
305
308
|
audioInput: supportsQwenAudioInput(modelId),
|
|
306
309
|
reasoning,
|
|
307
|
-
reasoningEfforts:
|
|
310
|
+
reasoningEfforts: modernHybrid
|
|
308
311
|
? ["none", "minimal", "low", "medium", "high", "xhigh", "max"]
|
|
309
312
|
: qwen38MaxPreview
|
|
310
313
|
? ["minimal", "low", "medium", "high", "xhigh", "max"]
|
|
@@ -314,6 +317,7 @@ const qwenLanguageCapabilities = (modelId) => {
|
|
|
314
317
|
agentCapabilities: {
|
|
315
318
|
...capabilities.agentCapabilities,
|
|
316
319
|
supportTier: tools && !omni ? "tier-b" : "tier-c",
|
|
320
|
+
durableAgent: Boolean(tools && !omni),
|
|
317
321
|
toolChoiceNone: tools,
|
|
318
322
|
hostedWebSearch: tools && !omni,
|
|
319
323
|
hostedFileSearch: tools && !omni && !omni38,
|
|
@@ -360,7 +364,8 @@ const mapContentParts = (message, modelId) => {
|
|
|
360
364
|
const hasMedia = message.parts.some((part) => part.type === "image" ||
|
|
361
365
|
part.type === "audio" ||
|
|
362
366
|
(part.type === "file" && part.mediaType.toLowerCase().startsWith("video/")));
|
|
363
|
-
|
|
367
|
+
const hasPartOptions = message.parts.some(part => Object.keys(qwen4PartOptions(part, modelId)).length > 0);
|
|
368
|
+
if (!hasMedia && !hasPartOptions) {
|
|
364
369
|
return message.parts
|
|
365
370
|
.filter((part) => part.type === "text")
|
|
366
371
|
.map((part) => part.text)
|
|
@@ -368,10 +373,10 @@ const mapContentParts = (message, modelId) => {
|
|
|
368
373
|
}
|
|
369
374
|
return message.parts.flatMap((part) => {
|
|
370
375
|
if (part.type === "text") {
|
|
371
|
-
return [{ type: "text", text: part.text }];
|
|
376
|
+
return [{ type: "text", text: part.text, ...qwen4PartOptions(part, modelId) }];
|
|
372
377
|
}
|
|
373
378
|
if (part.type === "image") {
|
|
374
|
-
return [{ type: "image_url", image_url: { url: imageInputToDataUrl(part) } }];
|
|
379
|
+
return [{ type: "image_url", image_url: { url: imageInputToDataUrl(part) }, ...qwen4PartOptions(part, modelId) }];
|
|
375
380
|
}
|
|
376
381
|
if (part.type === "audio") {
|
|
377
382
|
return [{
|
|
@@ -394,7 +399,8 @@ const mapContentParts = (message, modelId) => {
|
|
|
394
399
|
return [
|
|
395
400
|
{
|
|
396
401
|
type: "video_url",
|
|
397
|
-
video_url: { url: toQwenMediaURL(part.data, part.mediaType) }
|
|
402
|
+
video_url: { url: toQwenMediaURL(part.data, part.mediaType) },
|
|
403
|
+
...qwen4PartOptions(part, modelId)
|
|
398
404
|
}
|
|
399
405
|
];
|
|
400
406
|
}
|
|
@@ -431,6 +437,9 @@ const mapMessages = (messages, format, modelId) => messages.flatMap((message) =>
|
|
|
431
437
|
if (reasoningContent) {
|
|
432
438
|
payload.reasoning_content = reasoningContent;
|
|
433
439
|
}
|
|
440
|
+
const encryptedContent = encryptedReasoningFromMessage(message);
|
|
441
|
+
if (encryptedContent)
|
|
442
|
+
payload.encrypted_content = encryptedContent;
|
|
434
443
|
if (toolCalls.length) {
|
|
435
444
|
payload.tool_calls = toolCalls;
|
|
436
445
|
}
|
|
@@ -506,7 +515,7 @@ const mapStructuredOutput = (modelId, input) => {
|
|
|
506
515
|
if (!input.structuredOutput || input.structuredOutput.mode !== "native") {
|
|
507
516
|
return undefined;
|
|
508
517
|
}
|
|
509
|
-
if (isQwen38Flash(modelId)) {
|
|
518
|
+
if (isQwen38Flash(modelId) || isQwen4(modelId)) {
|
|
510
519
|
return {
|
|
511
520
|
type: "json_schema",
|
|
512
521
|
json_schema: {
|
|
@@ -522,7 +531,7 @@ const withStructuredOutputMessages = (modelId, input) => {
|
|
|
522
531
|
if (!input.structuredOutput || input.structuredOutput.mode !== "native") {
|
|
523
532
|
return input.messages;
|
|
524
533
|
}
|
|
525
|
-
if (isQwen38Flash(modelId)) {
|
|
534
|
+
if (isQwen38Flash(modelId) || isQwen4(modelId)) {
|
|
526
535
|
return input.messages;
|
|
527
536
|
}
|
|
528
537
|
const schema = JSON.stringify(toJSONSchema(input.structuredOutput.schema));
|
|
@@ -540,7 +549,9 @@ const withStructuredOutputMessages = (modelId, input) => {
|
|
|
540
549
|
];
|
|
541
550
|
};
|
|
542
551
|
const hasPreservedReasoning = (messages) => messages.some((message) => message.role === "assistant" && reasoningContentFromMessage(message));
|
|
543
|
-
const
|
|
552
|
+
const mapModernChatReasoningEffort = (modelId, effort) => {
|
|
553
|
+
if (isQwen4Max(modelId) && (effort === "medium" || effort === "high"))
|
|
554
|
+
return "high";
|
|
544
555
|
switch (effort) {
|
|
545
556
|
case undefined:
|
|
546
557
|
return undefined;
|
|
@@ -567,7 +578,7 @@ const validateQwenToolStream = (modelId, providerOptions, streaming) => {
|
|
|
567
578
|
throw new ConfigurationError(`Qwen ${modelId} tool_stream requires streamText(); it cannot be used with generateText() or generateObject().`);
|
|
568
579
|
}
|
|
569
580
|
};
|
|
570
|
-
const
|
|
581
|
+
const validateModernRequest = (modelId, input, providerOptions) => {
|
|
571
582
|
if (isQwen38OmniFlash(modelId)) {
|
|
572
583
|
const modalities = providerOptions.modalities;
|
|
573
584
|
if (providerOptions.audio !== undefined || (modalities !== undefined &&
|
|
@@ -596,8 +607,10 @@ const validateQwen38Request = (modelId, input, providerOptions) => {
|
|
|
596
607
|
}
|
|
597
608
|
}
|
|
598
609
|
}
|
|
610
|
+
if (isQwen4(modelId))
|
|
611
|
+
validateQwen4(modelId, input, providerOptions);
|
|
599
612
|
const sharedEffort = input.reasoning?.effort;
|
|
600
|
-
const providerEffort = providerOptions.reasoning_effort;
|
|
613
|
+
const providerEffort = providerOptions.reasoning_effort ?? (isQwen4(modelId) ? providerOptions.reasoning?.effort : undefined);
|
|
601
614
|
const sharedBudget = input.reasoning?.budgetTokens;
|
|
602
615
|
const providerBudget = providerOptions.thinking_budget;
|
|
603
616
|
if (isQwen38MaxPreview(modelId) &&
|
|
@@ -618,7 +631,7 @@ const validateQwen38Request = (modelId, input, providerOptions) => {
|
|
|
618
631
|
if (effort !== undefined && budget !== undefined) {
|
|
619
632
|
throw new ConfigurationError(`Qwen ${modelId} does not allow reasoning_effort and thinking_budget in the same request.`);
|
|
620
633
|
}
|
|
621
|
-
|
|
634
|
+
mapModernChatReasoningEffort(modelId, effort);
|
|
622
635
|
if (providerBudget !== undefined &&
|
|
623
636
|
(!Number.isInteger(providerBudget) || providerBudget < 0 || providerBudget > 262_144)) {
|
|
624
637
|
throw new ConfigurationError(`Qwen ${modelId} thinking_budget must be an integer between 0 and 262144.`);
|
|
@@ -626,12 +639,12 @@ const validateQwen38Request = (modelId, input, providerOptions) => {
|
|
|
626
639
|
if (sharedBudget !== undefined && sharedBudget > 262_144) {
|
|
627
640
|
throw new ConfigurationError(`Qwen ${modelId} reasoning.budgetTokens cannot exceed 262144.`);
|
|
628
641
|
}
|
|
629
|
-
if (
|
|
642
|
+
if (isModernHybridModel(modelId) &&
|
|
630
643
|
providerOptions.enable_thinking === false &&
|
|
631
644
|
((effort !== undefined && effort !== "none") || budget !== undefined)) {
|
|
632
645
|
throw new ConfigurationError(`Qwen ${modelId} cannot disable thinking while also configuring a reasoning effort or thinking budget.`);
|
|
633
646
|
}
|
|
634
|
-
if (
|
|
647
|
+
if (isModernHybridModel(modelId) &&
|
|
635
648
|
providerOptions.enable_thinking === true &&
|
|
636
649
|
effort === "none") {
|
|
637
650
|
throw new ConfigurationError(`Qwen ${modelId} cannot enable thinking with reasoning effort "none".`);
|
|
@@ -641,7 +654,7 @@ const validateQwen38Request = (modelId, input, providerOptions) => {
|
|
|
641
654
|
if (thinkingEnabled && (input.toolChoice === "required" || typeof input.toolChoice === "object")) {
|
|
642
655
|
throw new UnsupportedFeatureError(`Qwen ${modelId} supports toolChoice "required" or a named tool only when thinking is disabled.`);
|
|
643
656
|
}
|
|
644
|
-
if (
|
|
657
|
+
if (isModernHybridModel(modelId) &&
|
|
645
658
|
input.messages.some((message) => message.parts.some((part) => part.type === "file" && !part.mediaType.toLowerCase().startsWith("video/")))) {
|
|
646
659
|
throw new UnsupportedFeatureError(`Qwen ${modelId} FilePart input is reserved for video/* media. Use ImagePart for images.`);
|
|
647
660
|
}
|
|
@@ -649,8 +662,9 @@ const validateQwen38Request = (modelId, input, providerOptions) => {
|
|
|
649
662
|
const mapChatReasoning = (modelId, input, providerOptions) => {
|
|
650
663
|
if (thirdPartyProfile(modelId))
|
|
651
664
|
return thirdPartyReasoning(modelId, input, providerOptions, "chat");
|
|
652
|
-
if (
|
|
653
|
-
const
|
|
665
|
+
if (isModernReasoningModel(modelId)) {
|
|
666
|
+
const display = isQwen4Max(modelId) && (providerOptions.thinking_display === "summarized" || providerOptions.reasoning?.summary === "auto") ? { thinking_display: "summarized", enable_thinking: true } : {};
|
|
667
|
+
const rawEffort = input.reasoning?.effort ?? providerOptions.reasoning_effort ?? (isQwen4(modelId) ? providerOptions.reasoning?.effort : undefined);
|
|
654
668
|
const thinkingDisabled = rawEffort === "none" || providerOptions.enable_thinking === false;
|
|
655
669
|
if (thinkingDisabled) {
|
|
656
670
|
return {
|
|
@@ -659,7 +673,7 @@ const mapChatReasoning = (modelId, input, providerOptions) => {
|
|
|
659
673
|
preserve_thinking: true
|
|
660
674
|
};
|
|
661
675
|
}
|
|
662
|
-
const effort =
|
|
676
|
+
const effort = mapModernChatReasoningEffort(modelId, input.reasoning?.effort ?? providerOptions.reasoning_effort ?? (isQwen4(modelId) ? providerOptions.reasoning?.effort : undefined));
|
|
663
677
|
const budget = input.reasoning?.budgetTokens ?? providerOptions.thinking_budget;
|
|
664
678
|
return {
|
|
665
679
|
...(effort ? { reasoning_effort: effort } : {}),
|
|
@@ -667,7 +681,8 @@ const mapChatReasoning = (modelId, input, providerOptions) => {
|
|
|
667
681
|
...(providerOptions.enable_thinking === true && effort === undefined && budget === undefined
|
|
668
682
|
? { enable_thinking: true }
|
|
669
683
|
: {}),
|
|
670
|
-
preserve_thinking: true
|
|
684
|
+
preserve_thinking: true,
|
|
685
|
+
...display
|
|
671
686
|
};
|
|
672
687
|
}
|
|
673
688
|
if (!input.reasoning) {
|
|
@@ -684,24 +699,26 @@ const mapChatReasoning = (modelId, input, providerOptions) => {
|
|
|
684
699
|
const mapResponsesReasoning = (modelId, input, providerOptions) => {
|
|
685
700
|
if (thirdPartyProfile(modelId))
|
|
686
701
|
return thirdPartyReasoning(modelId, input, providerOptions, "responses");
|
|
687
|
-
const effort = input.reasoning?.effort ?? providerOptions.reasoning_effort;
|
|
688
|
-
const
|
|
702
|
+
const effort = input.reasoning?.effort ?? providerOptions.reasoning_effort ?? (isQwen4(modelId) ? providerOptions.reasoning?.effort : undefined);
|
|
703
|
+
const resolvedEffort = isModernHybridModel(modelId) &&
|
|
689
704
|
providerOptions.enable_thinking === false &&
|
|
690
705
|
effort === undefined
|
|
691
706
|
? "none"
|
|
692
707
|
: effort;
|
|
693
|
-
|
|
708
|
+
const summary = isQwen4Max(modelId) ? providerOptions.reasoning?.summary ?? (providerOptions.thinking_display === "summarized" ? "auto" : undefined) : undefined;
|
|
709
|
+
if (!resolvedEffort && !summary) {
|
|
694
710
|
return undefined;
|
|
695
711
|
}
|
|
696
712
|
return {
|
|
697
713
|
reasoning: {
|
|
714
|
+
...(summary ? { summary } : {}),
|
|
698
715
|
effort: isQwen38MaxPreview(modelId)
|
|
699
|
-
?
|
|
700
|
-
:
|
|
701
|
-
?
|
|
702
|
-
:
|
|
716
|
+
? mapModernChatReasoningEffort(modelId, resolvedEffort)
|
|
717
|
+
: isModernHybridModel(modelId)
|
|
718
|
+
? resolvedEffort
|
|
719
|
+
: resolvedEffort === "low"
|
|
703
720
|
? "minimal"
|
|
704
|
-
:
|
|
721
|
+
: resolvedEffort
|
|
705
722
|
}
|
|
706
723
|
};
|
|
707
724
|
};
|
|
@@ -709,6 +726,7 @@ const mapResponsesUsage = (usage) => usage
|
|
|
709
726
|
? {
|
|
710
727
|
inputTokens: usage.input_tokens,
|
|
711
728
|
cachedInputTokens: usage.input_tokens_details?.cached_tokens,
|
|
729
|
+
...(usage.input_tokens_details?.cache_write_tokens !== undefined ? { cacheWriteTokens: usage.input_tokens_details.cache_write_tokens } : {}),
|
|
712
730
|
outputTokens: usage.output_tokens,
|
|
713
731
|
reasoningTokens: usage.output_tokens_details?.reasoning_tokens,
|
|
714
732
|
totalTokens: usage.total_tokens
|
|
@@ -718,6 +736,7 @@ const mapChatUsage = (usage) => usage
|
|
|
718
736
|
? {
|
|
719
737
|
inputTokens: usage.prompt_tokens,
|
|
720
738
|
cachedInputTokens: usage.prompt_tokens_details?.cached_tokens ?? usage.input_tokens_details?.cached_tokens,
|
|
739
|
+
...((usage.prompt_tokens_details?.cache_write_tokens ?? usage.input_tokens_details?.cache_write_tokens) !== undefined ? { cacheWriteTokens: usage.prompt_tokens_details?.cache_write_tokens ?? usage.input_tokens_details.cache_write_tokens } : {}),
|
|
721
740
|
outputTokens: usage.completion_tokens,
|
|
722
741
|
reasoningTokens: usage.completion_tokens_details?.reasoning_tokens ?? usage.output_tokens_details?.reasoning_tokens,
|
|
723
742
|
totalTokens: usage.total_tokens
|
|
@@ -729,7 +748,7 @@ const hasVideoInput = (messages) => messages.some((message) => message.parts.som
|
|
|
729
748
|
const hasNonVideoFileInput = (messages) => messages.some((message) => message.parts.some((part) => part.type === "file" && !part.mediaType.toLowerCase().startsWith("video/")));
|
|
730
749
|
// Only documented Responses families may send a bounded output request.
|
|
731
750
|
const responsesOutputLimitFamilies = new Set([
|
|
732
|
-
"qwen3.8-max", "qwen3.8-flash", "qwen3.8-omni-flash", "qwen3.8-2.4t-a95b", "qwen3.8-27b",
|
|
751
|
+
"qwen4-max", "qwen4-max-preview", "qwen3.8-max", "qwen3.8-flash", "qwen3.8-omni-flash", "qwen3.8-2.4t-a95b", "qwen3.8-27b",
|
|
733
752
|
"qwen3.7-max", "qwen3.7-max-preview", "qwen3.7-plus", "qwen3.7-flash",
|
|
734
753
|
"qwen3.6-plus", "qwen3.6-flash", "qwen3.6-35b-a3b", "qwen3-max",
|
|
735
754
|
"qwen3.5-plus", "qwen3.5-flash", "qwen3.5-397b-a17b", "qwen3.5-122b-a10b", "qwen3.5-27b", "qwen3.5-35b-a3b"
|
|
@@ -761,7 +780,7 @@ const resolveApiMode = (modelId, requestedMode, input, providerOptions) => {
|
|
|
761
780
|
if (isQwenTranslation(modelId) || isQwenCharacter(modelId))
|
|
762
781
|
return "chat";
|
|
763
782
|
const videoInput = hasVideoInput(input.messages);
|
|
764
|
-
if (videoInput && !
|
|
783
|
+
if (videoInput && !isModernHybridModel(modelId) && !isQwen38Open(modelId)) {
|
|
765
784
|
throw new UnsupportedFeatureError(`Qwen model "${modelId}" does not support video FilePart input through this adapter.`);
|
|
766
785
|
}
|
|
767
786
|
const omni38 = isQwen38OmniFlash(modelId);
|
|
@@ -773,15 +792,21 @@ const resolveApiMode = (modelId, requestedMode, input, providerOptions) => {
|
|
|
773
792
|
if (glmCallableTools && requestedMode === "responses") {
|
|
774
793
|
throw new UnsupportedFeatureError('QwenCloud glm-5.2 callable tools require apiMode "chat" or "auto" because Responses function continuation is unavailable.');
|
|
775
794
|
}
|
|
795
|
+
const needsResponses = hasHostedTools(input.tools) || hasNonVideoFileInput(input.messages) || providerOptions.max_output_tokens !== undefined;
|
|
796
|
+
// Qwen Responses documents only text.format.type="text"; live Qwen4 requests
|
|
797
|
+
// echo json_schema but can return fenced, invalid JSON even with strict=true.
|
|
798
|
+
if (input.structuredOutput?.mode === "native" && (requestedMode === "responses" || needsResponses)) {
|
|
799
|
+
throw new UnsupportedFeatureError('Qwen native structured output requires Chat Completions and cannot be combined with Responses-only features. Use mode "prompted" for locally validated JSON with Responses or hosted tools.');
|
|
800
|
+
}
|
|
776
801
|
const needsChat = glmCallableTools ||
|
|
777
802
|
(input.maxTokens !== undefined && (!supportsResponsesOutputLimit(modelId) ||
|
|
778
803
|
(requestedMode === "auto" && !hasHostedTools(input.tools) && !hasNonVideoFileInput(input.messages) && providerOptions.max_output_tokens === undefined))) ||
|
|
779
804
|
input.reasoning?.budgetTokens !== undefined ||
|
|
780
805
|
providerOptions.thinking_budget !== undefined ||
|
|
781
806
|
providerOptions.tool_stream === true ||
|
|
807
|
+
(isQwen4(modelId) && providerOptions.response_format !== undefined) ||
|
|
782
808
|
input.structuredOutput?.mode === "native" ||
|
|
783
|
-
(!omni38 && (hasMessagePart(input.messages, "audio") || videoInput));
|
|
784
|
-
const needsResponses = hasHostedTools(input.tools) || hasNonVideoFileInput(input.messages) || providerOptions.max_output_tokens !== undefined;
|
|
809
|
+
(!omni38 && (hasMessagePart(input.messages, "audio") || videoInput && !isQwen4(modelId)));
|
|
785
810
|
if (needsChat && needsResponses) {
|
|
786
811
|
throw new UnsupportedFeatureError("Qwen cannot combine Responses-only hosted/file inputs with Chat-only options (including maxTokens on unsupported models), audio, video, reasoning budgets, structured output, or tool streaming.");
|
|
787
812
|
}
|
|
@@ -866,6 +891,8 @@ const parseAssistantMessage = (message, input) => {
|
|
|
866
891
|
return {
|
|
867
892
|
role: "assistant",
|
|
868
893
|
parts: [
|
|
894
|
+
...(typeof message.encrypted_content === "string" && message.encrypted_content
|
|
895
|
+
? [providerDataPart("qwen", { type: "encrypted_content", encryptedContent: message.encrypted_content })] : []),
|
|
869
896
|
...(typeof message.reasoning_content === "string" && message.reasoning_content
|
|
870
897
|
? [providerDataPart("qwen", { type: "reasoning_content", reasoningContent: message.reasoning_content })]
|
|
871
898
|
: []),
|
|
@@ -926,10 +953,10 @@ const toResponsesInput = (messages, format, modelId) => {
|
|
|
926
953
|
for (const part of message.parts) {
|
|
927
954
|
switch (part.type) {
|
|
928
955
|
case "text":
|
|
929
|
-
content.push({ type: "input_text", text: part.text });
|
|
956
|
+
content.push({ type: "input_text", text: part.text, ...qwen4PartOptions(part, modelId) });
|
|
930
957
|
break;
|
|
931
958
|
case "image":
|
|
932
|
-
content.push({ type: "input_image", image_url: imageInputToDataUrl(part) });
|
|
959
|
+
content.push({ type: "input_image", image_url: imageInputToDataUrl(part), ...qwen4PartOptions(part, modelId) });
|
|
933
960
|
break;
|
|
934
961
|
case "audio":
|
|
935
962
|
if (modelId && isQwen38OmniFlash(modelId)) {
|
|
@@ -942,8 +969,8 @@ const toResponsesInput = (messages, format, modelId) => {
|
|
|
942
969
|
}
|
|
943
970
|
break;
|
|
944
971
|
case "file":
|
|
945
|
-
if (modelId && isQwen38OmniFlash(modelId) && part.mediaType.toLowerCase().startsWith("video/")) {
|
|
946
|
-
content.push({ type: "input_video", video_url: toQwenMediaURL(part.data, part.mediaType) });
|
|
972
|
+
if (modelId && (isQwen38OmniFlash(modelId) || isQwen4(modelId)) && part.mediaType.toLowerCase().startsWith("video/")) {
|
|
973
|
+
content.push({ type: "input_video", video_url: toQwenMediaURL(part.data, part.mediaType), ...qwen4PartOptions(part, modelId) });
|
|
947
974
|
break;
|
|
948
975
|
}
|
|
949
976
|
if (!/^https?:\/\//i.test(part.data)) {
|
|
@@ -971,7 +998,7 @@ const toResponsesInput = (messages, format, modelId) => {
|
|
|
971
998
|
part.data &&
|
|
972
999
|
typeof part.data === "object" &&
|
|
973
1000
|
typeof part.data.type === "string" &&
|
|
974
|
-
!["response.annotations", "hosted-tool-usage"].includes(String(part.data.type))) {
|
|
1001
|
+
!["response.annotations", "hosted-tool-usage", "reasoning_content", "reasoning_summary", "encrypted_content"].includes(String(part.data.type))) {
|
|
975
1002
|
input.push(part.data);
|
|
976
1003
|
}
|
|
977
1004
|
break;
|
|
@@ -1124,19 +1151,24 @@ const normalizeResponsesFinishReason = (status, hasToolCalls) => {
|
|
|
1124
1151
|
}
|
|
1125
1152
|
return normalizeFinishReason(status);
|
|
1126
1153
|
};
|
|
1127
|
-
const streamResponses = async function* (response, input) {
|
|
1154
|
+
const streamResponses = async function* (response, input, modelId) {
|
|
1128
1155
|
const attemptId = globalThis.crypto.randomUUID();
|
|
1129
1156
|
const searchEnabled = Object.values(input.tools ?? {}).some(t => !isCallableToolDefinition(t) && t.type === "web_search");
|
|
1130
1157
|
if (searchEnabled)
|
|
1131
1158
|
yield { type: "provider-data", provider: "qwen", data: qwenSearchUsage(attemptId) };
|
|
1132
1159
|
const collectAnnotations = createAnnotationCollector();
|
|
1133
1160
|
const providerDataSnapshots = new Map();
|
|
1161
|
+
const reasoningSnapshots = new Map();
|
|
1134
1162
|
const collectProviderData = (item, outputIndex) => {
|
|
1135
1163
|
const data = parseResponsesProviderData(item);
|
|
1136
1164
|
if (!data)
|
|
1137
1165
|
return undefined;
|
|
1138
1166
|
const typedItem = item;
|
|
1139
1167
|
const key = JSON.stringify([typedItem.type, typeof typedItem.id === "string" ? typedItem.id : outputIndex]);
|
|
1168
|
+
if (modelId && isQwen4(modelId) && typedItem.type === "reasoning") {
|
|
1169
|
+
reasoningSnapshots.set(typeof outputIndex === "number" ? `output:${outputIndex}` : key, data);
|
|
1170
|
+
return undefined;
|
|
1171
|
+
}
|
|
1140
1172
|
const snapshot = JSON.stringify(data);
|
|
1141
1173
|
if (providerDataSnapshots.get(key) === snapshot)
|
|
1142
1174
|
return undefined;
|
|
@@ -1202,7 +1234,7 @@ const streamResponses = async function* (response, input) {
|
|
|
1202
1234
|
type: "provider-data",
|
|
1203
1235
|
provider: "qwen",
|
|
1204
1236
|
data: {
|
|
1205
|
-
type: "reasoning_content",
|
|
1237
|
+
type: type === "response.reasoning_summary_text.delta" && modelId && isQwen4(modelId) ? "reasoning_summary" : "reasoning_content",
|
|
1206
1238
|
reasoningContent: json.delta
|
|
1207
1239
|
}
|
|
1208
1240
|
};
|
|
@@ -1394,6 +1426,8 @@ const streamResponses = async function* (response, input) {
|
|
|
1394
1426
|
? { providerMetadata: { qwenResponsesCallId: call.providerCallId } } : {})
|
|
1395
1427
|
} });
|
|
1396
1428
|
}
|
|
1429
|
+
for (const data of reasoningSnapshots.values())
|
|
1430
|
+
yield { type: "provider-data", provider: "qwen", data };
|
|
1397
1431
|
for (const event of materialized) {
|
|
1398
1432
|
input.abortSignal?.throwIfAborted();
|
|
1399
1433
|
yield event;
|
|
@@ -1430,14 +1464,14 @@ class QwenLanguageModel {
|
|
|
1430
1464
|
validateThirdParty(this.modelId, input, providerOptions);
|
|
1431
1465
|
validateQwenSpecializedText(this.modelId, input);
|
|
1432
1466
|
validateQwenToolStream(this.modelId, providerOptions, false);
|
|
1433
|
-
if (
|
|
1434
|
-
|
|
1467
|
+
if (isModernReasoningModel(this.modelId)) {
|
|
1468
|
+
validateModernRequest(this.modelId, input, providerOptions);
|
|
1435
1469
|
}
|
|
1436
|
-
if (
|
|
1470
|
+
if (isModernHybridModel(this.modelId) && !isQwen4(this.modelId)) {
|
|
1437
1471
|
validateQwen38ProductionBaseURL(this.modelId, this.baseURL);
|
|
1438
1472
|
}
|
|
1439
|
-
if (isQwen38MaxPreview(this.modelId)) {
|
|
1440
|
-
|
|
1473
|
+
if (isQwen38MaxPreview(this.modelId) || isQwen4Preview(this.modelId)) {
|
|
1474
|
+
validateQwenPreviewBaseURL(this.baseURL, this.modelId);
|
|
1441
1475
|
}
|
|
1442
1476
|
const apiMode = resolveApiMode(this.modelId, providerOptions.apiMode ?? "auto", input, providerOptions);
|
|
1443
1477
|
delete providerOptions.apiMode;
|
|
@@ -1445,10 +1479,10 @@ class QwenLanguageModel {
|
|
|
1445
1479
|
const { signal, cleanup } = withTimeoutSignal(input);
|
|
1446
1480
|
try {
|
|
1447
1481
|
if (apiMode === "responses") {
|
|
1448
|
-
const previousResponse = getProviderResponseId(input.messages);
|
|
1482
|
+
const previousResponse = providerOptions.store === false ? undefined : getProviderResponseId(input.messages);
|
|
1449
1483
|
const baseResponseProviderOptions = stripResponsesRequestOptions(providerOptions);
|
|
1450
|
-
const responseProviderOptions = (
|
|
1451
|
-
?
|
|
1484
|
+
const responseProviderOptions = (isModernReasoningModel(this.modelId) || thirdPartyProfile(this.modelId))
|
|
1485
|
+
? stripModernReasoningOptions(baseResponseProviderOptions)
|
|
1452
1486
|
: baseResponseProviderOptions;
|
|
1453
1487
|
const messages = previousResponse && previousResponse.index < input.messages.length - 1
|
|
1454
1488
|
? input.messages.slice(previousResponse.index + 1)
|
|
@@ -1489,8 +1523,8 @@ class QwenLanguageModel {
|
|
|
1489
1523
|
};
|
|
1490
1524
|
}
|
|
1491
1525
|
const baseChatProviderOptions = stripHeaderOptions(providerOptions);
|
|
1492
|
-
const chatProviderOptions = (
|
|
1493
|
-
?
|
|
1526
|
+
const chatProviderOptions = (isModernReasoningModel(this.modelId) || thirdPartyProfile(this.modelId))
|
|
1527
|
+
? stripModernReasoningOptions(baseChatProviderOptions)
|
|
1494
1528
|
: baseChatProviderOptions;
|
|
1495
1529
|
const response = await withResponseRetry(() => this.fetcher(`${this.baseURL}/chat/completions`, {
|
|
1496
1530
|
method: "POST",
|
|
@@ -1503,10 +1537,10 @@ class QwenLanguageModel {
|
|
|
1503
1537
|
messages: mapMessages(withStructuredOutputMessages(this.modelId, input), input.toolResultFormat, this.modelId),
|
|
1504
1538
|
tools: mapChatTools(input.tools),
|
|
1505
1539
|
tool_choice: mapChatToolChoice(input.toolChoice),
|
|
1506
|
-
response_format: mapStructuredOutput(this.modelId, input),
|
|
1540
|
+
response_format: mapStructuredOutput(this.modelId, input) ?? (isQwen4(this.modelId) ? providerOptions.response_format : undefined),
|
|
1507
1541
|
temperature: input.temperature,
|
|
1508
|
-
max_tokens: (
|
|
1509
|
-
max_completion_tokens: (
|
|
1542
|
+
max_tokens: (isModernReasoningModel(this.modelId) || thirdPartyProfile(this.modelId)?.completionTokens) ? undefined : input.maxTokens,
|
|
1543
|
+
max_completion_tokens: (isModernReasoningModel(this.modelId) || thirdPartyProfile(this.modelId)?.completionTokens) ? input.maxTokens : undefined,
|
|
1510
1544
|
stream: false,
|
|
1511
1545
|
...mapChatReasoning(this.modelId, input, providerOptions)
|
|
1512
1546
|
})
|
|
@@ -1536,24 +1570,24 @@ class QwenLanguageModel {
|
|
|
1536
1570
|
validateThirdParty(this.modelId, input, providerOptions);
|
|
1537
1571
|
validateQwenSpecializedText(this.modelId, input);
|
|
1538
1572
|
validateQwenToolStream(this.modelId, providerOptions, true);
|
|
1539
|
-
if (
|
|
1540
|
-
|
|
1573
|
+
if (isModernReasoningModel(this.modelId)) {
|
|
1574
|
+
validateModernRequest(this.modelId, input, providerOptions);
|
|
1541
1575
|
}
|
|
1542
|
-
if (
|
|
1576
|
+
if (isModernHybridModel(this.modelId) && !isQwen4(this.modelId)) {
|
|
1543
1577
|
validateQwen38ProductionBaseURL(this.modelId, this.baseURL);
|
|
1544
1578
|
}
|
|
1545
|
-
if (isQwen38MaxPreview(this.modelId)) {
|
|
1546
|
-
|
|
1579
|
+
if (isQwen38MaxPreview(this.modelId) || isQwen4Preview(this.modelId)) {
|
|
1580
|
+
validateQwenPreviewBaseURL(this.baseURL, this.modelId);
|
|
1547
1581
|
}
|
|
1548
1582
|
const apiMode = resolveApiMode(this.modelId, providerOptions.apiMode ?? "auto", input, providerOptions);
|
|
1549
1583
|
delete providerOptions.apiMode;
|
|
1550
1584
|
const outputLimit = apiMode === "responses" ? responsesOutputLimit(this.modelId, input, providerOptions) : undefined;
|
|
1551
1585
|
const { signal, cleanup } = withTimeoutSignal(input);
|
|
1552
1586
|
if (apiMode === "responses") {
|
|
1553
|
-
const previousResponse = getProviderResponseId(input.messages);
|
|
1587
|
+
const previousResponse = providerOptions.store === false ? undefined : getProviderResponseId(input.messages);
|
|
1554
1588
|
const baseResponseProviderOptions = stripResponsesRequestOptions(providerOptions);
|
|
1555
|
-
const responseProviderOptions = (
|
|
1556
|
-
?
|
|
1589
|
+
const responseProviderOptions = (isModernReasoningModel(this.modelId) || thirdPartyProfile(this.modelId))
|
|
1590
|
+
? stripModernReasoningOptions(baseResponseProviderOptions)
|
|
1557
1591
|
: baseResponseProviderOptions;
|
|
1558
1592
|
const messages = previousResponse && previousResponse.index < input.messages.length - 1
|
|
1559
1593
|
? input.messages.slice(previousResponse.index + 1)
|
|
@@ -1575,9 +1609,10 @@ class QwenLanguageModel {
|
|
|
1575
1609
|
stream: true
|
|
1576
1610
|
})
|
|
1577
1611
|
}), { ...input, abortSignal: signal }, "Qwen").catch((error) => { cleanup(); throw error; });
|
|
1612
|
+
const modelId = this.modelId;
|
|
1578
1613
|
return (async function* () {
|
|
1579
1614
|
try {
|
|
1580
|
-
yield* streamResponses(response, { ...input, abortSignal: signal });
|
|
1615
|
+
yield* streamResponses(response, { ...input, abortSignal: signal }, modelId);
|
|
1581
1616
|
}
|
|
1582
1617
|
finally {
|
|
1583
1618
|
cleanup();
|
|
@@ -1585,8 +1620,8 @@ class QwenLanguageModel {
|
|
|
1585
1620
|
})();
|
|
1586
1621
|
}
|
|
1587
1622
|
const baseChatProviderOptions = stripHeaderOptions(providerOptions);
|
|
1588
|
-
const chatProviderOptions = (
|
|
1589
|
-
?
|
|
1623
|
+
const chatProviderOptions = (isModernReasoningModel(this.modelId) || thirdPartyProfile(this.modelId))
|
|
1624
|
+
? stripModernReasoningOptions(baseChatProviderOptions)
|
|
1590
1625
|
: baseChatProviderOptions;
|
|
1591
1626
|
const response = await withResponseRetry(() => this.fetcher(`${this.baseURL}/chat/completions`, {
|
|
1592
1627
|
method: "POST",
|
|
@@ -1599,10 +1634,10 @@ class QwenLanguageModel {
|
|
|
1599
1634
|
messages: mapMessages(withStructuredOutputMessages(this.modelId, input), input.toolResultFormat, this.modelId),
|
|
1600
1635
|
tools: mapChatTools(input.tools),
|
|
1601
1636
|
tool_choice: mapChatToolChoice(input.toolChoice),
|
|
1602
|
-
response_format: mapStructuredOutput(this.modelId, input),
|
|
1637
|
+
response_format: mapStructuredOutput(this.modelId, input) ?? (isQwen4(this.modelId) ? providerOptions.response_format : undefined),
|
|
1603
1638
|
temperature: input.temperature,
|
|
1604
|
-
max_tokens: (
|
|
1605
|
-
max_completion_tokens: (
|
|
1639
|
+
max_tokens: (isModernReasoningModel(this.modelId) || thirdPartyProfile(this.modelId)?.completionTokens) ? undefined : input.maxTokens,
|
|
1640
|
+
max_completion_tokens: (isModernReasoningModel(this.modelId) || thirdPartyProfile(this.modelId)?.completionTokens) ? input.maxTokens : undefined,
|
|
1606
1641
|
stream: true,
|
|
1607
1642
|
stream_options: { include_usage: true },
|
|
1608
1643
|
...mapChatReasoning(this.modelId, input, providerOptions)
|
|
@@ -1641,6 +1676,9 @@ class QwenLanguageModel {
|
|
|
1641
1676
|
}
|
|
1642
1677
|
};
|
|
1643
1678
|
}
|
|
1679
|
+
if (typeof delta?.encrypted_content === "string" && delta.encrypted_content) {
|
|
1680
|
+
yield { type: "provider-data", provider: "qwen", data: { type: "encrypted_content", encryptedContent: delta.encrypted_content } };
|
|
1681
|
+
}
|
|
1644
1682
|
if (delta?.content) {
|
|
1645
1683
|
const content = String(delta.content);
|
|
1646
1684
|
if (cumulativeTranslation && !content.startsWith(translationText))
|
|
@@ -1663,7 +1701,7 @@ class QwenLanguageModel {
|
|
|
1663
1701
|
existing.args += toolCall.function?.arguments ?? "";
|
|
1664
1702
|
toolBuffers.set(index, existing);
|
|
1665
1703
|
}
|
|
1666
|
-
if (choice?.finish_reason)
|
|
1704
|
+
if (choice?.finish_reason && choice.finish_reason !== "null")
|
|
1667
1705
|
lastFinishReason = choice.finish_reason;
|
|
1668
1706
|
if (json.usage) {
|
|
1669
1707
|
lastUsage = json.usage;
|
|
@@ -2050,7 +2088,11 @@ class QwenSpeechModel {
|
|
|
2050
2088
|
if (input.voice !== undefined && typeof input.voice !== "string") {
|
|
2051
2089
|
throw new UnsupportedFeatureError('Provider "qwen" accepts string voice names only.');
|
|
2052
2090
|
}
|
|
2053
|
-
const
|
|
2091
|
+
const isAudioGen = this.modelId === "qwen-audio-3.1-tts-next";
|
|
2092
|
+
if (isAudioGen && input.voice !== undefined)
|
|
2093
|
+
throw new UnsupportedFeatureError("Qwen TTS Next uses reference audio instead of a voice ID.");
|
|
2094
|
+
if (isAudioGen && (!input.input.trim() || [...input.input].length > 3000))
|
|
2095
|
+
throw new ConfigurationError("Qwen TTS Next requires 1–3000 characters.");
|
|
2054
2096
|
const providerOptions = { ...(input.providerOptions ?? {}) };
|
|
2055
2097
|
const nestedInput = providerOptions.input && typeof providerOptions.input === "object"
|
|
2056
2098
|
? providerOptions.input
|
|
@@ -2061,8 +2103,12 @@ class QwenSpeechModel {
|
|
|
2061
2103
|
delete providerOptions.input;
|
|
2062
2104
|
delete providerOptions.parameters;
|
|
2063
2105
|
delete providerOptions.model;
|
|
2106
|
+
const endpoint = isAudioGen ? "services/audio/tts/SpeechSynthesizer" : "services/aigc/multimodal-generation/generation";
|
|
2107
|
+
if (isAudioGen && (nestedInput.voice !== undefined || providerOptions.voice !== undefined || parameters !== undefined))
|
|
2108
|
+
throw new ConfigurationError("Qwen TTS Next accepts generation fields inside input and no voice parameter.");
|
|
2109
|
+
const { signal, cleanup, abort } = withTimeoutSignal(input);
|
|
2064
2110
|
try {
|
|
2065
|
-
const response = await withRetry(() => this.fetcher(`${this.taskBaseURL}
|
|
2111
|
+
const response = await withRetry(() => this.fetcher(`${this.taskBaseURL}/${endpoint}`, {
|
|
2066
2112
|
method: "POST",
|
|
2067
2113
|
headers: jsonHeaders(this.apiKey),
|
|
2068
2114
|
signal,
|
|
@@ -2071,12 +2117,11 @@ class QwenSpeechModel {
|
|
|
2071
2117
|
input: {
|
|
2072
2118
|
...providerOptions,
|
|
2073
2119
|
...nestedInput,
|
|
2074
|
-
text: input.input,
|
|
2075
|
-
voice: input.voice ?? "Cherry"
|
|
2120
|
+
...(isAudioGen ? { text_prompt: input.input } : { text: input.input, voice: input.voice ?? "Cherry" })
|
|
2076
2121
|
},
|
|
2077
2122
|
...(parameters ? { parameters } : {})
|
|
2078
2123
|
})
|
|
2079
|
-
}), input);
|
|
2124
|
+
}), isAudioGen ? { ...input, maxRetries: 0 } : input);
|
|
2080
2125
|
const json = await parseJson(response, {
|
|
2081
2126
|
maxBytes: this.responseLimits.speechJsonBytes,
|
|
2082
2127
|
errorBodyBytes: this.responseLimits.errorBodyBytes,
|
|
@@ -2461,7 +2506,7 @@ class QwenTasksClientImpl {
|
|
|
2461
2506
|
}
|
|
2462
2507
|
}
|
|
2463
2508
|
}
|
|
2464
|
-
const parseRealtimeEvent = (payload, fallbackRealtimeToolCallId, seenToolCallIds, liveTranslate = false) => {
|
|
2509
|
+
const parseRealtimeEvent = (payload, fallbackRealtimeToolCallId, seenToolCallIds, liveTranslate = false, modelId = "") => {
|
|
2465
2510
|
const type = String(payload.type ?? "");
|
|
2466
2511
|
const metadata = payload;
|
|
2467
2512
|
const itemId = typeof payload.item_id === "string" ? payload.item_id : undefined;
|
|
@@ -2515,6 +2560,10 @@ const parseRealtimeEvent = (payload, fallbackRealtimeToolCallId, seenToolCallIds
|
|
|
2515
2560
|
if (type === "session.finished") {
|
|
2516
2561
|
return [{ type: "realtime-end", reason: "finished", providerMetadata: metadata }];
|
|
2517
2562
|
}
|
|
2563
|
+
// Qwen-Audio documents these events for every audio realtime id. Other realtime models keep the .failed error path.
|
|
2564
|
+
if (type.startsWith("voiceprint_audio_list.") && isQwenAudioRealtime(modelId)) {
|
|
2565
|
+
return [{ type: "realtime-provider-data", provider: "qwen", data: metadata }];
|
|
2566
|
+
}
|
|
2518
2567
|
if (type === "error" || type.endsWith(".failed")) {
|
|
2519
2568
|
const error = payload.error;
|
|
2520
2569
|
return [{
|
|
@@ -2550,11 +2599,11 @@ const mapRealtimeTools = (config) => {
|
|
|
2550
2599
|
};
|
|
2551
2600
|
});
|
|
2552
2601
|
};
|
|
2553
|
-
const assertQwenRealtimeConfig = (config) => {
|
|
2602
|
+
const assertQwenRealtimeConfig = (modelId, config) => {
|
|
2554
2603
|
if (config.toolChoice !== undefined && !["auto", "none"].includes(String(config.toolChoice))) {
|
|
2555
2604
|
throw new UnsupportedFeatureError("Qwen realtime supports automatic tool selection or tool disabling, but not required or named tool choice.");
|
|
2556
2605
|
}
|
|
2557
|
-
if (config.tools && config.providerOptions?.enable_search === true) {
|
|
2606
|
+
if (config.tools && config.providerOptions?.enable_search === true && !isQwenAudio31RealtimeFlash(modelId)) {
|
|
2558
2607
|
throw new UnsupportedFeatureError("Qwen realtime tools and providerOptions.enable_search cannot be enabled together.");
|
|
2559
2608
|
}
|
|
2560
2609
|
};
|
|
@@ -2563,9 +2612,9 @@ const rejectObjectVoice = (voice) => {
|
|
|
2563
2612
|
throw new UnsupportedFeatureError('Provider "qwen" accepts string voice names only.');
|
|
2564
2613
|
}
|
|
2565
2614
|
};
|
|
2566
|
-
const mapRealtimeSession = (config) => {
|
|
2615
|
+
const mapRealtimeSession = (modelId, config) => {
|
|
2567
2616
|
rejectObjectVoice(config.voice);
|
|
2568
|
-
assertQwenRealtimeConfig(config);
|
|
2617
|
+
assertQwenRealtimeConfig(modelId, config);
|
|
2569
2618
|
return {
|
|
2570
2619
|
...(config.providerOptions ?? {}),
|
|
2571
2620
|
modalities: config.outputAudioMediaType || config.voice ? ["text", "audio"] : ["text"],
|
|
@@ -2598,12 +2647,33 @@ class QwenRealtimeModel {
|
|
|
2598
2647
|
if (isQwenCloudRealtime(this.modelId))
|
|
2599
2648
|
return {
|
|
2600
2649
|
...realtimeCapabilities, vision: !isQwenAudioRealtime(this.modelId), webSearch: true,
|
|
2601
|
-
agentCapabilities: {
|
|
2650
|
+
agentCapabilities: {
|
|
2651
|
+
...realtimeCapabilities.agentCapabilities,
|
|
2652
|
+
hostedWebSearch: true,
|
|
2653
|
+
remoteMcp: isQwenOmni38Realtime(this.modelId),
|
|
2654
|
+
// Docs describe mcp_approval_request for Omni 3.8 realtime. Approval stays
|
|
2655
|
+
// off, and this surface stays Tier B, until a live certification passes.
|
|
2656
|
+
approvalRequests: false,
|
|
2657
|
+
durableAgent: true,
|
|
2658
|
+
supportTier: "tier-b"
|
|
2659
|
+
},
|
|
2602
2660
|
realtime: { ...realtimeCapabilities.realtime, imageInput: !isQwenAudioRealtime(this.modelId) }
|
|
2603
2661
|
};
|
|
2604
2662
|
if (!isLiveTranslate38(this.modelId))
|
|
2605
2663
|
return realtimeCapabilities;
|
|
2606
|
-
return {
|
|
2664
|
+
return {
|
|
2665
|
+
...realtimeCapabilities,
|
|
2666
|
+
tools: false,
|
|
2667
|
+
agentCapabilities: {
|
|
2668
|
+
...realtimeCapabilities.agentCapabilities,
|
|
2669
|
+
durableAgent: false,
|
|
2670
|
+
supportTier: "tier-c",
|
|
2671
|
+
hostedWebSearch: false,
|
|
2672
|
+
remoteMcp: false,
|
|
2673
|
+
approvalRequests: false
|
|
2674
|
+
},
|
|
2675
|
+
realtime: { ...realtimeCapabilities.realtime, tools: false }
|
|
2676
|
+
};
|
|
2607
2677
|
}
|
|
2608
2678
|
constructor(modelId, apiKey, realtimeURL, connectionFactory) {
|
|
2609
2679
|
this.modelId = modelId;
|
|
@@ -2614,9 +2684,10 @@ class QwenRealtimeModel {
|
|
|
2614
2684
|
async connect(config = {}, options) {
|
|
2615
2685
|
const liveTranslate = isLiveTranslate38(this.modelId);
|
|
2616
2686
|
const cloudRealtime = isQwenCloudRealtime(this.modelId);
|
|
2617
|
-
const mapSession = liveTranslate ? liveTranslateSession :
|
|
2618
|
-
|
|
2619
|
-
:
|
|
2687
|
+
const mapSession = liveTranslate ? liveTranslateSession : (value) => {
|
|
2688
|
+
const base = mapRealtimeSession(this.modelId, value);
|
|
2689
|
+
return cloudRealtime ? mapQwenCloudRealtimeSession(this.modelId, value, base) : base;
|
|
2690
|
+
};
|
|
2620
2691
|
mapSession(config);
|
|
2621
2692
|
let audioSent = false;
|
|
2622
2693
|
let responseActive = false;
|
|
@@ -2648,7 +2719,7 @@ class QwenRealtimeModel {
|
|
|
2648
2719
|
const item = payload.item;
|
|
2649
2720
|
if (cloudRealtime && payload.type === "conversation.item.created" && item?.type === "mcp_approval_request" && typeof item.id === "string")
|
|
2650
2721
|
pendingMcpApprovals.add(item.id);
|
|
2651
|
-
return (cloudRealtime ? qwenCloudAudioEvent(payload, session.config) : undefined) ?? parseRealtimeEvent(payload, () => `qwen-realtime-tool-${fallbackRealtimeToolCallIndex++}`, seenRealtimeToolCallIds, liveTranslate || cloudRealtime);
|
|
2722
|
+
return (cloudRealtime ? qwenCloudAudioEvent(payload, session.config) : undefined) ?? parseRealtimeEvent(payload, () => `qwen-realtime-tool-${fallbackRealtimeToolCallIndex++}`, seenRealtimeToolCallIds, liveTranslate || cloudRealtime, this.modelId);
|
|
2652
2723
|
},
|
|
2653
2724
|
buildInitialPayloads: (value) => [{ type: "session.update", session: mapSession(value) }],
|
|
2654
2725
|
buildAudioPayloads: (frame, sessionConfig) => {
|