37 lines
1.1 KiB
TypeScript
37 lines
1.1 KiB
TypeScript
import { Encoding } from "effect";
|
|
import { CheckpointRef, ProjectId, type ThreadId } from "@t3tools/contracts";
|
|
|
|
export const CHECKPOINT_REFS_PREFIX = "refs/t3/checkpoints";
|
|
|
|
export function checkpointRefForThreadTurn(threadId: ThreadId, turnCount: number): CheckpointRef {
|
|
return CheckpointRef.makeUnsafe(
|
|
`${CHECKPOINT_REFS_PREFIX}/${Encoding.encodeBase64Url(threadId)}/turn/${turnCount}`,
|
|
);
|
|
}
|
|
|
|
function trimToNonEmpty(value: string | null | undefined): string | undefined {
|
|
const normalized = value?.trim();
|
|
return normalized && normalized.length > 0 ? normalized : undefined;
|
|
}
|
|
|
|
export 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 = trimToNonEmpty(input.thread.worktreePath);
|
|
if (worktreeCwd) {
|
|
return worktreeCwd;
|
|
}
|
|
|
|
const workspaceRoot = input.projects.find(
|
|
(project) => project.id === input.thread.projectId,
|
|
)?.workspaceRoot;
|
|
return trimToNonEmpty(workspaceRoot);
|
|
}
|