Reduce a trajectory to plain JSON-friendly Python. Handles the two shapes in this repo: SDK runners' ``Trajectory`` dataclass, and plan-execute's ``list[StepResult]`` (also dataclasses).
(trajectory: Any)
| 87 | |
| 88 | |
| 89 | def _serialize_trajectory(trajectory: Any) -> Any: |
| 90 | """Reduce a trajectory to plain JSON-friendly Python. |
| 91 | |
| 92 | Handles the two shapes in this repo: SDK runners' ``Trajectory`` |
| 93 | dataclass, and plan-execute's ``list[StepResult]`` (also dataclasses). |
| 94 | """ |
| 95 | if trajectory is None: |
| 96 | return None |
| 97 | if dataclasses.is_dataclass(trajectory): |
| 98 | return dataclasses.asdict(trajectory) |
| 99 | if isinstance(trajectory, list): |
| 100 | return [ |
| 101 | dataclasses.asdict(item) if dataclasses.is_dataclass(item) else item |
| 102 | for item in trajectory |
| 103 | ] |
| 104 | return trajectory |
no outgoing calls
no test coverage detected