diff --git a/packages/server/src/Interface.ts b/packages/server/src/Interface.ts index c8b981d501..73708439fd 100644 --- a/packages/server/src/Interface.ts +++ b/packages/server/src/Interface.ts @@ -288,5 +288,21 @@ export interface ICustomTemplate { usecases?: string } +export interface INodeOverrides { + [key: string]: { + label: string + name: string + type: string + enabled: boolean + }[] +} + +export interface IVariableOverride { + id: string + name: string + type: 'static' | 'runtime' + enabled: boolean +} + // DocumentStore related export * from './Interface.DocumentStore' diff --git a/packages/server/src/utils/index.ts b/packages/server/src/utils/index.ts index 9410a1b51b..6072594666 100644 --- a/packages/server/src/utils/index.ts +++ b/packages/server/src/utils/index.ts @@ -12,11 +12,13 @@ import { INodeData, INodeDependencies, INodeDirectedGraph, + INodeOverrides, INodeQueue, IOverrideConfig, IReactFlowEdge, IReactFlowNode, IVariableDict, + IVariableOverride, IncomingInput } from '../Interface' import { cloneDeep, get, isEqual } from 'lodash' @@ -436,8 +438,8 @@ type BuildFlowParams = { appDataSource: DataSource overrideConfig?: ICommonObject apiOverrideStatus?: boolean - nodeOverrides?: ICommonObject - variableOverrides?: ICommonObject[] + nodeOverrides?: INodeOverrides + variableOverrides?: IVariableOverride[] cachePool?: CachePool isUpsert?: boolean stopNodeId?: string @@ -1000,15 +1002,15 @@ export const resolveVariables = async ( * Loop through each inputs and replace their value with override config values * @param {INodeData} flowNodeData * @param {ICommonObject} overrideConfig - * @param {ICommonObject} nodeOverrides - * @param {ICommonObject[]} variableOverrides + * @param {INodeOverrides} nodeOverrides + * @param {IVariableOverride[]} variableOverrides * @returns {INodeData} */ export const replaceInputsWithConfig = ( flowNodeData: INodeData, overrideConfig: ICommonObject, - nodeOverrides: ICommonObject, - variableOverrides: ICommonObject[] + nodeOverrides: INodeOverrides, + variableOverrides: IVariableOverride[] ) => { const types = 'inputs' @@ -1676,9 +1678,12 @@ export const aMonthAgo = () => { export const getAPIOverrideConfig = (chatflow: IChatFlow) => { try { const apiConfig = chatflow.apiConfig ? JSON.parse(chatflow.apiConfig) : {} - const nodeOverrides = apiConfig.overrideConfig && apiConfig.overrideConfig.nodes ? apiConfig.overrideConfig.nodes : {} - const variableOverrides = apiConfig.overrideConfig && apiConfig.overrideConfig.variables ? apiConfig.overrideConfig.variables : [] - const apiOverrideStatus = apiConfig.overrideConfig && apiConfig.overrideConfig.status ? apiConfig.overrideConfig.status : false + const nodeOverrides: INodeOverrides = + apiConfig.overrideConfig && apiConfig.overrideConfig.nodes ? apiConfig.overrideConfig.nodes : {} + const variableOverrides: IVariableOverride[] = + apiConfig.overrideConfig && apiConfig.overrideConfig.variables ? apiConfig.overrideConfig.variables : [] + const apiOverrideStatus: boolean = + apiConfig.overrideConfig && apiConfig.overrideConfig.status ? apiConfig.overrideConfig.status : false return { nodeOverrides, variableOverrides, apiOverrideStatus } } catch (error) { diff --git a/packages/server/src/utils/upsertVector.ts b/packages/server/src/utils/upsertVector.ts index ad01bf5052..4d3cb5858b 100644 --- a/packages/server/src/utils/upsertVector.ts +++ b/packages/server/src/utils/upsertVector.ts @@ -159,6 +159,19 @@ export const upsertVector = async (req: Request, isInternal: boolean = false) => /*** Get API Config ***/ const { nodeOverrides, variableOverrides, apiOverrideStatus } = getAPIOverrideConfig(chatflow) + // For "files" input, add a new node override with the actual input name such as pdfFile, txtFile, etc. + for (const nodeLabel in nodeOverrides) { + const params = nodeOverrides[nodeLabel] + const enabledFileParam = params.find((param) => param.enabled && param.name === 'files') + if (enabledFileParam) { + const fileInputFieldFromExt = mapExtToInputField(enabledFileParam.type) + nodeOverrides[nodeLabel].push({ + ...enabledFileParam, + name: fileInputFieldFromExt + }) + } + } + const upsertedResult = await buildFlow({ startingNodeIds, reactFlowNodes: nodes,