The best way to control Claude Code, Codex and more from any computer or phone

main
ts 68 lines 2.24 KB
Raw
1 import { Connection } from "@t3tools/client-runtime/connection";
2 import { ShellSnapshotLoader } from "@t3tools/client-runtime/state/shell";
3 import { PullRequestDiffLoader } from "@t3tools/client-runtime/state/pull-requests";
4 import {
5 BoundedThreadSnapshotLoader,
6 ThreadHistoryController,
7 } from "@t3tools/client-runtime/state/threads";
8 import * as Layer from "effect/Layer";
9 import { Atom } from "effect/reactivity";
10
11 import type { FoundationHotModule } from "../lib/foundation-fast-refresh";
12 import { hotSwappableAtomRuntime } from "../lib/hot-swappable-atom-runtime";
13 import * as Runtime from "../lib/runtime";
14 import { appAtomRegistry } from "../state/atom-registry";
15 import * as BackgroundActivity from "./background-activity";
16 import * as ConnectionPlatform from "./platform";
17
18 declare const module: { readonly hot?: FoundationHotModule } | undefined;
19
20 const layerProvidedConnectionPlatform = ConnectionPlatform.layer.pipe(Layer.provide(Runtime.layer));
21
22 const layerSnapshotLoader = Layer.mergeAll(
23 PullRequestDiffLoader.layer,
24 BoundedThreadSnapshotLoader.layer,
25 ShellSnapshotLoader.layer,
26 ThreadHistoryController.layer,
27 );
28
29 type ConnectionLayerSource =
30 | typeof Connection.layer
31 | typeof layerSnapshotLoader
32 | typeof Runtime.layer
33 | typeof ConnectionPlatform.layer
34 | typeof BackgroundActivity.layerObserver
35 | typeof BackgroundActivity.layerReporter;
36
37 const layerProvidedClientConnection = layerSnapshotLoader.pipe(
38 Layer.provideMerge(
39 Connection.layerWithOptions({
40 usageLimitSources: true,
41 usageLimitsCommand: true,
42 providerCatalogsOnDemand: true,
43 providerCatalogDigests: true,
44 providerStatusDeltas: true,
45 }),
46 ),
47 Layer.provideMerge(
48 Layer.mergeAll(
49 Runtime.layer,
50 layerProvidedConnectionPlatform,
51 BackgroundActivity.layerObserver,
52 ),
53 ),
54 );
55
56 const layerConnection = BackgroundActivity.layerReporter.pipe(
57 Layer.provideMerge(layerProvidedClientConnection),
58 );
59
60 export const connectionAtomRuntime: Atom.AtomRuntime<
61 Layer.Success<ConnectionLayerSource>,
62 Layer.Error<ConnectionLayerSource>
63 > = hotSwappableAtomRuntime({
64 id: "t3.mobile.connection-runtime",
65 hotModule: typeof module === "undefined" ? undefined : module.hot,
66 registry: appAtomRegistry,
67 layer: layerConnection,
68 });