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

ProviderSessionRuntime.ts

81 lines2.6 KB

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 ProviderSessionRuntimeStatus,
11 RuntimeMode,
12 ThreadId,
13} from "@t3tools/contracts";
14import { Option, Schema, ServiceMap } from "effect";
15import type { Effect } from "effect";
16​
17import type { ProviderSessionRuntimeRepositoryError } from "../Errors.ts";
18​
19export const ProviderSessionRuntime = Schema.Struct({
20 threadId: ThreadId,
21 providerName: Schema.String,
22 adapterKey: Schema.String,
23 runtimeMode: RuntimeMode,
24 status: ProviderSessionRuntimeStatus,
25 lastSeenAt: IsoDateTime,
26 resumeCursor: Schema.NullOr(Schema.Unknown),
27 runtimePayload: Schema.NullOr(Schema.Unknown),
28});
29export type ProviderSessionRuntime = typeof ProviderSessionRuntime.Type;
30​
31export const GetProviderSessionRuntimeInput = Schema.Struct({ threadId: ThreadId });
32export type GetProviderSessionRuntimeInput = typeof GetProviderSessionRuntimeInput.Type;
33​
34export const DeleteProviderSessionRuntimeInput = Schema.Struct({ threadId: ThreadId });
35export type DeleteProviderSessionRuntimeInput = typeof DeleteProviderSessionRuntimeInput.Type;
36​
37/**
38 * ProviderSessionRuntimeRepositoryShape - Service API for provider runtime records.
39 */
40export interface ProviderSessionRuntimeRepositoryShape {
41 /**
42 * Insert or replace a provider runtime row.
43 *
44 * Upserts by canonical `threadId`, including JSON payload/cursor fields.
45 */
46 readonly upsert: (
47 runtime: ProviderSessionRuntime,
48 ) => Effect.Effect<void, ProviderSessionRuntimeRepositoryError>;
49​
50 /**
51 * Read provider runtime state by canonical thread id.
52 */
53 readonly getByThreadId: (
54 input: GetProviderSessionRuntimeInput,
55 ) => Effect.Effect<Option.Option<ProviderSessionRuntime>, ProviderSessionRuntimeRepositoryError>;
56​
57 /**
58 * List all provider runtime rows.
59 *
60 * Returned in ascending last-seen order.
61 */
62 readonly list: () => Effect.Effect<
63 ReadonlyArray<ProviderSessionRuntime>,
64 ProviderSessionRuntimeRepositoryError
65 >;
66​
67 /**
68 * Delete provider runtime state by canonical thread id.
69 */
70 readonly deleteByThreadId: (
71 input: DeleteProviderSessionRuntimeInput,
72 ) => Effect.Effect<void, ProviderSessionRuntimeRepositoryError>;
74​
75/**
76 * ProviderSessionRuntimeRepository - Service tag for provider runtime persistence.
77 */
78export class ProviderSessionRuntimeRepository extends ServiceMap.Service<
79 ProviderSessionRuntimeRepository,
80 ProviderSessionRuntimeRepositoryShape
81>()("t3/persistence/Services/ProviderSessionRuntime/ProviderSessionRuntimeRepository") {}