From ebe0b68e8fb6a7dc35b04f158de103288216c4fe Mon Sep 17 00:00:00 2001 From: Junyan Qin Date: Thu, 14 Aug 2025 23:42:57 +0800 Subject: [PATCH] feat: set cloud_service_url --- pkg/api/http/controller/groups/system.py | 11 ++++++++++- templates/config.yaml | 3 ++- web/src/app/infra/entities/api/index.ts | 1 + web/src/app/infra/http/HttpClient.ts | 19 ++++++++++--------- 4 files changed, 23 insertions(+), 11 deletions(-) diff --git a/pkg/api/http/controller/groups/system.py b/pkg/api/http/controller/groups/system.py index 2db910b9..9e85e3ad 100644 --- a/pkg/api/http/controller/groups/system.py +++ b/pkg/api/http/controller/groups/system.py @@ -14,6 +14,11 @@ class SystemRouterGroup(group.RouterGroup): 'version': constants.semantic_version, 'debug': constants.debug_mode, 'enabled_platform_count': len(self.ap.platform_mgr.get_running_adapters()), + 'cloud_service_url': ( + self.ap.instance_config.data['plugin']['cloud_service_url'] + if 'cloud_service_url' in self.ap.instance_config.data['plugin'] + else 'https://space.langbot.app' + ), } ) @@ -57,7 +62,11 @@ class SystemRouterGroup(group.RouterGroup): data=await self.ap.tool_mgr.execute_func_call(data['tool_name'], data['tool_parameters']) ) - @self.route('/debug/plugin/action', methods=['POST'], auth_type=group.AuthType.USER_TOKEN) + @self.route( + '/debug/plugin/action', + methods=['POST'], + auth_type=group.AuthType.USER_TOKEN, + ) async def _() -> str: if not constants.debug_mode: return self.http_status(403, 403, 'Forbidden') diff --git a/templates/config.yaml b/templates/config.yaml index c896417c..dd35e39c 100644 --- a/templates/config.yaml +++ b/templates/config.yaml @@ -19,4 +19,5 @@ system: expire: 604800 secret: '' plugin: - runtime_ws_url: 'ws://plugin-runtime:5400/control/ws' \ No newline at end of file + runtime_ws_url: 'ws://plugin-runtime:5400/control/ws' + cloud_service_url: 'https://space.langbot.app' \ No newline at end of file diff --git a/web/src/app/infra/entities/api/index.ts b/web/src/app/infra/entities/api/index.ts index c49ab861..a1c8d8cb 100644 --- a/web/src/app/infra/entities/api/index.ts +++ b/web/src/app/infra/entities/api/index.ts @@ -151,6 +151,7 @@ export interface PluginReorderElement { export interface ApiRespSystemInfo { debug: boolean; version: string; + cloud_service_url: string; } export interface ApiRespAsyncTasks { diff --git a/web/src/app/infra/http/HttpClient.ts b/web/src/app/infra/http/HttpClient.ts index a86cdbe8..e5192063 100644 --- a/web/src/app/infra/http/HttpClient.ts +++ b/web/src/app/infra/http/HttpClient.ts @@ -53,7 +53,11 @@ export interface RequestConfig extends AxiosRequestConfig { retry?: number; // 重试次数 } -export let systemInfo: ApiRespSystemInfo | null = null; +export let systemInfo: ApiRespSystemInfo = { + debug: false, + version: '', + cloud_service_url: '', +}; class HttpClient { private instance: AxiosInstance; @@ -74,7 +78,10 @@ class HttpClient { this.disableToken = disableToken || false; this.initInterceptors(); - if (systemInfo === null && baseURL != 'https://space.langbot.app') { + if ( + systemInfo.cloud_service_url === '' && + baseURL != 'https://space.langbot.app' + ) { this.getSystemInfo().then((res) => { systemInfo = res; }); @@ -86,12 +93,6 @@ class HttpClient { return this.baseURL; } - // 获取Session - private async getSession() { - // NOT IMPLEMENT - return ''; - } - // 同步获取Session private getSessionSync() { // NOT IMPLEMENT @@ -505,4 +506,4 @@ const getBaseURL = (): string => { export const httpClient = new HttpClient(getBaseURL()); // 临时写法,未来两种Client都继承自HttpClient父类,不允许共享方法 -export const spaceClient = new HttpClient('https://space.langbot.app'); +export const spaceClient = new HttpClient(systemInfo.cloud_service_url);