MCPcopy Create free account
hub / github.com/TanStack/ai / upsertRun

Function upsertRun

packages/ai-devtools/src/store/hook-registry.ts:641–681  ·  view source on GitHub ↗
(
  state: HookRegistryState,
  event: RunLifecycleEvent,
  eventId: string,
)

Source from the content-addressed store, hash-verified

639}
640
641function 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
683function attachRunToHook(
684 state: HookRegistryState,

Callers 1

applyHookEventFunction · 0.85

Calls 2

isTerminalRunStatusFunction · 0.70
pushMethod · 0.45

Tested by

no test coverage detected