Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions app/components/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -304,11 +304,13 @@ const Main: FC<IMainProps> = () => {

if (!currInputs || !promptConfig?.prompt_variables) { return true }

const inputLens = Object.values(currInputs).length
const promptVariablesLens = promptConfig.prompt_variables.length
let emptyRequiredInput = false
promptConfig.prompt_variables.forEach((item) => {
if (item.required && !currInputs[item.key])
emptyRequiredInput = true
})

const emptyInput = inputLens < promptVariablesLens || Object.values(currInputs).find(v => !v)
if (emptyInput) {
if (emptyRequiredInput) {
logError(t('app.errorMessage.valueOfVarRequired'))
return false
}
Expand Down
35 changes: 24 additions & 11 deletions app/components/welcome/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,22 +172,35 @@ const Welcome: FC<IWelcomeProps> = ({
}

const canChat = () => {
const inputLens = Object.values(inputs).length
const promptVariablesLens = promptConfig.prompt_variables.length
const emptyInput = inputLens < promptVariablesLens || Object.entries(inputs).filter(([k, v]) => {
const isRequired = promptConfig.prompt_variables.find(item => item.key === k)?.required ?? true
return isRequired && v === ''
}).length > 0
if (emptyInput) {
logError(t('app.errorMessage.valueOfVarRequired'))
return false
const vars = promptConfig?.prompt_variables ?? [];

const hasEmptyRequired = vars.some(v => {
const isRequired = v?.required ?? true;
if (!isRequired) return false;

const val = inputs?.[v.key];

if (typeof val === 'string') return val.trim() === '';

return val === undefined || val === null;
});

if (hasEmptyRequired) {
logError(t('app.errorMessage.valueOfVarRequired'));
return false;
}
return true
}

return true;
};

const handleChat = () => {
if (!canChat()) { return }

Object.keys(inputs).forEach((key) => {
if (!inputs[key])
delete inputs[key]
})

onStartChat(inputs)
}

Expand Down