|
|
|
|
|
|
|
|
import type { FC, FormEvent } from 'react' |
|
|
import type { FC, FormEvent } from 'react' |
|
|
import React from 'react' |
|
|
|
|
|
|
|
|
import React, { useCallback } from 'react' |
|
|
import { useTranslation } from 'react-i18next' |
|
|
import { useTranslation } from 'react-i18next' |
|
|
import { |
|
|
import { |
|
|
PlayIcon, |
|
|
PlayIcon, |
|
|
|
|
|
|
|
|
siteInfo: SiteInfo |
|
|
siteInfo: SiteInfo |
|
|
promptConfig: PromptConfig |
|
|
promptConfig: PromptConfig |
|
|
inputs: Record<string, any> |
|
|
inputs: Record<string, any> |
|
|
|
|
|
inputsRef: React.MutableRefObject<Record<string, any>> |
|
|
onInputsChange: (inputs: Record<string, any>) => void |
|
|
onInputsChange: (inputs: Record<string, any>) => void |
|
|
onSend: () => void |
|
|
onSend: () => void |
|
|
visionConfig: VisionSettings |
|
|
visionConfig: VisionSettings |
|
|
|
|
|
|
|
|
const RunOnce: FC<IRunOnceProps> = ({ |
|
|
const RunOnce: FC<IRunOnceProps> = ({ |
|
|
promptConfig, |
|
|
promptConfig, |
|
|
inputs, |
|
|
inputs, |
|
|
|
|
|
inputsRef, |
|
|
onInputsChange, |
|
|
onInputsChange, |
|
|
onSend, |
|
|
onSend, |
|
|
visionConfig, |
|
|
visionConfig, |
|
|
|
|
|
|
|
|
onSend() |
|
|
onSend() |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const handleInputsChange = useCallback((newInputs: Record<string, any>) => { |
|
|
|
|
|
onInputsChange(newInputs) |
|
|
|
|
|
inputsRef.current = newInputs |
|
|
|
|
|
}, [onInputsChange, inputsRef]) |
|
|
|
|
|
|
|
|
return ( |
|
|
return ( |
|
|
<div className=""> |
|
|
<div className=""> |
|
|
<section> |
|
|
<section> |
|
|
|
|
|
|
|
|
<Select |
|
|
<Select |
|
|
className='w-full' |
|
|
className='w-full' |
|
|
defaultValue={inputs[item.key]} |
|
|
defaultValue={inputs[item.key]} |
|
|
onSelect={(i) => { onInputsChange({ ...inputs, [item.key]: i.value }) }} |
|
|
|
|
|
|
|
|
onSelect={(i) => { handleInputsChange({ ...inputsRef.current, [item.key]: i.value }) }} |
|
|
items={(item.options || []).map(i => ({ name: i, value: i }))} |
|
|
items={(item.options || []).map(i => ({ name: i, value: i }))} |
|
|
allowSearch={false} |
|
|
allowSearch={false} |
|
|
bgClassName='bg-gray-50' |
|
|
bgClassName='bg-gray-50' |
|
|
|
|
|
|
|
|
className="block w-full p-2 text-gray-900 border border-gray-300 rounded-lg bg-gray-50 sm:text-xs focus:ring-blue-500 focus:border-blue-500 " |
|
|
className="block w-full p-2 text-gray-900 border border-gray-300 rounded-lg bg-gray-50 sm:text-xs focus:ring-blue-500 focus:border-blue-500 " |
|
|
placeholder={`${item.name}${!item.required ? `(${t('appDebug.variableTable.optional')})` : ''}`} |
|
|
placeholder={`${item.name}${!item.required ? `(${t('appDebug.variableTable.optional')})` : ''}`} |
|
|
value={inputs[item.key]} |
|
|
value={inputs[item.key]} |
|
|
onChange={(e) => { onInputsChange({ ...inputs, [item.key]: e.target.value }) }} |
|
|
|
|
|
|
|
|
onChange={(e) => { handleInputsChange({ ...inputsRef.current, [item.key]: e.target.value }) }} |
|
|
maxLength={item.max_length || DEFAULT_VALUE_MAX_LEN} |
|
|
maxLength={item.max_length || DEFAULT_VALUE_MAX_LEN} |
|
|
/> |
|
|
/> |
|
|
)} |
|
|
)} |
|
|
|
|
|
|
|
|
className='h-[104px] sm:text-xs' |
|
|
className='h-[104px] sm:text-xs' |
|
|
placeholder={`${item.name}${!item.required ? `(${t('appDebug.variableTable.optional')})` : ''}`} |
|
|
placeholder={`${item.name}${!item.required ? `(${t('appDebug.variableTable.optional')})` : ''}`} |
|
|
value={inputs[item.key]} |
|
|
value={inputs[item.key]} |
|
|
onChange={(e) => { onInputsChange({ ...inputs, [item.key]: e.target.value }) }} |
|
|
|
|
|
|
|
|
onChange={(e) => { handleInputsChange({ ...inputsRef.current, [item.key]: e.target.value }) }} |
|
|
/> |
|
|
/> |
|
|
)} |
|
|
)} |
|
|
{item.type === 'number' && ( |
|
|
{item.type === 'number' && ( |
|
|
|
|
|
|
|
|
className="block w-full p-2 text-gray-900 border border-gray-300 rounded-lg bg-gray-50 sm:text-xs focus:ring-blue-500 focus:border-blue-500 " |
|
|
className="block w-full p-2 text-gray-900 border border-gray-300 rounded-lg bg-gray-50 sm:text-xs focus:ring-blue-500 focus:border-blue-500 " |
|
|
placeholder={`${item.name}${!item.required ? `(${t('appDebug.variableTable.optional')})` : ''}`} |
|
|
placeholder={`${item.name}${!item.required ? `(${t('appDebug.variableTable.optional')})` : ''}`} |
|
|
value={inputs[item.key]} |
|
|
value={inputs[item.key]} |
|
|
onChange={(e) => { onInputsChange({ ...inputs, [item.key]: e.target.value }) }} |
|
|
|
|
|
|
|
|
onChange={(e) => { handleInputsChange({ ...inputsRef.current, [item.key]: e.target.value }) }} |
|
|
/> |
|
|
/> |
|
|
)} |
|
|
)} |
|
|
{item.type === 'file' && ( |
|
|
{item.type === 'file' && ( |
|
|
<FileUploaderInAttachmentWrapper |
|
|
<FileUploaderInAttachmentWrapper |
|
|
onChange={(files) => { onInputsChange({ ...inputs, [item.key]: getProcessedFiles(files)[0] }) }} |
|
|
|
|
|
|
|
|
onChange={(files) => { handleInputsChange({ ...inputsRef.current, [item.key]: getProcessedFiles(files)[0] }) }} |
|
|
fileConfig={{ |
|
|
fileConfig={{ |
|
|
...item.config, |
|
|
...item.config, |
|
|
fileUploadConfig: (visionConfig as any).fileUploadConfig, |
|
|
fileUploadConfig: (visionConfig as any).fileUploadConfig, |
|
|
|
|
|
|
|
|
)} |
|
|
)} |
|
|
{item.type === 'file-list' && ( |
|
|
{item.type === 'file-list' && ( |
|
|
<FileUploaderInAttachmentWrapper |
|
|
<FileUploaderInAttachmentWrapper |
|
|
onChange={(files) => { onInputsChange({ ...inputs, [item.key]: getProcessedFiles(files) }) }} |
|
|
|
|
|
|
|
|
onChange={(files) => { handleInputsChange({ ...inputsRef.current, [item.key]: getProcessedFiles(files) }) }} |
|
|
fileConfig={{ |
|
|
fileConfig={{ |
|
|
...item.config, |
|
|
...item.config, |
|
|
fileUploadConfig: (visionConfig as any).fileUploadConfig, |
|
|
fileUploadConfig: (visionConfig as any).fileUploadConfig, |