Compare commits
2 Commits
v3.5.27
...
copilot/fi
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
af03bc884b | ||
|
|
139621678f |
12
.github/workflows/dashboard_ci.yml
vendored
12
.github/workflows/dashboard_ci.yml
vendored
@@ -25,8 +25,6 @@ jobs:
|
||||
echo "COMMIT_SHA=$(git rev-parse HEAD)" >> $GITHUB_ENV
|
||||
mkdir -p dashboard/dist/assets
|
||||
echo $COMMIT_SHA > dashboard/dist/assets/version
|
||||
cd dashboard
|
||||
zip -r dist.zip dist
|
||||
|
||||
- name: Archive production artifacts
|
||||
uses: actions/upload-artifact@v4
|
||||
@@ -35,13 +33,3 @@ jobs:
|
||||
path: |
|
||||
dashboard/dist
|
||||
!dist/**/*.md
|
||||
|
||||
- name: Create GitHub Release
|
||||
uses: ncipollo/release-action@v1
|
||||
with:
|
||||
tag: release-${{ github.sha }}
|
||||
owner: AstrBotDevs
|
||||
repo: astrbot-release-harbour
|
||||
body: "Automated release from commit ${{ github.sha }}"
|
||||
token: ${{ secrets.ASTRBOT_HARBOUR_TOKEN }}
|
||||
artifacts: "dashboard/dist.zip"
|
||||
11
.github/workflows/docker-image.yml
vendored
11
.github/workflows/docker-image.yml
vendored
@@ -27,17 +27,6 @@ jobs:
|
||||
if: github.event_name == 'workflow_dispatch'
|
||||
run: git checkout ${{ steps.get-latest-tag.outputs.latest_tag }}
|
||||
|
||||
- name: Build Dashboard
|
||||
run: |
|
||||
cd dashboard
|
||||
npm install
|
||||
npm run build
|
||||
mkdir -p dist/assets
|
||||
echo $(git rev-parse HEAD) > dist/assets/version
|
||||
cd ..
|
||||
mkdir -p data
|
||||
cp -r dashboard/dist data/
|
||||
|
||||
- name: Set QEMU
|
||||
uses: docker/setup-qemu-action@v3
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<img width="430" height="31" alt="image" src="https://github.com/user-attachments/assets/474c822c-fab7-41be-8c23-6dae252823ed" /><p align="center">
|
||||
<p align="center">
|
||||
|
||||

