/** * ProviderRegistry - Provider snapshot service. * * Owns provider install/auth/version/model snapshots and exposes the latest * provider state to transport layers. * * @module ProviderRegistry */ import type { ProviderInstanceId, ProviderDriverKind, ServerProvider, ServerProviderUpdateState, } from "@t3tools/contracts"; import { Context } from "effect"; import type { Effect, Stream } from "effect"; import type { ProviderMaintenanceCapabilities } from "../providerMaintenance.ts"; export type ProviderMaintenanceActionKind = "update"; export interface ProviderRegistryShape { /** * Read the latest provider snapshots for every configured instance. * Multiple snapshots may share the same `provider` kind (multiple * instances of the same driver) and disambiguate via `instanceId`. */ readonly getProviders: Effect.Effect>; /** * Refresh all providers, or the default instance of the specified * kind when supplied. * * Retained for back-compat with legacy call sites (WS refresh RPC, * orchestration metrics). New code should prefer `refreshInstance`. * * @deprecated prefer `refreshInstance` for new call sites. */ readonly refresh: (provider?: ProviderDriverKind) => Effect.Effect>; /** * Refresh the specific configured instance. Returns the updated snapshot * list. When the instance id is unknown the call resolves with the * currently cached list (no error) — matching the legacy `refresh` shim * behaviour so transport layers don't have to special-case unknowns. */ readonly refreshInstance: ( instanceId: ProviderInstanceId, ) => Effect.Effect>; /** * Resolve the maintenance capabilities owned by one live provider instance. * Falls back to manual-only capabilities when the instance is not live. */ readonly getProviderMaintenanceCapabilitiesForInstance: ( instanceId: ProviderInstanceId, provider: ProviderDriverKind, ) => Effect.Effect; /** * Apply volatile maintenance-action state to one configured instance. * This state is never persisted to disk. Today only update actions are * projected onto `ServerProvider.updateState`; install/auth actions can * extend this action map without adding driver-scoped APIs. */ readonly setProviderMaintenanceActionState: (input: { readonly instanceId: ProviderInstanceId; readonly action: ProviderMaintenanceActionKind; readonly state: ServerProviderUpdateState | null; }) => Effect.Effect>; /** * Stream of provider snapshot updates — one emission per aggregated * change. The array contains the full current state. */ readonly streamChanges: Stream.Stream>; } export class ProviderRegistry extends Context.Service()( "t3/provider/Services/ProviderRegistry", ) {}