| 1 | import * as Base64Url from "effect/encoding/Base64Url"; |
| 2 | import { CheckpointRef, ProjectId, type ThreadId } from "@t3tools/contracts"; |
| 3 | |
| 4 | const CHECKPOINT_REFS_PREFIX = "refs/t3/checkpoints"; |
| 5 | |
| 6 | export function checkpointRefForThreadTurn(threadId: ThreadId, turnCount: number): CheckpointRef { |
| 7 | return CheckpointRef.make( |
| 8 | `${CHECKPOINT_REFS_PREFIX}/${Base64Url.encode(threadId)}/turn/${turnCount}`, |
| 9 | ); |
| 10 | } |
| 11 | |
| 12 | function resolveThreadWorkspaceCwd(input: { |
| 13 | readonly thread: { |
| 14 | readonly projectId: ProjectId; |
| 15 | readonly worktreePath: string | null; |
| 16 | }; |
| 17 | readonly projects: ReadonlyArray<{ |
| 18 | readonly id: ProjectId; |
| 19 | readonly workspaceRoot: string; |
| 20 | }>; |
| 21 | }): string | undefined { |
| 22 | const worktreeCwd = input.thread.worktreePath ?? undefined; |
| 23 | if (worktreeCwd) { |
| 24 | return worktreeCwd; |
| 25 | } |
| 26 | |
| 27 | return input.projects.find((project) => project.id === input.thread.projectId)?.workspaceRoot; |
| 28 | } |