| 613 | } |
| 614 | |
| 615 | function removeHookRecord(state: HookRegistryState, hookId: string): void { |
| 616 | const hook = state.hooks[hookId] |
| 617 | const hookRunIds = new Set(hook?.runIds ?? []) |
| 618 | const hookEventIds = new Set(hook?.eventIds ?? []) |
| 619 | |
| 620 | for (const [runId, run] of Object.entries(state.runs)) { |
| 621 | if (run.hookId === hookId || hookRunIds.has(runId)) { |
| 622 | delete state.runs[runId] |
| 623 | } |
| 624 | } |
| 625 | |
| 626 | // Only remove events that were attached to the hook via attachEventToHook; |
| 627 | // the unregister event itself is intentionally not attached so it survives |
| 628 | // and can still be inspected on the global timeline. |
| 629 | for (const eventId of hookEventIds) { |
| 630 | delete state.events[eventId] |
| 631 | } |
| 632 | |
| 633 | delete state.hooks[hookId] |
| 634 | delete state.seenHookActivityCounts[hookId] |
| 635 | |
| 636 | if (state.activeHookId === hookId) { |
| 637 | state.activeHookId = null |
| 638 | } |
| 639 | } |
| 640 | |
| 641 | function upsertRun( |
| 642 | state: HookRegistryState, |