(
existing: TerminalChunk[],
incoming: TerminalChunk[],
options: { max?: number } = {},
)
| 26 | } |
| 27 | |
| 28 | export function mergeTerminalChunks( |
| 29 | existing: TerminalChunk[], |
| 30 | incoming: TerminalChunk[], |
| 31 | options: { max?: number } = {}, |
| 32 | ): TerminalChunk[] { |
| 33 | if (incoming.length === 0) { |
| 34 | return existing; |
| 35 | } |
| 36 | const maxSize = options.max ?? MAX_BUFFER; |
| 37 | const map = new Map<number, TerminalChunk>(); |
| 38 | for (const chunk of existing) { |
| 39 | map.set(chunk.chunkIndex, chunk); |
| 40 | } |
| 41 | for (const chunk of incoming) { |
| 42 | map.set(chunk.chunkIndex, chunk); |
| 43 | } |
| 44 | const merged = Array.from(map.values()).sort((a, b) => a.chunkIndex - b.chunkIndex); |
| 45 | if (merged.length > maxSize) { |
| 46 | return merged.slice(merged.length - maxSize); |
| 47 | } |
| 48 | return merged; |
| 49 | } |
| 50 | |
| 51 | export function useTerminalStream(options: UseTerminalStreamOptions): UseTerminalStreamResult { |
| 52 | const { runId, nodeId, stream = 'pty', autoConnect = true } = options; |
no test coverage detected