The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import * as Lambda from "@alchemy.run/aws/Lambda"; |
| 2 | import * as Duration from "effect/Duration"; |
| 3 | import * as Effect from "effect/Effect"; |
| 4 | import * as HttpServerResponse from "effect/http/HttpServerResponse"; |
| 5 | import * as Stream from "effect/Stream"; |
| 6 | |
| 7 | export class StreamingFunction extends Lambda.Function<Lambda.Function>()("StreamingFunction") {} |
| 8 | |
| 9 | export default StreamingFunction.make( |
| 10 | { |
| 11 | main: import.meta.url, |
| 12 | functionUrl: { invokeMode: "RESPONSE_STREAM" }, |
| 13 | timeout: Duration.seconds(30), |
| 14 | }, |
| 15 | Effect.gen(function* () { |
| 16 | return { |
| 17 | // Each event is held back two seconds, so a buffered response would |
| 18 | // deliver all three at once. |
| 19 | fetch: Effect.succeed( |
| 20 | HttpServerResponse.stream( |
| 21 | Stream.make("data: one\n\n", "data: two\n\n", "data: three\n\n").pipe( |
| 22 | Stream.tap(() => Effect.sleep("2 seconds")), |
| 23 | Stream.encodeText, |
| 24 | ), |
| 25 | { |
| 26 | contentType: "text/event-stream", |
| 27 | headers: { "x-streamed": "true" }, |
| 28 | }, |
| 29 | ).pipe(HttpServerResponse.setCookieUnsafe("session", "abc")), |
| 30 | ), |
| 31 | }; |
| 32 | }), |
| 33 | ); |