fix(agentflow): handle empty form object in form-input mode#6176
fix(agentflow): handle empty form object in form-input mode#6176octo-patch wants to merge 1 commit intoFlowiseAI:mainfrom
Conversation
…owiseAI#6013) When an AgentFlow V2 uses Form Input on the Start node, subsequent messages from the embed chat arrive with an empty form payload and no question field. Because an empty object is truthy in JavaScript, the previous code treated it as a populated form, producing an empty string as both finalInput and finalUserInput. This caused chat messages stored in the database to appear blank and prevented the flow from receiving any user input after the initial form submission. Changes: - Use an explicit incomingFormHasData guard (checking Object.keys length) instead of bare truthiness checks before using incomingInput.form - Apply the same guard when computing finalUserInput for formInput flows - The question-and-form validation now only fires when the form actually contains data, allowing callers to send question alongside empty form
There was a problem hiding this comment.
Code Review
The pull request refactors form input handling in buildAgentflow.ts by introducing explicit checks for non-empty form data before processing. This includes creating incomingFormHasData in executeNode and adding Object.keys(form).length > 0 in executeAgentFlow, along with removing a redundant nullish coalescing in the latter. A review comment suggests that the || {} in executeNode is now also redundant and should be removed for consistency.
| finalInput = uploadedFilesContent ? `${uploadedFilesContent}\n\n${incomingInput.question}` : incomingInput.question | ||
| } else if (incomingInput.form) { | ||
| } else if (incomingFormHasData) { | ||
| finalInput = Object.entries(incomingInput.form || {}) |
There was a problem hiding this comment.
Since incomingFormHasData already ensures that incomingInput.form is a non-null object, the nullish coalescing with {} is no longer necessary here. Removing it would also make this code consistent with the change in executeAgentFlow where a similar || {} was removed.
finalInput = Object.entries(incomingInput.form)
Fixes #6013
Problem
When an AgentFlow V2 uses Form Input on the Start node, subsequent messages from the embed chat (or share link) arrive at the server with an empty
form: {}payload and noquestionfield:{"chatId":"...","form":{},"overrideConfig":{},"streaming":true}Because an empty object is truthy in JavaScript, the existing code branches treated
form: {}as a populated form. This caused two issues:finalInputwas set to""(empty string fromObject.entries({}).join('\n')) instead of falling through to the user'squestionfinalUserInput(the content saved to theChatMessagetable) was also set to"", causing blank user messages to be stored in the databaseif (incomingInput.question && incomingInput.form)would erroneously throw if a caller sentquestionalongside an emptyform: {}Solution
Introduce an explicit
incomingFormHasDatacheck (Object.keys(form).length > 0) instead of relying on bare object truthiness:incomingInput.formas real form data when it actually contains keysfinalUserInputforformInputflowsquestionand a non-emptyformare present simultaneouslyThis allows the server to correctly fall back to the
questionfield when an emptyform: {}is sent, and stores a meaningful user message in the database.Testing
buildAgentflow.ts