feat(ai): gracefully handle ui message validation in output-error scenarios #8302
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Background
The
validateUIMessages
utility function does not cover the potentialinput
and
rawInput
states foroutput-error
scenarios properly. In the case that atool fails due to a schematic error in
input
, the validation of thatToolUIPart
of{ state: "output-error" }
fails its schematic check againstthe tool's
inputSchema
, creating an invalid messages array despite the arraybeing technically valid based on it's type. see ToolUIPart
The main reason this happens is due to:
that the type defines
output-error
scenario still forces a schematic check on the input, even if theinput does not exist. In these scenarios, the part returned actually uses the
rawInput
property to portray that failed input.
The tests for this function do not cover this particular state, which allows the
test-suite to pass gracefully despite this potential state occurring in real-world
scenarios.
Manual Verification
output-error
's.Tasks
pnpm prettier-fix
in the project root)