diff --git a/web_ui/src/app/home/bots/components/bot-card/BotCard.tsx b/web_ui/src/app/home/bots/components/bot-card/BotCard.tsx index 29dd54f0..92d2449a 100644 --- a/web_ui/src/app/home/bots/components/bot-card/BotCard.tsx +++ b/web_ui/src/app/home/bots/components/bot-card/BotCard.tsx @@ -31,9 +31,9 @@ export default function BotCard({
描述:{botCardVO.description}
-
+ {/*
更新时间:{botCardVO.updateTime} -
+
*/} ) } \ No newline at end of file diff --git a/web_ui/src/app/home/bots/components/bot-form/BotForm.tsx b/web_ui/src/app/home/bots/components/bot-form/BotForm.tsx index 4eb6918e..b3fa4999 100644 --- a/web_ui/src/app/home/bots/components/bot-form/BotForm.tsx +++ b/web_ui/src/app/home/bots/components/bot-form/BotForm.tsx @@ -11,6 +11,7 @@ import {UUID} from 'uuidjs' import DynamicFormComponent from "@/app/home/components/dynamic-form/DynamicFormComponent"; import {ICreateLLMField} from "@/app/home/models/ICreateLLMField"; import {httpClient} from "@/app/infra/http/HttpClient"; +import { Bot } from "@/app/infra/api/api-types"; export default function BotForm({ initBotId, @@ -69,6 +70,7 @@ export default function BotForm({ if (initBotId) { getBotFieldById(initBotId).then(val => { form.setFieldsValue(val) + // TODO 这里有个bug,adapter config 并没有被设置到表单中,表单一直都只显示默认值 handleAdapterSelect(val.adapter) }) } else { @@ -86,22 +88,20 @@ export default function BotForm({ } async function getBotFieldById(botId: string): Promise { - return new BotFormEntity({ - adapter: "telegram", - description: "模拟拉取bot", - name: "模拟电报bot", - adapter_config: { - token: "aaabbbccc" - }, + const bot = (await httpClient.getBot(botId)).bot + let botFormEntity = new BotFormEntity({ + adapter: bot.adapter, + description: bot.description, + name: bot.name, + adapter_config: bot.adapter_config }) + return botFormEntity } function handleAdapterSelect(adapterName: string) { if (adapterName) { - console.log(adapterNameToDynamicConfigMap) const dynamicFormConfigList = adapterNameToDynamicConfigMap.get(adapterName) if (dynamicFormConfigList) { - console.log(dynamicFormConfigList) setDynamicFormConfigList(dynamicFormConfigList) } setShowDynamicForm(true) @@ -123,19 +123,47 @@ export default function BotForm({ if (initBotId) { // 编辑提交 console.log('submit edit', form.getFieldsValue() ,value) + let updateBot: Bot = { + uuid: initBotId, + name: form.getFieldsValue().name, + description: form.getFieldsValue().description, + adapter: form.getFieldsValue().adapter, + adapter_config: value + } + httpClient.updateBot(initBotId, updateBot).then(res => { + // TODO success toast + console.log("update bot success", res) + }).catch(err => { + // TODO error toast + console.log("update bot error", err) + }) } else { // 创建提交 console.log('submit create', form.getFieldsValue() ,value) + let newBot: Bot = { + name: form.getFieldsValue().name, + description: form.getFieldsValue().description, + adapter: form.getFieldsValue().adapter, + adapter_config: value + } + httpClient.createBot(newBot).then(res => { + // TODO success toast + console.log(res) + }).catch(err => { + // TODO error toast + console.log(err) + }) } onFormSubmit(form.getFieldsValue()) setShowDynamicForm(false) form.resetFields() dynamicForm.resetFields() - + // TODO 刷新bot列表 + // TODO 关闭当前弹窗 } function handleSaveButton() { - + form.submit() } return ( diff --git a/web_ui/src/app/home/bots/page.tsx b/web_ui/src/app/home/bots/page.tsx index 4e7a8c5c..1cb64f0f 100644 --- a/web_ui/src/app/home/bots/page.tsx +++ b/web_ui/src/app/home/bots/page.tsx @@ -10,7 +10,7 @@ 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"; - +import { Bot } from "@/app/infra/api/api-types"; export default function BotConfigPage() { const router = useRouter(); @@ -50,15 +50,14 @@ export default function BotConfigPage() { return new Promise((resolve) => { httpClient.getBots().then((resp) => { - console.log("get bot list (getBotList)", resp) - const botList: BotCardVO[] = resp.bots.map((bot: any) => { + const botList: BotCardVO[] = resp.bots.map((bot: Bot) => { return new BotCardVO({ adapter: bot.adapter, description: bot.description, - id: bot.id, + id: bot.uuid || "", name: bot.name, - updateTime: bot.update_time, - pipelineName: bot.pipeline_name, + updateTime: bot.updated_at || "", + pipelineName: bot.use_pipeline_name || "", }) }) resolve(botList) 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 35d91057..a68c022f 100644 --- a/web_ui/src/app/infra/api/api-types/index.ts +++ b/web_ui/src/app/infra/api/api-types/index.ts @@ -94,16 +94,16 @@ export interface ApiRespPlatformBot { } export interface Bot { - uuid: string; + uuid?: string; name: string; description: string; - enable: boolean; + enable?: boolean; adapter: string; adapter_config: object; - use_pipeline_name: string; - use_pipeline_uuid: string; - created_at: string; - updated_at: string; + use_pipeline_name?: string; + use_pipeline_uuid?: string; + created_at?: string; + updated_at?: string; } // plugins