mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-06-02 03:55:55 +00:00
feat(webui): user, system, plugins api client
This commit is contained in:
@@ -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;
|
||||
}
|
||||
@@ -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<ApiResponse<ApiRespPlugins>> {
|
||||
return this.get('/api/v1/plugins')
|
||||
}
|
||||
|
||||
public getPlugin(author: string, name: string): Promise<ApiResponse<ApiRespPlugin>> {
|
||||
return this.get(`/api/v1/plugins/${author}/${name}`)
|
||||
}
|
||||
|
||||
public getPluginConfig(author: string, name: string): Promise<ApiResponse<ApiRespPluginConfig>> {
|
||||
return this.get(`/api/v1/plugins/${author}/${name}/config`)
|
||||
}
|
||||
|
||||
public updatePluginConfig(author: string, name: string, config: object): Promise<ApiResponse<object>> {
|
||||
return this.put(`/api/v1/plugins/${author}/${name}/config`, config)
|
||||
}
|
||||
|
||||
public togglePlugin(author: string, name: string, target_enabled: boolean): Promise<ApiResponse<object>> {
|
||||
return this.post(`/api/v1/plugins/${author}/${name}/toggle`, { target_enabled })
|
||||
}
|
||||
|
||||
public reorderPlugins(plugins: PluginReorderElement[]): Promise<ApiResponse<object>> {
|
||||
return this.post('/api/v1/plugins/reorder', plugins)
|
||||
}
|
||||
|
||||
public updatePlugin(author: string, name: string): Promise<ApiResponse<AsyncTaskCreatedResp>> {
|
||||
return this.post(`/api/v1/plugins/${author}/${name}/update`)
|
||||
}
|
||||
|
||||
public installPluginFromGithub(source: string): Promise<ApiResponse<AsyncTaskCreatedResp>> {
|
||||
return this.post('/api/v1/plugins/install/github', { source })
|
||||
}
|
||||
|
||||
public removePlugin(author: string, name: string): Promise<ApiResponse<AsyncTaskCreatedResp>> {
|
||||
return this.delete(`/api/v1/plugins/${author}/${name}`)
|
||||
}
|
||||
|
||||
// ============ System API ============
|
||||
public getSystemInfo(): Promise<ApiResponse<ApiRespSystemInfo>> {
|
||||
return this.get('/api/v1/system/info')
|
||||
}
|
||||
|
||||
public getAsyncTasks(): Promise<ApiResponse<ApiRespAsyncTasks>> {
|
||||
return this.get('/api/v1/system/tasks')
|
||||
}
|
||||
|
||||
public getAsyncTask(id: number): Promise<ApiResponse<ApiRespAsyncTask>> {
|
||||
return this.get(`/api/v1/system/tasks/${id}`)
|
||||
}
|
||||
|
||||
// ============ User API ============
|
||||
public checkIfInited(): Promise<ApiResponse<object>> {
|
||||
return this.get('/api/v1/user/init')
|
||||
}
|
||||
|
||||
public initUser(user: string, password: string): Promise<ApiResponse<object>> {
|
||||
return this.post('/api/v1/user/init', { user, password })
|
||||
}
|
||||
|
||||
public authUser(user: string, password: string): Promise<ApiResponse<ApiRespUserToken>> {
|
||||
return this.post('/api/v1/user/auth', { user, password })
|
||||
}
|
||||
|
||||
public checkUserToken(): Promise<ApiResponse<ApiRespUserToken>> {
|
||||
return this.get('/api/v1/user/check-token')
|
||||
}
|
||||
}
|
||||
|
||||
export const httpClient = new HttpClient()
|
||||
|
||||
Reference in New Issue
Block a user