Skip to content

armgit / avibe

Public Imported from GitHub
0

Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.

fix(lark): adaptive multi-column quick-reply buttons (#794)

Qi Qi2f7302f85213
diff --git a/config/platform_registry.py b/config/platform_registry.py
index f0a7589e9..7572400e6 100644
--- a/config/platform_registry.py
+++ b/config/platform_registry.py
@@ -4,7 +4,7 @@ from __future__ import annotations
from dataclasses import asdict, dataclass, fields
from importlib import import_module
-from typing import Any
+from typing import Any, Optional
@dataclass(frozen=True)
@@ -20,6 +20,12 @@ class PlatformCapabilities:
supports_message_deletion: bool = False
markdown_upload_returns_message_id: bool = False
quick_reply_single_column: bool = False
+ # Max quick-reply buttons packed into one row before wrapping to the next.
+ # ``None`` means unlimited (all buttons on a single row). Ignored when
+ # ``quick_reply_single_column`` is set. Keeps wide-screen rows from
+ # overflowing and truncating button labels on platforms whose native
+ # wrapping (e.g. Lark's flow column_set) only kicks in on narrow screens.
+ quick_reply_max_per_row: Optional[int] = None
supports_typing_indicator: bool = False
typing_indicator_requires_clear: bool = False
typing_indicator_best_effort: bool = False
@@ -233,7 +239,13 @@ PLATFORM_REGISTRY: dict[str, PlatformDescriptor] = {
supports_quick_replies=True,
supports_message_editing=True,
markdown_upload_returns_message_id=True,
- quick_reply_single_column=True,
+ # Lark cards lay quick replies out in a flow column_set that wraps to
+ # the next line when a row is full, so keep them multi-column. Cap at
+ # 3 per row: Lark's flow wrapping only triggers on narrow screens, so
+ # on wide desktop a longer row would compress and truncate labels. 3
+ # fits comfortably in the desktop card for typical (2-4) short labels.
+ quick_reply_single_column=False,
+ quick_reply_max_per_row=3,
supports_reaction_indicator=True,
preferred_processing_indicator="reaction",
supports_status_bubble=True,
diff --git a/core/message_dispatcher.py b/core/message_dispatcher.py
index b4c6777a0..85a561335 100644
--- a/core/message_dispatcher.py
+++ b/core/message_dispatcher.py
@@ -1824,7 +1824,14 @@ class ConsolidatedMessageDispatcher:
callback = f"quick_reply:{btn.text}"
row.append(InlineButton(text=btn.text, callback_data=callback))
- rows = [[button] for button in row] if self._capabilities(context).quick_reply_single_column else [row]
+ caps = self._capabilities(context)
+ if caps.quick_reply_single_column:
+ rows = [[button] for button in row]
+ elif caps.quick_reply_max_per_row and caps.quick_reply_max_per_row > 0:
+ per_row = caps.quick_reply_max_per_row
+ rows = [row[i : i + per_row] for i in range(0, len(row), per_row)]
+ else:
+ rows = [row]
return InlineKeyboard(buttons=rows)
async def _send_result_inline(
diff --git a/modules/im/feishu.py b/modules/im/feishu.py
index 88b011abd..8d1cb92f3 100644
--- a/modules/im/feishu.py
+++ b/modules/im/feishu.py
@@ -498,8 +498,13 @@ class FeishuBot(BaseIMClient):
if text or subtext is None:
elements.append({"tag": "markdown", "content": text})
if buttons:
+ # Full-width ``fill`` only when the whole keyboard is a lone button.
+ # A single-button row that is merely the remainder of a chunked
+ # layout (e.g. 4 buttons -> 3 + 1) must stay in the flow column_set,
+ # otherwise it renders full width and clashes with the row above it.
+ single_button_card = len(buttons) == 1 and len(buttons[0]) == 1
for row in buttons:
- if len(row) == 1:
+ if len(row) == 1 and single_button_card:
btn = row[0]
behaviors_value: dict = {"key": btn["callback_data"]}
if btn.get("thread_id"):
@@ -524,8 +529,9 @@ class FeishuBot(BaseIMClient):
columns.append(
{
"tag": "column",
- "width": "weighted",
- "weight": 1,
+ # ``auto`` sizes each column to its button so the
+ # ``flow`` column_set can wrap to the next line.
+ "width": "auto",
"elements": [
{
"tag": "button",
@@ -541,7 +547,9 @@ class FeishuBot(BaseIMClient):
elements.append(
{
"tag": "column_set",
- "flex_mode": "none",
+ # ``flow`` wraps columns to the next line when a row is
+ # full, so quick replies stay readable on narrow screens.
+ "flex_mode": "flow",
"background_style": "default",
"columns": columns,
}
diff --git a/tests/test_feishu_post_messages.py b/tests/test_feishu_post_messages.py
index 96b8e7491..c4a71b5b6 100644
--- a/tests/test_feishu_post_messages.py
+++ b/tests/test_feishu_post_messages.py
@@ -218,5 +218,70 @@ class FeishuPostMessageTests(unittest.IsolatedAsyncioTestCase):
self.assertEqual(bot.on_message_callback.await_args.args[1], "scheduled follow-up context")
+class FeishuCardLayoutTests(unittest.TestCase):
+ def _make_bot(self) -> FeishuBot:
+ return FeishuBot(LarkConfig(app_id="app-id", app_secret="app-secret"))
+
+ def test_multi_button_row_uses_flow_column_set(self):
+ bot = self._make_bot()
+ card = json.loads(
+ bot._build_card_json(
+ "pick one",
+ [
+ [
+ {"text": "A", "callback_data": "quick_reply:A"},
+ {"text": "B", "callback_data": "quick_reply:B"},
+ ]
+ ],
+ )
+ )
+
+ column_set = card["body"]["elements"][1]
+ self.assertEqual(column_set["tag"], "column_set")
+ # ``flow`` lets a full row wrap to the next line on narrow screens, and
+ # ``auto`` widths size each column to its button so wrapping works.
+ self.assertEqual(column_set["flex_mode"], "flow")
+ self.assertEqual([c["width"] for c in column_set["columns"]], ["auto", "auto"])
+ self.assertNotIn("weight", column_set["columns"][0])
+
+ def test_single_button_row_fills_width(self):
+ bot = self._make_bot()
+ card = json.loads(
+ bot._build_card_json(
+ "confirm",
+ [[{"text": "OK", "callback_data": "quick_reply:OK"}]],
+ )
+ )
+
+ button = card["body"]["elements"][1]
+ self.assertEqual(button["tag"], "button")
+ self.assertEqual(button["width"], "fill")
+
+ def test_chunked_remainder_single_button_stays_in_flow_column_set(self):
+ # 4 buttons chunk to rows of [3, 1]; the trailing lone button must render
+ # as a flow column_set (auto width, left-aligned), not a full-width
+ # ``fill`` button that would clash with the row of three above it.
+ bot = self._make_bot()
+ card = json.loads(
+ bot._build_card_json(
+ "pick",
+ [
+ [
+ {"text": "A", "callback_data": "quick_reply:A"},
+ {"text": "B", "callback_data": "quick_reply:B"},
+ {"text": "C", "callback_data": "quick_reply:C"},
+ ],
+ [{"text": "D", "callback_data": "quick_reply:D"}],
+ ],
+ )
+ )
+
+ rows = card["body"]["elements"][1:]
+ self.assertEqual([e["tag"] for e in rows], ["column_set", "column_set"])
+ self.assertEqual(len(rows[1]["columns"]), 1)
+ self.assertEqual(rows[1]["columns"][0]["width"], "auto")
+ self.assertEqual(rows[1]["flex_mode"], "flow")
+
+
if __name__ == "__main__":
unittest.main()
diff --git a/tests/test_message_dispatcher_platform_limits.py b/tests/test_message_dispatcher_platform_limits.py
index 1c47c5e8e..7d4a648c2 100644
--- a/tests/test_message_dispatcher_platform_limits.py
+++ b/tests/test_message_dispatcher_platform_limits.py
@@ -164,5 +164,31 @@ class MessageDispatcherPlatformLimitTests(unittest.IsolatedAsyncioTestCase):
self.assertTrue(all(len(chunk.encode("utf-8")) <= 1900 for chunk in chunks))
+class _Btn:
+ def __init__(self, text: str):
+ self.text = text
+
+
+class QuickReplyKeyboardLayoutTests(unittest.TestCase):
+ def _rows(self, platform: str, count: int):
+ dispatcher = ConsolidatedMessageDispatcher(_StubController(platform))
+ context = MessageContext(user_id="u", channel_id="c", platform=platform)
+ buttons = [_Btn(f"b{i}") for i in range(count)]
+ keyboard = dispatcher._build_quick_reply_keyboard(context, buttons)
+ return [[b.text for b in row] for row in keyboard.buttons]
+
+ def test_lark_chunks_three_per_row(self):
+ # Lark caps at 3/row so wide-screen rows don't compress + truncate.
+ self.assertEqual(self._rows("lark", 5), [["b0", "b1", "b2"], ["b3", "b4"]])
+ self.assertEqual(self._rows("lark", 3), [["b0", "b1", "b2"]])
+
+ def test_telegram_stays_single_column(self):
+ self.assertEqual(self._rows("telegram", 3), [["b0"], ["b1"], ["b2"]])
+
+ def test_slack_keeps_single_row(self):
+ # No per-row cap and not single-column: all buttons stay on one row.
+ self.assertEqual(self._rows("slack", 3), [["b0", "b1", "b2"]])
+
+
if __name__ == "__main__":
unittest.main()
diff --git a/tests/test_reply_enhancer_platform.py b/tests/test_reply_enhancer_platform.py
index d3e6359d4..b2d97d59d 100644
--- a/tests/test_reply_enhancer_platform.py
+++ b/tests/test_reply_enhancer_platform.py
@@ -534,7 +534,7 @@ class ReplyEnhancerPlatformTests(unittest.IsolatedAsyncioTestCase):
[("C1", "Done.", "markdown")],
)
- async def test_lark_quick_reply_buttons_use_vertical_layout(self):
+ async def test_lark_quick_reply_buttons_use_horizontal_layout(self):
controller = _StubController("lark")
dispatcher = ConsolidatedMessageDispatcher(controller)
context = MessageContext(user_id="U1", channel_id="C1", platform="lark")
@@ -547,7 +547,9 @@ class ReplyEnhancerPlatformTests(unittest.IsolatedAsyncioTestCase):
self.assertEqual(len(controller.im_client.sent_button_messages), 1)
keyboard = controller.im_client.sent_button_messages[0][3]
- self.assertEqual([[button.text for button in row] for row in keyboard.buttons], [["继续"], ["提交PR"]])
+ # Lark quick replies are now multi-column (cap 3/row), so two buttons
+ # share a single row instead of stacking vertically.
+ self.assertEqual([[button.text for button in row] for row in keyboard.buttons], [["继续", "提交PR"]])
async def test_markdown_link_style_quick_reply_dispatches_label_callbacks(self):
controller = _StubController("slack")