Co-authored-by: Claude Opus 4.7 <[email protected]> Co-authored-by: codex <[email protected]>
91 lines
3.0 KiB
TypeScript
91 lines
3.0 KiB
TypeScript
/**
|
|
* ProviderSessionRuntimeRepository - Repository interface for provider runtime sessions.
|
|
*
|
|
* Owns persistence operations for provider runtime metadata and resume cursors.
|
|
*
|
|
* @module ProviderSessionRuntimeRepository
|
|
*/
|
|
import {
|
|
IsoDateTime,
|
|
ProviderInstanceId,
|
|
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,
|
|
/**
|
|
* User-defined routing key for the configured provider instance that
|
|
* owns this session. Nullable only at the storage/migration boundary:
|
|
* rows persisted before the driver/instance split carry only
|
|
* `providerName`. Repository consumers must materialize a concrete
|
|
* instance id before routing.
|
|
*/
|
|
providerInstanceId: Schema.NullOr(ProviderInstanceId),
|
|
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<void, ProviderSessionRuntimeRepositoryError>;
|
|
|
|
/**
|
|
* Read provider runtime state by canonical thread id.
|
|
*/
|
|
readonly getByThreadId: (
|
|
input: GetProviderSessionRuntimeInput,
|
|
) => Effect.Effect<Option.Option<ProviderSessionRuntime>, ProviderSessionRuntimeRepositoryError>;
|
|
|
|
/**
|
|
* List all provider runtime rows.
|
|
*
|
|
* Returned in ascending last-seen order.
|
|
*/
|
|
readonly list: () => Effect.Effect<
|
|
ReadonlyArray<ProviderSessionRuntime>,
|
|
ProviderSessionRuntimeRepositoryError
|
|
>;
|
|
|
|
/**
|
|
* Delete provider runtime state by canonical thread id.
|
|
*/
|
|
readonly deleteByThreadId: (
|
|
input: DeleteProviderSessionRuntimeInput,
|
|
) => Effect.Effect<void, ProviderSessionRuntimeRepositoryError>;
|
|
}
|
|
|
|
/**
|
|
* ProviderSessionRuntimeRepository - Service tag for provider runtime persistence.
|
|
*/
|
|
export class ProviderSessionRuntimeRepository extends Context.Service<
|
|
ProviderSessionRuntimeRepository,
|
|
ProviderSessionRuntimeRepositoryShape
|
|
>()("t3/persistence/Services/ProviderSessionRuntime/ProviderSessionRuntimeRepository") {}
|