From 58e47a3059b9f7841f35dc36defa488d52bf5b8d Mon Sep 17 00:00:00 2001 From: oliver Date: Wed, 29 Apr 2026 01:30:17 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=BE=AE=E4=BF=A1=E9=80=9A?= =?UTF-8?q?=E9=81=93=E5=AF=B9=20OpenAI=20=E7=BC=BA=E5=A4=B1=E5=AF=86?= =?UTF-8?q?=E9=92=A5=E6=8A=A5=E9=94=99=E6=96=87=E6=A1=88=E7=9A=84=E9=9D=99?= =?UTF-8?q?=E9=BB=98=E6=8A=91=E5=88=B6=E6=BC=8F=E5=88=A4=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 扩展 Missing API key 提示的匹配规则以覆盖引号与文案变体,确保 wechat/weixin 侧不再回传该错误,并新增单元测试锁定该行为。 Made-with: Cursor --- runtime/application/gateway/inbound_service.py | 15 +++++++++++++-- tests/test_inbound_service_reply_suppress.py | 15 +++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 tests/test_inbound_service_reply_suppress.py 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 +