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

ProjectionThreadActivities.ts

78 lines2.7 KB

1/**
2 * ProjectionThreadActivityRepository - Projection repository interface for thread activity.
3 *
4 * Owns persistence operations for activity timeline entries projected from
5 * orchestration events.
6 *
7 * @module ProjectionThreadActivityRepository
8 */
9import { EventId, IsoDateTime, NonNegativeInt, ThreadId, TurnId } from "@t3tools/contracts";
10import { OrchestrationThreadActivityTone } from "@t3tools/contracts/legacy-orchestration";
11import * as Schema from "effect/Schema";
12import * as Context from "effect/Context";
13import type * as Effect from "effect/Effect";
14​
15import type { ProjectionRepositoryError } from "../Errors.ts";
16​
17export const ProjectionThreadActivity = Schema.Struct({
18 activityId: EventId,
19 threadId: ThreadId,
20 turnId: Schema.NullOr(TurnId),
21 tone: OrchestrationThreadActivityTone,
22 kind: Schema.String,
23 summary: Schema.String,
24 payload: Schema.Unknown,
25 sequence: Schema.optional(NonNegativeInt),
26 createdAt: IsoDateTime,
27});
28export type ProjectionThreadActivity = typeof ProjectionThreadActivity.Type;
29​
30export const ListProjectionThreadActivitiesInput = Schema.Struct({
31 threadId: ThreadId,
32});
33export type ListProjectionThreadActivitiesInput = typeof ListProjectionThreadActivitiesInput.Type;
34​
35export const DeleteProjectionThreadActivitiesInput = Schema.Struct({
36 threadId: ThreadId,
37});
38export type DeleteProjectionThreadActivitiesInput =
39 typeof DeleteProjectionThreadActivitiesInput.Type;
40​
41/**
42 * ProjectionThreadActivityRepositoryShape - Service API for projected thread activity.
43 */
44export interface ProjectionThreadActivityRepositoryShape {
45 /**
46 * Insert or replace a projected thread activity row.
47 *
48 * Upserts by `activityId` and JSON-encodes payload.
49 */
50 readonly upsert: (
51 row: ProjectionThreadActivity,
52 ) => Effect.Effect<void, ProjectionRepositoryError>;
53​
54 /**
55 * List projected thread activity rows for a thread.
56 *
57 * Returned in ascending runtime sequence order (or creation order when
58 * sequence is unavailable).
59 */
60 readonly listByThreadId: (
61 input: ListProjectionThreadActivitiesInput,
62 ) => Effect.Effect<ReadonlyArray<ProjectionThreadActivity>, ProjectionRepositoryError>;
63​
64 /**
65 * Delete projected thread activity rows by thread.
66 */
67 readonly deleteByThreadId: (
68 input: DeleteProjectionThreadActivitiesInput,
69 ) => Effect.Effect<void, ProjectionRepositoryError>;
71​
72/**
73 * ProjectionThreadActivityRepository - Service tag for thread activity persistence.
74 */
75export class ProjectionThreadActivityRepository extends Context.Service<
76 ProjectionThreadActivityRepository,
77 ProjectionThreadActivityRepositoryShape
78>()("t3/persistence/Services/ProjectionThreadActivities/ProjectionThreadActivityRepository") {}