concat method
Merges this message with another by concatenating the content.
Implementation
@override
AIChatMessage concat(final ChatMessage other) {
if (other is! AIChatMessage) {
return this;
}
final mergedBlocks = [...content];
for (final otherBlock in other.content) {
final matchingIndex = mergedBlocks.indexWhere(
(block) => block.canMerge(otherBlock),
);
if (matchingIndex == -1) {
mergedBlocks.add(otherBlock);
} else {
mergedBlocks[matchingIndex] = mergedBlocks[matchingIndex].concat(
otherBlock,
);
}
}
return AIChatMessage(content: mergedBlocks);
}