MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / executeFunctionHook

Function executeFunctionHook

source code/utils/hooks.ts:4742–4840  ·  view source on GitHub ↗
({
  hook,
  messages,
  hookName,
  toolUseID,
  hookEvent,
  timeoutMs,
  signal,
}: {
  hook: FunctionHook
  messages: Message[]
  hookName: string
  toolUseID: string
  hookEvent: HookEvent
  timeoutMs: number
  signal?: AbortSignal
})

Source from the content-addressed store, hash-verified

4740}
4741
4742async function executeFunctionHook({
4743 hook,
4744 messages,
4745 hookName,
4746 toolUseID,
4747 hookEvent,
4748 timeoutMs,
4749 signal,
4750}: {
4751 hook: FunctionHook
4752 messages: Message[]
4753 hookName: string
4754 toolUseID: string
4755 hookEvent: HookEvent
4756 timeoutMs: number
4757 signal?: AbortSignal
4758}): Promise<HookResult> {
4759 const callbackTimeoutMs = hook.timeout ?? timeoutMs
4760 const { signal: abortSignal, cleanup } = createCombinedAbortSignal(signal, {
4761 timeoutMs: callbackTimeoutMs,
4762 })
4763
4764 try {
4765 // Check if already aborted
4766 if (abortSignal.aborted) {
4767 cleanup()
4768 return {
4769 outcome: 'cancelled',
4770 hook,
4771 }
4772 }
4773
4774 // Execute callback with abort signal
4775 const passed = await new Promise<boolean>((resolve, reject) => {
4776 // Handle abort signal
4777 const onAbort = () => reject(new Error('Function hook cancelled'))
4778 abortSignal.addEventListener('abort', onAbort)
4779
4780 // Execute callback
4781 Promise.resolve(hook.callback(messages, abortSignal))
4782 .then(result => {
4783 abortSignal.removeEventListener('abort', onAbort)
4784 resolve(result)
4785 })
4786 .catch(error => {
4787 abortSignal.removeEventListener('abort', onAbort)
4788 reject(error)
4789 })
4790 })
4791
4792 cleanup()
4793
4794 if (passed) {
4795 return {
4796 outcome: 'success',
4797 hook,
4798 }
4799 }

Callers 1

executeHooksFunction · 0.85

Calls 6

createAttachmentMessageFunction · 0.85
resolveMethod · 0.80
cleanupFunction · 0.70
resolveFunction · 0.70
logErrorFunction · 0.70

Tested by

no test coverage detected