MCPcopy Create free account
hub / github.com/Noumena-Network/code / executeHookCallback

Function executeHookCallback

src/utils/hooks.ts:4844–4900  ·  view source on GitHub ↗
({
  toolUseID,
  hook,
  hookEvent,
  hookInput,
  signal,
  hookIndex,
  toolUseContext,
}: {
  toolUseID: string
  hook: HookCallback
  hookEvent: HookEvent
  hookInput: HookInput
  signal: AbortSignal
  hookIndex?: number
  toolUseContext?: ToolUseContext
})

Source from the content-addressed store, hash-verified

4842}
4843
4844async function executeHookCallback({
4845 toolUseID,
4846 hook,
4847 hookEvent,
4848 hookInput,
4849 signal,
4850 hookIndex,
4851 toolUseContext,
4852}: {
4853 toolUseID: string
4854 hook: HookCallback
4855 hookEvent: HookEvent
4856 hookInput: HookInput
4857 signal: AbortSignal
4858 hookIndex?: number
4859 toolUseContext?: ToolUseContext
4860}): Promise<HookResult> {
4861 // Create context for callbacks that need state access
4862 const context = toolUseContext
4863 ? {
4864 getAppState: toolUseContext.getAppState,
4865 updateAttributionState: toolUseContext.updateAttributionState,
4866 }
4867 : undefined
4868 const json = await hook.callback(
4869 hookInput,
4870 toolUseID,
4871 signal,
4872 hookIndex,
4873 context,
4874 )
4875 if (isAsyncHookJSONOutput(json)) {
4876 return {
4877 outcome: 'success',
4878 hook,
4879 }
4880 }
4881
4882 const processed = processHookJSONOutput({
4883 json,
4884 command: 'callback',
4885 // TODO: If the hook came from a plugin, use the full path to the plugin for easier debugging
4886 hookName: `${hookEvent}:Callback`,
4887 toolUseID,
4888 hookEvent,
4889 expectedHookEvent: hookEvent,
4890 // Callbacks don't have stdout/stderr/exitCode
4891 stdout: undefined,
4892 stderr: undefined,
4893 exitCode: undefined,
4894 })
4895 return {
4896 ...processed,
4897 outcome: 'success',
4898 hook,
4899 }
4900}
4901

Callers 1

executeHooksFunction · 0.85

Calls 2

isAsyncHookJSONOutputFunction · 0.85
processHookJSONOutputFunction · 0.85

Tested by

no test coverage detected