Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

feat(chatMascot): add chat mascot context and dock

Steven Enamakel387fcffb1d64
diff --git a/app/src/features/human/chatMascot/ChatMascotContext.tsx b/app/src/features/human/chatMascot/ChatMascotContext.tsx
index b1f77b97d3..273715dd00 100644
--- a/app/src/features/human/chatMascot/ChatMascotContext.tsx
+++ b/app/src/features/human/chatMascot/ChatMascotContext.tsx
@@ -13,6 +13,7 @@ import {
import { useAppDispatch } from '../../../store/hooks';
import { setChatMascotExpanded } from '../../../store/mascotSlice';
+import { IDLE_REALTIME_VOICE_AUDIO, type RealtimeVoiceAudio } from '../voice/amplitudeLipsync';
import { type ChatMascotSendBinding, ChatMascotSendStore } from './sendBinding';
const mascotLog = debug('human:chat-mascot');
@@ -47,7 +48,23 @@ export interface ChatMascotContextValue {
/** How the stage reaches the chat's send path. */
sendStore: ChatMascotSendStore;
expand: () => void;
- collapse: () => void;
+ /**
+ * Expand the stage AND ask it to start a live voice session as soon as it
+ * mounts — what clicking the docked mascot does.
+ */
+ expandWithVoice: () => void;
+ /**
+ * Read-and-clear the pending "start talking" request. The stage's live voice
+ * control calls this once on mount, so a stage restored expanded on launch
+ * (no click) never opens the microphone on its own.
+ */
+ consumeVoiceStart: () => boolean;
+ /**
+ * The live session's output-loudness accessor, written by the stage's voice
+ * control and sampled per frame by the overlay for amplitude lip-sync. A ref
+ * because a 60fps signal must not travel through React state (#5357).
+ */
+ liveAudioRef: RefObject<RealtimeVoiceAudio>;
}
const ChatMascotContext = createContext<ChatMascotContextValue | null>(null);
@@ -84,6 +101,8 @@ export const ChatMascotProvider = ({ children }: { children: ReactNode }) => {
const sendStoreRef = useRef<ChatMascotSendStore | null>(null);
sendStoreRef.current ??= new ChatMascotSendStore();
const sendStore = sendStoreRef.current;
+ const voiceStartRef = useRef(false);
+ const liveAudioRef = useRef<RealtimeVoiceAudio>({ ...IDLE_REALTIME_VOICE_AUDIO });
const value = useMemo<ChatMascotContextValue>(
() => ({
@@ -97,8 +116,20 @@ export const ChatMascotProvider = ({ children }: { children: ReactNode }) => {
},
collapse: () => {
mascotLog('[chat-mascot] collapse requested');
+ voiceStartRef.current = false;
dispatch(setChatMascotExpanded(false));
},
+ expandWithVoice: () => {
+ mascotLog('[chat-mascot] expand + live voice requested');
+ voiceStartRef.current = true;
+ dispatch(setChatMascotExpanded(true));
+ },
+ consumeVoiceStart: () => {
+ const pending = voiceStartRef.current;
+ voiceStartRef.current = false;
+ return pending;
+ },
+ liveAudioRef,
}),
[dispatch, sendStore, setDockNode]
);
diff --git a/app/src/features/human/chatMascot/ChatMascotDock.tsx b/app/src/features/human/chatMascot/ChatMascotDock.tsx
index 4e4138f338..d918a65eef 100644
--- a/app/src/features/human/chatMascot/ChatMascotDock.tsx
+++ b/app/src/features/human/chatMascot/ChatMascotDock.tsx
@@ -22,13 +22,13 @@ const dockLog = debug('human:chat-mascot');
* and the accessible label — which is why it is safe for it to sit inside the
* composer without dragging Rive's per-frame re-render into the chat tree.
*
- * [ui-flow] chat-mascot: dock click → expanded (stage) → mascot/collapse → docked
+ * [ui-flow] chat-mascot: dock click → expanded (stage) + live voice session → mascot/collapse → docked
* [ui-flow] chat-mascot: dismiss (×) → confirm → hidden until re-enabled in settings
*/
const ChatMascotDock = () => {
const { t } = useT();
const dispatch = useAppDispatch();
- const { setDockNode, expand } = useChatMascot();
+ const { setDockNode, expandWithVoice } = useChatMascot();
const expanded = useAppSelector(selectChatMascotExpanded);
const dismissed = useAppSelector(selectChatMascotDismissed);
const [confirmingDismiss, setConfirmingDismiss] = useState(false);
@@ -58,7 +58,7 @@ const ChatMascotDock = () => {
aria-expanded={false}
data-testid="chat-mascot-dock"
data-analytics-id="chat-mascot-toggle"
- onClick={expand}
+ onClick={expandWithVoice}
/>
{/* Hidden until hover/focus so the mascot stays a mascot rather than a