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