MCPcopy Create free account
hub / github.com/ShipSecAI/studio / mergeTerminalChunks

Function mergeTerminalChunks

frontend/src/hooks/useTerminalStream.ts:28–49  ·  view source on GitHub ↗
(
  existing: TerminalChunk[],
  incoming: TerminalChunk[],
  options: { max?: number } = {},
)

Source from the content-addressed store, hash-verified

26}
27
28export 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
51export function useTerminalStream(options: UseTerminalStreamOptions): UseTerminalStreamResult {
52 const { runId, nodeId, stream = 'pty', autoConnect = true } = options;

Callers 3

useTerminalStreamFunction · 0.85
handleTerminalFunction · 0.85

Calls 2

fromMethod · 0.80
setMethod · 0.45

Tested by

no test coverage detected