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