Skip to content

Commit a929fbd

Browse files
committed
Merge branch 'master' into feat/universal-conversation-title
2 parents bd95e27 + 63dd28d commit a929fbd

45 files changed

Lines changed: 2628 additions & 349 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/unit_tests.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Unit Tests
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
paths-ignore:
8+
- 'README*.md'
9+
- 'changelogs/**'
10+
- 'dashboard/**'
11+
pull_request:
12+
workflow_dispatch:
13+
14+
jobs:
15+
unit-tests:
16+
name: Run pytest suite
17+
runs-on: ubuntu-latest
18+
timeout-minutes: 30
19+
20+
steps:
21+
- name: Checkout
22+
uses: actions/checkout@v6
23+
24+
- name: Set up Python
25+
uses: actions/setup-python@v6
26+
with:
27+
python-version: '3.12'
28+
29+
- name: Install uv
30+
run: |
31+
python -m pip install --upgrade pip
32+
python -m pip install uv
33+
34+
- name: Run tests
35+
run: |
36+
chmod +x scripts/run_pytests_ci.sh
37+
bash ./scripts/run_pytests_ci.sh ./tests

astrbot/core/astr_main_agent_resources.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
RunBrowserSkillTool,
3434
SyncSkillReleaseTool,
3535
)
36+
from astrbot.core.knowledge_base.kb_helper import KBHelper
3637
from astrbot.core.message.message_event_result import MessageChain
3738
from astrbot.core.platform.message_session import MessageSession
3839
from astrbot.core.star.context import Context
@@ -396,6 +397,18 @@ async def call(
396397
return f"Message sent to session {target_session}"
397398

398399

400+
def check_all_kb(kb_list: list[KBHelper | None]) -> bool:
401+
"""检查是否所有的知识库都为空
402+
Args:
403+
kb_list: 所选的知识库
404+
Returns:
405+
bool: 是否全为空
406+
"""
407+
return not any(
408+
kb and (kb.kb.doc_count != 0 or kb.kb.chunk_count != 0) for kb in kb_list
409+
)
410+
411+
399412
async def retrieve_knowledge_base(
400413
query: str,
401414
umo: str,
@@ -454,6 +467,12 @@ async def retrieve_knowledge_base(
454467
if not kb_names:
455468
return
456469

470+
all_kbs = [await kb_mgr.get_kb_by_name(kb) for kb in kb_names]
471+
472+
if check_all_kb(all_kbs):
473+
logger.debug("所配置的所有知识库全为空,跳过检索过程")
474+
return
475+
457476
logger.debug(f"[知识库] 开始检索知识库,数量: {len(kb_names)}, top_k={top_k}")
458477
kb_context = await kb_mgr.retrieve(
459478
query=query,

astrbot/core/computer/computer_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ def parse_description(text: str) -> str:
214214
if end_idx is None:
215215
return ""
216216
217-
frontmatter = "\n".join(lines[1:end_idx])
217+
frontmatter = "\\n".join(lines[1:end_idx])
218218
try:
219219
import yaml
220220
except ImportError:

astrbot/core/config/default.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,38 @@
77

88
VERSION = "4.21.0"
99
DB_PATH = os.path.join(get_astrbot_data_path(), "data_v4.db")
10+
PERSONAL_WECHAT_CONFIG_METADATA = {
11+
"weixin_oc_base_url": {
12+
"description": "Base URL",
13+
"type": "string",
14+
"hint": "默认值: https://ilinkai.weixin.qq.com",
15+
},
16+
"weixin_oc_bot_type": {
17+
"description": "扫码参数 bot_type",
18+
"type": "string",
19+
"hint": "默认值: 3",
20+
},
21+
"weixin_oc_qr_poll_interval": {
22+
"description": "二维码状态轮询间隔(秒)",
23+
"type": "int",
24+
"hint": "每隔多少秒轮询一次二维码状态。",
25+
},
26+
"weixin_oc_long_poll_timeout_ms": {
27+
"description": "getUpdates 长轮询超时时间(毫秒)",
28+
"type": "int",
29+
"hint": "会话消息拉取接口超时参数。",
30+
},
31+
"weixin_oc_api_timeout_ms": {
32+
"description": "HTTP 请求超时(毫秒)",
33+
"type": "int",
34+
"hint": "通用 API 请求超时参数。",
35+
},
36+
"weixin_oc_token": {
37+
"description": "登录后 token(可留空)",
38+
"type": "string",
39+
"hint": "扫码登录成功后会自动写入;高级场景可手动填写。",
40+
},
41+
}
1042

1143
WEBHOOK_SUPPORTED_PLATFORMS = [
1244
"qq_official_webhook",
@@ -364,6 +396,16 @@ class ChatProviderTemplate(TypedDict):
364396
"callback_server_host": "0.0.0.0",
365397
"port": 6198,
366398
},
399+
"个人微信": {
400+
"id": "weixin_personal",
401+
"type": "weixin_oc",
402+
"enable": False,
403+
"weixin_oc_base_url": "https://ilinkai.weixin.qq.com",
404+
"weixin_oc_bot_type": "3",
405+
"weixin_oc_qr_poll_interval": 1,
406+
"weixin_oc_long_poll_timeout_ms": 35_000,
407+
"weixin_oc_api_timeout_ms": 15_000,
408+
},
367409
"飞书(Lark)": {
368410
"id": "lark",
369411
"type": "lark",
@@ -869,6 +911,7 @@ class ChatProviderTemplate(TypedDict):
869911
"type": "bool",
870912
"hint": "Webhook 模式下使用 AstrBot 统一 Webhook 入口,无需单独开启端口。回调地址为 /api/platform/webhook/{webhook_uuid}。",
871913
},
914+
**PERSONAL_WECHAT_CONFIG_METADATA,
872915
"webhook_uuid": {
873916
"invisible": True,
874917
"description": "Webhook UUID",

astrbot/core/platform/manager.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,10 @@ async def load_platform(self, platform_config: dict) -> None:
170170
from .sources.misskey.misskey_adapter import (
171171
MisskeyPlatformAdapter, # noqa: F401
172172
)
173+
case "weixin_oc":
174+
from .sources.weixin_oc.weixin_oc_adapter import (
175+
WeixinOCAdapter, # noqa: F401
176+
)
173177
case "slack":
174178
from .sources.slack.slack_adapter import SlackAdapter # noqa: F401
175179
case "satori":

astrbot/core/platform/sources/telegram/tg_adapter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from apscheduler.schedulers.asyncio import AsyncIOScheduler
99
from telegram import BotCommand, Update
1010
from telegram.constants import ChatType
11-
from telegram.error import InvalidToken, Unauthorized
11+
from telegram.error import Forbidden, InvalidToken
1212
from telegram.ext import ApplicationBuilder, ContextTypes, ExtBot, filters
1313
from telegram.ext import MessageHandler as TelegramMessageHandler
1414

@@ -183,7 +183,7 @@ async def run(self) -> None:
183183
)
184184
except asyncio.CancelledError:
185185
raise
186-
except (Unauthorized, InvalidToken) as e:
186+
except (Forbidden, InvalidToken) as e:
187187
logger.error(
188188
f"Telegram token is invalid or unauthorized: {e}. Polling stopped."
189189
)

0 commit comments

Comments
 (0)