agentle 0.9.33__py3-none-any.whl → 0.9.35__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- agentle/agents/whatsapp/whatsapp_bot.py +56 -24
- {agentle-0.9.33.dist-info → agentle-0.9.35.dist-info}/METADATA +1 -1
- {agentle-0.9.33.dist-info → agentle-0.9.35.dist-info}/RECORD +5 -5
- {agentle-0.9.33.dist-info → agentle-0.9.35.dist-info}/WHEEL +0 -0
- {agentle-0.9.33.dist-info → agentle-0.9.35.dist-info}/licenses/LICENSE +0 -0
|
@@ -2679,11 +2679,25 @@ class WhatsAppBot[T_Schema: WhatsAppResponseBase = WhatsAppResponseBase](BaseMod
|
|
|
2679
2679
|
return "mp3" # default
|
|
2680
2680
|
|
|
2681
2681
|
def _split_message_by_line_breaks(self, text: str) -> Sequence[str]:
|
|
2682
|
-
"""Split message by line breaks first, then by length if needed with enhanced validation.
|
|
2682
|
+
"""Split message by line breaks first, then by length if needed with enhanced validation.
|
|
2683
|
+
|
|
2684
|
+
CRITICAL: This method must preserve line breaks within messages for proper WhatsApp formatting.
|
|
2685
|
+
"""
|
|
2683
2686
|
if not text or not text.strip():
|
|
2684
2687
|
return ["[Mensagem vazia]"] # Portuguese: "Empty message"
|
|
2685
2688
|
|
|
2686
2689
|
try:
|
|
2690
|
+
# Check if entire text fits in one message - if so, return it as-is
|
|
2691
|
+
if len(text) <= self.config.max_message_length:
|
|
2692
|
+
logger.debug(
|
|
2693
|
+
f"[SPLIT_MESSAGE] Message fits in single message ({len(text)} chars), returning as-is"
|
|
2694
|
+
)
|
|
2695
|
+
return [text]
|
|
2696
|
+
|
|
2697
|
+
logger.info(
|
|
2698
|
+
f"[SPLIT_MESSAGE] Message too long ({len(text)} chars), splitting into multiple messages"
|
|
2699
|
+
)
|
|
2700
|
+
|
|
2687
2701
|
# First split by double line breaks (paragraphs)
|
|
2688
2702
|
paragraphs = text.split("\n\n")
|
|
2689
2703
|
messages: MutableSequence[str] = []
|
|
@@ -2692,38 +2706,54 @@ class WhatsAppBot[T_Schema: WhatsAppResponseBase = WhatsAppResponseBase](BaseMod
|
|
|
2692
2706
|
if not paragraph.strip():
|
|
2693
2707
|
continue
|
|
2694
2708
|
|
|
2709
|
+
# If paragraph fits, keep it intact with all line breaks
|
|
2710
|
+
if len(paragraph) <= self.config.max_message_length:
|
|
2711
|
+
messages.append(paragraph)
|
|
2712
|
+
continue
|
|
2713
|
+
|
|
2714
|
+
# Paragraph is too long - need to split it
|
|
2695
2715
|
# Check if paragraph is a list (has list markers)
|
|
2696
2716
|
lines = paragraph.split("\n")
|
|
2697
2717
|
is_list_paragraph = self._is_list_content(lines)
|
|
2698
2718
|
|
|
2699
2719
|
if is_list_paragraph:
|
|
2700
|
-
# Group list items together
|
|
2701
|
-
# IMPORTANT: Keep line breaks intact for list formatting
|
|
2720
|
+
# Group list items together, preserving line breaks
|
|
2702
2721
|
grouped_list = self._group_list_items(lines)
|
|
2703
2722
|
messages.extend(grouped_list)
|
|
2704
2723
|
else:
|
|
2705
|
-
# For non-list paragraphs,
|
|
2706
|
-
|
|
2707
|
-
|
|
2708
|
-
|
|
2709
|
-
|
|
2710
|
-
|
|
2711
|
-
|
|
2712
|
-
|
|
2713
|
-
|
|
2714
|
-
#
|
|
2715
|
-
|
|
2716
|
-
|
|
2717
|
-
|
|
2718
|
-
continue
|
|
2724
|
+
# For non-list paragraphs, try to keep lines together
|
|
2725
|
+
current_chunk = ""
|
|
2726
|
+
for line in lines:
|
|
2727
|
+
if not line.strip():
|
|
2728
|
+
# Preserve empty lines for spacing
|
|
2729
|
+
if current_chunk:
|
|
2730
|
+
current_chunk += "\n"
|
|
2731
|
+
continue
|
|
2732
|
+
|
|
2733
|
+
# Try adding this line to current chunk
|
|
2734
|
+
test_chunk = (
|
|
2735
|
+
current_chunk + ("\n" if current_chunk else "") + line
|
|
2736
|
+
)
|
|
2719
2737
|
|
|
2720
|
-
|
|
2721
|
-
|
|
2722
|
-
|
|
2723
|
-
|
|
2724
|
-
|
|
2738
|
+
if len(test_chunk) <= self.config.max_message_length:
|
|
2739
|
+
current_chunk = test_chunk
|
|
2740
|
+
else:
|
|
2741
|
+
# Current chunk is full, save it
|
|
2742
|
+
if current_chunk:
|
|
2743
|
+
messages.append(current_chunk)
|
|
2744
|
+
|
|
2745
|
+
# Check if single line is too long
|
|
2746
|
+
if len(line) > self.config.max_message_length:
|
|
2747
|
+
# Split long line by length
|
|
2725
2748
|
split_lines = self._split_long_line(line)
|
|
2726
2749
|
messages.extend(split_lines)
|
|
2750
|
+
current_chunk = ""
|
|
2751
|
+
else:
|
|
2752
|
+
current_chunk = line
|
|
2753
|
+
|
|
2754
|
+
# Add remaining chunk
|
|
2755
|
+
if current_chunk:
|
|
2756
|
+
messages.append(current_chunk)
|
|
2727
2757
|
|
|
2728
2758
|
# Filter out empty messages and validate
|
|
2729
2759
|
final_messages = []
|
|
@@ -2735,9 +2765,11 @@ class WhatsAppBot[T_Schema: WhatsAppResponseBase = WhatsAppResponseBase](BaseMod
|
|
|
2735
2765
|
for i in range(0, len(msg), 65536):
|
|
2736
2766
|
chunk = msg[i : i + 65536]
|
|
2737
2767
|
if chunk.strip():
|
|
2738
|
-
|
|
2768
|
+
# Don't strip - preserve line breaks
|
|
2769
|
+
final_messages.append(chunk)
|
|
2739
2770
|
else:
|
|
2740
|
-
|
|
2771
|
+
# Don't strip - preserve line breaks within the message
|
|
2772
|
+
final_messages.append(msg)
|
|
2741
2773
|
|
|
2742
2774
|
# If no valid messages were created, return a placeholder
|
|
2743
2775
|
if not final_messages:
|
|
@@ -137,7 +137,7 @@ agentle/agents/ui/__init__.py,sha256=IjHRV0k2DNwvFrEHebmsXiBvmITE8nQUnsR07h9tVkU
|
|
|
137
137
|
agentle/agents/ui/streamlit.py,sha256=9afICL0cxtG1o2pWh6vH39-NdKiVfADKiXo405F2aB0,42829
|
|
138
138
|
agentle/agents/whatsapp/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
139
139
|
agentle/agents/whatsapp/human_delay_calculator.py,sha256=BGCDeoNTPsMn4d_QYmG0BWGCG8SiUJC6Fk295ulAsAk,18268
|
|
140
|
-
agentle/agents/whatsapp/whatsapp_bot.py,sha256=
|
|
140
|
+
agentle/agents/whatsapp/whatsapp_bot.py,sha256=tF35s2c4G9Fo0bLVmePYXWSnSNEgg-Rpi9V0MrrRCCA,164948
|
|
141
141
|
agentle/agents/whatsapp/models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
142
142
|
agentle/agents/whatsapp/models/audio_message.py,sha256=kUqG1HdNW6DCYD-CqscJ6WHlAyv9ufmTSKMdjio9XWk,2705
|
|
143
143
|
agentle/agents/whatsapp/models/context_info.py,sha256=sk80KuNE36S6VRnLh7n6UXmzZCXIB4E4lNxnRyVizg8,563
|
|
@@ -1018,7 +1018,7 @@ agentle/web/actions/scroll.py,sha256=WqVVAORNDK3BL1oASZBPmXJYeSVkPgAOmWA8ibYO82I
|
|
|
1018
1018
|
agentle/web/actions/viewport.py,sha256=KCwm88Pri19Qc6GLHC69HsRxmdJz1gEEAODfggC_fHo,287
|
|
1019
1019
|
agentle/web/actions/wait.py,sha256=IKEywjf-KC4ni9Gkkv4wgc7bY-hk7HwD4F-OFWlyf2w,571
|
|
1020
1020
|
agentle/web/actions/write_text.py,sha256=9mxfHcpKs_L7BsDnJvOYHQwG8M0GWe61SRJAsKk3xQ8,748
|
|
1021
|
-
agentle-0.9.
|
|
1022
|
-
agentle-0.9.
|
|
1023
|
-
agentle-0.9.
|
|
1024
|
-
agentle-0.9.
|
|
1021
|
+
agentle-0.9.35.dist-info/METADATA,sha256=x56kvGN-I-GmLRyrLOcTFTdrVFgpI4KV6tKbFRr_2Gc,86849
|
|
1022
|
+
agentle-0.9.35.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
1023
|
+
agentle-0.9.35.dist-info/licenses/LICENSE,sha256=T90S9vqRS6qP-voULxAcvwEs558wRRo6dHuZrjgcOUI,1085
|
|
1024
|
+
agentle-0.9.35.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|