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.
Python agentagent-osaiai-agentsai-partnerchatopsclaudeclaude-codecodexdevtoolsdiscord-botlark-botllmlocal-firstlong-term-memoryopencodeslack-botvibe-codingvibeywechat
refactor(platforms): drive indicators from capabilities
cyh0057a63b5e28
diff --git a/config/platform_registry.py b/config/platform_registry.pyindex b27b5f741..585190220 100644--- a/config/platform_registry.py+++ b/config/platform_registry.py@@ -16,6 +16,13 @@ class PlatformCapabilities:supports_message_editing: boolmarkdown_upload_returns_message_id: bool = Falsequick_reply_single_column: bool = False+ supports_processing_typing: bool = False+ processing_typing_requires_clear: bool = False+ supports_processing_reaction: bool = False+ supports_processing_message: bool = True+ supports_processing_message_delete: bool = False+ preferred_processing_indicator: str = "typing"+ force_preferred_processing_indicator: bool = False@dataclass(frozen=True)@@ -107,6 +114,8 @@ PLATFORM_REGISTRY: dict[str, PlatformDescriptor] = {supports_buttons=True,supports_quick_replies=True,supports_message_editing=True,+ supports_processing_typing=True,+ supports_processing_reaction=True,),),"discord": PlatformDescriptor(@@ -126,6 +135,8 @@ PLATFORM_REGISTRY: dict[str, PlatformDescriptor] = {supports_quick_replies=True,supports_message_editing=True,markdown_upload_returns_message_id=True,+ supports_processing_typing=True,+ supports_processing_reaction=True,),),"telegram": PlatformDescriptor(@@ -146,6 +157,9 @@ PLATFORM_REGISTRY: dict[str, PlatformDescriptor] = {supports_message_editing=True,markdown_upload_returns_message_id=True,quick_reply_single_column=True,+ supports_processing_typing=True,+ supports_processing_reaction=True,+ supports_processing_message_delete=True,),),"lark": PlatformDescriptor(@@ -166,6 +180,8 @@ PLATFORM_REGISTRY: dict[str, PlatformDescriptor] = {supports_message_editing=True,markdown_upload_returns_message_id=True,quick_reply_single_column=True,+ supports_processing_reaction=True,+ preferred_processing_indicator="reaction",),),"wechat": PlatformDescriptor(@@ -184,6 +200,11 @@ PLATFORM_REGISTRY: dict[str, PlatformDescriptor] = {supports_buttons=False,supports_quick_replies=False,supports_message_editing=False,+ supports_processing_typing=True,+ processing_typing_requires_clear=True,+ supports_processing_reaction=False,+ preferred_processing_indicator="typing",+ force_preferred_processing_indicator=True,),),}diff --git a/core/processing_indicator.py b/core/processing_indicator.pyindex 11615e916..eceb37b94 100644--- a/core/processing_indicator.py+++ b/core/processing_indicator.py@@ -10,14 +10,17 @@ from __future__ import annotationsimport asyncioimport logging-from dataclasses import dataclass+from dataclasses import dataclass, replacefrom typing import Any, Optional+from config.platform_registry import PlatformCapabilities, get_platform_descriptorfrom modules.im import MessageContextfrom vibe.i18n import t as i18n_tlogger = logging.getLogger(__name__)+_PROCESSING_INDICATOR_MODES = ("typing", "reaction", "message")+@dataclassclass ProcessingIndicatorHandle:@@ -94,14 +97,48 @@ class ProcessingIndicatorService:or getattr(self.config, "platform", ""))- def _should_use_typing_ack(self, context: MessageContext) -> bool:- if self._get_context_platform(context) == "wechat":- return True- return getattr(self.config, "ack_mode", "typing") == "typing"+ def _capabilities(self, context: MessageContext) -> PlatformCapabilities:+ return get_platform_descriptor(self._get_context_platform(context)).capabilities++ def _mode_supported(+ self,+ capabilities: PlatformCapabilities,+ mode: str,+ context: MessageContext,+ ) -> bool:+ if mode == "typing":+ return capabilities.supports_processing_typing+ if mode == "reaction":+ return capabilities.supports_processing_reaction and bool(context.message_id)+ if mode == "message":+ return capabilities.supports_processing_message+ return False++ def _candidate_modes(self, capabilities: PlatformCapabilities) -> list[str]:+ preferred = capabilities.preferred_processing_indicator+ configured = getattr(self.config, "ack_mode", "typing")+ if capabilities.force_preferred_processing_indicator:+ candidates = [preferred]+ else:+ candidates = [configured, preferred, "typing", "reaction", "message"]+ return [+ mode+ for index, mode in enumerate(candidates)+ if mode in _PROCESSING_INDICATOR_MODES and mode not in candidates[:index]+ ]++ def _processing_modes(self, context: MessageContext) -> list[str]:+ capabilities = self._capabilities(context)+ return [+ mode+ for mode in self._candidate_modes(capabilities)+ if self._mode_supported(capabilities, mode, context)+ ]def _get_target_context(self, context: MessageContext) -> MessageContext:im_client = self._get_im_client(context)- if im_client.should_use_thread_for_reply() and context.thread_id:+ capabilities = self._capabilities(context)+ if capabilities.supports_threads and im_client.should_use_thread_for_reply() and context.thread_id:return MessageContext(user_id=context.user_id,channel_id=context.channel_id,@@ -134,49 +171,103 @@ class ProcessingIndicatorService:if not enabled:return handle+ for mode in self._processing_modes(context):+ if mode == "message" and await self._start_message_indicator(handle, agent_name):+ return handle+ if mode == "typing" and await self._start_typing_indicator(handle):+ return handle+ if mode == "reaction" and await self._start_reaction_indicator(handle):+ return handle++ return handle++ async def _start_message_indicator(self, handle: ProcessingIndicatorHandle, agent_name: str) -> bool:+ ack_context = self._get_target_context(handle.context)+ try:+ ack_message_id = await self._get_im_client(ack_context).send_message(+ ack_context,+ self._get_ack_text(agent_name),+ )+ except Exception as ack_err:+ logger.debug("Failed to send ack message: %s", ack_err)+ return False++ if not ack_message_id:+ logger.info("Ack message not applied (platform returned empty message id)")+ return False++ handle.ack_message_id = ack_message_id+ handle.ack_message_channel_id = ack_context.channel_id+ return True++ async def _start_typing_indicator(self, handle: ProcessingIndicatorHandle) -> bool:+ context = handle.contextim_client = self._get_im_client(context)- ack_mode = getattr(self.config, "ack_mode", "typing")- effective_ack_mode = "typing" if self._get_context_platform(context) == "wechat" else ack_mode+ try:+ ok = await im_client.send_typing_indicator(context)+ except Exception as ack_err:+ logger.debug("Failed to send typing ack: %s", ack_err)+ return False- if effective_ack_mode == "message":- ack_context = self._get_target_context(context)- try:- handle.ack_message_id = await self._get_im_client(ack_context).send_message(- ack_context,- self._get_ack_text(agent_name),- )- handle.ack_message_channel_id = ack_context.channel_id- except Exception as ack_err:- logger.debug("Failed to send ack message: %s", ack_err)- return handle+ if not ok:+ logger.info("Typing indicator not applied (platform returned False)")+ return False- if self._should_use_typing_ack(context):- try:- ok = await im_client.send_typing_indicator(context)- if ok:- handle.typing_indicator_active = True- handle.typing_indicator_task = asyncio.create_task(self._typing_keepalive_loop(context))- return handle- logger.info("Typing indicator not applied (platform returned False)")- except Exception as ack_err:- logger.debug("Failed to send typing ack: %s", ack_err)- if self._get_context_platform(context) == "wechat":- return handle+ handle.typing_indicator_active = True+ handle.typing_indicator_task = asyncio.create_task(self._typing_keepalive_loop(context))+ return True+ async def _start_reaction_indicator(self, handle: ProcessingIndicatorHandle) -> bool:+ context = handle.context+ if not context.message_id:+ return False+ im_client = self._get_im_client(context)try:- if context.message_id:- handle.ack_reaction_message_id = context.message_id- handle.ack_reaction_emoji = ":eyes:"- ok = await im_client.add_reaction(- context,- handle.ack_reaction_message_id,- handle.ack_reaction_emoji,- )- if not ok:- logger.info("Ack reaction not applied (platform returned False)")+ ok = await im_client.add_reaction(context, context.message_id, ":eyes:")except Exception as ack_err:logger.debug("Failed to add reaction ack: %s", ack_err)- return handle+ return False++ if not ok:+ logger.info("Ack reaction not applied (platform returned False)")+ return False++ handle.ack_reaction_message_id = context.message_id+ handle.ack_reaction_emoji = ":eyes:"+ return True++ def _delete_context(self, handle: ProcessingIndicatorHandle, channel_id: Optional[str]) -> MessageContext:+ target_channel_id = channel_id or handle.ack_message_channel_id+ if target_channel_id and target_channel_id != handle.context.channel_id:+ return replace(handle.context, channel_id=target_channel_id)+ return handle.context++ def _should_delete_ack_message(self, handle: ProcessingIndicatorHandle) -> bool:+ return self._capabilities(handle.context).supports_processing_message_delete++ def _should_clear_typing_indicator(self, handle: ProcessingIndicatorHandle) -> bool:+ return self._capabilities(handle.context).processing_typing_requires_clear++ async def _delete_ack_message_for_handle(+ self,+ handle: ProcessingIndicatorHandle,+ *,+ request: Optional[Any] = None,+ channel_id: Optional[str] = None,+ ) -> None:+ ack_id = handle.ack_message_id+ if not ack_id:+ return+ if self._should_delete_ack_message(handle):+ im_client = self._get_im_client(handle.context)+ if hasattr(im_client, "delete_message"):+ try:+ await im_client.delete_message(self._delete_context(handle, channel_id), ack_id)+ except Exception as err:+ logger.debug("Could not delete ack message: %s", err)+ handle.ack_message_id = None+ if request is not None:+ request.ack_message_id = Nonedef apply_to_request(self, request: Any, handle: ProcessingIndicatorHandle) -> None:request.processing_indicator = handle@@ -223,29 +314,6 @@ class ProcessingIndicatorService:if getattr(request, "processing_indicator", None) is None:request.processing_indicator = handle- async def _delete_ack_message_for_handle(- self,- handle: ProcessingIndicatorHandle,- *,- request: Optional[Any] = None,- channel_id: Optional[str] = None,- ) -> None:- ack_id = handle.ack_message_id- if ack_id:- im_client = self._get_im_client(handle.context)- if hasattr(im_client, "delete_message"):- try:- await im_client.delete_message(- channel_id or handle.ack_message_channel_id or handle.context.channel_id,- ack_id,- )- except Exception as err:- logger.debug("Could not delete ack message: %s", err)- finally:- handle.ack_message_id = None- if request is not None:- request.ack_message_id = None-async def finish(self, request_or_handle: Any) -> None:if isinstance(request_or_handle, ProcessingIndicatorHandle):handle = request_or_handle@@ -270,15 +338,16 @@ class ProcessingIndicatorService:if request is not None:request.typing_indicator_task = None- if handle.typing_indicator_active:+ if handle.typing_indicator_active and self._should_clear_typing_indicator(handle):try:await self._get_im_client(handle.context).clear_typing_indicator(handle.context)except Exception as err:logger.debug("Failed to clear typing indicator: %s", err)- finally:- handle.typing_indicator_active = False- if request is not None:- request.typing_indicator_active = False++ if handle.typing_indicator_active:+ handle.typing_indicator_active = False+ if request is not None:+ request.typing_indicator_active = Falseif handle.ack_reaction_message_id and handle.ack_reaction_emoji:try:diff --git a/docs/plans/processing-indicator-lifecycle.md b/docs/plans/processing-indicator-lifecycle.mdindex f7c721ac6..3a0fb845f 100644--- a/docs/plans/processing-indicator-lifecycle.md+++ b/docs/plans/processing-indicator-lifecycle.md@@ -18,14 +18,28 @@ conversation context token, and restored OpenCode polls did not own that state.`core.processing_indicator.ProcessingIndicatorService` is the lifecycle owner.- Start indicators through one service.+- Select indicator strategy from platform registry capabilities, not platform+ string checks.- Store a single handle on `AgentRequest`.- Keep legacy request fields in sync for compatibility while callers migrate.- Finish and ack-message deletion go through the same service for OpenCode,Codex, Claude, and handler-level errors.- Persist a serializable handle snapshot for restored OpenCode polls.-## Follow-Up Boundary+## Platform Capability Source-This PR keeps the public request fields as a compatibility layer. A later cleanup-can remove direct reads of `ack_reaction_message_id`, `typing_indicator_active`,-and related fields once all tests and helper code use the handle directly.+The registry owns ACK/typing differences:++- which platforms can use typing, reaction, or message indicators+- whether typing requires an explicit clear operation+- whether message ACKs can be deleted+- whether a platform has a preferred or forced indicator mode++This keeps WeChat's explicit cancel requirement, Lark's reaction preference, and+Telegram's message-delete support out of backend-specific code.++## Compatibility Boundary++This PR keeps the public request fields as a compatibility layer. They mirror the+handle, but lifecycle ownership and platform policy live in+`ProcessingIndicatorService` plus `config.platform_registry`.diff --git a/tests/test_message_handler_typing.py b/tests/test_message_handler_typing.pyindex a701126a6..d6a95710e 100644--- a/tests/test_message_handler_typing.py+++ b/tests/test_message_handler_typing.py@@ -331,6 +331,20 @@ class MessageHandlerTypingTests(unittest.IsolatedAsyncioTestCase):self.assertEqual(request.ack_reaction_emoji, ":eyes:")self.assertEqual(controller.im_client.reactions, [("tg-chat", "m1", ":eyes:")])+ async def test_lark_typing_preference_uses_registry_reaction_capability(self):+ controller = _StubController(platform="lark", ack_mode="typing", typing_result=True)+ handler = MessageHandler(controller)+ handler.set_session_handler(_StubSessionHandler())+ context = MessageContext(user_id="lark-user", channel_id="lark-chat", message_id="om_1", platform="lark")++ await handler.handle_user_message(context, "hello")++ _, request = controller.agent_service.requests[0]+ self.assertFalse(request.typing_indicator_active)+ self.assertEqual(controller.im_client.typing_calls, [])+ self.assertEqual(request.ack_reaction_message_id, "om_1")+ self.assertEqual(controller.im_client.reactions, [("lark-chat", "om_1", ":eyes:")])+async def test_platform_specific_client_is_used_for_user_info(self):controller = _StubController(platform="slack", ack_mode="reaction", typing_result=True)handler = MessageHandler(controller)diff --git a/tests/test_multi_platform_runtime.py b/tests/test_multi_platform_runtime.pyindex cea570721..549a792dc 100644--- a/tests/test_multi_platform_runtime.py+++ b/tests/test_multi_platform_runtime.py@@ -83,6 +83,10 @@ class _StubClient(BaseIMClient):self.sent.append(("clear_typing", context.platform, context.user_id, (context.platform_specific or {}).get("context_token")))return True+ async def delete_message(self, context, message_id):+ self.sent.append(("delete", context.platform, context.channel_id, message_id))+ return True+def format_markdown(self, text: str) -> str:return text@@ -279,6 +283,64 @@ def test_processing_indicator_handle_is_source_of_truth_for_backend_cleanup():assert wechat.sent == [("clear_typing", "wechat", "user-1", "ctx-1")]+def test_processing_indicator_clear_policy_comes_from_platform_registry():+ slack = _StubClient("slack")++ class _Controller:+ def __init__(self):+ self.config = type("Config", (), {"platform": "slack", "ack_mode": "typing", "language": "en"})()+ self.im_client = slack++ def get_im_client_for_context(self, context):+ return slack++ controller = _Controller()+ service = ProcessingIndicatorService(controller)+ handle = service.handle_from_snapshot(+ {+ "platform": "slack",+ "user_id": "user-1",+ "channel_id": "chan-1",+ "typing_indicator_active": True,+ }+ )++ asyncio.run(service.finish(handle))++ assert handle.typing_indicator_active is False+ assert slack.sent == []+++def test_processing_indicator_message_delete_policy_comes_from_platform_registry():+ telegram = _StubClient("telegram")++ class _Controller:+ def __init__(self):+ self.config = type("Config", (), {"platform": "telegram", "ack_mode": "message", "language": "en"})()+ self.im_client = telegram++ def get_im_client_for_context(self, context):+ return telegram++ service = ProcessingIndicatorService(_Controller())+ handle = service.handle_from_snapshot(+ {+ "platform": "telegram",+ "user_id": "user-1",+ "channel_id": "chat-1",+ "ack_message_id": "ack-1",+ "ack_message_channel_id": "chat-1",+ }+ )+ request = type("Request", (), {"context": handle.context, "ack_message_id": "ack-1", "processing_indicator": handle})()++ asyncio.run(service.delete_ack_message(request))++ assert request.ack_message_id is None+ assert handle.ack_message_id is None+ assert telegram.sent == [("delete", "telegram", "chat-1", "ack-1")]++def test_multi_im_client_routes_download_by_file_info_platform():slack = _StubClient("slack")wechat = _StubClient("wechat")diff --git a/tests/test_platform_registry.py b/tests/test_platform_registry.pyindex 84beda17c..e3ecc3d07 100644--- a/tests/test_platform_registry.py+++ b/tests/test_platform_registry.py@@ -15,6 +15,12 @@ def test_platform_catalog_exposes_capability_flags() -> None:assert catalog["telegram"]["capabilities"]["supports_threads"] is Falseassert catalog["wechat"]["capabilities"]["supports_buttons"] is Falseassert catalog["wechat"]["capabilities"]["supports_channels"] is False+ assert catalog["wechat"]["capabilities"]["supports_processing_typing"] is True+ assert catalog["wechat"]["capabilities"]["processing_typing_requires_clear"] is True+ assert catalog["wechat"]["capabilities"]["force_preferred_processing_indicator"] is True+ assert catalog["lark"]["capabilities"]["supports_processing_typing"] is False+ assert catalog["lark"]["capabilities"]["preferred_processing_indicator"] == "reaction"+ assert catalog["telegram"]["capabilities"]["supports_processing_message_delete"] is Truedef test_credential_readiness_comes_from_platform_descriptor() -> None:diff --git a/ui/src/lib/platforms.ts b/ui/src/lib/platforms.tsindex 2111819ef..1d14f7075 100644--- a/ui/src/lib/platforms.ts+++ b/ui/src/lib/platforms.ts@@ -8,6 +8,13 @@ export type PlatformCapabilities = {supports_message_editing?: boolean;markdown_upload_returns_message_id?: boolean;quick_reply_single_column?: boolean;+ supports_processing_typing?: boolean;+ processing_typing_requires_clear?: boolean;+ supports_processing_reaction?: boolean;+ supports_processing_message?: boolean;+ supports_processing_message_delete?: boolean;+ preferred_processing_indicator?: string;+ force_preferred_processing_indicator?: boolean;};export type PlatformDescriptor = {@@ -32,6 +39,10 @@ const LEGACY_FALLBACK_CATALOG: PlatformDescriptor[] = [supports_buttons: true,supports_quick_replies: true,supports_message_editing: true,+ supports_processing_typing: true,+ supports_processing_reaction: true,+ supports_processing_message: true,+ preferred_processing_indicator: 'typing',},},{@@ -47,6 +58,10 @@ const LEGACY_FALLBACK_CATALOG: PlatformDescriptor[] = [supports_quick_replies: true,supports_message_editing: true,markdown_upload_returns_message_id: true,+ supports_processing_typing: true,+ supports_processing_reaction: true,+ supports_processing_message: true,+ preferred_processing_indicator: 'typing',},},{@@ -63,6 +78,11 @@ const LEGACY_FALLBACK_CATALOG: PlatformDescriptor[] = [supports_message_editing: true,markdown_upload_returns_message_id: true,quick_reply_single_column: true,+ supports_processing_typing: true,+ supports_processing_reaction: true,+ supports_processing_message: true,+ supports_processing_message_delete: true,+ preferred_processing_indicator: 'typing',},},{@@ -79,6 +99,9 @@ const LEGACY_FALLBACK_CATALOG: PlatformDescriptor[] = [supports_message_editing: true,markdown_upload_returns_message_id: true,quick_reply_single_column: true,+ supports_processing_reaction: true,+ supports_processing_message: true,+ preferred_processing_indicator: 'reaction',},},{@@ -93,6 +116,12 @@ const LEGACY_FALLBACK_CATALOG: PlatformDescriptor[] = [supports_buttons: false,supports_quick_replies: false,supports_message_editing: false,+ supports_processing_typing: true,+ processing_typing_requires_clear: true,+ supports_processing_reaction: false,+ supports_processing_message: true,+ preferred_processing_indicator: 'typing',+ force_preferred_processing_indicator: true,},},];