|
||||
|
||||
@@ -25,7 +25,7 @@ _✨ 易上手的多平台 LLM 聊天机器人及开发框架 ✨_
|
||||
<a href="https://github.com/Soulter/AstrBot/issues">问题提交</a>
|
||||
</div>
|
||||
|
||||
AstrBot 是一个开源的一站式 Agentic 聊天机器人平台及开发框架。
|
||||
AstrBot 是一个松耦合、异步、支持多消息平台部署、具有易用的插件系统和完善的大语言模型(LLM)接入功能的聊天机器人及开发框架。
|
||||
|
||||
## ✨ 主要功能
|
||||
|
||||
@@ -110,6 +110,7 @@ uv run main.py
|
||||
| 钉钉 | ✔ |
|
||||
| Slack | ✔ |
|
||||
| Discord | ✔ |
|
||||
| Matrix (Element等) | ✔ |
|
||||
| [KOOK](https://github.com/wuyan1003/astrbot_plugin_kook_adapter) | ✔ |
|
||||
| [VoceChat](https://github.com/HikariFroya/astrbot_plugin_vocechat) | ✔ |
|
||||
| 微信对话开放平台 | 🚧 |
|
||||
|
||||
@@ -70,6 +70,7 @@ See docs: [Source Code Deployment](https://astrbot.app/deploy/astrbot/cli.html)
|
||||
| [Telegram](https://github.com/Soulter/astrbot_plugin_telegram) | ✔ | Private/Group chats | Text, Images |
|
||||
| [WeChat Work](https://github.com/Soulter/astrbot_plugin_wecom) | ✔ | Private chats | Text, Images, Voice |
|
||||
| Feishu | ✔ | Group chats | Text, Images |
|
||||
| Matrix (Element, etc.) | ✔ | Private/Group chats | Text, Images, Files |
|
||||
| WeChat Open Platform | 🚧 | Planned | - |
|
||||
| Discord | 🚧 | Planned | - |
|
||||
| WhatsApp | 🚧 | Planned | - |
|
||||
|
||||
@@ -72,6 +72,7 @@ AstrBot は、疎結合、非同期、複数のメッセージプラットフォ
|
||||
| [Telegram](https://github.com/Soulter/astrbot_plugin_telegram) | ✔ | プライベートチャット、グループチャット | テキスト、画像 |
|
||||
| [WeChat(企業 WeChat)](https://github.com/Soulter/astrbot_plugin_wecom) | ✔ | プライベートチャット | テキスト、画像、音声 |
|
||||
| Feishu | ✔ | グループチャット | テキスト、画像 |
|
||||
| Matrix (Element等) | ✔ | プライベートチャット、グループチャット | テキスト、画像、ファイル |
|
||||
| WeChat 対話オープンプラットフォーム | 🚧 | 計画中 | - |
|
||||
| Discord | 🚧 | 計画中 | - |
|
||||
| WhatsApp | 🚧 | 計画中 | - |
|
||||
|
||||
@@ -37,10 +37,7 @@ async def check_dashboard(astrbot_root: Path) -> None:
|
||||
):
|
||||
click.echo("正在安装管理面板...")
|
||||
await download_dashboard(
|
||||
path="data/dashboard.zip",
|
||||
extract_path=str(astrbot_root),
|
||||
version=f"v{VERSION}",
|
||||
latest=False,
|
||||
path="data/dashboard.zip", extract_path=str(astrbot_root)
|
||||
)
|
||||
click.echo("管理面板安装完成")
|
||||
|
||||
@@ -53,10 +50,7 @@ async def check_dashboard(astrbot_root: Path) -> None:
|
||||
version = dashboard_version.split("v")[1]
|
||||
click.echo(f"管理面板版本: {version}")
|
||||
await download_dashboard(
|
||||
path="data/dashboard.zip",
|
||||
extract_path=str(astrbot_root),
|
||||
version=f"v{VERSION}",
|
||||
latest=False,
|
||||
path="data/dashboard.zip", extract_path=str(astrbot_root)
|
||||
)
|
||||
except Exception as e:
|
||||
click.echo(f"下载管理面板失败: {e}")
|
||||
@@ -65,10 +59,7 @@ async def check_dashboard(astrbot_root: Path) -> None:
|
||||
click.echo("初始化管理面板目录...")
|
||||
try:
|
||||
await download_dashboard(
|
||||
path=str(astrbot_root / "dashboard.zip"),
|
||||
extract_path=str(astrbot_root),
|
||||
version=f"v{VERSION}",
|
||||
latest=False,
|
||||
path=str(astrbot_root / "dashboard.zip"), extract_path=str(astrbot_root)
|
||||
)
|
||||
click.echo("管理面板初始化完成")
|
||||
except Exception as e:
|
||||
|
||||
@@ -6,7 +6,7 @@ import os
|
||||
|
||||
from astrbot.core.utils.astrbot_path import get_astrbot_data_path
|
||||
|
||||
VERSION = "3.5.27"
|
||||
VERSION = "3.5.24"
|
||||
DB_PATH = os.path.join(get_astrbot_data_path(), "data_v3.db")
|
||||
|
||||
# 默认配置
|
||||
@@ -65,7 +65,7 @@ DEFAULT_CONFIG = {
|
||||
"show_tool_use_status": False,
|
||||
"streaming_segmented": False,
|
||||
"separate_provider": True,
|
||||
"max_agent_step": 30,
|
||||
"max_agent_step": 30
|
||||
},
|
||||
"provider_stt_settings": {
|
||||
"enable": False,
|
||||
@@ -103,7 +103,6 @@ DEFAULT_CONFIG = {
|
||||
"t2i_endpoint": "",
|
||||
"t2i_use_file_service": False,
|
||||
"http_proxy": "",
|
||||
"no_proxy": ["localhost", "127.0.0.1", "::1"],
|
||||
"dashboard": {
|
||||
"enable": True,
|
||||
"username": "astrbot",
|
||||
@@ -599,8 +598,11 @@ CONFIG_METADATA_2 = {
|
||||
"key": [],
|
||||
"api_base": "https://api.openai.com/v1",
|
||||
"timeout": 120,
|
||||
"model_config": {"model": "gpt-4o-mini", "temperature": 0.4},
|
||||
"hint": "也兼容所有与OpenAI API兼容的服务。",
|
||||
"model_config": {
|
||||
"model": "gpt-4o-mini",
|
||||
"temperature": 0.4
|
||||
},
|
||||
"hint": "也兼容所有与OpenAI API兼容的服务。"
|
||||
},
|
||||
"Azure OpenAI": {
|
||||
"id": "azure",
|
||||
@@ -612,7 +614,10 @@ CONFIG_METADATA_2 = {
|
||||
"key": [],
|
||||
"api_base": "",
|
||||
"timeout": 120,
|
||||
"model_config": {"model": "gpt-4o-mini", "temperature": 0.4},
|
||||
"model_config": {
|
||||
"model": "gpt-4o-mini",
|
||||
"temperature": 0.4
|
||||
},
|
||||
},
|
||||
"xAI": {
|
||||
"id": "xai",
|
||||
@@ -623,7 +628,10 @@ CONFIG_METADATA_2 = {
|
||||
"key": [],
|
||||
"api_base": "https://api.x.ai/v1",
|
||||
"timeout": 120,
|
||||
"model_config": {"model": "grok-2-latest", "temperature": 0.4},
|
||||
"model_config": {
|
||||
"model": "grok-2-latest",
|
||||
"temperature": 0.4
|
||||
},
|
||||
},
|
||||
"Anthropic": {
|
||||
"hint": "注意Claude系列模型的温度调节范围为0到1.0,超出可能导致报错",
|
||||
@@ -638,11 +646,11 @@ CONFIG_METADATA_2 = {
|
||||
"model_config": {
|
||||
"model": "claude-3-5-sonnet-latest",
|
||||
"max_tokens": 4096,
|
||||
"temperature": 0.2,
|
||||
"temperature": 0.2
|
||||
},
|
||||
},
|
||||
"Ollama": {
|
||||
"hint": "启用前请确保已正确安装并运行 Ollama 服务端,Ollama默认不带鉴权,无需修改key",
|
||||
"hint":"启用前请确保已正确安装并运行 Ollama 服务端,Ollama默认不带鉴权,无需修改key",
|
||||
"id": "ollama_default",
|
||||
"provider": "ollama",
|
||||
"type": "openai_chat_completion",
|
||||
@@ -650,7 +658,10 @@ CONFIG_METADATA_2 = {
|
||||
"enable": True,
|
||||
"key": ["ollama"], # ollama 的 key 默认是 ollama
|
||||
"api_base": "http://localhost:11434/v1",
|
||||
"model_config": {"model": "llama3.1-8b", "temperature": 0.4},
|
||||
"model_config": {
|
||||
"model": "llama3.1-8b",
|
||||
"temperature": 0.4
|
||||
},
|
||||
},
|
||||
"LM Studio": {
|
||||
"id": "lm_studio",
|
||||
@@ -675,7 +686,7 @@ CONFIG_METADATA_2 = {
|
||||
"timeout": 120,
|
||||
"model_config": {
|
||||
"model": "gemini-1.5-flash",
|
||||
"temperature": 0.4,
|
||||
"temperature": 0.4
|
||||
},
|
||||
},
|
||||
"Gemini": {
|
||||
@@ -689,7 +700,7 @@ CONFIG_METADATA_2 = {
|
||||
"timeout": 120,
|
||||
"model_config": {
|
||||
"model": "gemini-2.0-flash-exp",
|
||||
"temperature": 0.4,
|
||||
"temperature": 0.4
|
||||
},
|
||||
"gm_resp_image_modal": False,
|
||||
"gm_native_search": False,
|
||||
@@ -714,7 +725,10 @@ CONFIG_METADATA_2 = {
|
||||
"key": [],
|
||||
"api_base": "https://api.deepseek.com/v1",
|
||||
"timeout": 120,
|
||||
"model_config": {"model": "deepseek-chat", "temperature": 0.4},
|
||||
"model_config": {
|
||||
"model": "deepseek-chat",
|
||||
"temperature": 0.4
|
||||
},
|
||||
},
|
||||
"302.AI": {
|
||||
"id": "302ai",
|
||||
@@ -725,7 +739,10 @@ CONFIG_METADATA_2 = {
|
||||
"key": [],
|
||||
"api_base": "https://api.302.ai/v1",
|
||||
"timeout": 120,
|
||||
"model_config": {"model": "gpt-4.1-mini", "temperature": 0.4},
|
||||
"model_config": {
|
||||
"model": "gpt-4.1-mini",
|
||||
"temperature": 0.4
|
||||
},
|
||||
},
|
||||
"硅基流动": {
|
||||
"id": "siliconflow",
|
||||
@@ -738,7 +755,7 @@ CONFIG_METADATA_2 = {
|
||||
"api_base": "https://api.siliconflow.cn/v1",
|
||||
"model_config": {
|
||||
"model": "deepseek-ai/DeepSeek-V3",
|
||||
"temperature": 0.4,
|
||||
"temperature": 0.4
|
||||
},
|
||||
},
|
||||
"PPIO派欧云": {
|
||||
@@ -752,7 +769,7 @@ CONFIG_METADATA_2 = {
|
||||
"timeout": 120,
|
||||
"model_config": {
|
||||
"model": "deepseek/deepseek-r1",
|
||||
"temperature": 0.4,
|
||||
"temperature": 0.4
|
||||
},
|
||||
},
|
||||
"优云智算": {
|
||||
@@ -777,7 +794,10 @@ CONFIG_METADATA_2 = {
|
||||
"key": [],
|
||||
"timeout": 120,
|
||||
"api_base": "https://api.moonshot.cn/v1",
|
||||
"model_config": {"model": "moonshot-v1-8k", "temperature": 0.4},
|
||||
"model_config": {
|
||||
"model": "moonshot-v1-8k",
|
||||
"temperature": 0.4
|
||||
},
|
||||
},
|
||||
"智谱 AI": {
|
||||
"id": "zhipu_default",
|
||||
@@ -805,7 +825,7 @@ CONFIG_METADATA_2 = {
|
||||
"dify_query_input_key": "astrbot_text_query",
|
||||
"variables": {},
|
||||
"timeout": 60,
|
||||
"hint": "请确保你在 AstrBot 里设置的 APP 类型和 Dify 里面创建的应用的类型一致!",
|
||||
"hint": "请确保你在 AstrBot 里设置的 APP 类型和 Dify 里面创建的应用的类型一致!"
|
||||
},
|
||||
"阿里云百炼应用": {
|
||||
"id": "dashscope",
|
||||
@@ -833,7 +853,10 @@ CONFIG_METADATA_2 = {
|
||||
"key": [],
|
||||
"timeout": 120,
|
||||
"api_base": "https://api-inference.modelscope.cn/v1",
|
||||
"model_config": {"model": "Qwen/Qwen3-32B", "temperature": 0.4},
|
||||
"model_config": {
|
||||
"model": "Qwen/Qwen3-32B",
|
||||
"temperature": 0.4
|
||||
},
|
||||
},
|
||||
"FastGPT": {
|
||||
"id": "fastgpt",
|
||||
@@ -948,7 +971,6 @@ CONFIG_METADATA_2 = {
|
||||
"api_key": "",
|
||||
"api_base": "https://api.fish.audio/v1",
|
||||
"fishaudio-tts-character": "可莉",
|
||||
"fishaudio-tts-reference-id": "",
|
||||
"timeout": "20",
|
||||
},
|
||||
"阿里云百炼 TTS(API)": {
|
||||
@@ -1542,11 +1564,6 @@ CONFIG_METADATA_2 = {
|
||||
"type": "string",
|
||||
"hint": "fishaudio TTS 的角色。默认为可莉。更多角色请访问:https://fish.audio/zh-CN/discovery",
|
||||
},
|
||||
"fishaudio-tts-reference-id": {
|
||||
"description": "reference_id",
|
||||
"type": "string",
|
||||
"hint": "fishaudio TTS 的参考模型ID(可选)。如果填入此字段,将直接使用模型ID而不通过角色名称查询。例如:626bb6d3f3364c9cbc3aa6a67300a664。更多模型请访问:https://fish.audio/zh-CN/discovery,进入模型详情界面后可复制模型ID",
|
||||
},
|
||||
"whisper_hint": {
|
||||
"description": "本地部署 Whisper 模型须知",
|
||||
"type": "string",
|
||||
@@ -1893,12 +1910,6 @@ CONFIG_METADATA_2 = {
|
||||
"type": "string",
|
||||
"hint": "启用后,会以添加环境变量的方式设置代理。格式为 `http://ip:port`",
|
||||
},
|
||||
"no_proxy": {
|
||||
"description": "直连地址列表",
|
||||
"type": "list",
|
||||
"items": {"type": "string"},
|
||||
"hint": "在此处添加不希望通过代理访问的地址,例如内部服务地址。回车添加,可添加多个,如未设置代理请忽略此配置",
|
||||
},
|
||||
"timezone": {
|
||||
"description": "时区",
|
||||
"type": "string",
|
||||
|
||||
@@ -47,23 +47,12 @@ class AstrBotCoreLifecycle:
|
||||
self.db = db # 初始化数据库
|
||||
|
||||
# 设置代理
|
||||
proxy_config = self.astrbot_config.get("http_proxy", "")
|
||||
if proxy_config != "":
|
||||
os.environ["https_proxy"] = proxy_config
|
||||
os.environ["http_proxy"] = proxy_config
|
||||
logger.debug(f"Using proxy: {proxy_config}")
|
||||
# 设置 no_proxy
|
||||
no_proxy_list = self.astrbot_config.get("no_proxy", [])
|
||||
os.environ["no_proxy"] = ",".join(no_proxy_list)
|
||||
else:
|
||||
# 清空代理环境变量
|
||||
if "https_proxy" in os.environ:
|
||||
del os.environ["https_proxy"]
|
||||
if "http_proxy" in os.environ:
|
||||
del os.environ["http_proxy"]
|
||||
if "no_proxy" in os.environ:
|
||||
del os.environ["no_proxy"]
|
||||
logger.debug("HTTP proxy cleared")
|
||||
if self.astrbot_config.get("http_proxy", ""):
|
||||
os.environ["https_proxy"] = self.astrbot_config["http_proxy"]
|
||||
os.environ["http_proxy"] = self.astrbot_config["http_proxy"]
|
||||
if proxy := os.environ.get("https_proxy"):
|
||||
logger.debug(f"Using proxy: {proxy}")
|
||||
os.environ["no_proxy"] = "localhost"
|
||||
|
||||
async def initialize(self):
|
||||
"""
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
from .vec_db import FaissVecDB
|
||||
|
||||
__all__ = ["FaissVecDB"]
|
||||
__all__ = ["FaissVecDB"]
|
||||
|
||||
@@ -335,10 +335,6 @@ class LLMRequestSubStage(Stage):
|
||||
):
|
||||
return
|
||||
|
||||
if not llm_response.completion_text and not req.tool_calls_result:
|
||||
logger.debug("LLM 响应为空,不保存记录。")
|
||||
return
|
||||
|
||||
# 历史上下文
|
||||
messages = copy.deepcopy(req.contexts)
|
||||
# 这一轮对话请求的用户输入
|
||||
|
||||
@@ -144,6 +144,8 @@ class RespondStage(Stage):
|
||||
try:
|
||||
if await self._is_empty_message_chain(result.chain):
|
||||
logger.info("消息为空,跳过发送阶段")
|
||||
event.clear_result()
|
||||
event.stop_event()
|
||||
return
|
||||
except Exception as e:
|
||||
logger.warning(f"空内容检查异常: {e}")
|
||||
|
||||
@@ -82,6 +82,10 @@ class PlatformManager:
|
||||
)
|
||||
case "slack":
|
||||
from .sources.slack.slack_adapter import SlackAdapter # noqa: F401
|
||||
case "matrix":
|
||||
from .sources.matrix.matrix_adapter import (
|
||||
MatrixPlatformAdapter, # noqa: F401
|
||||
)
|
||||
except (ImportError, ModuleNotFoundError) as e:
|
||||
logger.error(
|
||||
f"加载平台适配器 {platform_config['type']} 失败,原因:{e}。请检查依赖库是否安装。提示:可以在 管理面板->控制台->安装Pip库 中安装依赖库。"
|
||||
|
||||
@@ -26,7 +26,7 @@ class DingtalkMessageEvent(AstrMessageEvent):
|
||||
await asyncio.get_event_loop().run_in_executor(
|
||||
None,
|
||||
client.reply_markdown,
|
||||
segment.text,
|
||||
"AstrBot",
|
||||
segment.text,
|
||||
self.message_obj.raw_message,
|
||||
)
|
||||
|
||||
1
astrbot/core/platform/sources/matrix/__init__.py
Normal file
1
astrbot/core/platform/sources/matrix/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
# Matrix platform adapter for AstrBot
|
||||
331
astrbot/core/platform/sources/matrix/matrix_adapter.py
Normal file
331
astrbot/core/platform/sources/matrix/matrix_adapter.py
Normal file
@@ -0,0 +1,331 @@
|
||||
import asyncio
|
||||
import sys
|
||||
import re
|
||||
from typing import Awaitable, Any
|
||||
from nio import (
|
||||
AsyncClient,
|
||||
MatrixRoom,
|
||||
RoomMessageText,
|
||||
RoomMessageImage,
|
||||
RoomMessageFile,
|
||||
)
|
||||
from astrbot.api.platform import (
|
||||
Platform,
|
||||
AstrBotMessage,
|
||||
MessageMember,
|
||||
MessageType,
|
||||
PlatformMetadata,
|
||||
register_platform_adapter,
|
||||
)
|
||||
from astrbot.api.event import MessageChain
|
||||
from astrbot.api.message_components import Plain, Image, File
|
||||
from astrbot.api import logger
|
||||
from astrbot.core.platform.astr_message_event import MessageSesion
|
||||
from .matrix_event import MatrixMessageEvent
|
||||
|
||||
if sys.version_info >= (3, 12):
|
||||
from typing import override
|
||||
else:
|
||||
from typing_extensions import override
|
||||
|
||||
|
||||
@register_platform_adapter(
|
||||
"matrix",
|
||||
"Matrix 协议适配器 (支持 Element、VoceChat 等 Matrix 客户端)",
|
||||
{
|
||||
"homeserver": "https://matrix.org",
|
||||
"user_id": "",
|
||||
"access_token": "",
|
||||
"device_id": "",
|
||||
"store_path": "./data/matrix_store",
|
||||
"enable": False,
|
||||
},
|
||||
)
|
||||
class MatrixPlatformAdapter(Platform):
|
||||
def __init__(
|
||||
self, platform_config: dict, platform_settings: dict, event_queue: asyncio.Queue
|
||||
) -> None:
|
||||
super().__init__(event_queue)
|
||||
self.config = platform_config
|
||||
self.settings = platform_settings
|
||||
self.unique_session = platform_settings.get("unique_session", False)
|
||||
|
||||
# Matrix 配置
|
||||
self.homeserver = platform_config.get("homeserver", "https://matrix.org")
|
||||
self.user_id = platform_config.get("user_id", "")
|
||||
self.access_token = platform_config.get("access_token", "")
|
||||
self.device_id = platform_config.get("device_id", "ASTRBOT")
|
||||
self.store_path = platform_config.get("store_path", "./data/matrix_store")
|
||||
|
||||
if not self.user_id or not self.access_token:
|
||||
raise ValueError("Matrix user_id 和 access_token 是必需的")
|
||||
|
||||
# 初始化 Matrix 客户端
|
||||
self.client = AsyncClient(
|
||||
homeserver=self.homeserver,
|
||||
user=self.user_id,
|
||||
device_id=self.device_id,
|
||||
store_path=self.store_path,
|
||||
)
|
||||
self.client.access_token = self.access_token
|
||||
|
||||
# 设置事件回调
|
||||
self.client.add_event_callback(self._handle_message, RoomMessageText)
|
||||
self.client.add_event_callback(self._handle_image, RoomMessageImage)
|
||||
self.client.add_event_callback(self._handle_file, RoomMessageFile)
|
||||
|
||||
self.client_self_id = self.user_id
|
||||
logger.info(f"Matrix 适配器初始化完成: {self.user_id} @ {self.homeserver}")
|
||||
|
||||
@override
|
||||
def meta(self) -> PlatformMetadata:
|
||||
return PlatformMetadata(
|
||||
name="matrix",
|
||||
description="Matrix 协议适配器 (支持 Element、VoceChat 等 Matrix 客户端)",
|
||||
id=self.config.get("id", "matrix"),
|
||||
)
|
||||
|
||||
@override
|
||||
async def run(self) -> Awaitable[Any]:
|
||||
"""启动 Matrix 客户端"""
|
||||
try:
|
||||
logger.info("正在启动 Matrix 客户端...")
|
||||
|
||||
# 同步消息历史
|
||||
await self.client.sync()
|
||||
logger.info("Matrix 客户端同步完成")
|
||||
|
||||
# 开始监听事件
|
||||
await self.client.sync_forever(timeout=30000)
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Matrix 客户端运行出错: {e}")
|
||||
raise
|
||||
|
||||
async def terminate(self):
|
||||
"""关闭 Matrix 客户端"""
|
||||
try:
|
||||
await self.client.close()
|
||||
logger.info("Matrix 客户端已关闭")
|
||||
except Exception as e:
|
||||
logger.error(f"Matrix 客户端关闭出错: {e}")
|
||||
|
||||
@override
|
||||
async def send_by_session(
|
||||
self, session: MessageSesion, message_chain: MessageChain
|
||||
):
|
||||
"""通过会话发送消息"""
|
||||
room_id = session.session_id
|
||||
|
||||
if not room_id:
|
||||
logger.error("Matrix 会话缺少房间 ID")
|
||||
return
|
||||
|
||||
for message_component in message_chain:
|
||||
try:
|
||||
if isinstance(message_component, Plain):
|
||||
await self.client.room_send(
|
||||
room_id=room_id,
|
||||
message_type="m.room.message",
|
||||
content={
|
||||
"msgtype": "m.text",
|
||||
"body": message_component.text,
|
||||
},
|
||||
)
|
||||
|
||||
elif isinstance(message_component, Image):
|
||||
# 处理图片发送
|
||||
await self._send_image(room_id, message_component)
|
||||
|
||||
elif isinstance(message_component, File):
|
||||
# 处理文件发送
|
||||
await self._send_file(room_id, message_component)
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Matrix 消息发送失败: {e}")
|
||||
|
||||
async def _send_image(self, room_id: str, image_component: Image):
|
||||
"""发送图片消息"""
|
||||
try:
|
||||
image_path = image_component.file or image_component.url
|
||||
if not image_path:
|
||||
logger.error("Matrix 图片消息缺少文件路径或URL")
|
||||
return
|
||||
|
||||
# 这里简化处理,实际应该上传图片并获取 MXC URI
|
||||
await self.client.room_send(
|
||||
room_id=room_id,
|
||||
message_type="m.room.message",
|
||||
content={
|
||||
"msgtype": "m.text",
|
||||
"body": f"[图片] {image_component.filename or 'image'}",
|
||||
},
|
||||
)
|
||||
except Exception as e:
|
||||
logger.error(f"Matrix 图片发送失败: {e}")
|
||||
|
||||
async def _send_file(self, room_id: str, file_component: File):
|
||||
"""发送文件消息"""
|
||||
try:
|
||||
# 这里简化处理,实际应该上传文件并获取 MXC URI
|
||||
await self.client.room_send(
|
||||
room_id=room_id,
|
||||
message_type="m.room.message",
|
||||
content={
|
||||
"msgtype": "m.text",
|
||||
"body": f"[文件] {file_component.name}",
|
||||
},
|
||||
)
|
||||
except Exception as e:
|
||||
logger.error(f"Matrix 文件发送失败: {e}")
|
||||
|
||||
def get_client(self):
|
||||
"""获取 Matrix 客户端"""
|
||||
return self.client
|
||||
|
||||
async def _handle_message(self, room: MatrixRoom, event: RoomMessageText):
|
||||
"""处理文本消息"""
|
||||
if event.sender == self.user_id:
|
||||
return # 忽略自己发送的消息
|
||||
|
||||
try:
|
||||
message_content = event.body
|
||||
|
||||
# 处理 @机器人
|
||||
if self.user_id in message_content:
|
||||
# 移除 @机器人 部分
|
||||
message_content = re.sub(
|
||||
r"@[\w\-\.]+:[\w\-\.]+", "", message_content
|
||||
).strip()
|
||||
|
||||
abm = AstrBotMessage()
|
||||
abm.type = (
|
||||
MessageType.GROUP_MESSAGE
|
||||
if room.member_count > 2
|
||||
else MessageType.PRIVATE_MESSAGE
|
||||
)
|
||||
abm.group_id = (
|
||||
room.room_id if abm.type == MessageType.GROUP_MESSAGE else None
|
||||
)
|
||||
abm.message_str = message_content
|
||||
abm.sender = MessageMember(
|
||||
user_id=event.sender, nickname=room.user_name(event.sender)
|
||||
)
|
||||
abm.message = [Plain(text=message_content)]
|
||||
abm.raw_message = event
|
||||
abm.self_id = self.client_self_id
|
||||
abm.session_id = room.room_id
|
||||
abm.message_id = event.event_id
|
||||
|
||||
# 创建事件并提交
|
||||
matrix_event = MatrixMessageEvent(
|
||||
message_str=message_content,
|
||||
message_obj=abm,
|
||||
platform_meta=self.meta(),
|
||||
session_id=room.room_id,
|
||||
client=self.client,
|
||||
room_id=room.room_id,
|
||||
event_id=event.event_id,
|
||||
)
|
||||
|
||||
self.commit_event(matrix_event)
|
||||
logger.debug(f"Matrix 消息处理完成: {message_content[:100]}...")
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Matrix 消息处理失败: {e}")
|
||||
|
||||
async def _handle_image(self, room: MatrixRoom, event: RoomMessageImage):
|
||||
"""处理图片消息"""
|
||||
if event.sender == self.user_id:
|
||||
return
|
||||
|
||||
try:
|
||||
abm = AstrBotMessage()
|
||||
abm.type = (
|
||||
MessageType.GROUP_MESSAGE
|
||||
if room.member_count > 2
|
||||
else MessageType.PRIVATE_MESSAGE
|
||||
)
|
||||
abm.group_id = (
|
||||
room.room_id if abm.type == MessageType.GROUP_MESSAGE else None
|
||||
)
|
||||
abm.message_str = f"[图片] {event.body}"
|
||||
abm.sender = MessageMember(
|
||||
user_id=event.sender, nickname=room.user_name(event.sender)
|
||||
)
|
||||
|
||||
# 构建消息组件
|
||||
message_chain = [Plain(text=f"[图片] {event.body}")]
|
||||
if hasattr(event, "url") and event.url:
|
||||
message_chain.append(Image(url=event.url, filename=event.body))
|
||||
|
||||
abm.message = message_chain
|
||||
abm.raw_message = event
|
||||
abm.self_id = self.client_self_id
|
||||
abm.session_id = room.room_id
|
||||
abm.message_id = event.event_id
|
||||
|
||||
# 创建事件并提交
|
||||
matrix_event = MatrixMessageEvent(
|
||||
message_str=abm.message_str,
|
||||
message_obj=abm,
|
||||
platform_meta=self.meta(),
|
||||
session_id=room.room_id,
|
||||
client=self.client,
|
||||
room_id=room.room_id,
|
||||
event_id=event.event_id,
|
||||
)
|
||||
|
||||
self.commit_event(matrix_event)
|
||||
logger.debug(f"Matrix 图片消息处理完成: {event.body}")
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Matrix 图片消息处理失败: {e}")
|
||||
|
||||
async def _handle_file(self, room: MatrixRoom, event: RoomMessageFile):
|
||||
"""处理文件消息"""
|
||||
if event.sender == self.user_id:
|
||||
return
|
||||
|
||||
try:
|
||||
abm = AstrBotMessage()
|
||||
abm.type = (
|
||||
MessageType.GROUP_MESSAGE
|
||||
if room.member_count > 2
|
||||
else MessageType.PRIVATE_MESSAGE
|
||||
)
|
||||
abm.group_id = (
|
||||
room.room_id if abm.type == MessageType.GROUP_MESSAGE else None
|
||||
)
|
||||
abm.message_str = f"[文件] {event.body}"
|
||||
abm.sender = MessageMember(
|
||||
user_id=event.sender, nickname=room.user_name(event.sender)
|
||||
)
|
||||
|
||||
# 构建消息组件
|
||||
message_chain = [Plain(text=f"[文件] {event.body}")]
|
||||
if hasattr(event, "url") and event.url:
|
||||
message_chain.append(File(name=event.body, url=event.url))
|
||||
|
||||
abm.message = message_chain
|
||||
abm.raw_message = event
|
||||
abm.self_id = self.client_self_id
|
||||
abm.session_id = room.room_id
|
||||
abm.message_id = event.event_id
|
||||
|
||||
# 创建事件并提交
|
||||
matrix_event = MatrixMessageEvent(
|
||||
message_str=abm.message_str,
|
||||
message_obj=abm,
|
||||
platform_meta=self.meta(),
|
||||
session_id=room.room_id,
|
||||
client=self.client,
|
||||
room_id=room.room_id,
|
||||
event_id=event.event_id,
|
||||
)
|
||||
|
||||
self.commit_event(matrix_event)
|
||||
logger.debug(f"Matrix 文件消息处理完成: {event.body}")
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Matrix 文件消息处理失败: {e}")
|
||||
146
astrbot/core/platform/sources/matrix/matrix_event.py
Normal file
146
astrbot/core/platform/sources/matrix/matrix_event.py
Normal file
@@ -0,0 +1,146 @@
|
||||
import sys
|
||||
from astrbot.api import logger
|
||||
from astrbot.core.platform.astr_message_event import AstrMessageEvent
|
||||
from astrbot.core.platform.platform_metadata import PlatformMetadata
|
||||
from astrbot.api.event import MessageChain
|
||||
from astrbot.api.message_components import Plain, Image, File
|
||||
import aiohttp
|
||||
import os
|
||||
|
||||
if sys.version_info >= (3, 12):
|
||||
from typing import override
|
||||
else:
|
||||
from typing_extensions import override
|
||||
|
||||
|
||||
class MatrixMessageEvent(AstrMessageEvent):
|
||||
def __init__(
|
||||
self,
|
||||
message_str: str,
|
||||
message_obj,
|
||||
platform_meta: PlatformMetadata,
|
||||
session_id: str,
|
||||
client,
|
||||
room_id: str = None,
|
||||
event_id: str = None,
|
||||
):
|
||||
super().__init__(
|
||||
message_str=message_str,
|
||||
message_obj=message_obj,
|
||||
platform_meta=platform_meta,
|
||||
session_id=session_id,
|
||||
)
|
||||
self.client = client
|
||||
self.room_id = room_id
|
||||
self.event_id = event_id
|
||||
|
||||
@override
|
||||
async def send(self, message: MessageChain):
|
||||
"""发送消息到 Matrix 房间"""
|
||||
if not self.room_id or not self.client:
|
||||
logger.error("Matrix 房间 ID 或客户端不可用")
|
||||
return
|
||||
|
||||
for message_component in message:
|
||||
try:
|
||||
if isinstance(message_component, Plain):
|
||||
# 发送纯文本消息
|
||||
await self.client.room_send(
|
||||
room_id=self.room_id,
|
||||
message_type="m.room.message",
|
||||
content={
|
||||
"msgtype": "m.text",
|
||||
"body": message_component.text,
|
||||
},
|
||||
)
|
||||
logger.debug(
|
||||
f"Matrix 文本消息已发送: {message_component.text[:100]}..."
|
||||
)
|
||||
|
||||
elif isinstance(message_component, Image):
|
||||
# 发送图片消息
|
||||
try:
|
||||
if message_component.file:
|
||||
# 从文件路径读取
|
||||
image_path = message_component.file
|
||||
elif message_component.url:
|
||||
# 从URL下载
|
||||
image_path = await self._download_image(
|
||||
message_component.url
|
||||
)
|
||||
else:
|
||||
logger.error("Matrix 图片消息缺少文件或URL")
|
||||
continue
|
||||
|
||||
if os.path.exists(image_path):
|
||||
# 上传图片到 Matrix
|
||||
with open(image_path, "rb") as f:
|
||||
response = await self.client.upload(
|
||||
data_provider=f,
|
||||
content_type="image/jpeg",
|
||||
filename=os.path.basename(image_path),
|
||||
)
|
||||
|
||||
if response:
|
||||
await self.client.room_send(
|
||||
room_id=self.room_id,
|
||||
message_type="m.room.message",
|
||||
content={
|
||||
"msgtype": "m.image",
|
||||
"body": message_component.filename
|
||||
or "image.jpg",
|
||||
"url": response.content_uri,
|
||||
},
|
||||
)
|
||||
logger.debug("Matrix 图片消息已发送")
|
||||
else:
|
||||
logger.error(f"Matrix 图片文件不存在: {image_path}")
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Matrix 图片处理失败: {e}")
|
||||
continue
|
||||
|
||||
elif isinstance(message_component, File):
|
||||
# 发送文件消息
|
||||
try:
|
||||
file_path = message_component.name
|
||||
if os.path.exists(file_path):
|
||||
with open(file_path, "rb") as f:
|
||||
response = await self.client.upload(
|
||||
data_provider=f,
|
||||
content_type="application/octet-stream",
|
||||
filename=os.path.basename(file_path),
|
||||
)
|
||||
|
||||
if response:
|
||||
await self.client.room_send(
|
||||
room_id=self.room_id,
|
||||
message_type="m.room.message",
|
||||
content={
|
||||
"msgtype": "m.file",
|
||||
"body": os.path.basename(file_path),
|
||||
"url": response.content_uri,
|
||||
},
|
||||
)
|
||||
logger.debug("Matrix 文件消息已发送")
|
||||
except Exception as e:
|
||||
logger.error(f"Matrix 文件处理失败: {e}")
|
||||
continue
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Matrix 消息发送失败: {e}")
|
||||
|
||||
async def _download_image(self, url: str) -> str:
|
||||
"""下载图片到临时文件"""
|
||||
try:
|
||||
async with aiohttp.ClientSession() as session:
|
||||
async with session.get(url) as resp:
|
||||
if resp.status == 200:
|
||||
data = await resp.read()
|
||||
temp_path = f"/tmp/matrix_image_{self.event_id}.jpg"
|
||||
with open(temp_path, "wb") as f:
|
||||
f.write(data)
|
||||
return temp_path
|
||||
except Exception as e:
|
||||
logger.error(f"Matrix 图片下载失败: {e}")
|
||||
return ""
|
||||
@@ -3,23 +3,15 @@ import botpy.message
|
||||
import botpy.types
|
||||
import botpy.types.message
|
||||
import asyncio
|
||||
import base64
|
||||
import aiofiles
|
||||
from astrbot.core.utils.io import file_to_base64, download_image_by_url
|
||||
from astrbot.core.utils.tencent_record_helper import wav_to_tencent_silk
|
||||
from astrbot.core.utils.astrbot_path import get_astrbot_data_path
|
||||
from astrbot.api.event import AstrMessageEvent, MessageChain
|
||||
from astrbot.api.platform import AstrBotMessage, PlatformMetadata
|
||||
from astrbot.api.message_components import Plain, Image, Record
|
||||
from astrbot.api.message_components import Plain, Image
|
||||
from botpy import Client
|
||||
from botpy.http import Route
|
||||
from astrbot.api import logger
|
||||
from botpy.types.message import Media
|
||||
from botpy.types import message
|
||||
from typing import Optional
|
||||
import random
|
||||
import uuid
|
||||
import os
|
||||
|
||||
|
||||
class QQOfficialMessageEvent(AstrMessageEvent):
|
||||
@@ -44,7 +36,6 @@ class QQOfficialMessageEvent(AstrMessageEvent):
|
||||
stream_payload = {"state": 1, "id": None, "index": 0, "reset": False}
|
||||
last_edit_time = 0 # 上次编辑消息的时间
|
||||
throttle_interval = 1 # 编辑消息的间隔时间 (秒)
|
||||
ret = None
|
||||
try:
|
||||
async for chain in generator:
|
||||
source = self.message_obj.raw_message
|
||||
@@ -94,10 +85,9 @@ class QQOfficialMessageEvent(AstrMessageEvent):
|
||||
plain_text,
|
||||
image_base64,
|
||||
image_path,
|
||||
record_file_path
|
||||
) = await QQOfficialMessageEvent._parse_to_qqofficial(self.send_buffer)
|
||||
|
||||
if not plain_text and not image_base64 and not image_path and not record_file_path:
|
||||
if not plain_text and not image_base64 and not image_path:
|
||||
return
|
||||
|
||||
payload = {
|
||||
@@ -108,8 +98,6 @@ class QQOfficialMessageEvent(AstrMessageEvent):
|
||||
if not isinstance(source, (botpy.message.Message, botpy.message.DirectMessage)):
|
||||
payload["msg_seq"] = random.randint(1, 10000)
|
||||
|
||||
ret = None
|
||||
|
||||
match type(source):
|
||||
case botpy.message.GroupMessage:
|
||||
if image_base64:
|
||||
@@ -118,12 +106,6 @@ class QQOfficialMessageEvent(AstrMessageEvent):
|
||||
)
|
||||
payload["media"] = media
|
||||
payload["msg_type"] = 7
|
||||
if record_file_path: # group record msg
|
||||
media = await self.upload_group_and_c2c_record(
|
||||
record_file_path, 3, group_openid=source.group_openid
|
||||
)
|
||||
payload["media"] = media
|
||||
payload["msg_type"] = 7
|
||||
ret = await self.bot.api.post_group_message(
|
||||
group_openid=source.group_openid, **payload
|
||||
)
|
||||
@@ -134,12 +116,6 @@ class QQOfficialMessageEvent(AstrMessageEvent):
|
||||
)
|
||||
payload["media"] = media
|
||||
payload["msg_type"] = 7
|
||||
if record_file_path: # c2c record
|
||||
media = await self.upload_group_and_c2c_record(
|
||||
record_file_path, 3, openid = source.author.user_openid
|
||||
)
|
||||
payload["media"] = media
|
||||
payload["msg_type"] = 7
|
||||
if stream:
|
||||
ret = await self.post_c2c_message(
|
||||
openid=source.author.user_openid,
|
||||
@@ -189,59 +165,6 @@ class QQOfficialMessageEvent(AstrMessageEvent):
|
||||
)
|
||||
return await self.bot.api._http.request(route, json=payload)
|
||||
|
||||
async def upload_group_and_c2c_record(
|
||||
self,
|
||||
file_source: str,
|
||||
file_type: int,
|
||||
srv_send_msg: bool = False,
|
||||
**kwargs
|
||||
) -> Optional[Media]:
|
||||
"""
|
||||
上传媒体文件
|
||||
"""
|
||||
# 构建基础payload
|
||||
payload = {
|
||||
"file_type": file_type,
|
||||
"srv_send_msg": srv_send_msg
|
||||
}
|
||||
|
||||
# 处理文件数据
|
||||
if os.path.exists(file_source):
|
||||
# 读取本地文件
|
||||
async with aiofiles.open(file_source, 'rb') as f:
|
||||
file_content = await f.read()
|
||||
# use base64 encode
|
||||
payload["file_data"] = base64.b64encode(file_content).decode('utf-8')
|
||||
else:
|
||||
# 使用URL
|
||||
payload["url"] = file_source
|
||||
|
||||
# 添加接收者信息和确定路由
|
||||
if "openid" in kwargs:
|
||||
payload["openid"] = kwargs["openid"]
|
||||
route = Route("POST", "/v2/users/{openid}/files", openid=kwargs["openid"])
|
||||
elif "group_openid" in kwargs:
|
||||
payload["group_openid"] =kwargs["group_openid"]
|
||||
route = Route("POST", "/v2/groups/{group_openid}/files", group_openid=kwargs["group_openid"])
|
||||
else:
|
||||
return None
|
||||
|
||||
try:
|
||||
# 使用底层HTTP请求
|
||||
result = await self.bot.api._http.request(route, json=payload)
|
||||
|
||||
if result:
|
||||
return Media(
|
||||
file_uuid=result.get("file_uuid"),
|
||||
file_info=result.get("file_info"),
|
||||
ttl=result.get("ttl", 0),
|
||||
file_id=result.get("id", "")
|
||||
)
|
||||
except Exception as e:
|
||||
logger.error(f"上传请求错误: {e}")
|
||||
|
||||
return None
|
||||
|
||||
async def post_c2c_message(
|
||||
self,
|
||||
openid: str,
|
||||
@@ -268,7 +191,6 @@ class QQOfficialMessageEvent(AstrMessageEvent):
|
||||
plain_text = ""
|
||||
image_base64 = None # only one img supported
|
||||
image_file_path = None
|
||||
record_file_path = None
|
||||
for i in message.chain:
|
||||
if isinstance(i, Plain):
|
||||
plain_text += i.text
|
||||
@@ -284,21 +206,6 @@ class QQOfficialMessageEvent(AstrMessageEvent):
|
||||
else:
|
||||
image_base64 = file_to_base64(i.file)
|
||||
image_base64 = image_base64.removeprefix("base64://")
|
||||
elif isinstance(i, Record):
|
||||
if i.file:
|
||||
record_wav_path = await i.convert_to_file_path() # wav 路径
|
||||
temp_dir = os.path.join(get_astrbot_data_path(), "temp")
|
||||
record_tecent_silk_path = os.path.join(temp_dir, f"{uuid.uuid4()}.silk")
|
||||
try:
|
||||
duration = await wav_to_tencent_silk(record_wav_path, record_tecent_silk_path)
|
||||
if duration > 0:
|
||||
record_file_path = record_tecent_silk_path
|
||||
else:
|
||||
record_file_path = None
|
||||
logger.error("转换音频格式时出错:音频时长不大于0")
|
||||
except Exception as e:
|
||||
logger.error(f"处理语音时出错: {e}")
|
||||
record_file_path = None
|
||||
else:
|
||||
logger.debug(f"qq_official 忽略 {i.type}")
|
||||
return plain_text, image_base64, image_file_path, record_file_path
|
||||
return plain_text, image_base64, image_file_path
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import os
|
||||
import uuid
|
||||
import re
|
||||
import ormsgpack
|
||||
from pydantic import BaseModel, conint
|
||||
from httpx import AsyncClient
|
||||
@@ -25,8 +24,8 @@ class ServeTTSRequest(BaseModel):
|
||||
# 参考音频
|
||||
references: list[ServeReferenceAudio] = []
|
||||
# 参考模型 ID
|
||||
# 例如 https://fish.audio/m/626bb6d3f3364c9cbc3aa6a67300a664/
|
||||
# 其中reference_id为 626bb6d3f3364c9cbc3aa6a67300a664
|
||||
# 例如 https://fish.audio/m/7f92f8afb8ec43bf81429cc1c9199cb1/
|
||||
# 其中reference_id为 7f92f8afb8ec43bf81429cc1c9199cb1
|
||||
reference_id: str | None = None
|
||||
# 对中英文文本进行标准化,这可以提高数字的稳定性
|
||||
normalize: bool = True
|
||||
@@ -45,7 +44,6 @@ class ProviderFishAudioTTSAPI(TTSProvider):
|
||||
) -> None:
|
||||
super().__init__(provider_config, provider_settings)
|
||||
self.chosen_api_key: str = provider_config.get("api_key", "")
|
||||
self.reference_id: str = provider_config.get("fishaudio-tts-reference-id", "")
|
||||
self.character: str = provider_config.get("fishaudio-tts-character", "可莉")
|
||||
self.api_base: str = provider_config.get(
|
||||
"api_base", "https://api.fish-audio.cn/v1"
|
||||
@@ -83,43 +81,11 @@ class ProviderFishAudioTTSAPI(TTSProvider):
|
||||
return item["_id"]
|
||||
return None
|
||||
|
||||
def _validate_reference_id(self, reference_id: str) -> bool:
|
||||
"""
|
||||
验证reference_id格式是否有效
|
||||
|
||||
Args:
|
||||
reference_id: 参考模型ID
|
||||
|
||||
Returns:
|
||||
bool: ID是否有效
|
||||
"""
|
||||
if not reference_id or not reference_id.strip():
|
||||
return False
|
||||
|
||||
# FishAudio的reference_id通常是32位十六进制字符串
|
||||
# 例如: 626bb6d3f3364c9cbc3aa6a67300a664
|
||||
pattern = r'^[a-fA-F0-9]{32}$'
|
||||
return bool(re.match(pattern, reference_id.strip()))
|
||||
|
||||
async def _generate_request(self, text: str) -> dict:
|
||||
# 向前兼容逻辑:优先使用reference_id,如果没有则使用角色名称查询
|
||||
if self.reference_id and self.reference_id.strip():
|
||||
# 验证reference_id格式
|
||||
if not self._validate_reference_id(self.reference_id):
|
||||
raise ValueError(
|
||||
f"无效的FishAudio参考模型ID: '{self.reference_id}'. "
|
||||
f"请确保ID是32位十六进制字符串(例如: 626bb6d3f3364c9cbc3aa6a67300a664)。"
|
||||
f"您可以从 https://fish.audio/zh-CN/discovery 获取有效的模型ID。"
|
||||
)
|
||||
reference_id = self.reference_id.strip()
|
||||
else:
|
||||
# 回退到原来的角色名称查询逻辑
|
||||
reference_id = await self._get_reference_id_by_character(self.character)
|
||||
|
||||
return ServeTTSRequest(
|
||||
text=text,
|
||||
format="wav",
|
||||
reference_id=reference_id,
|
||||
reference_id=await self._get_reference_id_by_character(self.character),
|
||||
)
|
||||
|
||||
async def get_audio(self, text: str) -> str:
|
||||
|
||||
@@ -431,7 +431,6 @@ class ProviderGoogleGenAI(Provider):
|
||||
continue
|
||||
|
||||
llm_response = LLMResponse("assistant")
|
||||
llm_response.raw_completion = result
|
||||
llm_response.result_chain = self._process_content_parts(result, llm_response)
|
||||
return llm_response
|
||||
|
||||
@@ -482,7 +481,6 @@ class ProviderGoogleGenAI(Provider):
|
||||
part.function_call for part in chunk.candidates[0].content.parts
|
||||
):
|
||||
llm_response = LLMResponse("assistant", is_chunk=False)
|
||||
llm_response.raw_completion = chunk
|
||||
llm_response.result_chain = self._process_content_parts(
|
||||
chunk, llm_response
|
||||
)
|
||||
@@ -498,7 +496,6 @@ class ProviderGoogleGenAI(Provider):
|
||||
# Process the final chunk for potential tool calls or other content
|
||||
if chunk.candidates[0].content.parts:
|
||||
final_response = LLMResponse("assistant", is_chunk=False)
|
||||
final_response.raw_completion = chunk
|
||||
final_response.result_chain = self._process_content_parts(
|
||||
chunk, final_response
|
||||
)
|
||||
|
||||
@@ -99,13 +99,10 @@ class ProviderOpenAIOfficial(Provider):
|
||||
for key in to_del:
|
||||
del payloads[key]
|
||||
|
||||
model = payloads.get("model", "")
|
||||
# 针对 qwen3 模型的特殊处理:非流式调用必须设置 enable_thinking=false
|
||||
model = payloads.get("model", "")
|
||||
if "qwen3" in model.lower():
|
||||
extra_body["enable_thinking"] = False
|
||||
# 针对 deepseek 模型的特殊处理:deepseek-reasoner调用必须移除 tools ,否则将被切换至 deepseek-chat
|
||||
elif model == "deepseek-reasoner" and "tools" in payloads:
|
||||
del payloads["tools"]
|
||||
extra_body["enable_thinking"] = False
|
||||
|
||||
completion = await self.client.chat.completions.create(
|
||||
**payloads, stream=False, extra_body=extra_body
|
||||
|
||||
@@ -18,6 +18,7 @@ class PlatformAdapterType(enum.Flag):
|
||||
KOOK = enum.auto()
|
||||
VOCECHAT = enum.auto()
|
||||
WEIXIN_OFFICIAL_ACCOUNT = enum.auto()
|
||||
MATRIX = enum.auto()
|
||||
ALL = (
|
||||
AIOCQHTTP
|
||||
| QQOFFICIAL
|
||||
@@ -31,6 +32,7 @@ class PlatformAdapterType(enum.Flag):
|
||||
| KOOK
|
||||
| VOCECHAT
|
||||
| WEIXIN_OFFICIAL_ACCOUNT
|
||||
| MATRIX
|
||||
)
|
||||
|
||||
|
||||
@@ -47,6 +49,7 @@ ADAPTER_NAME_2_TYPE = {
|
||||
"wechatpadpro": PlatformAdapterType.WECHATPADPRO,
|
||||
"vocechat": PlatformAdapterType.VOCECHAT,
|
||||
"weixin_official_account": PlatformAdapterType.WEIXIN_OFFICIAL_ACCOUNT,
|
||||
"matrix": PlatformAdapterType.MATRIX,
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -809,11 +809,11 @@ class PluginManager:
|
||||
if star_metadata.star_cls is None:
|
||||
return
|
||||
|
||||
if '__del__' in star_metadata.star_cls_type.__dict__:
|
||||
if "__del__" in star_metadata.star_cls_type.__dict__:
|
||||
asyncio.get_event_loop().run_in_executor(
|
||||
None, star_metadata.star_cls.__del__
|
||||
)
|
||||
elif 'terminate' in star_metadata.star_cls_type.__dict__:
|
||||
elif "terminate" in star_metadata.star_cls_type.__dict__:
|
||||
await star_metadata.star_cls.terminate()
|
||||
|
||||
async def turn_on_plugin(self, plugin_name: str):
|
||||
|
||||
@@ -56,7 +56,9 @@ class AstrBotUpdator(RepoZipUpdator):
|
||||
try:
|
||||
if "astrbot" in os.path.basename(sys.argv[0]): # 兼容cli
|
||||
if os.name == "nt":
|
||||
args = [f'"{arg}"' if " " in arg else arg for arg in sys.argv[1:]]
|
||||
args = [
|
||||
f'"{arg}"' if " " in arg else arg for arg in sys.argv[1:]
|
||||
]
|
||||
else:
|
||||
args = sys.argv[1:]
|
||||
os.execl(sys.executable, py, "-m", "astrbot.cli.__main__", *args)
|
||||
@@ -66,13 +68,9 @@ class AstrBotUpdator(RepoZipUpdator):
|
||||
logger.error(f"重启失败({py}, {e}),请尝试手动重启。")
|
||||
raise e
|
||||
|
||||
async def check_update(
|
||||
self, url: str, current_version: str, consider_prerelease: bool = True
|
||||
) -> ReleaseInfo:
|
||||
async def check_update(self, url: str, current_version: str) -> ReleaseInfo:
|
||||
"""检查更新"""
|
||||
return await super().check_update(
|
||||
self.ASTRBOT_RELEASE_API, VERSION, consider_prerelease
|
||||
)
|
||||
return await super().check_update(self.ASTRBOT_RELEASE_API, VERSION)
|
||||
|
||||
async def get_releases(self) -> list:
|
||||
return await self.fetch_release_info(self.ASTRBOT_RELEASE_API)
|
||||
@@ -91,6 +89,7 @@ class AstrBotUpdator(RepoZipUpdator):
|
||||
file_url = update_data[0]["zipball_url"]
|
||||
elif str(version).startswith("v"):
|
||||
# 更新到指定版本
|
||||
logger.info(f"正在更新到指定版本: {version}")
|
||||
for data in update_data:
|
||||
if data["tag_name"] == version:
|
||||
file_url = data["zipball_url"]
|
||||
@@ -99,8 +98,8 @@ class AstrBotUpdator(RepoZipUpdator):
|
||||
else:
|
||||
if len(str(version)) != 40:
|
||||
raise Exception("commit hash 长度不正确,应为 40")
|
||||
file_url = f"https://github.com/Soulter/AstrBot/archive/{version}.zip"
|
||||
logger.info(f"准备更新至指定版本的 AstrBot Core: {version}")
|
||||
logger.info(f"正在尝试更新到指定 commit: {version}")
|
||||
file_url = "https://github.com/Soulter/AstrBot/archive/" + version + ".zip"
|
||||
|
||||
if proxy:
|
||||
proxy = proxy.removesuffix("/")
|
||||
@@ -108,7 +107,6 @@ class AstrBotUpdator(RepoZipUpdator):
|
||||
|
||||
try:
|
||||
await download_file(file_url, "temp.zip")
|
||||
logger.info("下载 AstrBot Core 更新文件完成,正在执行解压...")
|
||||
self.unzip_file("temp.zip", self.MAIN_PATH)
|
||||
except BaseException as e:
|
||||
raise e
|
||||
|
||||
@@ -8,7 +8,6 @@ import base64
|
||||
import zipfile
|
||||
import uuid
|
||||
import psutil
|
||||
import logging
|
||||
|
||||
import certifi
|
||||
|
||||
@@ -17,8 +16,6 @@ from typing import Union
|
||||
from PIL import Image
|
||||
from .astrbot_path import get_astrbot_data_path
|
||||
|
||||
logger = logging.getLogger("astrbot")
|
||||
|
||||
|
||||
def on_error(func, path, exc_info):
|
||||
"""
|
||||
@@ -215,50 +212,19 @@ async def get_dashboard_version():
|
||||
return None
|
||||
|
||||
|
||||
async def download_dashboard(
|
||||
path: str | None = None,
|
||||
extract_path: str = "data",
|
||||
latest: bool = True,
|
||||
version: str | None = None,
|
||||
proxy: str | None = None,
|
||||
):
|
||||
async def download_dashboard(path: str = None, extract_path: str = "data"):
|
||||
"""下载管理面板文件"""
|
||||
if path is None:
|
||||
path = os.path.join(get_astrbot_data_path(), "dashboard.zip")
|
||||
|
||||
if latest or len(str(version)) != 40:
|
||||
logger.info(f"准备下载 {version} 发行版本的 AstrBot WebUI 文件")
|
||||
ver_name = "latest" if latest else version
|
||||
dashboard_release_url = f"https://astrbot-registry.soulter.top/download/astrbot-dashboard/{ver_name}/dist.zip"
|
||||
try:
|
||||
await download_file(dashboard_release_url, path, show_progress=True)
|
||||
except BaseException as _:
|
||||
if latest:
|
||||
dashboard_release_url = "https://github.com/Soulter/AstrBot/releases/latest/download/dist.zip"
|
||||
else:
|
||||
dashboard_release_url = f"https://github.com/Soulter/AstrBot/releases/download/{version}/dist.zip"
|
||||
if proxy:
|
||||
dashboard_release_url = f"{proxy}/{dashboard_release_url}"
|
||||
await download_file(dashboard_release_url, path, show_progress=True)
|
||||
else:
|
||||
logger.info(f"准备下载指定版本的 AstrBot WebUI: {version}")
|
||||
|
||||
url = (
|
||||
"https://api.github.com/repos/AstrBotDevs/astrbot-release-harbour/releases"
|
||||
dashboard_release_url = "https://astrbot-registry.soulter.top/download/astrbot-dashboard/latest/dist.zip"
|
||||
try:
|
||||
await download_file(dashboard_release_url, path, show_progress=True)
|
||||
except BaseException as _:
|
||||
dashboard_release_url = (
|
||||
"https://github.com/Soulter/AstrBot/releases/latest/download/dist.zip"
|
||||
)
|
||||
if proxy:
|
||||
url = f"{proxy}/{url}"
|
||||
async with aiohttp.ClientSession(trust_env=True) as session:
|
||||
async with session.get(url) as resp:
|
||||
if resp.status == 200:
|
||||
releases = await resp.json()
|
||||
for release in releases:
|
||||
if version in release["tag_name"]:
|
||||
download_url = release["assets"][0]["browser_download_url"]
|
||||
await download_file(download_url, path, show_progress=True)
|
||||
else:
|
||||
logger.warning(f"未找到指定的版本的 Dashboard 构建文件: {version}")
|
||||
return
|
||||
|
||||
await download_file(dashboard_release_url, path, show_progress=True)
|
||||
print("解压管理面板文件中...")
|
||||
with zipfile.ZipFile(path, "r") as z:
|
||||
z.extractall(extract_path)
|
||||
|
||||
@@ -107,38 +107,16 @@ class RepoZipUpdator:
|
||||
"""Semver 版本比较"""
|
||||
return VersionComparator.compare_version(v1, v2)
|
||||
|
||||
async def check_update(
|
||||
self, url: str, current_version: str, consider_prerelease: bool = True
|
||||
) -> ReleaseInfo | None:
|
||||
async def check_update(self, url: str, current_version: str) -> ReleaseInfo | None:
|
||||
update_data = await self.fetch_release_info(url)
|
||||
|
||||
sel_release_data = None
|
||||
if consider_prerelease:
|
||||
tag_name = update_data[0]["tag_name"]
|
||||
sel_release_data = update_data[0]
|
||||
else:
|
||||
for data in update_data:
|
||||
# 跳过带有 alpha、beta 等预发布标签的版本
|
||||
if re.search(
|
||||
r"[\-_.]?(alpha|beta|rc|dev)[\-_.]?\d*$",
|
||||
data["tag_name"],
|
||||
re.IGNORECASE,
|
||||
):
|
||||
continue
|
||||
tag_name = data["tag_name"]
|
||||
sel_release_data = data
|
||||
break
|
||||
|
||||
if not sel_release_data or not tag_name:
|
||||
logger.error("未找到合适的发布版本")
|
||||
return None
|
||||
tag_name = update_data[0]["tag_name"]
|
||||
|
||||
if self.compare_version(current_version, tag_name) >= 0:
|
||||
return None
|
||||
return ReleaseInfo(
|
||||
version=tag_name,
|
||||
published_at=sel_release_data["published_at"],
|
||||
body=f"{tag_name}\n\n{sel_release_data['body']}",
|
||||
published_at=update_data[0]["published_at"],
|
||||
body=update_data[0]["body"],
|
||||
)
|
||||
|
||||
async def download_from_repo_url(self, target_path: str, repo_url: str, proxy=""):
|
||||
@@ -203,13 +181,14 @@ class RepoZipUpdator:
|
||||
"""
|
||||
os.makedirs(target_dir, exist_ok=True)
|
||||
update_dir = ""
|
||||
logger.info(f"解压文件: {zip_path}")
|
||||
with zipfile.ZipFile(zip_path, "r") as z:
|
||||
update_dir = z.namelist()[0]
|
||||
z.extractall(target_dir)
|
||||
logger.debug(f"解压文件完成: {zip_path}")
|
||||
|
||||
files = os.listdir(os.path.join(target_dir, update_dir))
|
||||
for f in files:
|
||||
logger.info(f"移动更新文件/目录: {f}")
|
||||
if os.path.isdir(os.path.join(target_dir, update_dir, f)):
|
||||
if os.path.exists(os.path.join(target_dir, f)):
|
||||
shutil.rmtree(os.path.join(target_dir, f), onerror=on_error)
|
||||
@@ -219,13 +198,13 @@ class RepoZipUpdator:
|
||||
shutil.move(os.path.join(target_dir, update_dir, f), target_dir)
|
||||
|
||||
try:
|
||||
logger.debug(
|
||||
logger.info(
|
||||
f"删除临时更新文件: {zip_path} 和 {os.path.join(target_dir, update_dir)}"
|
||||
)
|
||||
shutil.rmtree(os.path.join(target_dir, update_dir), onerror=on_error)
|
||||
os.remove(zip_path)
|
||||
except BaseException:
|
||||
logger.warning(
|
||||
logger.warn(
|
||||
f"删除更新文件失败,可以手动删除 {zip_path} 和 {os.path.join(target_dir, update_dir)}"
|
||||
)
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ class UpdateRoute(Route):
|
||||
.__dict__
|
||||
)
|
||||
else:
|
||||
ret = await self.astrbot_updator.check_update(None, None, False)
|
||||
ret = await self.astrbot_updator.check_update(None, None)
|
||||
return Response(
|
||||
status="success",
|
||||
message=str(ret) if ret is not None else "已经是最新版本了。",
|
||||
@@ -48,7 +48,7 @@ class UpdateRoute(Route):
|
||||
"version": f"v{VERSION}",
|
||||
"has_new_version": ret is not None,
|
||||
"dashboard_version": dv,
|
||||
"dashboard_has_new_version": dv and dv != f"v{VERSION}",
|
||||
"dashboard_has_new_version": dv != f"v{VERSION}",
|
||||
},
|
||||
).__dict__
|
||||
except Exception as e:
|
||||
@@ -82,10 +82,11 @@ class UpdateRoute(Route):
|
||||
latest=latest, version=version, proxy=proxy
|
||||
)
|
||||
|
||||
try:
|
||||
await download_dashboard(latest=latest, version=version, proxy=proxy)
|
||||
except Exception as e:
|
||||
logger.error(f"下载管理面板文件失败: {e}。")
|
||||
if latest:
|
||||
try:
|
||||
await download_dashboard()
|
||||
except Exception as e:
|
||||
logger.error(f"下载管理面板文件失败: {e}。")
|
||||
|
||||
# pip 更新依赖
|
||||
logger.info("更新依赖中...")
|
||||
@@ -114,7 +115,7 @@ class UpdateRoute(Route):
|
||||
async def update_dashboard(self):
|
||||
try:
|
||||
try:
|
||||
await download_dashboard(version=f"v{VERSION}", latest=False)
|
||||
await download_dashboard()
|
||||
except Exception as e:
|
||||
logger.error(f"下载管理面板文件失败: {e}。")
|
||||
return Response().error(f"下载管理面板文件失败: {e}").__dict__
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
# What's Changed
|
||||
|
||||
1. 修复: 修复插件可能存在的无法正常禁用的问题 ([#2352](https://github.com/Soulter/AstrBot/issues/2352))
|
||||
2. ❗修复:当返回文本为空并且存在函数调用时错误地被终止事件,导致函数调用结果未被正常返回 ([#2491](https://github.com/Soulter/AstrBot/issues/2491))
|
||||
3. 修复:修复无法清空 AstrBot 配置下的 http_proxy 代理的问题 ([#2434](https://github.com/Soulter/AstrBot/issues/2434))
|
||||
4. ❗修复:Gemini 下开启流式输出时,持久化的消息结果不完整 ([#2424](https://github.com/Soulter/AstrBot/issues/2424))
|
||||
5. 修复:注册文件时由于 file:/// 前缀,导致文件被误判为不存在的问题 ([#2325](https://github.com/Soulter/AstrBot/issues/2325))
|
||||
6. 优化: 为部分类型供应商添加默认的温度选项 ([#2321](https://github.com/Soulter/AstrBot/issues/2321))
|
||||
7. 优化: 适配 Qwen3 模型非流式输出下需要传入 enable_think 参数(否则报错) ([#2424](https://github.com/Soulter/AstrBot/issues/2424))
|
||||
8. 优化:支持配置工具调用轮数上限,默认 30
|
||||
9. 新增: 添加 WebUI 语义化预发布版本提醒和检测功能
|
||||
|
||||
> 新版本预告: v4.0.0 即将发布。
|
||||
@@ -1,9 +0,0 @@
|
||||
# What's Changed
|
||||
|
||||
1. 新增:为 FishAudio TTS 添加可选的 reference_id 直接指定功能 ([#2513](https://github.com/AstrBotDevs/AstrBot/issues/2513))
|
||||
2. 新增:Gemini 添加对 LLMResponse 的 raw_completion 支持
|
||||
3. 新增:支持官方 QQ 接口发送语音 ([#2525](https://github.com/AstrBotDevs/AstrBot/issues/2525))
|
||||
4. 新增:调用 deepseek-reasoner 时自动移除 tools ([#2531](https://github.com/AstrBotDevs/AstrBot/issues/2531))
|
||||
5. 新增:添加 no_proxy 配置支持以优化代理设置 ([#2564](https://github.com/AstrBotDevs/AstrBot/issues/2564))
|
||||
6. 新增:支持升级的同时更新到指定版本的 WebUI
|
||||
7. 修复: 修复编辑会话名称窗口的圆角和左右边距问题 ([#2583](https://github.com/AstrBotDevs/AstrBot/issues/2583))
|
||||
@@ -1,5 +0,0 @@
|
||||
# What's Changed
|
||||
|
||||
1. 修复:构建 docker 镜像时同时构建 webui,并放入镜像中。
|
||||
2. 修复:下载 WebUI 文件时,明确版本号,以防止 latest 不一致导致下载的 WebUI 文件版本号与实际所需不符的问题。
|
||||
3. 优化:优化版本检测,考虑预发布版本,移除 `更新到最新版本` 按钮
|
||||
@@ -25,16 +25,10 @@
|
||||
"dev": "🧐 Development (master branch)"
|
||||
},
|
||||
"updateToLatest": "Update to Latest Version",
|
||||
"preRelease": "Pre-release",
|
||||
"preReleaseWarning": {
|
||||
"title": "Pre-release Version Notice",
|
||||
"description": "Versions marked as pre-release may contain unknown issues or bugs and are not recommended for production use. If you encounter any problems, please visit ",
|
||||
"issueLink": "GitHub Issues"
|
||||
},
|
||||
"tip": "💡 TIP:",
|
||||
"tipLink": "",
|
||||
"tipContinue": "By default, the corresponding version of the WebUI files will be downloaded when switching versions. The WebUI code is located in the dashboard directory of the project, and you can use npm to build it yourself.",
|
||||
"dockerTip": "When switching versions, it will try to update both the bot main program and the dashboard. If you are using Docker deployment, you can also re-pull the image or use",
|
||||
"tip": "💡 TIP: Switching to an older version or a specific version will not re-download the dashboard files, which may cause some data display errors. You can find the corresponding dashboard files dist.zip at",
|
||||
"tipLink": "here",
|
||||
"tipContinue": ", extract and replace the data/dist folder. Of course, the frontend source code is in the dashboard directory, you can also build it yourself using npm install and npm build.",
|
||||
"dockerTip": "The `Update to Latest Version` button will try to update both the bot main program and the dashboard. If you are using Docker deployment, you can also re-pull the image or use",
|
||||
"dockerTipLink": "watchtower",
|
||||
"dockerTipContinue": "to automatically monitor and pull.",
|
||||
"table": {
|
||||
|
||||
@@ -25,15 +25,10 @@
|
||||
"dev": "🧐 开发版(master 分支)"
|
||||
},
|
||||
"updateToLatest": "更新到最新版本",
|
||||
"preRelease": "预发布",
|
||||
"preReleaseWarning": {
|
||||
"title": "预发布版本提醒",
|
||||
"description": "标有预发布标签的版本可能存在未知问题或 Bug,不建议在生产环境使用。如发现问题,请提交至 ",
|
||||
"issueLink": "GitHub Issues"
|
||||
},
|
||||
"tip": "💡 TIP: ",
|
||||
"tipContinue": "默认在切换版本时会下载对应版本的 WebUI 文件。WebUI 代码位于项目的 dashboard 目录,您可使用 npm 自行构建。",
|
||||
"dockerTip": "切换版本时,会同时尝试更新机器人主程序和管理面板。如果您正在使用 Docker 部署,也可以重新拉取镜像或者使用",
|
||||
"tip": "💡 TIP: 跳到旧版本或者切换到某个版本不会重新下载管理面板文件,这可能会造成部分数据显示错误。您可在",
|
||||
"tipLink": "此处",
|
||||
"tipContinue": "找到对应的面板文件 dist.zip,解压后替换 data/dist 文件夹即可。当然,前端源代码在 dashboard 目录下,你也可以自己使用 npm install 和 npm build 构建。",
|
||||
"dockerTip": "`更新到最新版本` 按钮会同时尝试更新机器人主程序和管理面板。如果您正在使用 Docker 部署,也可以重新拉取镜像或者使用",
|
||||
"dockerTipLink": "watchtower",
|
||||
"dockerTipContinue": "来自动监控拉取。",
|
||||
"table": {
|
||||
|
||||
@@ -36,7 +36,7 @@ let dashboardHasNewVersion = ref(false);
|
||||
let dashboardCurrentVersion = ref('');
|
||||
let version = ref('');
|
||||
let releases = ref([]);
|
||||
let devCommits = ref<{ sha: string; date: string; message: string }[]>([]);
|
||||
let devCommits = ref([]);
|
||||
let updatingDashboardLoading = ref(false);
|
||||
let installLoading = ref(false);
|
||||
|
||||
@@ -76,13 +76,6 @@ const open = (link: string) => {
|
||||
window.open(link, '_blank');
|
||||
};
|
||||
|
||||
// 检测是否为预发布版本
|
||||
const isPreRelease = (version: string) => {
|
||||
const preReleaseKeywords = ['alpha', 'beta', 'rc', 'pre', 'preview', 'dev'];
|
||||
const lowerVersion = version.toLowerCase();
|
||||
return preReleaseKeywords.some(keyword => lowerVersion.includes(keyword));
|
||||
};
|
||||
|
||||
// 账户修改
|
||||
function accountEdit() {
|
||||
accountEditStatus.value.loading = true;
|
||||
@@ -189,46 +182,23 @@ function getReleases() {
|
||||
}
|
||||
|
||||
function getDevCommits() {
|
||||
let proxy = localStorage.getItem('selectedGitHubProxy') || '';
|
||||
const originalUrl = "https://api.github.com/repos/Soulter/AstrBot/commits";
|
||||
let commits_url = originalUrl;
|
||||
if (proxy !== '') {
|
||||
proxy = proxy.endsWith('/') ? proxy : proxy + '/';
|
||||
commits_url = proxy + originalUrl;
|
||||
}
|
||||
|
||||
function fetchCommits(url: string, onError?: () => void) {
|
||||
fetch(url, {
|
||||
headers: {
|
||||
'Host': 'api.github.com',
|
||||
'Referer': 'https://api.github.com'
|
||||
}
|
||||
})
|
||||
fetch('https://api.github.com/repos/Soulter/AstrBot/commits', {
|
||||
headers: {
|
||||
'Host': 'api.github.com',
|
||||
'Referer': 'https://api.github.com'
|
||||
}
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
devCommits.value = Array.isArray(data)
|
||||
? data.map((commit: any) => ({
|
||||
sha: commit.sha,
|
||||
date: new Date(commit.commit.author.date).toLocaleString(),
|
||||
message: commit.commit.message
|
||||
}))
|
||||
: [];
|
||||
devCommits.value = data.map((commit: any) => ({
|
||||
sha: commit.sha,
|
||||
date: new Date(commit.commit.author.date).toLocaleString(),
|
||||
message: commit.commit.message
|
||||
}));
|
||||
})
|
||||
.catch(err => {
|
||||
if (onError) {
|
||||
onError();
|
||||
} else {
|
||||
console.log('获取开发版提交信息失败:', err);
|
||||
}
|
||||
console.log(err);
|
||||
});
|
||||
}
|
||||
|
||||
fetchCommits(commits_url, () => {
|
||||
if (proxy !== '' && commits_url !== originalUrl) {
|
||||
console.log('使用代理请求失败,尝试直接请求');
|
||||
fetchCommits(originalUrl);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function switchVersion(version: string) {
|
||||
@@ -335,7 +305,7 @@ commonStore.getStartTime();
|
||||
</v-btn>
|
||||
|
||||
<!-- 更新对话框 -->
|
||||
<v-dialog v-model="updateStatusDialog" :width="$vuetify.display.smAndDown ? '100%' : '1200'" :fullscreen="$vuetify.display.xs">
|
||||
<v-dialog v-model="updateStatusDialog" :width="$vuetify.display.smAndDown ? '100%' : '1000'" :fullscreen="$vuetify.display.xs">
|
||||
<template v-slot:activator="{ props }">
|
||||
<v-btn size="small" @click="checkUpdate(); getReleases(); getDevCommits();" class="action-btn"
|
||||
color="var(--v-theme-surface)" variant="flat" rounded="sm" v-bind="props">
|
||||
@@ -365,7 +335,8 @@ commonStore.getStartTime();
|
||||
</div>
|
||||
|
||||
<div class="mb-4 mt-4">
|
||||
<small>{{ t('core.header.updateDialog.tip') }}
|
||||
<small>{{ t('core.header.updateDialog.tip') }} <a
|
||||
href="https://github.com/Soulter/AstrBot/releases">{{ t('core.header.updateDialog.tipLink') }}</a>
|
||||
{{ t('core.header.updateDialog.tipContinue') }}</small>
|
||||
</div>
|
||||
|
||||
@@ -377,49 +348,20 @@ commonStore.getStartTime();
|
||||
|
||||
<!-- 发行版 -->
|
||||
<v-tabs-window-item key="0" v-show="tab == 0">
|
||||
<v-btn class="mt-4 mb-4" @click="switchVersion('latest')" color="primary" style="border-radius: 10px;"
|
||||
:disabled="!hasNewVersion">
|
||||
{{ t('core.header.updateDialog.updateToLatest') }}
|
||||
</v-btn>
|
||||
<div class="mb-4">
|
||||
<small>{{ t('core.header.updateDialog.dockerTip') }} <a
|
||||
href="https://containrrr.dev/watchtower/usage-overview/">{{ t('core.header.updateDialog.dockerTipLink') }}</a> {{ t('core.header.updateDialog.dockerTipContinue') }}</small>
|
||||
</div>
|
||||
|
||||
<v-alert
|
||||
v-if="releases.some(item => isPreRelease(item['tag_name']))"
|
||||
type="warning"
|
||||
variant="tonal"
|
||||
border="start"
|
||||
>
|
||||
<template v-slot:prepend>
|
||||
<v-icon>mdi-alert-circle-outline</v-icon>
|
||||
</template>
|
||||
<div class="text-body-2">
|
||||
<strong>{{ t('core.header.updateDialog.preReleaseWarning.title') }}</strong>
|
||||
<br>
|
||||
{{ t('core.header.updateDialog.preReleaseWarning.description') }}
|
||||
<a href="https://github.com/Soulter/AstrBot/issues" target="_blank" class="text-decoration-none">
|
||||
{{ t('core.header.updateDialog.preReleaseWarning.issueLink') }}
|
||||
</a>
|
||||
</div>
|
||||
</v-alert>
|
||||
|
||||
<v-data-table :headers="releasesHeader" :items="releases" item-key="name" :items-per-page="5">
|
||||
<template v-slot:item.tag_name="{ item }: { item: { tag_name: string } }">
|
||||
<div class="d-flex align-center">
|
||||
<span>{{ item.tag_name }}</span>
|
||||
<v-chip
|
||||
v-if="isPreRelease(item.tag_name)"
|
||||
size="x-small"
|
||||
color="warning"
|
||||
variant="tonal"
|
||||
class="ml-2"
|
||||
>
|
||||
{{ t('core.header.updateDialog.preRelease') }}
|
||||
</v-chip>
|
||||
</div>
|
||||
</template>
|
||||
<v-data-table :headers="releasesHeader" :items="releases" item-key="name">
|
||||
<template v-slot:item.body="{ item }: { item: { body: string } }">
|
||||
<v-tooltip :text="item.body">
|
||||
<template v-slot:activator="{ props }">
|
||||
<v-btn v-bind="props" rounded="xl" variant="tonal" color="primary" size="x-small">{{ t('core.header.updateDialog.table.view') }}</v-btn>
|
||||
<v-btn v-bind="props" rounded="xl" variant="tonal" color="primary" size="small">{{ t('core.header.updateDialog.table.view') }}</v-btn>
|
||||
</template>
|
||||
</v-tooltip>
|
||||
</template>
|
||||
|
||||
@@ -480,7 +480,7 @@
|
||||
|
||||
<!-- 会话命名编辑对话框 -->
|
||||
<v-dialog v-model="nameEditDialog" max-width="500" min-height="60%">
|
||||
<v-card v-if="selectedSessionForName">
|
||||
<v-card v-if="selectedSessionForName" rounded="12">
|
||||
<v-card-title class="bg-primary text-white py-3 px-4" style="display: flex; align-items: center;">
|
||||
<v-icon color="white" class="me-2">mdi-rename-box</v-icon>
|
||||
<span>{{ tm('nameEditor.title') }}</span>
|
||||
@@ -490,9 +490,8 @@
|
||||
</v-btn>
|
||||
</v-card-title>
|
||||
|
||||
<v-card-text>
|
||||
<div style="padding-left: 16px; padding-right: 16px;">
|
||||
<v-text-field
|
||||
<v-card-text class="pa-4">
|
||||
<v-text-field
|
||||
v-model="newSessionName"
|
||||
:label="tm('nameEditor.customName')"
|
||||
:placeholder="tm('nameEditor.placeholder')"
|
||||
@@ -519,7 +518,6 @@
|
||||
>
|
||||
{{ tm('nameEditor.hint') }}
|
||||
</v-alert>
|
||||
</div>
|
||||
</v-card-text>
|
||||
|
||||
<v-card-actions class="px-4 pb-4">
|
||||
|
||||
6
main.py
6
main.py
@@ -44,10 +44,10 @@ async def check_dashboard_files():
|
||||
if v is not None:
|
||||
# has file
|
||||
if v == f"v{VERSION}":
|
||||
logger.info("WebUI 版本已是最新。")
|
||||
logger.info("管理面板文件已是最新。")
|
||||
else:
|
||||
logger.warning(
|
||||
f"检测到 WebUI 版本 ({v}) 与当前 AstrBot 版本 (v{VERSION}) 不符。"
|
||||
"检测到管理面板有更新。可以使用 /dashboard_update 命令更新。"
|
||||
)
|
||||
return
|
||||
|
||||
@@ -56,7 +56,7 @@ async def check_dashboard_files():
|
||||
)
|
||||
|
||||
try:
|
||||
await download_dashboard(version=f"v{VERSION}", latest=False)
|
||||
await download_dashboard()
|
||||
except Exception as e:
|
||||
logger.critical(f"下载管理面板文件失败: {e}。")
|
||||
return
|
||||
|
||||
@@ -1119,7 +1119,7 @@ UID: {user_id} 此 ID 可用于设置管理员。
|
||||
@filter.command("dashboard_update")
|
||||
async def update_dashboard(self, event: AstrMessageEvent):
|
||||
yield event.plain_result("正在尝试更新管理面板...")
|
||||
await download_dashboard(version=f"v{VERSION}", latest=False)
|
||||
await download_dashboard()
|
||||
yield event.plain_result("管理面板更新完成。")
|
||||
|
||||
@filter.command("set")
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[project]
|
||||
name = "AstrBot"
|
||||
version = "3.5.27"
|
||||
version = "3.5.24"
|
||||
description = "易上手的多平台 LLM 聊天机器人及开发框架"
|
||||
readme = "README.md"
|
||||
requires-python = ">=3.10"
|
||||
@@ -26,6 +26,7 @@ dependencies = [
|
||||
"googlesearch-python>=1.3.0",
|
||||
"lark-oapi>=1.4.15",
|
||||
"lxml-html-clean>=0.4.2",
|
||||
"matrix-nio>=0.25.2",
|
||||
"mcp>=1.8.0",
|
||||
"openai>=1.78.0",
|
||||
"ormsgpack>=1.9.1",
|
||||
|
||||
Reference in New Issue
Block a user