Open History to see the last commit
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 readonly refreshWorkspaceSnapshot: (input: {
52 readonly instanceId: ProviderInstanceId;
53 readonly cwd: string;
54 }) => Effect.Effect<ReadonlyArray<ServerProvider>>;
55
56 /**
57 * Resolve the maintenance capabilities owned by one live provider instance.
58 * Falls back to manual-only capabilities when the instance is not live.
59 * `fresh` re-derives ownership from the executable instead of the cache.
60 */
61 readonly getProviderMaintenanceCapabilitiesForInstance: (
62 instanceId: ProviderInstanceId,
63 provider: ProviderDriverKind,
64 options?: { readonly fresh?: boolean },
65 ) => Effect.Effect<ProviderMaintenanceCapabilities>;
66
67 /**
68 * Apply volatile maintenance-action state to one configured instance.
69 * This state is never persisted to disk. Today only update actions are
70 * projected onto `ServerProvider.updateState`; install/auth actions can
71 * extend this action map without adding driver-scoped APIs.
72 */
73 readonly setProviderMaintenanceActionState: (input: {
74 readonly instanceId: ProviderInstanceId;
75 readonly action: ProviderMaintenanceActionKind;
76 readonly state: ServerProviderUpdateState | null;
77 }) => Effect.Effect<ReadonlyArray<ServerProvider>>;
78
79 /**
80 * Stream of provider snapshot updates — one emission per aggregated
81 * change. The array contains the full current state.
82 */
83 readonly streamChanges: Stream.Stream<ReadonlyArray<ServerProvider>>;
84}
85
86export class ProviderRegistry extends Context.Service<ProviderRegistry, ProviderRegistryShape>()(
87 "t3/provider/Services/ProviderRegistry",
88) {}