@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/dist/core/SSESession.js
CHANGED
|
@@ -118,6 +118,13 @@ export class SSESession {
|
|
|
118
118
|
credentialHeaders = { "API-AUTH-TOKEN": issued.authToken };
|
|
119
119
|
connectAttemptId = createWorkspaceConnectAttemptId();
|
|
120
120
|
}
|
|
121
|
+
let endUserToken;
|
|
122
|
+
if (this.options.getEndUserToken) {
|
|
123
|
+
const getEndUserToken = this.options.getEndUserToken;
|
|
124
|
+
endUserToken = await abortableOperation(() => getEndUserToken(), controller.signal);
|
|
125
|
+
if (controller.signal.aborted || !this.connected)
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
121
128
|
const characterSessionId = this.options.getCharacterSessionId();
|
|
122
129
|
const response = await abortableOperation(() => fetch(this.options.interactionApiUrl, {
|
|
123
130
|
method: "POST",
|
|
@@ -140,6 +147,7 @@ export class SSESession {
|
|
|
140
147
|
...(this.options.endUserMetadata
|
|
141
148
|
? { end_user_metadata: this.options.endUserMetadata }
|
|
142
149
|
: {}),
|
|
150
|
+
...(endUserToken ? { end_user_token: endUserToken } : {}),
|
|
143
151
|
...(buildEmotionConnectConfig(this.options) && {
|
|
144
152
|
emotion_config: buildEmotionConnectConfig(this.options),
|
|
145
153
|
}),
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { EndUserTokenSource } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Read the end user's token from its source. A function source is called
|
|
4
|
+
* every time, so the caller always gets what the page considers current.
|
|
5
|
+
* Anything that is not a non-empty string means "no token".
|
|
6
|
+
*/
|
|
7
|
+
export declare function resolveEndUserToken(source: EndUserTokenSource | null | undefined): Promise<string | undefined>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Read the end user's token from its source. A function source is called
|
|
3
|
+
* every time, so the caller always gets what the page considers current.
|
|
4
|
+
* Anything that is not a non-empty string means "no token".
|
|
5
|
+
*/
|
|
6
|
+
export async function resolveEndUserToken(source) {
|
|
7
|
+
if (source === undefined || source === null)
|
|
8
|
+
return undefined;
|
|
9
|
+
const value = typeof source === "function" ? await source() : source;
|
|
10
|
+
return typeof value === "string" && value !== "" ? value : undefined;
|
|
11
|
+
}
|
package/dist/core/index.d.ts
CHANGED
|
@@ -6,6 +6,10 @@ export { AudioManager } from './AudioManager.js';
|
|
|
6
6
|
export { VideoManager } from './VideoManager.js';
|
|
7
7
|
export { ScreenShareManager } from './ScreenShareManager.js';
|
|
8
8
|
export { MessageHandler } from './MessageHandler.js';
|
|
9
|
+
export { DataAudioPlayer, createWorkletSink, decodePcm16 } from './DataAudioPlayer.js';
|
|
10
|
+
export type { DataAudioSink, DataAudioPlayerOptions, DataAudioStats } from './DataAudioPlayer.js';
|
|
11
|
+
export { StreamController, STREAM_DEFAULTS } from './streamController.js';
|
|
12
|
+
export type { StreamControllerOptions, StreamState, StreamSnapshot } from './streamController.js';
|
|
9
13
|
export { MemoryManager } from './MemoryManager.js';
|
|
10
14
|
export { CharacterRoster } from './CharacterRoster.js';
|
|
11
15
|
export { ConvaiRoomError } from './ConvaiRoomError.js';
|
package/dist/core/index.js
CHANGED
|
@@ -9,6 +9,8 @@ export { AudioManager } from './AudioManager.js';
|
|
|
9
9
|
export { VideoManager } from './VideoManager.js';
|
|
10
10
|
export { ScreenShareManager } from './ScreenShareManager.js';
|
|
11
11
|
export { MessageHandler } from './MessageHandler.js';
|
|
12
|
+
export { DataAudioPlayer, createWorkletSink, decodePcm16 } from './DataAudioPlayer.js';
|
|
13
|
+
export { StreamController, STREAM_DEFAULTS } from './streamController.js';
|
|
12
14
|
export { MemoryManager } from './MemoryManager.js';
|
|
13
15
|
export { CharacterRoster } from './CharacterRoster.js';
|
|
14
16
|
export { ConvaiRoomError } from './ConvaiRoomError.js';
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* When to play and pause a reply whose voice arrives over the data channel
|
|
3
|
+
* (`audioRouting: 'data_only'`).
|
|
4
|
+
*
|
|
5
|
+
* Pure decision logic: it is told what arrived and where playback is, and answers
|
|
6
|
+
* play or pause. {@link DataAudioPlayer} drives it every 20 ms.
|
|
7
|
+
*
|
|
8
|
+
* One rule, from the Convai Unreal plugin's ConvaiAudioStreamer, which plays
|
|
9
|
+
* min(audio, lipsync): only SYNCED data is playable, the seconds for which both the
|
|
10
|
+
* audio and its blendshapes are in hand. Playback starts or resumes once `minBuffer`
|
|
11
|
+
* seconds of synced data are ahead of the playhead, and pauses when less than
|
|
12
|
+
* `lowWater` is left, or a little earlier, below `silenceWater`, if the buffer holds
|
|
13
|
+
* a silence to pause on so the stop falls between words. Once the reply has fully arrived, everything left plays out. The mouth is
|
|
14
|
+
* never asked to follow audio it has no frames for.
|
|
15
|
+
*/
|
|
16
|
+
export type StreamState = "idle" | "buffering" | "playing" | "paused" | "done";
|
|
17
|
+
export interface StreamControllerOptions {
|
|
18
|
+
/** Seconds of synced audio + blendshapes to have ahead before playing or resuming. */
|
|
19
|
+
minBuffer: number;
|
|
20
|
+
/** Pause when less than this much synced data is left ahead of the playhead, s. */
|
|
21
|
+
lowWater: number;
|
|
22
|
+
/** Below this much synced data ahead, s, pause early if the caller has a silence to pause on. */
|
|
23
|
+
silenceWater: number;
|
|
24
|
+
}
|
|
25
|
+
export declare const STREAM_DEFAULTS: StreamControllerOptions;
|
|
26
|
+
export interface StreamSnapshot {
|
|
27
|
+
state: StreamState;
|
|
28
|
+
/** Seconds of audio received this reply. */
|
|
29
|
+
audio: number;
|
|
30
|
+
/** Seconds of lipsync received this reply. */
|
|
31
|
+
frames: number;
|
|
32
|
+
/** The reply's length, once the turn has announced it. */
|
|
33
|
+
total: number | null;
|
|
34
|
+
/** All of the reply's audio is in. */
|
|
35
|
+
ended: boolean;
|
|
36
|
+
/** Pauses taken this reply. */
|
|
37
|
+
pauses: number;
|
|
38
|
+
}
|
|
39
|
+
export declare class StreamController {
|
|
40
|
+
readonly o: StreamControllerOptions;
|
|
41
|
+
private s;
|
|
42
|
+
/**
|
|
43
|
+
* Frames that arrived while no reply was open. On SaaS a reply's blendshapes start
|
|
44
|
+
* arriving before its first audio chunk (2.4 s of them, measured); they belong to it.
|
|
45
|
+
*/
|
|
46
|
+
private early;
|
|
47
|
+
constructor(options?: Partial<StreamControllerOptions>);
|
|
48
|
+
get snapshot(): Readonly<StreamSnapshot>;
|
|
49
|
+
get state(): StreamState;
|
|
50
|
+
/** Start a fresh reply. */
|
|
51
|
+
newReply(): void;
|
|
52
|
+
/** `seconds` of audio arrived. Starts a reply if none is open. */
|
|
53
|
+
onAudio(_t: number, seconds: number): void;
|
|
54
|
+
/** `seconds` of lipsync arrived for the open reply. */
|
|
55
|
+
onFrames(seconds: number): void;
|
|
56
|
+
/** The turn announced the reply's length. */
|
|
57
|
+
onTotal(seconds: number): void;
|
|
58
|
+
/** All of the reply's audio is in: play it out, no more waiting. */
|
|
59
|
+
onEnded(): void;
|
|
60
|
+
/** Drop the open reply (an interruption). */
|
|
61
|
+
reset(): void;
|
|
62
|
+
/** Mark the open reply as played out (the player reached its end). */
|
|
63
|
+
finish(): void;
|
|
64
|
+
/** Seconds of the reply with both audio and blendshapes in hand. */
|
|
65
|
+
get synced(): number;
|
|
66
|
+
/**
|
|
67
|
+
* Decide at wall time `t` (s), with `played` seconds of the reply already played.
|
|
68
|
+
* `silenceAhead` says whether the synced audio left holds a silence to pause on.
|
|
69
|
+
* Returns 'play', 'pause', or null for no change.
|
|
70
|
+
*/
|
|
71
|
+
tick(_t: number, played: number, silenceAhead?: () => boolean): "play" | "pause" | null;
|
|
72
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* When to play and pause a reply whose voice arrives over the data channel
|
|
3
|
+
* (`audioRouting: 'data_only'`).
|
|
4
|
+
*
|
|
5
|
+
* Pure decision logic: it is told what arrived and where playback is, and answers
|
|
6
|
+
* play or pause. {@link DataAudioPlayer} drives it every 20 ms.
|
|
7
|
+
*
|
|
8
|
+
* One rule, from the Convai Unreal plugin's ConvaiAudioStreamer, which plays
|
|
9
|
+
* min(audio, lipsync): only SYNCED data is playable, the seconds for which both the
|
|
10
|
+
* audio and its blendshapes are in hand. Playback starts or resumes once `minBuffer`
|
|
11
|
+
* seconds of synced data are ahead of the playhead, and pauses when less than
|
|
12
|
+
* `lowWater` is left, or a little earlier, below `silenceWater`, if the buffer holds
|
|
13
|
+
* a silence to pause on so the stop falls between words. Once the reply has fully arrived, everything left plays out. The mouth is
|
|
14
|
+
* never asked to follow audio it has no frames for.
|
|
15
|
+
*/
|
|
16
|
+
export const STREAM_DEFAULTS = {
|
|
17
|
+
minBuffer: 0.9,
|
|
18
|
+
// Low: the stretch between resume and pause is minBuffer - lowWater. At 0.6 a 0.9 s
|
|
19
|
+
// buffer played 0.3 s at a time (116 pauses on a 71 s story at 0.68x; 32 at 0.15).
|
|
20
|
+
lowWater: 0.15,
|
|
21
|
+
silenceWater: 0.4,
|
|
22
|
+
};
|
|
23
|
+
const fresh = (state) => ({ state, audio: 0, frames: 0, total: null, ended: false, pauses: 0 });
|
|
24
|
+
export class StreamController {
|
|
25
|
+
constructor(options = {}) {
|
|
26
|
+
this.s = fresh("idle");
|
|
27
|
+
/**
|
|
28
|
+
* Frames that arrived while no reply was open. On SaaS a reply's blendshapes start
|
|
29
|
+
* arriving before its first audio chunk (2.4 s of them, measured); they belong to it.
|
|
30
|
+
*/
|
|
31
|
+
this.early = 0;
|
|
32
|
+
this.o = { ...STREAM_DEFAULTS, ...options };
|
|
33
|
+
}
|
|
34
|
+
get snapshot() {
|
|
35
|
+
return this.s;
|
|
36
|
+
}
|
|
37
|
+
get state() {
|
|
38
|
+
return this.s.state;
|
|
39
|
+
}
|
|
40
|
+
/** Start a fresh reply. */
|
|
41
|
+
newReply() {
|
|
42
|
+
this.s = fresh("buffering");
|
|
43
|
+
this.s.frames = this.early;
|
|
44
|
+
this.early = 0;
|
|
45
|
+
}
|
|
46
|
+
/** `seconds` of audio arrived. Starts a reply if none is open. */
|
|
47
|
+
onAudio(_t, seconds) {
|
|
48
|
+
if (this.s.state === "idle" || this.s.state === "done")
|
|
49
|
+
this.newReply();
|
|
50
|
+
this.s.audio += seconds;
|
|
51
|
+
}
|
|
52
|
+
/** `seconds` of lipsync arrived for the open reply. */
|
|
53
|
+
onFrames(seconds) {
|
|
54
|
+
if (this.s.state !== "idle" && this.s.state !== "done")
|
|
55
|
+
this.s.frames += seconds;
|
|
56
|
+
else
|
|
57
|
+
this.early += seconds;
|
|
58
|
+
}
|
|
59
|
+
/** The turn announced the reply's length. */
|
|
60
|
+
onTotal(seconds) {
|
|
61
|
+
this.s.total = seconds;
|
|
62
|
+
}
|
|
63
|
+
/** All of the reply's audio is in: play it out, no more waiting. */
|
|
64
|
+
onEnded() {
|
|
65
|
+
this.s.ended = true;
|
|
66
|
+
}
|
|
67
|
+
/** Drop the open reply (an interruption). */
|
|
68
|
+
reset() {
|
|
69
|
+
this.s = fresh("idle");
|
|
70
|
+
this.early = 0;
|
|
71
|
+
}
|
|
72
|
+
/** Mark the open reply as played out (the player reached its end). */
|
|
73
|
+
finish() {
|
|
74
|
+
if (this.s.state === "playing" || this.s.state === "paused")
|
|
75
|
+
this.s.state = "done";
|
|
76
|
+
}
|
|
77
|
+
/** Seconds of the reply with both audio and blendshapes in hand. */
|
|
78
|
+
get synced() {
|
|
79
|
+
return Math.min(this.s.audio, this.s.frames);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Decide at wall time `t` (s), with `played` seconds of the reply already played.
|
|
83
|
+
* `silenceAhead` says whether the synced audio left holds a silence to pause on.
|
|
84
|
+
* Returns 'play', 'pause', or null for no change.
|
|
85
|
+
*/
|
|
86
|
+
tick(_t, played, silenceAhead = () => false) {
|
|
87
|
+
const s = this.s;
|
|
88
|
+
const ahead = this.synced - played;
|
|
89
|
+
if (s.state === "buffering" || s.state === "paused") {
|
|
90
|
+
if (s.ended || ahead >= this.o.minBuffer) {
|
|
91
|
+
s.state = "playing";
|
|
92
|
+
return "play";
|
|
93
|
+
}
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
if (s.state === "playing") {
|
|
97
|
+
// 50 ms: the heard position trails what has been played by the output latency.
|
|
98
|
+
if (s.ended && s.audio - played <= 0.05) {
|
|
99
|
+
s.state = "done";
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
if (!s.ended && (ahead < this.o.lowWater || (ahead < this.o.silenceWater && silenceAhead()))) {
|
|
103
|
+
s.state = "paused";
|
|
104
|
+
s.pauses++;
|
|
105
|
+
return "pause";
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
}
|
package/dist/core/types.d.ts
CHANGED
|
@@ -530,6 +530,11 @@ export interface AudioSettings {
|
|
|
530
530
|
/** Number of audio channels, 1 for mono, 2 for stereo (default: 1) */
|
|
531
531
|
channelCount?: number;
|
|
532
532
|
}
|
|
533
|
+
/**
|
|
534
|
+
* The signed-in end user's bearer token, or a function that returns a current
|
|
535
|
+
* one. See {@link ConvaiConfig.endUserToken}.
|
|
536
|
+
*/
|
|
537
|
+
export type EndUserTokenSource = string | (() => string | null | undefined | Promise<string | null | undefined>);
|
|
533
538
|
/**
|
|
534
539
|
* Configuration object for connecting to a Convai character.
|
|
535
540
|
*
|
|
@@ -695,6 +700,39 @@ export interface ConvaiConfig {
|
|
|
695
700
|
endUserId?: string;
|
|
696
701
|
/** Optional metadata object for the end user (sent as end_user_metadata to the API) */
|
|
697
702
|
endUserMetadata?: Record<string, unknown>;
|
|
703
|
+
/**
|
|
704
|
+
* Bearer token that belongs to the signed-in end user (optional), for example
|
|
705
|
+
* the JWT your site already holds for that person. Sent as `end_user_token`.
|
|
706
|
+
*
|
|
707
|
+
* For MCP servers the Convai deployment has opted in, the character's tools
|
|
708
|
+
* call the server with this token instead of the server's stored credential,
|
|
709
|
+
* so the server applies that person's access. Deployments that have not
|
|
710
|
+
* opted in ignore it.
|
|
711
|
+
*
|
|
712
|
+
* Pass a string, or a function that returns a current token. Prefer the
|
|
713
|
+
* function when the token expires: the SDK calls it each time it needs the
|
|
714
|
+
* token, so the page never hands over a stale one.
|
|
715
|
+
*
|
|
716
|
+
* ```ts
|
|
717
|
+
* endUserToken: () => auth.getAccessToken({ audience: 'enterprise-search' })
|
|
718
|
+
* ```
|
|
719
|
+
*
|
|
720
|
+
* - Your page obtains the token; the SDK only forwards it.
|
|
721
|
+
* - `livekit` transport: sent once on `/connect` and used for that session.
|
|
722
|
+
* Once the token expires the MCP server rejects those tool calls for the
|
|
723
|
+
* rest of the session. `reconnect()` sends a current token, except when
|
|
724
|
+
* the reconnect reattaches to the session that is still running (sessions
|
|
725
|
+
* with client tools), which keeps the token it started with.
|
|
726
|
+
* - `sse` transport: sent with every message, so a function source keeps a
|
|
727
|
+
* long conversation on a current token.
|
|
728
|
+
* - `websocket` transport: not supported yet. The session does not use the
|
|
729
|
+
* token and keeps the server's stored credential.
|
|
730
|
+
* - Not sent for roster rooms.
|
|
731
|
+
* - Never written to client state, events or storage.
|
|
732
|
+
* - If the function throws, the connect (or that SSE message) fails with its
|
|
733
|
+
* error. Return `undefined` to continue without a token.
|
|
734
|
+
*/
|
|
735
|
+
endUserToken?: EndUserTokenSource;
|
|
698
736
|
/** Custom Convai API URL (optional, defaults to production endpoint) */
|
|
699
737
|
url?: string;
|
|
700
738
|
/** Transport layer to use. Default: "livekit". */
|
|
@@ -763,6 +801,30 @@ export interface ConvaiConfig {
|
|
|
763
801
|
iceTransportPolicy?: RTCIceTransportPolicy;
|
|
764
802
|
/** Enable text-to-speech audio generation (default: true for LiveKit, false for SSE). */
|
|
765
803
|
ttsEnabled?: boolean;
|
|
804
|
+
/**
|
|
805
|
+
* How the character's voice reaches the client (LiveKit transport).
|
|
806
|
+
*
|
|
807
|
+
* - `"webrtc"` (default): an audio track, played by the browser as it arrives.
|
|
808
|
+
* - `"data_only"`: PCM chunks over the data channel, next to the lipsync
|
|
809
|
+
* frames. The SDK plays them itself ({@link IConvaiClient.dataAudio}): it
|
|
810
|
+
* holds a reply until enough audio and lipsync are in hand, plays it as one
|
|
811
|
+
* continuous stream, and on a link slower than real time pauses on a
|
|
812
|
+
* silence instead of stuttering. On this path `speakingChange` and
|
|
813
|
+
* `state.isSpeaking` follow what is HEARD, not when the server sent it.
|
|
814
|
+
*
|
|
815
|
+
* @example
|
|
816
|
+
* ```ts
|
|
817
|
+
* const client = new ConvaiClient({ apiKey, characterId, enableLipsync: true, audioRouting: 'data_only' })
|
|
818
|
+
* ```
|
|
819
|
+
*/
|
|
820
|
+
audioRouting?: AudioRouting;
|
|
821
|
+
/**
|
|
822
|
+
* With `audioRouting: 'data_only'`: seconds of synced audio and lipsync to have in hand
|
|
823
|
+
* before a reply plays, and again before it resumes after running low. Larger values
|
|
824
|
+
* mean fewer, longer pauses on a link slower than real time; on a fast link they only
|
|
825
|
+
* delay the start a little. Default 0.9 (the Convai Unreal plugin's MinBufferDuration).
|
|
826
|
+
*/
|
|
827
|
+
dataAudioBufferSeconds?: number;
|
|
766
828
|
/**
|
|
767
829
|
* Enable lipsync/facial animation blendshapes (default: false).
|
|
768
830
|
* When true, sets blendshape_provider to "neurosync".
|
|
@@ -1188,6 +1250,49 @@ export type RawMessageEvent = {
|
|
|
1188
1250
|
/** @deprecated Use {@link SSERequestContext}; retained for error-listener compatibility. */
|
|
1189
1251
|
export type SSERequestErrorContext = SSERequestContext;
|
|
1190
1252
|
/** A streamed signed 16-bit little-endian PCM audio chunk. */
|
|
1253
|
+
/** How the character's voice is delivered: a WebRTC audio track, or PCM chunks over the data channel. */
|
|
1254
|
+
export type AudioRouting = "webrtc" | "data_only";
|
|
1255
|
+
/** The lifecycle of the reply now being played on the data-channel audio path. */
|
|
1256
|
+
export type DataAudioState = "idle" | "buffering" | "playing" | "paused" | "done";
|
|
1257
|
+
/**
|
|
1258
|
+
* The SDK's player for `audioRouting: 'data_only'`. One per client; null on the
|
|
1259
|
+
* WebRTC path.
|
|
1260
|
+
*
|
|
1261
|
+
* Events (`on(name, cb)`, returning an unsubscribe):
|
|
1262
|
+
* - `replyStarted` — the reply's first sample is heard.
|
|
1263
|
+
* - `replyEnded` `{ interrupted }` — the reply has played out, or was interrupted.
|
|
1264
|
+
* - `paused` `{ atSilence }` / `resumed` — a rebuffer on a link slower than real time.
|
|
1265
|
+
* - `underrun` — playback ran out mid-reply (should not happen; counted in `stats`).
|
|
1266
|
+
*/
|
|
1267
|
+
export interface DataAudioPlayback {
|
|
1268
|
+
/** Where the open reply is: buffering before it starts, playing, paused to refill, done. */
|
|
1269
|
+
readonly state: DataAudioState;
|
|
1270
|
+
/** Chunks received, clean pauses taken, and underruns (stutters) since the client was made. */
|
|
1271
|
+
readonly stats: {
|
|
1272
|
+
chunks: number;
|
|
1273
|
+
pauses: number;
|
|
1274
|
+
underruns: number;
|
|
1275
|
+
};
|
|
1276
|
+
/** Seconds of the open reply heard so far; null before it starts. Holds while paused. */
|
|
1277
|
+
position(): number | null;
|
|
1278
|
+
/** RMS of the voice now playing (0–1); null when it cannot be read yet. */
|
|
1279
|
+
level(): number | null;
|
|
1280
|
+
/** Seconds of audio buffered ahead of what is heard. */
|
|
1281
|
+
queuedSeconds(): number;
|
|
1282
|
+
/**
|
|
1283
|
+
* The reply's heard position as an RTCRtpReceiver synchronization source
|
|
1284
|
+
* (48 kHz RTP units), so a lipsync clock written for a WebRTC receiver can
|
|
1285
|
+
* follow this player unchanged. Empty before a reply starts.
|
|
1286
|
+
*/
|
|
1287
|
+
getSynchronizationSources(): Array<{
|
|
1288
|
+
rtpTimestamp: number;
|
|
1289
|
+
timestamp: number;
|
|
1290
|
+
audioLevel?: number;
|
|
1291
|
+
}>;
|
|
1292
|
+
/** Resume audio output; call from a user gesture where the page blocks autoplay. */
|
|
1293
|
+
resume(): Promise<void>;
|
|
1294
|
+
on(event: "replyStarted" | "replyEnded" | "paused" | "resumed" | "underrun", callback: (detail: unknown) => void): () => void;
|
|
1295
|
+
}
|
|
1191
1296
|
export interface AudioDataEvent {
|
|
1192
1297
|
/** Sample rate of this chunk in hertz. */
|
|
1193
1298
|
sample_rate: number;
|
|
@@ -1225,6 +1330,12 @@ export interface ConvaiEventMap {
|
|
|
1225
1330
|
messagesChange: [messages: ChatMessage[]];
|
|
1226
1331
|
userTranscriptionChange: [transcription: string];
|
|
1227
1332
|
speakingChange: [isSpeaking: boolean];
|
|
1333
|
+
/**
|
|
1334
|
+
* The server's own bot-started/stopped-speaking flags, with
|
|
1335
|
+
* `audioRouting: 'data_only'`. They follow when the server SENT the audio;
|
|
1336
|
+
* `speakingChange` follows when it is heard.
|
|
1337
|
+
*/
|
|
1338
|
+
serverSpeakingChange: [isSpeaking: boolean];
|
|
1228
1339
|
listeningChange: [isListening: boolean];
|
|
1229
1340
|
botRespondingChange: [isResponding: boolean];
|
|
1230
1341
|
turnEnd: [turn: {
|
|
@@ -2063,6 +2174,17 @@ export interface IConvaiClient {
|
|
|
2063
2174
|
readonly screenShareControls: ScreenShareControls;
|
|
2064
2175
|
/** Blendshape queue for time-based lipsync synchronization */
|
|
2065
2176
|
readonly blendshapeQueue: BlendshapeQueue;
|
|
2177
|
+
/**
|
|
2178
|
+
* The player for the character's voice when `audioRouting: 'data_only'`;
|
|
2179
|
+
* null on the WebRTC path.
|
|
2180
|
+
*
|
|
2181
|
+
* @example
|
|
2182
|
+
* ```ts
|
|
2183
|
+
* client.dataAudio?.on('paused', () => console.log('waiting for the network'))
|
|
2184
|
+
* const heard = client.dataAudio?.position() // seconds into the reply
|
|
2185
|
+
* ```
|
|
2186
|
+
*/
|
|
2187
|
+
readonly dataAudio: DataAudioPlayback | null;
|
|
2066
2188
|
/** Incremental turn session ID used by conversation events (e.g. conversationStart, turnEnd) */
|
|
2067
2189
|
readonly conversationSessionId: number;
|
|
2068
2190
|
/**
|
|
@@ -2282,6 +2404,7 @@ export interface IConvaiClient {
|
|
|
2282
2404
|
* Update dynamic information about the current context.
|
|
2283
2405
|
* This helps the character understand the current situation.
|
|
2284
2406
|
* Pass any key-value pairs you want, but "text" field is required.
|
|
2407
|
+
* Recorded for `reconnect()` even when not connected.
|
|
2285
2408
|
*/
|
|
2286
2409
|
updateDynamicInfo: (dynamicInfo: DynamicInfo) => void;
|
|
2287
2410
|
/**
|
|
@@ -2315,7 +2438,13 @@ export interface IConvaiClient {
|
|
|
2315
2438
|
visionStatus: (options?: VisionStatusOptions) => string | null;
|
|
2316
2439
|
/** Attach buffered frames and optionally trigger a response. */
|
|
2317
2440
|
visionTrigger: (options?: VisionTriggerOptions) => string | null;
|
|
2318
|
-
/**
|
|
2441
|
+
/**
|
|
2442
|
+
* Update a session respond-mode default. Returns the update id, or `null`
|
|
2443
|
+
* when not connected. A mode the connect request accepts is recorded for
|
|
2444
|
+
* `reconnect()` either way; `"auto"` and `"silent"` for `text` and `audio`
|
|
2445
|
+
* are runtime-only (the connect request rejects lowering user input below
|
|
2446
|
+
* `"must_respond"`), so they are not replayed.
|
|
2447
|
+
*/
|
|
2319
2448
|
respondModeUpdate: (options: RespondModeUpdateOptions) => string | null;
|
|
2320
2449
|
/**
|
|
2321
2450
|
* Set or clear the character's temporary state of mind without triggering a response.
|
|
@@ -2337,12 +2466,33 @@ export interface IConvaiClient {
|
|
|
2337
2466
|
/**
|
|
2338
2467
|
* Toggle text-to-speech on or off.
|
|
2339
2468
|
* SSE applies the setting to subsequent interaction requests.
|
|
2469
|
+
*
|
|
2470
|
+
* The value is recorded in every connection state (disconnected,
|
|
2471
|
+
* connecting, connected), and `reconnect()` and `connect()` without a
|
|
2472
|
+
* config start the next session with it. `connect(config)` replaces the
|
|
2473
|
+
* stored config, so its `ttsEnabled` wins. A client constructed without a
|
|
2474
|
+
* config has nothing to record into until it connects.
|
|
2475
|
+
*
|
|
2476
|
+
* On LiveKit it is sent once this room's character can receive it: at
|
|
2477
|
+
* `botReady`, or at the character's first speech or transcription event on
|
|
2478
|
+
* a backend that sends no `botReady`. Until then only the latest value is
|
|
2479
|
+
* held, and a disconnect drops it. In a multi-character room it goes to
|
|
2480
|
+
* the routed character: held while it is not ready (including after it
|
|
2481
|
+
* fails or a route moves to one that is not ready yet) and while no
|
|
2482
|
+
* character is routed (`setInteractionTarget(null)`); switching between
|
|
2483
|
+
* ready routed characters re-sends nothing. On WebSocket it is
|
|
2484
|
+
* held during a connection attempt and sent once the session connects.
|
|
2485
|
+
* Neither a missing transport nor a failed LiveKit publish throws.
|
|
2340
2486
|
*/
|
|
2341
2487
|
toggleTts: (enabled: boolean) => void;
|
|
2342
2488
|
/**
|
|
2343
2489
|
* Toggle speech-to-text on or off.
|
|
2344
2490
|
* When enabled, user speech is transcribed to text (e.g. for dictation).
|
|
2345
2491
|
* When disabled, STT is off.
|
|
2492
|
+
*
|
|
2493
|
+
* On LiveKit and WebSocket it is held and sent like `toggleTts()`, latest
|
|
2494
|
+
* value only. It is not recorded for the next session: every session
|
|
2495
|
+
* starts with speech-to-text on.
|
|
2346
2496
|
*/
|
|
2347
2497
|
toggleStt: (enabled: boolean) => void;
|
|
2348
2498
|
/**
|
|
@@ -201,6 +201,7 @@ export const useConvaiClient = (config) => {
|
|
|
201
201
|
videoControls: client.videoControls,
|
|
202
202
|
screenShareControls: client.screenShareControls,
|
|
203
203
|
blendshapeQueue: client.blendshapeQueue,
|
|
204
|
+
dataAudio: client.dataAudio,
|
|
204
205
|
conversationSessionId: client.conversationSessionId,
|
|
205
206
|
memoryManager: client.memoryManager,
|
|
206
207
|
characterVersions: client.characterVersions,
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "2.0.
|
|
1
|
+
export declare const SDK_VERSION = "2.1.0-beta.1";
|
package/dist/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@convai/web-sdk",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.1.0-beta.1",
|
|
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",
|