@convai/web-sdk 1.2.1-beta.0 → 1.2.2-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.
- package/README.md +297 -43
- package/dist/core/ConvaiClient.d.ts +36 -7
- package/dist/core/ConvaiClient.d.ts.map +1 -1
- package/dist/core/ConvaiClient.js +190 -40
- package/dist/core/ConvaiClient.js.map +1 -1
- package/dist/core/MemoryManager.d.ts +179 -0
- package/dist/core/MemoryManager.d.ts.map +1 -0
- package/dist/core/MemoryManager.js +281 -0
- package/dist/core/MemoryManager.js.map +1 -0
- package/dist/core/MessageHandler.d.ts +1 -7
- package/dist/core/MessageHandler.d.ts.map +1 -1
- package/dist/core/MessageHandler.js +8 -21
- package/dist/core/MessageHandler.js.map +1 -1
- package/dist/core/index.d.ts +2 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +3 -0
- package/dist/core/index.js.map +1 -1
- package/dist/core/types.d.ts +422 -13
- package/dist/core/types.d.ts.map +1 -1
- package/dist/core/types.js +58 -1
- package/dist/core/types.js.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/lipsync-helpers/mappingTypes.d.ts +1 -1
- package/dist/lipsync-helpers/mappingTypes.js +4 -4
- package/dist/react/components/ConvaiWidget.d.ts.map +1 -1
- package/dist/react/components/ConvaiWidget.js +1 -1
- package/dist/react/components/ConvaiWidget.js.map +1 -1
- package/dist/react/hooks/useCharacterInfo.d.ts +1 -1
- package/dist/react/hooks/useCharacterInfo.d.ts.map +1 -1
- package/dist/react/hooks/useCharacterInfo.js +11 -5
- package/dist/react/hooks/useCharacterInfo.js.map +1 -1
- package/dist/react/hooks/useConvaiClient.d.ts.map +1 -1
- package/dist/react/hooks/useConvaiClient.js +4 -2
- package/dist/react/hooks/useConvaiClient.js.map +1 -1
- package/dist/react/index.d.ts +1 -0
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +2 -0
- package/dist/react/index.js.map +1 -1
- package/dist/vanilla/ConvaiWidget.d.ts.map +1 -1
- package/dist/vanilla/ConvaiWidget.js +6 -4
- package/dist/vanilla/ConvaiWidget.js.map +1 -1
- package/dist/vanilla/index.d.ts +2 -1
- package/dist/vanilla/index.d.ts.map +1 -1
- package/dist/vanilla/index.js +2 -0
- package/dist/vanilla/index.js.map +1 -1
- package/dist/vanilla/types.d.ts +3 -2
- package/dist/vanilla/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/dev.d.ts +0 -12
- package/dist/dev.d.ts.map +0 -1
- package/dist/dev.js +0 -12
- package/dist/dev.js.map +0 -1
- package/dist/types/index.d.ts +0 -310
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/index.js +0 -2
- package/dist/types/index.js.map +0 -1
- package/dist/utils/LatencyMonitor.d.ts +0 -88
- package/dist/utils/LatencyMonitor.d.ts.map +0 -1
- package/dist/utils/LatencyMonitor.js +0 -136
- package/dist/utils/LatencyMonitor.js.map +0 -1
package/dist/vanilla/types.d.ts
CHANGED
|
@@ -16,8 +16,10 @@ export interface VanillaWidgetOptions {
|
|
|
16
16
|
activity?: string;
|
|
17
17
|
chatMessages: ChatMessage[];
|
|
18
18
|
};
|
|
19
|
-
/** Option 2: Pass connection config directly (convenience shortcut) */
|
|
19
|
+
/** Option 2: Pass connection config directly (convenience shortcut). Either apiKey or authToken is required. */
|
|
20
20
|
apiKey?: string;
|
|
21
|
+
/** Auth token for realtime API (alternative to apiKey). See https://realtime-api.convai.com/docs */
|
|
22
|
+
authToken?: string;
|
|
21
23
|
characterId?: string;
|
|
22
24
|
enableVideo?: boolean;
|
|
23
25
|
startWithVideoOn?: boolean;
|
|
@@ -68,5 +70,4 @@ export interface VanillaWidget {
|
|
|
68
70
|
/** Update widget state (for future extensions) */
|
|
69
71
|
update?: (options: Partial<VanillaWidgetOptions>) => void;
|
|
70
72
|
}
|
|
71
|
-
export type { IConvaiClient, ConvaiConfig, ConvaiClientState, ChatMessage } from '../core/types';
|
|
72
73
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/vanilla/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/vanilla/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAEhE;;;;;;GAMG;AACH,MAAM,WAAW,oBAAoB;IACnC;;;;OAIG;IACH,YAAY,CAAC,EAAE,aAAa,GAAG;QAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,WAAW,EAAE,CAAA;KAAE,CAAC;IAElF,gHAAgH;IAChH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,oGAAoG;IACpG,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,mEAAmE;IACnE,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,uEAAuE;IACvE,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,2DAA2D;IAC3D,gBAAgB,CAAC,EAAE;QACjB,qFAAqF;QACrF,MAAM,CAAC,EAAE,OAAO,GAAG,KAAK,CAAC;QACzB,+DAA+D;QAC/D,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,YAAY,KAAK,YAAY,CAAC;KACjE,CAAC;IAEF;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB;;;OAGG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B;;;OAGG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAE3B,yBAAyB;IACzB,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC;IACvB,YAAY,CAAC,EAAE,MAAM,IAAI,CAAC;IAC1B,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,WAAW,KAAK,IAAI,CAAC;CAC5C;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,qCAAqC;IACrC,OAAO,EAAE,WAAW,CAAC;IACrB,qCAAqC;IACrC,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,iCAAiC;IACjC,MAAM,EAAE,aAAa,GAAG;QAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,WAAW,EAAE,CAAA;KAAE,CAAC;IAC3E,kDAAkD;IAClD,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,oBAAoB,CAAC,KAAK,IAAI,CAAC;CAC3D"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@convai/web-sdk",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.2-beta.0",
|
|
4
4
|
"description": "Bring realism to your digital characters with voice, expression, and lipsync. Convai Web SDK powers lifelike AI characters with real-time audio, video, and facial animation—for React or vanilla JavaScript/TypeScript.",
|
|
5
5
|
"private": false,
|
|
6
6
|
"type": "module",
|
package/dist/dev.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Development-only exports
|
|
3
|
-
*
|
|
4
|
-
* This module contains tools and utilities for development and debugging.
|
|
5
|
-
* Import from '@convai/web-sdk/dev' to access these features.
|
|
6
|
-
*
|
|
7
|
-
* @packageDocumentation
|
|
8
|
-
* @module dev
|
|
9
|
-
*/
|
|
10
|
-
export { LatencyMonitor } from "./utils/LatencyMonitor";
|
|
11
|
-
export type { LatencyMeasurement, LatencyStats } from "./utils/LatencyMonitor";
|
|
12
|
-
//# sourceMappingURL=dev.d.ts.map
|
package/dist/dev.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dev.d.ts","sourceRoot":"","sources":["../src/dev.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,YAAY,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC"}
|
package/dist/dev.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Development-only exports
|
|
3
|
-
*
|
|
4
|
-
* This module contains tools and utilities for development and debugging.
|
|
5
|
-
* Import from '@convai/web-sdk/dev' to access these features.
|
|
6
|
-
*
|
|
7
|
-
* @packageDocumentation
|
|
8
|
-
* @module dev
|
|
9
|
-
*/
|
|
10
|
-
// Export LatencyMonitor for development/debugging
|
|
11
|
-
export { LatencyMonitor } from "./utils/LatencyMonitor";
|
|
12
|
-
//# sourceMappingURL=dev.js.map
|
package/dist/dev.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dev.js","sourceRoot":"","sources":["../src/dev.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,kDAAkD;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC"}
|
package/dist/types/index.d.ts
DELETED
|
@@ -1,310 +0,0 @@
|
|
|
1
|
-
import { Room } from 'livekit-client';
|
|
2
|
-
/**
|
|
3
|
-
* Audio processing settings for the microphone input.
|
|
4
|
-
* These settings help optimize the audio quality and reduce interruptions.
|
|
5
|
-
* @internal - This is a fixed configuration and should not be modified by users
|
|
6
|
-
*/
|
|
7
|
-
interface AudioSettings {
|
|
8
|
-
/** Enable echo cancellation to prevent audio feedback (default: true) */
|
|
9
|
-
echoCancellation?: boolean;
|
|
10
|
-
/** Enable noise suppression to reduce background noise (default: true) */
|
|
11
|
-
noiseSuppression?: boolean;
|
|
12
|
-
/** Enable automatic gain control for consistent volume (default: true) */
|
|
13
|
-
autoGainControl?: boolean;
|
|
14
|
-
/** Audio sample rate in Hz (default: 48000) */
|
|
15
|
-
sampleRate?: number;
|
|
16
|
-
/** Number of audio channels, 1 for mono, 2 for stereo (default: 1) */
|
|
17
|
-
channelCount?: number;
|
|
18
|
-
}
|
|
19
|
-
export type { AudioSettings };
|
|
20
|
-
/**
|
|
21
|
-
* Configuration object for connecting to a Convai character.
|
|
22
|
-
*
|
|
23
|
-
* @example
|
|
24
|
-
* ```tsx
|
|
25
|
-
* const config: ConvaiConfig = {
|
|
26
|
-
* apiKey: 'your-api-key',
|
|
27
|
-
* characterId: 'your-character-id',
|
|
28
|
-
* endUserId: 'user-uuid', // Optional: enables long-term memory and analytics
|
|
29
|
-
* enableVideo: false, // If false, connection_type will be "audio"
|
|
30
|
-
* };
|
|
31
|
-
* ```
|
|
32
|
-
*/
|
|
33
|
-
export interface ConvaiConfig {
|
|
34
|
-
/** Your Convai API key from convai.com dashboard (required) */
|
|
35
|
-
apiKey: string;
|
|
36
|
-
/** The Character ID to connect to (required) */
|
|
37
|
-
characterId: string;
|
|
38
|
-
/**
|
|
39
|
-
* End user identifier for speaker management (optional).
|
|
40
|
-
*
|
|
41
|
-
* When provided:
|
|
42
|
-
* - Enables long-term memory: Character remembers context from previous conversations with this user
|
|
43
|
-
* - Enables analytics: Track user engagement and behavior
|
|
44
|
-
*
|
|
45
|
-
* When not provided:
|
|
46
|
-
* - Anonymous mode: No persistent memory or user tracking
|
|
47
|
-
* - Each session is independent with no conversation history
|
|
48
|
-
*
|
|
49
|
-
* Use a unique UUID or device ID for persistent user experiences.
|
|
50
|
-
*/
|
|
51
|
-
endUserId?: string;
|
|
52
|
-
/** Optional metadata object for the end user (sent as end_user_metadata to the API) */
|
|
53
|
-
endUserMetadata?: Record<string, unknown>;
|
|
54
|
-
/** Custom Convai API URL (optional, defaults to production endpoint) */
|
|
55
|
-
url?: string;
|
|
56
|
-
/**
|
|
57
|
-
* Character session ID (optional). Pass to resume an existing session;
|
|
58
|
-
* otherwise populated from the connect API response after first connection.
|
|
59
|
-
*/
|
|
60
|
-
characterSessionId?: string;
|
|
61
|
-
/**
|
|
62
|
-
* Enable video capability (default: false).
|
|
63
|
-
* If true, connection_type will be "video" (supports audio, video, and screenshare).
|
|
64
|
-
* If false, connection_type will be "audio" (audio only).
|
|
65
|
-
*/
|
|
66
|
-
enableVideo?: boolean;
|
|
67
|
-
/**
|
|
68
|
-
* Start with video camera on when connecting (default: false).
|
|
69
|
-
* Only works if enableVideo is true. If false, camera stays off until user enables it.
|
|
70
|
-
*/
|
|
71
|
-
startWithVideoOn?: boolean;
|
|
72
|
-
/**
|
|
73
|
-
* Start with microphone on when connecting (default: false).
|
|
74
|
-
* If false, microphone stays off until user enables it using audioControls.enableAudio().
|
|
75
|
-
* Useful for text-only modes where you want to defer microphone permission until voice mode.
|
|
76
|
-
*/
|
|
77
|
-
startWithAudioOn?: boolean;
|
|
78
|
-
/** Enable text-to-speech audio generation (default: true) */
|
|
79
|
-
ttsEnabled?: boolean;
|
|
80
|
-
/**
|
|
81
|
-
* Enable lipsync/facial animation blendshapes (default: false).
|
|
82
|
-
* When true, sets blendshape_provider to "neurosync".
|
|
83
|
-
* When false, sets blendshape_provider to "none" (no facial animation data).
|
|
84
|
-
*/
|
|
85
|
-
enableLipsync?: boolean;
|
|
86
|
-
/** Enable emotion detection and bot-emotion updates (default: true) */
|
|
87
|
-
enableEmotion?: boolean;
|
|
88
|
-
/** Blendshape configuration for facial animation format */
|
|
89
|
-
blendshapeConfig?: {
|
|
90
|
-
/** Format of blendshapes: "arkit" or "mha" (Meta Human Animation, default: "mha") */
|
|
91
|
-
format?: "arkit" | "mha";
|
|
92
|
-
/** Custom mapper function to transform incoming blendshapes */
|
|
93
|
-
customMapper?: (input: number[] | Float32Array) => Float32Array;
|
|
94
|
-
/**
|
|
95
|
-
* Buffer duration for blendshape frames in seconds (default: 1).
|
|
96
|
-
* Controls how much time the server should wait after generating blendshapes before playing the audio.
|
|
97
|
-
*/
|
|
98
|
-
frames_buffer_duration?: number;
|
|
99
|
-
};
|
|
100
|
-
/** Emotion configuration for character emotional state (sent to server on connect) */
|
|
101
|
-
emotionConfig?: {
|
|
102
|
-
/** Emotion provider (default: "llm") */
|
|
103
|
-
provider?: "llm";
|
|
104
|
-
/** Minimum word threshold for emotion detection */
|
|
105
|
-
min_word_threshold?: number;
|
|
106
|
-
/** Low intensity threshold (0–1) */
|
|
107
|
-
low_intensity_threshold?: number;
|
|
108
|
-
/** High intensity threshold (0–1) */
|
|
109
|
-
high_intensity_threshold?: number;
|
|
110
|
-
};
|
|
111
|
-
/** Configuration for character actions and environmental context */
|
|
112
|
-
actionConfig?: {
|
|
113
|
-
/** List of action names the character can perform */
|
|
114
|
-
actions: string[];
|
|
115
|
-
/** Other characters present in the scene or conversation */
|
|
116
|
-
characters: Array<{
|
|
117
|
-
/** Character name */
|
|
118
|
-
name: string;
|
|
119
|
-
/** Character biography or description */
|
|
120
|
-
bio: string;
|
|
121
|
-
}>;
|
|
122
|
-
/** Objects available in the scene or environment */
|
|
123
|
-
objects: Array<{
|
|
124
|
-
/** Object name */
|
|
125
|
-
name: string;
|
|
126
|
-
/** Object description or properties */
|
|
127
|
-
description: string;
|
|
128
|
-
}>;
|
|
129
|
-
/** Name of the object the character is currently focused on */
|
|
130
|
-
currentAttentionObject?: string;
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
/**
|
|
134
|
-
* Represents a single message in the chat conversation.
|
|
135
|
-
* Different message types are used for various parts of the conversation flow.
|
|
136
|
-
*/
|
|
137
|
-
export interface ChatMessage {
|
|
138
|
-
/** Unique identifier for the message */
|
|
139
|
-
id: string;
|
|
140
|
-
/**
|
|
141
|
-
* Type of message:
|
|
142
|
-
* - `user`: User's sent message
|
|
143
|
-
* - `convai`: Character's response
|
|
144
|
-
* - `user-transcription`: Real-time speech-to-text from user
|
|
145
|
-
* - `bot-llm-text`: Character's LLM-generated text
|
|
146
|
-
* - `emotion`: Character's emotional state
|
|
147
|
-
* - `behavior-tree`: Behavior tree response
|
|
148
|
-
* - `action`: Action execution
|
|
149
|
-
* - `bot-emotion`: Bot emotional response
|
|
150
|
-
* - `user-llm-text`: User text processed by LLM
|
|
151
|
-
*/
|
|
152
|
-
type: 'user' | 'convai' | 'emotion' | 'behavior-tree' | 'action' | 'user-transcription' | 'bot-llm-text' | 'bot-emotion' | 'user-llm-text';
|
|
153
|
-
/** The text content of the message */
|
|
154
|
-
content: string;
|
|
155
|
-
/** ISO timestamp string of when the message was created */
|
|
156
|
-
timestamp: string;
|
|
157
|
-
/** Whether this message is still streaming (mutable); false when finalized */
|
|
158
|
-
isStreaming?: boolean;
|
|
159
|
-
}
|
|
160
|
-
/**
|
|
161
|
-
* Represents the current state of the Convai client connection and activity.
|
|
162
|
-
* Use this to provide UI feedback about the conversation state.
|
|
163
|
-
*
|
|
164
|
-
* @example
|
|
165
|
-
* ```tsx
|
|
166
|
-
* const { state } = convaiClient;
|
|
167
|
-
*
|
|
168
|
-
* if (state.isConnected) {
|
|
169
|
-
* console.log('Connected to character');
|
|
170
|
-
* }
|
|
171
|
-
*
|
|
172
|
-
* if (state.isSpeaking) {
|
|
173
|
-
* console.log('Character is speaking');
|
|
174
|
-
* }
|
|
175
|
-
*
|
|
176
|
-
* // Or use the combined state
|
|
177
|
-
* console.log(state.agentState); // 'listening' | 'thinking' | 'speaking'
|
|
178
|
-
* ```
|
|
179
|
-
*/
|
|
180
|
-
export interface ConvaiClientState {
|
|
181
|
-
/** Whether the client is currently connected to Convai */
|
|
182
|
-
isConnected: boolean;
|
|
183
|
-
/** Whether a connection attempt is in progress */
|
|
184
|
-
isConnecting: boolean;
|
|
185
|
-
/** True from user-started-speaking until user-stopped-speaking (user is speaking, bot is listening). Priority below isSpeaking. */
|
|
186
|
-
isListening: boolean;
|
|
187
|
-
/** Whether the character is processing/thinking about a response */
|
|
188
|
-
isThinking: boolean;
|
|
189
|
-
/** Whether the character is currently speaking */
|
|
190
|
-
isSpeaking: boolean;
|
|
191
|
-
/**
|
|
192
|
-
* Combined state indicator for the character's current activity.
|
|
193
|
-
* Priority: speaking > listening (user speaking) > thinking > connected.
|
|
194
|
-
*/
|
|
195
|
-
agentState: 'disconnected' | 'connected' | 'listening' | 'thinking' | 'speaking';
|
|
196
|
-
/** Current bot emotion (name and optional scale). Updated when bot-emotion messages are received. */
|
|
197
|
-
emotion: {
|
|
198
|
-
emotion: string;
|
|
199
|
-
scale?: number;
|
|
200
|
-
} | null;
|
|
201
|
-
}
|
|
202
|
-
import type { AudioControls, VideoControls, ScreenShareControls } from "../core/types";
|
|
203
|
-
/**
|
|
204
|
-
* Main Convai client interface returned by useConvaiClient() hook.
|
|
205
|
-
* Provides complete control over Convai character connections and interactions.
|
|
206
|
-
*
|
|
207
|
-
* @example
|
|
208
|
-
* ```tsx
|
|
209
|
-
* import { useConvaiClient } from '@convai/web-sdk';
|
|
210
|
-
*
|
|
211
|
-
* function App() {
|
|
212
|
-
* const convaiClient = useConvaiClient();
|
|
213
|
-
*
|
|
214
|
-
* // Connect to character
|
|
215
|
-
* await convaiClient.connect({
|
|
216
|
-
* apiKey: 'your-api-key',
|
|
217
|
-
* characterId: 'your-character-id'
|
|
218
|
-
* });
|
|
219
|
-
*
|
|
220
|
-
* // Send a message
|
|
221
|
-
* convaiClient.sendUserTextMessage('Hello!');
|
|
222
|
-
*
|
|
223
|
-
* // Check state
|
|
224
|
-
* console.log(convaiClient.state.isConnected);
|
|
225
|
-
* }
|
|
226
|
-
* ```
|
|
227
|
-
*/
|
|
228
|
-
export interface ConvaiClient {
|
|
229
|
-
/** Current connection and activity state of the client */
|
|
230
|
-
state: ConvaiClientState;
|
|
231
|
-
/**
|
|
232
|
-
* Connection type: "audio" (audio only) or "video" (audio + video + screenshare).
|
|
233
|
-
* Set based on enableVideo in connect config.
|
|
234
|
-
*/
|
|
235
|
-
connectionType: 'audio' | 'video' | null;
|
|
236
|
-
/** API key used for the current connection (null if not connected) */
|
|
237
|
-
apiKey: string | null;
|
|
238
|
-
/** Character ID used for the current connection (null if not connected) */
|
|
239
|
-
characterId: string | null;
|
|
240
|
-
/**
|
|
241
|
-
* Speaker ID for the current user (null if not connected).
|
|
242
|
-
* Used for long-term memory and user analytics.
|
|
243
|
-
*/
|
|
244
|
-
speakerId: string | null;
|
|
245
|
-
/**
|
|
246
|
-
* Connect to a Convai character.
|
|
247
|
-
* Uses stored config from useConvaiClient() or accepts override config.
|
|
248
|
-
*/
|
|
249
|
-
connect: (config?: ConvaiConfig) => Promise<void>;
|
|
250
|
-
/** Disconnect from the current character session */
|
|
251
|
-
disconnect: () => Promise<void>;
|
|
252
|
-
/** Reconnect - disconnect and connect again using stored config */
|
|
253
|
-
reconnect: () => Promise<void>;
|
|
254
|
-
/** Reset the session ID to start a new conversation (clears history) */
|
|
255
|
-
resetSession: () => void;
|
|
256
|
-
/** Internal LiveKit Room instance (for advanced usage) */
|
|
257
|
-
room: Room;
|
|
258
|
-
/** Current video track (for advanced usage) */
|
|
259
|
-
videoTrack: any;
|
|
260
|
-
/** Current audio track (for advanced usage) */
|
|
261
|
-
audioTrack: any;
|
|
262
|
-
/** Send a text message to the character */
|
|
263
|
-
sendUserTextMessage: (text: string) => void;
|
|
264
|
-
/**
|
|
265
|
-
* Send a trigger message to invoke specific character actions or responses.
|
|
266
|
-
* @param triggerName - Name of the trigger to invoke
|
|
267
|
-
* @param triggerMessage - Optional message to accompany the trigger
|
|
268
|
-
*/
|
|
269
|
-
sendTriggerMessage: (triggerName?: string, triggerMessage?: string) => void;
|
|
270
|
-
/**
|
|
271
|
-
* Update template keys in the character's context (e.g., user name, location).
|
|
272
|
-
* These keys can be referenced in the character's responses.
|
|
273
|
-
*/
|
|
274
|
-
updateTemplateKeys: (templateKeys: {
|
|
275
|
-
[key: string]: string;
|
|
276
|
-
}) => void;
|
|
277
|
-
/**
|
|
278
|
-
* Update dynamic information about the current context.
|
|
279
|
-
* This helps the character understand the current situation.
|
|
280
|
-
*/
|
|
281
|
-
updateDynamicInfo: (dynamicInfo: {
|
|
282
|
-
text: string;
|
|
283
|
-
}) => void;
|
|
284
|
-
/** Array of all chat messages in the current conversation */
|
|
285
|
-
chatMessages: ChatMessage[];
|
|
286
|
-
/** Current real-time transcription of user speech */
|
|
287
|
-
userTranscription: string;
|
|
288
|
-
/** Unique session ID for the current character conversation */
|
|
289
|
-
characterSessionId: string | null;
|
|
290
|
-
/** Whether the bot is ready to receive messages (true after bot-ready message) */
|
|
291
|
-
isBotReady: boolean;
|
|
292
|
-
/** Audio control methods for managing microphone mute/unmute */
|
|
293
|
-
audioControls: AudioControls;
|
|
294
|
-
/** Video control methods for enabling/disabling camera */
|
|
295
|
-
videoControls: VideoControls;
|
|
296
|
-
/** Screen sharing control methods */
|
|
297
|
-
screenShareControls: ScreenShareControls;
|
|
298
|
-
/**
|
|
299
|
-
* Toggle text-to-speech on or off.
|
|
300
|
-
* When disabled, character responses won't be spoken aloud.
|
|
301
|
-
*/
|
|
302
|
-
toggleTts: (enabled: boolean) => void;
|
|
303
|
-
/**
|
|
304
|
-
* Toggle speech-to-text on or off.
|
|
305
|
-
* When enabled, user speech is transcribed to text (e.g. for dictation).
|
|
306
|
-
* When disabled, STT is off.
|
|
307
|
-
*/
|
|
308
|
-
toggleStt: (enabled: boolean) => void;
|
|
309
|
-
}
|
|
310
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAEtC;;;;GAIG;AACH,UAAU,aAAa;IACrB,yEAAyE;IACzE,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,0EAA0E;IAC1E,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,0EAA0E;IAC1E,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,+CAA+C;IAC/C,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,sEA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I,CAAC;IAE5E;;;OAGG;IACH,kBAAkB,EAAE,CAAC,YAAY,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;IAEtE;;;OAGG;IACH,iBAAiB,EAAE,CAAC,WAAW,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;IAE3D,6DAA6D;IAC7D,YAAY,EAAE,WAAW,EAAE,CAAC;IAE5B,qDAAqD;IACrD,iBAAiB,EAAE,MAAM,CAAC;IAE1B,+DAA+D;IAC/D,kBAAkB,EAAE,MAAM,GAAG,IAAI,CAAC;IAElC,kFAAkF;IAClF,UAAU,EAAE,OAAO,CAAC;IAEpB,gEAAgE;IAChE,aAAa,EAAE,aAAa,CAAC;IAE7B,0DAA0D;IAC1D,aAAa,EAAE,aAAa,CAAC;IAE7B,qCAAqC;IACrC,mBAAmB,EAAE,mBAAmB,CAAC;IAEzC;;;OAGG;IACH,SAAS,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;IAEtC;;;;OAIG;IACH,SAAS,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;CACvC"}
|
package/dist/types/index.js
DELETED
package/dist/types/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":""}
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import { EventEmitter } from "../core/EventEmitter";
|
|
2
|
-
/**
|
|
3
|
-
* Represents a single latency measurement
|
|
4
|
-
*/
|
|
5
|
-
export interface LatencyMeasurement {
|
|
6
|
-
id: string;
|
|
7
|
-
startTime: number;
|
|
8
|
-
endTime: number;
|
|
9
|
-
latency: number;
|
|
10
|
-
type: "text" | "voice";
|
|
11
|
-
userMessage?: string;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Latency statistics
|
|
15
|
-
*/
|
|
16
|
-
export interface LatencyStats {
|
|
17
|
-
average: number;
|
|
18
|
-
min: number;
|
|
19
|
-
max: number;
|
|
20
|
-
median: number;
|
|
21
|
-
p95: number;
|
|
22
|
-
count: number;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* LatencyMonitor - Tracks and manages latency measurements
|
|
26
|
-
* This is for dev/debugging purposes only
|
|
27
|
-
*/
|
|
28
|
-
export declare class LatencyMonitor extends EventEmitter {
|
|
29
|
-
private measurements;
|
|
30
|
-
private pendingMeasurement;
|
|
31
|
-
private maxMeasurements;
|
|
32
|
-
private isEnabled;
|
|
33
|
-
constructor(enabled?: boolean);
|
|
34
|
-
/**
|
|
35
|
-
* Enable latency monitoring
|
|
36
|
-
*/
|
|
37
|
-
enable(): void;
|
|
38
|
-
/**
|
|
39
|
-
* Disable latency monitoring
|
|
40
|
-
*/
|
|
41
|
-
disable(): void;
|
|
42
|
-
/**
|
|
43
|
-
* Check if monitoring is enabled
|
|
44
|
-
*/
|
|
45
|
-
get enabled(): boolean;
|
|
46
|
-
/**
|
|
47
|
-
* Start a new latency measurement
|
|
48
|
-
*/
|
|
49
|
-
startMeasurement(type: "text" | "voice", userMessage?: string): void;
|
|
50
|
-
/**
|
|
51
|
-
* Complete the current measurement
|
|
52
|
-
*/
|
|
53
|
-
endMeasurement(): void;
|
|
54
|
-
/**
|
|
55
|
-
* Cancel the current pending measurement
|
|
56
|
-
*/
|
|
57
|
-
cancelMeasurement(): void;
|
|
58
|
-
/**
|
|
59
|
-
* Get all measurements
|
|
60
|
-
*/
|
|
61
|
-
getMeasurements(): LatencyMeasurement[];
|
|
62
|
-
/**
|
|
63
|
-
* Get the latest measurement
|
|
64
|
-
*/
|
|
65
|
-
getLatestMeasurement(): LatencyMeasurement | null;
|
|
66
|
-
/**
|
|
67
|
-
* Get latency statistics
|
|
68
|
-
*/
|
|
69
|
-
getStats(): LatencyStats | null;
|
|
70
|
-
/**
|
|
71
|
-
* Clear all measurements
|
|
72
|
-
*/
|
|
73
|
-
clear(): void;
|
|
74
|
-
/**
|
|
75
|
-
* Check if there's a pending measurement
|
|
76
|
-
*/
|
|
77
|
-
get hasPendingMeasurement(): boolean;
|
|
78
|
-
/**
|
|
79
|
-
* Get pending measurement info
|
|
80
|
-
*/
|
|
81
|
-
getPendingMeasurement(): {
|
|
82
|
-
id: string;
|
|
83
|
-
startTime: number;
|
|
84
|
-
type: "text" | "voice";
|
|
85
|
-
userMessage?: string;
|
|
86
|
-
} | null;
|
|
87
|
-
}
|
|
88
|
-
//# sourceMappingURL=LatencyMonitor.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"LatencyMonitor.d.ts","sourceRoot":"","sources":["../../src/utils/LatencyMonitor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEpD;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;;GAGG;AACH,qBAAa,cAAe,SAAQ,YAAY;IAC9C,OAAO,CAAC,YAAY,CAA4B;IAChD,OAAO,CAAC,kBAAkB,CAKV;IAChB,OAAO,CAAC,eAAe,CAAe;IACtC,OAAO,CAAC,SAAS,CAAkB;gBAEvB,OAAO,GAAE,OAAe;IAKpC;;OAEG;IACH,MAAM,IAAI,IAAI;IAKd;;OAEG;IACH,OAAO,IAAI,IAAI;IAKf;;OAEG;IACH,IAAI,OAAO,IAAI,OAAO,CAErB;IAED;;OAEG;IACH,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI;IAYpE;;OAEG;IACH,cAAc,IAAI,IAAI;IA+BtB;;OAEG;IACH,iBAAiB,IAAI,IAAI;IAIzB;;OAEG;IACH,eAAe,IAAI,kBAAkB,EAAE;IAIvC;;OAEG;IACH,oBAAoB,IAAI,kBAAkB,GAAG,IAAI;IAMjD;;OAEG;IACH,QAAQ,IAAI,YAAY,GAAG,IAAI;IAkB/B;;OAEG;IACH,KAAK,IAAI,IAAI;IAMb;;OAEG;IACH,IAAI,qBAAqB,IAAI,OAAO,CAEnC;IAED;;OAEG;IACH,qBAAqB;YApJf,MAAM;mBACC,MAAM;cACX,MAAM,GAAG,OAAO;sBACR,MAAM;;CAoJvB"}
|
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
import { EventEmitter } from "../core/EventEmitter";
|
|
2
|
-
/**
|
|
3
|
-
* LatencyMonitor - Tracks and manages latency measurements
|
|
4
|
-
* This is for dev/debugging purposes only
|
|
5
|
-
*/
|
|
6
|
-
export class LatencyMonitor extends EventEmitter {
|
|
7
|
-
constructor(enabled = false) {
|
|
8
|
-
super();
|
|
9
|
-
this.measurements = [];
|
|
10
|
-
this.pendingMeasurement = null;
|
|
11
|
-
this.maxMeasurements = 100; // Keep last 100 measurements
|
|
12
|
-
this.isEnabled = false;
|
|
13
|
-
this.isEnabled = enabled;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Enable latency monitoring
|
|
17
|
-
*/
|
|
18
|
-
enable() {
|
|
19
|
-
this.isEnabled = true;
|
|
20
|
-
this.emit("enabledChange", true);
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Disable latency monitoring
|
|
24
|
-
*/
|
|
25
|
-
disable() {
|
|
26
|
-
this.isEnabled = false;
|
|
27
|
-
this.emit("enabledChange", false);
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Check if monitoring is enabled
|
|
31
|
-
*/
|
|
32
|
-
get enabled() {
|
|
33
|
-
return this.isEnabled;
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Start a new latency measurement
|
|
37
|
-
*/
|
|
38
|
-
startMeasurement(type, userMessage) {
|
|
39
|
-
if (!this.isEnabled)
|
|
40
|
-
return;
|
|
41
|
-
const id = `${type}-${Date.now()}-${Math.random()}`;
|
|
42
|
-
this.pendingMeasurement = {
|
|
43
|
-
id,
|
|
44
|
-
startTime: Date.now(),
|
|
45
|
-
type,
|
|
46
|
-
userMessage: userMessage?.substring(0, 50), // Keep first 50 chars
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Complete the current measurement
|
|
51
|
-
*/
|
|
52
|
-
endMeasurement() {
|
|
53
|
-
if (!this.isEnabled || !this.pendingMeasurement)
|
|
54
|
-
return;
|
|
55
|
-
const endTime = Date.now();
|
|
56
|
-
const latency = endTime - this.pendingMeasurement.startTime;
|
|
57
|
-
const measurement = {
|
|
58
|
-
id: this.pendingMeasurement.id,
|
|
59
|
-
startTime: this.pendingMeasurement.startTime,
|
|
60
|
-
endTime,
|
|
61
|
-
latency,
|
|
62
|
-
type: this.pendingMeasurement.type,
|
|
63
|
-
userMessage: this.pendingMeasurement.userMessage,
|
|
64
|
-
};
|
|
65
|
-
// Add to measurements array
|
|
66
|
-
this.measurements.push(measurement);
|
|
67
|
-
// Keep only the last N measurements
|
|
68
|
-
if (this.measurements.length > this.maxMeasurements) {
|
|
69
|
-
this.measurements.shift();
|
|
70
|
-
}
|
|
71
|
-
// Clear pending measurement
|
|
72
|
-
this.pendingMeasurement = null;
|
|
73
|
-
// Emit new measurement
|
|
74
|
-
this.emit("measurement", measurement);
|
|
75
|
-
this.emit("measurementsChange", this.measurements);
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Cancel the current pending measurement
|
|
79
|
-
*/
|
|
80
|
-
cancelMeasurement() {
|
|
81
|
-
this.pendingMeasurement = null;
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Get all measurements
|
|
85
|
-
*/
|
|
86
|
-
getMeasurements() {
|
|
87
|
-
return [...this.measurements];
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Get the latest measurement
|
|
91
|
-
*/
|
|
92
|
-
getLatestMeasurement() {
|
|
93
|
-
return this.measurements.length > 0
|
|
94
|
-
? this.measurements[this.measurements.length - 1]
|
|
95
|
-
: null;
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Get latency statistics
|
|
99
|
-
*/
|
|
100
|
-
getStats() {
|
|
101
|
-
if (this.measurements.length === 0)
|
|
102
|
-
return null;
|
|
103
|
-
const latencies = this.measurements.map((m) => m.latency).sort((a, b) => a - b);
|
|
104
|
-
const sum = latencies.reduce((acc, val) => acc + val, 0);
|
|
105
|
-
const p95Index = Math.floor(latencies.length * 0.95);
|
|
106
|
-
return {
|
|
107
|
-
average: sum / latencies.length,
|
|
108
|
-
min: latencies[0],
|
|
109
|
-
max: latencies[latencies.length - 1],
|
|
110
|
-
median: latencies[Math.floor(latencies.length / 2)],
|
|
111
|
-
p95: latencies[p95Index],
|
|
112
|
-
count: latencies.length,
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* Clear all measurements
|
|
117
|
-
*/
|
|
118
|
-
clear() {
|
|
119
|
-
this.measurements = [];
|
|
120
|
-
this.pendingMeasurement = null;
|
|
121
|
-
this.emit("measurementsChange", this.measurements);
|
|
122
|
-
}
|
|
123
|
-
/**
|
|
124
|
-
* Check if there's a pending measurement
|
|
125
|
-
*/
|
|
126
|
-
get hasPendingMeasurement() {
|
|
127
|
-
return this.pendingMeasurement !== null;
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* Get pending measurement info
|
|
131
|
-
*/
|
|
132
|
-
getPendingMeasurement() {
|
|
133
|
-
return this.pendingMeasurement ? { ...this.pendingMeasurement } : null;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
//# sourceMappingURL=LatencyMonitor.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"LatencyMonitor.js","sourceRoot":"","sources":["../../src/utils/LatencyMonitor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AA0BpD;;;GAGG;AACH,MAAM,OAAO,cAAe,SAAQ,YAAY;IAW9C,YAAY,UAAmB,KAAK;QAClC,KAAK,EAAE,CAAC;QAXF,iBAAY,GAAyB,EAAE,CAAC;QACxC,uBAAkB,GAKf,IAAI,CAAC;QACR,oBAAe,GAAW,GAAG,CAAC,CAAC,6BAA6B;QAC5D,cAAS,GAAY,KAAK,CAAC;QAIjC,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC;IAC3B,CAAC;IAED;;OAEG;IACH,MAAM;QACJ,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;QACtB,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE,IAAI,CAAC,CAAC;IACnC,CAAC;IAED;;OAEG;IACH,OAAO;QACL,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC;QACvB,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE,KAAK,CAAC,CAAC;IACpC,CAAC;IAED;;OAEG;IACH,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAED;;OAEG;IACH,gBAAgB,CAAC,IAAsB,EAAE,WAAoB;QAC3D,IAAI,CAAC,IAAI,CAAC,SAAS;YAAE,OAAO;QAE5B,MAAM,EAAE,GAAG,GAAG,IAAI,IAAI,IAAI,CAAC,GAAG,EAAE,IAAI,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC;QACpD,IAAI,CAAC,kBAAkB,GAAG;YACxB,E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