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

ProjectionThreadSessions.ts

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