(ptyId: string, data: string)
| 152 | } |
| 153 | |
| 154 | function sendOutput(ptyId: string, data: string): void { |
| 155 | const p = activePtys.get(ptyId) |
| 156 | if (!p) return |
| 157 | |
| 158 | const chunk: PtyOutputEvent = { |
| 159 | data: Buffer.from(data).toString("base64"), |
| 160 | timestamp: Date.now(), |
| 161 | } |
| 162 | |
| 163 | const chunkSize = Buffer.byteLength(data, "utf8") |
| 164 | if (p.bufferSizeBytes + chunkSize <= MAX_BUFFER_SIZE_BYTES) { |
| 165 | p.outputBuffer.push(chunk) |
| 166 | p.bufferSizeBytes += chunkSize |
| 167 | } else { |
| 168 | while (p.outputBuffer.length > 0 && p.bufferSizeBytes + chunkSize > MAX_BUFFER_SIZE_BYTES) { |
| 169 | const removed = p.outputBuffer.shift() |
| 170 | if (removed) { |
| 171 | p.bufferSizeBytes -= Buffer.byteLength(Buffer.from(removed.data, "base64").toString("utf8"), "utf8") |
| 172 | } |
| 173 | } |
| 174 | p.outputBuffer.push(chunk) |
| 175 | p.bufferSizeBytes += chunkSize |
| 176 | } |
| 177 | |
| 178 | emitLifecycle({ type: "output", ptyId, chunk }) |
| 179 | } |
| 180 | |
| 181 | function sendExit(ptyId: string, exitCode: number): void { |
| 182 | const p = activePtys.get(ptyId) |
no test coverage detected