Make userId actually optional for workspaceThread endpoint (#2276)

This commit is contained in:
Timothy Carambat 2024-09-12 13:33:41 -07:00 committed by GitHub
parent 906eb70ca1
commit 0cbe4d0b04
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -3,10 +3,7 @@ const { WorkspaceThread } = require("../../../models/workspaceThread");
const { Workspace } = require("../../../models/workspace"); const { Workspace } = require("../../../models/workspace");
const { validApiKey } = require("../../../utils/middleware/validApiKey"); const { validApiKey } = require("../../../utils/middleware/validApiKey");
const { reqBody, multiUserMode } = require("../../../utils/http"); const { reqBody, multiUserMode } = require("../../../utils/http");
const { const { VALID_CHAT_MODE } = require("../../../utils/chats/stream");
streamChatWithWorkspace,
VALID_CHAT_MODE,
} = require("../../../utils/chats/stream");
const { Telemetry } = require("../../../models/telemetry"); const { Telemetry } = require("../../../models/telemetry");
const { EventLogs } = require("../../../models/eventLogs"); const { EventLogs } = require("../../../models/eventLogs");
const { const {
@ -71,7 +68,7 @@ function apiWorkspaceThreadEndpoints(app) {
*/ */
try { try {
const { slug } = request.params; const { slug } = request.params;
const { userId } = reqBody(request); let { userId = null } = reqBody(request);
const workspace = await Workspace.get({ slug }); const workspace = await Workspace.get({ slug });
if (!workspace) { if (!workspace) {
@ -79,6 +76,11 @@ function apiWorkspaceThreadEndpoints(app) {
return; 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( const { thread, message } = await WorkspaceThread.new(
workspace, workspace,
userId ? Number(userId) : null userId ? Number(userId) : null