( setAppState: (updater: (prev: AppState) => AppState) => void, sessionId: string, event: HookEvent, hookId: string, )
| 118 | * Remove a function hook by ID from the session. |
| 119 | */ |
| 120 | export function removeFunctionHook( |
| 121 | setAppState: (updater: (prev: AppState) => AppState) => void, |
| 122 | sessionId: string, |
| 123 | event: HookEvent, |
| 124 | hookId: string, |
| 125 | ): void { |
| 126 | setAppState(prev => { |
| 127 | const store = prev.sessionHooks.get(sessionId) |
| 128 | if (!store) { |
| 129 | return prev |
| 130 | } |
| 131 | |
| 132 | const eventMatchers = store.hooks[event] || [] |
| 133 | |
| 134 | // Remove the hook with matching ID from all matchers |
| 135 | const updatedMatchers = eventMatchers |
| 136 | .map(matcher => { |
| 137 | const updatedHooks = matcher.hooks.filter(h => { |
| 138 | if (h.hook.type !== 'function') return true |
| 139 | return h.hook.id !== hookId |
| 140 | }) |
| 141 | |
| 142 | return updatedHooks.length > 0 |
| 143 | ? { ...matcher, hooks: updatedHooks } |
| 144 | : null |
| 145 | }) |
| 146 | .filter((m): m is SessionHookMatcher => m !== null) |
| 147 | |
| 148 | const newHooks = |
| 149 | updatedMatchers.length > 0 |
| 150 | ? { ...store.hooks, [event]: updatedMatchers } |
| 151 | : Object.fromEntries( |
| 152 | Object.entries(store.hooks).filter(([e]) => e !== event), |
| 153 | ) |
| 154 | |
| 155 | prev.sessionHooks.set(sessionId, { hooks: newHooks }) |
| 156 | return prev |
| 157 | }) |
| 158 | |
| 159 | logForDebugging( |
| 160 | `Removed function hook ${hookId} for event ${event} in session ${sessionId}`, |
| 161 | ) |
| 162 | } |
| 163 | |
| 164 | /** |
| 165 | * Internal helper to add a hook to session state |
nothing calls this directly
no test coverage detected