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