MCPcopy Create free account
hub / github.com/XxxXTeam/zai2api / Process

Method Process

internal/models.go:334–369  ·  view source on GitHub ↗
(content string)

Source from the content-addressed store, hash-verified

332}
333
334func (f *SearchRefFilter) Process(content string) string {
335 content = f.buffer + content
336 f.buffer = ""
337
338 if content == "" {
339 return ""
340 }
341
342 content = searchRefPattern.ReplaceAllStringFunc(content, func(match string) string {
343 runes := []rune(match)
344 refID := string(runes[1 : len(runes)-1])
345 if result, ok := f.searchResults[refID]; ok {
346 return fmt.Sprintf(`[\[%d\]](%s)`, result.Index, result.URL)
347 }
348 return ""
349 })
350
351 if content == "" {
352 return ""
353 }
354
355 maxPrefixLen := 20
356 if len(content) < maxPrefixLen {
357 maxPrefixLen = len(content)
358 }
359
360 for i := 1; i <= maxPrefixLen; i++ {
361 suffix := content[len(content)-i:]
362 if searchRefPrefixPattern.MatchString(suffix) {
363 f.buffer = suffix
364 return content[:len(content)-i]
365 }
366 }
367
368 return content
369}
370
371func (f *SearchRefFilter) Flush() string {
372 result := f.buffer

Callers 4

handleStreamResponseFunction · 0.95
handleNonStreamResponseFunction · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected