expansion.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import type { ExecutionViewV8 } from "@/lib/types";
  2. export interface ExpansionState {
  3. rounds: Set<number>;
  4. branches: Set<string>;
  5. retrievalAgents: Set<string>;
  6. }
  7. export function expandedStateFor(view: ExecutionViewV8): ExpansionState {
  8. return {
  9. rounds: new Set(view.rounds.map((round) => round.roundIndex)),
  10. branches: new Set(
  11. view.rounds.flatMap((round) =>
  12. round.branches.map((branch) => `${round.roundIndex}:${branch.branchId}`),
  13. ),
  14. ),
  15. retrievalAgents: new Set(
  16. view.rounds.flatMap((round) =>
  17. round.branches.flatMap((branch) =>
  18. branch.retrievalStage.agentRuns.map((agent) => agent.id),
  19. ),
  20. ),
  21. ),
  22. };
  23. }
  24. export function isFullyExpanded(
  25. view: ExecutionViewV8,
  26. expandedRounds: Set<number>,
  27. expandedBranches: Set<string>,
  28. expandedRetrievalAgents: Set<string>,
  29. ): boolean {
  30. const expected = expandedStateFor(view);
  31. return (
  32. [...expected.rounds].every((id) => expandedRounds.has(id))
  33. && [...expected.branches].every((id) => expandedBranches.has(id))
  34. && [...expected.retrievalAgents].every((id) => expandedRetrievalAgents.has(id))
  35. );
  36. }