|
1 | 1 | import * as NodeServices from "@effect/platform-node/NodeServices"; |
2 | | -import { Effect, FileSystem, Layer } from "effect"; |
| 2 | +import { Effect, FileSystem, Layer, Path } from "effect"; |
3 | 3 | import * as SqlClient from "effect/unstable/sql/SqlClient"; |
4 | 4 |
|
5 | 5 | import { CheckpointDiffQueryLive } from "./checkpointing/Layers/CheckpointDiffQuery"; |
@@ -33,10 +33,26 @@ import { GitCoreLive } from "./git/Layers/GitCore"; |
33 | 33 | import { GitHubCliLive } from "./git/Layers/GitHubCli"; |
34 | 34 | import { CodexTextGenerationLive } from "./git/Layers/CodexTextGeneration"; |
35 | 35 | import { GitServiceLive } from "./git/Layers/GitService"; |
36 | | -import { BunPtyAdapterLive } from "./terminal/Layers/BunPTY"; |
37 | | -import { NodePtyAdapterLive } from "./terminal/Layers/NodePTY"; |
| 36 | +import { PtyAdapter } from "./terminal/Services/PTY"; |
38 | 37 | import { AnalyticsService } from "./telemetry/Services/AnalyticsService"; |
39 | 38 |
|
| 39 | +type RuntimePtyAdapterLoader = { |
| 40 | + layer: Layer.Layer<PtyAdapter, never, FileSystem.FileSystem | Path.Path>; |
| 41 | +}; |
| 42 | + |
| 43 | +const runtimePtyAdapterLoaders = { |
| 44 | + bun: () => import("./terminal/Layers/BunPTY"), |
| 45 | + node: () => import("./terminal/Layers/NodePTY"), |
| 46 | +} satisfies Record<string, () => Promise<RuntimePtyAdapterLoader>>; |
| 47 | + |
| 48 | +const makeRuntimePtyAdapterLayer = () => |
| 49 | + Effect.gen(function* () { |
| 50 | + const runtime = process.versions.bun !== undefined ? "bun" : "node"; |
| 51 | + const loader = runtimePtyAdapterLoaders[runtime]; |
| 52 | + const ptyAdapterModule = yield* Effect.promise<RuntimePtyAdapterLoader>(loader); |
| 53 | + return ptyAdapterModule.layer; |
| 54 | + }).pipe(Layer.unwrap); |
| 55 | + |
40 | 56 | export function makeServerProviderLayer(): Layer.Layer< |
41 | 57 | ProviderService, |
42 | 58 | ProviderUnsupportedError, |
@@ -109,13 +125,7 @@ export function makeServerRuntimeServicesLayer() { |
109 | 125 | Layer.provideMerge(checkpointReactorLayer), |
110 | 126 | ); |
111 | 127 |
|
112 | | - const terminalLayer = TerminalManagerLive.pipe( |
113 | | - Layer.provide( |
114 | | - typeof Bun !== "undefined" && process.platform !== "win32" |
115 | | - ? BunPtyAdapterLive |
116 | | - : NodePtyAdapterLive, |
117 | | - ), |
118 | | - ); |
| 128 | + const terminalLayer = TerminalManagerLive.pipe(Layer.provide(makeRuntimePtyAdapterLayer())); |
119 | 129 |
|
120 | 130 | const gitManagerLayer = GitManagerLive.pipe( |
121 | 131 | Layer.provideMerge(gitCoreLayer), |
|
0 commit comments