(item: Sse)
| 416 | } |
| 417 | |
| 418 | function send(item: Sse) { |
| 419 | const head = bytes(item.head) |
| 420 | const tail = bytes([...item.tail, ...(item.hang || item.error ? [] : [done])]) |
| 421 | const empty = Stream.fromIterable<Uint8Array>([]) |
| 422 | const wait = item.wait |
| 423 | const body: Stream.Stream<Uint8Array, unknown> = wait |
| 424 | ? Stream.concat(head, Stream.fromEffect(Effect.promise(() => wait)).pipe(Stream.flatMap(() => tail))) |
| 425 | : Stream.concat(head, tail) |
| 426 | let end: Stream.Stream<Uint8Array, unknown> = empty |
| 427 | if (item.error) end = Stream.concat(empty, Stream.fail(item.error)) |
| 428 | else if (item.hang) end = Stream.concat(empty, Stream.never) |
| 429 | |
| 430 | return HttpServerResponse.stream(Stream.concat(body, end), { contentType: "text/event-stream" }) |
| 431 | } |
| 432 | |
| 433 | const reset = Effect.fn("TestLLMServer.reset")(function* (item: Sse) { |
| 434 | const req = yield* HttpServerRequest.HttpServerRequest |
no test coverage detected