Co-authored-by: crazywoola <427733928@qq.com> Co-authored-by: GuanMu <ballmanjq@gmail.com>tags/1.7.1
| import Checkbox from '@/app/components/base/checkbox' | import Checkbox from '@/app/components/base/checkbox' | ||||
| import { DEFAULT_FILE_UPLOAD_SETTING } from '@/app/components/workflow/constants' | import { DEFAULT_FILE_UPLOAD_SETTING } from '@/app/components/workflow/constants' | ||||
| import { DEFAULT_VALUE_MAX_LEN } from '@/config' | import { DEFAULT_VALUE_MAX_LEN } from '@/config' | ||||
| import { SimpleSelect } from '@/app/components/base/select' | |||||
| const TEXT_MAX_LENGTH = 256 | const TEXT_MAX_LENGTH = 256 | ||||
| )} | )} | ||||
| {type === InputVarType.select && ( | {type === InputVarType.select && ( | ||||
| <Field title={t('appDebug.variableConfig.options')}> | |||||
| <ConfigSelect options={options || []} onChange={handlePayloadChange('options')} /> | |||||
| </Field> | |||||
| <> | |||||
| <Field title={t('appDebug.variableConfig.options')}> | |||||
| <ConfigSelect options={options || []} onChange={handlePayloadChange('options')} /> | |||||
| </Field> | |||||
| {options && options.length > 0 && ( | |||||
| <Field title={t('appDebug.variableConfig.defaultValue')}> | |||||
| <SimpleSelect | |||||
| key={`default-select-${options.join('-')}`} | |||||
| className="w-full" | |||||
| items={[ | |||||
| { value: '', name: t('appDebug.variableConfig.noDefaultValue') }, | |||||
| ...options.filter(opt => opt.trim() !== '').map(option => ({ | |||||
| value: option, | |||||
| name: option, | |||||
| })), | |||||
| ]} | |||||
| defaultValue={tempPayload.default || ''} | |||||
| onSelect={item => handlePayloadChange('default')(item.value === '' ? undefined : item.value)} | |||||
| placeholder={t('appDebug.variableConfig.selectDefaultValue')} | |||||
| allowSearch={false} | |||||
| /> | |||||
| </Field> | |||||
| )} | |||||
| </> | |||||
| )} | )} | ||||
| {[InputVarType.singleFile, InputVarType.multiFiles].includes(type) && ( | {[InputVarType.singleFile, InputVarType.multiFiles].includes(type) && ( |
| const isInputInOptions = item.select.options.includes(initInputs[item.select.variable]) | const isInputInOptions = item.select.options.includes(initInputs[item.select.variable]) | ||||
| return { | return { | ||||
| ...item.select, | ...item.select, | ||||
| default: (isInputInOptions ? initInputs[item.select.variable] : undefined) || item.default, | |||||
| default: (isInputInOptions ? initInputs[item.select.variable] : undefined) || item.select.default, | |||||
| type: 'select', | type: 'select', | ||||
| } | } | ||||
| } | } |
| {form.type === InputVarType.select && ( | {form.type === InputVarType.select && ( | ||||
| <PortalSelect | <PortalSelect | ||||
| popupClassName='w-[200px]' | popupClassName='w-[200px]' | ||||
| value={inputsFormValue?.[form.variable]} | |||||
| value={inputsFormValue?.[form.variable] ?? form.default ?? ''} | |||||
| items={form.options.map((option: string) => ({ value: option, name: option }))} | items={form.options.map((option: string) => ({ value: option, name: option }))} | ||||
| onSelect={item => handleFormChange(form.variable, item.value as string)} | onSelect={item => handleFormChange(form.variable, item.value as string)} | ||||
| placeholder={form.label} | placeholder={form.label} |
| const isInputInOptions = item.select.options.includes(initInputs[item.select.variable]) | const isInputInOptions = item.select.options.includes(initInputs[item.select.variable]) | ||||
| return { | return { | ||||
| ...item.select, | ...item.select, | ||||
| default: (isInputInOptions ? initInputs[item.select.variable] : undefined) || item.default, | |||||
| default: (isInputInOptions ? initInputs[item.select.variable] : undefined) || item.select.default, | |||||
| type: 'select', | type: 'select', | ||||
| } | } | ||||
| } | } |
| {form.type === InputVarType.select && ( | {form.type === InputVarType.select && ( | ||||
| <PortalSelect | <PortalSelect | ||||
| popupClassName='w-[200px]' | popupClassName='w-[200px]' | ||||
| value={inputsFormValue?.[form.variable]} | |||||
| value={inputsFormValue?.[form.variable] ?? form.default ?? ''} | |||||
| items={form.options.map((option: string) => ({ value: option, name: option }))} | items={form.options.map((option: string) => ({ value: option, name: option }))} | ||||
| onSelect={item => handleFormChange(form.variable, item.value as string)} | onSelect={item => handleFormChange(form.variable, item.value as string)} | ||||
| placeholder={form.label} | placeholder={form.label} |
| type === InputVarType.select && ( | type === InputVarType.select && ( | ||||
| <Select | <Select | ||||
| className="w-full" | className="w-full" | ||||
| defaultValue={value || ''} | |||||
| defaultValue={value || payload.default || ''} | |||||
| items={payload.options?.map(option => ({ name: option, value: option })) || []} | items={payload.options?.map(option => ({ name: option, value: option })) || []} | ||||
| onSelect={i => onChange(i.value)} | onSelect={i => onChange(i.value)} | ||||
| allowSearch={false} | allowSearch={false} |
| const startVariables = startNode?.data.variables | const startVariables = startNode?.data.variables | ||||
| const appDetail = useAppStore(s => s.appDetail) | const appDetail = useAppStore(s => s.appDetail) | ||||
| const workflowStore = useWorkflowStore() | const workflowStore = useWorkflowStore() | ||||
| const inputs = useStore(s => s.inputs) | |||||
| const { inputs, setInputs } = useStore(s => ({ | |||||
| inputs: s.inputs, | |||||
| setInputs: s.setInputs, | |||||
| })) | |||||
| const initialInputs = useMemo(() => { | |||||
| const initInputs: Record<string, any> = {} | |||||
| if (startVariables) { | |||||
| startVariables.forEach((variable) => { | |||||
| if (variable.default) | |||||
| initInputs[variable.variable] = variable.default | |||||
| }) | |||||
| } | |||||
| return initInputs | |||||
| }, [startVariables]) | |||||
| const features = useFeatures(s => s.features) | const features = useFeatures(s => s.features) | ||||
| const config = useMemo(() => { | const config = useMemo(() => { | ||||
| return { | return { | ||||
| taskId => stopChatMessageResponding(appDetail!.id, taskId), | taskId => stopChatMessageResponding(appDetail!.id, taskId), | ||||
| ) | ) | ||||
| const handleRestartChat = useCallback(() => { | |||||
| handleRestart() | |||||
| setInputs(initialInputs) | |||||
| }, [handleRestart, setInputs, initialInputs]) | |||||
| const doSend: OnSend = useCallback((message, files, isRegenerate = false, parentAnswer: ChatItem | null = null) => { | const doSend: OnSend = useCallback((message, files, isRegenerate = false, parentAnswer: ChatItem | null = null) => { | ||||
| handleSend( | handleSend( | ||||
| { | { | ||||
| useImperativeHandle(ref, () => { | useImperativeHandle(ref, () => { | ||||
| return { | return { | ||||
| handleRestart, | |||||
| handleRestart: handleRestartChat, | |||||
| } | |||||
| }, [handleRestartChat]) | |||||
| useEffect(() => { | |||||
| if (Object.keys(initialInputs).length > 0) { | |||||
| setInputs({ | |||||
| ...initialInputs, | |||||
| ...inputs, | |||||
| }) | |||||
| } | } | ||||
| }, [handleRestart]) | |||||
| }, [initialInputs]) | |||||
| useEffect(() => { | useEffect(() => { | ||||
| if (isResponding) | if (isResponding) |
| options: 'Optionen', | options: 'Optionen', | ||||
| addOption: 'Option hinzufügen', | addOption: 'Option hinzufügen', | ||||
| apiBasedVar: 'API-basierte Variable', | apiBasedVar: 'API-basierte Variable', | ||||
| defaultValue: 'Standardwert', | |||||
| noDefaultValue: 'Kein Standardwert', | |||||
| selectDefaultValue: 'Standardwert auswählen', | |||||
| }, | }, | ||||
| vision: { | vision: { | ||||
| name: 'Vision', | name: 'Vision', |
| atLeastOneOption: 'At least one option is required', | atLeastOneOption: 'At least one option is required', | ||||
| optionRepeat: 'Has repeat options', | optionRepeat: 'Has repeat options', | ||||
| }, | }, | ||||
| 'defaultValue': 'Default value', | |||||
| 'noDefaultValue': 'No default value', | |||||
| 'selectDefaultValue': 'Select default value', | |||||
| }, | }, | ||||
| vision: { | vision: { | ||||
| name: 'Vision', | name: 'Vision', |
| atLeastOneOption: 'Se requiere al menos una opción', | atLeastOneOption: 'Se requiere al menos una opción', | ||||
| optionRepeat: 'Hay opciones repetidas', | optionRepeat: 'Hay opciones repetidas', | ||||
| }, | }, | ||||
| 'defaultValue': 'Valor predeterminado', | |||||
| 'noDefaultValue': 'Sin valor predeterminado', | |||||
| 'selectDefaultValue': 'Seleccionar valor predeterminado', | |||||
| }, | }, | ||||
| vision: { | vision: { | ||||
| name: 'Visión', | name: 'Visión', |
| atLeastOneOption: 'At least one option is required', | atLeastOneOption: 'At least one option is required', | ||||
| optionRepeat: 'Has repeat options', | optionRepeat: 'Has repeat options', | ||||
| }, | }, | ||||
| 'defaultValue': 'Valeur par défaut', | |||||
| 'noDefaultValue': 'Aucune valeur par défaut', | |||||
| 'selectDefaultValue': 'Sélectionner la valeur par défaut', | |||||
| }, | }, | ||||
| vision: { | vision: { | ||||
| name: 'Vision', | name: 'Vision', |
| atLeastOneOption: 'कम से कम एक विकल्प आवश्यक है', | atLeastOneOption: 'कम से कम एक विकल्प आवश्यक है', | ||||
| optionRepeat: 'विकल्प दोहराए गए हैं', | optionRepeat: 'विकल्प दोहराए गए हैं', | ||||
| }, | }, | ||||
| 'defaultValue': 'डिफ़ॉल्ट मान', | |||||
| 'noDefaultValue': 'कोई डिफ़ॉल्ट मान नहीं', | |||||
| 'selectDefaultValue': 'डिफ़ॉल्ट मान चुनें', | |||||
| }, | }, | ||||
| vision: { | vision: { | ||||
| name: 'विजन', | name: 'विजन', |
| atLeastOneOption: 'È richiesta almeno un\'opzione', | atLeastOneOption: 'È richiesta almeno un\'opzione', | ||||
| optionRepeat: 'Ci sono opzioni ripetute', | optionRepeat: 'Ci sono opzioni ripetute', | ||||
| }, | }, | ||||
| 'defaultValue': 'Valore predefinito', | |||||
| 'noDefaultValue': 'Nessun valore predefinito', | |||||
| 'selectDefaultValue': 'Seleziona valore predefinito', | |||||
| }, | }, | ||||
| vision: { | vision: { | ||||
| name: 'Visione', | name: 'Visione', |
| atLeastOneOption: '少なくとも 1 つのオプションが必要です', | atLeastOneOption: '少なくとも 1 つのオプションが必要です', | ||||
| optionRepeat: '繰り返しオプションがあります', | optionRepeat: '繰り返しオプションがあります', | ||||
| }, | }, | ||||
| 'defaultValue': 'デフォルト値', | |||||
| 'noDefaultValue': 'デフォルト値なし', | |||||
| 'selectDefaultValue': 'デフォルト値を選択', | |||||
| }, | }, | ||||
| vision: { | vision: { | ||||
| name: 'ビジョン', | name: 'ビジョン', |
| atLeastOneOption: '적어도 하나의 옵션이 필요합니다', | atLeastOneOption: '적어도 하나의 옵션이 필요합니다', | ||||
| optionRepeat: '옵션이 중복되어 있습니다', | optionRepeat: '옵션이 중복되어 있습니다', | ||||
| }, | }, | ||||
| 'defaultValue': '기본값', | |||||
| 'noDefaultValue': '기본값 없음', | |||||
| 'selectDefaultValue': '기본값 선택', | |||||
| }, | }, | ||||
| vision: { | vision: { | ||||
| name: '비전', | name: '비전', |
| atLeastOneOption: 'Wymagana jest co najmniej jedna opcja', | atLeastOneOption: 'Wymagana jest co najmniej jedna opcja', | ||||
| optionRepeat: 'Powtarzają się opcje', | optionRepeat: 'Powtarzają się opcje', | ||||
| }, | }, | ||||
| 'defaultValue': 'Wartość domyślna', | |||||
| 'noDefaultValue': 'Brak wartości domyślnej', | |||||
| 'selectDefaultValue': 'Wybierz wartość domyślną', | |||||
| }, | }, | ||||
| vision: { | vision: { | ||||
| name: 'Wizja', | name: 'Wizja', |
| atLeastOneOption: 'Pelo menos uma opção é obrigatória', | atLeastOneOption: 'Pelo menos uma opção é obrigatória', | ||||
| optionRepeat: 'Tem opções repetidas', | optionRepeat: 'Tem opções repetidas', | ||||
| }, | }, | ||||
| 'defaultValue': 'Valor padrão', | |||||
| 'noDefaultValue': 'Nenhum valor padrão', | |||||
| 'selectDefaultValue': 'Selecionar valor padrão', | |||||
| }, | }, | ||||
| vision: { | vision: { | ||||
| name: 'Visão', | name: 'Visão', |
| atLeastOneOption: 'Este necesară cel puțin o opțiune', | atLeastOneOption: 'Este necesară cel puțin o opțiune', | ||||
| optionRepeat: 'Există opțiuni repetate', | optionRepeat: 'Există opțiuni repetate', | ||||
| }, | }, | ||||
| 'defaultValue': 'Valoare implicită', | |||||
| 'noDefaultValue': 'Fără valoare implicită', | |||||
| 'selectDefaultValue': 'Selectați valoarea implicită', | |||||
| }, | }, | ||||
| vision: { | vision: { | ||||
| name: 'Viziune', | name: 'Viziune', |
| atLeastOneOption: 'Требуется хотя бы один вариант', | atLeastOneOption: 'Требуется хотя бы один вариант', | ||||
| optionRepeat: 'Есть повторяющиеся варианты', | optionRepeat: 'Есть повторяющиеся варианты', | ||||
| }, | }, | ||||
| 'defaultValue': 'Значение по умолчанию', | |||||
| 'noDefaultValue': 'Без значения по умолчанию', | |||||
| 'selectDefaultValue': 'Выберите значение по умолчанию', | |||||
| }, | }, | ||||
| vision: { | vision: { | ||||
| name: 'Зрение', | name: 'Зрение', |
| atLeastOneOption: 'En az bir seçenek gereklidir', | atLeastOneOption: 'En az bir seçenek gereklidir', | ||||
| optionRepeat: 'Yinelenen seçenekler var', | optionRepeat: 'Yinelenen seçenekler var', | ||||
| }, | }, | ||||
| defaultValue: 'Varsayılan değer', | |||||
| noDefaultValue: 'Varsayılan değer yok', | |||||
| selectDefaultValue: 'Varsayılan değer seç', | |||||
| }, | }, | ||||
| vision: { | vision: { | ||||
| name: 'Görüş', | name: 'Görüş', |
| atLeastOneOption: 'Потрібно щонайменше одну опцію', | atLeastOneOption: 'Потрібно щонайменше одну опцію', | ||||
| optionRepeat: 'Є повторні опції', | optionRepeat: 'Є повторні опції', | ||||
| }, | }, | ||||
| 'defaultValue': 'Значення за замовчуванням', | |||||
| 'noDefaultValue': 'Без значення за замовчуванням', | |||||
| 'selectDefaultValue': 'Обрати значення за замовчуванням', | |||||
| }, | }, | ||||
| vision: { | vision: { | ||||
| name: 'Зображення', // Vision | name: 'Зображення', // Vision |
| atLeastOneOption: 'Cần ít nhất một tùy chọn', | atLeastOneOption: 'Cần ít nhất một tùy chọn', | ||||
| optionRepeat: 'Có các tùy chọn trùng lặp', | optionRepeat: 'Có các tùy chọn trùng lặp', | ||||
| }, | }, | ||||
| 'defaultValue': 'Giá trị mặc định', | |||||
| 'noDefaultValue': 'Không có giá trị mặc định', | |||||
| 'selectDefaultValue': 'Chọn giá trị mặc định', | |||||
| }, | }, | ||||
| vision: { | vision: { | ||||
| name: 'Thị giác', | name: 'Thị giác', |
| atLeastOneOption: '至少需要一个选项', | atLeastOneOption: '至少需要一个选项', | ||||
| optionRepeat: '选项不能重复', | optionRepeat: '选项不能重复', | ||||
| }, | }, | ||||
| 'defaultValue': '默认值', | |||||
| 'noDefaultValue': '无默认值', | |||||
| 'selectDefaultValue': '选择默认值', | |||||
| }, | }, | ||||
| vision: { | vision: { | ||||
| name: '视觉', | name: '视觉', |
| atLeastOneOption: '至少需要一個選項', | atLeastOneOption: '至少需要一個選項', | ||||
| optionRepeat: '選項不能重複', | optionRepeat: '選項不能重複', | ||||
| }, | }, | ||||
| 'defaultValue': '預設值', | |||||
| 'noDefaultValue': '無預設值', | |||||
| 'selectDefaultValue': '選擇預設值', | |||||
| }, | }, | ||||
| vision: { | vision: { | ||||
| name: '視覺', | name: '視覺', |