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

ProviderRegistry.ts

86 lines3.2 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 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 */
60 readonly getProviderMaintenanceCapabilitiesForInstance: (
61 instanceId: ProviderInstanceId,
62 provider: ProviderDriverKind,
63 ) => Effect.Effect<ProviderMaintenanceCapabilities>;
64​
65 /**
66 * Apply volatile maintenance-action state to one configured instance.
67 * This state is never persisted to disk. Today only update actions are
68 * projected onto `ServerProvider.updateState`; install/auth actions can
69 * extend this action map without adding driver-scoped APIs.
70 */
71 readonly setProviderMaintenanceActionState: (input: {
72 readonly instanceId: ProviderInstanceId;
73 readonly action: ProviderMaintenanceActionKind;
74 readonly state: ServerProviderUpdateState | null;
75 }) => Effect.Effect<ReadonlyArray<ServerProvider>>;
76​
77 /**
78 * Stream of provider snapshot updates — one emission per aggregated
79 * change. The array contains the full current state.
80 */
81 readonly streamChanges: Stream.Stream<ReadonlyArray<ServerProvider>>;
83​
84export class ProviderRegistry extends Context.Service<ProviderRegistry, ProviderRegistryShape>()(
85 "t3/provider/Services/ProviderRegistry",
86) {}