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 activeOrderKey: Schema.optional(Schema.NullOr(Schema.String)),
51 titleRegenerationRequestId: Schema.optional(Schema.NullOr(CommandId)),
52 titleRegenerationStartedAt: Schema.optional(Schema.NullOr(IsoDateTime)),
53 latestUserMessageAt: Schema.NullOr(IsoDateTime),
54 pendingApprovalCount: NonNegativeInt,
55 pendingUserInputCount: NonNegativeInt,
56 hasActionableProposedPlan: NonNegativeInt,
57 deletedAt: Schema.NullOr(IsoDateTime),
58});
59export type ProjectionThread = typeof ProjectionThread.Type;
60
61export const GetProjectionThreadInput = Schema.Struct({
62 threadId: ThreadId,
63});
64export type GetProjectionThreadInput = typeof GetProjectionThreadInput.Type;
65
66export const DeleteProjectionThreadInput = Schema.Struct({
67 threadId: ThreadId,
68});
69export type DeleteProjectionThreadInput = typeof DeleteProjectionThreadInput.Type;
70
71export const ListProjectionThreadsByProjectInput = Schema.Struct({
72 projectId: ProjectId,
73});
74export type ListProjectionThreadsByProjectInput = typeof ListProjectionThreadsByProjectInput.Type;
75
76/**
77 * ProjectionThreadRepositoryShape - Service API for projected thread records.
78 */
79export interface ProjectionThreadRepositoryShape {
80 /**
81 * Insert or replace a projected thread row.
82 *
83 * Upserts by `threadId`.
84 */
85 readonly upsert: (thread: ProjectionThread) => Effect.Effect<void, ProjectionRepositoryError>;
86
87 /**
88 * Read a projected thread row by id.
89 */
90 readonly getById: (
91 input: GetProjectionThreadInput,
92 ) => Effect.Effect<Option.Option<ProjectionThread>, ProjectionRepositoryError>;
93
94 /**
95 * List projected threads for a project.
96 *
97 * Returned in deterministic creation order.
98 */
99 readonly listByProjectId: (
100 input: ListProjectionThreadsByProjectInput,
101 ) => Effect.Effect<ReadonlyArray<ProjectionThread>, ProjectionRepositoryError>;
102
103 /**
104 * Soft-delete a projected thread row by id.
105 */
106 readonly deleteById: (
107 input: DeleteProjectionThreadInput,
108 ) => Effect.Effect<void, ProjectionRepositoryError>;
109}
110
111/**
112 * ProjectionThreadRepository - Service tag for thread projection persistence.
113 */
114export class ProjectionThreadRepository extends Context.Service<
115 ProjectionThreadRepository,
116 ProjectionThreadRepositoryShape
117>()("t3/persistence/Services/ProjectionThreads/ProjectionThreadRepository") {}