Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 deletions apps/server/src/serverLayers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as NodeServices from "@effect/platform-node/NodeServices";
import { Effect, FileSystem, Layer } from "effect";
import { Effect, FileSystem, Layer, Path } from "effect";
import * as SqlClient from "effect/unstable/sql/SqlClient";

import { CheckpointDiffQueryLive } from "./checkpointing/Layers/CheckpointDiffQuery";
Expand Down Expand Up @@ -32,10 +32,26 @@ import { GitCoreLive } from "./git/Layers/GitCore";
import { GitHubCliLive } from "./git/Layers/GitHubCli";
import { CodexTextGenerationLive } from "./git/Layers/CodexTextGeneration";
import { GitServiceLive } from "./git/Layers/GitService";
import { BunPtyAdapterLive } from "./terminal/Layers/BunPTY";
import { NodePtyAdapterLive } from "./terminal/Layers/NodePTY";
import { PtyAdapter } from "./terminal/Services/PTY";
import { AnalyticsService } from "./telemetry/Services/AnalyticsService";

type RuntimePtyAdapterLoader = {
layer: Layer.Layer<PtyAdapter, never, FileSystem.FileSystem | Path.Path>;
};

const runtimePtyAdapterLoaders = {
bun: () => import("./terminal/Layers/BunPTY"),
node: () => import("./terminal/Layers/NodePTY"),
} satisfies Record<string, () => Promise<RuntimePtyAdapterLoader>>;

const makeRuntimePtyAdapterLayer = () =>
Effect.gen(function* () {
const runtime = process.versions.bun !== undefined ? "bun" : "node";
const loader = runtimePtyAdapterLoaders[runtime];
const ptyAdapterModule = yield* Effect.promise<RuntimePtyAdapterLoader>(loader);
return ptyAdapterModule.layer;
}).pipe(Layer.unwrap);

export function makeServerProviderLayer(): Layer.Layer<
ProviderService,
ProviderUnsupportedError,
Expand Down Expand Up @@ -108,13 +124,7 @@ export function makeServerRuntimeServicesLayer() {
Layer.provideMerge(checkpointReactorLayer),
);

const terminalLayer = TerminalManagerLive.pipe(
Layer.provide(
typeof Bun !== "undefined" && process.platform !== "win32"
? BunPtyAdapterLive
: NodePtyAdapterLive,
),
);
const terminalLayer = TerminalManagerLive.pipe(Layer.provide(makeRuntimePtyAdapterLayer()));

const gitManagerLayer = GitManagerLive.pipe(
Layer.provideMerge(gitCoreLayer),
Expand Down
6 changes: 4 additions & 2 deletions apps/server/src/terminal/Layers/BunPTY.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,13 @@ class BunPtyProcess implements PtyProcess {
}
}

export const BunPtyAdapterLive = Layer.effect(
export const layer = Layer.effect(
PtyAdapter,
Effect.gen(function* () {
if (process.platform === "win32") {
return yield* Effect.die("Bun PTY terminal support is unavailable on Windows.");
return yield* Effect.die(
"Bun PTY terminal support is unavailable on Windows. Please use Node.js (e.g. by running `npx t3`) instead.",
);
}
return {
spawn: (input) =>
Expand Down
2 changes: 1 addition & 1 deletion apps/server/src/terminal/Layers/NodePTY.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class NodePtyProcess implements PtyProcess {
}
}

export const NodePtyAdapterLive = Layer.effect(
export const layer = Layer.effect(
PtyAdapter,
Effect.gen(function* () {
const fs = yield* FileSystem.FileSystem;
Expand Down