@convai/web-sdk 2.0.2 → 2.1.0-beta.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 +37 -0
- package/dist/core/ConvaiClient.d.ts +98 -2
- package/dist/core/ConvaiClient.js +305 -25
- package/dist/core/DataAudioPlayer.d.ts +131 -0
- package/dist/core/DataAudioPlayer.js +397 -0
- package/dist/core/MessageHandler.d.ts +13 -0
- package/dist/core/MessageHandler.js +57 -0
- package/dist/core/SSESession.d.ts +2 -0
- package/dist/core/SSESession.js +8 -0
- package/dist/core/endUserToken.d.ts +7 -0
- package/dist/core/endUserToken.js +11 -0
- package/dist/core/index.d.ts +4 -0
- package/dist/core/index.js +2 -0
- package/dist/core/streamController.d.ts +72 -0
- package/dist/core/streamController.js +110 -0
- package/dist/core/types.d.ts +151 -1
- package/dist/react/hooks/useConvaiClient.js +1 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -10,6 +10,11 @@ TypeScript-first SDK for embedding Convai AI characters into React and vanilla J
|
|
|
10
10
|
|
|
11
11
|
---
|
|
12
12
|
|
|
13
|
+
## What's new in 2.1 (beta)
|
|
14
|
+
|
|
15
|
+
- **Voice over the data channel** — set `audioRouting: 'data_only'` and the character's voice arrives as audio chunks next to the lipsync frames, played by the SDK (`client.dataAudio`). Only audio whose lipsync has also arrived plays: a reply starts once 0.9 s of both is in hand (`dataAudioBufferSeconds`), plays as one continuous stream, and on a slow network pauses between words to refill instead of stuttering or speaking with a still face. A pause in delivery never ends a reply early. [Usage below.](#voice-over-the-data-channel-beta)
|
|
16
|
+
- **Speaking state follows what is heard** — on that path `speakingChange` and `state.isSpeaking` turn on when the reply is first heard and off when it finishes playing. The server's own flags, which follow when it sent the audio, arrive as the new `serverSpeakingChange` event.
|
|
17
|
+
|
|
13
18
|
## What's new in 2.0
|
|
14
19
|
|
|
15
20
|
Install with `npm install @convai/web-sdk @convai/web-widget` (the widget only if you use the bundled chat UI). 2.0 also carries every fix from 1.9.1 – 1.9.4: SSE sends `authToken` as `API-AUTH-TOKEN` and ends each request at `done`; the character-info lookup sends `CONVAI-API-KEY`; audio, video and screen-share controls follow tracks changed outside them; a disconnected mic reads as muted; the `mha` helpers no longer hold a frozen sneer.
|
|
@@ -312,6 +317,38 @@ your bundler handle the ESM.
|
|
|
312
317
|
|
|
313
318
|
---
|
|
314
319
|
|
|
320
|
+
## Voice over the data channel (beta)
|
|
321
|
+
|
|
322
|
+
Receive the character's voice next to its lipsync and let the SDK play it, so a 3D character's mouth and voice stay in step on every reply.
|
|
323
|
+
|
|
324
|
+
```ts
|
|
325
|
+
import { ConvaiClient } from '@convai/web-sdk/core';
|
|
326
|
+
|
|
327
|
+
const client = new ConvaiClient({
|
|
328
|
+
authToken: token,
|
|
329
|
+
characterId: 'YOUR_CHARACTER_ID',
|
|
330
|
+
enableLipsync: true,
|
|
331
|
+
audioRouting: 'data_only',
|
|
332
|
+
dataAudioBufferSeconds: 0.9, // voice + lipsync to have in hand before playing; the default
|
|
333
|
+
});
|
|
334
|
+
await client.connect();
|
|
335
|
+
|
|
336
|
+
client.on('speakingChange', (speaking) => console.log('heard:', speaking));
|
|
337
|
+
client.dataAudio?.on('paused', () => showRefilling());
|
|
338
|
+
client.dataAudio?.on('resumed', () => hideRefilling());
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
| `client.dataAudio` | Description |
|
|
342
|
+
|---|---|
|
|
343
|
+
| `state` | `'idle'`, `'buffering'`, `'playing'`, `'paused'` or `'done'` |
|
|
344
|
+
| `position()` | Seconds of the reply heard so far; holds while paused |
|
|
345
|
+
| `level()` | Loudness of the voice now playing, 0–1 |
|
|
346
|
+
| `queuedSeconds()` | Audio buffered ahead of what is heard |
|
|
347
|
+
| `getSynchronizationSources()` | The heard position in RTP form, for lipsync clocks written for WebRTC |
|
|
348
|
+
| `on(event, cb)` | `replyStarted`, `replyEnded`, `paused`, `resumed`, `underrun` |
|
|
349
|
+
|
|
350
|
+
Browsers start audio only after a user gesture; the player resumes on the page's next click, or call `client.dataAudio.resume()` from your own button. The player runs in an AudioWorklet loaded from a `blob:` URL, so a Content-Security-Policy must allow `worker-src blob:`. Available on the default LiveKit transport. Full guide: [Audio over the data channel](https://docs.convai.com/api-docs/plugins-and-integrations/web-plugins/convai-web-sdk/audio-over-the-data-channel).
|
|
351
|
+
|
|
315
352
|
## WebSocket transport
|
|
316
353
|
|
|
317
354
|
The default transport is WebRTC (LiveKit). A WebSocket-based transport is available for environments where WebRTC is unavailable or undesirable.
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Room } from "livekit-client";
|
|
2
2
|
import { ConvaiConfig, ConvaiClientState, ChatMessage, IConvaiClient, PublishedChatConnectOptions, AudioControls, CharacterMuteOptions, VideoControls, ScreenShareControls, DynamicInfo, ContextUpdateOptions, UploadFileOptions, ServerResponse, WebSocketSessionFactory, RespondModeUpdateOptions, UpdateSceneMetadataOptions, VisionStatusOptions, VisionTriggerOptions, ConnectionData, SendUserTextMessageOptions, StateOfMindInput, ConvaiCharacterInstance, ConvaiRoomSession, JoinRoomOptions, ActiveCharacterChange, CharacterRosterChange, UpdateCharacterRosterOptions, AppendMessageOptions, ConvaiEventMap, ActionResult, ActionResultAck, ActionResultAckFailureReason, ActionResultAckOptions } from "./types.js";
|
|
3
|
+
import { DataAudioPlayer } from "./DataAudioPlayer.js";
|
|
3
4
|
import { EventEmitter } from "./EventEmitter.js";
|
|
4
5
|
import { BlendshapeQueue } from "./BlendshapeQueue.js";
|
|
5
6
|
import { MemoryManager } from "./MemoryManager.js";
|
|
@@ -79,6 +80,9 @@ export declare class ConvaiClient extends EventEmitter implements IConvaiClient
|
|
|
79
80
|
* room, or a track republished by a reconnect.
|
|
80
81
|
*/
|
|
81
82
|
private _characterMuted;
|
|
83
|
+
/** Plays the voice when it arrives over the data channel (audioRouting: 'data_only'). */
|
|
84
|
+
private _dataAudio;
|
|
85
|
+
private _audioRouting;
|
|
82
86
|
/**
|
|
83
87
|
* Per-membership overrides of `_characterMuted`. A session-wide call clears
|
|
84
88
|
* this, so "mute everything" never leaves a member behind as an exception.
|
|
@@ -127,6 +131,26 @@ export declare class ConvaiClient extends EventEmitter implements IConvaiClient
|
|
|
127
131
|
private _clientReadyRetryTimer;
|
|
128
132
|
private _clientReadyTimeoutTimer;
|
|
129
133
|
private _clientReadyMsgId;
|
|
134
|
+
/**
|
|
135
|
+
* Single-character rooms and WebSocket: whether this room's bot can receive
|
|
136
|
+
* a toggle yet. LiveKit drops data published before the bot participant
|
|
137
|
+
* joins, so until the room shows a running bot (bot-ready, or bot pipeline
|
|
138
|
+
* output from a backend that sends no bot-ready) toggles wait in
|
|
139
|
+
* `_pendingUntilBotReady`, latest value per message type. Roster rooms
|
|
140
|
+
* derive this from the routed member instead (`_canDeliverToggles`). All
|
|
141
|
+
* of it resets when a connection attempt starts, on disconnect() and when
|
|
142
|
+
* the room disconnects, so a held value never reaches another room.
|
|
143
|
+
*/
|
|
144
|
+
private _toggleGate;
|
|
145
|
+
private _pendingUntilBotReady;
|
|
146
|
+
/**
|
|
147
|
+
* Roster members seen running in this connection attempt's room: their own
|
|
148
|
+
* identified bot-ready, or bot pipeline output from them on a backend that
|
|
149
|
+
* sends no bot-ready. Cleared with the gate (attempt start, disconnect(),
|
|
150
|
+
* room disconnect), so readiness from an earlier room never counts; the
|
|
151
|
+
* roster's own `isReady` can outlive an unexpected disconnect.
|
|
152
|
+
*/
|
|
153
|
+
private _membersSeenRunning;
|
|
130
154
|
private _pendingActionResultAcks;
|
|
131
155
|
private static readonly CLIENT_READY_RETRY_MS;
|
|
132
156
|
private static readonly CLIENT_READY_TIMEOUT_MS;
|
|
@@ -226,6 +250,13 @@ export declare class ConvaiClient extends EventEmitter implements IConvaiClient
|
|
|
226
250
|
private _applyCharacterMute;
|
|
227
251
|
get videoControls(): VideoControls;
|
|
228
252
|
get screenShareControls(): ScreenShareControls;
|
|
253
|
+
get dataAudio(): DataAudioPlayer | null;
|
|
254
|
+
/**
|
|
255
|
+
* Data-channel audio (audioRouting: 'data_only'): make the player and hand it
|
|
256
|
+
* the say over "speaking". Idempotent; on the WebRTC path speaking goes back
|
|
257
|
+
* to the server's flags.
|
|
258
|
+
*/
|
|
259
|
+
private _configureAudioRouting;
|
|
229
260
|
get blendshapeQueue(): BlendshapeQueue;
|
|
230
261
|
get conversationSessionId(): number;
|
|
231
262
|
get memoryManager(): MemoryManager | null;
|
|
@@ -385,6 +416,49 @@ export declare class ConvaiClient extends EventEmitter implements IConvaiClient
|
|
|
385
416
|
* bot publishes bot-ready before the client data-channel is subscribed.
|
|
386
417
|
*/
|
|
387
418
|
private _startClientReadyHandshake;
|
|
419
|
+
/**
|
|
420
|
+
* Send a toggle on the active transport. On LiveKit it waits, latest value
|
|
421
|
+
* only, until this room's bot can receive it (see `_toggleGate`); the bot
|
|
422
|
+
* joins after the client and LiveKit drops data published before that.
|
|
423
|
+
*/
|
|
424
|
+
private _sendToggle;
|
|
425
|
+
/**
|
|
426
|
+
* Whether a toggle published now reaches a bot that consumes it. Roster
|
|
427
|
+
* rooms: the routed member must be running in this attempt's room (its
|
|
428
|
+
* bot-ready, or pipeline output from it), re-evaluated on every route or
|
|
429
|
+
* status change, so a member that fails or a route to one that is not ready
|
|
430
|
+
* holds toggles again. Elsewhere: this room's gate.
|
|
431
|
+
*/
|
|
432
|
+
private _canDeliverToggles;
|
|
433
|
+
/** Send the held toggles, once, if they can be delivered now. */
|
|
434
|
+
private _flushHeldToggles;
|
|
435
|
+
/** Single-character room or WebSocket: the bot can receive toggles now. */
|
|
436
|
+
private _openToggleGate;
|
|
437
|
+
/** Bot pipeline output: the sender is running (backends without bot-ready). */
|
|
438
|
+
private _onBotPipelineFrame;
|
|
439
|
+
/**
|
|
440
|
+
* The member that consumes toggles. In a multi-character room
|
|
441
|
+
* core-service delivers tts-toggle and stt-toggle only to the routed
|
|
442
|
+
* (active) member and the others drop them, so another member's readiness
|
|
443
|
+
* must not open the gate. `undefined`: not a roster room, any bot counts.
|
|
444
|
+
* `null`: a roster room with no target (an acknowledged
|
|
445
|
+
* setInteractionTarget(null)), where no member consumes them.
|
|
446
|
+
*/
|
|
447
|
+
private _toggleRecipient;
|
|
448
|
+
private _resetToggleGate;
|
|
449
|
+
/**
|
|
450
|
+
* Start a connection attempt: drop anything held for an earlier room and
|
|
451
|
+
* name the transport this attempt uses. Every entry point calls it after
|
|
452
|
+
* its synchronous validation and before its first stateChange or await, so
|
|
453
|
+
* a toggle made at any point of the attempt is held for this attempt's room
|
|
454
|
+
* (or, on SSE, applied to the session it creates).
|
|
455
|
+
*/
|
|
456
|
+
private _beginAttempt;
|
|
457
|
+
/**
|
|
458
|
+
* ttsEnabled for a boot built now: toggleTts() may have run since the
|
|
459
|
+
* attempt captured its config (a stateChange listener, for example).
|
|
460
|
+
*/
|
|
461
|
+
private _latestTtsEnabled;
|
|
388
462
|
private _stopClientReadyHandshake;
|
|
389
463
|
/**
|
|
390
464
|
* Disconnect from the current character session
|
|
@@ -504,11 +578,33 @@ export declare class ConvaiClient extends EventEmitter implements IConvaiClient
|
|
|
504
578
|
*/
|
|
505
579
|
uploadFile(file: File, options?: UploadFileOptions): Promise<void>;
|
|
506
580
|
/**
|
|
507
|
-
* Toggle text-to-speech on or off
|
|
581
|
+
* Toggle text-to-speech on or off.
|
|
582
|
+
*
|
|
583
|
+
* The value is recorded in every connection state, and `reconnect()` and
|
|
584
|
+
* `connect()` without a config start the next session with it.
|
|
585
|
+
* `connect(config)` replaces the stored config, so pass `ttsEnabled` there.
|
|
586
|
+
*
|
|
587
|
+
* On LiveKit it is sent once this room's character can receive it: at
|
|
588
|
+
* `botReady`, or at the character's first speech or transcription event on
|
|
589
|
+
* a backend that sends no `botReady`. Until then only the latest value is
|
|
590
|
+
* held; a disconnect drops it, and the next session starts from the
|
|
591
|
+
* recorded value instead. In a multi-character room it goes to the routed
|
|
592
|
+
* character: held while it is not ready (including after it fails or a
|
|
593
|
+
* route moves to one that is not ready yet) and while no character is
|
|
594
|
+
* routed (`setInteractionTarget(null)`); switching between ready routed
|
|
595
|
+
* characters re-sends nothing. A failed LiveKit publish is logged,
|
|
596
|
+
* not thrown or left as an unhandled rejection. SSE applies it to
|
|
597
|
+
* subsequent requests; WebSocket holds it during a connection attempt and
|
|
598
|
+
* sends it once the session connects.
|
|
508
599
|
*/
|
|
509
600
|
toggleTts(enabled: boolean): void;
|
|
510
601
|
/**
|
|
511
|
-
* Toggle speech-to-text on or off
|
|
602
|
+
* Toggle speech-to-text on or off.
|
|
603
|
+
*
|
|
604
|
+
* On LiveKit and WebSocket it is held and sent like `toggleTts()`, latest
|
|
605
|
+
* value only. Unlike `toggleTts()` it is not recorded for the next session:
|
|
606
|
+
* every session starts with speech-to-text on. SSE sends it while
|
|
607
|
+
* connected.
|
|
512
608
|
*/
|
|
513
609
|
toggleStt(enabled: boolean): void;
|
|
514
610
|
/**
|