| 1 | import { desktopTerminalSocket } from "@t3tools/client-runtime/rpc"; |
| 2 | import { Connection } from "@t3tools/client-runtime/connection"; |
| 3 | import { ShellSnapshotLoader } from "@t3tools/client-runtime/state/shell"; |
| 4 | import { |
| 5 | BoundedThreadSnapshotLoader, |
| 6 | ThreadHistoryController, |
| 7 | } from "@t3tools/client-runtime/state/threads"; |
| 8 | import { PullRequestDiffLoader } from "@t3tools/client-runtime/state/pull-requests"; |
| 9 | import * as Layer from "effect/Layer"; |
| 10 | import { Atom } from "effect/reactivity"; |
| 11 | |
| 12 | import * as Runtime from "../lib/runtime"; |
| 13 | import * as BackgroundActivityReporter from "../lib/backgroundActivityReporter"; |
| 14 | import * as ConnectionPlatform from "./platform"; |
| 15 | |
| 16 | const layerProvidedConnectionPlatform = ConnectionPlatform.layer.pipe(Layer.provide(Runtime.layer)); |
| 17 | |
| 18 | const layerSnapshotLoader = Layer.mergeAll( |
| 19 | BoundedThreadSnapshotLoader.layer, |
| 20 | ShellSnapshotLoader.layer, |
| 21 | ThreadHistoryController.layer, |
| 22 | PullRequestDiffLoader.layer, |
| 23 | ); |
| 24 | |
| 25 | type 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 | |
| 33 | const 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 | |
| 51 | const layerConnection = BackgroundActivityReporter.layer.pipe( |
| 52 | Layer.provideMerge(layerProvidedClientConnection), |
| 53 | ); |
| 54 | |
| 55 | export const connectionAtomRuntime: Atom.AtomRuntime< |
| 56 | Layer.Success<ConnectionLayerSource>, |
| 57 | Layer.Error<ConnectionLayerSource> |
| 58 | > = Atom.runtime(layerConnection); |