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

ProjectionThreadSessions.ts

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