/** * ProviderSessionRuntimeRepository - Repository interface for provider runtime sessions. * * Owns persistence operations for provider runtime metadata and resume cursors. * * @module ProviderSessionRuntimeRepository */ import { IsoDateTime, ProviderSessionRuntimeStatus, RuntimeMode, ThreadId, } from "@t3tools/contracts"; import { Option, Schema, Context } from "effect"; import type { Effect } from "effect"; import type { ProviderSessionRuntimeRepositoryError } from "../Errors.ts"; export const ProviderSessionRuntime = Schema.Struct({ threadId: ThreadId, providerName: Schema.String, adapterKey: Schema.String, runtimeMode: RuntimeMode, status: ProviderSessionRuntimeStatus, lastSeenAt: IsoDateTime, resumeCursor: Schema.NullOr(Schema.Unknown), runtimePayload: Schema.NullOr(Schema.Unknown), }); export type ProviderSessionRuntime = typeof ProviderSessionRuntime.Type; export const GetProviderSessionRuntimeInput = Schema.Struct({ threadId: ThreadId }); export type GetProviderSessionRuntimeInput = typeof GetProviderSessionRuntimeInput.Type; export const DeleteProviderSessionRuntimeInput = Schema.Struct({ threadId: ThreadId }); export type DeleteProviderSessionRuntimeInput = typeof DeleteProviderSessionRuntimeInput.Type; /** * ProviderSessionRuntimeRepositoryShape - Service API for provider runtime records. */ export interface ProviderSessionRuntimeRepositoryShape { /** * Insert or replace a provider runtime row. * * Upserts by canonical `threadId`, including JSON payload/cursor fields. */ readonly upsert: ( runtime: ProviderSessionRuntime, ) => Effect.Effect; /** * Read provider runtime state by canonical thread id. */ readonly getByThreadId: ( input: GetProviderSessionRuntimeInput, ) => Effect.Effect, ProviderSessionRuntimeRepositoryError>; /** * List all provider runtime rows. * * Returned in ascending last-seen order. */ readonly list: () => Effect.Effect< ReadonlyArray, ProviderSessionRuntimeRepositoryError >; /** * Delete provider runtime state by canonical thread id. */ readonly deleteByThreadId: ( input: DeleteProviderSessionRuntimeInput, ) => Effect.Effect; } /** * ProviderSessionRuntimeRepository - Service tag for provider runtime persistence. */ export class ProviderSessionRuntimeRepository extends Context.Service< ProviderSessionRuntimeRepository, ProviderSessionRuntimeRepositoryShape >()("t3/persistence/Services/ProviderSessionRuntime/ProviderSessionRuntimeRepository") {}