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