| 1 | import * as Schema from "effect/Schema"; |
| 2 | |
| 3 | import { PortSchema, PositiveInt, TrimmedNonEmptyString } from "./baseSchemas.ts"; |
| 4 | |
| 5 | // A supervisor must not restart a server refused by the state-directory owner. |
| 6 | export const SERVER_EXIT_CODE_STATE_DIR_OWNED = 78; |
| 7 | |
| 8 | export const DesktopBackendBootstrap = Schema.Struct({ |
| 9 | mode: Schema.Literal("desktop"), |
| 10 | noBrowser: Schema.Boolean, |
| 11 | port: PortSchema, |
| 12 | // Omitted when the desktop launches the backend inside WSL, since the |
| 13 | // Windows-side baseDir maps to /mnt/c/... and the Linux side should use its |
| 14 | // own home directory instead. |
| 15 | t3Home: Schema.optional(Schema.String), |
| 16 | host: Schema.String, |
| 17 | desktopBootstrapToken: Schema.String, |
| 18 | // Present when the desktop rotates the renderer's bootstrap token: the |
| 19 | // backend derives the accepted tokens from this secret instead of trusting |
| 20 | // `desktopBootstrapToken` for its whole run. See |
| 21 | // `@t3tools/shared/desktopBootstrapToken`. |
| 22 | desktopBootstrapSecret: Schema.optionalKey(Schema.String), |
| 23 | // Set only when the desktop already merged the user's shell environment into |
| 24 | // the environment it hands this backend. Absent means the backend hydrates |
| 25 | // PATH itself, which WSL and older desktops rely on. |
| 26 | shellEnvironmentPrepared: Schema.optionalKey(Schema.Boolean), |
| 27 | tailscaleServeEnabled: Schema.Boolean, |
| 28 | tailscaleServePort: PortSchema, |
| 29 | otlpTracesUrl: Schema.optional(Schema.String), |
| 30 | otlpMetricsUrl: Schema.optional(Schema.String), |
| 31 | otlpLogsUrl: Schema.optional(Schema.String), |
| 32 | desktopTelemetryFd: Schema.optionalKey(PositiveInt), |
| 33 | desktopTelemetryControlFd: Schema.optionalKey(PositiveInt), |
| 34 | /** Desktop -> server: the desktop's browser tabs, as newline-delimited JSON. */ |
| 35 | desktopBrowserFd: Schema.optionalKey(PositiveInt), |
| 36 | /** Server -> desktop: commands for those tabs. */ |
| 37 | desktopBrowserControlFd: Schema.optionalKey(PositiveInt), |
| 38 | desktopTerminalFd: Schema.optionalKey(PositiveInt), |
| 39 | desktopTerminalControlFd: Schema.optionalKey(PositiveInt), |
| 40 | resourceMonitorPath: Schema.optionalKey(TrimmedNonEmptyString), |
| 41 | }); |
| 42 | |
| 43 | export type DesktopBackendBootstrap = typeof DesktopBackendBootstrap.Type; |
| 44 | |
| 45 | /** Written to `<t3Home>/runtime` just before the desktop app stops its |
| 46 | backend to install an update. The updated app starts a new backend right |
| 47 | away, so a backend that sees a fresh marker at shutdown keeps its managed |
| 48 | tunnel. */ |
| 49 | export const DESKTOP_UPDATE_RESTART_MARKER_FILE = "desktop-update-restart"; |