(messages: ChunkMessageInput[], config: ChunkerConfig)
| 234 | // ==================== parent / child 切分 ==================== |
| 235 | |
| 236 | function segmentParents(messages: ChunkMessageInput[], config: ChunkerConfig): ChunkMessageInput[][] { |
| 237 | const parents: ChunkMessageInput[][] = [] |
| 238 | let current: ChunkMessageInput[] = [] |
| 239 | const gapMs = config.parentGapSeconds * 1000 |
| 240 | |
| 241 | for (const m of messages) { |
| 242 | if (current.length === 0) { |
| 243 | current.push(m) |
| 244 | continue |
| 245 | } |
| 246 | const prev = current[current.length - 1] |
| 247 | const overGap = m.ts - prev.ts > gapMs |
| 248 | const overTokens = estimateTokens(current.map((x) => (x.content ?? '').trim()).join('\n')) >= config.parentMaxTokens |
| 249 | if (overGap || overTokens) { |
| 250 | parents.push(current) |
| 251 | current = [m] |
| 252 | } else { |
| 253 | current.push(m) |
| 254 | } |
| 255 | } |
| 256 | if (current.length > 0) parents.push(current) |
| 257 | return parents |
| 258 | } |
| 259 | |
| 260 | function buildChildDrafts(parent: ChunkMessageInput[], config: ChunkerConfig): ChunkMessageInput[][] { |
| 261 | const drafts: ChunkMessageInput[][] = [] |
no test coverage detected