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