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

ProjectionThreads.ts

119 lines3.9 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 CommandId,
11 IsoDateTime,
12 ModelSelection,
13 NonNegativeInt,
14 ProjectId,
15 ProviderInteractionMode,
16 RuntimeMode,
17 ThreadLinkedPullRequest,
18 ThreadTitleState,
19 ThreadId,
20 TurnId,
21} from "@t3tools/contracts";
22import * as Option from "effect/Option";
23import * as Schema from "effect/Schema";
24import * as Context from "effect/Context";
25import type * as Effect from "effect/Effect";
26​
27import type { ProjectionRepositoryError } from "../Errors.ts";
28​
29export const ProjectionThread = Schema.Struct({
30 threadId: ThreadId,
31 projectId: ProjectId,
32 title: Schema.String,
33 titleState: Schema.optional(Schema.NullOr(ThreadTitleState)),
34 modelSelection: ModelSelection,
35 runtimeMode: RuntimeMode,
36 interactionMode: ProviderInteractionMode,
37 branch: Schema.NullOr(Schema.String),
38 worktreePath: Schema.NullOr(Schema.String),
39 linkedPullRequest: Schema.optional(Schema.NullOr(ThreadLinkedPullRequest)),
40 branchPullRequest: Schema.optional(Schema.NullOr(ThreadLinkedPullRequest)),
41 latestTurnId: Schema.NullOr(TurnId),
42 createdAt: IsoDateTime,
43 updatedAt: IsoDateTime,
44 archivedAt: Schema.NullOr(IsoDateTime),
45 settledOverride: Schema.NullOr(Schema.Literals(["settled", "active"])),
46 settledAt: Schema.NullOr(IsoDateTime),
47 unsettledAt: Schema.NullOr(IsoDateTime),
48 snoozedUntil: Schema.NullOr(IsoDateTime),
49 snoozedAt: Schema.NullOr(IsoDateTime),
50 pinnedAt: Schema.NullOr(IsoDateTime),
51 pinOrderKey: Schema.optional(Schema.NullOr(Schema.String)),
52 activeOrderKey: Schema.optional(Schema.NullOr(Schema.String)),
53 titleRegenerationRequestId: Schema.optional(Schema.NullOr(CommandId)),
54 titleRegenerationStartedAt: Schema.optional(Schema.NullOr(IsoDateTime)),
55 latestUserMessageAt: Schema.NullOr(IsoDateTime),
56 pendingApprovalCount: NonNegativeInt,
57 pendingUserInputCount: NonNegativeInt,
58 hasActionableProposedPlan: NonNegativeInt,
59 deletedAt: Schema.NullOr(IsoDateTime),
60});
61export type ProjectionThread = typeof ProjectionThread.Type;
62​
63export const GetProjectionThreadInput = Schema.Struct({
64 threadId: ThreadId,
65});
66export type GetProjectionThreadInput = typeof GetProjectionThreadInput.Type;
67​
68export const DeleteProjectionThreadInput = Schema.Struct({
69 threadId: ThreadId,
70});
71export type DeleteProjectionThreadInput = typeof DeleteProjectionThreadInput.Type;
72​
73export const ListProjectionThreadsByProjectInput = Schema.Struct({
74 projectId: ProjectId,
75});
76export type ListProjectionThreadsByProjectInput = typeof ListProjectionThreadsByProjectInput.Type;
77​
78/**
79 * ProjectionThreadRepositoryShape - Service API for projected thread records.
80 */
81export interface ProjectionThreadRepositoryShape {
82 /**
83 * Insert or replace a projected thread row.
84 *
85 * Upserts by `threadId`.
86 */
87 readonly upsert: (thread: ProjectionThread) => Effect.Effect<void, ProjectionRepositoryError>;
88​
89 /**
90 * Read a projected thread row by id.
91 */
92 readonly getById: (
93 input: GetProjectionThreadInput,
94 ) => Effect.Effect<Option.Option<ProjectionThread>, ProjectionRepositoryError>;
95​
96 /**
97 * List projected threads for a project.
98 *
99 * Returned in deterministic creation order.
100 */
101 readonly listByProjectId: (
102 input: ListProjectionThreadsByProjectInput,
103 ) => Effect.Effect<ReadonlyArray<ProjectionThread>, ProjectionRepositoryError>;
104​
105 /**
106 * Soft-delete a projected thread row by id.
107 */
108 readonly deleteById: (
109 input: DeleteProjectionThreadInput,
110 ) => Effect.Effect<void, ProjectionRepositoryError>;
112​
113/**
114 * ProjectionThreadRepository - Service tag for thread projection persistence.
115 */
116export class ProjectionThreadRepository extends Context.Service<
117 ProjectionThreadRepository,
118 ProjectionThreadRepositoryShape
119>()("t3/persistence/Services/ProjectionThreads/ProjectionThreadRepository") {}