1import { desktopTerminalSocket } from "@t3tools/client-runtime/rpc";
2import { Connection } from "@t3tools/client-runtime/connection";
3import { ShellSnapshotLoader } from "@t3tools/client-runtime/state/shell";
4import {
5 BoundedThreadSnapshotLoader,
6 ThreadHistoryController,
7} from "@t3tools/client-runtime/state/threads";
8import { PullRequestDiffLoader } from "@t3tools/client-runtime/state/pull-requests";
9import * as Layer from "effect/Layer";
10import { Atom } from "effect/reactivity";
11
12import * as Runtime from "../lib/runtime";
13import * as BackgroundActivityReporter from "../lib/backgroundActivityReporter";
14import * as ConnectionPlatform from "./platform";
15
16const layerProvidedConnectionPlatform = ConnectionPlatform.layer.pipe(Layer.provide(Runtime.layer));
17
18const layerSnapshotLoader = Layer.mergeAll(
19 BoundedThreadSnapshotLoader.layer,
20 ShellSnapshotLoader.layer,
21 ThreadHistoryController.layer,
22 PullRequestDiffLoader.layer,
23);
24
25type ConnectionLayerSource =
26 | typeof Connection.layer
27 | typeof layerSnapshotLoader
28 | typeof Runtime.layer
29 | typeof ConnectionPlatform.layer
30 | typeof BackgroundActivityReporter.layerObserver
31 | typeof BackgroundActivityReporter.layer;
32
33const layerProvidedClientConnection = layerSnapshotLoader.pipe(
34 Layer.provideMerge(
35 Connection.layerWithOptions({
36 terminalSocket: (prepared) => desktopTerminalSocket(window.desktopBridge, prepared),
37 environmentThemes: true,
38 usageLimitSources: true,
39 usageLimitsCommand: true,
40 }),
41 ),
42 Layer.provideMerge(
43 Layer.mergeAll(
44 Runtime.layer,
45 layerProvidedConnectionPlatform,
46 BackgroundActivityReporter.layerObserver,
47 ),
48 ),
49);
50
51const layerConnection = BackgroundActivityReporter.layer.pipe(
52 Layer.provideMerge(layerProvidedClientConnection),
53);
54
55export const connectionAtomRuntime: Atom.AtomRuntime<
56 Layer.Success<ConnectionLayerSource>,
57 Layer.Error<ConnectionLayerSource>
58> = Atom.runtime(layerConnection);