MCPcopy
hub / github.com/promptfoo/promptfoo / handleData

Method handleData

src/python/stderr.ts:16–33  ·  view source on GitHub ↗
(data: Buffer | string)

Source from the content-addressed store, hash-verified

14 constructor(private readonly prefix = '') {}
15
16 handleData(data: Buffer | string): void {
17 const text = typeof data === 'string' ? data : this.decoder.write(data);
18 this.buffer += text;
19
20 const carry = this.buffer.endsWith('\r') ? '\r' : '';
21 const normalized = (carry ? this.buffer.slice(0, -1) : this.buffer).replace(/\r\n?/g, '\n');
22 const lines = normalized.split('\n');
23 this.buffer = (lines.pop() ?? '') + carry;
24
25 for (const line of lines) {
26 this.logLine(line);
27 }
28
29 if (this.buffer.length >= MAX_STDERR_BUFFER_LENGTH) {
30 this.logLine(this.buffer);
31 this.buffer = '';
32 }
33 }
34
35 flush(): void {
36 const remaining = this.buffer + this.decoder.end();

Callers 2

runPythonFunction · 0.95
handleStderrMethod · 0.80

Calls 3

logLineMethod · 0.95
splitMethod · 0.80
writeMethod · 0.65

Tested by

no test coverage detected