|
|
|
|
@ -16,7 +16,7 @@ import type {
|
|
|
|
|
Feedback,
|
|
|
|
|
} from '../types'
|
|
|
|
|
import { CONVERSATION_ID_INFO } from '../constants'
|
|
|
|
|
import { buildChatItemTree, getProcessedSystemVariablesFromUrlParams } from '../utils'
|
|
|
|
|
import { buildChatItemTree, getProcessedSystemVariablesFromUrlParams, getRawInputsFromUrlParams } from '../utils'
|
|
|
|
|
import { addFileInfos, sortAgentSorts } from '../../../tools/utils'
|
|
|
|
|
import { getProcessedFilesFromResponse } from '@/app/components/base/file-uploader/utils'
|
|
|
|
|
import {
|
|
|
|
|
@ -195,6 +195,7 @@ export const useChatWithHistory = (installedAppInfo?: InstalledApp) => {
|
|
|
|
|
const { t } = useTranslation()
|
|
|
|
|
const newConversationInputsRef = useRef<Record<string, any>>({})
|
|
|
|
|
const [newConversationInputs, setNewConversationInputs] = useState<Record<string, any>>({})
|
|
|
|
|
const [initInputs, setInitInputs] = useState<Record<string, any>>({})
|
|
|
|
|
const handleNewConversationInputsChange = useCallback((newInputs: Record<string, any>) => {
|
|
|
|
|
newConversationInputsRef.current = newInputs
|
|
|
|
|
setNewConversationInputs(newInputs)
|
|
|
|
|
@ -202,20 +203,29 @@ export const useChatWithHistory = (installedAppInfo?: InstalledApp) => {
|
|
|
|
|
const inputsForms = useMemo(() => {
|
|
|
|
|
return (appParams?.user_input_form || []).filter((item: any) => !item.external_data_tool).map((item: any) => {
|
|
|
|
|
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 {
|
|
|
|
|
...item.paragraph,
|
|
|
|
|
default: value || item.default,
|
|
|
|
|
type: 'paragraph',
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (item.number) {
|
|
|
|
|
const convertedNumber = Number(initInputs[item.number.variable]) ?? undefined
|
|
|
|
|
return {
|
|
|
|
|
...item.number,
|
|
|
|
|
default: convertedNumber || item.default,
|
|
|
|
|
type: 'number',
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (item.select) {
|
|
|
|
|
const isInputInOptions = item.select.options.includes(initInputs[item.select.variable])
|
|
|
|
|
return {
|
|
|
|
|
...item.select,
|
|
|
|
|
default: (isInputInOptions ? initInputs[item.select.variable] : undefined) || item.default,
|
|
|
|
|
type: 'select',
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -234,17 +244,30 @@ export const useChatWithHistory = (installedAppInfo?: InstalledApp) => {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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 {
|
|
|
|
|
...item['text-input'],
|
|
|
|
|
default: value || item.default,
|
|
|
|
|
type: 'text-input',
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}, [appParams])
|
|
|
|
|
}, [initInputs, appParams])
|
|
|
|
|
|
|
|
|
|
const allInputsHidden = useMemo(() => {
|
|
|
|
|
return inputsForms.length > 0 && inputsForms.every(item => item.hide === true)
|
|
|
|
|
}, [inputsForms])
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
// init inputs from url params
|
|
|
|
|
(async () => {
|
|
|
|
|
const inputs = await getRawInputsFromUrlParams()
|
|
|
|
|
setInitInputs(inputs)
|
|
|
|
|
})()
|
|
|
|
|
}, [])
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
const conversationInputs: Record<string, any> = {}
|
|
|
|
|
|
|
|
|
|
@ -362,11 +385,11 @@ export const useChatWithHistory = (installedAppInfo?: InstalledApp) => {
|
|
|
|
|
if (conversationId)
|
|
|
|
|
setClearChatList(false)
|
|
|
|
|
}, [handleConversationIdInfoChange, setClearChatList])
|
|
|
|
|
const handleNewConversation = useCallback(() => {
|
|
|
|
|
const handleNewConversation = useCallback(async () => {
|
|
|
|
|
currentChatInstanceRef.current.handleStop()
|
|
|
|
|
setShowNewConversationItemInList(true)
|
|
|
|
|
handleChangeConversation('')
|
|
|
|
|
handleNewConversationInputsChange({})
|
|
|
|
|
handleNewConversationInputsChange(await getRawInputsFromUrlParams())
|
|
|
|
|
setClearChatList(true)
|
|
|
|
|
}, [handleChangeConversation, setShowNewConversationItemInList, handleNewConversationInputsChange, setClearChatList])
|
|
|
|
|
const handleUpdateConversationList = useCallback(() => {
|
|
|
|
|
|