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

relayClient.ts

616 lines22.6 KB

1import * as Cache from "effect/Cache";
2import * as Clock from "effect/Clock";
3import type {
4 RelayClientInstallProgressEvent,
5 RelayClientInstallProgressStage,
6} from "@t3tools/contracts";
7import * as Config from "effect/Config";
8import * as Context from "effect/Context";
9import * as Crypto from "effect/Crypto";
10import * as Data from "effect/Data";
11import * as Duration from "effect/Duration";
12import * as Effect from "effect/Effect";
13import * as Exit from "effect/Exit";
14import * as Hex from "effect/encoding/Hex";
15import * as FileSystem from "effect/FileSystem";
16import * as Layer from "effect/Layer";
17import * as Option from "effect/Option";
18import * as Path from "effect/Path";
19import * as PlatformError from "effect/PlatformError";
20import * as Schedule from "effect/Schedule";
21import * as Semaphore from "effect/Semaphore";
22import { HttpClient, HttpClientRequest, HttpClientResponse } from "effect/http";
23import { ChildProcess, ChildProcessSpawner } from "effect/process";
24import { isWindowsRenameLock } from "./atomicWrite.ts";
25import * as HostProcess from "./HostProcess.ts";
26​
27export const CLOUDFLARED_VERSION = "2026.10.4";
28// Minimum for --output support; older connectors exit on that flag.
29export const CLOUDFLARED_MIN_VERSION = "2025.6.1";
30const CLOUDFLARED_PATH_ENV_NAME = "T3CODE_CLOUDFLARED_PATH";
31​
32const CLOUDFLARED_DOWNLOAD_TIMEOUT = "10 minutes";
33​
34export type RelayClientExecutableSource = "override" | "managed" | "path";
35​
36export type RelayClientStatus =
37 | {
38 readonly status: "available";
39 readonly executablePath: string;
40 readonly source: RelayClientExecutableSource;
41 readonly version: string;
42 }
43 | {
44 readonly status: "missing";
45 readonly version: string;
46 }
47 | {
48 readonly status: "unsupported";
49 readonly platform: NodeJS.Platform;
50 readonly arch: string;
51 readonly version: string;
52 };
53​
54export type AvailableRelayClient = Extract<RelayClientStatus, { readonly status: "available" }>;
55​
56export class RelayClientInstallError extends Data.TaggedError("RelayClientInstallError")<{
57 readonly reason:
58 | "download_failed"
59 | "invalid_checksum"
60 | "install_locked"
61 | "override_missing"
62 | "unsupported_platform"
63 | "validation_failed"
64 | "write_failed";
65 readonly message: string;
66 readonly cause?: unknown;
67}> {}
68​
69class CloudflaredCommandError extends Data.TaggedError("CloudflaredCommandError")<{
70 readonly command: string;
71 readonly exitCode: number;
72}> {}
73​
74export interface CloudflaredReleaseAsset {
75 readonly url: string;
76 readonly sha256: string;
77 readonly archive: "binary" | "tgz";
79​
80const CLOUDFLARED_RELEASE_ASSETS: Readonly<
81 Partial<Record<`${NodeJS.Platform}-${string}`, CloudflaredReleaseAsset>>
82> = {
83 "darwin-arm64": {
84 url: "https://github.com/cloudflare/cloudflared/releases/download/2026.10.4/cloudflared-darwin-arm64.tgz",
85 sha256: "68b6bc4080ac1330234db2a9002d07f98b000537a1bd531a687b660d4160fa7f",
86 archive: "tgz",
87 },
88 "darwin-x64": {
89 url: "https://github.com/cloudflare/cloudflared/releases/download/2026.10.4/cloudflared-darwin-amd64.tgz",
90 sha256: "f11fbef4207d715892331917dafd437f032cf4b7137ed64dea3008338c1c613d",
91 archive: "tgz",
92 },
93 "linux-arm64": {
94 url: "https://github.com/cloudflare/cloudflared/releases/download/2026.10.4/cloudflared-linux-arm64",
95 sha256: "2b7203b4fb0ba28a0c1e12f8855ce2c25f76d266a8d5edafac5540b6812acff6",
96 archive: "binary",
97 },
98 "linux-x64": {
99 url: "https://github.com/cloudflare/cloudflared/releases/download/2026.10.4/cloudflared-linux-amd64",
100 sha256: "ae5e8add7884b0531d66bbca4570d1de491ff6da51e4ebe7eb160cdf241d9e42",
101 archive: "binary",
102 },
103 "win32-x64": {
104 url: "https://github.com/cloudflare/cloudflared/releases/download/2026.10.4/cloudflared-windows-amd64.exe",
105 sha256: "411b16d40c8d872243efeb52c550053d00af0a8a97fbb32e730fb8aba429eaa8",
106 archive: "binary",
107 },
108 // Cloudflare publishes no Windows ARM64 build; Windows 11 on ARM runs x64 under emulation.
109 "win32-arm64": {
110 url: "https://github.com/cloudflare/cloudflared/releases/download/2026.10.4/cloudflared-windows-amd64.exe",
111 sha256: "411b16d40c8d872243efeb52c550053d00af0a8a97fbb32e730fb8aba429eaa8",
112 archive: "binary",
113 },
114};
115​
116const INSTALL_LOCK_RETRY_COUNT = 100;
117const INSTALL_LOCK_RETRY_DELAY = "100 millis";
118const INSTALL_LOCK_STALE_MS = 5 * 60 * 1_000;
119const VERSION_PROBE_TIMEOUT = "10 seconds";
120​
121const ACTIVATE_RETRY_COUNT = 40;
122const ACTIVATE_RETRY_DELAY = "250 millis";
123​
124const trimmedString = (name: string) =>
125 Config.String(name).pipe(
126 Config.option,
127 Config.map(
128 Option.flatMap((value) => {
129 const trimmed = value.trim();
130 return trimmed.length > 0 ? Option.some(trimmed) : Option.none();
131 }),
132 ),
133 );
134​
135const CloudflaredConfig = Config.all({
136 executableOverride: trimmedString(CLOUDFLARED_PATH_ENV_NAME),
137});
138​
139export interface CloudflaredRelayClientOptions {
140 readonly baseDir: string;
141 readonly releaseAsset?: CloudflaredReleaseAsset;
143​
144export interface RelayClientShape {
145 readonly resolve: Effect.Effect<RelayClientStatus>;
146 readonly install: Effect.Effect<AvailableRelayClient, RelayClientInstallError>;
147 readonly installWithProgress: (
148 report: (event: RelayClientInstallProgressEvent) => Effect.Effect<void>,
149 ) => Effect.Effect<AvailableRelayClient, RelayClientInstallError>;
150 /** Removes managed releases older than the pin, except the newest one. Call once the pin has connected. */
151 readonly pruneManagedVersions: Effect.Effect<void>;
153​
154export function isPinnedManagedRelayClient(client: AvailableRelayClient): boolean {
155 return client.source === "managed" && client.version === CLOUDFLARED_VERSION;
157​
158export class RelayClient extends Context.Service<RelayClient, RelayClientShape>()(
159 "@t3tools/shared/relayClient",
160) {}
161​
162function executableFileName(platform: NodeJS.Platform): string {
163 return platform === "win32" ? "cloudflared.exe" : "cloudflared";
165​
166function resolveReleaseAsset(
167 platform: NodeJS.Platform,
168 arch: string,
169): CloudflaredReleaseAsset | null {
170 return CLOUDFLARED_RELEASE_ASSETS[`${platform}-${arch}`] ?? null;
172​
173const VERSION_PATTERN = /\b(\d{4})\.(\d{1,2})\.(\d+)\b/u;
174​
175function parseVersion(value: string): readonly [number, number, number] | null {
176 const match = VERSION_PATTERN.exec(value);
177 return match ? [Number(match[1]), Number(match[2]), Number(match[3])] : null;
179​
180export function compareCloudflaredVersions(left: string, right: string): number {
181 const a = parseVersion(left) ?? [0, 0, 0];
182 const b = parseVersion(right) ?? [0, 0, 0];
183 return a[0] - b[0] || a[1] - b[1] || a[2] - b[2];
185​
186export function parseCloudflaredVersionOutput(output: string): string | null {
187 const version = parseVersion(output);
188 return version ? version.join(".") : null;
190​
191class VersionProbeKey extends Data.Class<{
192 readonly executablePath: string;
193 readonly size: number;
194 readonly mtimeMillis: number;
195}> {}
196​
197function isAlreadyExists(error: PlatformError.PlatformError): boolean {
198 return error.reason._tag === "AlreadyExists";
200​
201const wrapInstallFailure =
202 (
203 reason: RelayClientInstallError["reason"],
204 message: string,
205 ): (<E, R>(
206 effect: Effect.Effect<void, E, R>,
207 ) => Effect.Effect<void, RelayClientInstallError, R>) =>
208 (effect) =>
209 effect.pipe(
210 Effect.mapError(
211 (cause) =>
212 new RelayClientInstallError({
213 reason,
214 message,
215 cause,
216 }),
217 ),
218 );
219​
220export const makeCloudflaredRelayClient = Effect.fn("cloudflared.make")(function* (
221 options: CloudflaredRelayClientOptions,
222): Effect.fn.Return<
223 RelayClientShape,
224 never,
225 | ChildProcessSpawner.ChildProcessSpawner
226 | Crypto.Crypto
227 | FileSystem.FileSystem
228 | HttpClient.HttpClient
229 | Path.Path
230> {
231 const crypto = yield* Crypto.Crypto;
232 const fileSystem = yield* FileSystem.FileSystem;
233 const httpClient = yield* HttpClient.HttpClient;
234 const path = yield* Path.Path;
235 const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
236 const installSemaphore = yield* Semaphore.make(1);
237 const platform = yield* HostProcess.Platform;
238 const arch = yield* HostProcess.Architecture;
239 const releaseAsset = options.releaseAsset ?? resolveReleaseAsset(platform, arch);
240 const loadCloudflaredConfig = Effect.suspend(() => CloudflaredConfig).pipe(Effect.orDie);
241 const managedRoot = path.join(options.baseDir, "tools", "cloudflared");
242 const managedPathFor = (version: string) =>
243 path.join(managedRoot, version, `${platform}-${arch}`, executableFileName(platform));
244 const managedPath = managedPathFor(CLOUDFLARED_VERSION);
245​
246 const isExecutableFile = Effect.fn("cloudflared.isExecutableFile")(function* (
247 executablePath: string,
248 ) {
249 const info = yield* fileSystem.stat(executablePath).pipe(Effect.option);
250 if (Option.isNone(info) || info.value.type !== "File") return false;
251 return platform === "win32" || (info.value.mode & 0o111) !== 0;
252 });
253​
254 // Cache successful version probes per file revision; do not let transient failures hide valid binaries.
255 const versionCache = yield* Cache.makeWith(
256 (key: VersionProbeKey) =>
257 spawner
258 .string(
259 ChildProcess.make(key.executablePath, ["version"], { stdin: "ignore", stderr: "ignore" }),
260 )
261 .pipe(
262 Effect.map(parseCloudflaredVersionOutput),
263 Effect.timeoutOption(VERSION_PROBE_TIMEOUT),
264 Effect.map(Option.getOrNull),
265 Effect.orElseSucceed(() => null),
266 ),
267 {
268 capacity: 16,
269 timeToLive: (exit) =>
270 Exit.isSuccess(exit) && exit.value !== null ? Duration.infinity : Duration.zero,
271 },
272 );
273 const probeVersion = Effect.fn("cloudflared.probeVersion")(function* (executablePath: string) {
274 const info = yield* fileSystem.stat(executablePath).pipe(Effect.option);
275 if (Option.isNone(info) || info.value.type !== "File") return null;
276 if (platform !== "win32" && (info.value.mode & 0o111) === 0) return null;
277 return yield* Cache.get(
278 versionCache,
279 new VersionProbeKey({
280 executablePath,
281 size: Number(info.value.size),
282 mtimeMillis: Option.getOrUndefined(info.value.mtime)?.getTime() ?? 0,
283 }),
284 );
285 });
286​
287 const compatibleCandidate = Effect.fn("cloudflared.compatibleCandidate")(function* (
288 executablePath: string,
289 source: RelayClientExecutableSource,
290 expectedVersion?: string,
291 ) {
292 const version = yield* probeVersion(executablePath);
293 if (version === null || compareCloudflaredVersions(version, CLOUDFLARED_MIN_VERSION) < 0) {
294 return null;
295 }
296 if (expectedVersion !== undefined && version !== expectedVersion) {
297 yield* Effect.logWarning("Ignoring a managed relay client that reports another version", {
298 executablePath,
299 expectedVersion,
300 version,
301 });
302 return null;
303 }
304 return { status: "available", executablePath, source, version } satisfies AvailableRelayClient;
305 });
306​
307 // Newer managed folders may belong to another server; never use or prune them.
308 const olderManagedVersions = Effect.gen(function* () {
309 const entries = yield* fileSystem
310 .readDirectory(managedRoot)
311 .pipe(Effect.orElseSucceed(() => []));
312 return entries
313 .filter(
314 (entry) =>
315 parseVersion(entry) !== null &&
316 compareCloudflaredVersions(entry, CLOUDFLARED_VERSION) < 0,
317 )
318 .sort((left, right) => compareCloudflaredVersions(right, left));
319 });
320​
321 const resolvePathExecutable = Effect.gen(function* () {
322 // Read hydrated PATH directly; ConfigProvider may have cached it before fixPath.
323 const pathValue = (yield* HostProcess.Environment).PATH?.trim();
324 if (!pathValue) return null;
325 const delimiter = platform === "win32" ? ";" : ":";
326 for (const directory of pathValue.split(delimiter)) {
327 const trimmed = directory.trim().replace(/^"|"$/gu, "");
328 if (trimmed.length === 0) continue;
329 const candidate = path.join(trimmed, executableFileName(platform));
330 if (!(yield* isExecutableFile(candidate))) continue;
331 const available = yield* compatibleCandidate(candidate, "path");
332 if (available) return available;
333 yield* Effect.logWarning("Skipping an incompatible relay client on PATH", {
334 executablePath: candidate,
335 minimumVersion: CLOUDFLARED_MIN_VERSION,
336 });
337 }
338 return null;
339 });
340​
341 const missingStatus: RelayClientStatus = { status: "missing", version: CLOUDFLARED_VERSION };
342 const unsupportedStatus: RelayClientStatus = {
343 status: "unsupported",
344 platform,
345 arch,
346 version: CLOUDFLARED_VERSION,
347 };
348 const resolve: RelayClientShape["resolve"] = Effect.gen(function* () {
349 const config = yield* loadCloudflaredConfig;
350 if (Option.isSome(config.executableOverride)) {
351 const override = yield* compatibleCandidate(config.executableOverride.value, "override");
352 if (override) return override;
353 yield* Effect.logWarning(
354 `${CLOUDFLARED_PATH_ENV_NAME} must point to cloudflared ${CLOUDFLARED_MIN_VERSION} or newer`,
355 { executablePath: config.executableOverride.value },
356 );
357 return missingStatus;
358 }
359 const pinned = yield* compatibleCandidate(managedPath, "managed");
360 if (pinned) return pinned;
361 for (const version of yield* olderManagedVersions) {
362 const older = yield* compatibleCandidate(managedPathFor(version), "managed");
363 if (older) return older;
364 }
365 const pathExecutable = yield* resolvePathExecutable;
366 if (pathExecutable) return pathExecutable;
367 return releaseAsset ? missingStatus : unsupportedStatus;
368 }).pipe(Effect.withSpan("cloudflared.resolve"));
369​
370 const pruneManagedVersions: RelayClientShape["pruneManagedVersions"] = Effect.gen(function* () {
371 // Retain the newest older release for rollback or older servers that cannot redownload it.
372 for (const version of (yield* olderManagedVersions).slice(1)) {
373 // Windows cannot delete another server's running connector; retry next prune.
374 yield* fileSystem.remove(path.join(managedRoot, version), { recursive: true }).pipe(
375 Effect.tap(() => Effect.logInfo("Removed an older managed relay client", { version })),
376 Effect.catch((cause) =>
377 Effect.logDebug("Could not remove an older managed relay client", { version, cause }),
378 ),
379 );
380 }
381 }).pipe(Effect.withSpan("cloudflared.pruneManagedVersions"));
382​
383 const renameWhenUnlocked = (from: string, to: string) =>
384 fileSystem.rename(from, to).pipe(
385 Effect.retry({
386 times: ACTIVATE_RETRY_COUNT,
387 schedule: Schedule.spaced(ACTIVATE_RETRY_DELAY),
388 while: (error) => platform === "win32" && isWindowsRenameLock(error),
389 }),
390 );
391​
392 const runCommand = Effect.fn("cloudflared.runCommand")(function* (
393 command: string,
394 args: ReadonlyArray<string>,
395 ) {
396 const child = yield* spawner.spawn(
397 ChildProcess.make(command, args, {
398 shell: false,
399 stdout: "ignore",
400 stderr: "ignore",
401 }),
402 );
403 const exitCode = Number(yield* child.exitCode);
404 if (exitCode !== 0) {
405 return yield* new CloudflaredCommandError({ command, exitCode });
406 }
407 });
408​
409 const downloadAsset = Effect.fn("cloudflared.downloadAsset")(function* (
410 asset: CloudflaredReleaseAsset,
411 report: (stage: RelayClientInstallProgressStage) => Effect.Effect<void>,
412 ) {
413 yield* report("downloading");
414 const response = yield* httpClient.execute(HttpClientRequest.get(asset.url)).pipe(
415 Effect.timeout(CLOUDFLARED_DOWNLOAD_TIMEOUT),
416 Effect.flatMap(HttpClientResponse.filterStatusOk),
417 Effect.mapError(
418 (cause) =>
419 new RelayClientInstallError({
420 reason: "download_failed",
421 message: "Could not download the relay client.",
422 cause,
423 }),
424 ),
425 );
426 const bytes = new Uint8Array(
427 yield* response.arrayBuffer.pipe(
428 Effect.timeout(CLOUDFLARED_DOWNLOAD_TIMEOUT),
429 Effect.mapError(
430 (cause) =>
431 new RelayClientInstallError({
432 reason: "download_failed",
433 message: "Could not read the downloaded relay client binary.",
434 cause,
435 }),
436 ),
437 ),
438 );
439 yield* report("verifying");
440 const checksum = yield* crypto.digest("SHA-256", bytes).pipe(
441 Effect.mapError(
442 (cause) =>
443 new RelayClientInstallError({
444 reason: "validation_failed",
445 message: "Could not verify the downloaded relay client checksum.",
446 cause,
447 }),
448 ),
449 );
450 if (Hex.encode(checksum) !== asset.sha256) {
451 return yield* new RelayClientInstallError({
452 reason: "invalid_checksum",
453 message: "Downloaded relay client checksum did not match the pinned release.",
454 });
455 }
456 return bytes;
457 });
458​
459 const acquireInstallLock = Effect.fn("cloudflared.acquireInstallLock")(function* (
460 lockPath: string,
461 ) {
462 for (let attempt = 0; attempt < INSTALL_LOCK_RETRY_COUNT; attempt += 1) {
463 const acquired = yield* Effect.acquireRelease(
464 fileSystem.writeFileString(lockPath, "", { flag: "wx" }),
465 () => fileSystem.remove(lockPath, { force: true }).pipe(Effect.ignore),
466 ).pipe(
467 Effect.as(true),
468 Effect.catchIf(isAlreadyExists, () => Effect.succeed(false)),
469 );
470 if (acquired) return;
471​
472 const now = yield* Clock.currentTimeMillis;
473 const lockInfo = yield* fileSystem.stat(lockPath).pipe(Effect.option);
474 const mtime = Option.flatMap(lockInfo, (info) => info.mtime);
475 if (Option.isSome(mtime) && now - mtime.value.getTime() > INSTALL_LOCK_STALE_MS) {
476 yield* fileSystem.remove(lockPath, { force: true });
477 continue;
478 }
479 yield* Effect.sleep(INSTALL_LOCK_RETRY_DELAY);
480 }
481 return yield* new RelayClientInstallError({
482 reason: "install_locked",
483 message: "Another relay client installation is still in progress.",
484 });
485 });
486​
487 const installUnlocked = Effect.fn("cloudflared.installUnlocked")(function* (
488 report: (stage: RelayClientInstallProgressStage) => Effect.Effect<void>,
489 ) {
490 yield* report("checking");
491 const config = yield* loadCloudflaredConfig;
492 if (Option.isSome(config.executableOverride)) {
493 const override = yield* compatibleCandidate(config.executableOverride.value, "override");
494 if (override) return override;
495 return yield* new RelayClientInstallError({
496 reason: "override_missing",
497 message: `${CLOUDFLARED_PATH_ENV_NAME} must point to cloudflared ${CLOUDFLARED_MIN_VERSION} or newer.`,
498 });
499 }
500 const existing = yield* compatibleCandidate(managedPath, "managed", CLOUDFLARED_VERSION);
501 if (existing) return existing;
502 if (!releaseAsset) {
503 return yield* new RelayClientInstallError({
504 reason: "unsupported_platform",
505 message: `T3 Code does not provide a managed relay client binary for ${platform}-${arch}.`,
506 });
507 }
508​
509 const managedDirectory = path.dirname(managedPath);
510 const lockPath = `${managedPath}.lock`;
511 yield* fileSystem
512 .makeDirectory(managedDirectory, { recursive: true })
513 .pipe(
514 wrapInstallFailure("write_failed", "Could not create the relay client tool directory."),
515 );
516 yield* report("waiting_for_lock");
517 yield* acquireInstallLock(lockPath).pipe(
518 Effect.catchTags({
519 PlatformError: (cause) =>
520 Effect.fail(
521 new RelayClientInstallError({
522 reason: "write_failed",
523 message: "Could not acquire the relay client installation lock.",
524 cause,
525 }),
526 ),
527 }),
528 );
529 return yield* Effect.gen(function* () {
530 const afterLock = yield* compatibleCandidate(managedPath, "managed", CLOUDFLARED_VERSION);
531 if (afterLock) return afterLock;
532​
533 const tempDirectory = yield* fileSystem.makeTempDirectoryScoped({
534 directory: managedDirectory,
535 prefix: ".install-",
536 });
537 const archivePath = path.join(
538 tempDirectory,
539 releaseAsset.archive === "tgz" ? "cloudflared.tgz" : executableFileName(platform),
540 );
541 const download = yield* downloadAsset(releaseAsset, report);
542 yield* report("installing");
543 yield* fileSystem
544 .writeFile(archivePath, download)
545 .pipe(wrapInstallFailure("write_failed", "Could not write the relay client download."));
546​
547 const executablePath = path.join(tempDirectory, executableFileName(platform));
548 if (releaseAsset.archive === "tgz") {
549 yield* runCommand("tar", ["-xzf", archivePath, "-C", tempDirectory]).pipe(
550 wrapInstallFailure("write_failed", "Could not extract the relay client."),
551 );
552 }
553 if (platform !== "win32") {
554 yield* fileSystem
555 .chmod(executablePath, 0o755)
556 .pipe(wrapInstallFailure("write_failed", "Could not make the relay client executable."));
557 }
558 yield* report("validating");
559 // Verify the pin so mislabeled assets cannot cause repeated redownloads.
560 const installedVersion = yield* probeVersion(executablePath);
561 if (installedVersion !== CLOUDFLARED_VERSION) {
562 return yield* new RelayClientInstallError({
563 reason: "validation_failed",
564 message:
565 installedVersion === null
566 ? "The downloaded relay client binary did not run."
567 : `The downloaded relay client reports version ${installedVersion}, not ${CLOUDFLARED_VERSION}.`,
568 });
569 }
570​
571 const stagedPath = `${managedPath}.${yield* crypto.randomUUIDv4()}.tmp`;
572 yield* report("activating");
573 yield* renameWhenUnlocked(executablePath, stagedPath).pipe(
574 wrapInstallFailure("write_failed", "Could not stage the relay client."),
575 );
576 yield* renameWhenUnlocked(stagedPath, managedPath).pipe(
577 wrapInstallFailure("write_failed", "Could not activate the relay client."),
578 Effect.ensuring(fileSystem.remove(stagedPath, { force: true }).pipe(Effect.ignore)),
579 );
580 return {
581 status: "available",
582 executablePath: managedPath,
583 source: "managed",
584 version: CLOUDFLARED_VERSION,
585 } satisfies AvailableRelayClient;
586 }).pipe(
587 Effect.scoped,
588 Effect.catchIf(
589 (cause) => !(cause instanceof RelayClientInstallError),
590 (cause) =>
591 Effect.fail(
592 new RelayClientInstallError({
593 reason: "write_failed",
594 message: "Could not install the relay client.",
595 cause,
596 }),
597 ),
598 ),
599 );
600 });
601 const installWithProgress: RelayClientShape["installWithProgress"] = (report) =>
602 installSemaphore.withPermit(
603 installUnlocked((stage) =>
604 report({
605 type: "progress",
606 stage,
607 }),
608 ).pipe(Effect.scoped),
609 );
610 const install = installWithProgress(() => Effect.void);
611​
612 return RelayClient.of({ resolve, install, installWithProgress, pruneManagedVersions });
613});
614​
615export const layerCloudflared = (options: CloudflaredRelayClientOptions) =>
616 Layer.effect(RelayClient, makeCloudflaredRelayClient(options));