33from __future__ import annotations
44
55import datetime
6- from dataclasses import dataclass , replace
6+ from dataclasses import dataclass
77from enum import Enum
88from typing import Any
99
@@ -2547,26 +2547,13 @@ def events_to_operations(events: list[Event]) -> list[Operation]:
25472547 # Merge with previous operation if it exists
25482548 # Most fields are immutable, so they get preserved from previous events
25492549 if previous_operation :
2550- operation = replace (
2551- operation ,
2552- name = operation .name or previous_operation .name ,
2553- parent_id = operation .parent_id or previous_operation .parent_id ,
2554- sub_type = operation .sub_type or previous_operation .sub_type ,
2555- start_timestamp = previous_operation .start_timestamp ,
2556- end_timestamp = previous_operation .end_timestamp ,
2557- execution_details = previous_operation .execution_details ,
2558- context_details = previous_operation .context_details ,
2559- step_details = previous_operation .step_details ,
2560- wait_details = previous_operation .wait_details ,
2561- callback_details = previous_operation .callback_details ,
2562- chained_invoke_details = previous_operation .chained_invoke_details ,
2563- )
2550+ operation = operation .create_merged_from_previous (previous_operation )
25642551
25652552 # Set timestamps based on event configuration
25662553 if event_config .is_start_event :
2567- operation = replace ( operation , start_timestamp = event .event_timestamp )
2554+ operation = operation . create_with_start_timestamp ( event .event_timestamp )
25682555 if event_config .is_end_event :
2569- operation = replace ( operation , end_timestamp = event .event_timestamp )
2556+ operation = operation . create_with_end_timestamp ( event .event_timestamp )
25702557
25712558 # Add operation-specific details incrementally
25722559 # Each event type contributes only the fields it has
@@ -2577,11 +2564,10 @@ def events_to_operations(events: list[Event]) -> list[Operation]:
25772564 and event .execution_started_details
25782565 and event .execution_started_details .input
25792566 ):
2580- operation = replace (
2581- operation ,
2582- execution_details = ExecutionDetails (
2567+ operation = operation .create_with_execution_details (
2568+ ExecutionDetails (
25832569 input_payload = event .execution_started_details .input .payload
2584- ),
2570+ )
25852571 )
25862572
25872573 # CALLBACK details - merge callback_id, result, and error from different events
@@ -2613,13 +2599,12 @@ def events_to_operations(events: list[Event]) -> list[Operation]:
26132599 ):
26142600 error = event .callback_timed_out_details .error .payload
26152601
2616- operation = replace (
2617- operation ,
2618- callback_details = CallbackDetails (
2602+ operation = operation .create_with_callback_details (
2603+ CallbackDetails (
26192604 callback_id = callback_id ,
26202605 result = result ,
26212606 error = error ,
2622- ),
2607+ )
26232608 )
26242609
26252610 # STEP details - only update if this event type has result data
@@ -2655,23 +2640,21 @@ def events_to_operations(events: list[Event]) -> list[Operation]:
26552640 seconds = event .step_failed_details .retry_details .next_attempt_delay_seconds
26562641 )
26572642
2658- operation = replace (
2659- operation ,
2660- step_details = StepDetails (
2643+ operation = operation .create_with_step_details (
2644+ StepDetails (
26612645 result = result_val ,
26622646 error = error_val ,
26632647 attempt = attempt ,
26642648 next_attempt_timestamp = next_attempt_ts ,
2665- ),
2649+ )
26662650 )
26672651
26682652 # WAIT details
26692653 if operation_type == OperationType .WAIT and event .wait_started_details :
2670- operation = replace (
2671- operation ,
2672- wait_details = WaitDetails (
2654+ operation = operation .create_with_wait_details (
2655+ WaitDetails (
26732656 scheduled_end_timestamp = event .wait_started_details .scheduled_end_timestamp
2674- ),
2657+ )
26752658 )
26762659
26772660 # CONTEXT details - only update if this event type has result data (matching TypeScript hasResult)
@@ -2680,20 +2663,18 @@ def events_to_operations(events: list[Event]) -> list[Operation]:
26802663 event .context_succeeded_details
26812664 and event .context_succeeded_details .result
26822665 ):
2683- operation = replace (
2684- operation ,
2685- context_details = ContextDetails (
2666+ operation = operation .create_with_context_details (
2667+ ContextDetails (
26862668 result = event .context_succeeded_details .result .payload ,
26872669 error = None ,
2688- ),
2670+ )
26892671 )
26902672 elif event .context_failed_details and event .context_failed_details .error :
2691- operation = replace (
2692- operation ,
2693- context_details = ContextDetails (
2673+ operation = operation .create_with_context_details (
2674+ ContextDetails (
26942675 result = None ,
26952676 error = event .context_failed_details .error .payload ,
2696- ),
2677+ )
26972678 )
26982679
26992680 # CHAINED_INVOKE details - only update if this event type has result data (matching TypeScript hasResult)
@@ -2702,23 +2683,21 @@ def events_to_operations(events: list[Event]) -> list[Operation]:
27022683 event .chained_invoke_succeeded_details
27032684 and event .chained_invoke_succeeded_details .result
27042685 ):
2705- operation = replace (
2706- operation ,
2707- chained_invoke_details = ChainedInvokeDetails (
2686+ operation = operation .create_with_chained_invoke_details (
2687+ ChainedInvokeDetails (
27082688 result = event .chained_invoke_succeeded_details .result .payload ,
27092689 error = None ,
2710- ),
2690+ )
27112691 )
27122692 elif (
27132693 event .chained_invoke_failed_details
27142694 and event .chained_invoke_failed_details .error
27152695 ):
2716- operation = replace (
2717- operation ,
2718- chained_invoke_details = ChainedInvokeDetails (
2696+ operation = operation .create_with_chained_invoke_details (
2697+ ChainedInvokeDetails (
27192698 result = None ,
27202699 error = event .chained_invoke_failed_details .error .payload ,
2721- ),
2700+ )
27222701 )
27232702
27242703 # Store in map
0 commit comments