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

ProjectionThreads.ts

103 lines3.1 KB

1/**
2 * ProjectionThreadRepository - Projection repository interface for threads.
3 *
4 * Owns persistence operations for projected thread records in the
5 * orchestration read model.
6 *
7 * @module ProjectionThreadRepository
8 */
9import {
10 IsoDateTime,
11 ModelSelection,
12 NonNegativeInt,
13 ProjectId,
14 ProviderInteractionMode,
15 RuntimeMode,
16 ThreadId,
17 TurnId,
18} from "@t3tools/contracts";
19import * as Option from "effect/Option";
20import * as Schema from "effect/Schema";
21import * as Context from "effect/Context";
22import type * as Effect from "effect/Effect";
23​
24import type { ProjectionRepositoryError } from "../Errors.ts";
25​
26export const ProjectionThread = Schema.Struct({
27 threadId: ThreadId,
28 projectId: ProjectId,
29 title: Schema.String,
30 modelSelection: ModelSelection,
31 runtimeMode: RuntimeMode,
32 interactionMode: ProviderInteractionMode,
33 branch: Schema.NullOr(Schema.String),
34 worktreePath: Schema.NullOr(Schema.String),
35 latestTurnId: Schema.NullOr(TurnId),
36 createdAt: IsoDateTime,
37 updatedAt: IsoDateTime,
38 archivedAt: Schema.NullOr(IsoDateTime),
39 latestUserMessageAt: Schema.NullOr(IsoDateTime),
40 pendingApprovalCount: NonNegativeInt,
41 pendingUserInputCount: NonNegativeInt,
42 hasActionableProposedPlan: NonNegativeInt,
43 deletedAt: Schema.NullOr(IsoDateTime),
44});
45export type ProjectionThread = typeof ProjectionThread.Type;
46​
47export const GetProjectionThreadInput = Schema.Struct({
48 threadId: ThreadId,
49});
50export type GetProjectionThreadInput = typeof GetProjectionThreadInput.Type;
51​
52export const DeleteProjectionThreadInput = Schema.Struct({
53 threadId: ThreadId,
54});
55export type DeleteProjectionThreadInput = typeof DeleteProjectionThreadInput.Type;
56​
57export const ListProjectionThreadsByProjectInput = Schema.Struct({
58 projectId: ProjectId,
59});
60export type ListProjectionThreadsByProjectInput = typeof ListProjectionThreadsByProjectInput.Type;
61​
62/**
63 * ProjectionThreadRepositoryShape - Service API for projected thread records.
64 */
65export interface ProjectionThreadRepositoryShape {
66 /**
67 * Insert or replace a projected thread row.
68 *
69 * Upserts by `threadId`.
70 */
71 readonly upsert: (thread: ProjectionThread) => Effect.Effect<void, ProjectionRepositoryError>;
72​
73 /**
74 * Read a projected thread row by id.
75 */
76 readonly getById: (
77 input: GetProjectionThreadInput,
78 ) => Effect.Effect<Option.Option<ProjectionThread>, ProjectionRepositoryError>;
79​
80 /**
81 * List projected threads for a project.
82 *
83 * Returned in deterministic creation order.
84 */
85 readonly listByProjectId: (
86 input: ListProjectionThreadsByProjectInput,
87 ) => Effect.Effect<ReadonlyArray<ProjectionThread>, ProjectionRepositoryError>;
88​
89 /**
90 * Soft-delete a projected thread row by id.
91 */
92 readonly deleteById: (
93 input: DeleteProjectionThreadInput,
94 ) => Effect.Effect<void, ProjectionRepositoryError>;
96​
97/**
98 * ProjectionThreadRepository - Service tag for thread projection persistence.
99 */
100export class ProjectionThreadRepository extends Context.Service<
101 ProjectionThreadRepository,
102 ProjectionThreadRepositoryShape
103>()("t3/persistence/Services/ProjectionThreads/ProjectionThreadRepository") {}