@zhivex-ai/qwen 0.18.0 → 0.19.0
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 +20 -2
- package/dist/capabilities.d.ts.map +1 -1
- package/dist/capabilities.js +2 -0
- package/dist/capabilities.js.map +1 -1
- package/dist/cloud-media.d.ts +11 -0
- package/dist/cloud-media.d.ts.map +1 -1
- package/dist/cloud-media.js +122 -0
- package/dist/cloud-media.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.map +1 -1
- package/dist/index.js +91 -34
- package/dist/index.js.map +1 -1
- package/dist/portable-decision.d.ts.map +1 -1
- package/dist/portable-decision.js +4 -3
- package/dist/portable-decision.js.map +1 -1
- 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
|
@@ -7,10 +7,10 @@ export { connectQwenWebRTC, connectQwenAOQ } from "./browser-realtime.js";
|
|
|
7
7
|
import { createQwenTemporaryKeysClient } from "./temporary-keys.js";
|
|
8
8
|
import { createQwenNativeTranscriptionModel, createQwenFileTranscriptionModel } from "./native-asr.js";
|
|
9
9
|
export { createQwenWorldRTC } from "./world-rtc.js";
|
|
10
|
-
import { createQwenImageTranslationModel, validateWan30, validateQwenImage21, validateQwenImage30, validateHappyHorse, prepareViduVideo, validateViduImage } from "./cloud-media.js";
|
|
10
|
+
import { createQwenImageTranslationModel, validateWan30, validateQwenImage21, validateQwenImage30, validateHappyHorse, prepareViduVideo, preparePixVerseVideo, assertPixVerseRegion, validateViduImage } from "./cloud-media.js";
|
|
11
11
|
import { createQwenWorldsClient } from "./worlds.js";
|
|
12
12
|
import { QwenCloudSpeechModel, QwenCloudStreamingASRModel, isQwenCloudSpeech, isQwenCloudStreamingASR } from "./inference-audio.js";
|
|
13
|
-
import { isQwenCloudRealtime, isQwenAudioRealtime, isQwenOmni38Realtime, mapQwenCloudRealtimeSession, validateQwenCloudAudioFrame, qwenCloudAudioEvent, extendQwenCloudRealtimeSession } from "./cloud-realtime.js";
|
|
13
|
+
import { isQwenCloudRealtime, isQwenAudioRealtime, isQwenAudio31RealtimeFlash, isQwenOmni38Realtime, mapQwenCloudRealtimeSession, validateQwenCloudAudioFrame, qwenCloudAudioEvent, extendQwenCloudRealtimeSession } from "./cloud-realtime.js";
|
|
14
14
|
import { createQwenDecisionModel } from "./decision.js";
|
|
15
15
|
import { assertQwenLanguageModel, isQwenTranslation, isQwenCharacter, isQwen38Open, validateQwenSpecializedText } from "./text-profiles.js";
|
|
16
16
|
import { createQwenTextEmbeddingModel } from "./embeddings.js";
|
|
@@ -314,6 +314,7 @@ const qwenLanguageCapabilities = (modelId) => {
|
|
|
314
314
|
agentCapabilities: {
|
|
315
315
|
...capabilities.agentCapabilities,
|
|
316
316
|
supportTier: tools && !omni ? "tier-b" : "tier-c",
|
|
317
|
+
durableAgent: Boolean(tools && !omni),
|
|
317
318
|
toolChoiceNone: tools,
|
|
318
319
|
hostedWebSearch: tools && !omni,
|
|
319
320
|
hostedFileSearch: tools && !omni && !omni38,
|
|
@@ -2050,7 +2051,11 @@ class QwenSpeechModel {
|
|
|
2050
2051
|
if (input.voice !== undefined && typeof input.voice !== "string") {
|
|
2051
2052
|
throw new UnsupportedFeatureError('Provider "qwen" accepts string voice names only.');
|
|
2052
2053
|
}
|
|
2053
|
-
const
|
|
2054
|
+
const isAudioGen = this.modelId === "qwen-audio-3.1-tts-next";
|
|
2055
|
+
if (isAudioGen && input.voice !== undefined)
|
|
2056
|
+
throw new UnsupportedFeatureError("Qwen TTS Next uses reference audio instead of a voice ID.");
|
|
2057
|
+
if (isAudioGen && (!input.input.trim() || [...input.input].length > 3000))
|
|
2058
|
+
throw new ConfigurationError("Qwen TTS Next requires 1–3000 characters.");
|
|
2054
2059
|
const providerOptions = { ...(input.providerOptions ?? {}) };
|
|
2055
2060
|
const nestedInput = providerOptions.input && typeof providerOptions.input === "object"
|
|
2056
2061
|
? providerOptions.input
|
|
@@ -2061,8 +2066,12 @@ class QwenSpeechModel {
|
|
|
2061
2066
|
delete providerOptions.input;
|
|
2062
2067
|
delete providerOptions.parameters;
|
|
2063
2068
|
delete providerOptions.model;
|
|
2069
|
+
const endpoint = isAudioGen ? "services/audio/tts/SpeechSynthesizer" : "services/aigc/multimodal-generation/generation";
|
|
2070
|
+
if (isAudioGen && (nestedInput.voice !== undefined || providerOptions.voice !== undefined || parameters !== undefined))
|
|
2071
|
+
throw new ConfigurationError("Qwen TTS Next accepts generation fields inside input and no voice parameter.");
|
|
2072
|
+
const { signal, cleanup, abort } = withTimeoutSignal(input);
|
|
2064
2073
|
try {
|
|
2065
|
-
const response = await withRetry(() => this.fetcher(`${this.taskBaseURL}
|
|
2074
|
+
const response = await withRetry(() => this.fetcher(`${this.taskBaseURL}/${endpoint}`, {
|
|
2066
2075
|
method: "POST",
|
|
2067
2076
|
headers: jsonHeaders(this.apiKey),
|
|
2068
2077
|
signal,
|
|
@@ -2071,12 +2080,11 @@ class QwenSpeechModel {
|
|
|
2071
2080
|
input: {
|
|
2072
2081
|
...providerOptions,
|
|
2073
2082
|
...nestedInput,
|
|
2074
|
-
text: input.input,
|
|
2075
|
-
voice: input.voice ?? "Cherry"
|
|
2083
|
+
...(isAudioGen ? { text_prompt: input.input } : { text: input.input, voice: input.voice ?? "Cherry" })
|
|
2076
2084
|
},
|
|
2077
2085
|
...(parameters ? { parameters } : {})
|
|
2078
2086
|
})
|
|
2079
|
-
}), input);
|
|
2087
|
+
}), isAudioGen ? { ...input, maxRetries: 0 } : input);
|
|
2080
2088
|
const json = await parseJson(response, {
|
|
2081
2089
|
maxBytes: this.responseLimits.speechJsonBytes,
|
|
2082
2090
|
errorBodyBytes: this.responseLimits.errorBodyBytes,
|
|
@@ -2281,11 +2289,24 @@ class QwenVideoGenerationModel {
|
|
|
2281
2289
|
delete providerOptions.parameters;
|
|
2282
2290
|
delete providerOptions.model;
|
|
2283
2291
|
const happyHorseEdit = /^happyhorse-.*-video-edit$/.test(this.modelId);
|
|
2284
|
-
const
|
|
2285
|
-
|
|
2292
|
+
const pixverse = this.modelId.startsWith("pixverse/");
|
|
2293
|
+
let media;
|
|
2294
|
+
if (pixverse) {
|
|
2295
|
+
if (input.image && nestedInput.media !== undefined)
|
|
2296
|
+
throw new ConfigurationError("Pass either image or providerOptions.input.media for PixVerse, not both.");
|
|
2297
|
+
// it2v and r2v publish image_url. kf2v publishes first_frame plus last_frame, so a single convenience image cannot satisfy it.
|
|
2298
|
+
media = input.image
|
|
2299
|
+
? [{ type: this.modelId.endsWith("-kf2v") ? "first_frame" : "image_url", url: mediaValue(input.image) }]
|
|
2300
|
+
: nestedInput.media;
|
|
2301
|
+
}
|
|
2302
|
+
else if (input.image) {
|
|
2303
|
+
media = happyHorseEdit
|
|
2286
2304
|
? [...(Array.isArray(nestedInput.media) ? nestedInput.media : []), { type: "reference_image", url: mediaValue(input.image) }]
|
|
2287
|
-
: [{ type: this.modelId.startsWith("vidu/") ? "image" : "first_frame", url: mediaValue(input.image) }]
|
|
2288
|
-
|
|
2305
|
+
: [{ type: this.modelId.startsWith("vidu/") ? "image" : "first_frame", url: mediaValue(input.image) }];
|
|
2306
|
+
}
|
|
2307
|
+
else {
|
|
2308
|
+
media = nestedInput.media;
|
|
2309
|
+
}
|
|
2289
2310
|
let parameters = { ...providerOptions, ...nestedParameters };
|
|
2290
2311
|
if (input.aspectRatio !== undefined)
|
|
2291
2312
|
parameters.ratio = input.aspectRatio;
|
|
@@ -2295,13 +2316,21 @@ class QwenVideoGenerationModel {
|
|
|
2295
2316
|
parameters.n = input.count;
|
|
2296
2317
|
if (input.outputStorageUri !== undefined)
|
|
2297
2318
|
parameters.output_storage_uri = input.outputStorageUri;
|
|
2298
|
-
const usesMedia = /^(?:wan(?:2\.7|3\.0)(?:$|-)|happyhorse-|vidu\/)/i.test(this.modelId);
|
|
2319
|
+
const usesMedia = /^(?:wan(?:2\.7|3\.0)(?:$|-)|happyhorse-|vidu\/|pixverse\/)/i.test(this.modelId);
|
|
2299
2320
|
if (/^happyhorse-/.test(this.modelId))
|
|
2300
2321
|
validateHappyHorse(this.modelId, media, parameters);
|
|
2301
2322
|
if (/^wan3\.0-/.test(this.modelId))
|
|
2302
2323
|
validateWan30(media, parameters);
|
|
2303
2324
|
if (this.modelId.startsWith("vidu/"))
|
|
2304
2325
|
parameters = prepareViduVideo(this.modelId, media, parameters);
|
|
2326
|
+
if (pixverse) {
|
|
2327
|
+
if (input.negativePrompt !== undefined || nestedInput.negative_prompt !== undefined)
|
|
2328
|
+
throw new ConfigurationError("PixVerse does not support negative_prompt.");
|
|
2329
|
+
assertPixVerseRegion(this.taskBaseURL);
|
|
2330
|
+
const prepared = preparePixVerseVideo(this.modelId, media, parameters, input.prompt);
|
|
2331
|
+
parameters = prepared.parameters;
|
|
2332
|
+
media = prepared.media;
|
|
2333
|
+
}
|
|
2305
2334
|
const { signal, cleanup } = withTimeoutSignal(input);
|
|
2306
2335
|
try {
|
|
2307
2336
|
const response = await withRetry(() => this.fetcher(`${this.taskBaseURL}/services/aigc/video-generation/video-synthesis`, {
|
|
@@ -2311,16 +2340,18 @@ class QwenVideoGenerationModel {
|
|
|
2311
2340
|
signal,
|
|
2312
2341
|
body: JSON.stringify({
|
|
2313
2342
|
model: this.modelId,
|
|
2314
|
-
input:
|
|
2315
|
-
...
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
|
|
2343
|
+
input: pixverse
|
|
2344
|
+
? { prompt: input.prompt, ...(media !== undefined ? { media } : {}) }
|
|
2345
|
+
: {
|
|
2346
|
+
...nestedInput,
|
|
2347
|
+
prompt: input.prompt,
|
|
2348
|
+
negative_prompt: input.negativePrompt ?? nestedInput.negative_prompt,
|
|
2349
|
+
...(input.image
|
|
2350
|
+
? usesMedia
|
|
2351
|
+
? { media }
|
|
2352
|
+
: { img_url: mediaValue(input.image) }
|
|
2353
|
+
: {})
|
|
2354
|
+
},
|
|
2324
2355
|
parameters
|
|
2325
2356
|
})
|
|
2326
2357
|
}), { ...input, maxRetries: input.maxRetries ?? 0 });
|
|
@@ -2330,7 +2361,7 @@ class QwenVideoGenerationModel {
|
|
|
2330
2361
|
const items = json.output?.results ??
|
|
2331
2362
|
json.output?.videos ??
|
|
2332
2363
|
(json.output?.video_url ? [{ url: json.output.video_url }] : []);
|
|
2333
|
-
if (/^(?:wan3\.0-|happyhorse-|vidu\/)/.test(this.modelId) && !items.length &&
|
|
2364
|
+
if (/^(?:wan3\.0-|happyhorse-|vidu\/|pixverse\/)/.test(this.modelId) && !items.length &&
|
|
2334
2365
|
(typeof (json.output?.task_id ?? json.task_id) !== "string" || !(json.output?.task_id ?? json.task_id))) {
|
|
2335
2366
|
throw new ValidationError("Qwen video submission returned neither output nor a task ID.");
|
|
2336
2367
|
}
|
|
@@ -2438,7 +2469,7 @@ class QwenTasksClientImpl {
|
|
|
2438
2469
|
}
|
|
2439
2470
|
}
|
|
2440
2471
|
}
|
|
2441
|
-
const parseRealtimeEvent = (payload, fallbackRealtimeToolCallId, seenToolCallIds, liveTranslate = false) => {
|
|
2472
|
+
const parseRealtimeEvent = (payload, fallbackRealtimeToolCallId, seenToolCallIds, liveTranslate = false, modelId = "") => {
|
|
2442
2473
|
const type = String(payload.type ?? "");
|
|
2443
2474
|
const metadata = payload;
|
|
2444
2475
|
const itemId = typeof payload.item_id === "string" ? payload.item_id : undefined;
|
|
@@ -2492,6 +2523,10 @@ const parseRealtimeEvent = (payload, fallbackRealtimeToolCallId, seenToolCallIds
|
|
|
2492
2523
|
if (type === "session.finished") {
|
|
2493
2524
|
return [{ type: "realtime-end", reason: "finished", providerMetadata: metadata }];
|
|
2494
2525
|
}
|
|
2526
|
+
// Qwen-Audio documents these events for every audio realtime id. Other realtime models keep the .failed error path.
|
|
2527
|
+
if (type.startsWith("voiceprint_audio_list.") && isQwenAudioRealtime(modelId)) {
|
|
2528
|
+
return [{ type: "realtime-provider-data", provider: "qwen", data: metadata }];
|
|
2529
|
+
}
|
|
2495
2530
|
if (type === "error" || type.endsWith(".failed")) {
|
|
2496
2531
|
const error = payload.error;
|
|
2497
2532
|
return [{
|
|
@@ -2527,11 +2562,11 @@ const mapRealtimeTools = (config) => {
|
|
|
2527
2562
|
};
|
|
2528
2563
|
});
|
|
2529
2564
|
};
|
|
2530
|
-
const assertQwenRealtimeConfig = (config) => {
|
|
2565
|
+
const assertQwenRealtimeConfig = (modelId, config) => {
|
|
2531
2566
|
if (config.toolChoice !== undefined && !["auto", "none"].includes(String(config.toolChoice))) {
|
|
2532
2567
|
throw new UnsupportedFeatureError("Qwen realtime supports automatic tool selection or tool disabling, but not required or named tool choice.");
|
|
2533
2568
|
}
|
|
2534
|
-
if (config.tools && config.providerOptions?.enable_search === true) {
|
|
2569
|
+
if (config.tools && config.providerOptions?.enable_search === true && !isQwenAudio31RealtimeFlash(modelId)) {
|
|
2535
2570
|
throw new UnsupportedFeatureError("Qwen realtime tools and providerOptions.enable_search cannot be enabled together.");
|
|
2536
2571
|
}
|
|
2537
2572
|
};
|
|
@@ -2540,9 +2575,9 @@ const rejectObjectVoice = (voice) => {
|
|
|
2540
2575
|
throw new UnsupportedFeatureError('Provider "qwen" accepts string voice names only.');
|
|
2541
2576
|
}
|
|
2542
2577
|
};
|
|
2543
|
-
const mapRealtimeSession = (config) => {
|
|
2578
|
+
const mapRealtimeSession = (modelId, config) => {
|
|
2544
2579
|
rejectObjectVoice(config.voice);
|
|
2545
|
-
assertQwenRealtimeConfig(config);
|
|
2580
|
+
assertQwenRealtimeConfig(modelId, config);
|
|
2546
2581
|
return {
|
|
2547
2582
|
...(config.providerOptions ?? {}),
|
|
2548
2583
|
modalities: config.outputAudioMediaType || config.voice ? ["text", "audio"] : ["text"],
|
|
@@ -2575,12 +2610,33 @@ class QwenRealtimeModel {
|
|
|
2575
2610
|
if (isQwenCloudRealtime(this.modelId))
|
|
2576
2611
|
return {
|
|
2577
2612
|
...realtimeCapabilities, vision: !isQwenAudioRealtime(this.modelId), webSearch: true,
|
|
2578
|
-
agentCapabilities: {
|
|
2613
|
+
agentCapabilities: {
|
|
2614
|
+
...realtimeCapabilities.agentCapabilities,
|
|
2615
|
+
hostedWebSearch: true,
|
|
2616
|
+
remoteMcp: isQwenOmni38Realtime(this.modelId),
|
|
2617
|
+
// Docs describe mcp_approval_request for Omni 3.8 realtime. Approval stays
|
|
2618
|
+
// off, and this surface stays Tier B, until a live certification passes.
|
|
2619
|
+
approvalRequests: false,
|
|
2620
|
+
durableAgent: true,
|
|
2621
|
+
supportTier: "tier-b"
|
|
2622
|
+
},
|
|
2579
2623
|
realtime: { ...realtimeCapabilities.realtime, imageInput: !isQwenAudioRealtime(this.modelId) }
|
|
2580
2624
|
};
|
|
2581
2625
|
if (!isLiveTranslate38(this.modelId))
|
|
2582
2626
|
return realtimeCapabilities;
|
|
2583
|
-
return {
|
|
2627
|
+
return {
|
|
2628
|
+
...realtimeCapabilities,
|
|
2629
|
+
tools: false,
|
|
2630
|
+
agentCapabilities: {
|
|
2631
|
+
...realtimeCapabilities.agentCapabilities,
|
|
2632
|
+
durableAgent: false,
|
|
2633
|
+
supportTier: "tier-c",
|
|
2634
|
+
hostedWebSearch: false,
|
|
2635
|
+
remoteMcp: false,
|
|
2636
|
+
approvalRequests: false
|
|
2637
|
+
},
|
|
2638
|
+
realtime: { ...realtimeCapabilities.realtime, tools: false }
|
|
2639
|
+
};
|
|
2584
2640
|
}
|
|
2585
2641
|
constructor(modelId, apiKey, realtimeURL, connectionFactory) {
|
|
2586
2642
|
this.modelId = modelId;
|
|
@@ -2591,9 +2647,10 @@ class QwenRealtimeModel {
|
|
|
2591
2647
|
async connect(config = {}, options) {
|
|
2592
2648
|
const liveTranslate = isLiveTranslate38(this.modelId);
|
|
2593
2649
|
const cloudRealtime = isQwenCloudRealtime(this.modelId);
|
|
2594
|
-
const mapSession = liveTranslate ? liveTranslateSession :
|
|
2595
|
-
|
|
2596
|
-
:
|
|
2650
|
+
const mapSession = liveTranslate ? liveTranslateSession : (value) => {
|
|
2651
|
+
const base = mapRealtimeSession(this.modelId, value);
|
|
2652
|
+
return cloudRealtime ? mapQwenCloudRealtimeSession(this.modelId, value, base) : base;
|
|
2653
|
+
};
|
|
2597
2654
|
mapSession(config);
|
|
2598
2655
|
let audioSent = false;
|
|
2599
2656
|
let responseActive = false;
|
|
@@ -2625,7 +2682,7 @@ class QwenRealtimeModel {
|
|
|
2625
2682
|
const item = payload.item;
|
|
2626
2683
|
if (cloudRealtime && payload.type === "conversation.item.created" && item?.type === "mcp_approval_request" && typeof item.id === "string")
|
|
2627
2684
|
pendingMcpApprovals.add(item.id);
|
|
2628
|
-
return (cloudRealtime ? qwenCloudAudioEvent(payload, session.config) : undefined) ?? parseRealtimeEvent(payload, () => `qwen-realtime-tool-${fallbackRealtimeToolCallIndex++}`, seenRealtimeToolCallIds, liveTranslate || cloudRealtime);
|
|
2685
|
+
return (cloudRealtime ? qwenCloudAudioEvent(payload, session.config) : undefined) ?? parseRealtimeEvent(payload, () => `qwen-realtime-tool-${fallbackRealtimeToolCallIndex++}`, seenRealtimeToolCallIds, liveTranslate || cloudRealtime, this.modelId);
|
|
2629
2686
|
},
|
|
2630
2687
|
buildInitialPayloads: (value) => [{ type: "session.update", session: mapSession(value) }],
|
|
2631
2688
|
buildAudioPayloads: (frame, sessionConfig) => {
|