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