MCPcopy Create free account
hub / github.com/freecodexyz/free-code / removeFunctionHook

Function removeFunctionHook

src/utils/hooks/sessionHooks.ts:120–162  ·  view source on GitHub ↗
(
  setAppState: (updater: (prev: AppState) => AppState) => void,
  sessionId: string,
  event: HookEvent,
  hookId: string,
)

Source from the content-addressed store, hash-verified

118 * Remove a function hook by ID from the session.
119 */
120export 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

Callers

nothing calls this directly

Calls 4

logForDebuggingFunction · 0.85
entriesMethod · 0.80
setMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected