✨ 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:
ManyManyTomato
2026-03-26 17:18:22 +08:00
committed by GitHub
co-authored by ATTomatoo pre-commit-ci[bot]
parent 65b125dd07
commit 6da4f27b12
13 changed files with 214 additions and 18 deletions
+6 -4
View File
@@ -39,14 +39,16 @@ class GeminiAdapter(BaseAdapter):
def supported_api_types(self) -> list[str]:
return ["gemini"]
def get_base_headers(self, api_key: str) -> dict[str, str]:
def get_base_headers(
self, api_key: str, model: "LLMModel | None" = None
) -> dict[str, str]:
"""获取基础请求头"""
from zhenxun.utils.user_agent import get_user_agent
headers = get_user_agent()
headers.update({"Content-Type": "application/json"})
headers["x-goog-api-key"] = api_key
headers.update(self._get_provider_extra_headers(model))
return headers
async def prepare_advanced_request(
@@ -109,7 +111,7 @@ class GeminiAdapter(BaseAdapter):
endpoint = self._get_gemini_endpoint(model, effective_config)
url = self.get_api_url(model, endpoint)
headers = self.get_base_headers(api_key)
headers = self.get_base_headers(api_key, model)
converter = GeminiMessageConverter()
system_instruction_parts: list[dict[str, Any]] | None = None
@@ -252,7 +254,7 @@ class GeminiAdapter(BaseAdapter):
base_url = model.api_base.rstrip("/")
url = f"{base_url}/v1beta/{api_model_name}:batchEmbedContents"
headers = self.get_base_headers(api_key)
headers = self.get_base_headers(api_key, model)
requests_payload = []
for text_content in texts: