Files
t3code/apps/server/src/persistence/Services/ProjectionThreadSessions.ts
T
Julius Marminge 8ef653fcc0 Persist required approval policy and sandbox mode for sessions
- Make `approvalPolicy` and `sandboxMode` required in orchestration contracts and turn-start flow
- Add defaults in provider reactors/ingestion to guarantee values are always set
- Store and hydrate both fields in projection persistence, snapshots, and related tests
2026-02-26 21:26:35 -08:00

81 lines
2.6 KiB
TypeScript

/**
* ProjectionThreadSessionRepository - Repository interface for thread sessions.
*
* Owns persistence operations for projected provider-session linkage and
* runtime status for each thread.
*
* @module ProjectionThreadSessionRepository
*/
import {
IsoDateTime,
OrchestrationSessionStatus,
ProviderApprovalPolicy,
ProviderSandboxMode,
ProviderSessionId,
ProviderThreadId,
ThreadId,
TurnId,
} from "@t3tools/contracts";
import { Option, Schema, ServiceMap } from "effect";
import type { Effect } from "effect";
import type { ProjectionRepositoryError } from "../Errors.ts";
export const ProjectionThreadSession = Schema.Struct({
threadId: ThreadId,
status: OrchestrationSessionStatus,
providerName: Schema.NullOr(Schema.String),
providerSessionId: Schema.NullOr(ProviderSessionId),
providerThreadId: Schema.NullOr(ProviderThreadId),
approvalPolicy: ProviderApprovalPolicy,
sandboxMode: ProviderSandboxMode,
activeTurnId: Schema.NullOr(TurnId),
lastError: Schema.NullOr(Schema.String),
updatedAt: IsoDateTime,
});
export type ProjectionThreadSession = typeof ProjectionThreadSession.Type;
export const GetProjectionThreadSessionInput = Schema.Struct({
threadId: ThreadId,
});
export type GetProjectionThreadSessionInput = typeof GetProjectionThreadSessionInput.Type;
export const DeleteProjectionThreadSessionInput = Schema.Struct({
threadId: ThreadId,
});
export type DeleteProjectionThreadSessionInput = typeof DeleteProjectionThreadSessionInput.Type;
/**
* ProjectionThreadSessionRepositoryShape - Service API for projected thread sessions.
*/
export interface ProjectionThreadSessionRepositoryShape {
/**
* Insert or replace a projected thread-session row.
*
* Upserts by `threadId`.
*/
readonly upsert: (row: ProjectionThreadSession) => Effect.Effect<void, ProjectionRepositoryError>;
/**
* Read projected thread-session state by thread id.
*/
readonly getByThreadId: (
input: GetProjectionThreadSessionInput,
) => Effect.Effect<Option.Option<ProjectionThreadSession>, ProjectionRepositoryError>;
/**
* Delete projected thread-session state by thread id.
*/
readonly deleteByThreadId: (
input: DeleteProjectionThreadSessionInput,
) => Effect.Effect<void, ProjectionRepositoryError>;
}
/**
* ProjectionThreadSessionRepository - Service tag for thread-session persistence.
*/
export class ProjectionThreadSessionRepository extends ServiceMap.Service<
ProjectionThreadSessionRepository,
ProjectionThreadSessionRepositoryShape
>()("t3/persistence/Services/ProjectionThreadSessions/ProjectionThreadSessionRepository") {}