( state: HookRegistryState, event: RunLifecycleEvent, eventId: string, )
| 639 | } |
| 640 | |
| 641 | function upsertRun( |
| 642 | state: HookRegistryState, |
| 643 | event: RunLifecycleEvent, |
| 644 | eventId: string, |
| 645 | ): void { |
| 646 | const existing = state.runs[event.runId] |
| 647 | if (!existing) { |
| 648 | state.runs[event.runId] = { |
| 649 | id: event.runId, |
| 650 | ...(event.hookId ? { hookId: event.hookId } : {}), |
| 651 | ...(event.threadId ? { threadId: event.threadId } : {}), |
| 652 | status: event.status, |
| 653 | ...(event.source ? { source: event.source } : {}), |
| 654 | ...(event.visibility ? { visibility: event.visibility } : {}), |
| 655 | startedAt: event.timestamp, |
| 656 | updatedAt: event.timestamp, |
| 657 | ...(isTerminalRunStatus(event.status) |
| 658 | ? { completedAt: event.timestamp } |
| 659 | : {}), |
| 660 | ...(event.error ? { error: event.error } : {}), |
| 661 | eventIds: [eventId], |
| 662 | } |
| 663 | return |
| 664 | } |
| 665 | |
| 666 | if (event.hookId) existing.hookId = event.hookId |
| 667 | if (event.threadId) existing.threadId = event.threadId |
| 668 | if (event.source) existing.source = event.source |
| 669 | if (event.visibility) existing.visibility = event.visibility |
| 670 | existing.status = event.status |
| 671 | existing.updatedAt = event.timestamp |
| 672 | if (isTerminalRunStatus(event.status)) { |
| 673 | existing.completedAt = event.timestamp |
| 674 | } |
| 675 | if (event.error) { |
| 676 | existing.error = event.error |
| 677 | } |
| 678 | if (!existing.eventIds.includes(eventId)) { |
| 679 | existing.eventIds.push(eventId) |
| 680 | } |
| 681 | } |
| 682 | |
| 683 | function attachRunToHook( |
| 684 | state: HookRegistryState, |
no test coverage detected