feat: add supports for bot-selector config field

This commit is contained in:
Junyan Qin
2025-11-06 15:36:43 +08:00
parent 4a84bf2355
commit 61bc6a1dc2
7 changed files with 41 additions and 1 deletions

View File

@@ -58,6 +58,9 @@ export default function DynamicFormComponent({
case 'knowledge-base-selector': case 'knowledge-base-selector':
fieldSchema = z.string(); fieldSchema = z.string();
break; break;
case 'bot-selector':
fieldSchema = z.string();
break;
case 'prompt-editor': case 'prompt-editor':
fieldSchema = z.array( fieldSchema = z.array(
z.object({ z.object({

View File

@@ -17,7 +17,7 @@ import { ControllerRenderProps } from 'react-hook-form';
import { Button } from '@/components/ui/button'; import { Button } from '@/components/ui/button';
import { useEffect, useState } from 'react'; import { useEffect, useState } from 'react';
import { httpClient } from '@/app/infra/http/HttpClient'; import { httpClient } from '@/app/infra/http/HttpClient';
import { LLMModel } from '@/app/infra/entities/api'; import { LLMModel, Bot } from '@/app/infra/entities/api';
import { KnowledgeBase } from '@/app/infra/entities/api'; import { KnowledgeBase } from '@/app/infra/entities/api';
import { toast } from 'sonner'; import { toast } from 'sonner';
import { import {
@@ -42,6 +42,7 @@ export default function DynamicFormItemComponent({
}) { }) {
const [llmModels, setLlmModels] = useState<LLMModel[]>([]); const [llmModels, setLlmModels] = useState<LLMModel[]>([]);
const [knowledgeBases, setKnowledgeBases] = useState<KnowledgeBase[]>([]); const [knowledgeBases, setKnowledgeBases] = useState<KnowledgeBase[]>([]);
const [bots, setBots] = useState<Bot[]>([]);
const [uploading, setUploading] = useState<boolean>(false); const [uploading, setUploading] = useState<boolean>(false);
const { t } = useTranslation(); const { t } = useTranslation();
@@ -101,6 +102,19 @@ export default function DynamicFormItemComponent({
} }
}, [config.type]); }, [config.type]);
useEffect(() => {
if (config.type === DynamicFormItemType.BOT_SELECTOR) {
httpClient
.getBots()
.then((resp) => {
setBots(resp.bots);
})
.catch((err) => {
toast.error('Failed to get bot list: ' + err.message);
});
}
}, [config.type]);
switch (config.type) { switch (config.type) {
case DynamicFormItemType.INT: case DynamicFormItemType.INT:
case DynamicFormItemType.FLOAT: case DynamicFormItemType.FLOAT:
@@ -322,6 +336,24 @@ export default function DynamicFormItemComponent({
</Select> </Select>
); );
case DynamicFormItemType.BOT_SELECTOR:
return (
<Select value={field.value} onValueChange={field.onChange}>
<SelectTrigger className="bg-[#ffffff] dark:bg-[#2a2a2e]">
<SelectValue placeholder={t('bots.selectBot')} />
</SelectTrigger>
<SelectContent>
<SelectGroup>
{bots.map((bot) => (
<SelectItem key={bot.uuid} value={bot.uuid ?? ''}>
{bot.name}
</SelectItem>
))}
</SelectGroup>
</SelectContent>
</Select>
);
case DynamicFormItemType.PROMPT_EDITOR: case DynamicFormItemType.PROMPT_EDITOR:
return ( return (
<div className="space-y-2"> <div className="space-y-2">

View File

@@ -30,6 +30,7 @@ export enum DynamicFormItemType {
UNKNOWN = 'unknown', UNKNOWN = 'unknown',
KNOWLEDGE_BASE_SELECTOR = 'knowledge-base-selector', KNOWLEDGE_BASE_SELECTOR = 'knowledge-base-selector',
PLUGIN_SELECTOR = 'plugin-selector', PLUGIN_SELECTOR = 'plugin-selector',
BOT_SELECTOR = 'bot-selector',
} }
export interface IFileConfig { export interface IFileConfig {

View File

@@ -139,6 +139,7 @@ const enUS = {
adapterConfig: 'Adapter Configuration', adapterConfig: 'Adapter Configuration',
bindPipeline: 'Bind Pipeline', bindPipeline: 'Bind Pipeline',
selectPipeline: 'Select Pipeline', selectPipeline: 'Select Pipeline',
selectBot: 'Select Bot',
botLogTitle: 'Bot Log', botLogTitle: 'Bot Log',
enableAutoRefresh: 'Enable Auto Refresh', enableAutoRefresh: 'Enable Auto Refresh',
session: 'Session', session: 'Session',

View File

@@ -141,6 +141,7 @@ const jaJP = {
adapterConfig: 'アダプター設定', adapterConfig: 'アダプター設定',
bindPipeline: 'パイプラインを紐付け', bindPipeline: 'パイプラインを紐付け',
selectPipeline: 'パイプラインを選択', selectPipeline: 'パイプラインを選択',
selectBot: 'ボットを選択してください',
botLogTitle: 'ボットログ', botLogTitle: 'ボットログ',
enableAutoRefresh: '自動更新を有効にする', enableAutoRefresh: '自動更新を有効にする',
session: 'セッション', session: 'セッション',

View File

@@ -136,6 +136,7 @@ const zhHans = {
adapterConfig: '适配器配置', adapterConfig: '适配器配置',
bindPipeline: '绑定流水线', bindPipeline: '绑定流水线',
selectPipeline: '选择流水线', selectPipeline: '选择流水线',
selectBot: '请选择机器人',
botLogTitle: '机器人日志', botLogTitle: '机器人日志',
enableAutoRefresh: '开启自动刷新', enableAutoRefresh: '开启自动刷新',
session: '会话', session: '会话',

View File

@@ -136,6 +136,7 @@ const zhHant = {
adapterConfig: '適配器設定', adapterConfig: '適配器設定',
bindPipeline: '綁定流程線', bindPipeline: '綁定流程線',
selectPipeline: '選擇流程線', selectPipeline: '選擇流程線',
selectBot: '請選擇機器人',
botLogTitle: '機器人日誌', botLogTitle: '機器人日誌',
enableAutoRefresh: '開啟自動重新整理', enableAutoRefresh: '開啟自動重新整理',
session: '對話', session: '對話',