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

ProjectionThreads.ts

93 lines3.1 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 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 titleRegenerationRequestId: Schema.optional(Schema.NullOr(CommandId)),
54 titleRegenerationStartedAt: Schema.optional(Schema.NullOr(IsoDateTime)),
55 latestUserMessageAt: Schema.NullOr(IsoDateTime),
56 pendingApprovalCount: NonNegativeInt,
57 pendingUserInputCount: NonNegativeInt,
58 hasActionableProposedPlan: NonNegativeInt,
59 deletedAt: Schema.NullOr(IsoDateTime),
60});
61export type ProjectionThread = typeof ProjectionThread.Type;
62​
63export const GetProjectionThreadInput = Schema.Struct({
64 threadId: ThreadId,
65});
66export type GetProjectionThreadInput = typeof GetProjectionThreadInput.Type;
67​
68/**
69 * ProjectionThreadRepositoryShape - Service API for projected thread records.
70 */
71export interface ProjectionThreadRepositoryShape {
72 /**
73 * Insert or replace a projected thread row.
74 *
75 * Upserts by `threadId`.
76 */
77 readonly upsert: (thread: ProjectionThread) => Effect.Effect<void, ProjectionRepositoryError>;
78​
79 /**
80 * Read a projected thread row by id.
81 */
82 readonly getById: (
83 input: GetProjectionThreadInput,
84 ) => Effect.Effect<Option.Option<ProjectionThread>, ProjectionRepositoryError>;
86​
87/**
88 * ProjectionThreadRepository - Service tag for thread projection persistence.
89 */
90export class ProjectionThreadRepository extends Context.Service<
91 ProjectionThreadRepository,
92 ProjectionThreadRepositoryShape
93>()("t3/persistence/Services/ProjectionThreads/ProjectionThreadRepository") {}