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

Function executeStopFailureHooks

src/utils/hooks.ts:3598–3631  ·  view source on GitHub ↗
(
  lastMessage: AssistantMessage,
  toolUseContext?: ToolUseContext,
  timeoutMs: number = TOOL_HOOK_EXECUTION_TIMEOUT_MS,
)

Source from the content-addressed store, hash-verified

3596}
3597
3598export async function executeStopFailureHooks(
3599 lastMessage: AssistantMessage,
3600 toolUseContext?: ToolUseContext,
3601 timeoutMs: number = TOOL_HOOK_EXECUTION_TIMEOUT_MS,
3602): Promise<void> {
3603 const appState = toolUseContext?.getAppState()
3604 // executeHooksOutsideREPL hardcodes main sessionId (:2738). Agent frontmatter
3605 // hooks (registerFrontmatterHooks) key by agentId; gating with agentId here
3606 // would pass the gate but fail execution. Align gate with execution.
3607 const sessionId = getSessionId()
3608 if (!hasHookForEvent('StopFailure', appState, sessionId)) return
3609
3610 const lastAssistantText =
3611 extractTextContent(lastMessage.message.content, '\n').trim() || undefined
3612
3613 // Some createAssistantAPIErrorMessage call sites omit `error` (e.g.
3614 // image-size at errors.ts:431). Default to 'unknown' so matcher filtering
3615 // at getMatchingHooks:1525 always applies.
3616 const error = lastMessage.error ?? 'unknown'
3617 const hookInput: StopFailureHookInput = {
3618 ...createBaseHookInput(undefined, undefined, toolUseContext),
3619 hook_event_name: 'StopFailure',
3620 error,
3621 error_details: lastMessage.errorDetails,
3622 last_assistant_message: lastAssistantText,
3623 }
3624
3625 await executeHooksOutsideREPL({
3626 getAppState: toolUseContext?.getAppState,
3627 hookInput,
3628 timeoutMs,
3629 matchQuery: error,
3630 })
3631}
3632
3633/**
3634 * Execute stop hooks if configured

Callers 1

queryLoopFunction · 0.85

Calls 5

getSessionIdFunction · 0.85
hasHookForEventFunction · 0.85
extractTextContentFunction · 0.85
createBaseHookInputFunction · 0.85
executeHooksOutsideREPLFunction · 0.85

Tested by

no test coverage detected