MCPcopy Create free account
hub / github.com/CreminiAI/skillpack / findSlackSafeSplitPoint

Method findSlackSafeSplitPoint

src/runtime/adapters/slack.ts:658–685  ·  view source on GitHub ↗
(text: string)

Source from the content-addressed store, hash-verified

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);

Callers 1

splitMessageMethod · 0.95

Calls 2

Tested by

no test coverage detected