mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2026-10-18 10:40:03 +08:00
✨ feat(auth): 添加群组和机器人唤醒命令支持,优化权限检查逻辑 (#2113)
* ✨ feat(auth): 添加群组和机器人唤醒命令支持,优化权限检查逻辑 ✨ feat(llm): 增加额外请求头配置,改进API适配器请求头处理 * 🚨 auto fix by pre-commit hooks * ``` fix(auth): 优化bot权限验证逻辑并改进错误提示 - 将bot存在性检查与状态检查分离,提供更精确的错误信息 - 修复当bot为None时的状态访问问题 - 移除不必要的注释,保持代码简洁 - 优化日志记录的位置和条件判断 ``` --------- Co-authored-by: ATTomatoo <1126160939@qq.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
co-authored by
ATTomatoo
pre-commit-ci[bot]
parent
65b125dd07
commit
6da4f27b12
@@ -46,6 +46,24 @@ from .types.capabilities import ModelCapabilities, ModelModality
|
||||
T = TypeVar("T", bound=BaseModel)
|
||||
|
||||
|
||||
def _sanitize_request_headers(headers: dict[str, Any]) -> dict[str, str]:
|
||||
sanitized: dict[str, str] = {}
|
||||
sensitive_parts = ("authorization", "token", "api-key", "api_key", "secret")
|
||||
for key, value in headers.items():
|
||||
key_text = str(key)
|
||||
value_text = str(value)
|
||||
lowered = key_text.lower()
|
||||
if any(part in lowered for part in sensitive_parts):
|
||||
if " " in value_text:
|
||||
prefix = value_text.split(" ", 1)[0]
|
||||
sanitized[key_text] = f"{prefix} ***"
|
||||
else:
|
||||
sanitized[key_text] = "***"
|
||||
else:
|
||||
sanitized[key_text] = value_text
|
||||
return sanitized
|
||||
|
||||
|
||||
class LLMContext(BaseModel):
|
||||
"""LLM 执行上下文,用于在中间件管道中传递请求状态"""
|
||||
|
||||
@@ -583,7 +601,7 @@ class NetworkRequestMiddleware(BaseLLMMiddleware):
|
||||
)
|
||||
logger.debug(f"🔑 API密钥: {masked_key}")
|
||||
logger.debug(f"📡 请求URL: {request_data.url}")
|
||||
logger.debug(f"📋 请求头: {dict(request_data.headers)}")
|
||||
logger.debug(f"📋 请求头: {_sanitize_request_headers(request_data.headers)}")
|
||||
|
||||
if self.model.api_type == "smart":
|
||||
effective_type = self.model._get_effective_api_type()
|
||||
|
||||
Reference in New Issue
Block a user