From 436b45c05cde57d3b607f0fb11f22a36f9931659 Mon Sep 17 00:00:00 2001 From: Junyan Qin Date: Thu, 8 May 2025 12:09:20 +0800 Subject: [PATCH] feat: bot enable and pipeline binding --- web/package-lock.json | 30 +++++++ web/package.json | 1 + .../home/bots/components/bot-form/BotForm.tsx | 79 ++++++++++++++++++- ...ChooseAdapterEntity.ts => ChooseEntity.ts} | 5 ++ web/src/components/ui/switch.tsx | 31 ++++++++ 5 files changed, 145 insertions(+), 1 deletion(-) rename web/src/app/home/bots/components/bot-form/{ChooseAdapterEntity.ts => ChooseEntity.ts} (51%) create mode 100644 web/src/components/ui/switch.tsx diff --git a/web/package-lock.json b/web/package-lock.json index f682d665..eb709ffe 100644 --- a/web/package-lock.json +++ b/web/package-lock.json @@ -15,6 +15,7 @@ "@radix-ui/react-label": "^2.1.6", "@radix-ui/react-select": "^2.2.4", "@radix-ui/react-slot": "^1.2.2", + "@radix-ui/react-switch": "^1.2.4", "@radix-ui/react-toggle": "^1.1.8", "@radix-ui/react-toggle-group": "^1.1.9", "@tailwindcss/postcss": "^4.1.5", @@ -1473,6 +1474,35 @@ } } }, + "node_modules/@radix-ui/react-switch": { + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/@radix-ui/react-switch/-/react-switch-1.2.4.tgz", + "integrity": "sha512-yZCky6XZFnR7pcGonJkr9VyNRu46KcYAbyg1v/gVVCZUr8UJ4x+RpncC27hHtiZ15jC+3WS8Yg/JSgyIHnYYsQ==", + "license": "MIT", + "dependencies": { + "@radix-ui/primitive": "1.1.2", + "@radix-ui/react-compose-refs": "1.1.2", + "@radix-ui/react-context": "1.1.2", + "@radix-ui/react-primitive": "2.1.2", + "@radix-ui/react-use-controllable-state": "1.2.2", + "@radix-ui/react-use-previous": "1.1.1", + "@radix-ui/react-use-size": "1.1.1" + }, + "peerDependencies": { + "@types/react": "*", + "@types/react-dom": "*", + "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc", + "react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + }, + "@types/react-dom": { + "optional": true + } + } + }, "node_modules/@radix-ui/react-toggle": { "version": "1.1.8", "resolved": "https://registry.npmjs.org/@radix-ui/react-toggle/-/react-toggle-1.1.8.tgz", diff --git a/web/package.json b/web/package.json index 887f9a93..e800ae9b 100644 --- a/web/package.json +++ b/web/package.json @@ -18,6 +18,7 @@ "@radix-ui/react-label": "^2.1.6", "@radix-ui/react-select": "^2.2.4", "@radix-ui/react-slot": "^1.2.2", + "@radix-ui/react-switch": "^1.2.4", "@radix-ui/react-toggle": "^1.1.8", "@radix-ui/react-toggle-group": "^1.1.9", "@tailwindcss/postcss": "^4.1.5", diff --git a/web/src/app/home/bots/components/bot-form/BotForm.tsx b/web/src/app/home/bots/components/bot-form/BotForm.tsx index 69d8b0e6..1954cf9b 100644 --- a/web/src/app/home/bots/components/bot-form/BotForm.tsx +++ b/web/src/app/home/bots/components/bot-form/BotForm.tsx @@ -1,5 +1,5 @@ import { useEffect, useState } from 'react'; -import { IChooseAdapterEntity } from '@/app/home/bots/components/bot-form/ChooseAdapterEntity'; +import { IChooseAdapterEntity, IPipelineEntity } from '@/app/home/bots/components/bot-form/ChooseEntity'; import { DynamicFormItemConfig, IDynamicFormItemConfig, @@ -37,12 +37,15 @@ import { import { Input } from "@/components/ui/input" import { Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectTrigger, SelectValue } from "@/components/ui/select" import { Checkbox } from "@/components/ui/checkbox" +import { Switch } from "@/components/ui/switch" const formSchema = z.object({ name: z.string().min(1, { message: '机器人名称不能为空' }), description: z.string().min(1, { message: '机器人描述不能为空' }), adapter: z.string().min(1, { message: '适配器不能为空' }), adapter_config: z.record(z.string(), z.any()), + enable: z.boolean(), + use_pipeline_uuid: z.string().min(1, { message: '流水线不能为空' }), }); export default function BotForm({ @@ -64,6 +67,8 @@ export default function BotForm({ description: '一个机器人', adapter: '', adapter_config: {}, + enable: true, + use_pipeline_uuid: '', }, }); @@ -85,6 +90,10 @@ export default function BotForm({ Record >({}); + const [pipelineNameList, setPipelineNameList] = useState< + IPipelineEntity[] + >([]); + const [dynamicFormConfigList, setDynamicFormConfigList] = useState< IDynamicFormItemConfig[] >([]); @@ -100,6 +109,9 @@ export default function BotForm({ form.setValue('description', val.description); form.setValue('adapter', val.adapter); form.setValue('adapter_config', val.adapter_config); + form.setValue('enable', val.enable); + form.setValue('use_pipeline_uuid', val.use_pipeline_uuid || ''); + console.log('form', form.getValues()); handleAdapterSelect(val.adapter); // dynamicForm.setFieldsValue(val.adapter_config); }); @@ -138,6 +150,19 @@ export default function BotForm({ }, {} as Record), ); + if (initBotId) { + // 初始化流水线列表 + const rawPipelineList = await httpClient.getPipelines(); + setPipelineNameList( + rawPipelineList.pipelines.map((item) => { + return { + label: item.name, + value: item.uuid, + }; + }), + ); + } + // 初始化适配器表单map rawAdapterList.adapters.forEach((rawAdapter) => { adapterNameToDynamicConfigMap.set( @@ -172,6 +197,8 @@ export default function BotForm({ description: bot.description, name: bot.name, adapter_config: bot.adapter_config, + enable: bot.enable ?? true, + use_pipeline_uuid: bot.use_pipeline_uuid, }; } @@ -214,6 +241,8 @@ export default function BotForm({ description: form.getValues().description, adapter: form.getValues().adapter, adapter_config: form.getValues().adapter_config, + enable: form.getValues().enable, + use_pipeline_uuid: form.getValues().use_pipeline_uuid, }; httpClient .updateBot(initBotId, updateBot) @@ -316,6 +345,54 @@ export default function BotForm({
+ {/* 是否启用 & 绑定流水线 仅在编辑模式 */} + {initBotId && ( +
+ ( + + 是否启用 + + + + + )} + /> + + ( + + 绑定流水线 + + + + + )} + /> +
+ + )} + ) { + return ( + + + + ) +} + +export { Switch }