MCPcopy Create free account
hub / github.com/getagentseal/codeburn / extractLargeUserTextBuffer

Function extractLargeUserTextBuffer

src/parser.ts:706–738  ·  view source on GitHub ↗
(source: Buffer, contentBounds: BufferJsonValueBounds | null)

Source from the content-addressed store, hash-verified

704}
705
706function extractLargeUserTextBuffer(source: Buffer, contentBounds: BufferJsonValueBounds | null): string | undefined {
707 if (!contentBounds) return undefined
708 if (contentBounds.kind === 'string') return readJsonStringBuffer(source, contentBounds, USER_TEXT_CAP)
709 if (contentBounds.kind !== 'array') return undefined
710
711 let text = ''
712 let i = contentBounds.start + 1
713 while (i < contentBounds.end - 1 && text.length < USER_TEXT_CAP) {
714 while (i < contentBounds.end && isJsonWhitespaceByte(source[i])) i++
715 if (source[i] === 0x2c) {
716 i++
717 continue
718 }
719 if (source[i] !== 0x7b) {
720 i++
721 continue
722 }
723 const objectEnd = findJsonContainerEndBuffer(source, i, 0x7b, 0x7d, contentBounds.end)
724 if (objectEnd === -1) break
725 const objectBounds = { start: i, end: objectEnd + 1, kind: 'object' as const }
726 const type = readJsonStringBuffer(source, findObjectFieldValueBuffer(source, objectBounds.start, objectBounds.end, 'type'))
727 if (type === 'text' || type === 'input_text') {
728 const part = readJsonStringBuffer(
729 source,
730 findObjectFieldValueBuffer(source, objectBounds.start, objectBounds.end, 'text'),
731 USER_TEXT_CAP - text.length,
732 )
733 if (part) text += (text ? ' ' : '') + part
734 }
735 i = objectEnd + 1
736 }
737 return text || undefined
738}
739
740function extractLargeAddedNamesBuffer(source: Buffer, attachmentBounds: BufferJsonValueBounds | null): string[] {
741 if (!attachmentBounds || attachmentBounds.kind !== 'object') return []

Callers 1

parseLargeJsonlBufferFunction · 0.85

Calls 4

readJsonStringBufferFunction · 0.85
isJsonWhitespaceByteFunction · 0.85

Tested by

no test coverage detected