@convai/web-sdk 0.3.1-beta.2 → 0.3.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 +535 -1077
- package/dist/core/AudioManager.d.ts.map +1 -0
- package/dist/core/AudioManager.js +262 -0
- package/dist/core/AudioManager.js.map +1 -0
- package/dist/core/BlendshapeQueue.d.ts +128 -0
- package/dist/core/BlendshapeQueue.d.ts.map +1 -0
- package/dist/core/BlendshapeQueue.js +229 -0
- package/dist/core/BlendshapeQueue.js.map +1 -0
- package/dist/{types/core → core}/ConvaiClient.d.ts +19 -15
- package/dist/core/ConvaiClient.d.ts.map +1 -0
- package/dist/core/ConvaiClient.js +623 -0
- package/dist/core/ConvaiClient.js.map +1 -0
- package/dist/core/EventEmitter.d.ts.map +1 -0
- package/dist/core/EventEmitter.js +68 -0
- package/dist/core/EventEmitter.js.map +1 -0
- package/dist/{types/core → core}/MessageHandler.d.ts +7 -0
- package/dist/core/MessageHandler.d.ts.map +1 -0
- package/dist/core/MessageHandler.js +333 -0
- package/dist/core/MessageHandler.js.map +1 -0
- package/dist/core/ScreenShareManager.d.ts.map +1 -0
- package/dist/core/ScreenShareManager.js +207 -0
- package/dist/core/ScreenShareManager.js.map +1 -0
- package/dist/core/VideoManager.d.ts.map +1 -0
- package/dist/core/VideoManager.js +205 -0
- package/dist/core/VideoManager.js.map +1 -0
- package/dist/{types/core → core}/index.d.ts +2 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +14 -1970
- package/dist/core/index.js.map +1 -0
- package/dist/{types/core → core}/types.d.ts +12 -21
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +2 -0
- package/dist/core/types.js.map +1 -0
- package/dist/dev.d.ts.map +1 -0
- package/dist/dev.js +12 -0
- package/dist/dev.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/lipsync-helpers/arkitBlendshapeHelpers.d.ts.map +1 -0
- package/dist/lipsync-helpers/arkitBlendshapeHelpers.js +201 -0
- package/dist/lipsync-helpers/arkitBlendshapeHelpers.js.map +1 -0
- package/dist/lipsync-helpers/arkitOrder61.d.ts.map +1 -0
- package/dist/lipsync-helpers/arkitOrder61.js +287 -0
- package/dist/lipsync-helpers/arkitOrder61.js.map +1 -0
- package/dist/lipsync-helpers/arkitPhonemeReference.d.ts.map +1 -0
- package/dist/lipsync-helpers/arkitPhonemeReference.js +362 -0
- package/dist/lipsync-helpers/arkitPhonemeReference.js.map +1 -0
- package/dist/{types/lipsync-helpers → lipsync-helpers}/index.d.ts +1 -0
- package/dist/lipsync-helpers/index.d.ts.map +1 -0
- package/dist/lipsync-helpers/index.js +20 -1165
- package/dist/lipsync-helpers/index.js.map +1 -0
- package/dist/lipsync-helpers/metahumanOrder251.d.ts +115 -0
- package/dist/lipsync-helpers/metahumanOrder251.d.ts.map +1 -0
- package/dist/lipsync-helpers/metahumanOrder251.js +432 -0
- package/dist/lipsync-helpers/metahumanOrder251.js.map +1 -0
- package/dist/lipsync-helpers/neurosyncBlendshapeMapper.d.ts.map +1 -0
- package/dist/lipsync-helpers/neurosyncBlendshapeMapper.js +315 -0
- package/dist/lipsync-helpers/neurosyncBlendshapeMapper.js.map +1 -0
- package/dist/react/components/ConvaiWidget.d.ts.map +1 -0
- package/dist/react/components/ConvaiWidget.js +505 -0
- package/dist/react/components/ConvaiWidget.js.map +1 -0
- package/dist/react/components/index.d.ts.map +1 -0
- package/dist/react/components/index.js +3 -0
- package/dist/react/components/index.js.map +1 -0
- package/dist/react/components/rtc-widget/components/AudioSettingsPanel.d.ts.map +1 -0
- package/dist/react/components/rtc-widget/components/AudioSettingsPanel.js +316 -0
- package/dist/react/components/rtc-widget/components/AudioSettingsPanel.js.map +1 -0
- package/dist/react/components/rtc-widget/components/AudioVisualizer.d.ts.map +1 -0
- package/dist/react/components/rtc-widget/components/AudioVisualizer.js +259 -0
- package/dist/react/components/rtc-widget/components/AudioVisualizer.js.map +1 -0
- package/dist/react/components/rtc-widget/components/ConviMessage.d.ts.map +1 -0
- package/dist/react/components/rtc-widget/components/ConviMessage.js +14 -0
- package/dist/react/components/rtc-widget/components/ConviMessage.js.map +1 -0
- package/dist/react/components/rtc-widget/components/FloatingVideo.d.ts.map +1 -0
- package/dist/react/components/rtc-widget/components/FloatingVideo.js +122 -0
- package/dist/react/components/rtc-widget/components/FloatingVideo.js.map +1 -0
- package/dist/react/components/rtc-widget/components/MarkdownRenderer.d.ts.map +1 -0
- package/dist/react/components/rtc-widget/components/MarkdownRenderer.js +68 -0
- package/dist/react/components/rtc-widget/components/MarkdownRenderer.js.map +1 -0
- package/dist/react/components/rtc-widget/components/MessageBubble.d.ts.map +1 -0
- package/dist/react/components/rtc-widget/components/MessageBubble.js +23 -0
- package/dist/react/components/rtc-widget/components/MessageBubble.js.map +1 -0
- package/dist/react/components/rtc-widget/components/MessageList.d.ts.map +1 -0
- package/dist/react/components/rtc-widget/components/MessageList.js +89 -0
- package/dist/react/components/rtc-widget/components/MessageList.js.map +1 -0
- package/dist/react/components/rtc-widget/components/UserMessage.d.ts.map +1 -0
- package/dist/react/components/rtc-widget/components/UserMessage.js +15 -0
- package/dist/react/components/rtc-widget/components/UserMessage.js.map +1 -0
- package/dist/react/components/rtc-widget/components/conviComponents/ConviButton.d.ts.map +1 -0
- package/dist/react/components/rtc-widget/components/conviComponents/ConviButton.js +15 -0
- package/dist/react/components/rtc-widget/components/conviComponents/ConviButton.js.map +1 -0
- package/dist/react/components/rtc-widget/components/conviComponents/ConviFooter.d.ts.map +1 -0
- package/dist/react/components/rtc-widget/components/conviComponents/ConviFooter.js +172 -0
- package/dist/react/components/rtc-widget/components/conviComponents/ConviFooter.js.map +1 -0
- package/dist/react/components/rtc-widget/components/conviComponents/ConviHeader.d.ts.map +1 -0
- package/dist/react/components/rtc-widget/components/conviComponents/ConviHeader.js +66 -0
- package/dist/react/components/rtc-widget/components/conviComponents/ConviHeader.js.map +1 -0
- package/dist/react/components/rtc-widget/components/conviComponents/SettingsTray.d.ts.map +1 -0
- package/dist/react/components/rtc-widget/components/conviComponents/SettingsTray.js +68 -0
- package/dist/react/components/rtc-widget/components/conviComponents/SettingsTray.js.map +1 -0
- package/dist/react/components/rtc-widget/components/conviComponents/VoiceModeOverlay.d.ts.map +1 -0
- package/dist/react/components/rtc-widget/components/conviComponents/VoiceModeOverlay.js +255 -0
- package/dist/react/components/rtc-widget/components/conviComponents/VoiceModeOverlay.js.map +1 -0
- package/dist/react/components/rtc-widget/components/conviComponents/index.d.ts.map +1 -0
- package/dist/react/components/rtc-widget/components/conviComponents/index.js +6 -0
- package/dist/react/components/rtc-widget/components/conviComponents/index.js.map +1 -0
- package/dist/react/components/rtc-widget/components/index.d.ts.map +1 -0
- package/dist/react/components/rtc-widget/components/index.js +15 -0
- package/dist/react/components/rtc-widget/components/index.js.map +1 -0
- package/dist/react/components/rtc-widget/index.d.ts.map +1 -0
- package/dist/react/components/rtc-widget/index.js +9 -0
- package/dist/react/components/rtc-widget/index.js.map +1 -0
- package/dist/react/components/rtc-widget/styles/framerConfig.d.ts.map +1 -0
- package/dist/react/components/rtc-widget/styles/framerConfig.js +73 -0
- package/dist/react/components/rtc-widget/styles/framerConfig.js.map +1 -0
- package/dist/react/components/rtc-widget/styles/icons.d.ts.map +1 -0
- package/dist/react/components/rtc-widget/styles/icons.js +257 -0
- package/dist/react/components/rtc-widget/styles/icons.js.map +1 -0
- package/dist/react/components/rtc-widget/styles/index.d.ts.map +1 -0
- package/dist/react/components/rtc-widget/styles/index.js +9 -0
- package/dist/react/components/rtc-widget/styles/index.js.map +1 -0
- package/dist/react/components/rtc-widget/styles/styledComponents.d.ts.map +1 -0
- package/dist/react/components/rtc-widget/styles/styledComponents.js +663 -0
- package/dist/react/components/rtc-widget/styles/styledComponents.js.map +1 -0
- package/dist/react/components/rtc-widget/styles/theme.d.ts.map +1 -0
- package/dist/react/components/rtc-widget/styles/theme.js +290 -0
- package/dist/react/components/rtc-widget/styles/theme.js.map +1 -0
- package/dist/react/components/rtc-widget/types/index.d.ts.map +1 -0
- package/dist/react/components/rtc-widget/types/index.js +2 -0
- package/dist/react/components/rtc-widget/types/index.js.map +1 -0
- package/dist/react/hooks/index.d.ts.map +1 -0
- package/dist/react/hooks/index.js +6 -0
- package/dist/react/hooks/index.js.map +1 -0
- package/dist/react/hooks/useCharacterInfo.d.ts.map +1 -0
- package/dist/react/hooks/useCharacterInfo.js +60 -0
- package/dist/react/hooks/useCharacterInfo.js.map +1 -0
- package/dist/react/hooks/useConvaiClient.d.ts +35 -0
- package/dist/react/hooks/useConvaiClient.d.ts.map +1 -0
- package/dist/react/hooks/useConvaiClient.js +183 -0
- package/dist/react/hooks/useConvaiClient.js.map +1 -0
- package/dist/react/hooks/useLocalCameraTrack.d.ts.map +1 -0
- package/dist/react/hooks/useLocalCameraTrack.js +34 -0
- package/dist/react/hooks/useLocalCameraTrack.js.map +1 -0
- package/dist/{types/react → react}/index.d.ts +0 -2
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +13 -0
- package/dist/react/index.js.map +1 -0
- package/dist/types/index.d.ts +260 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +2 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/LatencyMonitor.d.ts.map +1 -0
- package/dist/utils/LatencyMonitor.js +136 -0
- package/dist/utils/LatencyMonitor.js.map +1 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +96 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/speakerManagement.d.ts.map +1 -0
- package/dist/utils/speakerManagement.js +64 -0
- package/dist/utils/speakerManagement.js.map +1 -0
- package/dist/{types/vanilla → vanilla}/AudioRenderer.d.ts +5 -0
- package/dist/vanilla/AudioRenderer.d.ts.map +1 -0
- package/dist/vanilla/AudioRenderer.js +135 -0
- package/dist/vanilla/AudioRenderer.js.map +1 -0
- package/dist/vanilla/ConvaiWidget.d.ts.map +1 -0
- package/dist/vanilla/ConvaiWidget.js +1786 -0
- package/dist/vanilla/ConvaiWidget.js.map +1 -0
- package/dist/vanilla/icons.d.ts.map +1 -0
- package/dist/vanilla/icons.js +222 -0
- package/dist/vanilla/icons.js.map +1 -0
- package/dist/{types/vanilla → vanilla}/index.d.ts +1 -3
- package/dist/vanilla/index.d.ts.map +1 -0
- package/dist/vanilla/index.js +20 -5507
- package/dist/vanilla/index.js.map +1 -0
- package/dist/vanilla/styles.d.ts.map +1 -0
- package/dist/vanilla/styles.js +287 -0
- package/dist/vanilla/styles.js.map +1 -0
- package/dist/vanilla/types.d.ts +43 -0
- package/dist/vanilla/types.d.ts.map +1 -0
- package/dist/vanilla/types.js +2 -0
- package/dist/vanilla/types.js.map +1 -0
- package/package.json +33 -38
- package/CHANGELOG.md +0 -165
- package/dist/core/index.cjs +0 -1977
- package/dist/lipsync-helpers/index.cjs +0 -1195
- package/dist/types/core/AudioManager.d.ts.map +0 -1
- package/dist/types/core/ConvaiClient.d.ts.map +0 -1
- package/dist/types/core/EventEmitter.d.ts.map +0 -1
- package/dist/types/core/MessageHandler.d.ts.map +0 -1
- package/dist/types/core/ScreenShareManager.d.ts.map +0 -1
- package/dist/types/core/VideoManager.d.ts.map +0 -1
- package/dist/types/core/index.d.ts.map +0 -1
- package/dist/types/core/types.d.ts.map +0 -1
- package/dist/types/dev.d.ts.map +0 -1
- package/dist/types/lipsync-helpers/arkitBlendshapeHelpers.d.ts.map +0 -1
- package/dist/types/lipsync-helpers/arkitOrder61.d.ts.map +0 -1
- package/dist/types/lipsync-helpers/arkitPhonemeReference.d.ts.map +0 -1
- package/dist/types/lipsync-helpers/index.d.ts.map +0 -1
- package/dist/types/lipsync-helpers/neurosyncBlendshapeMapper.d.ts.map +0 -1
- package/dist/types/react/components/ConvaiWidget.d.ts.map +0 -1
- package/dist/types/react/components/index.d.ts.map +0 -1
- package/dist/types/react/components/rtc-widget/components/AudioSettingsPanel.d.ts.map +0 -1
- package/dist/types/react/components/rtc-widget/components/AudioVisualizer.d.ts.map +0 -1
- package/dist/types/react/components/rtc-widget/components/ConviMessage.d.ts.map +0 -1
- package/dist/types/react/components/rtc-widget/components/FloatingVideo.d.ts.map +0 -1
- package/dist/types/react/components/rtc-widget/components/MarkdownRenderer.d.ts.map +0 -1
- package/dist/types/react/components/rtc-widget/components/MessageBubble.d.ts.map +0 -1
- package/dist/types/react/components/rtc-widget/components/MessageList.d.ts.map +0 -1
- package/dist/types/react/components/rtc-widget/components/UserMessage.d.ts.map +0 -1
- package/dist/types/react/components/rtc-widget/components/conviComponents/ConviButton.d.ts.map +0 -1
- package/dist/types/react/components/rtc-widget/components/conviComponents/ConviFooter.d.ts.map +0 -1
- package/dist/types/react/components/rtc-widget/components/conviComponents/ConviHeader.d.ts.map +0 -1
- package/dist/types/react/components/rtc-widget/components/conviComponents/SettingsTray.d.ts.map +0 -1
- package/dist/types/react/components/rtc-widget/components/conviComponents/VoiceModeOverlay.d.ts.map +0 -1
- package/dist/types/react/components/rtc-widget/components/conviComponents/index.d.ts.map +0 -1
- package/dist/types/react/components/rtc-widget/components/index.d.ts.map +0 -1
- package/dist/types/react/components/rtc-widget/index.d.ts.map +0 -1
- package/dist/types/react/components/rtc-widget/styles/framerConfig.d.ts.map +0 -1
- package/dist/types/react/components/rtc-widget/styles/icons.d.ts.map +0 -1
- package/dist/types/react/components/rtc-widget/styles/index.d.ts.map +0 -1
- package/dist/types/react/components/rtc-widget/styles/styledComponents.d.ts.map +0 -1
- package/dist/types/react/components/rtc-widget/styles/theme.d.ts.map +0 -1
- package/dist/types/react/components/rtc-widget/types/index.d.ts.map +0 -1
- package/dist/types/react/hooks/index.d.ts.map +0 -1
- package/dist/types/react/hooks/useCharacterInfo.d.ts.map +0 -1
- package/dist/types/react/hooks/useConvaiClient.d.ts +0 -141
- package/dist/types/react/hooks/useConvaiClient.d.ts.map +0 -1
- package/dist/types/react/hooks/useLocalCameraTrack.d.ts.map +0 -1
- package/dist/types/react/index.d.ts.map +0 -1
- package/dist/types/types/index.d.ts +0 -261
- package/dist/types/types/index.d.ts.map +0 -1
- package/dist/types/utils/LatencyMonitor.d.ts.map +0 -1
- package/dist/types/utils/logger.d.ts.map +0 -1
- package/dist/types/utils/speakerManagement.d.ts.map +0 -1
- package/dist/types/vanilla/AudioRenderer.d.ts.map +0 -1
- package/dist/types/vanilla/ConvaiWidget.d.ts.map +0 -1
- package/dist/types/vanilla/icons.d.ts.map +0 -1
- package/dist/types/vanilla/index.d.ts.map +0 -1
- package/dist/types/vanilla/styles.d.ts.map +0 -1
- package/dist/types/vanilla/types.d.ts +0 -106
- package/dist/types/vanilla/types.d.ts.map +0 -1
- package/dist/umd/convai.umd.js +0 -1
- package/dist/vanilla/index.cjs +0 -5557
- /package/dist/{types/core → core}/AudioManager.d.ts +0 -0
- /package/dist/{types/core → core}/EventEmitter.d.ts +0 -0
- /package/dist/{types/core → core}/ScreenShareManager.d.ts +0 -0
- /package/dist/{types/core → core}/VideoManager.d.ts +0 -0
- /package/dist/{types/dev.d.ts → dev.d.ts} +0 -0
- /package/dist/{types/lipsync-helpers → lipsync-helpers}/arkitBlendshapeHelpers.d.ts +0 -0
- /package/dist/{types/lipsync-helpers → lipsync-helpers}/arkitOrder61.d.ts +0 -0
- /package/dist/{types/lipsync-helpers → lipsync-helpers}/arkitPhonemeReference.d.ts +0 -0
- /package/dist/{types/lipsync-helpers → lipsync-helpers}/neurosyncBlendshapeMapper.d.ts +0 -0
- /package/dist/{types/react → react}/components/ConvaiWidget.d.ts +0 -0
- /package/dist/{types/react → react}/components/index.d.ts +0 -0
- /package/dist/{types/react → react}/components/rtc-widget/components/AudioSettingsPanel.d.ts +0 -0
- /package/dist/{types/react → react}/components/rtc-widget/components/AudioVisualizer.d.ts +0 -0
- /package/dist/{types/react → react}/components/rtc-widget/components/ConviMessage.d.ts +0 -0
- /package/dist/{types/react → react}/components/rtc-widget/components/FloatingVideo.d.ts +0 -0
- /package/dist/{types/react → react}/components/rtc-widget/components/MarkdownRenderer.d.ts +0 -0
- /package/dist/{types/react → react}/components/rtc-widget/components/MessageBubble.d.ts +0 -0
- /package/dist/{types/react → react}/components/rtc-widget/components/MessageList.d.ts +0 -0
- /package/dist/{types/react → react}/components/rtc-widget/components/UserMessage.d.ts +0 -0
- /package/dist/{types/react → react}/components/rtc-widget/components/conviComponents/ConviButton.d.ts +0 -0
- /package/dist/{types/react → react}/components/rtc-widget/components/conviComponents/ConviFooter.d.ts +0 -0
- /package/dist/{types/react → react}/components/rtc-widget/components/conviComponents/ConviHeader.d.ts +0 -0
- /package/dist/{types/react → react}/components/rtc-widget/components/conviComponents/SettingsTray.d.ts +0 -0
- /package/dist/{types/react → react}/components/rtc-widget/components/conviComponents/VoiceModeOverlay.d.ts +0 -0
- /package/dist/{types/react → react}/components/rtc-widget/components/conviComponents/index.d.ts +0 -0
- /package/dist/{types/react → react}/components/rtc-widget/components/index.d.ts +0 -0
- /package/dist/{types/react → react}/components/rtc-widget/index.d.ts +0 -0
- /package/dist/{types/react → react}/components/rtc-widget/styles/framerConfig.d.ts +0 -0
- /package/dist/{types/react → react}/components/rtc-widget/styles/icons.d.ts +0 -0
- /package/dist/{types/react → react}/components/rtc-widget/styles/index.d.ts +0 -0
- /package/dist/{types/react → react}/components/rtc-widget/styles/styledComponents.d.ts +0 -0
- /package/dist/{types/react → react}/components/rtc-widget/styles/theme.d.ts +0 -0
- /package/dist/{types/react → react}/components/rtc-widget/types/index.d.ts +0 -0
- /package/dist/{types/react → react}/hooks/index.d.ts +0 -0
- /package/dist/{types/react → react}/hooks/useCharacterInfo.d.ts +0 -0
- /package/dist/{types/react → react}/hooks/useLocalCameraTrack.d.ts +0 -0
- /package/dist/{types/utils → utils}/LatencyMonitor.d.ts +0 -0
- /package/dist/{types/utils → utils}/logger.d.ts +0 -0
- /package/dist/{types/utils → utils}/speakerManagement.d.ts +0 -0
- /package/dist/{types/vanilla → vanilla}/ConvaiWidget.d.ts +0 -0
- /package/dist/{types/vanilla → vanilla}/icons.d.ts +0 -0
- /package/dist/{types/vanilla → vanilla}/styles.d.ts +0 -0
|
@@ -2,6 +2,7 @@ import { Room } from "livekit-client";
|
|
|
2
2
|
import { ConvaiConfig, ConvaiClientState, ChatMessage, IConvaiClient, AudioControls, VideoControls, ScreenShareControls } from "./types";
|
|
3
3
|
import { EventEmitter } from "./EventEmitter";
|
|
4
4
|
import { LatencyMonitor } from "../utils/LatencyMonitor";
|
|
5
|
+
import { BlendshapeQueue } from "./BlendshapeQueue";
|
|
5
6
|
/**
|
|
6
7
|
* Main Convai client class for managing AI voice assistant connections
|
|
7
8
|
* Provides complete interface for connecting to Convai's voice assistants,
|
|
@@ -55,6 +56,8 @@ export declare class ConvaiClient extends EventEmitter implements IConvaiClient
|
|
|
55
56
|
private _screenShareManager;
|
|
56
57
|
private _messageHandler;
|
|
57
58
|
private _latencyMonitor;
|
|
59
|
+
private _conversationSessionId;
|
|
60
|
+
private _conversationStartTime;
|
|
58
61
|
constructor(config?: ConvaiConfig);
|
|
59
62
|
get state(): ConvaiClientState;
|
|
60
63
|
get connectionType(): "audio" | "video" | null;
|
|
@@ -70,21 +73,8 @@ export declare class ConvaiClient extends EventEmitter implements IConvaiClient
|
|
|
70
73
|
get videoControls(): VideoControls;
|
|
71
74
|
get screenShareControls(): ScreenShareControls;
|
|
72
75
|
get latencyMonitor(): LatencyMonitor;
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
* Convenience getter - equivalent to audioControls.isAudioMuted
|
|
76
|
-
*/
|
|
77
|
-
get isAudioMuted(): boolean;
|
|
78
|
-
/**
|
|
79
|
-
* Whether the user's video is currently enabled
|
|
80
|
-
* Convenience getter - equivalent to videoControls.isVideoEnabled
|
|
81
|
-
*/
|
|
82
|
-
get isVideoEnabled(): boolean;
|
|
83
|
-
/**
|
|
84
|
-
* Whether screen sharing is currently active
|
|
85
|
-
* Convenience getter - equivalent to screenShareControls.isScreenShareActive
|
|
86
|
-
*/
|
|
87
|
-
get isScreenShareActive(): boolean;
|
|
76
|
+
get blendshapeQueue(): BlendshapeQueue;
|
|
77
|
+
get conversationSessionId(): number;
|
|
88
78
|
/**
|
|
89
79
|
* Setup event listeners for room and managers
|
|
90
80
|
*/
|
|
@@ -149,5 +139,19 @@ export declare class ConvaiClient extends EventEmitter implements IConvaiClient
|
|
|
149
139
|
* Toggle text-to-speech on or off
|
|
150
140
|
*/
|
|
151
141
|
toggleTts(enabled: boolean): void;
|
|
142
|
+
/**
|
|
143
|
+
* Add a post-processor to modify blendshape frames during playback
|
|
144
|
+
* @param processor - Function that processes blendshape frames
|
|
145
|
+
*/
|
|
146
|
+
addLipsyncPostProcessor(processor: import("./BlendshapeQueue").BlendshapePostProcessor): void;
|
|
147
|
+
/**
|
|
148
|
+
* Remove a post-processor
|
|
149
|
+
* @param processor - The processor function to remove
|
|
150
|
+
*/
|
|
151
|
+
removeLipsyncPostProcessor(processor: import("./BlendshapeQueue").BlendshapePostProcessor): void;
|
|
152
|
+
/**
|
|
153
|
+
* Clear all post-processors
|
|
154
|
+
*/
|
|
155
|
+
clearLipsyncPostProcessors(): void;
|
|
152
156
|
}
|
|
153
157
|
//# sourceMappingURL=ConvaiClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConvaiClient.d.ts","sourceRoot":"","sources":["../../src/core/ConvaiClient.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,623 @@
|
|
|
1
|
+
import { Room, RoomEvent } from "livekit-client";
|
|
2
|
+
import { AudioManager } from "./AudioManager";
|
|
3
|
+
import { VideoManager } from "./VideoManager";
|
|
4
|
+
import { ScreenShareManager } from "./ScreenShareManager";
|
|
5
|
+
import { MessageHandler } from "./MessageHandler";
|
|
6
|
+
import { EventEmitter } from "./EventEmitter";
|
|
7
|
+
import { resolveSpeakerId } from "../utils/speakerManagement";
|
|
8
|
+
import { LatencyMonitor } from "../utils/LatencyMonitor";
|
|
9
|
+
/**
|
|
10
|
+
* Main Convai client class for managing AI voice assistant connections
|
|
11
|
+
* Provides complete interface for connecting to Convai's voice assistants,
|
|
12
|
+
* managing real-time audio/video conversations, and handling messages.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* import { ConvaiClient } from '@convai/web-sdk/core';
|
|
17
|
+
*
|
|
18
|
+
* // Recommended: Pass config to constructor
|
|
19
|
+
* const client = new ConvaiClient({
|
|
20
|
+
* apiKey: 'your-api-key',
|
|
21
|
+
* characterId: 'your-character-id',
|
|
22
|
+
* endUserId: 'user-uuid', // Optional: enables memory & analytics
|
|
23
|
+
* enableVideo: true,
|
|
24
|
+
* });
|
|
25
|
+
*
|
|
26
|
+
* // Listen for state changes
|
|
27
|
+
* client.on('stateChange', (state) => {
|
|
28
|
+
* console.log('State:', state);
|
|
29
|
+
* });
|
|
30
|
+
*
|
|
31
|
+
* // Connect (uses stored config from constructor)
|
|
32
|
+
* await client.connect();
|
|
33
|
+
*
|
|
34
|
+
* // Send a message
|
|
35
|
+
* client.sendUserTextMessage('Hello!');
|
|
36
|
+
*
|
|
37
|
+
* // Advanced: Override config or connect without constructor config
|
|
38
|
+
* await client.connect({ apiKey: 'different-key', characterId: 'different-id' });
|
|
39
|
+
*
|
|
40
|
+
* // Disconnect and reconnect
|
|
41
|
+
* await client.disconnect();
|
|
42
|
+
* await client.reconnect();
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export class ConvaiClient extends EventEmitter {
|
|
46
|
+
constructor(config) {
|
|
47
|
+
super();
|
|
48
|
+
this._connectionType = null;
|
|
49
|
+
this._apiKey = null;
|
|
50
|
+
this._characterId = null;
|
|
51
|
+
this._speakerId = null;
|
|
52
|
+
this._characterSessionId = "-1";
|
|
53
|
+
this._isBotReady = false;
|
|
54
|
+
this._participantSid = "";
|
|
55
|
+
this._storedConfig = null;
|
|
56
|
+
// Conversation session tracking
|
|
57
|
+
this._conversationSessionId = 0;
|
|
58
|
+
this._conversationStartTime = 0;
|
|
59
|
+
// Store config if provided
|
|
60
|
+
if (config) {
|
|
61
|
+
this._storedConfig = config;
|
|
62
|
+
}
|
|
63
|
+
// Initialize room
|
|
64
|
+
this._room = new Room();
|
|
65
|
+
// Initialize state
|
|
66
|
+
this._state = {
|
|
67
|
+
isConnected: false,
|
|
68
|
+
isConnecting: false,
|
|
69
|
+
isListening: false,
|
|
70
|
+
isThinking: false,
|
|
71
|
+
isSpeaking: false,
|
|
72
|
+
agentState: "disconnected",
|
|
73
|
+
};
|
|
74
|
+
// Default audio settings for optimal interruption handling
|
|
75
|
+
this._audioSettings = {
|
|
76
|
+
echoCancellation: true,
|
|
77
|
+
noiseSuppression: true,
|
|
78
|
+
autoGainControl: true,
|
|
79
|
+
sampleRate: 48000,
|
|
80
|
+
channelCount: 1,
|
|
81
|
+
};
|
|
82
|
+
// Initialize managers
|
|
83
|
+
this._audioManager = new AudioManager(this._room);
|
|
84
|
+
this._videoManager = new VideoManager(this._room);
|
|
85
|
+
this._screenShareManager = new ScreenShareManager(this._room);
|
|
86
|
+
this._latencyMonitor = new LatencyMonitor(false); // Disabled by default
|
|
87
|
+
this._messageHandler = new MessageHandler(this._room, this._latencyMonitor);
|
|
88
|
+
// Setup event listeners
|
|
89
|
+
this.setupEventListeners();
|
|
90
|
+
}
|
|
91
|
+
// Getters
|
|
92
|
+
get state() {
|
|
93
|
+
return { ...this._state };
|
|
94
|
+
}
|
|
95
|
+
get connectionType() {
|
|
96
|
+
return this._connectionType;
|
|
97
|
+
}
|
|
98
|
+
get apiKey() {
|
|
99
|
+
return this._apiKey;
|
|
100
|
+
}
|
|
101
|
+
get characterId() {
|
|
102
|
+
return this._characterId;
|
|
103
|
+
}
|
|
104
|
+
get speakerId() {
|
|
105
|
+
return this._speakerId;
|
|
106
|
+
}
|
|
107
|
+
get room() {
|
|
108
|
+
return this._room;
|
|
109
|
+
}
|
|
110
|
+
get chatMessages() {
|
|
111
|
+
return this._messageHandler.getChatMessages();
|
|
112
|
+
}
|
|
113
|
+
get userTranscription() {
|
|
114
|
+
return this._messageHandler.getUserTranscription();
|
|
115
|
+
}
|
|
116
|
+
get characterSessionId() {
|
|
117
|
+
return this._characterSessionId;
|
|
118
|
+
}
|
|
119
|
+
get isBotReady() {
|
|
120
|
+
return this._isBotReady;
|
|
121
|
+
}
|
|
122
|
+
get audioControls() {
|
|
123
|
+
return this._audioManager;
|
|
124
|
+
}
|
|
125
|
+
get videoControls() {
|
|
126
|
+
return this._videoManager;
|
|
127
|
+
}
|
|
128
|
+
get screenShareControls() {
|
|
129
|
+
return this._screenShareManager;
|
|
130
|
+
}
|
|
131
|
+
get latencyMonitor() {
|
|
132
|
+
return this._latencyMonitor;
|
|
133
|
+
}
|
|
134
|
+
get blendshapeQueue() {
|
|
135
|
+
return this._messageHandler.getBlendshapeQueue();
|
|
136
|
+
}
|
|
137
|
+
get conversationSessionId() {
|
|
138
|
+
return this._conversationSessionId;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Setup event listeners for room and managers
|
|
142
|
+
*/
|
|
143
|
+
setupEventListeners() {
|
|
144
|
+
// Room event listeners
|
|
145
|
+
this._room.on(RoomEvent.Disconnected, this.handleDisconnected.bind(this));
|
|
146
|
+
this._room.on(RoomEvent.ConnectionStateChanged, this.handleConnectionStateChanged.bind(this));
|
|
147
|
+
// Message handler events
|
|
148
|
+
this._messageHandler.on("botReady", () => {
|
|
149
|
+
this._isBotReady = true;
|
|
150
|
+
this.updateState({ isConnected: true });
|
|
151
|
+
this.emit("botReady");
|
|
152
|
+
});
|
|
153
|
+
this._messageHandler.on("messagesChange", (messages) => {
|
|
154
|
+
this.emit("message", messages[messages.length - 1]);
|
|
155
|
+
this.emit("messagesChange", messages);
|
|
156
|
+
});
|
|
157
|
+
this._messageHandler.on("userTranscriptionChange", (transcription) => {
|
|
158
|
+
this.emit("userTranscriptionChange", transcription);
|
|
159
|
+
});
|
|
160
|
+
this._messageHandler.on("speakingChange", (isSpeaking) => {
|
|
161
|
+
this.updateState({ isSpeaking });
|
|
162
|
+
this.emit("speakingChange", isSpeaking);
|
|
163
|
+
// End latency measurement when bot starts speaking
|
|
164
|
+
if (isSpeaking) {
|
|
165
|
+
this._latencyMonitor.endMeasurement();
|
|
166
|
+
}
|
|
167
|
+
else if (this._conversationSessionId > 0) {
|
|
168
|
+
// Bot stopped speaking - conversation end
|
|
169
|
+
const duration = ((Date.now() - this._conversationStartTime) /
|
|
170
|
+
1000).toFixed(2);
|
|
171
|
+
this.emit("conversationEnd", {
|
|
172
|
+
sessionId: this._conversationSessionId,
|
|
173
|
+
duration: parseFloat(duration),
|
|
174
|
+
timestamp: Date.now(),
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
this._messageHandler.on("botRespondingChange", (isResponding) => {
|
|
179
|
+
this.updateState({ isThinking: isResponding });
|
|
180
|
+
});
|
|
181
|
+
// Forward blendshapes events
|
|
182
|
+
this._messageHandler.on("blendshapes", (data) => {
|
|
183
|
+
this.emit("blendshapes", data);
|
|
184
|
+
});
|
|
185
|
+
// Forward blendshape stats event (conversation end marker)
|
|
186
|
+
this._messageHandler.on("blendshapeStatsReceived", (stats) => {
|
|
187
|
+
this.emit("blendshapeStatsReceived", stats);
|
|
188
|
+
});
|
|
189
|
+
// Forward latency monitor events
|
|
190
|
+
this._latencyMonitor.on("measurement", (measurement) => {
|
|
191
|
+
this.emit("latencyMeasurement", measurement);
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Handle room disconnection
|
|
196
|
+
*/
|
|
197
|
+
handleDisconnected() {
|
|
198
|
+
this.updateState({
|
|
199
|
+
isConnected: false,
|
|
200
|
+
isConnecting: false,
|
|
201
|
+
isSpeaking: false,
|
|
202
|
+
isThinking: false,
|
|
203
|
+
isListening: false,
|
|
204
|
+
});
|
|
205
|
+
this._isBotReady = false;
|
|
206
|
+
this._messageHandler.reset();
|
|
207
|
+
this.emit("disconnect");
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Handle connection state changes
|
|
211
|
+
*/
|
|
212
|
+
handleConnectionStateChanged(state) {
|
|
213
|
+
if (state === "disconnected") {
|
|
214
|
+
this.updateState({
|
|
215
|
+
isConnected: false,
|
|
216
|
+
isConnecting: false,
|
|
217
|
+
});
|
|
218
|
+
this._isBotReady = false;
|
|
219
|
+
this._messageHandler.reset();
|
|
220
|
+
}
|
|
221
|
+
else if (state === "connected") {
|
|
222
|
+
this.updateState({
|
|
223
|
+
isConnected: true,
|
|
224
|
+
isConnecting: false,
|
|
225
|
+
});
|
|
226
|
+
this._isBotReady = false; // Wait for bot-ready message
|
|
227
|
+
}
|
|
228
|
+
else if (state === "connecting") {
|
|
229
|
+
this.updateState({
|
|
230
|
+
isConnecting: true,
|
|
231
|
+
isConnected: false,
|
|
232
|
+
});
|
|
233
|
+
this._isBotReady = false;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Update state and emit changes
|
|
238
|
+
*/
|
|
239
|
+
updateState(updates) {
|
|
240
|
+
const oldState = { ...this._state };
|
|
241
|
+
this._state = { ...this._state, ...updates };
|
|
242
|
+
// Update agentState based on individual flags
|
|
243
|
+
if (!this._state.isConnected) {
|
|
244
|
+
this._state.agentState = "disconnected";
|
|
245
|
+
}
|
|
246
|
+
else if (this._state.isSpeaking) {
|
|
247
|
+
this._state.agentState = "speaking";
|
|
248
|
+
}
|
|
249
|
+
else if (this._state.isThinking) {
|
|
250
|
+
this._state.agentState = "thinking";
|
|
251
|
+
}
|
|
252
|
+
else if (this._state.isListening) {
|
|
253
|
+
this._state.agentState = "listening";
|
|
254
|
+
}
|
|
255
|
+
else {
|
|
256
|
+
this._state.agentState = "connected";
|
|
257
|
+
}
|
|
258
|
+
// Emit state change if changed
|
|
259
|
+
if (JSON.stringify(oldState) !== JSON.stringify(this._state)) {
|
|
260
|
+
this.emit("stateChange", this._state);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Connect to a Convai character
|
|
265
|
+
*/
|
|
266
|
+
async connect(config) {
|
|
267
|
+
// Use provided config or stored config
|
|
268
|
+
const finalConfig = config || this._storedConfig;
|
|
269
|
+
if (!finalConfig) {
|
|
270
|
+
throw new Error("No configuration provided. Pass config to connect() or store it in the client");
|
|
271
|
+
}
|
|
272
|
+
// Store config for reconnection
|
|
273
|
+
this._storedConfig = finalConfig;
|
|
274
|
+
// Add default URL if not provided
|
|
275
|
+
const configWithDefaults = {
|
|
276
|
+
url: "https://realtime-api.convai.com",
|
|
277
|
+
...finalConfig,
|
|
278
|
+
};
|
|
279
|
+
if (!configWithDefaults.apiKey || !configWithDefaults.characterId) {
|
|
280
|
+
throw new Error("apiKey and characterId are required");
|
|
281
|
+
}
|
|
282
|
+
this.updateState({ isConnecting: true });
|
|
283
|
+
try {
|
|
284
|
+
// Store connection config
|
|
285
|
+
this._apiKey = configWithDefaults.apiKey;
|
|
286
|
+
this._characterId = configWithDefaults.characterId;
|
|
287
|
+
// Resolve speaker ID based on endUserId
|
|
288
|
+
const resolvedSpeakerId = await resolveSpeakerId(configWithDefaults.endUserId, configWithDefaults.apiKey);
|
|
289
|
+
this._speakerId = resolvedSpeakerId;
|
|
290
|
+
// Determine connection type based on enableVideo
|
|
291
|
+
const connType = configWithDefaults.enableVideo ? "video" : "audio";
|
|
292
|
+
this._connectionType = connType;
|
|
293
|
+
// Prepare request body with required parameters
|
|
294
|
+
const requestBody = {
|
|
295
|
+
character_id: configWithDefaults.characterId,
|
|
296
|
+
...(resolvedSpeakerId && { speaker_id: resolvedSpeakerId }),
|
|
297
|
+
transport: "livekit",
|
|
298
|
+
connection_type: connType,
|
|
299
|
+
blendshape_provider: configWithDefaults.blendshapeProvider || "neurosync",
|
|
300
|
+
blendshape_config: {
|
|
301
|
+
enable_chunking: true,
|
|
302
|
+
chunk_size: 10,
|
|
303
|
+
format: configWithDefaults.blendshapeConfig?.format || "mha",
|
|
304
|
+
frames_buffer_duration: 2.5,
|
|
305
|
+
output_fps: 120,
|
|
306
|
+
},
|
|
307
|
+
llm_provider: "dynamic",
|
|
308
|
+
default_tts_enabled: configWithDefaults.ttsEnabled !== undefined
|
|
309
|
+
? configWithDefaults.ttsEnabled
|
|
310
|
+
: true,
|
|
311
|
+
...(this._characterSessionId &&
|
|
312
|
+
this._characterSessionId !== "-1" && {
|
|
313
|
+
character_session_id: this._characterSessionId,
|
|
314
|
+
}),
|
|
315
|
+
...(configWithDefaults.actionConfig && {
|
|
316
|
+
action_config: configWithDefaults.actionConfig,
|
|
317
|
+
}),
|
|
318
|
+
};
|
|
319
|
+
// Call Core Service API
|
|
320
|
+
const response = await fetch(`${configWithDefaults.url}/connect`, {
|
|
321
|
+
method: "POST",
|
|
322
|
+
headers: {
|
|
323
|
+
"x-api-key": configWithDefaults.apiKey,
|
|
324
|
+
"Content-Type": "application/json",
|
|
325
|
+
},
|
|
326
|
+
body: JSON.stringify(requestBody),
|
|
327
|
+
});
|
|
328
|
+
if (!response.ok) {
|
|
329
|
+
const errorText = await response.text();
|
|
330
|
+
let errorMessage = `HTTP error! status: ${response.status}`;
|
|
331
|
+
try {
|
|
332
|
+
const errorData = JSON.parse(errorText);
|
|
333
|
+
if (errorData.message) {
|
|
334
|
+
errorMessage = errorData.message;
|
|
335
|
+
}
|
|
336
|
+
else if (errorData.error) {
|
|
337
|
+
errorMessage = errorData.error;
|
|
338
|
+
}
|
|
339
|
+
else if (errorData.detail) {
|
|
340
|
+
errorMessage = errorData.detail;
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
catch (e) {
|
|
344
|
+
if (errorText) {
|
|
345
|
+
errorMessage = `${errorMessage}: ${errorText}`;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
throw new Error(errorMessage);
|
|
349
|
+
}
|
|
350
|
+
const connectionData = await response.json();
|
|
351
|
+
// Capture character_session_id from connection response
|
|
352
|
+
if (connectionData.character_session_id) {
|
|
353
|
+
this._characterSessionId = connectionData.character_session_id;
|
|
354
|
+
}
|
|
355
|
+
// Connect to LiveKit room
|
|
356
|
+
await this._room.connect(connectionData.room_url, connectionData.token, {
|
|
357
|
+
rtcConfig: {
|
|
358
|
+
iceTransportPolicy: "relay",
|
|
359
|
+
},
|
|
360
|
+
});
|
|
361
|
+
// Enable microphone only if startWithAudioOn is true (default: false)
|
|
362
|
+
// If false, microphone stays off until user enables it via audioControls
|
|
363
|
+
if (configWithDefaults.startWithAudioOn) {
|
|
364
|
+
await this._room.localParticipant.setMicrophoneEnabled(true, {
|
|
365
|
+
echoCancellation: this._audioSettings.echoCancellation,
|
|
366
|
+
noiseSuppression: this._audioSettings.noiseSuppression,
|
|
367
|
+
autoGainControl: this._audioSettings.autoGainControl,
|
|
368
|
+
sampleRate: this._audioSettings.sampleRate,
|
|
369
|
+
channelCount: this._audioSettings.channelCount,
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
// Enable camera only if enableVideo is true AND startWithVideoOn is true
|
|
373
|
+
if (configWithDefaults.enableVideo &&
|
|
374
|
+
configWithDefaults.startWithVideoOn) {
|
|
375
|
+
await this._room.localParticipant.setCameraEnabled(true);
|
|
376
|
+
}
|
|
377
|
+
// Ensure audio manager mirrors the actual microphone permission state
|
|
378
|
+
this._audioManager.syncStateFromRoom({ emit: true });
|
|
379
|
+
// Capture participant SID
|
|
380
|
+
this._participantSid = this._room.localParticipant.sid;
|
|
381
|
+
this.updateState({
|
|
382
|
+
isConnected: true,
|
|
383
|
+
isConnecting: false,
|
|
384
|
+
});
|
|
385
|
+
this.emit("connect");
|
|
386
|
+
}
|
|
387
|
+
catch (error) {
|
|
388
|
+
this.updateState({
|
|
389
|
+
isConnected: false,
|
|
390
|
+
isConnecting: false,
|
|
391
|
+
});
|
|
392
|
+
this.emit("error", error);
|
|
393
|
+
throw error;
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
/**
|
|
397
|
+
* Disconnect from the current character session
|
|
398
|
+
*/
|
|
399
|
+
async disconnect() {
|
|
400
|
+
if (this._room && this._room.state !== "disconnected") {
|
|
401
|
+
try {
|
|
402
|
+
await this._room.disconnect();
|
|
403
|
+
this.resetConnectionState();
|
|
404
|
+
}
|
|
405
|
+
catch (error) {
|
|
406
|
+
// Handle disconnect errors gracefully
|
|
407
|
+
this.resetConnectionState();
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
/**
|
|
412
|
+
* Reset connection state
|
|
413
|
+
*/
|
|
414
|
+
resetConnectionState() {
|
|
415
|
+
this.updateState({
|
|
416
|
+
isConnected: false,
|
|
417
|
+
isConnecting: false,
|
|
418
|
+
isSpeaking: false,
|
|
419
|
+
isThinking: false,
|
|
420
|
+
isListening: false,
|
|
421
|
+
});
|
|
422
|
+
this._isBotReady = false;
|
|
423
|
+
this._connectionType = null;
|
|
424
|
+
this._apiKey = null;
|
|
425
|
+
this._characterId = null;
|
|
426
|
+
this._speakerId = null;
|
|
427
|
+
this._messageHandler.reset();
|
|
428
|
+
this._audioManager.reset();
|
|
429
|
+
this._videoManager.reset();
|
|
430
|
+
this._screenShareManager.reset();
|
|
431
|
+
}
|
|
432
|
+
/**
|
|
433
|
+
* Reconnect - disconnect and connect again using stored config
|
|
434
|
+
*/
|
|
435
|
+
async reconnect() {
|
|
436
|
+
if (!this._storedConfig) {
|
|
437
|
+
throw new Error("No stored config available for reconnection");
|
|
438
|
+
}
|
|
439
|
+
await this.disconnect();
|
|
440
|
+
await this.connect(this._storedConfig);
|
|
441
|
+
}
|
|
442
|
+
/**
|
|
443
|
+
* Reset the session ID to start a new conversation
|
|
444
|
+
*/
|
|
445
|
+
resetSession() {
|
|
446
|
+
this._characterSessionId = "-1";
|
|
447
|
+
this._messageHandler.reset();
|
|
448
|
+
}
|
|
449
|
+
/**
|
|
450
|
+
* Send a text message to the character
|
|
451
|
+
*/
|
|
452
|
+
sendUserTextMessage(text) {
|
|
453
|
+
if (!this._room ||
|
|
454
|
+
this._room.state === "disconnected" ||
|
|
455
|
+
!this._room.localParticipant) {
|
|
456
|
+
return;
|
|
457
|
+
}
|
|
458
|
+
if (!text || !text.trim()) {
|
|
459
|
+
return;
|
|
460
|
+
}
|
|
461
|
+
try {
|
|
462
|
+
// Start new conversation session
|
|
463
|
+
this._conversationSessionId++;
|
|
464
|
+
this._conversationStartTime = Date.now();
|
|
465
|
+
console.log(`------conversation ${this._conversationSessionId}-------`);
|
|
466
|
+
// Emit conversation start event
|
|
467
|
+
this.emit("conversationStart", {
|
|
468
|
+
sessionId: this._conversationSessionId,
|
|
469
|
+
userMessage: text.trim(),
|
|
470
|
+
timestamp: this._conversationStartTime,
|
|
471
|
+
});
|
|
472
|
+
// Start latency measurement for text message
|
|
473
|
+
this._latencyMonitor.startMeasurement("text", text.trim());
|
|
474
|
+
const message = {
|
|
475
|
+
type: "user_text_message",
|
|
476
|
+
data: {
|
|
477
|
+
text: text.trim(),
|
|
478
|
+
participant_sid: this._participantSid || this._room.localParticipant.sid,
|
|
479
|
+
},
|
|
480
|
+
};
|
|
481
|
+
const encodedData = new TextEncoder().encode(JSON.stringify(message));
|
|
482
|
+
this._room.localParticipant.publishData(encodedData, {
|
|
483
|
+
reliable: true,
|
|
484
|
+
});
|
|
485
|
+
}
|
|
486
|
+
catch (error) {
|
|
487
|
+
// Cancel latency measurement on error
|
|
488
|
+
this._latencyMonitor.cancelMeasurement();
|
|
489
|
+
throw error;
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
/**
|
|
493
|
+
* Send a trigger message to invoke specific character actions
|
|
494
|
+
*/
|
|
495
|
+
sendTriggerMessage(triggerName, triggerMessage) {
|
|
496
|
+
if (this._room && this._room.localParticipant) {
|
|
497
|
+
const message = {
|
|
498
|
+
type: "trigger-message",
|
|
499
|
+
data: {
|
|
500
|
+
...(triggerName && { trigger_name: triggerName }),
|
|
501
|
+
...(triggerMessage && { trigger_message: triggerMessage }),
|
|
502
|
+
participant_sid: this._participantSid || this._room.localParticipant.sid,
|
|
503
|
+
},
|
|
504
|
+
};
|
|
505
|
+
const encodedData = new TextEncoder().encode(JSON.stringify(message));
|
|
506
|
+
this._room.localParticipant.publishData(encodedData, {
|
|
507
|
+
reliable: true,
|
|
508
|
+
});
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
/**
|
|
512
|
+
* Send an interrupt message to stop the bot's current response
|
|
513
|
+
*/
|
|
514
|
+
sendInterruptMessage() {
|
|
515
|
+
if (!this._room ||
|
|
516
|
+
this._room.state === "disconnected" ||
|
|
517
|
+
!this._room.localParticipant) {
|
|
518
|
+
return;
|
|
519
|
+
}
|
|
520
|
+
try {
|
|
521
|
+
const message = {
|
|
522
|
+
type: "interrupt-bot",
|
|
523
|
+
data: {
|
|
524
|
+
participant_sid: this._participantSid || this._room.localParticipant.sid,
|
|
525
|
+
},
|
|
526
|
+
};
|
|
527
|
+
const encodedData = new TextEncoder().encode(JSON.stringify(message));
|
|
528
|
+
this._room.localParticipant.publishData(encodedData, {
|
|
529
|
+
reliable: true,
|
|
530
|
+
});
|
|
531
|
+
}
|
|
532
|
+
catch (error) {
|
|
533
|
+
throw error;
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
/**
|
|
537
|
+
* Update template keys in the character's context
|
|
538
|
+
*/
|
|
539
|
+
updateTemplateKeys(templateKeys) {
|
|
540
|
+
if (this._room &&
|
|
541
|
+
this._room.localParticipant &&
|
|
542
|
+
Object.keys(templateKeys).length > 0) {
|
|
543
|
+
const message = {
|
|
544
|
+
type: "update-template-keys",
|
|
545
|
+
data: {
|
|
546
|
+
template_keys: templateKeys,
|
|
547
|
+
participant_sid: this._participantSid || this._room.localParticipant.sid,
|
|
548
|
+
},
|
|
549
|
+
};
|
|
550
|
+
const encodedData = new TextEncoder().encode(JSON.stringify(message));
|
|
551
|
+
this._room.localParticipant.publishData(encodedData, {
|
|
552
|
+
reliable: true,
|
|
553
|
+
});
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
/**
|
|
557
|
+
* Update dynamic information about the current context
|
|
558
|
+
*/
|
|
559
|
+
updateDynamicInfo(dynamicInfo) {
|
|
560
|
+
if (this._room && this._room.localParticipant && dynamicInfo.text?.trim()) {
|
|
561
|
+
const message = {
|
|
562
|
+
type: "update-dynamic-info",
|
|
563
|
+
data: {
|
|
564
|
+
dynamic_info: {
|
|
565
|
+
text: dynamicInfo.text.trim(),
|
|
566
|
+
},
|
|
567
|
+
participant_sid: this._participantSid || this._room.localParticipant.sid,
|
|
568
|
+
},
|
|
569
|
+
};
|
|
570
|
+
const encodedData = new TextEncoder().encode(JSON.stringify(message));
|
|
571
|
+
this._room.localParticipant.publishData(encodedData, {
|
|
572
|
+
reliable: true,
|
|
573
|
+
});
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
/**
|
|
577
|
+
* Toggle text-to-speech on or off
|
|
578
|
+
*/
|
|
579
|
+
toggleTts(enabled) {
|
|
580
|
+
if (!this._room ||
|
|
581
|
+
this._room.state === "disconnected" ||
|
|
582
|
+
!this._room.localParticipant) {
|
|
583
|
+
return;
|
|
584
|
+
}
|
|
585
|
+
try {
|
|
586
|
+
const message = {
|
|
587
|
+
type: "tts-toggle",
|
|
588
|
+
data: {
|
|
589
|
+
enabled: enabled,
|
|
590
|
+
},
|
|
591
|
+
};
|
|
592
|
+
const encodedData = new TextEncoder().encode(JSON.stringify(message));
|
|
593
|
+
this._room.localParticipant.publishData(encodedData, {
|
|
594
|
+
reliable: true,
|
|
595
|
+
});
|
|
596
|
+
}
|
|
597
|
+
catch (error) {
|
|
598
|
+
throw error;
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
// ========== Lipsync Post-Processing Methods ==========
|
|
602
|
+
/**
|
|
603
|
+
* Add a post-processor to modify blendshape frames during playback
|
|
604
|
+
* @param processor - Function that processes blendshape frames
|
|
605
|
+
*/
|
|
606
|
+
addLipsyncPostProcessor(processor) {
|
|
607
|
+
this.blendshapeQueue.addPostProcessor(processor);
|
|
608
|
+
}
|
|
609
|
+
/**
|
|
610
|
+
* Remove a post-processor
|
|
611
|
+
* @param processor - The processor function to remove
|
|
612
|
+
*/
|
|
613
|
+
removeLipsyncPostProcessor(processor) {
|
|
614
|
+
this.blendshapeQueue.removePostProcessor(processor);
|
|
615
|
+
}
|
|
616
|
+
/**
|
|
617
|
+
* Clear all post-processors
|
|
618
|
+
*/
|
|
619
|
+
clearLipsyncPostProcessors() {
|
|
620
|
+
this.blendshapeQueue.clearPostProcessors();
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
//# sourceMappingURL=ConvaiClient.js.map
|