diff --git a/runtime/application/gateway/inbound_service.py b/runtime/application/gateway/inbound_service.py index 9754c304..da17a545 100644 --- a/runtime/application/gateway/inbound_service.py +++ b/runtime/application/gateway/inbound_service.py @@ -1,6 +1,7 @@ from __future__ import annotations import hashlib +import re from typing import Any from oclaw.interfaces.channels.base import InboundMessage, OutboundMessage @@ -307,9 +308,19 @@ def _should_suppress_channel_reply(*, channel: str, text: str) -> bool: if not t: return True low = t.lower() - if 'missing api key for provider "openai"' in low: + # Silence gateway/provider credential errors for weixin user-facing channel. + # Match variants like: + # - Missing API key for provider "openai" + # - Missing API key for provider 'openai' + # - Missing API key ... provider openai + if ( + ("missing api key" in low and "provider" in low and "openai" in low) + or bool(re.search(r'missing\s+api\s+key.*provider\s+[\'"]?openai[\'"]?', low)) + ): return True - if "openai / 兼容 api" in t and "api key" in low: + if ("openai / 兼容 api" in t or "openai 兼容 api" in t) and "api key" in low: + return True + if "configure the gateway auth for that provider" in low and "openai" in low: return True return False diff --git a/tests/test_inbound_service_reply_suppress.py b/tests/test_inbound_service_reply_suppress.py new file mode 100644 index 00000000..67813950 --- /dev/null +++ b/tests/test_inbound_service_reply_suppress.py @@ -0,0 +1,15 @@ +from __future__ import annotations + +from oclaw.runtime.application.gateway.inbound_service import _should_suppress_channel_reply + + +def test_should_suppress_weixin_openai_missing_api_key_message() -> None: + text = '⚠️ Missing API key for provider "openai". Configure the gateway auth for that provider, then try again.' + assert _should_suppress_channel_reply(channel="wechat", text=text) is True + assert _should_suppress_channel_reply(channel="weixin", text=text) is True + + +def test_should_not_suppress_non_weixin_channel() -> None: + text = '⚠️ Missing API key for provider "openai". Configure the gateway auth for that provider, then try again.' + assert _should_suppress_channel_reply(channel="admin_chat", text=text) is False +