- Convert `get_recent_group_speaker` and `count_messages_between` in `chat/utils` to async functions to align with underlying asynchronous database calls, preventing potential blocking issues.
- Implement optional import for `sleep_system` within the `affinity_flow_chatter` plugin using a try-except block. This decouples the hard dependency between the two plugins, enhancing modularity and ensuring the chatter plugin remains operational even if the sleep system is unavailable.
In the LLM response post-processing flow, a new protection layer for quoted content has been added. This prevents the sentence splitter from incorrectly breaking up complete sentences enclosed in quotation marks, thus ensuring the integrity of the quoted text.
- Adds `protect_quoted_content` and `recover_quoted_content` functions.
- Upgrades the response processing to a three-layer protection system (kaomoji, quotes, special blocks).
- Also adjusts the default values for typing simulation time to improve user experience.
This commit redesigns the LLM response handling pipeline to gracefully manage complex, long, and structured outputs, shifting from a restrictive filtering model to a more resilient and content-aware approach.
The previous implementation suffered from brittleness, often discarding valid responses or corrupting formatted content. This refactor introduces two core changes to ensure response integrity:
1. **Adaptive Message Merging:** Replaces the rigid message count and length limits, which caused the silent dropping of valid long-form answers. The new logic dynamically merges the shortest adjacent sentences if a response is overly fragmented, ensuring the full thought is preserved while adhering to display limits.
2. **Content-Aware Pre-processing:** Implements a protection mechanism for special text formats. It now identifies and isolates Markdown code blocks, LaTeX-style math equations, and other code-like segments using placeholders before splitting or typo generation. This prevents formatting corruption and ensures technical content is rendered correctly.
Additionally, the LLM prompt for splitting has been refined to emphasize logical coherence over simple fragmentation.
Finally, this commit also hardens the `LLMRequest` class against race conditions by adding an `asyncio.Lock` to serialize generation requests, improving the system's stability under concurrent workloads.