|
| 1 | +// Implementation note (Effect migration, issue #48): |
| 2 | +// `@arcp/bun` is a single-file `Bun.serve({ websocket })` adapter that |
| 3 | +// terminates ARCP connections on Bun's native WS server (no `ws` dep) and |
| 4 | +// hands each accepted socket to `onTransport` as a `BunWebSocketTransport`. |
| 5 | +// All runtime state — handshake, dispatch loop, back-pressure, resume — is |
| 6 | +// owned by `ARCPServer.accept`; this package never holds it. The Bun socket |
| 7 | +// is only available inside the `websocket.open` callback and is consumed by |
| 8 | +// `BunWebSocketTransport` immediately, leaving no socket-level seam for an |
| 9 | +// Effect-shape `TransportEffect` factory to slot into without rewriting the |
| 10 | +// per-socket state machine. Adding a dedicated `effect` twin here would |
| 11 | +// duplicate the legacy adapter and force a runtime `effect` dependency on |
| 12 | +// the Bun package. |
| 13 | +// |
| 14 | +// Effect-graph consumers should keep using `serveArcp` and dispatch the |
| 15 | +// legacy transport into their `ManagedRuntime` from `onTransport`: |
| 16 | +// |
| 17 | +// import { Effect, ManagedRuntime } from "effect" |
| 18 | +// import { |
| 19 | +// ARCPRuntimeLayer, |
| 20 | +// ARCPServerService, |
| 21 | +// } from "@arcp/runtime" |
| 22 | +// import { serveArcp } from "@arcp/bun" |
| 23 | +// |
| 24 | +// const runtime = ManagedRuntime.make(ARCPRuntimeLayer({ ... })) |
| 25 | +// const handle = serveArcp({ |
| 26 | +// port: 7777, |
| 27 | +// onTransport: (transport) => |
| 28 | +// runtime.runFork( |
| 29 | +// Effect.gen(function* () { |
| 30 | +// const { server } = yield* ARCPServerService |
| 31 | +// server?.accept(transport) |
| 32 | +// }), |
| 33 | +// ), |
| 34 | +// }) |
| 35 | +// |
| 36 | +// `acceptSessionEffect` (from `@arcp/runtime`) remains the right call-site |
| 37 | +// when the consumer is driving sessions from an already-Effect-shape |
| 38 | +// transport (e.g. their own `TransportEffect` over a stdio pipe); it is not |
| 39 | +// a better fit for the Bun adapter's `ServerWebSocket`-owned socket — that |
| 40 | +// socket is already inside `BunWebSocketTransport` by the time `onTransport` |
| 41 | +// fires. |
| 42 | + |
1 | 43 | import { BunWebSocketTransport } from "./transport.js"; |
2 | 44 | import type { ArcpServeHandle, BunServeArcpOptions } from "./types.js"; |
3 | 45 |
|
|
0 commit comments