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