MCPcopy Create free account
hub / github.com/ChatLab/ChatLab / splitIntoSegments

Function splitIntoSegments

packages/node-runtime/src/ai/summary/index.ts:155–175  ·  view source on GitHub ↗
(
  messages: Array<{ senderName: string; content: string }>,
  maxCharsPerSegment: number
)

Source from the content-addressed store, hash-verified

153}
154
155export function splitIntoSegments(
156 messages: Array<{ senderName: string; content: string }>,
157 maxCharsPerSegment: number
158): Array<Array<{ senderName: string; content: string }>> {
159 const segments: Array<Array<{ senderName: string; content: string }>> = []
160 let currentSegment: Array<{ senderName: string; content: string }> = []
161 let currentLength = 0
162
163 for (const msg of messages) {
164 const msgLength = msg.senderName.length + msg.content.length + 3
165 if (currentLength + msgLength > maxCharsPerSegment && currentSegment.length > 0) {
166 segments.push(currentSegment)
167 currentSegment = []
168 currentLength = 0
169 }
170 currentSegment.push(msg)
171 currentLength += msgLength
172 }
173 if (currentSegment.length > 0) segments.push(currentSegment)
174 return segments
175}
176
177// ==================== Prompt builders ====================
178

Callers 2

summary.test.tsFile · 0.90
generateSessionSummaryFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected