| 1 | import { useMemo } from "react"; |
| 2 | import { deriveThreadCheckpointSummaries } from "@t3tools/client-runtime/state/thread-checkpoints"; |
| 3 | import type { OrchestrationV2ThreadProjection } from "@t3tools/contracts"; |
| 4 | import { inferCheckpointTurnCountByRunId } from "../session-logic"; |
| 5 | import type { TurnDiffSummary } from "../types"; |
| 6 | |
| 7 | export function useTurnDiffSummaries(projection: OrchestrationV2ThreadProjection | null) { |
| 8 | const turnDiffSummaries = useMemo<ReadonlyArray<TurnDiffSummary>>(() => { |
| 9 | if (projection === null) { |
| 10 | return []; |
| 11 | } |
| 12 | return deriveThreadCheckpointSummaries(projection); |
| 13 | }, [projection]); |
| 14 | |
| 15 | const inferredCheckpointTurnCountByRunId = useMemo( |
| 16 | () => inferCheckpointTurnCountByRunId(turnDiffSummaries), |
| 17 | [turnDiffSummaries], |
| 18 | ); |
| 19 | |
| 20 | return { turnDiffSummaries, inferredCheckpointTurnCountByRunId }; |
| 21 | } |