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(feishu): preserve routing fields when selectors are missing

cyh802c93c5cfe8
diff --git a/modules/im/feishu.py b/modules/im/feishu.py
index 94f7612dc..100088b3a 100644
--- a/modules/im/feishu.py
+++ b/modules/im/feishu.py
@@ -1898,33 +1898,33 @@ class FeishuBot(BaseIMClient):
async def _handle_routing_form_submit(self, context: MessageContext, form_value: Dict[str, Any]):
"""Handle step 2 routing form submission (backend-specific options)."""
# Backend is embedded in form as a disabled select or retrieved from cache
+ cache_key = f"{context.channel_id}:{context.user_id}"
+ cached = self._routing_cache.get(cache_key, {})
backend = form_value.get("backend", "")
if not backend:
# Fallback: get from cache
- cache_key = f"{context.channel_id}:{context.user_id}"
- cached = self._routing_cache.get(cache_key, {})
backend = cached.get("_selected_backend", "")
if not backend:
logger.warning("Routing form submitted with empty backend, ignoring")
return
- # Helper to normalise "__default__" to None
- def _val(key: str):
- v = form_value.get(key)
- if v == "__default__" or not v:
- return None
- return v
-
- opencode_agent = _val("opencode_agent")
- opencode_model = _val("opencode_model")
- opencode_reasoning = _val("opencode_reasoning")
- claude_agent = _val("claude_agent")
- claude_model = _val("claude_model")
- claude_reasoning = _val("claude_reasoning")
- codex_agent = _val("codex_agent")
- codex_model = _val("codex_model")
- codex_reasoning = _val("codex_reasoning")
+ draft_routing = cached.get("draft_routing") or self._routing_draft_from_current(cached.get("current_routing"))
+
+ def _val(form_key: str, routing_field: str) -> Optional[str]:
+ if form_key in form_value:
+ return self._normalize_routing_field_value(form_value.get(form_key))
+ return draft_routing.get(routing_field)
+
+ opencode_agent = _val("opencode_agent", "opencode_agent")
+ opencode_model = _val("opencode_model", "opencode_model")
+ opencode_reasoning = _val("opencode_reasoning", "opencode_reasoning_effort")
+ claude_agent = _val("claude_agent", "claude_agent")
+ claude_model = _val("claude_model", "claude_model")
+ claude_reasoning = _val("claude_reasoning", "claude_reasoning_effort")
+ codex_agent = _val("codex_agent", "codex_agent")
+ codex_model = _val("codex_model", "codex_model")
+ codex_reasoning = _val("codex_reasoning", "codex_reasoning_effort")
if self._on_routing_update:
await self._on_routing_update(
diff --git a/tests/test_feishu_routing_card.py b/tests/test_feishu_routing_card.py
index 4107a6309..ffa684d38 100644
--- a/tests/test_feishu_routing_card.py
+++ b/tests/test_feishu_routing_card.py
@@ -19,13 +19,14 @@ def _install_opencode_utils_module() -> None:
return
repo_root = Path(__file__).resolve().parents[1]
- agents_mod = types.ModuleType("modules.agents")
- agents_mod.__path__ = [str(repo_root / "modules" / "agents")]
- opencode_mod = types.ModuleType("modules.agents.opencode")
- opencode_mod.__path__ = [str(repo_root / "modules" / "agents" / "opencode")]
-
- sys.modules["modules.agents"] = agents_mod
- sys.modules["modules.agents.opencode"] = opencode_mod
+ if "modules.agents" not in sys.modules:
+ agents_mod = types.ModuleType("modules.agents")
+ agents_mod.__path__ = [str(repo_root / "modules" / "agents")]
+ sys.modules["modules.agents"] = agents_mod
+ if "modules.agents.opencode" not in sys.modules:
+ opencode_mod = types.ModuleType("modules.agents.opencode")
+ opencode_mod.__path__ = [str(repo_root / "modules" / "agents" / "opencode")]
+ sys.modules["modules.agents.opencode"] = opencode_mod
spec = importlib.util.spec_from_file_location(
"modules.agents.opencode.utils",
@@ -169,6 +170,62 @@ class FeishuRoutingCardTests(unittest.IsolatedAsyncioTestCase):
reasoning_values = [option["value"] for option in reasoning_select["options"]]
self.assertIn("max", reasoning_values)
+ async def test_routing_submit_preserves_cached_codex_agent_when_field_missing(self):
+ bot = self._make_bot()
+ bot._on_routing_update = AsyncMock()
+
+ current_routing = SimpleNamespace(
+ claude_agent=None,
+ claude_model=None,
+ claude_reasoning_effort=None,
+ opencode_agent=None,
+ opencode_model=None,
+ opencode_reasoning_effort=None,
+ codex_agent="reviewer",
+ codex_model="gpt-5.1",
+ codex_reasoning_effort="medium",
+ )
+ bot._routing_cache["chat:user"] = {
+ "current_routing": current_routing,
+ "draft_routing": bot._routing_draft_from_current(current_routing),
+ "_selected_backend": "codex",
+ "claude_agents": [],
+ "claude_models": [],
+ "opencode_agents": [],
+ "opencode_models": {},
+ "opencode_default_config": {},
+ "codex_agents": [],
+ "codex_models": ["gpt-5.1", "gpt-5.4"],
+ }
+
+ context = MessageContext(
+ user_id="user",
+ channel_id="chat",
+ platform="lark",
+ platform_specific={"is_dm": False},
+ )
+
+ await bot._handle_routing_form_submit(
+ context,
+ {
+ "backend": "codex",
+ "codex_model": "gpt-5.4",
+ "codex_reasoning": "high",
+ },
+ )
+
+ bot._on_routing_update.assert_awaited_once()
+ args = bot._on_routing_update.await_args.args
+ self.assertEqual(args[3], None)
+ self.assertEqual(args[4], None)
+ self.assertEqual(args[5], None)
+ self.assertEqual(args[6], None)
+ self.assertEqual(args[7], None)
+ self.assertEqual(args[8], None)
+ self.assertEqual(args[9], "reviewer")
+ self.assertEqual(args[10], "gpt-5.4")
+ self.assertEqual(args[11], "high")
+
async def test_quick_reply_card_action_sets_lark_platform(self):
bot = self._make_bot()
bot.check_authorization = lambda **kwargs: AuthResult(allowed=True)