| 792 | |
| 793 | |
| 794 | def _split_text(content: str, limit: int) -> list[str]: |
| 795 | text = content.strip() |
| 796 | if not text: |
| 797 | return [""] |
| 798 | if len(text) <= limit: |
| 799 | return [text] |
| 800 | chunks = [] |
| 801 | remaining = text |
| 802 | while remaining: |
| 803 | chunk = remaining[:limit] |
| 804 | if len(remaining) > limit: |
| 805 | split_at = chunk.rfind("\n") |
| 806 | if split_at < limit // 3: |
| 807 | split_at = chunk.rfind(" ") |
| 808 | if split_at >= limit // 3: |
| 809 | chunk = chunk[:split_at] |
| 810 | chunks.append(chunk.strip()) |
| 811 | remaining = remaining[len(chunk):].lstrip() |
| 812 | return [chunk for chunk in chunks if chunk] |
| 813 | |
| 814 | |
| 815 | def _is_webhook_signature_valid(*, encrypt_key: str, headers: Any, body_bytes: bytes) -> bool: |