2025-08-14 23:55:14 +08:00
|
|
|
|
import { BaseHttpClient } from './BaseHttpClient';
|
|
|
|
|
|
import {
|
|
|
|
|
|
ApiRespProviderRequesters,
|
|
|
|
|
|
ApiRespProviderRequester,
|
|
|
|
|
|
ApiRespProviderLLMModels,
|
|
|
|
|
|
ApiRespProviderLLMModel,
|
|
|
|
|
|
LLMModel,
|
|
|
|
|
|
ApiRespPipelines,
|
|
|
|
|
|
Pipeline,
|
|
|
|
|
|
ApiRespPlatformAdapters,
|
|
|
|
|
|
ApiRespPlatformAdapter,
|
|
|
|
|
|
ApiRespPlatformBots,
|
|
|
|
|
|
ApiRespPlatformBot,
|
|
|
|
|
|
Bot,
|
|
|
|
|
|
ApiRespPlugins,
|
|
|
|
|
|
ApiRespPlugin,
|
|
|
|
|
|
ApiRespPluginConfig,
|
|
|
|
|
|
AsyncTaskCreatedResp,
|
|
|
|
|
|
ApiRespSystemInfo,
|
|
|
|
|
|
ApiRespAsyncTasks,
|
|
|
|
|
|
ApiRespUserToken,
|
|
|
|
|
|
GetPipelineResponseData,
|
|
|
|
|
|
GetPipelineMetadataResponseData,
|
|
|
|
|
|
AsyncTask,
|
|
|
|
|
|
ApiRespWebChatMessage,
|
|
|
|
|
|
ApiRespWebChatMessages,
|
2025-08-24 21:40:02 +08:00
|
|
|
|
ApiRespKnowledgeBases,
|
|
|
|
|
|
ApiRespKnowledgeBase,
|
|
|
|
|
|
KnowledgeBase,
|
|
|
|
|
|
ApiRespKnowledgeBaseFiles,
|
|
|
|
|
|
ApiRespKnowledgeBaseRetrieve,
|
|
|
|
|
|
ApiRespProviderEmbeddingModels,
|
|
|
|
|
|
ApiRespProviderEmbeddingModel,
|
|
|
|
|
|
EmbeddingModel,
|
2025-09-22 22:49:22 +08:00
|
|
|
|
ApiRespPluginSystemStatus,
|
2025-08-06 21:57:43 +08:00
|
|
|
|
ApiRespMCPServers,
|
|
|
|
|
|
ApiRespMCPServer,
|
|
|
|
|
|
MCPServerConfig,
|
2025-08-14 23:55:14 +08:00
|
|
|
|
} from '@/app/infra/entities/api';
|
|
|
|
|
|
import { GetBotLogsRequest } from '@/app/infra/http/requestParam/bots/GetBotLogsRequest';
|
|
|
|
|
|
import { GetBotLogsResponse } from '@/app/infra/http/requestParam/bots/GetBotLogsResponse';
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 后端服务客户端
|
|
|
|
|
|
* 负责与后端 API 的所有交互
|
|
|
|
|
|
*/
|
|
|
|
|
|
export class BackendClient extends BaseHttpClient {
|
|
|
|
|
|
constructor(baseURL: string) {
|
|
|
|
|
|
super(baseURL, false);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ============ Provider API ============
|
2025-08-24 21:40:02 +08:00
|
|
|
|
public getProviderRequesters(
|
|
|
|
|
|
model_type: string,
|
|
|
|
|
|
): Promise<ApiRespProviderRequesters> {
|
|
|
|
|
|
return this.get('/api/v1/provider/requesters', { type: model_type });
|
2025-08-14 23:55:14 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public getProviderRequester(name: string): Promise<ApiRespProviderRequester> {
|
|
|
|
|
|
return this.get(`/api/v1/provider/requesters/${name}`);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public getProviderRequesterIconURL(name: string): string {
|
|
|
|
|
|
if (this.instance.defaults.baseURL === '/') {
|
|
|
|
|
|
// 获取用户访问的URL
|
|
|
|
|
|
const url = window.location.href;
|
|
|
|
|
|
const baseURL = url.split('/').slice(0, 3).join('/');
|
|
|
|
|
|
return `${baseURL}/api/v1/provider/requesters/${name}/icon`;
|
|
|
|
|
|
}
|
|
|
|
|
|
return (
|
|
|
|
|
|
this.instance.defaults.baseURL +
|
|
|
|
|
|
`/api/v1/provider/requesters/${name}/icon`
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ============ Provider Model LLM ============
|
|
|
|
|
|
public getProviderLLMModels(): Promise<ApiRespProviderLLMModels> {
|
|
|
|
|
|
return this.get('/api/v1/provider/models/llm');
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public getProviderLLMModel(uuid: string): Promise<ApiRespProviderLLMModel> {
|
|
|
|
|
|
return this.get(`/api/v1/provider/models/llm/${uuid}`);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public createProviderLLMModel(model: LLMModel): Promise<object> {
|
|
|
|
|
|
return this.post('/api/v1/provider/models/llm', model);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public deleteProviderLLMModel(uuid: string): Promise<object> {
|
|
|
|
|
|
return this.delete(`/api/v1/provider/models/llm/${uuid}`);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public updateProviderLLMModel(
|
|
|
|
|
|
uuid: string,
|
|
|
|
|
|
model: LLMModel,
|
|
|
|
|
|
): Promise<object> {
|
|
|
|
|
|
return this.put(`/api/v1/provider/models/llm/${uuid}`, model);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public testLLMModel(uuid: string, model: LLMModel): Promise<object> {
|
|
|
|
|
|
return this.post(`/api/v1/provider/models/llm/${uuid}/test`, model);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-08-24 21:40:02 +08:00
|
|
|
|
// ============ Provider Model Embedding ============
|
|
|
|
|
|
public getProviderEmbeddingModels(): Promise<ApiRespProviderEmbeddingModels> {
|
|
|
|
|
|
return this.get('/api/v1/provider/models/embedding');
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public getProviderEmbeddingModel(
|
|
|
|
|
|
uuid: string,
|
|
|
|
|
|
): Promise<ApiRespProviderEmbeddingModel> {
|
|
|
|
|
|
return this.get(`/api/v1/provider/models/embedding/${uuid}`);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public createProviderEmbeddingModel(model: EmbeddingModel): Promise<object> {
|
|
|
|
|
|
return this.post('/api/v1/provider/models/embedding', model);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public deleteProviderEmbeddingModel(uuid: string): Promise<object> {
|
|
|
|
|
|
return this.delete(`/api/v1/provider/models/embedding/${uuid}`);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public updateProviderEmbeddingModel(
|
|
|
|
|
|
uuid: string,
|
|
|
|
|
|
model: EmbeddingModel,
|
|
|
|
|
|
): Promise<object> {
|
|
|
|
|
|
return this.put(`/api/v1/provider/models/embedding/${uuid}`, model);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public testEmbeddingModel(
|
|
|
|
|
|
uuid: string,
|
|
|
|
|
|
model: EmbeddingModel,
|
|
|
|
|
|
): Promise<object> {
|
|
|
|
|
|
return this.post(`/api/v1/provider/models/embedding/${uuid}/test`, model);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-08-14 23:55:14 +08:00
|
|
|
|
// ============ Pipeline API ============
|
|
|
|
|
|
public getGeneralPipelineMetadata(): Promise<GetPipelineMetadataResponseData> {
|
|
|
|
|
|
// as designed, this method will be deprecated, and only for developer to check the prefered config schema
|
|
|
|
|
|
return this.get('/api/v1/pipelines/_/metadata');
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-08-24 21:46:20 +08:00
|
|
|
|
public getPipelines(
|
|
|
|
|
|
sortBy?: string,
|
|
|
|
|
|
sortOrder?: string,
|
|
|
|
|
|
): Promise<ApiRespPipelines> {
|
|
|
|
|
|
const params = new URLSearchParams();
|
|
|
|
|
|
if (sortBy) params.append('sort_by', sortBy);
|
|
|
|
|
|
if (sortOrder) params.append('sort_order', sortOrder);
|
|
|
|
|
|
const queryString = params.toString();
|
|
|
|
|
|
return this.get(`/api/v1/pipelines${queryString ? `?${queryString}` : ''}`);
|
2025-08-14 23:55:14 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public getPipeline(uuid: string): Promise<GetPipelineResponseData> {
|
|
|
|
|
|
return this.get(`/api/v1/pipelines/${uuid}`);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public createPipeline(pipeline: Pipeline): Promise<{
|
|
|
|
|
|
uuid: string;
|
|
|
|
|
|
}> {
|
|
|
|
|
|
return this.post('/api/v1/pipelines', pipeline);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public updatePipeline(uuid: string, pipeline: Pipeline): Promise<object> {
|
|
|
|
|
|
return this.put(`/api/v1/pipelines/${uuid}`, pipeline);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public deletePipeline(uuid: string): Promise<object> {
|
|
|
|
|
|
return this.delete(`/api/v1/pipelines/${uuid}`);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-08-24 21:40:02 +08:00
|
|
|
|
// ============ Debug WebChat API ============
|
|
|
|
|
|
|
2025-08-14 23:55:14 +08:00
|
|
|
|
// ============ Debug WebChat API ============
|
|
|
|
|
|
public sendWebChatMessage(
|
|
|
|
|
|
sessionType: string,
|
|
|
|
|
|
messageChain: object[],
|
|
|
|
|
|
pipelineId: string,
|
|
|
|
|
|
timeout: number = 15000,
|
|
|
|
|
|
): Promise<ApiRespWebChatMessage> {
|
|
|
|
|
|
return this.post(
|
|
|
|
|
|
`/api/v1/pipelines/${pipelineId}/chat/send`,
|
|
|
|
|
|
{
|
|
|
|
|
|
session_type: sessionType,
|
|
|
|
|
|
message: messageChain,
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
timeout,
|
|
|
|
|
|
},
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-08-24 21:40:02 +08:00
|
|
|
|
public async sendStreamingWebChatMessage(
|
|
|
|
|
|
sessionType: string,
|
|
|
|
|
|
messageChain: object[],
|
|
|
|
|
|
pipelineId: string,
|
|
|
|
|
|
onMessage: (data: ApiRespWebChatMessage) => void,
|
|
|
|
|
|
onComplete: () => void,
|
|
|
|
|
|
onError: (error: Error) => void,
|
|
|
|
|
|
): Promise<void> {
|
|
|
|
|
|
try {
|
|
|
|
|
|
// 构造完整的URL,处理相对路径的情况
|
|
|
|
|
|
let url = `${this.baseURL}/api/v1/pipelines/${pipelineId}/chat/send`;
|
|
|
|
|
|
if (this.baseURL === '/') {
|
|
|
|
|
|
// 获取用户访问的完整URL
|
|
|
|
|
|
const baseURL = window.location.origin;
|
|
|
|
|
|
url = `${baseURL}/api/v1/pipelines/${pipelineId}/chat/send`;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 使用fetch发送流式请求,因为axios在浏览器环境中不直接支持流式响应
|
|
|
|
|
|
const response = await fetch(url, {
|
|
|
|
|
|
method: 'POST',
|
|
|
|
|
|
headers: {
|
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
|
Authorization: `Bearer ${this.getSessionSync()}`,
|
|
|
|
|
|
},
|
|
|
|
|
|
body: JSON.stringify({
|
|
|
|
|
|
session_type: sessionType,
|
|
|
|
|
|
message: messageChain,
|
|
|
|
|
|
is_stream: true,
|
|
|
|
|
|
}),
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
if (!response.ok) {
|
|
|
|
|
|
throw new Error(`HTTP error! status: ${response.status}`);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!response.body) {
|
|
|
|
|
|
throw new Error('ReadableStream not supported');
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const reader = response.body.getReader();
|
|
|
|
|
|
const decoder = new TextDecoder();
|
|
|
|
|
|
let buffer = '';
|
|
|
|
|
|
|
|
|
|
|
|
// 读取流式响应
|
|
|
|
|
|
try {
|
|
|
|
|
|
while (true) {
|
|
|
|
|
|
const { done, value } = await reader.read();
|
|
|
|
|
|
|
|
|
|
|
|
if (done) {
|
|
|
|
|
|
onComplete();
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 解码数据
|
|
|
|
|
|
buffer += decoder.decode(value, { stream: true });
|
|
|
|
|
|
|
|
|
|
|
|
// 处理完整的JSON对象
|
|
|
|
|
|
const lines = buffer.split('\n\n');
|
|
|
|
|
|
buffer = lines.pop() || '';
|
|
|
|
|
|
|
|
|
|
|
|
for (const line of lines) {
|
|
|
|
|
|
if (line.startsWith('data:')) {
|
|
|
|
|
|
try {
|
|
|
|
|
|
const data = JSON.parse(line.slice(5));
|
|
|
|
|
|
|
|
|
|
|
|
if (data.type === 'end') {
|
|
|
|
|
|
// 流传输结束
|
|
|
|
|
|
reader.cancel();
|
|
|
|
|
|
onComplete();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (data.type === 'start') {
|
|
|
|
|
|
console.log(data.type);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (data.message) {
|
|
|
|
|
|
// 处理消息数据
|
|
|
|
|
|
onMessage(data);
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
console.error('Error parsing streaming data:', error);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
reader.releaseLock();
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
onError(error as Error);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-08-14 23:55:14 +08:00
|
|
|
|
public getWebChatHistoryMessages(
|
|
|
|
|
|
pipelineId: string,
|
|
|
|
|
|
sessionType: string,
|
|
|
|
|
|
): Promise<ApiRespWebChatMessages> {
|
|
|
|
|
|
return this.get(
|
|
|
|
|
|
`/api/v1/pipelines/${pipelineId}/chat/messages/${sessionType}`,
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public resetWebChatSession(
|
|
|
|
|
|
pipelineId: string,
|
|
|
|
|
|
sessionType: string,
|
|
|
|
|
|
): Promise<{ message: string }> {
|
|
|
|
|
|
return this.post(
|
|
|
|
|
|
`/api/v1/pipelines/${pipelineId}/chat/reset/${sessionType}`,
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ============ Platform API ============
|
|
|
|
|
|
public getAdapters(): Promise<ApiRespPlatformAdapters> {
|
|
|
|
|
|
return this.get('/api/v1/platform/adapters');
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public getAdapter(name: string): Promise<ApiRespPlatformAdapter> {
|
|
|
|
|
|
return this.get(`/api/v1/platform/adapters/${name}`);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public getAdapterIconURL(name: string): string {
|
|
|
|
|
|
if (this.instance.defaults.baseURL === '/') {
|
|
|
|
|
|
// 获取用户访问的URL
|
|
|
|
|
|
const url = window.location.href;
|
|
|
|
|
|
const baseURL = url.split('/').slice(0, 3).join('/');
|
|
|
|
|
|
return `${baseURL}/api/v1/platform/adapters/${name}/icon`;
|
|
|
|
|
|
}
|
|
|
|
|
|
return (
|
|
|
|
|
|
this.instance.defaults.baseURL + `/api/v1/platform/adapters/${name}/icon`
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ============ Platform Bots ============
|
|
|
|
|
|
public getBots(): Promise<ApiRespPlatformBots> {
|
|
|
|
|
|
return this.get('/api/v1/platform/bots');
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public getBot(uuid: string): Promise<ApiRespPlatformBot> {
|
|
|
|
|
|
return this.get(`/api/v1/platform/bots/${uuid}`);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public createBot(bot: Bot): Promise<{ uuid: string }> {
|
|
|
|
|
|
return this.post('/api/v1/platform/bots', bot);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public updateBot(uuid: string, bot: Bot): Promise<object> {
|
|
|
|
|
|
return this.put(`/api/v1/platform/bots/${uuid}`, bot);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public deleteBot(uuid: string): Promise<object> {
|
|
|
|
|
|
return this.delete(`/api/v1/platform/bots/${uuid}`);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public getBotLogs(
|
|
|
|
|
|
botId: string,
|
|
|
|
|
|
request: GetBotLogsRequest,
|
|
|
|
|
|
): Promise<GetBotLogsResponse> {
|
|
|
|
|
|
return this.post(`/api/v1/platform/bots/${botId}/logs`, request);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-08-24 21:40:02 +08:00
|
|
|
|
// ============ File management API ============
|
|
|
|
|
|
public uploadDocumentFile(file: File): Promise<{ file_id: string }> {
|
|
|
|
|
|
const formData = new FormData();
|
|
|
|
|
|
formData.append('file', file);
|
|
|
|
|
|
|
|
|
|
|
|
return this.request<{ file_id: string }>({
|
|
|
|
|
|
method: 'post',
|
|
|
|
|
|
url: '/api/v1/files/documents',
|
|
|
|
|
|
data: formData,
|
|
|
|
|
|
headers: {
|
|
|
|
|
|
'Content-Type': 'multipart/form-data',
|
|
|
|
|
|
},
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ============ Knowledge Base API ============
|
|
|
|
|
|
public getKnowledgeBases(): Promise<ApiRespKnowledgeBases> {
|
|
|
|
|
|
return this.get('/api/v1/knowledge/bases');
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public getKnowledgeBase(uuid: string): Promise<ApiRespKnowledgeBase> {
|
|
|
|
|
|
return this.get(`/api/v1/knowledge/bases/${uuid}`);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public createKnowledgeBase(base: KnowledgeBase): Promise<{ uuid: string }> {
|
|
|
|
|
|
return this.post('/api/v1/knowledge/bases', base);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public updateKnowledgeBase(
|
|
|
|
|
|
uuid: string,
|
|
|
|
|
|
base: KnowledgeBase,
|
|
|
|
|
|
): Promise<{ uuid: string }> {
|
|
|
|
|
|
return this.put(`/api/v1/knowledge/bases/${uuid}`, base);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public uploadKnowledgeBaseFile(
|
|
|
|
|
|
uuid: string,
|
|
|
|
|
|
file_id: string,
|
|
|
|
|
|
): Promise<object> {
|
|
|
|
|
|
return this.post(`/api/v1/knowledge/bases/${uuid}/files`, {
|
|
|
|
|
|
file_id,
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public getKnowledgeBaseFiles(
|
|
|
|
|
|
uuid: string,
|
|
|
|
|
|
): Promise<ApiRespKnowledgeBaseFiles> {
|
|
|
|
|
|
return this.get(`/api/v1/knowledge/bases/${uuid}/files`);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public deleteKnowledgeBaseFile(
|
|
|
|
|
|
uuid: string,
|
|
|
|
|
|
file_id: string,
|
|
|
|
|
|
): Promise<object> {
|
|
|
|
|
|
return this.delete(`/api/v1/knowledge/bases/${uuid}/files/${file_id}`);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public deleteKnowledgeBase(uuid: string): Promise<object> {
|
|
|
|
|
|
return this.delete(`/api/v1/knowledge/bases/${uuid}`);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public retrieveKnowledgeBase(
|
|
|
|
|
|
uuid: string,
|
|
|
|
|
|
query: string,
|
|
|
|
|
|
): Promise<ApiRespKnowledgeBaseRetrieve> {
|
|
|
|
|
|
return this.post(`/api/v1/knowledge/bases/${uuid}/retrieve`, { query });
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-08-14 23:55:14 +08:00
|
|
|
|
// ============ Plugins API ============
|
|
|
|
|
|
public getPlugins(): Promise<ApiRespPlugins> {
|
|
|
|
|
|
return this.get('/api/v1/plugins');
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public getPlugin(author: string, name: string): Promise<ApiRespPlugin> {
|
|
|
|
|
|
return this.get(`/api/v1/plugins/${author}/${name}`);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public getPluginConfig(
|
|
|
|
|
|
author: string,
|
|
|
|
|
|
name: string,
|
|
|
|
|
|
): Promise<ApiRespPluginConfig> {
|
|
|
|
|
|
return this.get(`/api/v1/plugins/${author}/${name}/config`);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public updatePluginConfig(
|
|
|
|
|
|
author: string,
|
|
|
|
|
|
name: string,
|
|
|
|
|
|
config: object,
|
|
|
|
|
|
): Promise<object> {
|
|
|
|
|
|
return this.put(`/api/v1/plugins/${author}/${name}/config`, config);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-08-28 23:50:26 +08:00
|
|
|
|
public getPluginIconURL(author: string, name: string): string {
|
|
|
|
|
|
if (this.instance.defaults.baseURL === '/') {
|
|
|
|
|
|
const url = window.location.href;
|
|
|
|
|
|
const baseURL = url.split('/').slice(0, 3).join('/');
|
|
|
|
|
|
return `${baseURL}/api/v1/plugins/${author}/${name}/icon`;
|
|
|
|
|
|
}
|
|
|
|
|
|
return (
|
|
|
|
|
|
this.instance.defaults.baseURL + `/api/v1/plugins/${author}/${name}/icon`
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-08-14 23:55:14 +08:00
|
|
|
|
public installPluginFromGithub(
|
|
|
|
|
|
source: string,
|
|
|
|
|
|
): Promise<AsyncTaskCreatedResp> {
|
|
|
|
|
|
return this.post('/api/v1/plugins/install/github', { source });
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-08-15 22:05:39 +08:00
|
|
|
|
public installPluginFromLocal(file: File): Promise<AsyncTaskCreatedResp> {
|
|
|
|
|
|
const formData = new FormData();
|
|
|
|
|
|
formData.append('file', file);
|
|
|
|
|
|
return this.postFile('/api/v1/plugins/install/local', formData);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-08-16 18:05:33 +08:00
|
|
|
|
public installPluginFromMarketplace(
|
|
|
|
|
|
author: string,
|
|
|
|
|
|
name: string,
|
|
|
|
|
|
version: string,
|
|
|
|
|
|
): Promise<AsyncTaskCreatedResp> {
|
|
|
|
|
|
return this.post('/api/v1/plugins/install/marketplace', {
|
|
|
|
|
|
plugin_author: author,
|
|
|
|
|
|
plugin_name: name,
|
|
|
|
|
|
plugin_version: version,
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-08-14 23:55:14 +08:00
|
|
|
|
public removePlugin(
|
|
|
|
|
|
author: string,
|
|
|
|
|
|
name: string,
|
|
|
|
|
|
): Promise<AsyncTaskCreatedResp> {
|
|
|
|
|
|
return this.delete(`/api/v1/plugins/${author}/${name}`);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-08-17 18:07:51 +08:00
|
|
|
|
public upgradePlugin(
|
|
|
|
|
|
author: string,
|
|
|
|
|
|
name: string,
|
|
|
|
|
|
): Promise<AsyncTaskCreatedResp> {
|
|
|
|
|
|
return this.post(`/api/v1/plugins/${author}/${name}/upgrade`);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-30 00:21:13 +08:00
|
|
|
|
// ============ MCP API ============
|
|
|
|
|
|
public getMCPServers(): Promise<ApiRespMCPServers> {
|
|
|
|
|
|
return this.get('/api/v1/mcp/servers');
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public getMCPServer(serverName: string): Promise<ApiRespMCPServer> {
|
|
|
|
|
|
return this.get(`/api/v1/mcp/servers/${serverName}`);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public createMCPServer(
|
|
|
|
|
|
server: MCPServerConfig,
|
|
|
|
|
|
): Promise<AsyncTaskCreatedResp> {
|
2025-10-22 13:37:53 +00:00
|
|
|
|
return this.post('/api/v1/mcp/servers', { source: server });
|
2025-09-30 00:21:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public updateMCPServer(
|
|
|
|
|
|
serverName: string,
|
|
|
|
|
|
server: Partial<MCPServerConfig>,
|
|
|
|
|
|
): Promise<AsyncTaskCreatedResp> {
|
|
|
|
|
|
return this.put(`/api/v1/mcp/servers/${serverName}`, server);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public deleteMCPServer(serverName: string): Promise<AsyncTaskCreatedResp> {
|
|
|
|
|
|
return this.delete(`/api/v1/mcp/servers/${serverName}`);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public toggleMCPServer(
|
|
|
|
|
|
serverName: string,
|
|
|
|
|
|
target_enabled: boolean,
|
|
|
|
|
|
): Promise<AsyncTaskCreatedResp> {
|
|
|
|
|
|
return this.put(`/api/v1/mcp/servers/${serverName}/toggle`, {
|
|
|
|
|
|
target_enabled,
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public testMCPServer(serverName: string): Promise<AsyncTaskCreatedResp> {
|
|
|
|
|
|
return this.post(`/api/v1/mcp/servers/${serverName}/test`);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// public getMCPMarketServers(
|
|
|
|
|
|
// page: number,
|
|
|
|
|
|
// page_size: number,
|
|
|
|
|
|
// query: string,
|
|
|
|
|
|
// sort_by: string = 'stars',
|
|
|
|
|
|
// sort_order: string = 'DESC',
|
|
|
|
|
|
// ): Promise<MCPMarketResponse> {
|
|
|
|
|
|
// return this.post(`/api/v1/market/mcp`, {
|
|
|
|
|
|
// page,
|
|
|
|
|
|
// page_size,
|
|
|
|
|
|
// query,
|
|
|
|
|
|
// sort_by,
|
|
|
|
|
|
// sort_order,
|
|
|
|
|
|
// });
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
public installMCPServerFromGithub(
|
|
|
|
|
|
source: string,
|
|
|
|
|
|
): Promise<AsyncTaskCreatedResp> {
|
|
|
|
|
|
return this.post('/api/v1/mcp/install/github', { source });
|
|
|
|
|
|
}
|
2025-08-06 21:57:43 +08:00
|
|
|
|
|
2025-10-13 12:51:58 +00:00
|
|
|
|
public installMCPServerFromSSE(
|
|
|
|
|
|
source: {},
|
|
|
|
|
|
): Promise<AsyncTaskCreatedResp> {
|
2025-10-21 16:18:03 +08:00
|
|
|
|
return this.post('/api/v1/mcp/servers', { source });
|
2025-10-13 12:51:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-08-14 23:55:14 +08:00
|
|
|
|
// ============ System API ============
|
|
|
|
|
|
public getSystemInfo(): Promise<ApiRespSystemInfo> {
|
|
|
|
|
|
return this.get('/api/v1/system/info');
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public getAsyncTasks(): Promise<ApiRespAsyncTasks> {
|
|
|
|
|
|
return this.get('/api/v1/system/tasks');
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public getAsyncTask(id: number): Promise<AsyncTask> {
|
|
|
|
|
|
return this.get(`/api/v1/system/tasks/${id}`);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-22 22:49:22 +08:00
|
|
|
|
public getPluginSystemStatus(): Promise<ApiRespPluginSystemStatus> {
|
|
|
|
|
|
return this.get('/api/v1/system/status/plugin-system');
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-08-14 23:55:14 +08:00
|
|
|
|
// ============ User API ============
|
|
|
|
|
|
public checkIfInited(): Promise<{ initialized: boolean }> {
|
|
|
|
|
|
return this.get('/api/v1/user/init');
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public initUser(user: string, password: string): Promise<object> {
|
|
|
|
|
|
return this.post('/api/v1/user/init', { user, password });
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public authUser(user: string, password: string): Promise<ApiRespUserToken> {
|
|
|
|
|
|
return this.post('/api/v1/user/auth', { user, password });
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public checkUserToken(): Promise<ApiRespUserToken> {
|
|
|
|
|
|
return this.get('/api/v1/user/check-token');
|
|
|
|
|
|
}
|
2025-08-24 21:40:02 +08:00
|
|
|
|
|
|
|
|
|
|
public resetPassword(
|
|
|
|
|
|
user: string,
|
|
|
|
|
|
recoveryKey: string,
|
|
|
|
|
|
newPassword: string,
|
|
|
|
|
|
): Promise<{ user: string }> {
|
|
|
|
|
|
return this.post('/api/v1/user/reset-password', {
|
|
|
|
|
|
user,
|
|
|
|
|
|
recovery_key: recoveryKey,
|
|
|
|
|
|
new_password: newPassword,
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public changePassword(
|
|
|
|
|
|
currentPassword: string,
|
|
|
|
|
|
newPassword: string,
|
|
|
|
|
|
): Promise<{ user: string }> {
|
|
|
|
|
|
return this.post('/api/v1/user/change-password', {
|
|
|
|
|
|
current_password: currentPassword,
|
|
|
|
|
|
new_password: newPassword,
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
2025-08-14 23:55:14 +08:00
|
|
|
|
}
|