diff --git a/packages/components/src/utils.ts b/packages/components/src/utils.ts index e811dd15b..1f24fb813 100644 --- a/packages/components/src/utils.ts +++ b/packages/components/src/utils.ts @@ -943,10 +943,13 @@ export const getVars = async ( nodeData: INodeData, options: ICommonObject ) => { + if (!options.workspaceId) { + return [] + } const variables = ((await appDataSource .getRepository(databaseEntities['Variable']) - .findBy(options.workspaceId ? { workspaceId: Equal(options.workspaceId) } : {})) as IVariable[]) ?? [] + .findBy({ workspaceId: Equal(options.workspaceId) })) as IVariable[]) ?? [] // override variables defined in overrideConfig // nodeData.inputs.vars is an Object, check each property and override the variable diff --git a/packages/server/src/controllers/nodes/index.ts b/packages/server/src/controllers/nodes/index.ts index 5c7295d8d..b6b96cf49 100644 --- a/packages/server/src/controllers/nodes/index.ts +++ b/packages/server/src/controllers/nodes/index.ts @@ -86,7 +86,8 @@ const executeCustomFunction = async (req: Request, res: Response, next: NextFunc ) } const orgId = req.user?.activeOrganizationId - const apiResponse = await nodesService.executeCustomFunction(req.body, orgId) + const workspaceId = req.user?.activeWorkspaceId + const apiResponse = await nodesService.executeCustomFunction(req.body, workspaceId, orgId) return res.json(apiResponse) } catch (error) { next(error) diff --git a/packages/server/src/services/nodes/index.ts b/packages/server/src/services/nodes/index.ts index a709a8bd2..9a64cb55b 100644 --- a/packages/server/src/services/nodes/index.ts +++ b/packages/server/src/services/nodes/index.ts @@ -122,14 +122,15 @@ const getSingleNodeAsyncOptions = async (nodeName: string, requestBody: any): Pr } // execute custom function node -const executeCustomFunction = async (requestBody: any, orgId?: string) => { +const executeCustomFunction = async (requestBody: any, workspaceId?: string, orgId?: string) => { const appServer = getRunningExpressApp() const executeData = { appDataSource: appServer.AppDataSource, componentNodes: appServer.nodesPool.componentNodes, data: requestBody, isExecuteCustomFunction: true, - orgId + orgId, + workspaceId } if (process.env.MODE === MODE.QUEUE) { diff --git a/packages/server/src/services/openai-realtime/index.ts b/packages/server/src/services/openai-realtime/index.ts index ed6462027..8877474bd 100644 --- a/packages/server/src/services/openai-realtime/index.ts +++ b/packages/server/src/services/openai-realtime/index.ts @@ -147,6 +147,7 @@ const buildAndInitTool = async (chatflowid: string, _chatId?: string, _apiMessag chatflowid, chatId, orgId, + workspaceId, appDataSource: appServer.AppDataSource, databaseEntities, analytic: chatflow.analytic diff --git a/packages/server/src/utils/buildChatflow.ts b/packages/server/src/utils/buildChatflow.ts index 195c54b97..d71f4f27a 100644 --- a/packages/server/src/utils/buildChatflow.ts +++ b/packages/server/src/utils/buildChatflow.ts @@ -750,6 +750,8 @@ export const executeFlow = async ({ rawOutput: resultText, appDataSource, databaseEntities, + workspaceId, + orgId, logger } const customFuncNodeInstance = new nodeModule.nodeClass() diff --git a/packages/server/src/utils/createAttachment.ts b/packages/server/src/utils/createAttachment.ts index 3e5aeec94..d1e7ceaaa 100644 --- a/packages/server/src/utils/createAttachment.ts +++ b/packages/server/src/utils/createAttachment.ts @@ -100,6 +100,7 @@ export const createFileAttachment = async (req: Request) => { const options = { retrieveAttachmentChatId: true, orgId, + workspaceId, chatflowid, chatId } diff --git a/packages/server/src/utils/executeCustomNodeFunction.ts b/packages/server/src/utils/executeCustomNodeFunction.ts index a22a0291a..b0da4bf9c 100644 --- a/packages/server/src/utils/executeCustomNodeFunction.ts +++ b/packages/server/src/utils/executeCustomNodeFunction.ts @@ -9,11 +9,15 @@ import { IComponentNodes } from '../Interface' export const executeCustomNodeFunction = async ({ appDataSource, componentNodes, - data + data, + workspaceId, + orgId }: { appDataSource: DataSource componentNodes: IComponentNodes data: any + workspaceId?: string + orgId?: string }) => { try { const body = data @@ -37,7 +41,9 @@ export const executeCustomNodeFunction = async ({ const options: ICommonObject = { appDataSource, - databaseEntities + databaseEntities, + workspaceId, + orgId } const returnData = await newNodeInstance.init(nodeData, '', options)