Files
t3code/apps/server/src/checkpointing/Utils.ts
T
2026-10-05 13:15:14 -07:00

29 lines
897 B
TypeScript

import * as Base64Url from "effect/encoding/Base64Url";
import { CheckpointRef, ProjectId, type ThreadId } from "@t3tools/contracts";
const CHECKPOINT_REFS_PREFIX = "refs/t3/checkpoints";
export function checkpointRefForThreadTurn(threadId: ThreadId, turnCount: number): CheckpointRef {
return CheckpointRef.make(
`${CHECKPOINT_REFS_PREFIX}/${Base64Url.encode(threadId)}/turn/${turnCount}`,
);
}
function resolveThreadWorkspaceCwd(input: {
readonly thread: {
readonly projectId: ProjectId;
readonly worktreePath: string | null;
};
readonly projects: ReadonlyArray<{
readonly id: ProjectId;
readonly workspaceRoot: string;
}>;
}): string | undefined {
const worktreeCwd = input.thread.worktreePath ?? undefined;
if (worktreeCwd) {
return worktreeCwd;
}
return input.projects.find((project) => project.id === input.thread.projectId)?.workspaceRoot;
}