|
|
|
@ -31,6 +31,7 @@ import type {
|
|
|
|
import { addFileInfos, sortAgentSorts } from '@/app/components/tools/utils'
|
|
|
|
import { addFileInfos, sortAgentSorts } from '@/app/components/tools/utils'
|
|
|
|
import { useToastContext } from '@/app/components/base/toast'
|
|
|
|
import { useToastContext } from '@/app/components/base/toast'
|
|
|
|
import { changeLanguage } from '@/i18n/i18next-config'
|
|
|
|
import { changeLanguage } from '@/i18n/i18next-config'
|
|
|
|
|
|
|
|
import { getProcessedInputsFromUrlParams } from '@/app/components/base/chat/utils'
|
|
|
|
|
|
|
|
|
|
|
|
export const useEmbeddedChatbot = () => {
|
|
|
|
export const useEmbeddedChatbot = () => {
|
|
|
|
const isInstalledApp = false
|
|
|
|
const isInstalledApp = false
|
|
|
|
@ -109,6 +110,7 @@ export const useEmbeddedChatbot = () => {
|
|
|
|
const { t } = useTranslation()
|
|
|
|
const { t } = useTranslation()
|
|
|
|
const newConversationInputsRef = useRef<Record<string, any>>({})
|
|
|
|
const newConversationInputsRef = useRef<Record<string, any>>({})
|
|
|
|
const [newConversationInputs, setNewConversationInputs] = useState<Record<string, any>>({})
|
|
|
|
const [newConversationInputs, setNewConversationInputs] = useState<Record<string, any>>({})
|
|
|
|
|
|
|
|
const [initInputs, setInitInputs] = useState<Record<string, any>>({})
|
|
|
|
const handleNewConversationInputsChange = useCallback((newInputs: Record<string, any>) => {
|
|
|
|
const handleNewConversationInputsChange = useCallback((newInputs: Record<string, any>) => {
|
|
|
|
newConversationInputsRef.current = newInputs
|
|
|
|
newConversationInputsRef.current = newInputs
|
|
|
|
setNewConversationInputs(newInputs)
|
|
|
|
setNewConversationInputs(newInputs)
|
|
|
|
@ -116,30 +118,49 @@ export const useEmbeddedChatbot = () => {
|
|
|
|
const inputsForms = useMemo(() => {
|
|
|
|
const inputsForms = useMemo(() => {
|
|
|
|
return (appParams?.user_input_form || []).filter((item: any) => item.paragraph || item.select || item['text-input'] || item.number).map((item: any) => {
|
|
|
|
return (appParams?.user_input_form || []).filter((item: any) => item.paragraph || item.select || item['text-input'] || item.number).map((item: any) => {
|
|
|
|
if (item.paragraph) {
|
|
|
|
if (item.paragraph) {
|
|
|
|
|
|
|
|
let value = initInputs[item.paragraph.variable]
|
|
|
|
|
|
|
|
if (value && item.paragraph.max_length && value.length > item.paragraph.max_length)
|
|
|
|
|
|
|
|
value = value.slice(0, item.paragraph.max_length)
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
...item.paragraph,
|
|
|
|
...item.paragraph,
|
|
|
|
|
|
|
|
default: value || item.default,
|
|
|
|
type: 'paragraph',
|
|
|
|
type: 'paragraph',
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (item.number) {
|
|
|
|
if (item.number) {
|
|
|
|
|
|
|
|
const convertedNumber = Number(initInputs[item.number.variable]) ?? undefined
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
...item.number,
|
|
|
|
...item.number,
|
|
|
|
|
|
|
|
default: convertedNumber || item.default,
|
|
|
|
type: 'number',
|
|
|
|
type: 'number',
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (item.select) {
|
|
|
|
if (item.select) {
|
|
|
|
|
|
|
|
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,
|
|
|
|
type: 'select',
|
|
|
|
type: 'select',
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let value = initInputs[item['text-input'].variable]
|
|
|
|
|
|
|
|
if (value && item['text-input'].max_length && value.length > item['text-input'].max_length)
|
|
|
|
|
|
|
|
value = value.slice(0, item['text-input'].max_length)
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
...item['text-input'],
|
|
|
|
...item['text-input'],
|
|
|
|
|
|
|
|
default: value || item.default,
|
|
|
|
type: 'text-input',
|
|
|
|
type: 'text-input',
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}, [appParams])
|
|
|
|
}, [appParams])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
|
|
// init inputs from url params
|
|
|
|
|
|
|
|
setInitInputs(getProcessedInputsFromUrlParams())
|
|
|
|
|
|
|
|
}, [])
|
|
|
|
useEffect(() => {
|
|
|
|
useEffect(() => {
|
|
|
|
const conversationInputs: Record<string, any> = {}
|
|
|
|
const conversationInputs: Record<string, any> = {}
|
|
|
|
|
|
|
|
|
|
|
|
|