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

ProjectionThreadSessions.ts

76 lines2.4 KB

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 ProviderInstanceId,
14 ThreadId,
15 TurnId,
16} from "@t3tools/contracts";
17import { Option, Schema, Context } from "effect";
18import type { Effect } from "effect";
19​
20import type { ProjectionRepositoryError } from "../Errors.ts";
21​
22export const ProjectionThreadSession = Schema.Struct({
23 threadId: ThreadId,
24 status: OrchestrationSessionStatus,
25 providerName: Schema.NullOr(Schema.String),
26 providerInstanceId: Schema.NullOr(ProviderInstanceId),
27 runtimeMode: RuntimeMode,
28 activeTurnId: Schema.NullOr(TurnId),
29 lastError: Schema.NullOr(Schema.String),
30 updatedAt: IsoDateTime,
31});
32export type ProjectionThreadSession = typeof ProjectionThreadSession.Type;
33​
34export const GetProjectionThreadSessionInput = Schema.Struct({
35 threadId: ThreadId,
36});
37export type GetProjectionThreadSessionInput = typeof GetProjectionThreadSessionInput.Type;
38​
39export const DeleteProjectionThreadSessionInput = Schema.Struct({
40 threadId: ThreadId,
41});
42export type DeleteProjectionThreadSessionInput = typeof DeleteProjectionThreadSessionInput.Type;
43​
44/**
45 * ProjectionThreadSessionRepositoryShape - Service API for projected thread sessions.
46 */
47export interface ProjectionThreadSessionRepositoryShape {
48 /**
49 * Insert or replace a projected thread-session row.
50 *
51 * Upserts by `threadId`.
52 */
53 readonly upsert: (row: ProjectionThreadSession) => Effect.Effect<void, ProjectionRepositoryError>;
54​
55 /**
56 * Read projected thread-session state by thread id.
57 */
58 readonly getByThreadId: (
59 input: GetProjectionThreadSessionInput,
60 ) => Effect.Effect<Option.Option<ProjectionThreadSession>, ProjectionRepositoryError>;
61​
62 /**
63 * Delete projected thread-session state by thread id.
64 */
65 readonly deleteByThreadId: (
66 input: DeleteProjectionThreadSessionInput,
67 ) => Effect.Effect<void, ProjectionRepositoryError>;
69​
70/**
71 * ProjectionThreadSessionRepository - Service tag for thread-session persistence.
72 */
73export class ProjectionThreadSessionRepository extends Context.Service<
74 ProjectionThreadSessionRepository,
75 ProjectionThreadSessionRepositoryShape
76>()("t3/persistence/Services/ProjectionThreadSessions/ProjectionThreadSessionRepository") {}