Skip to content

Commit 7d9e151

Browse files
authored
Bugfix/Upsert files override (#3569)
add fix for upsert files
1 parent a2c36b4 commit 7d9e151

File tree

3 files changed

+43
-9
lines changed

3 files changed

+43
-9
lines changed

packages/server/src/Interface.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,5 +288,21 @@ export interface ICustomTemplate {
288288
usecases?: string
289289
}
290290

291+
export interface INodeOverrides {
292+
[key: string]: {
293+
label: string
294+
name: string
295+
type: string
296+
enabled: boolean
297+
}[]
298+
}
299+
300+
export interface IVariableOverride {
301+
id: string
302+
name: string
303+
type: 'static' | 'runtime'
304+
enabled: boolean
305+
}
306+
291307
// DocumentStore related
292308
export * from './Interface.DocumentStore'

packages/server/src/utils/index.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ import {
1212
INodeData,
1313
INodeDependencies,
1414
INodeDirectedGraph,
15+
INodeOverrides,
1516
INodeQueue,
1617
IOverrideConfig,
1718
IReactFlowEdge,
1819
IReactFlowNode,
1920
IVariableDict,
21+
IVariableOverride,
2022
IncomingInput
2123
} from '../Interface'
2224
import { cloneDeep, get, isEqual } from 'lodash'
@@ -436,8 +438,8 @@ type BuildFlowParams = {
436438
appDataSource: DataSource
437439
overrideConfig?: ICommonObject
438440
apiOverrideStatus?: boolean
439-
nodeOverrides?: ICommonObject
440-
variableOverrides?: ICommonObject[]
441+
nodeOverrides?: INodeOverrides
442+
variableOverrides?: IVariableOverride[]
441443
cachePool?: CachePool
442444
isUpsert?: boolean
443445
stopNodeId?: string
@@ -1000,15 +1002,15 @@ export const resolveVariables = async (
10001002
* Loop through each inputs and replace their value with override config values
10011003
* @param {INodeData} flowNodeData
10021004
* @param {ICommonObject} overrideConfig
1003-
* @param {ICommonObject} nodeOverrides
1004-
* @param {ICommonObject[]} variableOverrides
1005+
* @param {INodeOverrides} nodeOverrides
1006+
* @param {IVariableOverride[]} variableOverrides
10051007
* @returns {INodeData}
10061008
*/
10071009
export const replaceInputsWithConfig = (
10081010
flowNodeData: INodeData,
10091011
overrideConfig: ICommonObject,
1010-
nodeOverrides: ICommonObject,
1011-
variableOverrides: ICommonObject[]
1012+
nodeOverrides: INodeOverrides,
1013+
variableOverrides: IVariableOverride[]
10121014
) => {
10131015
const types = 'inputs'
10141016

@@ -1676,9 +1678,12 @@ export const aMonthAgo = () => {
16761678
export const getAPIOverrideConfig = (chatflow: IChatFlow) => {
16771679
try {
16781680
const apiConfig = chatflow.apiConfig ? JSON.parse(chatflow.apiConfig) : {}
1679-
const nodeOverrides = apiConfig.overrideConfig && apiConfig.overrideConfig.nodes ? apiConfig.overrideConfig.nodes : {}
1680-
const variableOverrides = apiConfig.overrideConfig && apiConfig.overrideConfig.variables ? apiConfig.overrideConfig.variables : []
1681-
const apiOverrideStatus = apiConfig.overrideConfig && apiConfig.overrideConfig.status ? apiConfig.overrideConfig.status : false
1681+
const nodeOverrides: INodeOverrides =
1682+
apiConfig.overrideConfig && apiConfig.overrideConfig.nodes ? apiConfig.overrideConfig.nodes : {}
1683+
const variableOverrides: IVariableOverride[] =
1684+
apiConfig.overrideConfig && apiConfig.overrideConfig.variables ? apiConfig.overrideConfig.variables : []
1685+
const apiOverrideStatus: boolean =
1686+
apiConfig.overrideConfig && apiConfig.overrideConfig.status ? apiConfig.overrideConfig.status : false
16821687

16831688
return { nodeOverrides, variableOverrides, apiOverrideStatus }
16841689
} catch (error) {

packages/server/src/utils/upsertVector.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,19 @@ export const upsertVector = async (req: Request, isInternal: boolean = false) =>
159159
/*** Get API Config ***/
160160
const { nodeOverrides, variableOverrides, apiOverrideStatus } = getAPIOverrideConfig(chatflow)
161161

162+
// For "files" input, add a new node override with the actual input name such as pdfFile, txtFile, etc.
163+
for (const nodeLabel in nodeOverrides) {
164+
const params = nodeOverrides[nodeLabel]
165+
const enabledFileParam = params.find((param) => param.enabled && param.name === 'files')
166+
if (enabledFileParam) {
167+
const fileInputFieldFromExt = mapExtToInputField(enabledFileParam.type)
168+
nodeOverrides[nodeLabel].push({
169+
...enabledFileParam,
170+
name: fileInputFieldFromExt
171+
})
172+
}
173+
}
174+
162175
const upsertedResult = await buildFlow({
163176
startingNodeIds,
164177
reactFlowNodes: nodes,

0 commit comments

Comments
 (0)