Remove agent state concept (#58)
This commit is contained in:
parent
2d7d3f3d6d
commit
ba9aedf666
@ -15,7 +15,6 @@ import {
|
|||||||
import { AgentMultibandAudioVisualizer } from "@/components/visualization/AgentMultibandAudioVisualizer";
|
import { AgentMultibandAudioVisualizer } from "@/components/visualization/AgentMultibandAudioVisualizer";
|
||||||
import { useConfig } from "@/hooks/useConfig";
|
import { useConfig } from "@/hooks/useConfig";
|
||||||
import { useMultibandTrackVolume } from "@/hooks/useTrackVolume";
|
import { useMultibandTrackVolume } from "@/hooks/useTrackVolume";
|
||||||
import { AgentState } from "@/lib/types";
|
|
||||||
import {
|
import {
|
||||||
VideoTrack,
|
VideoTrack,
|
||||||
useChat,
|
useChat,
|
||||||
@ -56,7 +55,6 @@ export default function Playground({
|
|||||||
}: PlaygroundProps) {
|
}: PlaygroundProps) {
|
||||||
const { config, setUserSettings } = useConfig();
|
const { config, setUserSettings } = useConfig();
|
||||||
const { name } = useRoomInfo();
|
const { name } = useRoomInfo();
|
||||||
const [agentState, setAgentState] = useState<AgentState>("offline");
|
|
||||||
const [messages, setMessages] = useState<ChatMessageType[]>([]);
|
const [messages, setMessages] = useState<ChatMessageType[]>([]);
|
||||||
const [transcripts, setTranscripts] = useState<ChatMessageType[]>([]);
|
const [transcripts, setTranscripts] = useState<ChatMessageType[]>([]);
|
||||||
const { localParticipant } = useLocalParticipant();
|
const { localParticipant } = useLocalParticipant();
|
||||||
@ -65,6 +63,7 @@ export default function Playground({
|
|||||||
updateOnlyOn: [RoomEvent.ParticipantMetadataChanged],
|
updateOnlyOn: [RoomEvent.ParticipantMetadataChanged],
|
||||||
});
|
});
|
||||||
const agentParticipant = participants.find((p) => p.isAgent);
|
const agentParticipant = participants.find((p) => p.isAgent);
|
||||||
|
const isAgentConnected = agentParticipant !== undefined;
|
||||||
|
|
||||||
const { send: sendChat, chatMessages } = useChat();
|
const { send: sendChat, chatMessages } = useChat();
|
||||||
const roomState = useConnectionState();
|
const roomState = useConnectionState();
|
||||||
@ -109,24 +108,6 @@ export default function Playground({
|
|||||||
20
|
20
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (!agentParticipant) {
|
|
||||||
setAgentState("offline");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let agentMd: any = {};
|
|
||||||
if (agentParticipant.metadata) {
|
|
||||||
agentMd = JSON.parse(agentParticipant.metadata);
|
|
||||||
}
|
|
||||||
if (agentMd.agent_state) {
|
|
||||||
setAgentState(agentMd.agent_state);
|
|
||||||
} else {
|
|
||||||
setAgentState("starting");
|
|
||||||
}
|
|
||||||
}, [agentParticipant, agentParticipant?.metadata]);
|
|
||||||
|
|
||||||
const isAgentConnected = agentState !== "offline";
|
|
||||||
|
|
||||||
const onDataReceived = useCallback(
|
const onDataReceived = useCallback(
|
||||||
(msg: any) => {
|
(msg: any) => {
|
||||||
if (msg.topic === "transcription") {
|
if (msg.topic === "transcription") {
|
||||||
@ -233,10 +214,11 @@ export default function Playground({
|
|||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// TODO: keep it in the speaking state until we come up with a better protocol for agent states
|
||||||
const visualizerContent = (
|
const visualizerContent = (
|
||||||
<div className="flex items-center justify-center w-full">
|
<div className="flex items-center justify-center w-full">
|
||||||
<AgentMultibandAudioVisualizer
|
<AgentMultibandAudioVisualizer
|
||||||
state={agentState}
|
state="speaking"
|
||||||
barWidth={30}
|
barWidth={30}
|
||||||
minBarHeight={30}
|
minBarHeight={30}
|
||||||
maxBarHeight={150}
|
maxBarHeight={150}
|
||||||
@ -260,7 +242,6 @@ export default function Playground({
|
|||||||
return visualizerContent;
|
return visualizerContent;
|
||||||
}, [
|
}, [
|
||||||
agentAudioTrack,
|
agentAudioTrack,
|
||||||
agentState,
|
|
||||||
config.settings.theme_color,
|
config.settings.theme_color,
|
||||||
subscribedVolumes,
|
subscribedVolumes,
|
||||||
roomState,
|
roomState,
|
||||||
@ -334,24 +315,6 @@ export default function Playground({
|
|||||||
: "gray-500"
|
: "gray-500"
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
<NameValueRow
|
|
||||||
name="Agent status"
|
|
||||||
value={
|
|
||||||
agentState !== "offline" && agentState !== "speaking" ? (
|
|
||||||
<div className="flex gap-2 items-center">
|
|
||||||
<LoadingSVG diameter={12} strokeWidth={2} />
|
|
||||||
{agentState}
|
|
||||||
</div>
|
|
||||||
) : (
|
|
||||||
agentState
|
|
||||||
)
|
|
||||||
}
|
|
||||||
valueColor={
|
|
||||||
agentState === "speaking"
|
|
||||||
? `${config.settings.theme_color}-500`
|
|
||||||
: "gray-500"
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
</ConfigurationPanelItem>
|
</ConfigurationPanelItem>
|
||||||
{localVideoTrack && (
|
{localVideoTrack && (
|
||||||
@ -405,7 +368,6 @@ export default function Playground({
|
|||||||
name,
|
name,
|
||||||
roomState,
|
roomState,
|
||||||
isAgentConnected,
|
isAgentConnected,
|
||||||
agentState,
|
|
||||||
localVideoTrack,
|
localVideoTrack,
|
||||||
localMicTrack,
|
localMicTrack,
|
||||||
localMultibandVolume,
|
localMultibandVolume,
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
import { AgentState } from "@/lib/types";
|
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
|
|
||||||
|
type VisualizerState = "listening" | "idle" | "speaking" | "thinking";
|
||||||
type AgentMultibandAudioVisualizerProps = {
|
type AgentMultibandAudioVisualizerProps = {
|
||||||
state: AgentState;
|
state: VisualizerState;
|
||||||
barWidth: number;
|
barWidth: number;
|
||||||
minBarHeight: number;
|
minBarHeight: number;
|
||||||
maxBarHeight: number;
|
maxBarHeight: number;
|
||||||
|
|||||||
@ -14,11 +14,3 @@ export interface TokenResult {
|
|||||||
identity: string;
|
identity: string;
|
||||||
accessToken: string;
|
accessToken: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type AgentState =
|
|
||||||
| "idle"
|
|
||||||
| "listening"
|
|
||||||
| "speaking"
|
|
||||||
| "thinking"
|
|
||||||
| "offline"
|
|
||||||
| "starting";
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user