From 2d64447c08f0354565412a9084ae2f0013ac8525 Mon Sep 17 00:00:00 2001 From: Junyan Qin Date: Thu, 24 Apr 2025 22:42:31 +0800 Subject: [PATCH] feat(webui): user, system, plugins api client --- web_ui/src/app/infra/api/api-types/index.ts | 79 +++++++++++++++++++++ web_ui/src/app/infra/http/HttpClient.ts | 69 +++++++++++++++++- 2 files changed, 147 insertions(+), 1 deletion(-) diff --git a/web_ui/src/app/infra/api/api-types/index.ts b/web_ui/src/app/infra/api/api-types/index.ts index d5615c9f..35d91057 100644 --- a/web_ui/src/app/infra/api/api-types/index.ts +++ b/web_ui/src/app/infra/api/api-types/index.ts @@ -9,6 +9,10 @@ export interface I18nText { zh_CN: string; } +export interface AsyncTaskCreatedResp { + task_id: number; +} + export interface ApiRespProviderRequesters { requesters: Requester[]; } @@ -100,4 +104,79 @@ export interface Bot { use_pipeline_uuid: string; created_at: string; updated_at: string; +} + +// plugins +export interface ApiRespPlugins { + plugins: Plugin[]; +} + +export interface ApiRespPlugin { + plugin: Plugin; +} + +export interface Plugin { + author: string; + name: string; + description: I18nText; + label: I18nText; + version: string; + enabled: boolean; + priority: number; + status: string; + tools: object[]; + event_handlers: object; + main_file: string; + pkg_path: string; + repository: string; + config_schema: object; +} + +export interface ApiRespPluginConfig { + config: object; +} + +export interface PluginReorderElement { + author: string; + name: string; + priority: number; +} + +// system +export interface ApiRespSystemInfo { + debug: boolean; + version: string; +} + +export interface ApiRespAsyncTasks { + tasks: AsyncTask[]; +} + +export interface ApiRespAsyncTask { + task: AsyncTask; +} + +export interface AsyncTaskRuntimeInfo { + done: boolean; + exception?: string; + result?: object; + state: string; +} + +export interface AsyncTaskTaskContext { + current_action: string; + log: string; +} + +export interface AsyncTask { + id: number; + kind: string; + name: string; + task_type: string; // system or user + runtime: AsyncTaskRuntimeInfo; + task_context: AsyncTaskTaskContext; +} + +export interface ApiRespUserToken { + token: string; } \ No newline at end of file diff --git a/web_ui/src/app/infra/http/HttpClient.ts b/web_ui/src/app/infra/http/HttpClient.ts index 8618f973..af0cdb35 100644 --- a/web_ui/src/app/infra/http/HttpClient.ts +++ b/web_ui/src/app/infra/http/HttpClient.ts @@ -2,7 +2,9 @@ import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse, AxiosError } f import { ApiResponse, ApiRespProviderRequesters, ApiRespProviderRequester, ApiRespProviderLLMModels, ApiRespProviderLLMModel, LLMModel, ApiRespPipelines, ApiRespPipeline, Pipeline, ApiRespPlatformAdapters, - ApiRespPlatformAdapter, ApiRespPlatformBots, ApiRespPlatformBot, Bot + ApiRespPlatformAdapter, ApiRespPlatformBots, ApiRespPlatformBot, Bot, ApiRespPlugins, ApiRespPlugin, Plugin, + ApiRespPluginConfig, PluginReorderElement, AsyncTaskCreatedResp, ApiRespSystemInfo, ApiRespAsyncTasks, AsyncTask, + ApiRespAsyncTask, ApiRespUserToken } from '../api/api-types' type JSONValue = string | number | boolean | JSONObject | JSONArray | null @@ -269,6 +271,71 @@ class HttpClient { } // ============ Plugins API ============ + public getPlugins(): Promise> { + return this.get('/api/v1/plugins') + } + + public getPlugin(author: string, name: string): Promise> { + return this.get(`/api/v1/plugins/${author}/${name}`) + } + + public getPluginConfig(author: string, name: string): Promise> { + return this.get(`/api/v1/plugins/${author}/${name}/config`) + } + + public updatePluginConfig(author: string, name: string, config: object): Promise> { + return this.put(`/api/v1/plugins/${author}/${name}/config`, config) + } + + public togglePlugin(author: string, name: string, target_enabled: boolean): Promise> { + return this.post(`/api/v1/plugins/${author}/${name}/toggle`, { target_enabled }) + } + + public reorderPlugins(plugins: PluginReorderElement[]): Promise> { + return this.post('/api/v1/plugins/reorder', plugins) + } + + public updatePlugin(author: string, name: string): Promise> { + return this.post(`/api/v1/plugins/${author}/${name}/update`) + } + + public installPluginFromGithub(source: string): Promise> { + return this.post('/api/v1/plugins/install/github', { source }) + } + + public removePlugin(author: string, name: string): Promise> { + return this.delete(`/api/v1/plugins/${author}/${name}`) + } + + // ============ System API ============ + public getSystemInfo(): Promise> { + return this.get('/api/v1/system/info') + } + + public getAsyncTasks(): Promise> { + return this.get('/api/v1/system/tasks') + } + + public getAsyncTask(id: number): Promise> { + return this.get(`/api/v1/system/tasks/${id}`) + } + + // ============ User API ============ + public checkIfInited(): Promise> { + return this.get('/api/v1/user/init') + } + + public initUser(user: string, password: string): Promise> { + return this.post('/api/v1/user/init', { user, password }) + } + + public authUser(user: string, password: string): Promise> { + return this.post('/api/v1/user/auth', { user, password }) + } + + public checkUserToken(): Promise> { + return this.get('/api/v1/user/check-token') + } } export const httpClient = new HttpClient()