-
Notifications
You must be signed in to change notification settings - Fork 66
/
Copy pathpage.tsx
102 lines (91 loc) · 3.39 KB
/
page.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
"use client"
import React, { useEffect, useState } from "react"
import useWebRTCAudioSession from "@/hooks/use-webrtc"
import { tools } from "@/lib/tools"
import { Welcome } from "@/components/welcome"
import { VoiceSelector } from "@/components/voice-select"
import { BroadcastButton } from "@/components/broadcast-button"
import { StatusDisplay } from "@/components/status"
import { TokenUsageDisplay } from "@/components/token-usage"
import { MessageControls } from "@/components/message-controls"
import { ToolsEducation } from "@/components/tools-education"
import { TextInput } from "@/components/text-input"
import { motion } from "framer-motion"
import { useToolsFunctions } from "@/hooks/use-tools"
const App: React.FC = () => {
// State for voice selection
const [voice, setVoice] = useState("ash")
// WebRTC Audio Session Hook
const {
status,
isSessionActive,
registerFunction,
handleStartStopClick,
msgs,
conversation,
sendTextMessage
} = useWebRTCAudioSession(voice, tools)
// Get all tools functions
const toolsFunctions = useToolsFunctions();
useEffect(() => {
// Register all functions by iterating over the object
Object.entries(toolsFunctions).forEach(([name, func]) => {
const functionNames: Record<string, string> = {
timeFunction: 'getCurrentTime',
backgroundFunction: 'changeBackgroundColor',
partyFunction: 'partyMode',
launchWebsite: 'launchWebsite',
copyToClipboard: 'copyToClipboard',
scrapeWebsite: 'scrapeWebsite'
};
registerFunction(functionNames[name], func);
});
}, [registerFunction, toolsFunctions])
return (
<main className="h-full">
<motion.div
className="container flex flex-col items-center justify-center mx-auto max-w-3xl my-20 p-12 border rounded-lg shadow-xl"
initial={{ opacity: 0, y: 20 }}
animate={{ opacity: 1, y: 0 }}
transition={{ duration: 0.5 }}
>
<Welcome />
<motion.div
className="w-full max-w-md bg-card text-card-foreground rounded-xl border shadow-sm p-6 space-y-4"
initial={{ opacity: 0, scale: 0.95 }}
animate={{ opacity: 1, scale: 1 }}
transition={{ delay: 0.2, duration: 0.4 }}
>
<VoiceSelector value={voice} onValueChange={setVoice} />
<div className="flex flex-col items-center gap-4">
<BroadcastButton
isSessionActive={isSessionActive}
onClick={handleStartStopClick}
/>
</div>
{msgs.length > 4 && <TokenUsageDisplay messages={msgs} />}
{status && (
<motion.div
className="w-full flex flex-col gap-2"
initial={{ opacity: 0, height: 0 }}
animate={{ opacity: 1, height: "auto" }}
exit={{ opacity: 0, height: 0 }}
transition={{ duration: 0.3 }}
>
<MessageControls conversation={conversation} msgs={msgs} />
<TextInput
onSubmit={sendTextMessage}
disabled={!isSessionActive}
/>
</motion.div>
)}
</motion.div>
{status && <StatusDisplay status={status} />}
<div className="w-full flex flex-col items-center gap-4">
<ToolsEducation />
</div>
</motion.div>
</main>
)
}
export default App;