@convai/web-sdk 1.5.0-beta.0 → 1.6.0-beta.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.
Files changed (44) hide show
  1. package/LICENSE +191 -0
  2. package/README.md +85 -19
  3. package/dist/core/BlendshapeQueue.d.ts +75 -4
  4. package/dist/core/BlendshapeQueue.d.ts.map +1 -1
  5. package/dist/core/BlendshapeQueue.js +400 -24
  6. package/dist/core/BlendshapeQueue.js.map +1 -1
  7. package/dist/core/ConvaiClient.d.ts +10 -2
  8. package/dist/core/ConvaiClient.d.ts.map +1 -1
  9. package/dist/core/ConvaiClient.js +208 -57
  10. package/dist/core/ConvaiClient.js.map +1 -1
  11. package/dist/core/MessageHandler.d.ts +8 -0
  12. package/dist/core/MessageHandler.d.ts.map +1 -1
  13. package/dist/core/MessageHandler.js +63 -12
  14. package/dist/core/MessageHandler.js.map +1 -1
  15. package/dist/core/VideoManager.d.ts +40 -5
  16. package/dist/core/VideoManager.d.ts.map +1 -1
  17. package/dist/core/VideoManager.js +579 -30
  18. package/dist/core/VideoManager.js.map +1 -1
  19. package/dist/core/connectRequest.d.ts +23 -0
  20. package/dist/core/connectRequest.d.ts.map +1 -0
  21. package/dist/core/connectRequest.js +31 -0
  22. package/dist/core/connectRequest.js.map +1 -0
  23. package/dist/core/contextUpdateRequest.d.ts +4 -0
  24. package/dist/core/contextUpdateRequest.d.ts.map +1 -0
  25. package/dist/core/contextUpdateRequest.js +10 -0
  26. package/dist/core/contextUpdateRequest.js.map +1 -0
  27. package/dist/core/index.d.ts +1 -1
  28. package/dist/core/index.d.ts.map +1 -1
  29. package/dist/core/types.d.ts +172 -3
  30. package/dist/core/types.d.ts.map +1 -1
  31. package/dist/core/videoSourceState.d.ts +4 -0
  32. package/dist/core/videoSourceState.d.ts.map +1 -0
  33. package/dist/core/videoSourceState.js +9 -0
  34. package/dist/core/videoSourceState.js.map +1 -0
  35. package/dist/core/visionRequest.d.ts +4 -0
  36. package/dist/core/visionRequest.d.ts.map +1 -0
  37. package/dist/core/visionRequest.js +42 -0
  38. package/dist/core/visionRequest.js.map +1 -0
  39. package/dist/react/hooks/useConvaiClient.d.ts.map +1 -1
  40. package/dist/react/hooks/useConvaiClient.js +3 -0
  41. package/dist/react/hooks/useConvaiClient.js.map +1 -1
  42. package/dist/vanilla/types.d.ts +6 -0
  43. package/dist/vanilla/types.d.ts.map +1 -1
  44. package/package.json +6 -3
package/LICENSE ADDED
@@ -0,0 +1,191 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ Copyright 2025 Convai
180
+
181
+ Licensed under the Apache License, Version 2.0 (the "License");
182
+ you may not use this file except in compliance with the License.
183
+ You may obtain a copy of the License at
184
+
185
+ http://www.apache.org/licenses/LICENSE-2.0
186
+
187
+ Unless required by applicable law or agreed to in writing, software
188
+ distributed under the License is distributed on an "AS IS" BASIS,
189
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
190
+ See the License for the specific language governing permissions and
191
+ limitations under the License.
package/README.md CHANGED
@@ -2,8 +2,9 @@
2
2
 
3
3
  **Real-time conversational AI characters for the web.**
4
4
 
