Open History to see the last commit
1/**
2 * ProviderSessionRuntimeRepository - Repository interface for provider runtime sessions.
3 *
4 * Owns persistence operations for provider runtime metadata and resume cursors.
5 *
6 * @module ProviderSessionRuntimeRepository
7 */
8import {
9 IsoDateTime,
10 ProviderSessionId,
11 ProviderSessionRuntimeStatus,
12 ProviderThreadId,
13 ThreadId,
14} from "@t3tools/contracts";
15import { Option, Schema, ServiceMap } from "effect";
16import type { Effect } from "effect";
17
18import type { ProviderSessionRuntimeRepositoryError } from "../Errors.ts";
19
20export const ProviderSessionRuntime = Schema.Struct({
21 providerSessionId: ProviderSessionId,
22 threadId: ThreadId,
23 providerName: Schema.String,
24 adapterKey: Schema.String,
25 providerThreadId: Schema.NullOr(ProviderThreadId),
26 status: ProviderSessionRuntimeStatus,
27 lastSeenAt: IsoDateTime,
28 resumeCursor: Schema.NullOr(Schema.Unknown),
29 runtimePayload: Schema.NullOr(Schema.Unknown),
30});
31export type ProviderSessionRuntime = typeof ProviderSessionRuntime.Type;
32
33export const GetProviderSessionRuntimeInput = Schema.Struct({
34 providerSessionId: ProviderSessionId,
35});
36export type GetProviderSessionRuntimeInput = typeof GetProviderSessionRuntimeInput.Type;
37
38export const DeleteProviderSessionRuntimeInput = Schema.Struct({
39 providerSessionId: ProviderSessionId,
40});
41export type DeleteProviderSessionRuntimeInput = typeof DeleteProviderSessionRuntimeInput.Type;
42
43/**
44 * ProviderSessionRuntimeRepositoryShape - Service API for provider runtime records.
45 */
46export interface ProviderSessionRuntimeRepositoryShape {
47 /**
48 * Insert or replace a provider runtime row.
49 *
50 * Upserts by `providerSessionId`, including JSON payload/cursor fields.
51 */
52 readonly upsert: (
53 runtime: ProviderSessionRuntime,
54 ) => Effect.Effect<void, ProviderSessionRuntimeRepositoryError>;
55
56 /**
57 * Read provider runtime state by provider session id.
58 */
59 readonly getBySessionId: (
60 input: GetProviderSessionRuntimeInput,
61 ) => Effect.Effect<Option.Option<ProviderSessionRuntime>, ProviderSessionRuntimeRepositoryError>;
62
63 /**
64 * List all provider runtime rows.
65 *
66 * Returned in ascending last-seen order.
67 */
68 readonly list: () => Effect.Effect<
69 ReadonlyArray<ProviderSessionRuntime>,
70 ProviderSessionRuntimeRepositoryError
71 >;
72
73 /**
74 * Delete provider runtime state by provider session id.
75 */
76 readonly deleteBySessionId: (
77 input: DeleteProviderSessionRuntimeInput,
78 ) => Effect.Effect<void, ProviderSessionRuntimeRepositoryError>;
79}
80
81/**
82 * ProviderSessionRuntimeRepository - Service tag for provider runtime persistence.
83 */
84export class ProviderSessionRuntimeRepository extends ServiceMap.Service<
85 ProviderSessionRuntimeRepository,
86 ProviderSessionRuntimeRepositoryShape
87>()("t3/persistence/Services/ProviderSessionRuntime/ProviderSessionRuntimeRepository") {}