@devries-cameron20 / t3code Mirror · read-only
Fork 0

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

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
ts 39 lines 1.61 KB
Raw
1 import * as NodeHttpServer from "@effect/platform-node/NodeHttpServer"
2 import * as NodeRuntime from "@effect/platform-node/NodeRuntime"
3 import * as SqliteClient from "@effect/sql-sqlite-node/SqliteClient"
4 import * as Config from "effect/Config"
5 import * as EventLogServerEncrypted from "effect/eventlog/EventLogServerEncrypted"
6 import * as SqlEventLogServerEncrypted from "effect/eventlog/SqlEventLogServerEncrypted"
7 import * as HttpRouter from "effect/http/HttpRouter"
8 import * as HttpServerResponse from "effect/http/HttpServerResponse"
9 import * as Layer from "effect/Layer"
10 import * as RpcSerialization from "effect/rpc/RpcSerialization"
11 import * as RpcServer from "effect/rpc/RpcServer"
12 import { createServer } from "node:http"
13
14 const SqlLive = SqliteClient.layerConfig({
15 filename: Config.String("DATABASE_PATH").pipe(Config.withDefault("/data/eventlog.db"))
16 })
17
18 // Encrypted event log RPCs over a websocket at `/`. Event log messages carry
19 // binary fields, so they need a binary serialization.
20 const EventLogLive = EventLogServerEncrypted.layer.pipe(
21 Layer.provide([
22 RpcServer.layerProtocolWebsocket({ path: "/" }).pipe(
23 Layer.provide(RpcSerialization.layerSchemaBinary())
24 ),
25 SqlEventLogServerEncrypted.layerStorageSubtle().pipe(
26 Layer.provide(SqlLive)
27 )
28 ])
29 )
30
31 const HealthLive = HttpRouter.add("GET", "/health", HttpServerResponse.empty())
32
33 const ServerLive = HttpRouter.serve(Layer.mergeAll(EventLogLive, HealthLive)).pipe(
34 Layer.provide(NodeHttpServer.layerConfig(createServer, {
35 port: Config.Port("PORT").pipe(Config.withDefault(8080))
36 }))
37 )
38
39 Layer.launch(ServerLive).pipe(NodeRuntime.runMain)