5
- [![npm](https://img.shields.io/npm/v/@convai/web-sdk)](https://www.npmjs.com/package/@convai/web-sdk)
5
+ [![npm](https://img.shields.io/badge/npm-1.6.0--beta.0-blue)](https://www.npmjs.com/package/@convai/web-sdk)
6
6
  [![TypeScript](https://img.shields.io/badge/TypeScript-first-3178C6)](https://www.typescriptlang.org/)
7
+ [![License](https://img.shields.io/badge/license-Apache--2.0-green)](./LICENSE)
7
8
 
8
9
  TypeScript-first SDK for embedding Convai AI characters into React and vanilla JS applications. Voice, text, lipsync, emotions, video, and screen share — all in one package.
9
10
 
@@ -15,7 +16,7 @@ TypeScript-first SDK for embedding Convai AI characters into React and vanilla J
15
16
  - **Real-time audio/video** — full-duplex WebRTC with echo cancellation, camera, and screen share
16
17
  - **Lipsync** — ARKit and MetaHuman blendshape streams for facial animation
17
18
  - **Emotions** — per-turn emotion detection with intensity scale
18
- - **Dynamic context** — inject game state, user preferences, or scene data mid-session
19
+ - **Dynamic context & vision** — inject text state, scene metadata, and LiveKit video frames mid-session
19
20
  - **Long-term memory** — persistent cross-session memories scoped to each end user
20
21
  - **File upload** — send images to the character during a live session
21
22
  - **WebSocket transport** — opt-in alternative to WebRTC for constrained networks
@@ -78,24 +79,24 @@ window.addEventListener('beforeunload', () => {
78
79
 
79
80
  ## Documentation
80
81
 
81
- Full documentation is at **[docs.convai.com](https://docs.convai.com/api-docs/plugins-and-integrations/web-plugins/convai-web-sdk)**.
82
+ Full documentation is at **<a href="https://docs.convai.com/api-docs/plugins-and-integrations/web-plugins/convai-web-sdk" target="_blank" rel="noopener noreferrer">docs.convai.com</a>**.
82
83
 
83
84
  | Guide | Description |
84
85
  |---|---|
85
- | [Quick Start](https://docs.convai.com/api-docs/plugins-and-integrations/web-plugins/convai-web-sdk) | First working integration in under 5 minutes |
86
- | [Configuration](https://docs.convai.com/api-docs/plugins-and-integrations/web-plugins/convai-web-sdk) | All `ConvaiConfig` options |
87
- | [React Integration](https://docs.convai.com/api-docs/plugins-and-integrations/web-plugins/convai-web-sdk) | `useConvaiClient`, `ConvaiWidget`, and React-specific patterns |
88
- | [Vanilla JS](https://docs.convai.com/api-docs/plugins-and-integrations/web-plugins/convai-web-sdk) | `ConvaiClient`, `createConvaiWidget`, and audio setup |
89
- | [Events](https://docs.convai.com/api-docs/plugins-and-integrations/web-plugins/convai-web-sdk) | Full event reference — `botReady`, `stateChange`, `messagesChange`, `interactionCreated`, and more |
90
- | [Context Management](https://docs.convai.com/api-docs/plugins-and-integrations/web-plugins/convai-web-sdk) | Dynamic context, `updateContext`, file upload, session management |
91
- | [Emotions](https://docs.convai.com/api-docs/plugins-and-integrations/web-plugins/convai-web-sdk) | Per-turn emotion detection with provider options |
92
- | [Lipsync](https://docs.convai.com/api-docs/plugins-and-integrations/web-plugins/convai-web-sdk) | ARKit / MetaHuman blendshape streams and `BlendshapeQueue` API |
93
- | [Actions](https://docs.convai.com/api-docs/plugins-and-integrations/web-plugins/convai-web-sdk) | Trigger character behaviors and scene actions |
94
- | [Memory](https://docs.convai.com/api-docs/plugins-and-integrations/web-plugins/convai-web-sdk) | Long-term memory scoped to end users |
95
- | [Audio & Video](https://docs.convai.com/api-docs/plugins-and-integrations/web-plugins/convai-web-sdk) | Microphone, camera, screen share controls |
96
- | [Error Handling](https://docs.convai.com/api-docs/plugins-and-integrations/web-plugins/convai-web-sdk) | `error`, `disconnect`, `serverResponse`, retry patterns |
97
- | [Auth Tokens](https://docs.convai.com/api-docs/plugins-and-integrations/web-plugins/convai-web-sdk) | Server-side token exchange for production |
98
- | [WebSocket Transport](https://docs.convai.com/api-docs/plugins-and-integrations/web-plugins/convai-web-sdk) | Alternative transport for WebRTC-constrained environments |
86
+ | <a href="https://docs.convai.com/api-docs/plugins-and-integrations/web-plugins/convai-web-sdk" target="_blank" rel="noopener noreferrer">Quick Start</a> | First working integration in under 5 minutes |
87
+ | <a href="https://docs.convai.com/api-docs/plugins-and-integrations/web-plugins/convai-web-sdk" target="_blank" rel="noopener noreferrer">Configuration</a> | All `ConvaiConfig` options |
88
+ | <a href="https://docs.convai.com/api-docs/plugins-and-integrations/web-plugins/convai-web-sdk" target="_blank" rel="noopener noreferrer">React Integration</a> | `useConvaiClient`, `ConvaiWidget`, and React-specific patterns |
89
+ | <a href="https://docs.convai.com/api-docs/plugins-and-integrations/web-plugins/convai-web-sdk" target="_blank" rel="noopener noreferrer">Vanilla JS</a> | `ConvaiClient`, `createConvaiWidget`, and audio setup |
90
+ | <a href="https://docs.convai.com/api-docs/plugins-and-integrations/web-plugins/convai-web-sdk/event-reference" target="_blank" rel="noopener noreferrer">Events</a> | Full event reference — `botReady`, `stateChange`, `messagesChange`, `interactionCreated`, and more |
91
+ | <a href="https://docs.convai.com/api-docs/plugins-and-integrations/web-plugins/convai-web-sdk/dynamic-context" target="_blank" rel="noopener noreferrer">Context Management</a> | Dynamic context, `updateContext`, file upload, session management |
92
+ | <a href="https://docs.convai.com/api-docs/plugins-and-integrations/web-plugins/convai-web-sdk/emotions" target="_blank" rel="noopener noreferrer">Emotions</a> | Per-turn emotion detection with provider options |
93
+ | <a href="https://docs.convai.com/api-docs/plugins-and-integrations/web-plugins/convai-web-sdk" target="_blank" rel="noopener noreferrer">Lipsync</a> | ARKit / MetaHuman blendshape streams and `BlendshapeQueue` API |
94
+ | <a href="https://docs.convai.com/api-docs/plugins-and-integrations/web-plugins/convai-web-sdk/actions" target="_blank" rel="noopener noreferrer">Actions</a> | Trigger character behaviors and scene actions |
95
+ | <a href="https://docs.convai.com/api-docs/plugins-and-integrations/web-plugins/convai-web-sdk/long-term-memory" target="_blank" rel="noopener noreferrer">Memory</a> | Long-term memory scoped to end users |
96
+ | <a href="https://docs.convai.com/api-docs/plugins-and-integrations/web-plugins/convai-web-sdk" target="_blank" rel="noopener noreferrer">Audio & Video</a> | Microphone, camera, screen share controls |
97
+ | <a href="https://docs.convai.com/api-docs/plugins-and-integrations/web-plugins/convai-web-sdk/error-handling" target="_blank" rel="noopener noreferrer">Error Handling</a> | `error`, `disconnect`, `serverResponse`, retry patterns |
98
+ | <a href="https://docs.convai.com/api-docs/plugins-and-integrations/web-plugins/convai-web-sdk/auth-tokens" target="_blank" rel="noopener noreferrer">Auth Tokens</a> | Server-side token exchange for production |
99
+ | <a href="https://docs.convai.com/api-docs/plugins-and-integrations/web-plugins/convai-web-sdk/websocket-transport-layer" target="_blank" rel="noopener noreferrer">WebSocket Transport</a> | Alternative transport for WebRTC-constrained environments |
99
100
 
100
101
  ---
101
102
 
@@ -130,11 +131,76 @@ const client = new ConvaiClient({
130
131
 
131
132
  The WebSocket packages (`@pipecat-ai/client-js`, `@pipecat-ai/websocket-transport`) are **excluded from your bundle** unless you import the `/vanilla/websocket` subpath — so LiveKit-only apps pay no bundle cost.
132
133
 
133
- See the [WebSocket Transport guide](https://docs.convai.com/api-docs/plugins-and-integrations/web-plugins/convai-web-sdk) for the full feature comparison.
134
+ See the <a href="https://docs.convai.com/api-docs/plugins-and-integrations/web-plugins/convai-web-sdk/websocket-transport-layer" target="_blank" rel="noopener noreferrer">WebSocket Transport guide</a> for the full feature comparison.
135
+
136
+ ---
137
+
138
+ ## Vision dynamic context beta
139
+
140
+ Vision dynamic context is the default WebRTC/LiveKit vision path when `enableVideo: true`. Camera, screen, canvas, and custom video tracks can feed unified vision context; set `visionInputConfig.enabled: false` only when you need to keep the video channel while opting out.
141
+
142
+ ```tsx
143
+ import { useConvaiClient } from '@convai/web-sdk';
144
+
145
+ const client = useConvaiClient({
146
+ apiKey: import.meta.env.VITE_CONVAI_API_KEY,
147
+ characterId: import.meta.env.VITE_CONVAI_CHARACTER_ID,
148
+ enableVideo: true,
149
+ visionInputConfig: {
150
+ framesPerTurn: 12,
151
+ bufferFrames: 30,
152
+ samplingWindows: [
153
+ { count: 6, intervalMs: 300 },
154
+ { count: 6, intervalMs: 1000 },
155
+ ],
156
+ stalenessSeconds: 10,
157
+ replacePreviousVisionContext: true,
158
+ },
159
+ respondModes: {
160
+ vision: 'silent',
161
+ contextUpdate: 'auto',
162
+ sceneMetadata: 'silent',
163
+ trigger: 'must_respond',
164
+ },
165
+ });
166
+ ```
167
+
168
+ Publish visual sources with semantic labels so acknowledgments can distinguish webcam, canvas, screen, and custom feeds:
169
+
170
+ ```ts
171
+ await client.videoControls.enableVideo(); // webcam source
172
+
173
+ const handle = await client.videoControls.publishCanvas(canvas, {
174
+ source: 'canvas',
175
+ name: 'canvas-pov',
176
+ fps: 1,
177
+ });
178
+
179
+ const statusId = client.visionStatus();
180
+ const triggerId = client.visionTrigger({
181
+ respondMode: 'silent',
182
+ frameIndices: [-1, -1],
183
+ });
184
+
185
+ await client.videoControls.unpublishVisionSource(handle);
186
+ ```
187
+
188
+ `visionStatus()` and `visionTrigger()` return an update id. Match it against `serverResponse` events for outcomes such as `frames_available`, `buffer_empty`, `attached`, or `no_active_video`.
189
+
190
+ After the beta package is published, install it with:
191
+
192
+ ```bash
193
+ npm install @convai/web-sdk@beta
194
+ ```
134
195
 
135
196
  ---
136
197
 
137
198
  ## Example app
138
199
 
139
- A full React Three Fiber integration demo is in [`examples/react-three-fiber`](./examples/react-three-fiber/). It demonstrates lipsync on a 3D character, emotion display, dynamic context, and file upload.
200
+ A full React Three Fiber integration demo is in [`examples/react-three-fiber`](./examples/react-three-fiber/). It demonstrates lipsync on a 3D character, emotion display, dynamic context, vision validation, and file upload.
201
+
202
+ ---
203
+
204
+ ## License
140
205
 
206
+ Licensed under the [Apache License 2.0](./LICENSE). Copyright 2025 Convai.
@@ -27,8 +27,19 @@ export interface TurnStats {
27
27
  total_blendshapes: number;
28
28
  total_turn_duration_ms: number;
29
29
  }
30
+ export interface BlendshapeChunkMetadata {
31
+ fps?: number;
32
+ startFrameIndex?: number;
33
+ responseId?: string;
34
+ neurosyncTurnId?: number;
35
+ epoch?: number;
36
+ }
30
37
  export declare class BlendshapeQueue {
31
38
  private queue;
39
+ private pendingTimelineFrames;
40
+ private activeTimelineAliases;
41
+ private retiredTimelineAliases;
42
+ private retiredOwnerlessTimelineAliases;
32
43
  private conversationActive;
33
44
  private botSpeaking;
34
45
  private conversationEnded;
@@ -39,17 +50,61 @@ export declare class BlendshapeQueue {
39
50
  private interruptedAtFrame;
40
51
  private needsNormalization;
41
52
  private _awaitingBotSpeak;
53
+ private playbackFps;
54
+ private ownerReplacementStoppedSpeaking;
55
+ private missingExpectedFramesSinceMs;
56
+ private readonly now;
42
57
  private static readonly TARGET_FPS;
58
+ private static readonly MAX_RETIRED_TIMELINE_ALIASES;
59
+ private static readonly MISSING_INDEXED_FRAME_GRACE_MS;
43
60
  /**
44
61
  * Create a new BlendshapeQueue
45
62
  * @param mapper - Optional function to map/transform blendshape data as it's added
46
63
  */
47
- constructor(mapper?: (input: number[] | Float32Array) => Float32Array);
64
+ constructor(mapper?: (input: number[] | Float32Array) => Float32Array, now?: () => number);
48
65
  /**
49
66
  * Add a chunk of blendshapes to the queue
50
67
  * @param blendshapes - Array of blendshape frames (each frame is an array of numbers)
68
+ * @param metadata - Optional timeline metadata for ahead-delivered chunks
69
+ */
70
+ addChunk(blendshapes: number[][], metadata?: BlendshapeChunkMetadata): void;
71
+ private mapFrame;
72
+ private addTimelineChunk;
73
+ private flushContiguousTimelineFrames;
74
+ private timelineAliases;
75
+ private hasActiveTimelineOwner;
76
+ private responseAlias;
77
+ private turnEpochAlias;
78
+ private turnAlias;
79
+ private activeHasResponseAlias;
80
+ private activeHasTurnEpochAlias;
81
+ private matchesActiveTimelineOwner;
82
+ private matchesActiveTimelineChunkOwner;
83
+ private mergeActiveTimelineAliases;
84
+ private isRetiredTimelineOwner;
85
+ private rememberRetiredTimelineAliases;
86
+ private rememberRetiredOwnerlessTimelineAliases;
87
+ private rememberBoundedAliases;
88
+ private adoptTimelineOwner;
89
+ private clearTimelineOwner;
90
+ /**
91
+ * True when a lifecycle event belongs to an owner that has already been
92
+ * interrupted/cancelled or does not match the active indexed timeline.
93
+ * Ownerless events are treated as current for backward compatibility.
94
+ */
95
+ isStaleOwner(metadata?: BlendshapeChunkMetadata): boolean;
96
+ /**
97
+ * True when an owner was explicitly interrupted/cancelled/completed.
98
+ * Chunk messages use this narrower predicate so a newer owner can still
99
+ * reach addChunk() and atomically replace the active owner there.
100
+ */
101
+ isRetiredOwner(metadata?: BlendshapeChunkMetadata): boolean;
102
+ /**
103
+ * Drop buffered ahead-delivered frames for a server-cancelled owner.
104
+ * Returns true when the active owner was flushed.
51
105
  */
52
- addChunk(blendshapes: number[][]): void;
106
+ cancelOwner(metadata?: BlendshapeChunkMetadata): boolean;
107
+ hasBufferedFrames(): boolean;
53
108
  /**
54
109
  * Set or update the mapper function
55
110
  * @param mapper - Function to map/transform blendshape data
@@ -112,7 +167,11 @@ export declare class BlendshapeQueue {
112
167
  */
113
168
  isConversationEnded(): boolean;
114
169
  /**
115
- * Check if server has signaled conversation end (blendshape-turn-stats received)
170
+ * Check if the server end signal is safe to expose to playback consumers.
171
+ *
172
+ * Ahead-delivery can deliver blendshape-turn-stats before bot-started-speaking.
173
+ * Keep those early stats internally for expected-frame accounting, but do not
174
+ * expose a public drain signal until audio playback has actually started.
116
175
  * This does NOT check if all frames have been consumed - use isConversationEnded() for that.
117
176
  */
118
177
  hasReceivedEndSignal(): boolean;
@@ -135,12 +194,17 @@ export declare class BlendshapeQueue {
135
194
  * Lipsync player should only play frames when this is true
136
195
  */
137
196
  isBotSpeaking(): boolean;
197
+ /**
198
+ * Consume the signal that a newer ahead-delivered owner replaced an active
199
+ * speaking owner before the old bot-stopped-speaking event arrived.
200
+ */
201
+ consumeOwnerReplacementStoppedSpeaking(): boolean;
138
202
  /**
139
203
  * Mark conversation end with turn stats
140
204
  * Called when blendshape-turn-stats received
141
205
  * Stops accepting new frames and marks conversation as ended
142
206
  */
143
- endConversation(stats?: TurnStats): void;
207
+ endConversation(stats?: TurnStats, metadata?: BlendshapeChunkMetadata): void;
144
208
  /**
145
209
  * Handle interruption - mark for fade out
146
210
  * Keeps last 10 frames in queue and fades them out
@@ -161,6 +225,10 @@ export declare class BlendshapeQueue {
161
225
  * Get number of frames consumed
162
226
  */
163
227
  getFramesConsumed(): number;
228
+ /**
229
+ * Get playback FPS from chunk metadata, falling back to 60fps.
230
+ */
231
+ getPlaybackFps(): number;
164
232
  /**
165
233
  * Calculate time left in milliseconds based on turn stats
166
234
  * Returns null if stats not available
@@ -170,6 +238,7 @@ export declare class BlendshapeQueue {
170
238
  * Check if all frames have been consumed based on turn stats
171
239
  */
172
240
  isAllFramesConsumed(): boolean;
241
+ private hasUnconsumedExpectedFrames;
173
242
  /**
174
243
  * Reset queue for new conversation
175
244
  * Should be called after all frames have been consumed
@@ -197,6 +266,8 @@ export declare class BlendshapeQueue {
197
266
  framesConsumed: number;
198
267
  turnStats: TurnStats | null;
199
268
  timeLeftMs: number | null;
269
+ pendingTimelineFrames: number;
270
+ playbackFps: number;
200
271
  };
201
272
  }
202
273
  //# sourceMappingURL=BlendshapeQueue.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"BlendshapeQueue.d.ts","sourceRoot":"","sources":["../../src/core/BlendshapeQueue.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,MAAM,WAAW,SAAS;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ,iBAAiB,EAAE,MAAM,CAAC;IAC1B,uBAAuB,EAAE,MAAM,CAAC;IAChC,iBAAiB,EAAE,MAAM,CAAC;IAC1B,sBAAsB,EAAE,MAAM,CAAC;CAChC;AAED,qBAAa,eAAe;IAC1B,OAAO,CAAC,KAAK,CAAsB;IACnC,OAAO,CAAC,kBAAkB,CAAkB;IAC5C,OAAO,CAAC,WAAW,CAAkB;IACrC,OAAO,CAAC,iBAAiB,CAAkB;IAC3C,OAAO,CAAC,MAA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