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