diff --git a/web_ui/src/app/home/bots/page.tsx b/web_ui/src/app/home/bots/page.tsx index 4ac6ca5b..4e7a8c5c 100644 --- a/web_ui/src/app/home/bots/page.tsx +++ b/web_ui/src/app/home/bots/page.tsx @@ -9,6 +9,7 @@ import {Modal} from "antd"; import BotForm from "@/app/home/bots/components/bot-form/BotForm"; import BotCard from "@/app/home/bots/components/bot-card/BotCard"; import CreateCardComponent from "@/app/infra/basic-component/create-card-component/CreateCardComponent" +import {httpClient} from "@/app/infra/http/HttpClient"; export default function BotConfigPage() { @@ -23,13 +24,17 @@ export default function BotConfigPage() { // TODO:补齐加载转圈逻辑 checkHasLLM().then((hasLLM) => { if (hasLLM) { - const botList = getBotList() - if (botList.length === 0) { - setPageShowRule(BotConfigPageShowRule.NO_BOT) - } else { + getBotList().then((botList) => { + if (botList.length === 0) { + setPageShowRule(BotConfigPageShowRule.NO_BOT) + } else { setPageShowRule(BotConfigPageShowRule.HAVE_BOT) - } - setBotList(botList) + } + setBotList(botList) + }).catch((err) => { + // TODO error toast + console.error("get bot list error (useEffect)", err) + }) } else { setPageShowRule(BotConfigPageShowRule.NO_LLM) } @@ -41,27 +46,28 @@ export default function BotConfigPage() { return true } - function getBotList(): BotCardVO[] { - let botList: BotCardVO[] = [ - new BotCardVO({ - adapter: "QQ bot", - description: "1111", - id: "1111", - name: "第一个bot", - updateTime: "202300001111", - pipelineName: "默认流水线", - }), - new BotCardVO({ - adapter: "WX bot", - description: "22211", - id: "2222", - name: "第2个bot", - updateTime: "2025011011", - pipelineName: "默认流水线", - }), - ] - // botList = [] - return botList + function getBotList(): Promise { + + return new Promise((resolve) => { + httpClient.getBots().then((resp) => { + console.log("get bot list (getBotList)", resp) + const botList: BotCardVO[] = resp.bots.map((bot: any) => { + return new BotCardVO({ + adapter: bot.adapter, + description: bot.description, + id: bot.id, + name: bot.name, + updateTime: bot.update_time, + pipelineName: bot.pipeline_name, + }) + }) + resolve(botList) + }).catch((err) => { + // TODO error toast + console.error("get bot list error", err) + resolve([]) + }) + }) } function handleCreateBotClick() { diff --git a/web_ui/src/app/infra/http/HttpClient.ts b/web_ui/src/app/infra/http/HttpClient.ts index af0cdb35..f02bbff2 100644 --- a/web_ui/src/app/infra/http/HttpClient.ts +++ b/web_ui/src/app/infra/http/HttpClient.ts @@ -43,6 +43,7 @@ class HttpClient { // 兜底URL,如果使用未配置会走到这里 private getBaseUrl(): string { + return "http://localhost:5300" // NOT IMPLEMENT if (typeof window === 'undefined') { // 服务端环境 @@ -61,7 +62,7 @@ class HttpClient { // 同步获取Session private getSessionSync() { // NOT IMPLEMENT - return "" + return "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjoicm9ja2NoaW5xQGdtYWlsLmNvbSIsImlzcyI6IkxhbmdCb3QtY29tbXVuaXR5IiwiZXhwIjoyMzUwNDk1NTQ3fQ.d6r0lNGud1OecOLMM-ADDDwiABmek3hkMIFH7ZBkaX4" } // 拦截器配置 @@ -71,8 +72,9 @@ class HttpClient { async (config) => { // 服务端请求自动携带 cookie, Langbot暂时用不到SSR相关 // if (typeof window === 'undefined' && config.isSSR) { } - const { cookies } = await import('next/headers') - config.headers.Cookie = cookies().toString() + // cookie not required + // const { cookies } = await import('next/headers') + // config.headers.Cookie = cookies().toString() // 客户端添加认证头 if (typeof window !== 'undefined') { @@ -182,11 +184,11 @@ class HttpClient { // real api request implementation // ============ Provider API ============ - public getProviderRequesters(): Promise> { + public getProviderRequesters(): Promise { return this.get('/api/v1/provider/requesters') } - public getProviderRequester(name: string): Promise> { + public getProviderRequester(name: string): Promise { return this.get(`/api/v1/provider/requesters/${name}`) } @@ -195,53 +197,53 @@ class HttpClient { } // ============ Provider Model LLM ============ - public getProviderLLMModels(): Promise> { + public getProviderLLMModels(): Promise { return this.get('/api/v1/provider/models/llm') } - public getProviderLLMModel(uuid: string): Promise> { + public getProviderLLMModel(uuid: string): Promise { return this.get(`/api/v1/provider/models/llm/${uuid}`) } - public createProviderLLMModel(model: LLMModel): Promise> { + public createProviderLLMModel(model: LLMModel): Promise { return this.post('/api/v1/provider/models/llm', model) } - public deleteProviderLLMModel(uuid: string): Promise> { + public deleteProviderLLMModel(uuid: string): Promise { return this.delete(`/api/v1/provider/models/llm/${uuid}`) } // ============ Pipeline API ============ - public getGeneralPipelineMetadata(): Promise> { // as designed, this method will be deprecated, and only for developer to check the prefered config schema + public getGeneralPipelineMetadata(): Promise { // as designed, this method will be deprecated, and only for developer to check the prefered config schema return this.get('/api/v1/pipelines/_/metadata') } - public getPipelines(): Promise> { + public getPipelines(): Promise { return this.get('/api/v1/pipelines') } - public getPipeline(uuid: string): Promise> { + public getPipeline(uuid: string): Promise { return this.get(`/api/v1/pipelines/${uuid}`) } - public createPipeline(pipeline: Pipeline): Promise> { + public createPipeline(pipeline: Pipeline): Promise { return this.post('/api/v1/pipelines', pipeline) } - public updatePipeline(uuid: string, pipeline: Pipeline): Promise> { + public updatePipeline(uuid: string, pipeline: Pipeline): Promise { return this.put(`/api/v1/pipelines/${uuid}`, pipeline) } - public deletePipeline(uuid: string): Promise> { + public deletePipeline(uuid: string): Promise { return this.delete(`/api/v1/pipelines/${uuid}`) } // ============ Platform API ============ - public getAdapters(): Promise> { + public getAdapters(): Promise { return this.get('/api/v1/platform/adapters') } - public getAdapter(name: string): Promise> { + public getAdapter(name: string): Promise { return this.get(`/api/v1/platform/adapters/${name}`) } @@ -250,90 +252,90 @@ class HttpClient { } // ============ Platform Bots ============ - public getBots(): Promise> { + public getBots(): Promise { return this.get('/api/v1/platform/bots') } - public getBot(uuid: string): Promise> { + public getBot(uuid: string): Promise { return this.get(`/api/v1/platform/bots/${uuid}`) } - public createBot(bot: Bot): Promise> { + public createBot(bot: Bot): Promise { return this.post('/api/v1/platform/bots', bot) } - public updateBot(uuid: string, bot: Bot): Promise> { + public updateBot(uuid: string, bot: Bot): Promise { return this.put(`/api/v1/platform/bots/${uuid}`, bot) } - public deleteBot(uuid: string): Promise> { + public deleteBot(uuid: string): Promise { return this.delete(`/api/v1/platform/bots/${uuid}`) } // ============ Plugins API ============ - public getPlugins(): Promise> { + public getPlugins(): Promise { return this.get('/api/v1/plugins') } - public getPlugin(author: string, name: string): Promise> { + public getPlugin(author: string, name: string): Promise { return this.get(`/api/v1/plugins/${author}/${name}`) } - public getPluginConfig(author: string, name: string): Promise> { + 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> { + 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> { + 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> { + public reorderPlugins(plugins: PluginReorderElement[]): Promise { return this.post('/api/v1/plugins/reorder', plugins) } - public updatePlugin(author: string, name: string): Promise> { + public updatePlugin(author: string, name: string): Promise { return this.post(`/api/v1/plugins/${author}/${name}/update`) } - public installPluginFromGithub(source: string): Promise> { + public installPluginFromGithub(source: string): Promise { return this.post('/api/v1/plugins/install/github', { source }) } - public removePlugin(author: string, name: string): Promise> { + public removePlugin(author: string, name: string): Promise { return this.delete(`/api/v1/plugins/${author}/${name}`) } // ============ System API ============ - public getSystemInfo(): Promise> { + public getSystemInfo(): Promise { return this.get('/api/v1/system/info') } - public getAsyncTasks(): Promise> { + public getAsyncTasks(): Promise { return this.get('/api/v1/system/tasks') } - public getAsyncTask(id: number): Promise> { + public getAsyncTask(id: number): Promise { return this.get(`/api/v1/system/tasks/${id}`) } // ============ User API ============ - public checkIfInited(): Promise> { + public checkIfInited(): Promise { return this.get('/api/v1/user/init') } - public initUser(user: string, password: string): Promise> { + public initUser(user: string, password: string): Promise { return this.post('/api/v1/user/init', { user, password }) } - public authUser(user: string, password: string): Promise> { + public authUser(user: string, password: string): Promise { return this.post('/api/v1/user/auth', { user, password }) } - public checkUserToken(): Promise> { + public checkUserToken(): Promise { return this.get('/api/v1/user/check-token') } }