Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 | /** * Chat Domain Hooks * * React hooks for accessing chat state with Valtio. * Only re-renders when accessed properties change. */ import { useSnapshot } from 'valtio'; import { chatStore } from './store'; import type { Message, Agent, Conversation } from './types'; /** * Hook to access the full chat state snapshot. * Only re-renders when accessed properties change. */ export function useChatState() { return useSnapshot(chatStore); } /** * Hook to access messages only. * Only re-renders when messages change. */ export function useMessages() { const { messages } = useSnapshot(chatStore); return messages as readonly Message[]; } /** * Hook to access streaming state. * Only re-renders when isStreaming changes. */ export function useIsStreaming(): boolean { const { isStreaming } = useSnapshot(chatStore); return isStreaming; } /** * Hook to access current agent. */ export function useCurrentAgent(): Agent | null { const { currentAgent } = useSnapshot(chatStore); return currentAgent; } /** * Hook to access all agents. */ export function useAgents() { const { agents } = useSnapshot(chatStore); return agents as readonly Agent[]; } /** * Hook to access conversations. */ export function useConversations() { const { conversations } = useSnapshot(chatStore); return conversations as readonly Conversation[]; } /** * Hook to access current model. */ export function useCurrentModel(): string { const { currentModel } = useSnapshot(chatStore); return currentModel; } /** * Hook to access chat actions. * Returns the store directly for calling actions. * Does not cause re-renders. */ export function useChatActions() { return chatStore; } |