/** * ProviderService - Service interface for provider sessions, turns, and checkpoints. * * Acts as the cross-provider facade used by transports (WebSocket/RPC). It * resolves provider adapters through `ProviderAdapterRegistry`, routes * session-scoped calls via `ProviderSessionDirectory`, and exposes one unified * provider event stream to callers. * * Uses Effect `ServiceMap.Service` for dependency injection and returns typed * domain errors for validation, session, codex, and checkpoint workflows. * * @module ProviderService */ import type { ProviderInterruptTurnInput, ProviderRespondToRequestInput, ProviderRuntimeEvent, ProviderSendTurnInput, ProviderSession, ProviderSessionId, ProviderSessionStartInput, ProviderStopSessionInput, ThreadId, ProviderTurnStartResult, } from "@t3tools/contracts"; import { ServiceMap } from "effect"; import type { Effect, Stream } from "effect"; import type { ProviderServiceError } from "../Errors.ts"; /** * ProviderServiceShape - Service API for provider session and turn orchestration. */ export interface ProviderServiceShape { /** * Start a provider session. */ readonly startSession: ( threadId: ThreadId, input: ProviderSessionStartInput, ) => Effect.Effect; /** * Send a provider turn. */ readonly sendTurn: ( input: ProviderSendTurnInput, ) => Effect.Effect; /** * Interrupt a running provider turn. */ readonly interruptTurn: ( input: ProviderInterruptTurnInput, ) => Effect.Effect; /** * Respond to a provider approval request. */ readonly respondToRequest: ( input: ProviderRespondToRequestInput, ) => Effect.Effect; /** * Stop a provider session. */ readonly stopSession: ( input: ProviderStopSessionInput, ) => Effect.Effect; /** * List active provider sessions. * * Aggregates runtime session lists from all registered adapters. */ readonly listSessions: () => Effect.Effect>; /** * Roll back provider conversation state by a number of turns. */ readonly rollbackConversation: (input: { readonly sessionId: ProviderSessionId; readonly numTurns: number; }) => Effect.Effect; /** * Stop all active provider sessions. * * Persisted session bindings remain so stale sessions can be resumed after * process restart. * * Runtime alias mappings are cleared as part of shutdown. */ readonly stopAll: () => Effect.Effect; /** * Canonical provider runtime event stream. * * Fan-out is owned by ProviderService (not by a standalone event-bus service). */ readonly streamEvents: Stream.Stream; } /** * ProviderService - Service tag for provider orchestration. */ export class ProviderService extends ServiceMap.Service()( "t3/provider/Services/ProviderService", ) {}