/** * Sends an `effect/ui` app's log to a DevTools server from a host with no * DOM, such as an OpenTUI app in a terminal. * * Run `effect-ui-devtools` and open the URL it prints to inspect the newest * session in a read-only browser page. This entry point does not load the * browser overlay in the app. * * **Example** (Inspecting an OpenTUI app) * * ```ts * import { NodeRuntime } from "@effect/platform-node" * import { layer } from "@effect/ui-devtools/DevToolsHeadless" * import { OpenTui, OpenTuiHost } from "@effect/ui-opentui" * import { Effect, Schema } from "effect" * * const App = OpenTui.component({ * name: "App", * model: Schema.Struct({}), * message: Schema.Never * }).make({ * init: () => ({}), * update: (model) => model, * view: (h) => h.text("Hello") * }) * * OpenTuiHost.run(App, {}).pipe( * Effect.provide(layer()), * NodeRuntime.runMain * ) * ``` * * @stability experimental * @since 4.2.0 */ import * as Layer from "effect/Layer" import * as Socket from "effect/socket/Socket" import * as MessageLog from "effect/ui/MessageLog" import * as Control from "./internal/control.ts" /** * Provides a `MessageLog` that sends entries to `server` * (`http://127.0.0.1:4774` by default) through a provided * `Socket.WebSocketConstructor`, for hosts without a global `WebSocket` * such as JavaScriptCore or QuickJS. * * **Details** * * The session's `host` defaults to `"terminal"`; inspection is read-only. * Retains the last `size` entries (1,000 by default) for replay on * connection, so the server can start after the app. Retries lost connections * with backoff. A Model or message over `maxEntryBytes` is sent as * `{ "~truncated": bytes }`. * * @see {@link layer} to use the global `WebSocket` instead * @stability experimental * @category layers * @since 4.2.0 */ export const layerWebSocket = (options?: { readonly server?: string | undefined readonly host?: MessageLog.WireHost | undefined readonly size?: number | undefined readonly maxEntryBytes?: number | undefined }): Layer.Layer => MessageLog.socket( Control.socketUrl(options?.server ?? Control.serverUrl(), "/log"), { host: options?.host ?? "terminal", buffer: options?.size, maxEntryBytes: options?.maxEntryBytes } ) /** * `layerWebSocket` with the global `WebSocket` provided. * * @see {@link layerWebSocket} to provide your own `Socket.WebSocketConstructor` * @stability experimental * @category layers * @since 4.2.0 */ export const layer = ( options?: Parameters[0] ): Layer.Layer => layerWebSocket(options).pipe( Layer.provide(Socket.layerWebSocketConstructorGlobal) )