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