(text: string)
| 656 | } |
| 657 | |
| 658 | private findSlackSafeSplitPoint(text: string): number { |
| 659 | const preferredBreaks = ["\n\n", "\n", " "]; |
| 660 | const minSplit = Math.floor(MAX_MESSAGE_LENGTH * 0.3); |
| 661 | |
| 662 | for (const token of preferredBreaks) { |
| 663 | const index = this.findBestSlackSplitBefore(text, token); |
| 664 | if (index >= minSplit) { |
| 665 | return index; |
| 666 | } |
| 667 | } |
| 668 | |
| 669 | let low = 1; |
| 670 | let high = text.length; |
| 671 | let best = Math.min(text.length, MAX_MESSAGE_LENGTH); |
| 672 | |
| 673 | while (low <= high) { |
| 674 | const mid = Math.floor((low + high) / 2); |
| 675 | const candidate = text.slice(0, mid); |
| 676 | if (this.isSlackMessageWithinLimit(candidate)) { |
| 677 | best = mid; |
| 678 | low = mid + 1; |
| 679 | } else { |
| 680 | high = mid - 1; |
| 681 | } |
| 682 | } |
| 683 | |
| 684 | return Math.max(1, best); |
| 685 | } |
| 686 | |
| 687 | private findBestSlackSplitBefore(text: string, token: string): number { |
| 688 | let fromIndex = Math.min(text.length, MAX_MESSAGE_LENGTH); |
no test coverage detected