fix: validate chat message input (#4811)

* fix: validate chat message input

* fix: align message validation for thread stream-chat endpoint

---------

Co-authored-by: Timothy Carambat <rambat1010@gmail.com>
This commit is contained in:
Ocheretovich
2026-01-09 03:00:15 +02:00
committed by GitHub
parent ebe8b146f5
commit 54b4b34b75

View File

@@ -30,14 +30,14 @@ function chatEndpoints(app) {
const { message, attachments = [] } = reqBody(request);
const workspace = response.locals.workspace;
if (!message?.length) {
if (typeof message !== "string" || message.trim().length === 0) {
response.status(400).json({
id: uuidv4(),
type: "abort",
textResponse: null,
sources: [],
close: true,
error: !message?.length ? "Message is empty." : null,
error: "Message is empty.",
});
return;
}
@@ -117,14 +117,14 @@ function chatEndpoints(app) {
const workspace = response.locals.workspace;
const thread = response.locals.thread;
if (!message?.length) {
if (typeof message !== "string" || message.trim().length === 0) {
response.status(400).json({
id: uuidv4(),
type: "abort",
textResponse: null,
sources: [],
close: true,
error: !message?.length ? "Message is empty." : null,
error: "Message is empty.",
});
return;
}