MCPcopy
hub / github.com/CodebuffAI/codebuff / process

Method process

common/src/util/stop-sequence.ts:12–51  ·  view source on GitHub ↗
(
    text: string,
  )

Source from the content-addressed store, hash-verified

10 }
11
12 public process(
13 text: string,
14 ):
15 | { text: string; endOfStream: boolean }
16 | { text: null; endOfStream: true } {
17 if (this.finished) {
18 return {
19 text: null,
20 endOfStream: true,
21 }
22 }
23 this.buffer += text
24 let longestOverlap = ''
25
26 for (const stopSequence of this.stopSequences) {
27 const index = this.buffer.indexOf(stopSequence)
28 if (index !== -1) {
29 this.finished = true
30 return {
31 text: this.buffer.slice(0, index),
32 endOfStream: true,
33 }
34 }
35 }
36
37 for (const stopSequence of this.stopSequences) {
38 const overlap = suffixPrefixOverlap(this.buffer, stopSequence)
39 longestOverlap =
40 overlap.length > longestOverlap.length ? overlap : longestOverlap
41 }
42
43 const index = this.buffer.length - longestOverlap.length
44 const processed = this.buffer.slice(0, index)
45 this.buffer = this.buffer.slice(index)
46
47 return {
48 text: processed,
49 endOfStream: false,
50 }
51 }
52
53 public flush(): string {
54 if (this.finished) {

Callers 4

promptAiSdkStreamFunction · 0.95
sendAnalyticsAndLogFunction · 0.80
logWithSyncFunction · 0.80

Calls 1

suffixPrefixOverlapFunction · 0.90

Tested by

no test coverage detected