| 88 | |
| 89 | // Frame a stream of exec events as JSONL bytes for the wire. |
| 90 | export function encodeExecEvents( |
| 91 | events: ReadableStream<WorkspaceExecEvent<ExecEncoding>>, |
| 92 | ): ReadableStream<Uint8Array> { |
| 93 | return events.pipeThrough( |
| 94 | new TransformStream<WorkspaceExecEvent<ExecEncoding>, Uint8Array>({ |
| 95 | transform(event, controller) { |
| 96 | controller.enqueue(encodeExecEvent(event)); |
| 97 | }, |
| 98 | }), |
| 99 | ); |
| 100 | } |
| 101 | |
| 102 | // Parse a JSONL byte stream from the wire back into exec events. |
| 103 | // Buffers partial lines so a chunk boundary can fall anywhere. |