(input: {
type: TaskLedgerEvent['type'];
sessionId: string;
task: Task;
previous?: Task;
context: TaskLedgerMutationContext;
})
| 817 | } |
| 818 | |
| 819 | function buildTaskLedgerEvent(input: { |
| 820 | type: TaskLedgerEvent['type']; |
| 821 | sessionId: string; |
| 822 | task: Task; |
| 823 | previous?: Task; |
| 824 | context: TaskLedgerMutationContext; |
| 825 | }): TaskLedgerEvent { |
| 826 | return { |
| 827 | eventId: `task-event-${randomUUID()}`, |
| 828 | type: input.type, |
| 829 | ts: Date.now(), |
| 830 | sessionId: input.sessionId, |
| 831 | taskId: input.task.id, |
| 832 | ...(input.previous ? { previousStatus: input.previous.status } : {}), |
| 833 | nextStatus: input.task.status, |
| 834 | task: input.task, |
| 835 | ...((input.context.reason ?? eventReason(input.task)) |
| 836 | ? { reason: input.context.reason ?? eventReason(input.task) } |
| 837 | : {}), |
| 838 | ...(eventEvidence(input.task) ? { evidence: eventEvidence(input.task) } : {}), |
| 839 | ...(eventRefs(input.context) ? { refs: eventRefs(input.context) } : {}), |
| 840 | ...(input.context.source ? { source: input.context.source } : {}), |
| 841 | ...(input.context.actor ? { actor: input.context.actor } : {}), |
| 842 | }; |
| 843 | } |
| 844 | |
| 845 | function eventReason(task: Task): string | undefined { |
| 846 | return task.blockedReason ?? task.failureReason; |
no test coverage detected