Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

ProviderRegistry.ts

81 lines3.0 KB

1/**
2 * ProviderRegistry - Provider snapshot service.
3 *
4 * Owns provider install/auth/version/model snapshots and exposes the latest
5 * provider state to transport layers.
6 *
7 * @module ProviderRegistry
8 */
9import type {
10 ProviderInstanceId,
11 ProviderDriverKind,
12 ServerProvider,
13 ServerProviderUpdateState,
14} from "@t3tools/contracts";
15import * as Context from "effect/Context";
16import type * as Effect from "effect/Effect";
17import type * as Stream from "effect/Stream";
18import type { ProviderMaintenanceCapabilities } from "../providerMaintenance.ts";
19​
20export type ProviderMaintenanceActionKind = "update";
21​
22export interface ProviderRegistryShape {
23 /**
24 * Read the latest provider snapshots for every configured instance.
25 * Multiple snapshots may share the same `provider` kind (multiple
26 * instances of the same driver) and disambiguate via `instanceId`.
27 */
28 readonly getProviders: Effect.Effect<ReadonlyArray<ServerProvider>>;
29​
30 /**
31 * Refresh all providers, or the default instance of the specified
32 * kind when supplied.
33 *
34 * Retained for back-compat with legacy call sites (WS refresh RPC,
35 * orchestration metrics). New code should prefer `refreshInstance`.
36 *
37 * @deprecated prefer `refreshInstance` for new call sites.
38 */
39 readonly refresh: (provider?: ProviderDriverKind) => Effect.Effect<ReadonlyArray<ServerProvider>>;
40​
41 /**
42 * Refresh the specific configured instance. Returns the updated snapshot
43 * list. When the instance id is unknown the call resolves with the
44 * currently cached list (no error) — matching the legacy `refresh` shim
45 * behaviour so transport layers don't have to special-case unknowns.
46 */
47 readonly refreshInstance: (
48 instanceId: ProviderInstanceId,
49 ) => Effect.Effect<ReadonlyArray<ServerProvider>>;
50​
51 /**
52 * Resolve the maintenance capabilities owned by one live provider instance.
53 * Falls back to manual-only capabilities when the instance is not live.
54 */
55 readonly getProviderMaintenanceCapabilitiesForInstance: (
56 instanceId: ProviderInstanceId,
57 provider: ProviderDriverKind,
58 ) => Effect.Effect<ProviderMaintenanceCapabilities>;
59​
60 /**
61 * Apply volatile maintenance-action state to one configured instance.
62 * This state is never persisted to disk. Today only update actions are
63 * projected onto `ServerProvider.updateState`; install/auth actions can
64 * extend this action map without adding driver-scoped APIs.
65 */
66 readonly setProviderMaintenanceActionState: (input: {
67 readonly instanceId: ProviderInstanceId;
68 readonly action: ProviderMaintenanceActionKind;
69 readonly state: ServerProviderUpdateState | null;
70 }) => Effect.Effect<ReadonlyArray<ServerProvider>>;
71​
72 /**
73 * Stream of provider snapshot updates — one emission per aggregated
74 * change. The array contains the full current state.
75 */
76 readonly streamChanges: Stream.Stream<ReadonlyArray<ServerProvider>>;
78​
79export class ProviderRegistry extends Context.Service<ProviderRegistry, ProviderRegistryShape>()(
80 "t3/provider/Services/ProviderRegistry",
81) {}