@convai/web-sdk 0.0.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 +239 -0
- package/dist/components/RTCWidget.d.ts +56 -0
- package/dist/components/RTCWidget.d.ts.map +1 -0
- package/dist/components/RTCWidget.js +419 -0
- package/dist/components/RTCWidget.js.map +1 -0
- package/dist/components/index.d.ts +3 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/index.js +5 -0
- package/dist/components/index.js.map +1 -0
- package/dist/components/rtc-widget/components/AudioSettingsPanel.d.ts +10 -0
- package/dist/components/rtc-widget/components/AudioSettingsPanel.d.ts.map +1 -0
- package/dist/components/rtc-widget/components/AudioSettingsPanel.js +316 -0
- package/dist/components/rtc-widget/components/AudioSettingsPanel.js.map +1 -0
- package/dist/components/rtc-widget/components/ConviMessage.d.ts +10 -0
- package/dist/components/rtc-widget/components/ConviMessage.d.ts.map +1 -0
- package/dist/components/rtc-widget/components/ConviMessage.js +14 -0
- package/dist/components/rtc-widget/components/ConviMessage.js.map +1 -0
- package/dist/components/rtc-widget/components/FloatingVideo.d.ts +9 -0
- package/dist/components/rtc-widget/components/FloatingVideo.d.ts.map +1 -0
- package/dist/components/rtc-widget/components/FloatingVideo.js +122 -0
- package/dist/components/rtc-widget/components/FloatingVideo.js.map +1 -0
- package/dist/components/rtc-widget/components/MarkdownRenderer.d.ts +7 -0
- package/dist/components/rtc-widget/components/MarkdownRenderer.d.ts.map +1 -0
- package/dist/components/rtc-widget/components/MarkdownRenderer.js +68 -0
- package/dist/components/rtc-widget/components/MarkdownRenderer.js.map +1 -0
- package/dist/components/rtc-widget/components/MessageBubble.d.ts +10 -0
- package/dist/components/rtc-widget/components/MessageBubble.d.ts.map +1 -0
- package/dist/components/rtc-widget/components/MessageBubble.js +23 -0
- package/dist/components/rtc-widget/components/MessageBubble.js.map +1 -0
- package/dist/components/rtc-widget/components/MessageList.d.ts +11 -0
- package/dist/components/rtc-widget/components/MessageList.d.ts.map +1 -0
- package/dist/components/rtc-widget/components/MessageList.js +89 -0
- package/dist/components/rtc-widget/components/MessageList.js.map +1 -0
- package/dist/components/rtc-widget/components/UserMessage.d.ts +9 -0
- package/dist/components/rtc-widget/components/UserMessage.d.ts.map +1 -0
- package/dist/components/rtc-widget/components/UserMessage.js +15 -0
- package/dist/components/rtc-widget/components/UserMessage.js.map +1 -0
- package/dist/components/rtc-widget/components/conviComponents/ConviButton.d.ts +6 -0
- package/dist/components/rtc-widget/components/conviComponents/ConviButton.d.ts.map +1 -0
- package/dist/components/rtc-widget/components/conviComponents/ConviButton.js +15 -0
- package/dist/components/rtc-widget/components/conviComponents/ConviButton.js.map +1 -0
- package/dist/components/rtc-widget/components/conviComponents/ConviFooter.d.ts +25 -0
- package/dist/components/rtc-widget/components/conviComponents/ConviFooter.d.ts.map +1 -0
- package/dist/components/rtc-widget/components/conviComponents/ConviFooter.js +172 -0
- package/dist/components/rtc-widget/components/conviComponents/ConviFooter.js.map +1 -0
- package/dist/components/rtc-widget/components/conviComponents/ConviHeader.d.ts +17 -0
- package/dist/components/rtc-widget/components/conviComponents/ConviHeader.d.ts.map +1 -0
- package/dist/components/rtc-widget/components/conviComponents/ConviHeader.js +66 -0
- package/dist/components/rtc-widget/components/conviComponents/ConviHeader.js.map +1 -0
- package/dist/components/rtc-widget/components/conviComponents/SettingsTray.d.ts +12 -0
- package/dist/components/rtc-widget/components/conviComponents/SettingsTray.d.ts.map +1 -0
- package/dist/components/rtc-widget/components/conviComponents/SettingsTray.js +68 -0
- package/dist/components/rtc-widget/components/conviComponents/SettingsTray.js.map +1 -0
- package/dist/components/rtc-widget/components/conviComponents/VoiceModeOverlay.d.ts +8 -0
- package/dist/components/rtc-widget/components/conviComponents/VoiceModeOverlay.d.ts.map +1 -0
- package/dist/components/rtc-widget/components/conviComponents/VoiceModeOverlay.js +199 -0
- package/dist/components/rtc-widget/components/conviComponents/VoiceModeOverlay.js.map +1 -0
- package/dist/components/rtc-widget/components/conviComponents/index.d.ts +6 -0
- package/dist/components/rtc-widget/components/conviComponents/index.d.ts.map +1 -0
- package/dist/components/rtc-widget/components/conviComponents/index.js +6 -0
- package/dist/components/rtc-widget/components/conviComponents/index.js.map +1 -0
- package/dist/components/rtc-widget/components/index.d.ts +9 -0
- package/dist/components/rtc-widget/components/index.d.ts.map +1 -0
- package/dist/components/rtc-widget/components/index.js +13 -0
- package/dist/components/rtc-widget/components/index.js.map +1 -0
- package/dist/components/rtc-widget/index.d.ts +6 -0
- package/dist/components/rtc-widget/index.d.ts.map +1 -0
- package/dist/components/rtc-widget/index.js +7 -0
- package/dist/components/rtc-widget/index.js.map +1 -0
- package/dist/components/rtc-widget/styles/framerConfig.d.ts +116 -0
- package/dist/components/rtc-widget/styles/framerConfig.d.ts.map +1 -0
- package/dist/components/rtc-widget/styles/framerConfig.js +73 -0
- package/dist/components/rtc-widget/styles/framerConfig.js.map +1 -0
- package/dist/components/rtc-widget/styles/icons.d.ts +28 -0
- package/dist/components/rtc-widget/styles/icons.d.ts.map +1 -0
- package/dist/components/rtc-widget/styles/icons.js +257 -0
- package/dist/components/rtc-widget/styles/icons.js.map +1 -0
- package/dist/components/rtc-widget/styles/index.d.ts +6 -0
- package/dist/components/rtc-widget/styles/index.d.ts.map +1 -0
- package/dist/components/rtc-widget/styles/index.js +9 -0
- package/dist/components/rtc-widget/styles/index.js.map +1 -0
- package/dist/components/rtc-widget/styles/styledComponents.d.ts +90 -0
- package/dist/components/rtc-widget/styles/styledComponents.d.ts.map +1 -0
- package/dist/components/rtc-widget/styles/styledComponents.js +640 -0
- package/dist/components/rtc-widget/styles/styledComponents.js.map +1 -0
- package/dist/components/rtc-widget/styles/theme.d.ts +188 -0
- package/dist/components/rtc-widget/styles/theme.d.ts.map +1 -0
- package/dist/components/rtc-widget/styles/theme.js +290 -0
- package/dist/components/rtc-widget/styles/theme.js.map +1 -0
- package/dist/components/rtc-widget/types/index.d.ts +60 -0
- package/dist/components/rtc-widget/types/index.d.ts.map +1 -0
- package/dist/components/rtc-widget/types/index.js +2 -0
- package/dist/components/rtc-widget/types/index.js.map +1 -0
- package/dist/hooks/index.d.ts +13 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/index.js +14 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/useAudioControls.d.ts +41 -0
- package/dist/hooks/useAudioControls.d.ts.map +1 -0
- package/dist/hooks/useAudioControls.js +219 -0
- package/dist/hooks/useAudioControls.js.map +1 -0
- package/dist/hooks/useCharacterInfo.d.ts +17 -0
- package/dist/hooks/useCharacterInfo.d.ts.map +1 -0
- package/dist/hooks/useCharacterInfo.js +61 -0
- package/dist/hooks/useCharacterInfo.js.map +1 -0
- package/dist/hooks/useConvaiClient.d.ts +37 -0
- package/dist/hooks/useConvaiClient.d.ts.map +1 -0
- package/dist/hooks/useConvaiClient.js +348 -0
- package/dist/hooks/useConvaiClient.js.map +1 -0
- package/dist/hooks/useDynamicInfoUpdater.d.ts +33 -0
- package/dist/hooks/useDynamicInfoUpdater.d.ts.map +1 -0
- package/dist/hooks/useDynamicInfoUpdater.js +51 -0
- package/dist/hooks/useDynamicInfoUpdater.js.map +1 -0
- package/dist/hooks/useLocalCameraTrack.d.ts +22 -0
- package/dist/hooks/useLocalCameraTrack.d.ts.map +1 -0
- package/dist/hooks/useLocalCameraTrack.js +34 -0
- package/dist/hooks/useLocalCameraTrack.js.map +1 -0
- package/dist/hooks/useMessageHandler.d.ts +28 -0
- package/dist/hooks/useMessageHandler.d.ts.map +1 -0
- package/dist/hooks/useMessageHandler.js +317 -0
- package/dist/hooks/useMessageHandler.js.map +1 -0
- package/dist/hooks/useScreenShare.d.ts +45 -0
- package/dist/hooks/useScreenShare.d.ts.map +1 -0
- package/dist/hooks/useScreenShare.js +198 -0
- package/dist/hooks/useScreenShare.js.map +1 -0
- package/dist/hooks/useTemplateKeysUpdater.d.ts +35 -0
- package/dist/hooks/useTemplateKeysUpdater.d.ts.map +1 -0
- package/dist/hooks/useTemplateKeysUpdater.js +53 -0
- package/dist/hooks/useTemplateKeysUpdater.js.map +1 -0
- package/dist/hooks/useTriggerMessageSender.d.ts +28 -0
- package/dist/hooks/useTriggerMessageSender.d.ts.map +1 -0
- package/dist/hooks/useTriggerMessageSender.js +52 -0
- package/dist/hooks/useTriggerMessageSender.js.map +1 -0
- package/dist/hooks/useTtsToggle.d.ts +37 -0
- package/dist/hooks/useTtsToggle.d.ts.map +1 -0
- package/dist/hooks/useTtsToggle.js +65 -0
- package/dist/hooks/useTtsToggle.js.map +1 -0
- package/dist/hooks/useUserTextMessageSender.d.ts +28 -0
- package/dist/hooks/useUserTextMessageSender.d.ts.map +1 -0
- package/dist/hooks/useUserTextMessageSender.js +61 -0
- package/dist/hooks/useUserTextMessageSender.js.map +1 -0
- package/dist/hooks/useVideoControls.d.ts +39 -0
- package/dist/hooks/useVideoControls.d.ts.map +1 -0
- package/dist/hooks/useVideoControls.js +211 -0
- package/dist/hooks/useVideoControls.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/types/index.d.ts +225 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +2 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/logger.d.ts +27 -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/package.json +94 -0
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
import { useCallback } from "react";
|
|
2
|
+
import { RoomEvent } from "livekit-client";
|
|
3
|
+
import { logger } from "../utils/logger";
|
|
4
|
+
/**
|
|
5
|
+
* Hook for handling incoming messages from Convai.
|
|
6
|
+
*
|
|
7
|
+
* Sets up data message listeners to process various message types
|
|
8
|
+
* from the AI assistant and updates the chat message history.
|
|
9
|
+
*
|
|
10
|
+
* @param {Room} room - LiveKit room instance
|
|
11
|
+
* @param {Function} setChatMessages - Function to update chat messages state
|
|
12
|
+
* @returns {Function} Cleanup function to remove message listeners
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```tsx
|
|
16
|
+
* function ChatComponent() {
|
|
17
|
+
* const [chatMessages, setChatMessages] = useState([]);
|
|
18
|
+
* const cleanup = useMessageHandler(room, setChatMessages);
|
|
19
|
+
*
|
|
20
|
+
* useEffect(() => {
|
|
21
|
+
* return cleanup;
|
|
22
|
+
* }, []);
|
|
23
|
+
* }
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export const useMessageHandler = (room, setChatMessages, onUserTranscription, setIsBotResponding, isBotResponding, setIsSpeaking, onConnectionStateChange, setActivity, setIsBotReady) => {
|
|
27
|
+
const handleDataReceived = useCallback((payload, participant) => {
|
|
28
|
+
try {
|
|
29
|
+
// Decode bytes to string
|
|
30
|
+
const decoder = new TextDecoder();
|
|
31
|
+
const messageString = decoder.decode(payload);
|
|
32
|
+
// Parse JSON
|
|
33
|
+
const messageData = JSON.parse(messageString);
|
|
34
|
+
logger.log("📨 Data message received:", messageData);
|
|
35
|
+
// Extract and categorize messages for chat display
|
|
36
|
+
const timestamp = new Date().toISOString();
|
|
37
|
+
const messageId = `${messageData.type}-${Date.now()}-${Math.random()}`;
|
|
38
|
+
// Debug: Log all incoming messages to see what's being received
|
|
39
|
+
logger.log("%c📨 INCOMING MESSAGE%c", "background: #673ab7; color: white; padding: 2px 6px; border-radius: 3px; font-weight: bold;", {
|
|
40
|
+
type: messageData.type,
|
|
41
|
+
data: messageData.data,
|
|
42
|
+
message: messageData.message,
|
|
43
|
+
text: messageData.text,
|
|
44
|
+
content: messageData.content,
|
|
45
|
+
fullMessage: messageData,
|
|
46
|
+
});
|
|
47
|
+
// Handle different message types
|
|
48
|
+
switch (messageData.type) {
|
|
49
|
+
// User text messages - Skip these, only allow user-transcription
|
|
50
|
+
case "user_text_message":
|
|
51
|
+
case "user-llm-text":
|
|
52
|
+
case "text-input":
|
|
53
|
+
case "user-input":
|
|
54
|
+
case "text-message":
|
|
55
|
+
case "chat-message":
|
|
56
|
+
case "input-text":
|
|
57
|
+
case "message":
|
|
58
|
+
// Skip user text messages - only allow user-transcription
|
|
59
|
+
logger.log("%c🚫 SKIPPED USER TEXT%c %c" +
|
|
60
|
+
(messageData.data?.text ||
|
|
61
|
+
messageData.message ||
|
|
62
|
+
messageData.text ||
|
|
63
|
+
messageData.content ||
|
|
64
|
+
"unknown"), "background: #ff5722; color: white; padding: 2px 6px; border-radius: 3px; font-weight: bold;", "color: #ff5722; font-weight: bold;", "color: #f7f1e3;");
|
|
65
|
+
break;
|
|
66
|
+
// Bot Ready - Bot is ready, connection should be true
|
|
67
|
+
case "bot-ready":
|
|
68
|
+
logger.log("%c✅ BOT READY%c", "background: #4caf50; color: white; padding: 2px 6px; border-radius: 3px; font-weight: bold;");
|
|
69
|
+
// Set connection state to true when bot is ready
|
|
70
|
+
if (onConnectionStateChange) {
|
|
71
|
+
onConnectionStateChange(true);
|
|
72
|
+
}
|
|
73
|
+
// Set bot-ready state to true - bot can now receive messages
|
|
74
|
+
if (setIsBotReady) {
|
|
75
|
+
setIsBotReady(true);
|
|
76
|
+
}
|
|
77
|
+
// Update activity state
|
|
78
|
+
if (setActivity) {
|
|
79
|
+
setActivity("Connected");
|
|
80
|
+
}
|
|
81
|
+
break;
|
|
82
|
+
// Bot LLM Started - Begin streaming response
|
|
83
|
+
case "bot-llm-started":
|
|
84
|
+
logger.log("%c🤖 BOT RESPONSE STARTED%c", "background: #4caf50; color: white; padding: 2px 6px; border-radius: 3px; font-weight: bold;");
|
|
85
|
+
if (setIsBotResponding) {
|
|
86
|
+
setIsBotResponding(true);
|
|
87
|
+
}
|
|
88
|
+
// Add initial streaming message to chat
|
|
89
|
+
const streamingMessage = {
|
|
90
|
+
id: messageId,
|
|
91
|
+
type: "bot-llm-text",
|
|
92
|
+
content: "",
|
|
93
|
+
timestamp: timestamp,
|
|
94
|
+
isFinal: true,
|
|
95
|
+
};
|
|
96
|
+
setChatMessages((prev) => [...prev, streamingMessage]);
|
|
97
|
+
break;
|
|
98
|
+
// Bot LLM Text Messages - Streaming chunks
|
|
99
|
+
case "bot-llm-text":
|
|
100
|
+
if (messageData.data?.text) {
|
|
101
|
+
const newChunk = messageData.data.text;
|
|
102
|
+
logger.log("%c🤖 BOT CHUNK%c %c" + newChunk, "background: #45b7d1; color: white; padding: 2px 6px; border-radius: 3px; font-weight: bold;", "color: #45b7d1; font-weight: bold;", "color: #f7f1e3;");
|
|
103
|
+
// Update the streaming message in chat
|
|
104
|
+
setChatMessages((prevMessages) => {
|
|
105
|
+
const lastMessage = prevMessages[prevMessages.length - 1];
|
|
106
|
+
if (lastMessage && lastMessage.isFinal) {
|
|
107
|
+
return [
|
|
108
|
+
...prevMessages.slice(0, -1),
|
|
109
|
+
{ ...lastMessage, content: lastMessage.content + newChunk }
|
|
110
|
+
];
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
// If no streaming message exists yet, create one
|
|
114
|
+
const streamingMessage = {
|
|
115
|
+
id: `${messageData.type}-${Date.now()}-${Math.random()}`,
|
|
116
|
+
type: "bot-llm-text",
|
|
117
|
+
content: newChunk,
|
|
118
|
+
timestamp: new Date().toISOString(),
|
|
119
|
+
isFinal: true,
|
|
120
|
+
};
|
|
121
|
+
return [...prevMessages, streamingMessage];
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
break;
|
|
126
|
+
// Bot LLM Stopped - Complete streaming response
|
|
127
|
+
case "bot-llm-stopped":
|
|
128
|
+
// Get the most up-to-date content from the current message in chat
|
|
129
|
+
setChatMessages((prevMessages) => {
|
|
130
|
+
const lastMessage = prevMessages[prevMessages.length - 1];
|
|
131
|
+
if (lastMessage && lastMessage.isFinal) {
|
|
132
|
+
const finalContent = lastMessage.content;
|
|
133
|
+
logger.log("%c🤖 BOT RESPONSE COMPLETED%c %c" + finalContent, "background: #ff9800; color: white; padding: 2px 6px; border-radius: 3px; font-weight: bold;", "color: #ff9800; font-weight: bold;", "color: #f7f1e3;");
|
|
134
|
+
return [
|
|
135
|
+
...prevMessages.slice(0, -1),
|
|
136
|
+
{ ...lastMessage, content: finalContent, isFinal: false }
|
|
137
|
+
];
|
|
138
|
+
}
|
|
139
|
+
return prevMessages;
|
|
140
|
+
});
|
|
141
|
+
// Clear streaming state
|
|
142
|
+
if (setIsBotResponding) {
|
|
143
|
+
setIsBotResponding(false);
|
|
144
|
+
}
|
|
145
|
+
break;
|
|
146
|
+
// User Transcription Messages
|
|
147
|
+
case "user-transcription":
|
|
148
|
+
if (messageData.data?.text) {
|
|
149
|
+
const messageContent = messageData.data.text;
|
|
150
|
+
if (messageData.data?.final) {
|
|
151
|
+
// Final transcription - add to chat messages
|
|
152
|
+
// Check if this transcription already exists to prevent duplicates
|
|
153
|
+
setChatMessages((prev) => {
|
|
154
|
+
const alreadyExists = prev.some((msg) => msg.type === "user-transcription" &&
|
|
155
|
+
msg.content.toLowerCase().trim() ===
|
|
156
|
+
messageContent.toLowerCase().trim());
|
|
157
|
+
if (alreadyExists) {
|
|
158
|
+
logger.log("%c🔄 DUPLICATE SKIPPED%c UserTranscription: %c" +
|
|
159
|
+
messageContent, "background: #ff6b6b; color: white; padding: 2px 6px; border-radius: 3px; font-weight: bold;", "color: #ff6b6b; font-weight: bold;", "color: #ffa726; font-weight: bold;");
|
|
160
|
+
return prev;
|
|
161
|
+
}
|
|
162
|
+
const userMessage = {
|
|
163
|
+
id: messageId,
|
|
164
|
+
type: "user-transcription",
|
|
165
|
+
content: messageContent,
|
|
166
|
+
timestamp: timestamp,
|
|
167
|
+
};
|
|
168
|
+
logger.log("%c🎤 USER TRANSCRIPTION (FINAL)%c %c" + messageContent, "background: #ffa726; color: white; padding: 2px 6px; border-radius: 3px; font-weight: bold;", "color: #ffa726; font-weight: bold;", "color: #f7f1e3;");
|
|
169
|
+
return [...prev, userMessage];
|
|
170
|
+
});
|
|
171
|
+
// Clear live transcription when final
|
|
172
|
+
if (onUserTranscription) {
|
|
173
|
+
onUserTranscription('');
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
// Non-final transcription - show in input field
|
|
178
|
+
if (onUserTranscription) {
|
|
179
|
+
onUserTranscription(messageContent);
|
|
180
|
+
logger.log("%c🎤 LIVE TRANSCRIPTION%c %c" + messageContent, "background: #4caf50; color: white; padding: 2px 6px; border-radius: 3px; font-weight: bold;", "color: #4caf50; font-weight: bold;", "color: #f7f1e3;");
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
break;
|
|
185
|
+
// Bot Emotion Messages
|
|
186
|
+
case "bot-emotion":
|
|
187
|
+
if (messageData.data?.emotion) {
|
|
188
|
+
const emotionMessage = {
|
|
189
|
+
id: messageId,
|
|
190
|
+
type: "bot-emotion",
|
|
191
|
+
content: `${messageData.data.emotion} (scale: ${messageData.data.scale || 1})`,
|
|
192
|
+
timestamp,
|
|
193
|
+
};
|
|
194
|
+
setChatMessages((prev) => [...prev, emotionMessage]);
|
|
195
|
+
logger.log("%c😊 CONVAI EMOTION%c %c" +
|
|
196
|
+
messageData.data.emotion +
|
|
197
|
+
"%c (scale: %c" +
|
|
198
|
+
(messageData.data.scale || 1) +
|
|
199
|
+
"%c)", "background: #e91e63; color: white; padding: 2px 6px; border-radius: 3px; font-weight: bold;", "color: #e91e63; font-weight: bold;", "color: #f7f1e3; font-weight: bold;", "color: #e91e63;", "color: #ffeb3b; font-weight: bold;", "color: #e91e63;");
|
|
200
|
+
}
|
|
201
|
+
break;
|
|
202
|
+
// Bot Started Speaking
|
|
203
|
+
case "bot-started-speaking":
|
|
204
|
+
logger.log("%c🔊 BOT STARTED SPEAKING%c", "background: #10b981; color: white; padding: 2px 6px; border-radius: 3px; font-weight: bold;");
|
|
205
|
+
if (setIsSpeaking) {
|
|
206
|
+
setIsSpeaking(true);
|
|
207
|
+
}
|
|
208
|
+
break;
|
|
209
|
+
// Bot Stopped Speaking
|
|
210
|
+
case "bot-stopped-speaking":
|
|
211
|
+
logger.log("%c🔇 BOT STOPPED SPEAKING%c", "background: #6b7280; color: white; padding: 2px 6px; border-radius: 3px; font-weight: bold;");
|
|
212
|
+
if (setIsSpeaking) {
|
|
213
|
+
setIsSpeaking(false);
|
|
214
|
+
}
|
|
215
|
+
break;
|
|
216
|
+
// Action Response Messages
|
|
217
|
+
case "action-response":
|
|
218
|
+
if (messageData.data?.actions) {
|
|
219
|
+
const actionMessage = {
|
|
220
|
+
id: messageId,
|
|
221
|
+
type: "action",
|
|
222
|
+
content: `Actions: ${messageData.data.actions.join(", ")}`,
|
|
223
|
+
timestamp,
|
|
224
|
+
};
|
|
225
|
+
setChatMessages((prev) => [...prev, actionMessage]);
|
|
226
|
+
logger.log("%c🎭 ACTION RESPONSE%c %c" +
|
|
227
|
+
messageData.data.actions.join(", "), "background: #9c27b0; color: white; padding: 2px 6px; border-radius: 3px; font-weight: bold;", "color: #9c27b0; font-weight: bold;", "color: #f7f1e3;");
|
|
228
|
+
}
|
|
229
|
+
break;
|
|
230
|
+
// Behavior Tree Response Messages
|
|
231
|
+
case "behavior-tree-response":
|
|
232
|
+
if (messageData.data?.narrative_section_id) {
|
|
233
|
+
const behaviorMessage = {
|
|
234
|
+
id: messageId,
|
|
235
|
+
type: "behavior-tree",
|
|
236
|
+
content: `Narrative Section: ${messageData.data.narrative_section_id}`,
|
|
237
|
+
timestamp,
|
|
238
|
+
};
|
|
239
|
+
setChatMessages((prev) => [...prev, behaviorMessage]);
|
|
240
|
+
logger.log("%c🌳 BEHAVIOR TREE%c %c" +
|
|
241
|
+
messageData.data.narrative_section_id, "background: #4caf50; color: white; padding: 2px 6px; border-radius: 3px; font-weight: bold;", "color: #4caf50; font-weight: bold;", "color: #f7f1e3;");
|
|
242
|
+
logger.log("%c🌳 BT DETAILS%c", "background: #4caf50; color: white; padding: 2px 6px; border-radius: 3px; font-weight: bold;", {
|
|
243
|
+
narrativeSection: messageData.data.narrative_section_id,
|
|
244
|
+
btCode: messageData.data.bt_code,
|
|
245
|
+
btConstants: messageData.data.bt_constants,
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
break;
|
|
249
|
+
// Moderation Response Messages
|
|
250
|
+
case "moderation-response":
|
|
251
|
+
logger.log("%c🛡️ MODERATION%c %c" + (messageData.data?.result || "unknown"), "background: #ff9800; color: white; padding: 2px 6px; border-radius: 3px; font-weight: bold;", "color: #ff9800; font-weight: bold;", "color: #f7f1e3;");
|
|
252
|
+
logger.log("%c🛡️ MODERATION DETAILS%c", "background: #ff9800; color: white; padding: 2px 6px; border-radius: 3px; font-weight: bold;", {
|
|
253
|
+
result: messageData.data?.result,
|
|
254
|
+
userInput: messageData.data?.user_input,
|
|
255
|
+
reason: messageData.data?.reason,
|
|
256
|
+
});
|
|
257
|
+
break;
|
|
258
|
+
// Trigger Messages
|
|
259
|
+
case "trigger-message":
|
|
260
|
+
logger.log("%c🎯 TRIGGER MESSAGE%c", "background: #2196f3; color: white; padding: 2px 6px; border-radius: 3px; font-weight: bold;", messageData.data);
|
|
261
|
+
break;
|
|
262
|
+
// Template Keys Updates
|
|
263
|
+
case "update-template-keys":
|
|
264
|
+
logger.log("%c🔑 TEMPLATE KEYS%c", "background: #607d8b; color: white; padding: 2px 6px; border-radius: 3px; font-weight: bold;", messageData.data);
|
|
265
|
+
break;
|
|
266
|
+
// Dynamic Info Updates
|
|
267
|
+
case "update-dynamic-info":
|
|
268
|
+
logger.log("%c🔄 DYNAMIC INFO%c", "background: #795548; color: white; padding: 2px 6px; border-radius: 3px; font-weight: bold;", messageData.data);
|
|
269
|
+
break;
|
|
270
|
+
}
|
|
271
|
+
// Log any unhandled message types
|
|
272
|
+
if (![
|
|
273
|
+
"user_text_message",
|
|
274
|
+
"user-llm-text",
|
|
275
|
+
"text-input",
|
|
276
|
+
"user-input",
|
|
277
|
+
"text-message",
|
|
278
|
+
"chat-message",
|
|
279
|
+
"input-text",
|
|
280
|
+
"message",
|
|
281
|
+
"bot-llm-text",
|
|
282
|
+
"bot-llm-started",
|
|
283
|
+
"bot-llm-stopped",
|
|
284
|
+
"user-transcription",
|
|
285
|
+
"bot-emotion",
|
|
286
|
+
"bot-started-speaking",
|
|
287
|
+
"bot-stopped-speaking",
|
|
288
|
+
"action-response",
|
|
289
|
+
"behavior-tree-response",
|
|
290
|
+
"moderation-response",
|
|
291
|
+
"trigger-message",
|
|
292
|
+
"update-template-keys",
|
|
293
|
+
"update-dynamic-info",
|
|
294
|
+
].includes(messageData.type)) {
|
|
295
|
+
logger.log("%c🔍 UNHANDLED MESSAGE TYPE%c %c" + messageData.type, "background: #f44336; color: white; padding: 2px 6px; border-radius: 3px; font-weight: bold;", "color: #f44336; font-weight: bold;", "color: #f7f1e3;");
|
|
296
|
+
logger.log("%c🔍 UNHANDLED DATA%c", "background: #f44336; color: white; padding: 2px 6px; border-radius: 3px; font-weight: bold;", messageData);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
catch (error) {
|
|
300
|
+
logger.error("Failed to parse data message:", error);
|
|
301
|
+
}
|
|
302
|
+
}, [setChatMessages, onUserTranscription, setIsBotResponding, isBotResponding, setIsSpeaking, onConnectionStateChange, setActivity]);
|
|
303
|
+
const setupMessageListener = useCallback(() => {
|
|
304
|
+
if (!room)
|
|
305
|
+
return;
|
|
306
|
+
// Listen for data received events
|
|
307
|
+
room.on(RoomEvent.DataReceived, handleDataReceived);
|
|
308
|
+
// Return cleanup function
|
|
309
|
+
return () => {
|
|
310
|
+
room.off(RoomEvent.DataReceived, handleDataReceived);
|
|
311
|
+
};
|
|
312
|
+
}, [room, handleDataReceived]);
|
|
313
|
+
return {
|
|
314
|
+
setupMessageListener,
|
|
315
|
+
};
|
|
316
|
+
};
|
|
317
|
+
//# sourceMappingURL=useMessageHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useMessageHandler.js","sourceRoot":"","sources":["../../src/hooks/useMessageHandler.ts"],"names":[],"mappings":"AAAA,OAAO,E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,eAAe,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,eAAe,EAAE,aAAa,EAAE,uBAAuB,EAAE,WAAW,CAAC,CACjI,CAAC;IAEF,MAAM,oBAAoB,GAAG,WAAW,CAAC,GAAG,EAAE;QAC5C,IAAI,CAAC,IAAI;YAAE,OAAO;QAElB,kCAAkC;QAClC,IAAI,CAAC,EAAE,CAAC,SAAS,CAAC,YAAY,EAAE,kBAAkB,CAAC,CAAC;QAEpD,0BAA0B;QAC1B,OAAO,GAAG,EAAE;YACV,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,YAAY,EAAE,kBAAkB,CAAC,CAAC;QACvD,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,IAAI,EAAE,kBAAkB,CAAC,CAAC,CAAC;IAE/B,OAAO;QACL,oBAAoB;KACrB,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Room } from "livekit-client";
|
|
2
|
+
export interface ScreenShareControls {
|
|
3
|
+
isScreenShareEnabled: boolean;
|
|
4
|
+
isScreenShareActive: boolean;
|
|
5
|
+
enableScreenShare: () => Promise<void>;
|
|
6
|
+
disableScreenShare: () => Promise<void>;
|
|
7
|
+
toggleScreenShare: () => Promise<void>;
|
|
8
|
+
enableScreenShareWithAudio: () => Promise<void>;
|
|
9
|
+
getScreenShareTracks: () => Promise<any[]>;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Hook for managing screen sharing controls in LiveKit.
|
|
13
|
+
*
|
|
14
|
+
* Provides methods to enable/disable screen sharing, manage screen share state,
|
|
15
|
+
* and handle screen sharing with audio support.
|
|
16
|
+
*
|
|
17
|
+
* Features:
|
|
18
|
+
* - Includes current tab in screen share options (selfBrowserSurface: "include")
|
|
19
|
+
* - Supports surface switching during screen share
|
|
20
|
+
* - Supports system audio capture
|
|
21
|
+
*
|
|
22
|
+
* Note: By default, browsers exclude the current tab from screen share to prevent
|
|
23
|
+
* infinite recursion ("hall of mirrors" effect). This hook enables it by setting
|
|
24
|
+
* selfBrowserSurface: "include", but be aware this may cause visual feedback loops.
|
|
25
|
+
*
|
|
26
|
+
* @param {Room | null} room - LiveKit room instance
|
|
27
|
+
* @returns {ScreenShareControls} Object containing screen share control methods and state
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```tsx
|
|
31
|
+
* function ScreenShareControls() {
|
|
32
|
+
* const screenShareControls = useScreenShare(room);
|
|
33
|
+
*
|
|
34
|
+
* return (
|
|
35
|
+
* <div>
|
|
36
|
+
* <button onClick={screenShareControls.toggleScreenShare}>
|
|
37
|
+
* {screenShareControls.isScreenShareEnabled ? 'Stop Sharing' : 'Share Screen'}
|
|
38
|
+
* </button>
|
|
39
|
+
* </div>
|
|
40
|
+
* );
|
|
41
|
+
* }
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export declare const useScreenShare: (room: Room | null) => ScreenShareControls;
|
|
45
|
+
//# sourceMappingURL=useScreenShare.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useScreenShare.d.ts","sourceRoot":"","sources":["../../src/hooks/useScreenShare.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAGtC,MAAM,WAAW,mBAAmB;IAElC,oBAAoB,EAAE,OAAO,CAAC;IAC9B,mBAAmB,EAAE,OAAO,CAAC;IAG7B,iBAAiB,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IACvC,kBAAkB,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IACxC,iBAAiB,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAGvC,0BAA0B,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAGhD,oBAAoB,EAAE,MAAM,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;CAC5C;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,eAAO,MAAM,cAAc,GAAI,MAAM,IAAI,GAAG,IAAI,KAAG,mBAsLlD,CAAC"}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { useCallback, useState, useEffect } from "react";
|
|
2
|
+
import { logger } from "../utils/logger";
|
|
3
|
+
/**
|
|
4
|
+
* Hook for managing screen sharing controls in LiveKit.
|
|
5
|
+
*
|
|
6
|
+
* Provides methods to enable/disable screen sharing, manage screen share state,
|
|
7
|
+
* and handle screen sharing with audio support.
|
|
8
|
+
*
|
|
9
|
+
* Features:
|
|
10
|
+
* - Includes current tab in screen share options (selfBrowserSurface: "include")
|
|
11
|
+
* - Supports surface switching during screen share
|
|
12
|
+
* - Supports system audio capture
|
|
13
|
+
*
|
|
14
|
+
* Note: By default, browsers exclude the current tab from screen share to prevent
|
|
15
|
+
* infinite recursion ("hall of mirrors" effect). This hook enables it by setting
|
|
16
|
+
* selfBrowserSurface: "include", but be aware this may cause visual feedback loops.
|
|
17
|
+
*
|
|
18
|
+
* @param {Room | null} room - LiveKit room instance
|
|
19
|
+
* @returns {ScreenShareControls} Object containing screen share control methods and state
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```tsx
|
|
23
|
+
* function ScreenShareControls() {
|
|
24
|
+
* const screenShareControls = useScreenShare(room);
|
|
25
|
+
*
|
|
26
|
+
* return (
|
|
27
|
+
* <div>
|
|
28
|
+
* <button onClick={screenShareControls.toggleScreenShare}>
|
|
29
|
+
* {screenShareControls.isScreenShareEnabled ? 'Stop Sharing' : 'Share Screen'}
|
|
30
|
+
* </button>
|
|
31
|
+
* </div>
|
|
32
|
+
* );
|
|
33
|
+
* }
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export const useScreenShare = (room) => {
|
|
37
|
+
const [isScreenShareEnabled, setIsScreenShareEnabled] = useState(false);
|
|
38
|
+
const [isScreenShareActive, setIsScreenShareActive] = useState(false);
|
|
39
|
+
// Update screen share state when room changes
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
if (!room) {
|
|
42
|
+
setIsScreenShareEnabled(false);
|
|
43
|
+
setIsScreenShareActive(false);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const localParticipant = room.localParticipant;
|
|
47
|
+
// Set initial state
|
|
48
|
+
setIsScreenShareEnabled(localParticipant.isScreenShareEnabled);
|
|
49
|
+
setIsScreenShareActive(localParticipant.isScreenShareEnabled);
|
|
50
|
+
// Listen for screen share state changes
|
|
51
|
+
const handleTrackPublished = (track) => {
|
|
52
|
+
if (track.source === 'screen_share') {
|
|
53
|
+
setIsScreenShareActive(true);
|
|
54
|
+
logger.log("🖥️ Screen share started");
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
const handleTrackUnpublished = (track) => {
|
|
58
|
+
if (track.source === 'screen_share') {
|
|
59
|
+
setIsScreenShareActive(false);
|
|
60
|
+
logger.log("🖥️ Screen share stopped");
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
const handleTrackMuted = (track) => {
|
|
64
|
+
if (track.source === 'screen_share') {
|
|
65
|
+
setIsScreenShareActive(false);
|
|
66
|
+
logger.log("🖥️ Screen share muted");
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
const handleTrackUnmuted = (track) => {
|
|
70
|
+
if (track.source === 'screen_share') {
|
|
71
|
+
setIsScreenShareActive(true);
|
|
72
|
+
logger.log("🖥️ Screen share unmuted");
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
// Subscribe to events
|
|
76
|
+
localParticipant.on('trackPublished', handleTrackPublished);
|
|
77
|
+
localParticipant.on('trackUnpublished', handleTrackUnpublished);
|
|
78
|
+
localParticipant.on('trackMuted', handleTrackMuted);
|
|
79
|
+
localParticipant.on('trackUnmuted', handleTrackUnmuted);
|
|
80
|
+
return () => {
|
|
81
|
+
localParticipant.off('trackPublished', handleTrackPublished);
|
|
82
|
+
localParticipant.off('trackUnpublished', handleTrackUnpublished);
|
|
83
|
+
localParticipant.off('trackMuted', handleTrackMuted);
|
|
84
|
+
localParticipant.off('trackUnmuted', handleTrackUnmuted);
|
|
85
|
+
};
|
|
86
|
+
}, [room]);
|
|
87
|
+
// Enable screen share
|
|
88
|
+
const enableScreenShare = useCallback(async () => {
|
|
89
|
+
if (!room) {
|
|
90
|
+
logger.warn("Cannot enable screen share: no room connection");
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
try {
|
|
94
|
+
// Use setScreenShareEnabled with options to include current tab
|
|
95
|
+
await room.localParticipant.setScreenShareEnabled(true, {
|
|
96
|
+
// @ts-ignore - selfBrowserSurface is a valid Chrome option but may not be in types
|
|
97
|
+
selfBrowserSurface: "include",
|
|
98
|
+
surfaceSwitching: "include",
|
|
99
|
+
systemAudio: "include",
|
|
100
|
+
});
|
|
101
|
+
setIsScreenShareEnabled(true);
|
|
102
|
+
logger.log("🖥️ Screen share enabled successfully");
|
|
103
|
+
}
|
|
104
|
+
catch (error) {
|
|
105
|
+
logger.error("Failed to enable screen share:", error);
|
|
106
|
+
throw error;
|
|
107
|
+
}
|
|
108
|
+
}, [room]);
|
|
109
|
+
// Disable screen share
|
|
110
|
+
const disableScreenShare = useCallback(async () => {
|
|
111
|
+
if (!room) {
|
|
112
|
+
logger.warn("Cannot disable screen share: no room connection");
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
try {
|
|
116
|
+
await room.localParticipant.setScreenShareEnabled(false);
|
|
117
|
+
setIsScreenShareEnabled(false);
|
|
118
|
+
logger.log("🖥️ Screen share disabled successfully");
|
|
119
|
+
}
|
|
120
|
+
catch (error) {
|
|
121
|
+
logger.error("Failed to disable screen share:", error);
|
|
122
|
+
throw error;
|
|
123
|
+
}
|
|
124
|
+
}, [room]);
|
|
125
|
+
// Toggle screen share
|
|
126
|
+
const toggleScreenShare = useCallback(async () => {
|
|
127
|
+
if (isScreenShareEnabled) {
|
|
128
|
+
await disableScreenShare();
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
await enableScreenShare();
|
|
132
|
+
}
|
|
133
|
+
}, [isScreenShareEnabled, enableScreenShare, disableScreenShare]);
|
|
134
|
+
// Enable screen share with audio
|
|
135
|
+
const enableScreenShareWithAudio = useCallback(async () => {
|
|
136
|
+
if (!room) {
|
|
137
|
+
logger.warn("Cannot enable screen share with audio: no room connection");
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
try {
|
|
141
|
+
// Create screen tracks with audio enabled and include current tab
|
|
142
|
+
const tracks = await room.localParticipant.createScreenTracks({
|
|
143
|
+
audio: true,
|
|
144
|
+
// @ts-ignore - selfBrowserSurface is a valid Chrome option but may not be in types
|
|
145
|
+
selfBrowserSurface: "include",
|
|
146
|
+
surfaceSwitching: "include",
|
|
147
|
+
systemAudio: "include",
|
|
148
|
+
});
|
|
149
|
+
// Publish each track
|
|
150
|
+
tracks.forEach((track) => {
|
|
151
|
+
room.localParticipant.publishTrack(track);
|
|
152
|
+
});
|
|
153
|
+
setIsScreenShareEnabled(true);
|
|
154
|
+
logger.log("🖥️ Screen share with audio enabled successfully");
|
|
155
|
+
}
|
|
156
|
+
catch (error) {
|
|
157
|
+
logger.error("Failed to enable screen share with audio:", error);
|
|
158
|
+
throw error;
|
|
159
|
+
}
|
|
160
|
+
}, [room]);
|
|
161
|
+
// Get screen share tracks
|
|
162
|
+
const getScreenShareTracks = useCallback(async () => {
|
|
163
|
+
if (!room) {
|
|
164
|
+
logger.warn("Cannot get screen share tracks: no room connection");
|
|
165
|
+
return [];
|
|
166
|
+
}
|
|
167
|
+
try {
|
|
168
|
+
const localParticipant = room.localParticipant;
|
|
169
|
+
const screenShareTracks = [];
|
|
170
|
+
// Get all published tracks
|
|
171
|
+
localParticipant.trackPublications.forEach((publication) => {
|
|
172
|
+
if (publication.source === 'screen_share' && publication.track) {
|
|
173
|
+
screenShareTracks.push(publication.track);
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
logger.log("🖥️ Screen share tracks:", screenShareTracks);
|
|
177
|
+
return screenShareTracks;
|
|
178
|
+
}
|
|
179
|
+
catch (error) {
|
|
180
|
+
logger.error("Failed to get screen share tracks:", error);
|
|
181
|
+
throw error;
|
|
182
|
+
}
|
|
183
|
+
}, [room]);
|
|
184
|
+
return {
|
|
185
|
+
// Screen share state
|
|
186
|
+
isScreenShareEnabled,
|
|
187
|
+
isScreenShareActive,
|
|
188
|
+
// Screen share controls
|
|
189
|
+
enableScreenShare,
|
|
190
|
+
disableScreenShare,
|
|
191
|
+
toggleScreenShare,
|
|
192
|
+
// Screen share with audio
|
|
193
|
+
enableScreenShareWithAudio,
|
|
194
|
+
// Screen share settings
|
|
195
|
+
getScreenShareTracks,
|
|
196
|
+
};
|
|
197
|
+
};
|
|
198
|
+
//# sourceMappingURL=useScreenShare.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useScreenShare.js","sourceRoot":"","sources":["../../src/hooks/useScreenShare.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEzD,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAmBzC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,IAAiB,EAAuB,EAAE;IACvE,MAAM,CAAC,oBAAoB,EAAE,uBAAuB,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IACxE,MAAM,CAAC,mBAAmB,EAAE,sBAAsB,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAEtE,8CAA8C;IAC9C,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,uBAAuB,CAAC,KAAK,CAAC,CAAC;YAC/B,sBAAsB,CAAC,KAAK,CAAC,CAAC;YAC9B,OAAO;QACT,CAAC;QAED,MAAM,gBAAgB,GAAG,IAAI,CAAC,gBAAgB,CAA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AoB;QACpB,mBAAmB;QAEnB,wBAAwB;QACxB,iBAAiB;QACjB,kBAAkB;QAClB,iBAAiB;QAEjB,0BAA0B;QAC1B,0BAA0B;QAE1B,wBAAwB;QACxB,oBAAoB;KACrB,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Room } from "livekit-client";
|
|
2
|
+
export interface TemplateKeys {
|
|
3
|
+
[key: string]: string;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Hook for updating template keys in Convai.
|
|
7
|
+
*
|
|
8
|
+
* Updates dynamic template variables that can be used in AI responses
|
|
9
|
+
* to provide personalized and contextual information.
|
|
10
|
+
*
|
|
11
|
+
* @param {Room} room - LiveKit room instance
|
|
12
|
+
* @param {string} participantSid - Participant session ID
|
|
13
|
+
* @returns {Object} Object containing updateTemplateKeys function
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```tsx
|
|
17
|
+
* function TemplateComponent() {
|
|
18
|
+
* const { updateTemplateKeys } = useTemplateKeysUpdater(room, participantSid);
|
|
19
|
+
*
|
|
20
|
+
* const handleUpdate = () => {
|
|
21
|
+
* updateTemplateKeys({
|
|
22
|
+
* user_name: "John",
|
|
23
|
+
* location: "New York",
|
|
24
|
+
* mood: "happy"
|
|
25
|
+
* });
|
|
26
|
+
* };
|
|
27
|
+
*
|
|
28
|
+
* return <button onClick={handleUpdate}>Update Templates</button>;
|
|
29
|
+
* }
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export declare const useTemplateKeysUpdater: (room: Room, participantSid: string) => {
|
|
33
|
+
updateTemplateKeys: (templateKeys: TemplateKeys) => void;
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=useTemplateKeysUpdater.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useTemplateKeysUpdater.d.ts","sourceRoot":"","sources":["../../src/hooks/useTemplateKeysUpdater.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAGtC,MAAM,WAAW,YAAY;IAC3B,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;CACvB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,eAAO,MAAM,sBAAsB,GACjC,MAAM,IAAI,EACV,gBAAgB,MAAM;uCAGL,YAAY;CA4B9B,CAAC"}
|