diff --git a/server/endpoints/api/workspaceThread/index.js b/server/endpoints/api/workspaceThread/index.js index 66c3a6844..e7f53698a 100644 --- a/server/endpoints/api/workspaceThread/index.js +++ b/server/endpoints/api/workspaceThread/index.js @@ -3,10 +3,7 @@ const { WorkspaceThread } = require("../../../models/workspaceThread"); const { Workspace } = require("../../../models/workspace"); const { validApiKey } = require("../../../utils/middleware/validApiKey"); const { reqBody, multiUserMode } = require("../../../utils/http"); -const { - streamChatWithWorkspace, - VALID_CHAT_MODE, -} = require("../../../utils/chats/stream"); +const { VALID_CHAT_MODE } = require("../../../utils/chats/stream"); const { Telemetry } = require("../../../models/telemetry"); const { EventLogs } = require("../../../models/eventLogs"); const { @@ -71,7 +68,7 @@ function apiWorkspaceThreadEndpoints(app) { */ try { const { slug } = request.params; - const { userId } = reqBody(request); + let { userId = null } = reqBody(request); const workspace = await Workspace.get({ slug }); if (!workspace) { @@ -79,6 +76,11 @@ function apiWorkspaceThreadEndpoints(app) { return; } + // If the system is not multi-user and you pass in a userId + // it needs to be nullified as no users exist. This can still fail validation + // as we don't check if the userID is valid. + if (!response.locals.multiUserMode && !!userId) userId = null; + const { thread, message } = await WorkspaceThread.new( workspace, userId ? Number(userId) : null