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