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