@convai/web-sdk 2.1.0-beta.2 → 2.1.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/dist/core/BlendshapeQueue.d.ts +20 -16
- package/dist/core/BlendshapeQueue.js +52 -42
- package/dist/core/ConvaiClient.js +11 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
|
@@ -53,19 +53,23 @@ export declare class BlendshapeQueue {
|
|
|
53
53
|
private playbackFps;
|
|
54
54
|
private ownerReplacementStoppedSpeaking;
|
|
55
55
|
private missingExpectedFramesSinceMs;
|
|
56
|
-
/** When the
|
|
57
|
-
private
|
|
56
|
+
/** When the indexed timeline first showed a hole in front of waiting frames, ms. */
|
|
57
|
+
private timelineGapSinceMs;
|
|
58
58
|
private readonly now;
|
|
59
59
|
private static readonly TARGET_FPS;
|
|
60
60
|
private static readonly MAX_RETIRED_TIMELINE_ALIASES;
|
|
61
|
+
private static readonly MISSING_INDEXED_FRAME_GRACE_MS;
|
|
61
62
|
/**
|
|
62
|
-
* How long
|
|
63
|
-
*
|
|
64
|
-
* the
|
|
65
|
-
*
|
|
63
|
+
* How long an indexed timeline waits for a missing chunk before playing on
|
|
64
|
+
* from the frames beyond it. A chunk can be lost between the server and
|
|
65
|
+
* the queue (dropped by the transport, or wiped by a local interrupt that
|
|
66
|
+
* raced the turn's first chunks); the frames after it kept arriving but
|
|
67
|
+
* nothing could flush past the hole, and the mouth stayed shut for the rest
|
|
68
|
+
* of a 25 s reply (measured 2026-11-12: 1480 frames waiting behind a
|
|
69
|
+
* six-frame hole). A quarter second is longer than any inter-chunk gap
|
|
70
|
+
* seen in production, so a late chunk still fills its hole in time.
|
|
66
71
|
*/
|
|
67
|
-
private static readonly
|
|
68
|
-
private static readonly MISSING_INDEXED_FRAME_GRACE_MS;
|
|
72
|
+
private static readonly INDEXED_GAP_SKIP_MS;
|
|
69
73
|
/**
|
|
70
74
|
* Create a new BlendshapeQueue
|
|
71
75
|
* @param mapper - Optional function to map/transform blendshape data as it's added
|
|
@@ -80,6 +84,14 @@ export declare class BlendshapeQueue {
|
|
|
80
84
|
private mapFrame;
|
|
81
85
|
private addTimelineChunk;
|
|
82
86
|
private flushContiguousTimelineFrames;
|
|
87
|
+
/**
|
|
88
|
+
* Play on past a hole in the indexed timeline once it has waited
|
|
89
|
+
* INDEXED_GAP_SKIP_MS: the missing frames count as consumed, so the
|
|
90
|
+
* server's frame accounting (turn stats, end fades) stays on its timeline,
|
|
91
|
+
* and the waiting frames flush. Called from every flush and from the
|
|
92
|
+
* player's reads, since a hole with nothing arriving gets no flush.
|
|
93
|
+
*/
|
|
94
|
+
private recoverTimelineGap;
|
|
83
95
|
private timelineAliases;
|
|
84
96
|
private hasActiveTimelineOwner;
|
|
85
97
|
private responseAlias;
|
|
@@ -159,14 +171,6 @@ export declare class BlendshapeQueue {
|
|
|
159
171
|
* Check if queue has frames
|
|
160
172
|
*/
|
|
161
173
|
hasFrames(): boolean;
|
|
162
|
-
/**
|
|
163
|
-
* The queue is dry, but indexed frames wait beyond a hole: give the missing chunk
|
|
164
|
-
* HOLE_GRACE_MS to arrive, then count the hole as consumed and play on from the
|
|
165
|
-
* frames beyond it. A consumer that follows `getFramesConsumed()` lands on them at
|
|
166
|
-
* the voice's time for them; a chunk for the hole that arrives later is dropped
|
|
167
|
-
* (its frames are behind `framesConsumed`).
|
|
168
|
-
*/
|
|
169
|
-
private skipLateHole;
|
|
170
174
|
/**
|
|
171
175
|
* Check if conversation is active
|
|
172
176
|
*/
|
|
@@ -62,8 +62,8 @@ export class BlendshapeQueue {
|
|
|
62
62
|
this.playbackFps = 60;
|
|
63
63
|
this.ownerReplacementStoppedSpeaking = false;
|
|
64
64
|
this.missingExpectedFramesSinceMs = null;
|
|
65
|
-
/** When the
|
|
66
|
-
this.
|
|
65
|
+
/** When the indexed timeline first showed a hole in front of waiting frames, ms. */
|
|
66
|
+
this.timelineGapSinceMs = null;
|
|
67
67
|
this.mapper = mapper;
|
|
68
68
|
this.now = now;
|
|
69
69
|
}
|
|
@@ -161,6 +161,41 @@ export class BlendshapeQueue {
|
|
|
161
161
|
this.queue.push(frame);
|
|
162
162
|
nextFrameIndex += 1;
|
|
163
163
|
}
|
|
164
|
+
this.recoverTimelineGap();
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Play on past a hole in the indexed timeline once it has waited
|
|
168
|
+
* INDEXED_GAP_SKIP_MS: the missing frames count as consumed, so the
|
|
169
|
+
* server's frame accounting (turn stats, end fades) stays on its timeline,
|
|
170
|
+
* and the waiting frames flush. Called from every flush and from the
|
|
171
|
+
* player's reads, since a hole with nothing arriving gets no flush.
|
|
172
|
+
*/
|
|
173
|
+
recoverTimelineGap() {
|
|
174
|
+
if (this.queue.length > 0 || this.pendingTimelineFrames.size === 0) {
|
|
175
|
+
this.timelineGapSinceMs = null;
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
const next = this.framesConsumed;
|
|
179
|
+
let lowest = Infinity;
|
|
180
|
+
for (const index of this.pendingTimelineFrames.keys()) {
|
|
181
|
+
if (index < lowest)
|
|
182
|
+
lowest = index;
|
|
183
|
+
}
|
|
184
|
+
if (lowest <= next) {
|
|
185
|
+
this.timelineGapSinceMs = null;
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
const t = this.now();
|
|
189
|
+
if (this.timelineGapSinceMs === null) {
|
|
190
|
+
this.timelineGapSinceMs = t;
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
if (t - this.timelineGapSinceMs < BlendshapeQueue.INDEXED_GAP_SKIP_MS) {
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
this.framesConsumed = lowest;
|
|
197
|
+
this.timelineGapSinceMs = null;
|
|
198
|
+
this.flushContiguousTimelineFrames();
|
|
164
199
|
}
|
|
165
200
|
timelineAliases(metadata = {}) {
|
|
166
201
|
const aliases = [];
|
|
@@ -291,7 +326,6 @@ export class BlendshapeQueue {
|
|
|
291
326
|
this.activeTimelineAliases = new Set(ownerAliases);
|
|
292
327
|
this.queue = [];
|
|
293
328
|
this.pendingTimelineFrames.clear();
|
|
294
|
-
this.holeSinceMs = null;
|
|
295
329
|
this.framesConsumed = 0;
|
|
296
330
|
this.turnStats = null;
|
|
297
331
|
this.missingExpectedFramesSinceMs = null;
|
|
@@ -360,7 +394,6 @@ export class BlendshapeQueue {
|
|
|
360
394
|
}
|
|
361
395
|
this.queue = [];
|
|
362
396
|
this.pendingTimelineFrames.clear();
|
|
363
|
-
this.holeSinceMs = null;
|
|
364
397
|
this.framesConsumed = 0;
|
|
365
398
|
this.missingExpectedFramesSinceMs = null;
|
|
366
399
|
this.botSpeaking = false;
|
|
@@ -405,6 +438,8 @@ export class BlendshapeQueue {
|
|
|
405
438
|
* @returns The frame at the given index, or null if out of bounds
|
|
406
439
|
*/
|
|
407
440
|
getFrame(index) {
|
|
441
|
+
if (this.queue.length === 0)
|
|
442
|
+
this.recoverTimelineGap();
|
|
408
443
|
if (index < 0 || index >= this.queue.length) {
|
|
409
444
|
return null;
|
|
410
445
|
}
|
|
@@ -474,37 +509,10 @@ export class BlendshapeQueue {
|
|
|
474
509
|
* Check if queue has frames
|
|
475
510
|
*/
|
|
476
511
|
hasFrames() {
|
|
477
|
-
this.
|
|
512
|
+
if (this.queue.length === 0)
|
|
513
|
+
this.recoverTimelineGap();
|
|
478
514
|
return this.queue.length > 0;
|
|
479
515
|
}
|
|
480
|
-
/**
|
|
481
|
-
* The queue is dry, but indexed frames wait beyond a hole: give the missing chunk
|
|
482
|
-
* HOLE_GRACE_MS to arrive, then count the hole as consumed and play on from the
|
|
483
|
-
* frames beyond it. A consumer that follows `getFramesConsumed()` lands on them at
|
|
484
|
-
* the voice's time for them; a chunk for the hole that arrives later is dropped
|
|
485
|
-
* (its frames are behind `framesConsumed`).
|
|
486
|
-
*/
|
|
487
|
-
skipLateHole() {
|
|
488
|
-
if (this.queue.length > 0 || this.pendingTimelineFrames.size === 0) {
|
|
489
|
-
this.holeSinceMs = null;
|
|
490
|
-
return;
|
|
491
|
-
}
|
|
492
|
-
const t = this.now();
|
|
493
|
-
if (this.holeSinceMs === null) {
|
|
494
|
-
this.holeSinceMs = t;
|
|
495
|
-
return;
|
|
496
|
-
}
|
|
497
|
-
if (t - this.holeSinceMs < BlendshapeQueue.HOLE_GRACE_MS)
|
|
498
|
-
return;
|
|
499
|
-
let next = Infinity;
|
|
500
|
-
for (const k of this.pendingTimelineFrames.keys())
|
|
501
|
-
if (k < next)
|
|
502
|
-
next = k;
|
|
503
|
-
if (next > this.framesConsumed)
|
|
504
|
-
this.framesConsumed = next;
|
|
505
|
-
this.holeSinceMs = null;
|
|
506
|
-
this.flushContiguousTimelineFrames();
|
|
507
|
-
}
|
|
508
516
|
/**
|
|
509
517
|
* Check if conversation is active
|
|
510
518
|
*/
|
|
@@ -587,7 +595,6 @@ export class BlendshapeQueue {
|
|
|
587
595
|
// Clear any leftover frames from previous conversation
|
|
588
596
|
this.queue = [];
|
|
589
597
|
this.pendingTimelineFrames.clear();
|
|
590
|
-
this.holeSinceMs = null;
|
|
591
598
|
this.rememberRetiredTimelineAliases(this.activeTimelineAliases);
|
|
592
599
|
this.clearTimelineOwner();
|
|
593
600
|
this.conversationActive = true;
|
|
@@ -694,8 +701,8 @@ export class BlendshapeQueue {
|
|
|
694
701
|
this.needsNormalization = true; // Signal lipsync player to lerp morphs back to 0
|
|
695
702
|
this.ownerReplacementStoppedSpeaking = false;
|
|
696
703
|
this.pendingTimelineFrames.clear();
|
|
697
|
-
this.holeSinceMs = null;
|
|
698
704
|
this.missingExpectedFramesSinceMs = null;
|
|
705
|
+
this.timelineGapSinceMs = null;
|
|
699
706
|
// Ahead-delivered turns may have many seconds of future frames buffered.
|
|
700
707
|
// On interrupt, audio stops immediately, so visuals must hard-stop too.
|
|
701
708
|
this.queue = [];
|
|
@@ -766,7 +773,6 @@ export class BlendshapeQueue {
|
|
|
766
773
|
reset() {
|
|
767
774
|
this.queue = [];
|
|
768
775
|
this.pendingTimelineFrames.clear();
|
|
769
|
-
this.holeSinceMs = null;
|
|
770
776
|
this.rememberRetiredTimelineAliases(this.activeTimelineAliases);
|
|
771
777
|
this.clearTimelineOwner();
|
|
772
778
|
this.conversationActive = false;
|
|
@@ -820,11 +826,15 @@ export class BlendshapeQueue {
|
|
|
820
826
|
// Constants
|
|
821
827
|
BlendshapeQueue.TARGET_FPS = 60;
|
|
822
828
|
BlendshapeQueue.MAX_RETIRED_TIMELINE_ALIASES = 48;
|
|
829
|
+
BlendshapeQueue.MISSING_INDEXED_FRAME_GRACE_MS = (24 / BlendshapeQueue.TARGET_FPS) * 1000;
|
|
823
830
|
/**
|
|
824
|
-
* How long
|
|
825
|
-
*
|
|
826
|
-
* the
|
|
827
|
-
*
|
|
831
|
+
* How long an indexed timeline waits for a missing chunk before playing on
|
|
832
|
+
* from the frames beyond it. A chunk can be lost between the server and
|
|
833
|
+
* the queue (dropped by the transport, or wiped by a local interrupt that
|
|
834
|
+
* raced the turn's first chunks); the frames after it kept arriving but
|
|
835
|
+
* nothing could flush past the hole, and the mouth stayed shut for the rest
|
|
836
|
+
* of a 25 s reply (measured 2026-11-12: 1480 frames waiting behind a
|
|
837
|
+
* six-frame hole). A quarter second is longer than any inter-chunk gap
|
|
838
|
+
* seen in production, so a late chunk still fills its hole in time.
|
|
828
839
|
*/
|
|
829
|
-
BlendshapeQueue.
|
|
830
|
-
BlendshapeQueue.MISSING_INDEXED_FRAME_GRACE_MS = (24 / BlendshapeQueue.TARGET_FPS) * 1000;
|
|
840
|
+
BlendshapeQueue.INDEXED_GAP_SKIP_MS = 250;
|
|
@@ -714,7 +714,17 @@ export class ConvaiClient extends EventEmitter {
|
|
|
714
714
|
// Voice input path — activate the blendshape queue as soon as the user
|
|
715
715
|
// starts speaking (user-started-speaking) so conversationActive is true
|
|
716
716
|
// immediately, matching the text-input path where it's true on send.
|
|
717
|
-
|
|
717
|
+
//
|
|
718
|
+
// Not for a turn this client already started and the bot has not begun:
|
|
719
|
+
// the server sends user-started-speaking for a text turn too (~0.4 s
|
|
720
|
+
// after the send), and resetting the queue then wiped the turn's own
|
|
721
|
+
// ahead-delivered chunks and left the rest stuck behind the hole, so
|
|
722
|
+
// the mouth stayed shut for the reply (2026-11-12, four of eight text
|
|
723
|
+
// replies). The send already reset the queue; the turn is pending.
|
|
724
|
+
const turnPending = this.blendshapeQueue.isConversationActive() &&
|
|
725
|
+
!this.blendshapeQueue.isBotSpeaking() &&
|
|
726
|
+
!this._state.isSpeaking;
|
|
727
|
+
if (!wasListening && isListening && !turnPending) {
|
|
718
728
|
// Reset blendshape queue if mid-conversation, but don't interrupt the server
|
|
719
729
|
if (this.blendshapeQueue.isConversationActive() ||
|
|
720
730
|
this._state.isSpeaking ||
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "2.1.0
|
|
1
|
+
export declare const SDK_VERSION = "2.1.0";
|
package/dist/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@convai/web-sdk",
|
|
3
|
-
"version": "2.1.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "Build web apps with lifelike AI characters. The Convai Web SDK gives you real-time voice, lipsync, emotions, and dynamic context — with first-class support for React and vanilla TypeScript.",
|
|
5
5
|
"private": false,
|
|
6
6
|
"type": "module",
|