109 lines · 3.1 KB · TypeScript
RawDownload
/** * 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<ProviderSession, ProviderServiceError>;   /**   * Send a provider turn.   */  readonly sendTurn: (    input: ProviderSendTurnInput,  ) => Effect.Effect<ProviderTurnStartResult, ProviderServiceError>;   /**   * Interrupt a running provider turn.   */  readonly interruptTurn: (    input: ProviderInterruptTurnInput,  ) => Effect.Effect<void, ProviderServiceError>;   /**   * Respond to a provider approval request.   */  readonly respondToRequest: (    input: ProviderRespondToRequestInput,  ) => Effect.Effect<void, ProviderServiceError>;   /**   * Stop a provider session.   */  readonly stopSession: (    input: ProviderStopSessionInput,  ) => Effect.Effect<void, ProviderServiceError>;   /**   * List active provider sessions.   *   * Aggregates runtime session lists from all registered adapters.   */  readonly listSessions: () => Effect.Effect<ReadonlyArray<ProviderSession>>;   /**   * Roll back provider conversation state by a number of turns.   */  readonly rollbackConversation: (input: {    readonly sessionId: ProviderSessionId;    readonly numTurns: number;  }) => Effect.Effect<void, ProviderServiceError>;   /**   * 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<void, ProviderServiceError>;   /**   * Canonical provider runtime event stream.   *   * Fan-out is owned by ProviderService (not by a standalone event-bus service).   */  readonly streamEvents: Stream.Stream<ProviderRuntimeEvent>;} /** * ProviderService - Service tag for provider orchestration. */export class ProviderService extends ServiceMap.Service<ProviderService, ProviderServiceShape>()(  "t3/provider/Services/ProviderService",) {}