MCPcopy
hub / github.com/Waishnav/devspace / drain

Method drain

src/process-sessions.ts:173–191  ·  view source on GitHub ↗
(maxCharacters: number)

Source from the content-addressed store, hash-verified

171 }
172
173 drain(maxCharacters: number): { output: string; truncated: boolean } {
174 if (!Number.isInteger(maxCharacters) || maxCharacters < 1) {
175 throw new Error("Output limit must be a positive integer.");
176 }
177
178 const omittedByBuffer = Math.max(
179 0,
180 this.totalCharacters - codePointLength(this.head) - codePointLength(this.tail),
181 );
182 const retained = formatHeadTail(this.head, this.tail, omittedByBuffer);
183 const output = truncateOutput(retained, maxCharacters);
184 const truncated = omittedByBuffer > 0 || output.truncated;
185
186 this.head = "";
187 this.tail = "";
188 this.totalCharacters = 0;
189
190 return { output: output.output, truncated };
191 }
192}
193
194function truncateOutput(output: string, maxCharacters: number): { output: string; truncated: boolean } {

Callers 2

consumeMethod · 0.80

Calls 3

codePointLengthFunction · 0.85
formatHeadTailFunction · 0.85
truncateOutputFunction · 0.85

Tested by

no test coverage detected