Skip to content

[draft] datastream text input #133

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 54 additions & 47 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
"lint": "next lint"
},
"dependencies": {
"@livekit/components-react": "^2.6.0",
"@livekit/components-styles": "^1.1.1",
"@livekit/components-react": "^2.8.1",
"@livekit/components-styles": "^1.1.4",
"@radix-ui/react-dropdown-menu": "^2.0.6",
"cookies-next": "^4.1.1",
"framer-motion": "^10.16.16",
"js-yaml": "^4.1.0",
"livekit-client": "^2.5.1",
"livekit-server-sdk": "^2.6.1",
"livekit-client": "^2.9.3",
"livekit-server-sdk": "^2.10.1",
"lodash": "^4.17.21",
"next": "^14.0.4",
"next-plugin-preval": "^1.2.6",
Expand Down
6 changes: 4 additions & 2 deletions src/components/playground/Playground.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -221,17 +221,19 @@ export default function Playground({
const handleRpcCall = useCallback(async () => {
if (!voiceAssistant.agent || !room) return;

const agent_identity = voiceAssistant.agentAttributes?.['lk.publish_for'] || voiceAssistant.agent.identity;
console.log('Agent identity for RPC call:', agent_identity);
try {
const response = await room.localParticipant.performRpc({
destinationIdentity: voiceAssistant.agent.identity,
destinationIdentity: agent_identity,
method: rpcMethod,
payload: rpcPayload,
});
console.log('RPC response:', response);
} catch (e) {
console.error('RPC call failed:', e);
}
}, [room, rpcMethod, rpcPayload, voiceAssistant.agent]);
}, [room, rpcMethod, rpcPayload, voiceAssistant.agent, voiceAssistant.agentAttributes]);

const settingsTileContent = useMemo(() => {
return (
Expand Down
22 changes: 22 additions & 0 deletions src/hooks/useSendText.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { useCallback } from 'react';
import { useRoomContext } from '@livekit/components-react';

export const useSendText = () => {
const room = useRoomContext();

const sendText = useCallback(async (message: string) => {
if (!room?.localParticipant) return;

try {
console.log('Sending text message:', message);
const info = await room.localParticipant.sendText(message, {
topic: 'lk.chat'
});
console.log('Text message sent:', info);
} catch (e) {
console.error('Failed to send message:', e);
}
}, [room]);

return sendText;
};
12 changes: 11 additions & 1 deletion src/transcriptions/TranscriptionTile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
TranscriptionSegment,
} from "livekit-client";
import { useEffect, useState } from "react";
import { useSendText } from '@/hooks/useSendText';

export function TranscriptionTile({
agentAudioTrack,
Expand All @@ -33,6 +34,7 @@ export function TranscriptionTile({
);
const [messages, setMessages] = useState<ChatMessageType[]>([]);
const { chatMessages, send: sendChat } = useChat();
const sendText = useSendText();

// store transcripts
useEffect(() => {
Expand Down Expand Up @@ -91,8 +93,16 @@ export function TranscriptionTile({
localMessages.segments,
]);

const handleSendMessage = async (message: string) => {
const [chatMessage, _] = await Promise.all([
sendChat(message),
sendText(message)
]);
return chatMessage;
};

return (
<ChatTile messages={messages} accentColor={accentColor} onSend={sendChat} />
<ChatTile messages={messages} accentColor={accentColor} onSend={handleSendMessage} />
);
}

Expand Down