1import type { EnvironmentId, ThreadId } from "@t3tools/contracts";
2
3export interface CheckpointDiffTarget {
4 readonly environmentId: EnvironmentId | null;
5 readonly threadId: ThreadId | null;
6 readonly fromTurnCount: number | null;
7 readonly toTurnCount: number | null;
8 readonly ignoreWhitespace: boolean;
9}
10
11export function normalizeComposerPathSearchQuery(query: string | null): string {
12 return query?.trim() ?? "";
13}
14
15export function buildCheckpointDiffTargets(target: CheckpointDiffTarget) {
16 if (
17 target.environmentId === null ||
18 target.threadId === null ||
19 target.fromTurnCount === null ||
20 target.toTurnCount === null
21 ) {
22 return { fullThread: null, turn: null } as const;
23 }
24
25 if (target.fromTurnCount === 0) {
26 return {
27 fullThread: {
28 environmentId: target.environmentId,
29 input: {
30 threadId: target.threadId,
31 toTurnCount: target.toTurnCount,
32 ignoreWhitespace: target.ignoreWhitespace,
33 },
34 },
35 turn: null,
36 } as const;
37 }
38
39 return {
40 fullThread: null,
41 turn: {
42 environmentId: target.environmentId,
43 input: {
44 threadId: target.threadId,
45 fromTurnCount: target.fromTurnCount,
46 toTurnCount: target.toTurnCount,
47 ignoreWhitespace: target.ignoreWhitespace,
48 },
49 },
50 } as const;
51}