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

ProjectionThreads.ts

110 lines3.4 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 titleRegenerationRequestId: Schema.optional(Schema.NullOr(CommandId)),
45 titleRegenerationStartedAt: Schema.optional(Schema.NullOr(IsoDateTime)),
46 latestUserMessageAt: Schema.NullOr(IsoDateTime),
47 pendingApprovalCount: NonNegativeInt,
48 pendingUserInputCount: NonNegativeInt,
49 hasActionableProposedPlan: NonNegativeInt,
50 deletedAt: Schema.NullOr(IsoDateTime),
51});
52export type ProjectionThread = typeof ProjectionThread.Type;
53​
54export const GetProjectionThreadInput = Schema.Struct({
55 threadId: ThreadId,
56});
57export type GetProjectionThreadInput = typeof GetProjectionThreadInput.Type;
58​
59export const DeleteProjectionThreadInput = Schema.Struct({
60 threadId: ThreadId,
61});
62export type DeleteProjectionThreadInput = typeof DeleteProjectionThreadInput.Type;
63​
64export const ListProjectionThreadsByProjectInput = Schema.Struct({
65 projectId: ProjectId,
66});
67export type ListProjectionThreadsByProjectInput = typeof ListProjectionThreadsByProjectInput.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 * List projected threads for a project.
89 *
90 * Returned in deterministic creation order.
91 */
92 readonly listByProjectId: (
93 input: ListProjectionThreadsByProjectInput,
94 ) => Effect.Effect<ReadonlyArray<ProjectionThread>, ProjectionRepositoryError>;
95​
96 /**
97 * Soft-delete a projected thread row by id.
98 */
99 readonly deleteById: (
100 input: DeleteProjectionThreadInput,
101 ) => Effect.Effect<void, ProjectionRepositoryError>;
103​
104/**
105 * ProjectionThreadRepository - Service tag for thread projection persistence.
106 */
107export class ProjectionThreadRepository extends Context.Service<
108 ProjectionThreadRepository,
109 ProjectionThreadRepositoryShape
110>()("t3/persistence/Services/ProjectionThreads/ProjectionThreadRepository") {}