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, 06:00 UTC
| 1 | import * as Domain from "@alchemy.run/domain"; |
| 2 | import * as Effect from "effect/Effect"; |
| 3 | import * as FetchHttpClient from "effect/http/FetchHttpClient"; |
| 4 | import * as Layer from "effect/Layer"; |
| 5 | import * as Socket from "effect/socket/Socket"; |
| 6 | import { Runtime } from "foldkit"; |
| 7 | import { NotesApi } from "../NotesApi.api.ts"; |
| 8 | import { UserId } from "../User.id.ts"; |
| 9 | import { auth } from "./auth.ts"; |
| 10 | import { Flags, init, Model, subscriptions, update, view } from "./Notes.ts"; |
| 11 | |
| 12 | // Who better-auth says is signed in, before the app starts. |
| 13 | const flags = Effect.promise(() => auth.getSession()).pipe( |
| 14 | Effect.map(({ data }) => ({ |
| 15 | user: data ? { userId: UserId.make(data.user.id), name: data.user.name } : null, |
| 16 | })), |
| 17 | ); |
| 18 | |
| 19 | // The session cookie is first-party, so every call and watch on /api carries it. |
| 20 | const NotesConnection = NotesApi.layerClient.pipe( |
| 21 | Layer.provide(Domain.protocolWebSocket(`${location.origin}/api`)), |
| 22 | Layer.provide(Layer.mergeAll(FetchHttpClient.layer, Socket.layerWebSocketConstructorGlobal)), |
| 23 | ); |
| 24 | |
| 25 | Runtime.run( |
| 26 | Runtime.makeApplication({ |
| 27 | Model, |
| 28 | Flags, |
| 29 | init, |
| 30 | update, |
| 31 | view, |
| 32 | subscriptions, |
| 33 | resources: NotesConnection, |
| 34 | container: document.getElementById("root"), |
| 35 | }), |
| 36 | { flags }, |
| 37 | ); |