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

ProjectionThreadSessions.ts

80 lines2.6 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 IsoDateTime,
11 OrchestrationSessionStatus,
12 ProviderApprovalPolicy,
13 ProviderSandboxMode,
14 ProviderSessionId,
15 ProviderThreadId,
16 ThreadId,
17 TurnId,
18} from "@t3tools/contracts";
19import { Option, Schema, ServiceMap } from "effect";
20import type { Effect } from "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 providerSessionId: Schema.NullOr(ProviderSessionId),
29 providerThreadId: Schema.NullOr(ProviderThreadId),
30 approvalPolicy: ProviderApprovalPolicy,
31 sandboxMode: ProviderSandboxMode,
32 activeTurnId: Schema.NullOr(TurnId),
33 lastError: Schema.NullOr(Schema.String),
34 updatedAt: IsoDateTime,
35});
36export type ProjectionThreadSession = typeof ProjectionThreadSession.Type;
37​
38export const GetProjectionThreadSessionInput = Schema.Struct({
39 threadId: ThreadId,
40});
41export type GetProjectionThreadSessionInput = typeof GetProjectionThreadSessionInput.Type;
42​
43export const DeleteProjectionThreadSessionInput = Schema.Struct({
44 threadId: ThreadId,
45});
46export type DeleteProjectionThreadSessionInput = typeof DeleteProjectionThreadSessionInput.Type;
47​
48/**
49 * ProjectionThreadSessionRepositoryShape - Service API for projected thread sessions.
50 */
51export interface ProjectionThreadSessionRepositoryShape {
52 /**
53 * Insert or replace a projected thread-session row.
54 *
55 * Upserts by `threadId`.
56 */
57 readonly upsert: (row: ProjectionThreadSession) => Effect.Effect<void, ProjectionRepositoryError>;
58​
59 /**
60 * Read projected thread-session state by thread id.
61 */
62 readonly getByThreadId: (
63 input: GetProjectionThreadSessionInput,
64 ) => Effect.Effect<Option.Option<ProjectionThreadSession>, ProjectionRepositoryError>;
65​
66 /**
67 * Delete projected thread-session state by thread id.
68 */
69 readonly deleteByThreadId: (
70 input: DeleteProjectionThreadSessionInput,
71 ) => Effect.Effect<void, ProjectionRepositoryError>;
73​
74/**
75 * ProjectionThreadSessionRepository - Service tag for thread-session persistence.
76 */
77export class ProjectionThreadSessionRepository extends ServiceMap.Service<
78 ProjectionThreadSessionRepository,
79 ProjectionThreadSessionRepositoryShape
80>()("t3/persistence/Services/ProjectionThreadSessions/ProjectionThreadSessionRepository") {}