feat: basic chat app support bool

feat/support-bool-variable-fe
Joel 7 months ago
parent f2dfb5363f
commit b5782fff8f

@ -190,7 +190,7 @@ const ConfigVar: FC<IConfigVarProps> = ({ promptVariables, readonly, onPromptVar
const handleConfig = ({ key, type, index, name, config, icon, icon_background }: ExternalDataToolParams) => { const handleConfig = ({ key, type, index, name, config, icon, icon_background }: ExternalDataToolParams) => {
// setCurrKey(key) // setCurrKey(key)
setCurrIndex(index) setCurrIndex(index)
if (type !== 'string' && type !== 'paragraph' && type !== 'select' && type !== 'number') { if (type !== 'string' && type !== 'paragraph' && type !== 'select' && type !== 'number' && type !== 'boolean') {
handleOpenExternalDataToolModal({ key, type, index, name, config, icon, icon_background }, promptVariables) handleOpenExternalDataToolModal({ key, type, index, name, config, icon, icon_background }, promptVariables)
return return
} }

@ -65,6 +65,7 @@ const SelectVarType: FC<Props> = ({
<SelectItem type={InputVarType.paragraph} value='paragraph' text={t('appDebug.variableConfig.paragraph')} onClick={handleChange}></SelectItem> <SelectItem type={InputVarType.paragraph} value='paragraph' text={t('appDebug.variableConfig.paragraph')} onClick={handleChange}></SelectItem>
<SelectItem type={InputVarType.select} value='select' text={t('appDebug.variableConfig.select')} onClick={handleChange}></SelectItem> <SelectItem type={InputVarType.select} value='select' text={t('appDebug.variableConfig.select')} onClick={handleChange}></SelectItem>
<SelectItem type={InputVarType.number} value='number' text={t('appDebug.variableConfig.number')} onClick={handleChange}></SelectItem> <SelectItem type={InputVarType.number} value='number' text={t('appDebug.variableConfig.number')} onClick={handleChange}></SelectItem>
<SelectItem type={InputVarType.boolean} value='boolean' text={t('appDebug.variableConfig.boolean')} onClick={handleChange}></SelectItem>
</div> </div>
<div className='h-[1px] border-t border-components-panel-border'></div> <div className='h-[1px] border-t border-components-panel-border'></div>
<div className='p-1'> <div className='p-1'>

@ -8,6 +8,7 @@ import Textarea from '@/app/components/base/textarea'
import { DEFAULT_VALUE_MAX_LEN } from '@/config' import { DEFAULT_VALUE_MAX_LEN } from '@/config'
import type { Inputs } from '@/models/debug' import type { Inputs } from '@/models/debug'
import cn from '@/utils/classnames' import cn from '@/utils/classnames'
import BoolInput from '@/app/components/workflow/nodes/_base/components/before-run-form/bool-input'
type Props = { type Props = {
inputs: Inputs inputs: Inputs
@ -31,7 +32,7 @@ const ChatUserInput = ({
return obj return obj
})() })()
const handleInputValueChange = (key: string, value: string) => { const handleInputValueChange = (key: string, value: string | boolean) => {
if (!(key in promptVariableObj)) if (!(key in promptVariableObj))
return return
@ -55,10 +56,12 @@ const ChatUserInput = ({
className='mb-4 last-of-type:mb-0' className='mb-4 last-of-type:mb-0'
> >
<div> <div>
{type !== 'boolean' && (
<div className='system-sm-semibold mb-1 flex h-6 items-center gap-1 text-text-secondary'> <div className='system-sm-semibold mb-1 flex h-6 items-center gap-1 text-text-secondary'>
<div className='truncate'>{name || key}</div> <div className='truncate'>{name || key}</div>
{!required && <span className='system-xs-regular text-text-tertiary'>{t('workflow.panel.optional')}</span>} {!required && <span className='system-xs-regular text-text-tertiary'>{t('workflow.panel.optional')}</span>}
</div> </div>
)}
<div className='grow'> <div className='grow'>
{type === 'string' && ( {type === 'string' && (
<Input <Input
@ -96,6 +99,14 @@ const ChatUserInput = ({
maxLength={max_length || DEFAULT_VALUE_MAX_LEN} maxLength={max_length || DEFAULT_VALUE_MAX_LEN}
/> />
)} )}
{type === 'boolean' && (
<BoolInput
name={name || key}
value={!!inputs[key]}
required={required}
onChange={(value) => { handleInputValueChange(key, value) }}
/>
)}
</div> </div>
</div> </div>
</div> </div>

@ -2,10 +2,12 @@
import Checkbox from '@/app/components/base/checkbox' import Checkbox from '@/app/components/base/checkbox'
import type { FC } from 'react' import type { FC } from 'react'
import React, { useCallback } from 'react' import React, { useCallback } from 'react'
import { useTranslation } from 'react-i18next'
type Props = { type Props = {
name: string name: string
value: boolean value: boolean
required?: boolean
onChange: (value: boolean) => void onChange: (value: boolean) => void
} }
@ -13,7 +15,9 @@ const BoolInput: FC<Props> = ({
value, value,
onChange, onChange,
name, name,
required,
}) => { }) => {
const { t } = useTranslation()
const handleChange = useCallback(() => { const handleChange = useCallback(() => {
onChange(!value) onChange(!value)
}, [value, onChange]) }, [value, onChange])
@ -24,7 +28,10 @@ const BoolInput: FC<Props> = ({
checked={!!value} checked={!!value}
onCheck={handleChange} onCheck={handleChange}
/> />
<div className='system-sm-medium text-text-secondary'>{name}</div> <div className='system-sm-medium flex items-center gap-1 text-text-secondary'>
{name}
{!required && <span className='system-xs-regular text-text-tertiary'>{t('workflow.panel.optional')}</span>}
</div>
</div> </div>
) )
} }

@ -172,6 +172,7 @@ const FormItem: FC<Props> = ({
<BoolInput <BoolInput
name={payload.label as string} name={payload.label as string}
value={!!value} value={!!value}
required={payload.required}
onChange={onChange} onChange={onChange}
/> />
)} )}

@ -9,7 +9,7 @@ import type {
MetadataFilteringModeEnum, MetadataFilteringModeEnum,
} from '@/app/components/workflow/nodes/knowledge-retrieval/types' } from '@/app/components/workflow/nodes/knowledge-retrieval/types'
import type { ModelConfig as NodeModelConfig } from '@/app/components/workflow/types' import type { ModelConfig as NodeModelConfig } from '@/app/components/workflow/types'
export type Inputs = Record<string, string | number | object> export type Inputs = Record<string, string | number | object | boolean>
export enum PromptMode { export enum PromptMode {
simple = 'simple', simple = 'simple',

Loading…
Cancel
Save