Open History to see the last commit
1/**
2 * ProjectionThreadSessionRepository - Repository interface for thread sessions.
3 *
4 * Owns persistence operations for projected provider-session linkage and
5 * runtime status for each thread.
6 *
7 * @module ProjectionThreadSessionRepository
8 */
9import {
10 RuntimeMode,
11 IsoDateTime,
12 OrchestrationSessionStatus,
13 ThreadId,
14 TurnId,
15} from "@t3tools/contracts";
16import { Option, Schema, ServiceMap } from "effect";
17import type { Effect } from "effect";
18
19import type { ProjectionRepositoryError } from "../Errors.ts";
20
21export const ProjectionThreadSession = Schema.Struct({
22 threadId: ThreadId,
23 status: OrchestrationSessionStatus,
24 providerName: Schema.NullOr(Schema.String),
25 runtimeMode: RuntimeMode,
26 activeTurnId: Schema.NullOr(TurnId),
27 lastError: Schema.NullOr(Schema.String),
28 updatedAt: IsoDateTime,
29});
30export type ProjectionThreadSession = typeof ProjectionThreadSession.Type;
31
32export const GetProjectionThreadSessionInput = Schema.Struct({
33 threadId: ThreadId,
34});
35export type GetProjectionThreadSessionInput = typeof GetProjectionThreadSessionInput.Type;
36
37export const DeleteProjectionThreadSessionInput = Schema.Struct({
38 threadId: ThreadId,
39});
40export type DeleteProjectionThreadSessionInput = typeof DeleteProjectionThreadSessionInput.Type;
41
42/**
43 * ProjectionThreadSessionRepositoryShape - Service API for projected thread sessions.
44 */
45export interface ProjectionThreadSessionRepositoryShape {
46 /**
47 * Insert or replace a projected thread-session row.
48 *
49 * Upserts by `threadId`.
50 */
51 readonly upsert: (row: ProjectionThreadSession) => Effect.Effect<void, ProjectionRepositoryError>;
52
53 /**
54 * Read projected thread-session state by thread id.
55 */
56 readonly getByThreadId: (
57 input: GetProjectionThreadSessionInput,
58 ) => Effect.Effect<Option.Option<ProjectionThreadSession>, ProjectionRepositoryError>;
59
60 /**
61 * Delete projected thread-session state by thread id.
62 */
63 readonly deleteByThreadId: (
64 input: DeleteProjectionThreadSessionInput,
65 ) => Effect.Effect<void, ProjectionRepositoryError>;
66}
67
68/**
69 * ProjectionThreadSessionRepository - Service tag for thread-session persistence.
70 */
71export class ProjectionThreadSessionRepository extends ServiceMap.Service<
72 ProjectionThreadSessionRepository,
73 ProjectionThreadSessionRepositoryShape
74>()("t3/persistence/Services/ProjectionThreadSessions/ProjectionThreadSessionRepository") {}