修复微信通道对 OpenAI 缺失密钥报错文案的静默抑制漏判。

扩展 Missing API key 提示的匹配规则以覆盖引号与文案变体,确保 wechat/weixin 侧不再回传该错误,并新增单元测试锁定该行为。

Made-with: Cursor
This commit is contained in:
oliver 2026-04-29 01:30:17 +08:00
parent b6dd8edc5d
commit 58e47a3059
2 changed files with 28 additions and 2 deletions

View file

@ -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

View file

@ -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