export function indexTaskExecutionRecords(records) {
    const indexed = {};
    for (const record of records || []) {
        if (!record?.taskId)
            continue;
        indexed[record.taskId] = record;
    }
    return indexed;
}
export function overlayTaskExecution(task, record) {
    if (!record)
        return task;
    const finalAgentId = record.agentId ?? task.assignedAgentId;
    return {
        ...task,
        status: record.taskStatus,
        executionState: record.executionState,
        executionAttentionReason: record.attentionReason,
        executionBlockedByProjectIds: record.blockedByProjectIds ?? [],
        executionVersion: record.version,
        executionUpdatedAt: record.updatedAt,
        executionError: record.errorMessage,
        waitingOnDialogId: record.waitingOnDialogId,
        waitingOnToolCallId: record.waitingOnToolCallId,
        resultData: record.resultData ?? task.resultData,
        assignedAgentId: finalAgentId,
    };
}
export function overlayTaskExecutionList(tasks, recordsByTaskId) {
    return tasks.map((task) => overlayTaskExecution(task, recordsByTaskId[task.taskId]));
}
export function getTaskExecutionRecordFromTask(task) {
    if (!task)
        return null;
    return {
        projectId: task.projectId,
        taskId: task.taskId,
        taskStatus: task.status,
        executionState: task.executionState,
        attentionReason: task.executionAttentionReason || "none",
        agentId: task.assignedAgentId,
        blockedByTaskIds: [],
        blockedByProjectIds: task.executionBlockedByProjectIds || [],
        waitingOnDialogId: task.waitingOnDialogId,
        waitingOnToolCallId: task.waitingOnToolCallId,
        resultData: task.resultData,
        errorMessage: task.executionError,
        updatedAt: task.executionUpdatedAt || task.updatedAt,
        version: task.executionVersion || 0,
    };
}
//# sourceMappingURL=taskExecutionRecords.js.map