Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

Utils.ts

28 lines901 Bytes

1import * as Encoding from "effect/Encoding";
2import { CheckpointRef, ProjectId, type ThreadId } from "@t3tools/contracts";
3​
4const CHECKPOINT_REFS_PREFIX = "refs/t3/checkpoints";
5​
6export function checkpointRefForThreadTurn(threadId: ThreadId, turnCount: number): CheckpointRef {
7 return CheckpointRef.make(
8 `${CHECKPOINT_REFS_PREFIX}/${Encoding.encodeBase64Url(threadId)}/turn/${turnCount}`,
9 );
11​
12export 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;