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

ProjectionThreads.ts

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