feat(bots): crud api request

This commit is contained in:
Junyan Qin
2025-04-27 10:55:03 +08:00
parent ca183d2eb7
commit 9c6f2ce088
4 changed files with 52 additions and 25 deletions
@@ -31,9 +31,9 @@ export default function BotCard({
<div className={`${styles.urlAndUpdateText}`}> <div className={`${styles.urlAndUpdateText}`}>
{botCardVO.description} {botCardVO.description}
</div> </div>
<div className={`${styles.urlAndUpdateText}`}> {/* <div className={`${styles.urlAndUpdateText}`}>
更新时间:{botCardVO.updateTime} 更新时间:{botCardVO.updateTime}
</div> </div> */}
</div> </div>
) )
} }
@@ -11,6 +11,7 @@ import {UUID} from 'uuidjs'
import DynamicFormComponent from "@/app/home/components/dynamic-form/DynamicFormComponent"; import DynamicFormComponent from "@/app/home/components/dynamic-form/DynamicFormComponent";
import {ICreateLLMField} from "@/app/home/models/ICreateLLMField"; import {ICreateLLMField} from "@/app/home/models/ICreateLLMField";
import {httpClient} from "@/app/infra/http/HttpClient"; import {httpClient} from "@/app/infra/http/HttpClient";
import { Bot } from "@/app/infra/api/api-types";
export default function BotForm({ export default function BotForm({
initBotId, initBotId,
@@ -69,6 +70,7 @@ export default function BotForm({
if (initBotId) { if (initBotId) {
getBotFieldById(initBotId).then(val => { getBotFieldById(initBotId).then(val => {
form.setFieldsValue(val) form.setFieldsValue(val)
// TODO 这里有个bugadapter config 并没有被设置到表单中,表单一直都只显示默认值
handleAdapterSelect(val.adapter) handleAdapterSelect(val.adapter)
}) })
} else { } else {
@@ -86,22 +88,20 @@ export default function BotForm({
} }
async function getBotFieldById(botId: string): Promise<IBotFormEntity> { async function getBotFieldById(botId: string): Promise<IBotFormEntity> {
return new BotFormEntity({ const bot = (await httpClient.getBot(botId)).bot
adapter: "telegram", let botFormEntity = new BotFormEntity({
description: "模拟拉取bot", adapter: bot.adapter,
name: "模拟电报bot", description: bot.description,
adapter_config: { name: bot.name,
token: "aaabbbccc" adapter_config: bot.adapter_config
},
}) })
return botFormEntity
} }
function handleAdapterSelect(adapterName: string) { function handleAdapterSelect(adapterName: string) {
if (adapterName) { if (adapterName) {
console.log(adapterNameToDynamicConfigMap)
const dynamicFormConfigList = adapterNameToDynamicConfigMap.get(adapterName) const dynamicFormConfigList = adapterNameToDynamicConfigMap.get(adapterName)
if (dynamicFormConfigList) { if (dynamicFormConfigList) {
console.log(dynamicFormConfigList)
setDynamicFormConfigList(dynamicFormConfigList) setDynamicFormConfigList(dynamicFormConfigList)
} }
setShowDynamicForm(true) setShowDynamicForm(true)
@@ -123,19 +123,47 @@ export default function BotForm({
if (initBotId) { if (initBotId) {
// 编辑提交 // 编辑提交
console.log('submit edit', form.getFieldsValue() ,value) 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 { } else {
// 创建提交 // 创建提交
console.log('submit create', form.getFieldsValue() ,value) 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()) onFormSubmit(form.getFieldsValue())
setShowDynamicForm(false) setShowDynamicForm(false)
form.resetFields() form.resetFields()
dynamicForm.resetFields() dynamicForm.resetFields()
// TODO 刷新bot列表
// TODO 关闭当前弹窗
} }
function handleSaveButton() { function handleSaveButton() {
form.submit()
} }
return ( return (
+5 -6
View File
@@ -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 BotCard from "@/app/home/bots/components/bot-card/BotCard";
import CreateCardComponent from "@/app/infra/basic-component/create-card-component/CreateCardComponent" import CreateCardComponent from "@/app/infra/basic-component/create-card-component/CreateCardComponent"
import {httpClient} from "@/app/infra/http/HttpClient"; import {httpClient} from "@/app/infra/http/HttpClient";
import { Bot } from "@/app/infra/api/api-types";
export default function BotConfigPage() { export default function BotConfigPage() {
const router = useRouter(); const router = useRouter();
@@ -50,15 +50,14 @@ export default function BotConfigPage() {
return new Promise((resolve) => { return new Promise((resolve) => {
httpClient.getBots().then((resp) => { httpClient.getBots().then((resp) => {
console.log("get bot list (getBotList)", resp) const botList: BotCardVO[] = resp.bots.map((bot: Bot) => {
const botList: BotCardVO[] = resp.bots.map((bot: any) => {
return new BotCardVO({ return new BotCardVO({
adapter: bot.adapter, adapter: bot.adapter,
description: bot.description, description: bot.description,
id: bot.id, id: bot.uuid || "",
name: bot.name, name: bot.name,
updateTime: bot.update_time, updateTime: bot.updated_at || "",
pipelineName: bot.pipeline_name, pipelineName: bot.use_pipeline_name || "",
}) })
}) })
resolve(botList) resolve(botList)
+6 -6
View File
@@ -94,16 +94,16 @@ export interface ApiRespPlatformBot {
} }
export interface Bot { export interface Bot {
uuid: string; uuid?: string;
name: string; name: string;
description: string; description: string;
enable: boolean; enable?: boolean;
adapter: string; adapter: string;
adapter_config: object; adapter_config: object;
use_pipeline_name: string; use_pipeline_name?: string;
use_pipeline_uuid: string; use_pipeline_uuid?: string;
created_at: string; created_at?: string;
updated_at: string; updated_at?: string;
} }
// plugins // plugins