| 311 | controller.enqueue(event); |
| 312 | }; |
| 313 | const flushPending = ( |
| 314 | controller: TransformStreamDefaultController<WorkspaceExecEvent<E>>, |
| 315 | beforeSeq?: number, |
| 316 | ) => { |
| 317 | const pending: Array<{ |
| 318 | id: string; |
| 319 | seq: number; |
| 320 | name: "stdout" | "stderr"; |
| 321 | value: Chunk<E>; |
| 322 | }> = []; |
| 323 | const stdout = stdoutDec.decode(); |
| 324 | const stderr = stderrDec.decode(); |
| 325 | if (stdout && stdoutMeta) { |
| 326 | pending.push({ ...stdoutMeta, name: "stdout", value: stdout as Chunk<E> }); |
| 327 | } |
| 328 | if (stderr && stderrMeta) { |
| 329 | pending.push({ ...stderrMeta, name: "stderr", value: stderr as Chunk<E> }); |
| 330 | } |
| 331 | pending.sort((a, b) => a.seq - b.seq); |
| 332 | const span = beforeSeq !== undefined && beforeSeq > lastSeq ? beforeSeq - lastSeq : 1; |
| 333 | for (let index = 0; index < pending.length; index++) { |
| 334 | const event = pending[index]; |
| 335 | enqueue(controller, { |
| 336 | ...event, |
| 337 | seq: lastSeq + (span * (index + 1)) / (pending.length + 1), |
| 338 | }); |
| 339 | } |
| 340 | stdoutMeta = undefined; |
| 341 | stderrMeta = undefined; |
| 342 | }; |
| 343 | return source.pipeThrough( |
| 344 | new TransformStream<ExecEvent, WorkspaceExecEvent<E>>({ |
| 345 | transform(event, controller) { |