Open History to see the last commit
1import { EnvironmentId } from "@t3tools/contracts";
2import * as Context from "effect/Context";
3import * as Effect from "effect/Effect";
4import * as Equal from "effect/Equal";
5import * as Exit from "effect/Exit";
6import * as Layer from "effect/Layer";
7import * as Option from "effect/Option";
8import * as Ref from "effect/Ref";
9import * as Schema from "effect/Schema";
10import * as Scope from "effect/Scope";
11import * as Semaphore from "effect/Semaphore";
12import * as Stream from "effect/Stream";
13import * as SubscriptionRef from "effect/SubscriptionRef";
14
15import * as ClientCapabilities from "../platform/capabilities.ts";
16import {
17 type ConnectionCatalogEntry,
18 type ConnectionRegistration,
19 type PlatformConnectionRegistration,
20 type PrimaryConnectionRegistration,
21 SshConnectionProfile,
22 connectionRegistrationCatalogEntry,
23} from "./catalog.ts";
24import * as ConnectionCredentialStore from "./credentialStore.ts";
25import * as ConnectionProfileStore from "./profileStore.ts";
26import * as Connectivity from "./connectivity.ts";
27import type {
28 ConnectionAttemptError,
29 ConnectionTarget,
30 NetworkStatus,
31 SupervisorConnectionState,
32} from "./model.ts";
33import * as Persistence from "../platform/persistence.ts";
34import * as EnvironmentSupervisor from "./supervisor.ts";
35import * as ConnectionDriver from "./driver.ts";
36import * as ConnectionWakeups from "./wakeups.ts";
37
38const isSshConnectionProfile = Schema.is(SshConnectionProfile);
39
40export class EnvironmentNotRegisteredError extends Schema.TaggedErrorClass<EnvironmentNotRegisteredError>()(
41 "EnvironmentNotRegisteredError",
42 {
43 environmentId: EnvironmentId,
44 },
45) {
46 override get message(): string {
47 return `Environment ${this.environmentId} is not registered.`;
48 }
49}
50
51export class PlatformEnvironmentRemovalError extends Schema.TaggedErrorClass<PlatformEnvironmentRemovalError>()(
52 "PlatformEnvironmentRemovalError",
53 {
54 environmentId: EnvironmentId,
55 },
56) {
57 override get message(): string {
58 return `Platform-managed environment ${this.environmentId} cannot be removed.`;
59 }
60}
61
62export class EnvironmentRegistry extends Context.Service<
63 EnvironmentRegistry,
64 {
65 readonly entries: SubscriptionRef.SubscriptionRef<
66 ReadonlyMap<EnvironmentId, ConnectionCatalogEntry>
67 >;
68 readonly networkStatus: SubscriptionRef.SubscriptionRef<NetworkStatus>;
69 readonly start: Effect.Effect<void>;
70 readonly register: (
71 registration: ConnectionRegistration,
72 ) => Effect.Effect<void, Persistence.ConnectionPersistenceError>;
73 readonly registerPlatform: (registration: PrimaryConnectionRegistration) => Effect.Effect<void>;
74 readonly reconcilePlatform: (
75 registrations: ReadonlyArray<PlatformConnectionRegistration>,
76 ) => Effect.Effect<void>;
77 readonly remove: (
78 environmentId: EnvironmentId,
79 ) => Effect.Effect<
80 void,
81 | Persistence.ConnectionPersistenceError
82 | ConnectionAttemptError
83 | EnvironmentNotRegisteredError
84 | PlatformEnvironmentRemovalError
85 >;
86 readonly removeRelayEnvironments: () => Effect.Effect<
87 void,
88 | Persistence.ConnectionPersistenceError
89 | ConnectionAttemptError
90 | PlatformEnvironmentRemovalError
91 >;
92 readonly retryNow: (environmentId: EnvironmentId) => Effect.Effect<void>;
93 readonly state: (
94 environmentId: EnvironmentId,
95 ) => Effect.Effect<SupervisorConnectionState, EnvironmentNotRegisteredError>;
96 readonly stateChanges: (
97 environmentId: EnvironmentId,
98 ) => Stream.Stream<SupervisorConnectionState, EnvironmentNotRegisteredError>;
99 readonly run: <A, E, R>(
100 environmentId: EnvironmentId,
101 effect: Effect.Effect<A, E, R>,
102 ) => Effect.Effect<
103 A,
104 E | EnvironmentNotRegisteredError,
105 Exclude<R, EnvironmentSupervisor.EnvironmentSupervisor>
106 >;
107 readonly runStream: <A, E, R>(
108 environmentId: EnvironmentId,
109 stream: Stream.Stream<A, E, R>,
110 ) => Stream.Stream<
111 A,
112 E | EnvironmentNotRegisteredError,
113 Exclude<R, EnvironmentSupervisor.EnvironmentSupervisor>
114 >;
115 readonly followStream: <A, E, R>(
116 environmentId: EnvironmentId,
117 stream: Stream.Stream<A, E, R>,
118 ) => Stream.Stream<A, E, Exclude<R, EnvironmentSupervisor.EnvironmentSupervisor>>;
119 }
120>()("@t3tools/client-runtime/connection/registry/EnvironmentRegistry") {}
121
122interface EnvironmentServiceScope {
123 readonly entry: ConnectionCatalogEntry;
124 readonly supervisor: EnvironmentSupervisor.EnvironmentSupervisor["Service"];
125 readonly scope: Scope.Closeable;
126}
127
128export const make = Effect.gen(function* () {
129 const storage = yield* Persistence.ConnectionTargetStore;
130 const registrations = yield* Persistence.ConnectionRegistrationStore;
131 const cache = yield* Persistence.EnvironmentCacheStore;
132 const ownedDataCleanup = yield* Persistence.EnvironmentOwnedDataCleanup;
133 const profiles = yield* ConnectionProfileStore.ConnectionProfileStore;
134 const credentials = yield* ConnectionCredentialStore.ConnectionCredentialStore;
135 const connectivity = yield* Connectivity.Connectivity;
136 const driver = yield* ConnectionDriver.ConnectionDriver;
137 const wakeups = yield* ConnectionWakeups.ConnectionWakeups;
138 const ssh = yield* ClientCapabilities.SshEnvironmentGateway;
139 const persistedTargets = yield* storage.list;
140 const initialEntries = new Map(
141 yield* Effect.forEach(
142 persistedTargets,
143 Effect.fn("EnvironmentRegistry.loadCatalogEntry")(function* (target) {
144 const profile =
145 target._tag === "BearerConnectionTarget" || target._tag === "SshConnectionTarget"
146 ? yield* profiles.get(target.connectionId)
147 : Option.none();
148 return [
149 target.environmentId,
150 { target, profile } satisfies ConnectionCatalogEntry,
151 ] as const;
152 }),
153 { concurrency: "unbounded" },
154 ),
155 );
156 const entries =
157 yield* SubscriptionRef.make<ReadonlyMap<EnvironmentId, ConnectionCatalogEntry>>(initialEntries);
158 const networkStatus = yield* SubscriptionRef.make(yield* connectivity.status);
159 const serviceScopes = yield* SubscriptionRef.make<
160 ReadonlyMap<EnvironmentId, EnvironmentServiceScope>
161 >(new Map());
162 const platformEnvironmentIds = yield* Ref.make<ReadonlySet<EnvironmentId>>(new Set());
163 const persistedTargetsByEnvironment = yield* Ref.make<
164 ReadonlyMap<EnvironmentId, ConnectionTarget>
165 >(new Map(persistedTargets.map((target) => [target.environmentId, target])));
166 interface LeaseLock {
167 readonly semaphore: Semaphore.Semaphore;
168 readonly users: number;
169 }
170
171 const leaseLocks = yield* Ref.make<ReadonlyMap<EnvironmentId, LeaseLock>>(new Map());
172 const leaseLocksGuard = yield* Semaphore.make(1);
173 const started = yield* Ref.make(false);
174
175 const withLeaseLock = <A, E, R>(
176 environmentId: EnvironmentId,
177 effect: Effect.Effect<A, E, R>,
178 ): Effect.Effect<A, E, R> =>
179 Effect.acquireUseRelease(
180 leaseLocksGuard.withPermits(1)(
181 Effect.gen(function* () {
182 const current = yield* Ref.get(leaseLocks);
183 const existing = current.get(environmentId);
184 if (existing !== undefined) {
185 yield* Ref.set(
186 leaseLocks,
187 new Map(current).set(environmentId, {
188 semaphore: existing.semaphore,
189 users: existing.users + 1,
190 }),
191 );
192 return existing.semaphore;
193 }
194 const semaphore = yield* Semaphore.make(1);
195 yield* Ref.set(leaseLocks, new Map(current).set(environmentId, { semaphore, users: 1 }));
196 return semaphore;
197 }),
198 ),
199 (semaphore) => semaphore.withPermits(1)(effect),
200 (semaphore) =>
201 leaseLocksGuard.withPermits(1)(
202 Ref.update(leaseLocks, (current) => {
203 const existing = current.get(environmentId);
204 if (existing === undefined || existing.semaphore !== semaphore) {
205 return current;
206 }
207 const next = new Map(current);
208 if (existing.users === 1) {
209 next.delete(environmentId);
210 } else {
211 next.set(environmentId, {
212 semaphore,
213 users: existing.users - 1,
214 });
215 }
216 return next;
217 }),
218 ),
219 ).pipe(Effect.withSpan("EnvironmentRegistry.withLeaseLock"));
220
221 const getEntry = Effect.fn("EnvironmentRegistry.getEntry")(function* (
222 environmentId: EnvironmentId,
223 ) {
224 const entry = (yield* SubscriptionRef.get(entries)).get(environmentId);
225 if (entry === undefined) {
226 return yield* new EnvironmentNotRegisteredError({
227 environmentId,
228 });
229 }
230 return entry;
231 });
232
233 const closeServiceScope = Effect.fn("EnvironmentRegistry.closeServiceScope")(function* (
234 environmentId: EnvironmentId,
235 ) {
236 const current = yield* SubscriptionRef.get(serviceScopes);
237 const lease = current.get(environmentId);
238 if (lease === undefined) {
239 return;
240 }
241 const next = new Map(current);
242 next.delete(environmentId);
243 yield* SubscriptionRef.set(serviceScopes, next);
244 yield* Scope.close(lease.scope, Exit.void);
245 });
246
247 const createServiceScope = Effect.fn("EnvironmentRegistry.createServiceScope")(
248 (entry: ConnectionCatalogEntry) =>
249 Effect.uninterruptible(
250 Effect.gen(function* () {
251 const environmentId = entry.target.environmentId;
252 const scope = yield* Scope.make();
253 const supervisor = yield* EnvironmentSupervisor.make(entry, {
254 initiallyDesired: false,
255 }).pipe(
256 Effect.provideService(Connectivity.Connectivity, connectivity),
257 Effect.provideService(ConnectionDriver.ConnectionDriver, driver),
258 Effect.provideService(ConnectionWakeups.ConnectionWakeups, wakeups),
259 Scope.provide(scope),
260 Effect.onError(() => Scope.close(scope, Exit.void)),
261 );
262 yield* supervisor.connect;
263 yield* SubscriptionRef.update(serviceScopes, (current) => {
264 const next = new Map(current);
265 next.set(environmentId, { entry, supervisor, scope });
266 return next;
267 });
268 return supervisor;
269 }),
270 ),
271 );
272
273 const acquireSupervisor = Effect.fn("EnvironmentRegistry.acquireSupervisor")(function* (
274 environmentId: EnvironmentId,
275 ) {
276 return yield* withLeaseLock(
277 environmentId,
278 Effect.gen(function* () {
279 const entry = yield* getEntry(environmentId);
280 const existing = (yield* SubscriptionRef.get(serviceScopes)).get(environmentId);
281 if (existing !== undefined) {
282 if (Equal.equals(existing.entry, entry)) {
283 return existing.supervisor;
284 }
285 yield* closeServiceScope(environmentId);
286 }
287 return yield* createServiceScope(entry);
288 }),
289 );
290 });
291
292 const run: EnvironmentRegistry["Service"]["run"] = Effect.fn("EnvironmentRegistry.run")(
293 function* <A, E, R>(environmentId: EnvironmentId, effect: Effect.Effect<A, E, R>) {
294 const supervisor = yield* acquireSupervisor(environmentId);
295 return yield* Effect.provideService(
296 effect,
297 EnvironmentSupervisor.EnvironmentSupervisor,
298 supervisor,
299 );
300 },
301 );
302
303 const runStream: EnvironmentRegistry["Service"]["runStream"] = <A, E, R>(
304 environmentId: EnvironmentId,
305 stream: Stream.Stream<A, E, R>,
306 ) =>
307 Stream.unwrap(
308 acquireSupervisor(environmentId).pipe(
309 Effect.map((supervisor) =>
310 Stream.provideService(stream, EnvironmentSupervisor.EnvironmentSupervisor, supervisor),
311 ),
312 ),
313 );
314
315 const followStream: EnvironmentRegistry["Service"]["followStream"] = <A, E, R>(
316 environmentId: EnvironmentId,
317 stream: Stream.Stream<A, E, R>,
318 ) =>
319 Stream.concat(
320 Stream.fromEffect(SubscriptionRef.get(entries)),
321 SubscriptionRef.changes(entries),
322 ).pipe(
323 Stream.map((current) => Option.fromUndefinedOr(current.get(environmentId))),
324 Stream.changes,
325 Stream.switchMap(
326 Option.match({
327 onNone: () => Stream.empty,
328 onSome: () =>
329 Stream.unwrap(
330 acquireSupervisor(environmentId).pipe(
331 Effect.match({
332 onFailure: () => Stream.empty,
333 onSuccess: (supervisor) =>
334 Stream.provideService(
335 stream,
336 EnvironmentSupervisor.EnvironmentSupervisor,
337 supervisor,
338 ),
339 }),
340 ),
341 ),
342 }),
343 ),
344 );
345
346 const start = Effect.gen(function* () {
347 if (yield* Ref.getAndSet(started, true)) {
348 return;
349 }
350 yield* Effect.forEach(
351 persistedTargets,
352 (target) =>
353 acquireSupervisor(target.environmentId).pipe(
354 Effect.catchTag("EnvironmentNotRegisteredError", () => Effect.void),
355 ),
356 {
357 concurrency: "unbounded",
358 discard: true,
359 },
360 );
361 }).pipe(Effect.withSpan("EnvironmentRegistry.start"));
362
363 const installEntryLocked = Effect.fn("EnvironmentRegistry.installEntryLocked")(function* (
364 entry: ConnectionCatalogEntry,
365 options?: { readonly retainEquivalentRuntime?: boolean },
366 ) {
367 const target = entry.target;
368 const previous = (yield* SubscriptionRef.get(entries)).get(target.environmentId);
369 const existingScope = (yield* SubscriptionRef.get(serviceScopes)).get(target.environmentId);
370 if (
371 options?.retainEquivalentRuntime === true &&
372 previous !== undefined &&
373 Equal.equals(previous, entry) &&
374 existingScope !== undefined &&
375 Equal.equals(existingScope.entry, entry)
376 ) {
377 return;
378 }
379
380 yield* closeServiceScope(target.environmentId);
381 yield* SubscriptionRef.update(entries, (current) => {
382 const next = new Map(current);
383 next.set(target.environmentId, entry);
384 return next;
385 });
386 yield* createServiceScope(entry);
387 });
388
389 const register = Effect.fn("EnvironmentRegistry.register")(function* (
390 registration: ConnectionRegistration,
391 ) {
392 const entry = connectionRegistrationCatalogEntry(registration);
393 const environmentId = entry.target.environmentId;
394 yield* withLeaseLock(
395 environmentId,
396 Effect.gen(function* () {
397 if ((yield* Ref.get(platformEnvironmentIds)).has(environmentId)) {
398 return;
399 }
400 yield* registrations.register(registration);
401 yield* Ref.update(persistedTargetsByEnvironment, (current) => {
402 const next = new Map(current);
403 next.set(environmentId, registration.target);
404 return next;
405 });
406 yield* installEntryLocked(entry);
407 }),
408 );
409 });
410
411 const installPlatformRegistration = Effect.fn("EnvironmentRegistry.installPlatformRegistration")(
412 function* (registration: PlatformConnectionRegistration) {
413 const entry = connectionRegistrationCatalogEntry(registration);
414 const target = entry.target;
415 yield* withLeaseLock(
416 target.environmentId,
417 Effect.gen(function* () {
418 yield* Ref.update(platformEnvironmentIds, (current) => {
419 const next = new Set(current);
420 next.add(target.environmentId);
421 return next;
422 });
423
424 // Secondary desktop-local backends (e.g. a parallel WSL backend) live
425 // on their own loopback origin, so they authenticate with a bearer
426 // token instead of the primary's same-origin cookie. Stash it where
427 // the resolver's bearer broker looks it up.
428 if (registration._tag === "BearerConnectionRegistration") {
429 yield* credentials.put(registration.target.connectionId, registration.credential).pipe(
430 Effect.catch((error) =>
431 Effect.logWarning("Could not store the platform bearer credential.", {
432 environmentId: target.environmentId,
433 error,
434 }),
435 ),
436 );
437 }
438
439 const persistedTarget = (yield* Ref.get(persistedTargetsByEnvironment)).get(
440 target.environmentId,
441 );
442 if (persistedTarget !== undefined) {
443 yield* registrations.remove(persistedTarget).pipe(
444 Effect.tap(() =>
445 Ref.update(persistedTargetsByEnvironment, (current) => {
446 const next = new Map(current);
447 next.delete(target.environmentId);
448 return next;
449 }),
450 ),
451 Effect.catch((error) =>
452 Effect.logWarning(
453 "Could not remove a persisted registration shadowed by a platform environment.",
454 {
455 environmentId: target.environmentId,
456 error,
457 },
458 ),
459 ),
460 );
461 }
462
463 yield* installEntryLocked(entry, { retainEquivalentRuntime: true });
464 }),
465 );
466 },
467 );
468
469 // Tear down a platform-managed environment that the host no longer reports
470 // (e.g. the user turned the parallel WSL backend off). Platform environments
471 // bypass the user-facing `remove` guard since they are reconciled from the
472 // bootstrap rather than removed by hand.
473 const removePlatformEnvironment = Effect.fn("EnvironmentRegistry.removePlatformEnvironment")(
474 function* (environmentId: EnvironmentId) {
475 yield* withLeaseLock(
476 environmentId,
477 Effect.gen(function* () {
478 const entry = (yield* SubscriptionRef.get(entries)).get(environmentId);
479 yield* Ref.update(platformEnvironmentIds, (current) => {
480 const next = new Set(current);
481 next.delete(environmentId);
482 return next;
483 });
484 yield* closeServiceScope(environmentId);
485 yield* SubscriptionRef.update(entries, (current) => {
486 const next = new Map(current);
487 next.delete(environmentId);
488 return next;
489 });
490 if (entry !== undefined && entry.target._tag === "BearerConnectionTarget") {
491 yield* credentials.remove(entry.target.connectionId).pipe(
492 Effect.catch((error) =>
493 Effect.logWarning("Could not clear the platform bearer credential.", {
494 environmentId,
495 error,
496 }),
497 ),
498 );
499 }
500 yield* Effect.all(
501 [
502 cache.clear(environmentId).pipe(
503 Effect.catch((error) =>
504 Effect.logWarning("Could not clear cached environment data after removal.", {
505 environmentId,
506 error,
507 }),
508 ),
509 ),
510 ownedDataCleanup.clear(environmentId),
511 ],
512 { concurrency: "unbounded", discard: true },
513 );
514 }),
515 );
516 },
517 );
518
519 const registerPlatform = Effect.fn("EnvironmentRegistry.registerPlatform")(function* (
520 registration: PrimaryConnectionRegistration,
521 ) {
522 yield* installPlatformRegistration(registration);
523 });
524
525 // Reconcile the full set of platform-managed environments against what the
526 // host currently reports: add/refresh the desired ones and tear down any
527 // platform environment that disappeared (WSL toggled off, distro switched).
528 const reconcilePlatform = Effect.fn("EnvironmentRegistry.reconcilePlatform")(function* (
529 platformRegistrations: ReadonlyArray<PlatformConnectionRegistration>,
530 ) {
531 const desiredIds = new Set(
532 platformRegistrations.map((registration) => registration.target.environmentId),
533 );
534 const currentPlatformIds = yield* Ref.get(platformEnvironmentIds);
535 yield* Effect.forEach(
536 currentPlatformIds,
537 (environmentId) =>
538 desiredIds.has(environmentId) ? Effect.void : removePlatformEnvironment(environmentId),
539 { discard: true },
540 );
541 yield* Effect.forEach(platformRegistrations, installPlatformRegistration, { discard: true });
542 });
543
544 const remove = Effect.fn("EnvironmentRegistry.remove")(function* (environmentId: EnvironmentId) {
545 return yield* withLeaseLock(
546 environmentId,
547 Effect.gen(function* () {
548 if ((yield* Ref.get(platformEnvironmentIds)).has(environmentId)) {
549 return yield* new PlatformEnvironmentRemovalError({
550 environmentId,
551 });
552 }
553 const target = (yield* getEntry(environmentId)).target;
554 const profile =
555 target._tag === "BearerConnectionTarget" || target._tag === "SshConnectionTarget"
556 ? yield* profiles.get(target.connectionId)
557 : Option.none();
558
559 yield* registrations.remove(target);
560 yield* Ref.update(persistedTargetsByEnvironment, (current) => {
561 const next = new Map(current);
562 next.delete(environmentId);
563 return next;
564 });
565 yield* closeServiceScope(environmentId);
566 yield* SubscriptionRef.update(entries, (current) => {
567 const next = new Map(current);
568 next.delete(environmentId);
569 return next;
570 });
571 yield* Effect.all(
572 [
573 cache.clear(environmentId).pipe(
574 Effect.catch((error) =>
575 Effect.logWarning("Could not clear cached environment data after removal.", {
576 environmentId,
577 error,
578 }),
579 ),
580 ),
581 ownedDataCleanup.clear(environmentId),
582 ],
583 { concurrency: "unbounded", discard: true },
584 );
585
586 if (
587 target._tag === "SshConnectionTarget" &&
588 Option.isSome(profile) &&
589 isSshConnectionProfile(profile.value)
590 ) {
591 yield* ssh.disconnect(profile.value.target).pipe(
592 Effect.tapError((error) =>
593 Effect.logWarning("Could not disconnect the managed SSH environment.", {
594 environmentId,
595 error,
596 }),
597 ),
598 Effect.ignore,
599 );
600 }
601 }),
602 );
603 });
604
605 const removeRelayEnvironments = Effect.fn("EnvironmentRegistry.removeRelayEnvironments")(
606 function* () {
607 const relayEnvironmentIds = [...(yield* SubscriptionRef.get(entries)).values()]
608 .filter((entry) => entry.target._tag === "RelayConnectionTarget")
609 .map((entry) => entry.target.environmentId);
610
611 yield* Effect.forEach(
612 relayEnvironmentIds,
613 (environmentId) =>
614 remove(environmentId).pipe(
615 Effect.catchTag("EnvironmentNotRegisteredError", () => Effect.void),
616 ),
617 {
618 concurrency: "unbounded",
619 discard: true,
620 },
621 );
622 },
623 );
624
625 const retryNow = (environmentId: EnvironmentId) =>
626 acquireSupervisor(environmentId).pipe(
627 Effect.flatMap((supervisor) => supervisor.retryNow),
628 Effect.catchTag("EnvironmentNotRegisteredError", () => Effect.void),
629 Effect.withSpan("EnvironmentRegistry.retryNow"),
630 );
631 const state = Effect.fn("EnvironmentRegistry.state")(function* (environmentId: EnvironmentId) {
632 const supervisor = yield* acquireSupervisor(environmentId);
633 return yield* SubscriptionRef.get(supervisor.state);
634 });
635 const stateChanges = (environmentId: EnvironmentId) =>
636 followStream(
637 environmentId,
638 Stream.unwrap(
639 EnvironmentSupervisor.EnvironmentSupervisor.pipe(
640 Effect.map((supervisor) => SubscriptionRef.changes(supervisor.state)),
641 ),
642 ),
643 );
644
645 yield* Effect.addFinalizer(() =>
646 SubscriptionRef.get(serviceScopes).pipe(
647 Effect.flatMap((current) =>
648 Effect.forEach(current.values(), (lease) => Scope.close(lease.scope, Exit.void), {
649 concurrency: "unbounded",
650 discard: true,
651 }),
652 ),
653 ),
654 );
655 yield* connectivity.changes.pipe(
656 Stream.runForEach((status) => SubscriptionRef.set(networkStatus, status)),
657 Effect.forkScoped,
658 );
659
660 return EnvironmentRegistry.of({
661 entries,
662 networkStatus,
663 start,
664 register,
665 registerPlatform,
666 reconcilePlatform,
667 remove,
668 removeRelayEnvironments,
669 retryNow,
670 state,
671 stateChanges,
672 run,
673 runStream,
674 followStream,
675 });
676});
677
678export const layer = Layer.effect(EnvironmentRegistry, make);