Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

ProjectionThreads.ts

111 lines3.5 KB

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