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