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

ProjectionCheckpoints.ts

97 lines2.9 KB

1/**
2 * ProjectionCheckpointRepository - Projection repository interface for checkpoints.
3 *
4 * Owns persistence operations for projected checkpoint summaries in thread
5 * timelines.
6 *
7 * @module ProjectionCheckpointRepository
8 */
9import {
10 CheckpointRef,
11 IsoDateTime,
12 MessageId,
13 NonNegativeInt,
14 ThreadId,
15 TurnId,
16} from "@t3tools/contracts";
17import {
18 OrchestrationCheckpointFile,
19 OrchestrationCheckpointStatus,
20} from "@t3tools/contracts/legacy-orchestration";
21import * as Option from "effect/Option";
22import * as Context from "effect/Context";
23import * as Schema from "effect/Schema";
24import type * as Effect from "effect/Effect";
25​
26import type { ProjectionRepositoryError } from "../Errors.ts";
27​
28export const ProjectionCheckpoint = Schema.Struct({
29 threadId: ThreadId,
30 turnId: TurnId,
31 checkpointTurnCount: NonNegativeInt,
32 checkpointRef: CheckpointRef,
33 status: OrchestrationCheckpointStatus,
34 files: Schema.Array(OrchestrationCheckpointFile),
35 assistantMessageId: Schema.NullOr(MessageId),
36 completedAt: IsoDateTime,
37});
38export type ProjectionCheckpoint = typeof ProjectionCheckpoint.Type;
39​
40export const ListByThreadIdInput = Schema.Struct({
41 threadId: ThreadId,
42});
43export type ListByThreadIdInput = typeof ListByThreadIdInput.Type;
44​
45export const GetByThreadAndTurnCountInput = Schema.Struct({
46 threadId: ThreadId,
47 checkpointTurnCount: NonNegativeInt,
48});
49export type GetByThreadAndTurnCountInput = typeof GetByThreadAndTurnCountInput.Type;
50​
51export const DeleteByThreadIdInput = Schema.Struct({
52 threadId: ThreadId,
53});
54export type DeleteByThreadIdInput = typeof DeleteByThreadIdInput.Type;
55​
56/**
57 * ProjectionCheckpointRepositoryShape - Service API for projected checkpoints.
58 */
59export interface ProjectionCheckpointRepositoryShape {
60 /**
61 * Insert or replace a projected checkpoint row.
62 *
63 * Upserts by composite key `(threadId, checkpointTurnCount)`.
64 */
65 readonly upsert: (row: ProjectionCheckpoint) => Effect.Effect<void, ProjectionRepositoryError>;
66​
67 /**
68 * List projected checkpoints for a thread.
69 *
70 * Returned in ascending checkpoint turn-count order.
71 */
72 readonly listByThreadId: (
73 input: ListByThreadIdInput,
74 ) => Effect.Effect<ReadonlyArray<ProjectionCheckpoint>, ProjectionRepositoryError>;
75​
76 /**
77 * Read a projected checkpoint by thread and turn-count key.
78 */
79 readonly getByThreadAndTurnCount: (
80 input: GetByThreadAndTurnCountInput,
81 ) => Effect.Effect<Option.Option<ProjectionCheckpoint>, ProjectionRepositoryError>;
82​
83 /**
84 * Delete projected checkpoint rows by thread.
85 */
86 readonly deleteByThreadId: (
87 input: DeleteByThreadIdInput,
88 ) => Effect.Effect<void, ProjectionRepositoryError>;
90​
91/**
92 * ProjectionCheckpointRepository - Service tag for checkpoint projection persistence.
93 */
94export class ProjectionCheckpointRepository extends Context.Service<
95 ProjectionCheckpointRepository,
96 ProjectionCheckpointRepositoryShape
97>()("t3/persistence/Services/ProjectionCheckpoints/ProjectionCheckpointRepository") {}