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 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 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 | /** * Intelligence Domain Hooks * * React hooks for accessing intelligence state with Valtio. * Provides reactive access to memory, heartbeat, reflection, and identity. */ import { useSnapshot } from 'valtio'; import { intelligenceStore } from './store'; import type { MemoryEntry, CacheStats } from './types'; // === Memory Hooks === /** * Hook to access memories list */ export function useMemories() { const { memories } = useSnapshot(intelligenceStore); return memories as readonly MemoryEntry[]; } /** * Hook to access memory stats */ export function useMemoryStats() { const { memoryStats } = useSnapshot(intelligenceStore); return memoryStats; } /** * Hook to check if memories are loading */ export function useMemoryLoading(): boolean { const { isMemoryLoading } = useSnapshot(intelligenceStore); return isMemoryLoading; } // === Heartbeat Hooks === /** * Hook to access heartbeat config */ export function useHeartbeatConfig() { const { heartbeatConfig } = useSnapshot(intelligenceStore); return heartbeatConfig; } /** * Hook to access heartbeat history */ export function useHeartbeatHistory() { const { heartbeatHistory } = useSnapshot(intelligenceStore); return heartbeatHistory; } /** * Hook to check if heartbeat is running */ export function useHeartbeatRunning(): boolean { const { isHeartbeatRunning } = useSnapshot(intelligenceStore); return isHeartbeatRunning; } // === Compaction Hooks === /** * Hook to access last compaction result */ export function useLastCompaction() { const { lastCompaction } = useSnapshot(intelligenceStore); return lastCompaction; } /** * Hook to access compaction check */ export function useCompactionCheck() { const { compactionCheck } = useSnapshot(intelligenceStore); return compactionCheck; } // === Reflection Hooks === /** * Hook to access reflection state */ export function useReflectionState() { const { reflectionState } = useSnapshot(intelligenceStore); return reflectionState; } /** * Hook to access last reflection result */ export function useLastReflection() { const { lastReflection } = useSnapshot(intelligenceStore); return lastReflection; } // === Identity Hooks === /** * Hook to access current identity */ export function useIdentity() { const { currentIdentity } = useSnapshot(intelligenceStore); return currentIdentity; } /** * Hook to access pending identity proposals */ export function usePendingProposals() { const { pendingProposals } = useSnapshot(intelligenceStore); return pendingProposals; } // === Cache Hooks === /** * Hook to access cache stats */ export function useCacheStats(): CacheStats { const { cacheStats } = useSnapshot(intelligenceStore); return cacheStats; } // === General Hooks === /** * Hook to check if any intelligence operation is loading */ export function useIntelligenceLoading(): boolean { const { isLoading, isMemoryLoading } = useSnapshot(intelligenceStore); return isLoading || isMemoryLoading; } /** * Hook to access intelligence error */ export function useIntelligenceError(): string | null { const { error } = useSnapshot(intelligenceStore); return error; } /** * Hook to access the full intelligence state snapshot */ export function useIntelligenceState() { return useSnapshot(intelligenceStore); } /** * Hook to access intelligence actions * Returns the store directly for calling actions. * Does not cause re-renders. */ export function useIntelligenceActions() { return intelligenceStore; } // === Convenience Hooks === /** * Hook for memory operations with loading state */ export function useMemoryOperations() { const memories = useMemories(); const isLoading = useMemoryLoading(); const stats = useMemoryStats(); const actions = useIntelligenceActions(); return { memories, isLoading, stats, loadMemories: actions.loadMemories, storeMemory: actions.storeMemory, deleteMemory: actions.deleteMemory, loadStats: actions.loadMemoryStats, }; } /** * Hook for heartbeat operations */ export function useHeartbeatOperations() { const config = useHeartbeatConfig(); const isRunning = useHeartbeatRunning(); const history = useHeartbeatHistory(); const actions = useIntelligenceActions(); return { config, isRunning, history, init: actions.initHeartbeat, start: actions.startHeartbeat, stop: actions.stopHeartbeat, tick: actions.tickHeartbeat, }; } /** * Hook for compaction operations */ export function useCompactionOperations() { const lastCompaction = useLastCompaction(); const check = useCompactionCheck(); const actions = useIntelligenceActions(); return { lastCompaction, check, checkThreshold: actions.checkCompaction, compact: actions.compact, }; } /** * Hook for reflection operations */ export function useReflectionOperations() { const state = useReflectionState(); const lastReflection = useLastReflection(); const actions = useIntelligenceActions(); return { state, lastReflection, recordConversation: actions.recordConversation, shouldReflect: actions.shouldReflect, reflect: actions.reflect, }; } /** * Hook for identity operations */ export function useIdentityOperations() { const identity = useIdentity(); const pendingProposals = usePendingProposals(); const actions = useIntelligenceActions(); return { identity, pendingProposals, loadIdentity: actions.loadIdentity, buildPrompt: actions.buildPrompt, proposeChange: actions.proposeIdentityChange, approveProposal: actions.approveProposal, rejectProposal: actions.rejectProposal, }; } |