From 10270b559558f47a6084ae9a45022ad447c5d386 Mon Sep 17 00:00:00 2001 From: Soulter <905617992@qq.com> Date: Sat, 17 May 2025 15:38:51 +0800 Subject: [PATCH 01/18] feat: alkaid framework and supports to customize webapi endpoint --- astrbot/core/star/context.py | 5 + astrbot/dashboard/server.py | 10 + dashboard/package.json | 3 + .../full/vertical-sidebar/VerticalSidebar.vue | 4 + .../full/vertical-sidebar/sidebarItem.ts | 6 +- dashboard/src/router/MainRoutes.ts | 6 +- dashboard/src/views/ATRIProject.vue | 87 ------ dashboard/src/views/AlkaidPage.vue | 249 ++++++++++++++++++ dashboard/src/views/ChatPage.vue | 28 +- 9 files changed, 292 insertions(+), 106 deletions(-) delete mode 100644 dashboard/src/views/ATRIProject.vue create mode 100644 dashboard/src/views/AlkaidPage.vue diff --git a/astrbot/core/star/context.py b/astrbot/core/star/context.py index d2df31ec4..b1aed8ed9 100644 --- a/astrbot/core/star/context.py +++ b/astrbot/core/star/context.py @@ -42,6 +42,8 @@ class Context: platform_manager: PlatformManager = None + registered_web_apis: list = [] + # back compatibility _register_tasks: List[Awaitable] = [] _star_manager = None @@ -301,3 +303,6 @@ class Context: 注册一个异步任务。 """ self._register_tasks.append(task) + + def register_web_api(self, route: str, view_handler: Awaitable, methods: list, desc: str): + self.registered_web_apis.append((route, view_handler, methods, desc)) diff --git a/astrbot/dashboard/server.py b/astrbot/dashboard/server.py index 124291718..a34606d31 100644 --- a/astrbot/dashboard/server.py +++ b/astrbot/dashboard/server.py @@ -15,6 +15,8 @@ from astrbot.core.db import BaseDatabase from astrbot.core.utils.io import get_local_ip_addresses from astrbot.core.utils.astrbot_path import get_astrbot_data_path +APP: Quart = None + class AstrBotDashboard: def __init__( @@ -27,6 +29,7 @@ class AstrBotDashboard: self.config = core_lifecycle.astrbot_config self.data_path = os.path.abspath(os.path.join(get_astrbot_data_path(), "dist")) self.app = Quart("dashboard", static_folder=self.data_path, static_url_path="/") + APP = self.app # noqa self.app.config["MAX_CONTENT_LENGTH"] = ( 128 * 1024 * 1024 ) # 将 Flask 允许的最大上传文件体大小设置为 128 MB @@ -51,6 +54,13 @@ class AstrBotDashboard: self.conversation_route = ConversationRoute(self.context, db, core_lifecycle) self.file_route = FileRoute(self.context) + if self.core_lifecycle.star_context.registered_web_apis: + for api in self.core_lifecycle.star_context.registered_web_apis: + route, view_handler, methods, _ = api + self.app.add_url_rule( + f"/api/plug{route}", view_func=view_handler, methods=methods + ) + self.shutdown_event = shutdown_event async def auth_middleware(self): diff --git a/dashboard/package.json b/dashboard/package.json index a7edd4935..59d3f3042 100644 --- a/dashboard/package.json +++ b/dashboard/package.json @@ -21,12 +21,15 @@ "axios-mock-adapter": "^1.22.0", "chance": "1.1.11", "date-fns": "2.30.0", + "graphology": "^0.26.0", + "graphology-layout-force": "^0.2.4", "highlight.js": "^11.11.1", "js-md5": "^0.8.3", "lodash": "4.17.21", "marked": "^15.0.7", "pinia": "2.1.6", "remixicon": "3.5.0", + "sigma": "^3.0.1", "vee-validate": "4.11.3", "vite-plugin-vuetify": "1.0.2", "vue": "3.3.4", diff --git a/dashboard/src/layouts/full/vertical-sidebar/VerticalSidebar.vue b/dashboard/src/layouts/full/vertical-sidebar/VerticalSidebar.vue index d505e0422..82f160746 100644 --- a/dashboard/src/layouts/full/vertical-sidebar/VerticalSidebar.vue +++ b/dashboard/src/layouts/full/vertical-sidebar/VerticalSidebar.vue @@ -166,6 +166,10 @@ function endDrag() {
+ + 🔧 设置 + +
官方文档 diff --git a/dashboard/src/layouts/full/vertical-sidebar/sidebarItem.ts b/dashboard/src/layouts/full/vertical-sidebar/sidebarItem.ts index 803642e95..e8f49c741 100644 --- a/dashboard/src/layouts/full/vertical-sidebar/sidebarItem.ts +++ b/dashboard/src/layouts/full/vertical-sidebar/sidebarItem.ts @@ -66,9 +66,9 @@ const sidebarItem: menu[] = [ to: '/console' }, { - title: '设置', - icon: 'mdi-wrench', - to: '/settings' + title: 'Alkaid', + icon: 'mdi-test-tube', + to: '/alkaid' }, { title: '关于', diff --git a/dashboard/src/router/MainRoutes.ts b/dashboard/src/router/MainRoutes.ts index f1ac3002d..2d3defd54 100644 --- a/dashboard/src/router/MainRoutes.ts +++ b/dashboard/src/router/MainRoutes.ts @@ -57,9 +57,9 @@ const MainRoutes = { component: () => import('@/views/ConsolePage.vue') }, { - name: 'Project ATRI', - path: '/project-atri', - component: () => import('@/views/ATRIProject.vue') + name: 'Alkaid', + path: '/alkaid', + component: () => import('@/views/AlkaidPage.vue') }, { name: 'Chat', diff --git a/dashboard/src/views/ATRIProject.vue b/dashboard/src/views/ATRIProject.vue deleted file mode 100644 index 4c9a771d4..000000000 --- a/dashboard/src/views/ATRIProject.vue +++ /dev/null @@ -1,87 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/dashboard/src/views/AlkaidPage.vue b/dashboard/src/views/AlkaidPage.vue new file mode 100644 index 000000000..3690bedf5 --- /dev/null +++ b/dashboard/src/views/AlkaidPage.vue @@ -0,0 +1,249 @@ + + + + + + + + \ No newline at end of file diff --git a/dashboard/src/views/ChatPage.vue b/dashboard/src/views/ChatPage.vue index 07eb41c22..e686e693c 100644 --- a/dashboard/src/views/ChatPage.vue +++ b/dashboard/src/views/ChatPage.vue @@ -12,19 +12,22 @@ marked.setOptions({
-