MCPcopy Create free account
hub / github.com/bearlyai/OpenADE / sendOutput

Function sendOutput

projects/electron/src/modules/code/pty.ts:154–179  ·  view source on GitHub ↗
(ptyId: string, data: string)

Source from the content-addressed store, hash-verified

152}
153
154function 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
181function sendExit(ptyId: string, exitCode: number): void {
182 const p = activePtys.get(ptyId)

Callers 1

handleSpawnFunction · 0.70

Calls 3

pushMethod · 0.80
emitLifecycleFunction · 0.70
getMethod · 0.65

Tested by

no test coverage detected