Open History to see the last commit
1import {
2 createAdvertisedEndpoint,
3 type CreateAdvertisedEndpointInput,
4} from "@t3tools/shared/advertisedEndpoint";
5import {
6 DesktopServerExposureModeSchema,
7 type AdvertisedEndpoint,
8 type AdvertisedEndpointProvider,
9 type DesktopServerExposureMode,
10 type DesktopServerExposureState,
11} from "@t3tools/contracts";
12import { isTailscaleIpv4Address, readTailscaleStatus } from "@t3tools/tailscale";
13import * as Cache from "effect/Cache";
14import * as Context from "effect/Context";
15import * as Duration from "effect/Duration";
16import * as Effect from "effect/Effect";
17import * as Layer from "effect/Layer";
18import * as Option from "effect/Option";
19import * as Ref from "effect/Ref";
20import * as Schema from "effect/Schema";
21import * as Semaphore from "effect/Semaphore";
22import * as HttpClient from "effect/http/HttpClient";
23import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
24
25import * as DesktopManagedPolicy from "../app/DesktopManagedPolicy.ts";
26import * as DesktopAppSettings from "../settings/DesktopAppSettings.ts";
27import * as DesktopConfig from "../app/DesktopConfig.ts";
28import * as DesktopNetworkInterfaces from "./DesktopNetworkInterfaces.ts";
29import { resolveTailscaleAdvertisedEndpoints } from "./tailscaleEndpointProvider.ts";
30
31const TAILSCALE_STATUS_CACHE_TTL = Duration.seconds(60);
32
33const DESKTOP_LOOPBACK_HOST = "127.0.0.1";
34const DESKTOP_LAN_BIND_HOST = "0.0.0.0";
35
36interface ResolvedDesktopServerExposure {
37 readonly mode: DesktopServerExposureMode;
38 readonly bindHost: string;
39 readonly localHttpUrl: string;
40 readonly localWsUrl: string;
41 readonly endpointUrl: string | null;
42 readonly advertisedHost: string | null;
43}
44
45interface DesktopAdvertisedEndpointInput {
46 readonly port: number;
47 readonly exposure: ResolvedDesktopServerExposure;
48 readonly customHttpsEndpointUrls?: readonly string[];
49}
50
51const DESKTOP_CORE_ENDPOINT_PROVIDER: AdvertisedEndpointProvider = {
52 id: "desktop-core",
53 label: "Desktop",
54 kind: "core",
55 isAddon: false,
56};
57
58const DESKTOP_MANUAL_ENDPOINT_PROVIDER: AdvertisedEndpointProvider = {
59 id: "manual",
60 label: "Manual",
61 kind: "manual",
62 isAddon: false,
63};
64
65const normalizeOptionalHost = (value: string | undefined): string | undefined => {
66 const normalized = value?.trim();
67 return normalized && normalized.length > 0 ? normalized : undefined;
68};
69
70const isUsableLanIpv4Address = (address: string): boolean =>
71 !address.startsWith("127.") &&
72 !address.startsWith("169.254.") &&
73 !isTailscaleIpv4Address(address);
74
75// Private bridges and VM adapters are fallbacks; host bridges can carry the real LAN address.
76const HOST_ONLY_INTERFACE =
77 /^(bridge\d|utun|ipsec|ppp|tun|tap|wg|docker|br-|veth|virbr|vmnet|vboxnet|VirtualBox|VMware)/;
78
79const isHttpsEndpointUrl = (value: string): boolean => {
80 try {
81 return new URL(value).protocol === "https:";
82 } catch {
83 return false;
84 }
85};
86
87const resolveLanAdvertisedHost = (
88 networkInterfaces: DesktopNetworkInterfaces.NetworkInterfaces,
89 explicitHost: string | undefined,
90): string | null => {
91 const normalizedExplicitHost = normalizeOptionalHost(explicitHost);
92 if (normalizedExplicitHost) {
93 return normalizedExplicitHost;
94 }
95
96 const lanAddresses = Object.entries(networkInterfaces).flatMap(([name, addresses]) =>
97 (addresses ?? [])
98 .filter(
99 (address) =>
100 !address.internal && address.family === "IPv4" && isUsableLanIpv4Address(address.address),
101 )
102 .map((address) => ({ name, address: address.address })),
103 );
104 const preferred =
105 lanAddresses.find(({ name }) => !HOST_ONLY_INTERFACE.test(name)) ?? lanAddresses[0];
106 return preferred?.address ?? null;
107};
108
109const resolveDesktopServerExposure = (input: {
110 readonly mode: DesktopServerExposureMode;
111 readonly port: number;
112 readonly networkInterfaces: DesktopNetworkInterfaces.NetworkInterfaces;
113 readonly advertisedHostOverride?: string;
114}): ResolvedDesktopServerExposure => {
115 const localHttpUrl = `http://${DESKTOP_LOOPBACK_HOST}:${input.port}`;
116 const localWsUrl = `ws://${DESKTOP_LOOPBACK_HOST}:${input.port}`;
117
118 if (input.mode === "local-only") {
119 return {
120 mode: input.mode,
121 bindHost: DESKTOP_LOOPBACK_HOST,
122 localHttpUrl,
123 localWsUrl,
124 endpointUrl: null,
125 advertisedHost: null,
126 };
127 }
128
129 const advertisedHost = resolveLanAdvertisedHost(
130 input.networkInterfaces,
131 input.advertisedHostOverride,
132 );
133
134 return {
135 mode: input.mode,
136 bindHost: DESKTOP_LAN_BIND_HOST,
137 localHttpUrl,
138 localWsUrl,
139 endpointUrl: advertisedHost ? `http://${advertisedHost}:${input.port}` : null,
140 advertisedHost,
141 };
142};
143
144const createDesktopEndpoint = (
145 input: Omit<CreateAdvertisedEndpointInput, "provider" | "source">,
146): AdvertisedEndpoint =>
147 createAdvertisedEndpoint({
148 ...input,
149 provider: DESKTOP_CORE_ENDPOINT_PROVIDER,
150 source: "desktop-core",
151 });
152
153const createManualEndpoint = (
154 input: Omit<CreateAdvertisedEndpointInput, "provider" | "source">,
155): AdvertisedEndpoint =>
156 createAdvertisedEndpoint({
157 ...input,
158 provider: DESKTOP_MANUAL_ENDPOINT_PROVIDER,
159 source: "user",
160 });
161
162const resolveDesktopCoreAdvertisedEndpoints = (
163 input: DesktopAdvertisedEndpointInput,
164): readonly AdvertisedEndpoint[] => {
165 const endpoints: AdvertisedEndpoint[] = [
166 createDesktopEndpoint({
167 id: `desktop-loopback:${input.port}`,
168 label: "This machine",
169 httpBaseUrl: input.exposure.localHttpUrl,
170 reachability: "loopback",
171 status: "available",
172 description: "Loopback endpoint for this desktop app.",
173 }),
174 ];
175
176 if (input.exposure.endpointUrl) {
177 endpoints.push(
178 createDesktopEndpoint({
179 id: `desktop-lan:${input.exposure.endpointUrl}`,
180 label: "Local network",
181 httpBaseUrl: input.exposure.endpointUrl,
182 reachability: "lan",
183 status: "available",
184 isDefault: true,
185 description: "Reachable from devices on the same network.",
186 }),
187 );
188 }
189
190 for (const customEndpointUrl of input.customHttpsEndpointUrls ?? []) {
191 try {
192 const isHttpsEndpoint = isHttpsEndpointUrl(customEndpointUrl);
193 endpoints.push(
194 createManualEndpoint({
195 id: `manual:${customEndpointUrl}`,
196 label: isHttpsEndpoint ? "Custom HTTPS" : "Custom endpoint",
197 httpBaseUrl: customEndpointUrl,
198 reachability: "public",
199 ...(isHttpsEndpoint ? ({ hostedHttpsCompatibility: "compatible" } as const) : {}),
200 status: "unknown",
201 description: isHttpsEndpoint
202 ? "User-configured HTTPS endpoint for this desktop backend."
203 : "User-configured endpoint for this desktop backend.",
204 }),
205 );
206 } catch {}
207 }
208
209 return endpoints;
210};
211
212export class DesktopServerExposureNoNetworkAddressError extends Schema.TaggedError<DesktopServerExposureNoNetworkAddressError>()(
213 "DesktopServerExposureNoNetworkAddressError",
214 {
215 port: Schema.Number,
216 },
217) {
218 override get message(): string {
219 return `No reachable network address is available for desktop network access on port ${this.port}.`;
220 }
221}
222
223export class DesktopServerExposureModePersistenceError extends Schema.TaggedError<DesktopServerExposureModePersistenceError>()(
224 "DesktopServerExposureModePersistenceError",
225 {
226 mode: DesktopServerExposureModeSchema,
227 cause: Schema.instanceOf(DesktopAppSettings.DesktopSettingsWriteError),
228 },
229) {
230 override get message(): string {
231 return `Failed to persist desktop server exposure mode ${this.mode}.`;
232 }
233}
234
235export class DesktopTailscaleServePersistenceError extends Schema.TaggedError<DesktopTailscaleServePersistenceError>()(
236 "DesktopTailscaleServePersistenceError",
237 {
238 enabled: Schema.Boolean,
239 port: Schema.NullOr(Schema.Number),
240 cause: Schema.instanceOf(DesktopAppSettings.DesktopSettingsWriteError),
241 },
242) {
243 override get message(): string {
244 return `Failed to persist desktop Tailscale Serve settings (enabled: ${this.enabled}, port: ${this.port ?? "unchanged"}).`;
245 }
246}
247
248export const DesktopServerExposureSetModeError = Schema.Union([
249 DesktopServerExposureNoNetworkAddressError,
250 DesktopServerExposureModePersistenceError,
251]);
252export type DesktopServerExposureSetModeError = typeof DesktopServerExposureSetModeError.Type;
253
254export const DesktopServerExposureError = Schema.Union([
255 DesktopServerExposureNoNetworkAddressError,
256 DesktopServerExposureModePersistenceError,
257 DesktopTailscaleServePersistenceError,
258]);
259export type DesktopServerExposureError = typeof DesktopServerExposureError.Type;
260
261export interface DesktopServerExposureBackendConfig {
262 readonly port: number;
263 readonly bindHost: string;
264 readonly httpBaseUrl: URL;
265 readonly tailscaleServeEnabled: boolean;
266 readonly tailscaleServePort: number;
267}
268
269export interface DesktopServerExposureChange {
270 readonly state: DesktopServerExposureState;
271 readonly requiresRelaunch: boolean;
272}
273
274export class DesktopServerExposure extends Context.Service<
275 DesktopServerExposure,
276 {
277 readonly getState: Effect.Effect<DesktopServerExposureState>;
278 readonly backendConfig: Effect.Effect<DesktopServerExposureBackendConfig>;
279 readonly configureFromSettings: (input: {
280 readonly port: number;
281 }) => Effect.Effect<DesktopServerExposureState>;
282 readonly setMode: (
283 mode: DesktopServerExposureMode,
284 ) => Effect.Effect<DesktopServerExposureChange, DesktopServerExposureSetModeError>;
285 readonly setTailscaleServeEnabled: (input: {
286 readonly enabled: boolean;
287 readonly port?: number;
288 }) => Effect.Effect<DesktopServerExposureChange, DesktopTailscaleServePersistenceError>;
289 readonly getAdvertisedEndpoints: Effect.Effect<readonly AdvertisedEndpoint[]>;
290 }
291>()("@t3tools/desktop/backend/DesktopServerExposure") {}
292
293interface RuntimeState {
294 readonly requestedMode: DesktopServerExposureMode;
295 readonly mode: DesktopServerExposureMode;
296 readonly port: number;
297 readonly bindHost: string;
298 readonly localHttpUrl: string;
299 readonly localWsUrl: string;
300 readonly httpBaseUrl: URL;
301 readonly endpointUrl: Option.Option<string>;
302 readonly advertisedHost: Option.Option<string>;
303 readonly tailscaleServeEnabled: boolean;
304 readonly tailscaleServePort: number;
305}
306
307interface ResolvedRuntimeState {
308 readonly state: RuntimeState;
309 readonly unavailable: boolean;
310}
311
312const initialRuntimeState = (): RuntimeState =>
313 runtimeStateFromResolvedExposure({
314 requestedMode: DesktopAppSettings.DEFAULT_DESKTOP_SETTINGS.serverExposureMode,
315 settings: DesktopAppSettings.DEFAULT_DESKTOP_SETTINGS,
316 exposure: resolveDesktopServerExposure({
317 mode: DesktopAppSettings.DEFAULT_DESKTOP_SETTINGS.serverExposureMode,
318 port: 0,
319 networkInterfaces: {},
320 }),
321 port: 0,
322 });
323
324const toContractState = (state: RuntimeState): DesktopServerExposureState => ({
325 mode: state.mode,
326 endpointUrl: Option.getOrNull(state.endpointUrl),
327 advertisedHost: Option.getOrNull(state.advertisedHost),
328 tailscaleServeEnabled: state.tailscaleServeEnabled,
329 tailscaleServePort: state.tailscaleServePort,
330});
331
332const toBackendConfig = (state: RuntimeState): DesktopServerExposureBackendConfig => ({
333 port: state.port,
334 bindHost: state.bindHost,
335 httpBaseUrl: state.httpBaseUrl,
336 tailscaleServeEnabled: state.tailscaleServeEnabled,
337 tailscaleServePort: state.tailscaleServePort,
338});
339
340const toResolvedExposure = (state: RuntimeState): ResolvedDesktopServerExposure => ({
341 mode: state.mode,
342 bindHost: state.bindHost,
343 localHttpUrl: state.localHttpUrl,
344 localWsUrl: state.localWsUrl,
345 endpointUrl: Option.getOrNull(state.endpointUrl),
346 advertisedHost: Option.getOrNull(state.advertisedHost),
347});
348
349function runtimeStateFromResolvedExposure(input: {
350 readonly requestedMode: DesktopServerExposureMode;
351 readonly settings: DesktopAppSettings.DesktopSettings;
352 readonly exposure: ResolvedDesktopServerExposure;
353 readonly port: number;
354}): RuntimeState {
355 return {
356 requestedMode: input.requestedMode,
357 mode: input.exposure.mode,
358 port: input.port,
359 bindHost: input.exposure.bindHost,
360 localHttpUrl: input.exposure.localHttpUrl,
361 localWsUrl: input.exposure.localWsUrl,
362 httpBaseUrl: new URL(input.exposure.localHttpUrl),
363 endpointUrl: Option.fromNullishOr(input.exposure.endpointUrl),
364 advertisedHost: Option.fromNullishOr(input.exposure.advertisedHost),
365 tailscaleServeEnabled: input.settings.tailscaleServeEnabled,
366 tailscaleServePort: input.settings.tailscaleServePort,
367 };
368}
369
370function resolveRuntimeState(input: {
371 readonly requestedMode: DesktopServerExposureMode;
372 readonly settings: DesktopAppSettings.DesktopSettings;
373 readonly port: number;
374 readonly networkInterfaces: DesktopNetworkInterfaces.NetworkInterfaces;
375 readonly advertisedHostOverride: Option.Option<string>;
376}): ResolvedRuntimeState {
377 const advertisedHostOverride = Option.getOrUndefined(input.advertisedHostOverride);
378 const requestedExposure = resolveDesktopServerExposure({
379 mode: input.requestedMode,
380 port: input.port,
381 networkInterfaces: input.networkInterfaces,
382 ...(advertisedHostOverride ? { advertisedHostOverride } : {}),
383 });
384 const unavailable =
385 input.requestedMode === "network-accessible" &&
386 requestedExposure.endpointUrl === null &&
387 !Object.values(input.networkInterfaces).some((addresses) =>
388 addresses?.some(
389 (address) =>
390 !address.internal && address.family === "IPv4" && isTailscaleIpv4Address(address.address),
391 ),
392 );
393 const exposure = unavailable
394 ? resolveDesktopServerExposure({
395 mode: "local-only",
396 port: input.port,
397 networkInterfaces: input.networkInterfaces,
398 ...(advertisedHostOverride ? { advertisedHostOverride } : {}),
399 })
400 : requestedExposure;
401
402 return {
403 state: runtimeStateFromResolvedExposure({
404 requestedMode: input.requestedMode,
405 settings: input.settings,
406 exposure,
407 port: input.port,
408 }),
409 unavailable,
410 };
411}
412
413// A network-accessible backend binds every interface, so a new Wi-Fi network
414// or DHCP lease changes only the address worth advertising, not the binding.
415const withCurrentAdvertisedHost = (
416 state: RuntimeState,
417 networkInterfaces: DesktopNetworkInterfaces.NetworkInterfaces,
418 advertisedHostOverride: Option.Option<string>,
419): RuntimeState => {
420 if (state.mode !== "network-accessible") {
421 return state;
422 }
423 const override = Option.getOrUndefined(advertisedHostOverride);
424 const exposure = resolveDesktopServerExposure({
425 mode: state.mode,
426 port: state.port,
427 networkInterfaces,
428 ...(override ? { advertisedHostOverride: override } : {}),
429 });
430 return {
431 ...state,
432 endpointUrl: Option.fromNullishOr(exposure.endpointUrl),
433 advertisedHost: Option.fromNullishOr(exposure.advertisedHost),
434 };
435};
436
437const tailscaleIpv4AddressKey = (
438 networkInterfaces: DesktopNetworkInterfaces.NetworkInterfaces,
439): string =>
440 [
441 ...new Set(
442 Object.values(networkInterfaces)
443 .flatMap((addresses) => addresses ?? [])
444 .filter(
445 (address) =>
446 !address.internal &&
447 address.family === "IPv4" &&
448 isTailscaleIpv4Address(address.address),
449 )
450 .map((address) => address.address),
451 ),
452 ]
453 .toSorted()
454 .join(",");
455
456const requiresBackendRelaunch = (previous: RuntimeState, next: RuntimeState): boolean =>
457 previous.port !== next.port ||
458 previous.bindHost !== next.bindHost ||
459 previous.localHttpUrl !== next.localHttpUrl;
460
461/** @public */
462export const make = Effect.gen(function* () {
463 const config = yield* DesktopConfig.DesktopConfig;
464 const networkInterfaces = yield* DesktopNetworkInterfaces.DesktopNetworkInterfaces;
465 const childProcessSpawner = yield* ChildProcessSpawner.ChildProcessSpawner;
466 const httpClient = yield* HttpClient.HttpClient;
467 const desktopSettings = yield* DesktopAppSettings.DesktopAppSettings;
468 const stateRef = yield* Ref.make(initialRuntimeState());
469 // Serialize read-persist-write changes so stale runtime state cannot overwrite another update.
470 const changePermit = yield* Semaphore.make(1);
471
472 // Key status by interface addresses so network changes bypass stale DNS and
473 // identity. Cache unchanged addresses to avoid repeated macOS TCC prompts.
474 const tailscaleStatusCache = yield* Cache.make({
475 capacity: 1,
476 timeToLive: TAILSCALE_STATUS_CACHE_TTL,
477 lookup: (_addresses: string) =>
478 readTailscaleStatus.pipe(
479 Effect.orElseSucceed(() => null),
480 Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, childProcessSpawner),
481 ),
482 });
483
484 const readNetworkInterfaces = networkInterfaces.read;
485
486 // The server refuses to bind wider than the policy's clients allow, so network access or Serve
487 // saved before the policy would keep the backend from starting. The backend runs without them;
488 // the saved choice stays for when the policy allows it.
489 const remoteAllowed = yield* (yield* DesktopManagedPolicy.DesktopManagedPolicy).read.pipe(
490 Effect.map((found) => found?.document.limits?.clients?.includes("remote") ?? true),
491 Effect.orElseSucceed(() => false),
492 );
493 const withinPolicy = (settings: DesktopAppSettings.DesktopSettings) =>
494 remoteAllowed
495 ? settings
496 : { ...settings, serverExposureMode: "local-only" as const, tailscaleServeEnabled: false };
497
498 const readCurrentState = (currentNetworkInterfaces: DesktopNetworkInterfaces.NetworkInterfaces) =>
499 Ref.get(stateRef).pipe(
500 Effect.map((state) =>
501 withCurrentAdvertisedHost(state, currentNetworkInterfaces, config.desktopLanHostOverride),
502 ),
503 );
504
505 const getState = readNetworkInterfaces.pipe(
506 Effect.flatMap(readCurrentState),
507 Effect.map(toContractState),
508 );
509 const backendConfig = Ref.get(stateRef).pipe(Effect.map(toBackendConfig));
510
511 const configureFromSettings = Effect.fn("desktop.serverExposure.configureFromSettings")(
512 function* ({ port }: { readonly port: number }) {
513 yield* Effect.annotateCurrentSpan({ port });
514 const settings = yield* desktopSettings.get;
515 const currentNetworkInterfaces = yield* readNetworkInterfaces;
516 const resolved = resolveRuntimeState({
517 requestedMode: withinPolicy(settings).serverExposureMode,
518 settings: withinPolicy(settings),
519 port,
520 networkInterfaces: currentNetworkInterfaces,
521 advertisedHostOverride: config.desktopLanHostOverride,
522 });
523 yield* Ref.set(stateRef, resolved.state);
524 return toContractState(resolved.state);
525 },
526 );
527
528 const setMode = Effect.fn("desktop.serverExposure.setMode")(function* (
529 mode: DesktopServerExposureMode,
530 ) {
531 yield* Effect.annotateCurrentSpan({ mode });
532 const previous = yield* Ref.get(stateRef);
533 const currentSettings = yield* desktopSettings.get;
534 const nextSettings = {
535 ...currentSettings,
536 serverExposureMode: mode,
537 };
538 const currentNetworkInterfaces = yield* readNetworkInterfaces;
539 const resolved = resolveRuntimeState({
540 requestedMode: withinPolicy(nextSettings).serverExposureMode,
541 settings: withinPolicy(nextSettings),
542 port: previous.port,
543 networkInterfaces: currentNetworkInterfaces,
544 advertisedHostOverride: config.desktopLanHostOverride,
545 });
546
547 if (resolved.unavailable) {
548 return yield* new DesktopServerExposureNoNetworkAddressError({ port: previous.port });
549 }
550
551 const change = yield* desktopSettings.setServerExposureMode(mode).pipe(
552 Effect.mapError(
553 (cause) =>
554 new DesktopServerExposureModePersistenceError({
555 mode,
556 cause,
557 }),
558 ),
559 );
560
561 yield* Ref.set(stateRef, resolved.state);
562 return {
563 state: toContractState(resolved.state),
564 requiresRelaunch: change.changed || requiresBackendRelaunch(previous, resolved.state),
565 };
566 }, changePermit.withPermit);
567
568 const setTailscaleServeEnabled = Effect.fn("desktop.serverExposure.setTailscaleServeEnabled")(
569 function* (input: { readonly enabled: boolean; readonly port?: number }) {
570 yield* Effect.annotateCurrentSpan({
571 enabled: input.enabled,
572 ...(input.port === undefined ? {} : { port: input.port }),
573 });
574 const result = yield* desktopSettings
575 .setTailscaleServe({
576 enabled: input.enabled,
577 port: Option.fromNullishOr(input.port),
578 })
579 .pipe(
580 Effect.mapError(
581 (cause) =>
582 new DesktopTailscaleServePersistenceError({
583 enabled: input.enabled,
584 port: input.port ?? null,
585 cause,
586 }),
587 ),
588 );
589
590 const nextState = yield* Ref.updateAndGet(stateRef, (current) => ({
591 ...current,
592 tailscaleServeEnabled: withinPolicy(result.settings).tailscaleServeEnabled,
593 tailscaleServePort: result.settings.tailscaleServePort,
594 }));
595
596 return {
597 state: toContractState(nextState),
598 requiresRelaunch: result.changed,
599 };
600 },
601 changePermit.withPermit,
602 );
603
604 const getAdvertisedEndpoints = Effect.gen(function* () {
605 const currentNetworkInterfaces = yield* readNetworkInterfaces;
606 const state = yield* readCurrentState(currentNetworkInterfaces);
607 const coreEndpoints = resolveDesktopCoreAdvertisedEndpoints({
608 port: state.port,
609 exposure: toResolvedExposure(state),
610 customHttpsEndpointUrls: config.desktopHttpsEndpointUrls,
611 });
612
613 // Spawning Mac App Store Tailscale can prompt for TCC access even when exposure is disabled.
614 if (state.mode !== "network-accessible" && !state.tailscaleServeEnabled) {
615 return coreEndpoints;
616 }
617
618 const tailscaleEndpoints = yield* resolveTailscaleAdvertisedEndpoints({
619 port: state.port,
620 serveEnabled: state.tailscaleServeEnabled,
621 servePort: state.tailscaleServePort,
622 networkInterfaces: currentNetworkInterfaces,
623 readStatus: Cache.get(
624 tailscaleStatusCache,
625 tailscaleIpv4AddressKey(currentNetworkInterfaces),
626 ),
627 }).pipe(
628 Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, childProcessSpawner),
629 Effect.provideService(HttpClient.HttpClient, httpClient),
630 );
631 return [...coreEndpoints, ...tailscaleEndpoints];
632 }).pipe(Effect.withSpan("desktop.serverExposure.getAdvertisedEndpoints"));
633
634 return DesktopServerExposure.of({
635 getState,
636 backendConfig,
637 configureFromSettings,
638 setMode,
639 setTailscaleServeEnabled,
640 getAdvertisedEndpoints,
641 });
642});
643
644export const layer = Layer.effect(DesktopServerExposure, make);