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, 07:15 UTC
| 1 | import * as Cloudflare from "@alchemy.run/cloudflare"; |
| 2 | import * as Effect from "effect/Effect"; |
| 3 | import { History } from "./History.ts"; |
| 4 | |
| 5 | // #region show |
| 6 | export default class Room extends Cloudflare.DurableObject<Room>()( |
| 7 | "Room", |
| 8 | Effect.gen(function* () { |
| 9 | const state = yield* Cloudflare.DurableObjectState; |
| 10 | // #region history |
| 11 | const history = yield* History; |
| 12 | // #endregion history |
| 13 | |
| 14 | return Effect.gen(function* () { |
| 15 | return { |
| 16 | // #region connect |
| 17 | fetch: Effect.gen(function* () { |
| 18 | const [response] = yield* Cloudflare.upgrade(); |
| 19 | return response; |
| 20 | }), |
| 21 | // #endregion connect |
| 22 | // #region message |
| 23 | webSocketMessage: Effect.fn(function* (_from, text) { |
| 24 | // #region broadcast |
| 25 | for (const socket of yield* state.getWebSockets()) { |
| 26 | yield* socket.send(text); |
| 27 | } |
| 28 | // #endregion broadcast |
| 29 | // #region send |
| 30 | yield* history.append(state.id.name!, text); |
| 31 | // #endregion send |
| 32 | }), |
| 33 | // #endregion message |
| 34 | }; |
| 35 | }); |
| 36 | }), |
| 37 | ) {} |
| 38 | // #endregion show |