deriveTrajectoryLayout function

List<TrajectoryTurnModel> deriveTrajectoryLayout(
  1. TrajectorySnapshot snapshot
)

Folds a snapshot into turns of Message/Step groups.

User, context, and system rows enclose into the next assistant turn, else the in-flight partial's turn (anchoring the streaming turn without emitting cells), else one past the last assistant turn, else 1. Compaction rows become standalone sections. Requests with no represented record for their turn/step produce request-only separator rows; running calls append after the placed entries. Orphan turn-0 cells fold into Turn 1's prefix.

Implementation

List<TrajectoryTurnModel> deriveTrajectoryLayout(TrajectorySnapshot snapshot) {
  final fold = _LayoutFold(snapshot);
  fold
    ..addRequestSeparators()
    ..addRecords()
    ..addRunningCalls();
  return fold.build();
}