@@ -43,7 +43,7 @@ import type { ChatNodeUsageType } from '@fastgpt/global/support/wallet/bill/type
4343import { addLog } from '../../../common/system/log' ;
4444import { surrenderProcess } from '../../../common/system/tools' ;
4545import type { DispatchFlowResponse , WorkflowDebugResponse } from './type' ;
46- import { rewriteRuntimeWorkFlow , removeSystemVariable } from './utils' ;
46+ import { rewriteRuntimeWorkFlow , runtimeSystemVar2StoreType } from './utils' ;
4747import { getHandleId } from '@fastgpt/global/core/workflow/utils' ;
4848import { callbackMap } from './constants' ;
4949import { anyValueDecrypt } from '../../../common/secret/utils' ;
@@ -79,7 +79,16 @@ export async function dispatchWorkFlow({
7979 concatUsage,
8080 ...data
8181} : Props & WorkflowUsageProps ) : Promise < DispatchFlowResponse > {
82- const { res, stream, runningUserInfo, runningAppInfo, lastInteractive, histories, query } = data ;
82+ const {
83+ res,
84+ stream,
85+ runningUserInfo,
86+ runningAppInfo,
87+ lastInteractive,
88+ histories,
89+ query,
90+ chatConfig
91+ } = data ;
8392
8493 await checkTeamAIPoints ( runningUserInfo . teamId ) ;
8594 const [ { timezone, externalProvider } , newUsageId ] = await Promise . all ( [
@@ -141,14 +150,15 @@ export async function dispatchWorkFlow({
141150 }
142151
143152 // Get default variables
153+
144154 const defaultVariables = {
145155 ...externalProvider . externalWorkflowVariables ,
146- ...getSystemVariables ( {
156+ ...( await getSystemVariables ( {
147157 ...data ,
148158 query,
149159 histories,
150160 timezone
151- } )
161+ } ) )
152162 } ;
153163
154164 // Init some props
@@ -211,11 +221,11 @@ export const runWorkflow = async (data: RunWorkflowProps): Promise<DispatchFlowR
211221 [ DispatchNodeResponseKeyEnum . runTimes ] : 1 ,
212222 [ DispatchNodeResponseKeyEnum . assistantResponses ] : [ ] ,
213223 [ DispatchNodeResponseKeyEnum . toolResponses ] : null ,
214- newVariables : removeSystemVariable (
224+ [ DispatchNodeResponseKeyEnum . newVariables ] : runtimeSystemVar2StoreType ( {
215225 variables,
216- externalProvider . externalWorkflowVariables ,
217- data . chatConfig ?. variables
218- ) ,
226+ removeObj : externalProvider . externalWorkflowVariables ,
227+ userVariablesConfigs : data . chatConfig ?. variables
228+ } ) ,
219229 durationSeconds : 0
220230 } ;
221231 }
@@ -983,12 +993,6 @@ export const runWorkflow = async (data: RunWorkflowProps): Promise<DispatchFlowR
983993 } ) ;
984994 }
985995
986- const encryptedNewVariables = removeSystemVariable (
987- variables ,
988- externalProvider . externalWorkflowVariables ,
989- data . chatConfig ?. variables
990- ) ;
991-
992996 return {
993997 flowResponses : workflowQueue . chatResponses ,
994998 flowUsages : workflowQueue . chatNodeUsages ,
@@ -999,7 +1003,11 @@ export const runWorkflow = async (data: RunWorkflowProps): Promise<DispatchFlowR
9991003 workflowQueue . chatAssistantResponse
10001004 ) ,
10011005 [ DispatchNodeResponseKeyEnum . toolResponses ] : workflowQueue . toolRunResponse ,
1002- [ DispatchNodeResponseKeyEnum . newVariables ] : encryptedNewVariables ,
1006+ [ DispatchNodeResponseKeyEnum . newVariables ] : runtimeSystemVar2StoreType ( {
1007+ variables,
1008+ removeObj : externalProvider . externalWorkflowVariables ,
1009+ userVariablesConfigs : data . chatConfig ?. variables
1010+ } ) ,
10031011 [ DispatchNodeResponseKeyEnum . memories ] :
10041012 Object . keys ( workflowQueue . system_memories ) . length > 0
10051013 ? workflowQueue . system_memories
@@ -1009,7 +1017,7 @@ export const runWorkflow = async (data: RunWorkflowProps): Promise<DispatchFlowR
10091017} ;
10101018
10111019/* get system variable */
1012- const getSystemVariables = ( {
1020+ const getSystemVariables = async ( {
10131021 timezone,
10141022 runningAppInfo,
10151023 chatId,
@@ -1020,30 +1028,29 @@ const getSystemVariables = ({
10201028 variables
10211029} : Props & {
10221030 timezone : string ;
1023- } ) : SystemVariablesType => {
1031+ } ) : Promise < SystemVariablesType > => {
10241032 // Get global variables(Label -> key; Key -> key)
10251033 const variablesConfig = chatConfig ?. variables || [ ] ;
10261034
1027- const variablesMap = variablesConfig . reduce < Record < string , any > > ( ( acc , item ) => {
1035+ const variablesMap : Record < string , any > = { } ;
1036+ for await ( const item of variablesConfig ) {
10281037 // For internal variables, ignore external input and use default value
10291038 if ( item . type === VariableInputEnum . password ) {
10301039 const val = variables [ item . label ] || variables [ item . key ] || item . defaultValue ;
10311040 const actualValue = anyValueDecrypt ( val ) ;
1032- acc [ item . key ] = valueTypeFormat ( actualValue , item . valueType ) ;
1041+ variablesMap [ item . key ] = valueTypeFormat ( actualValue , item . valueType ) ;
10331042 }
1034-
10351043 // API
10361044 else if ( variables [ item . label ] !== undefined ) {
1037- acc [ item . key ] = valueTypeFormat ( variables [ item . label ] , item . valueType ) ;
1045+ variablesMap [ item . key ] = valueTypeFormat ( variables [ item . label ] , item . valueType ) ;
10381046 }
10391047 // Web
10401048 else if ( variables [ item . key ] !== undefined ) {
1041- acc [ item . key ] = valueTypeFormat ( variables [ item . key ] , item . valueType ) ;
1049+ variablesMap [ item . key ] = valueTypeFormat ( variables [ item . key ] , item . valueType ) ;
10421050 } else {
1043- acc [ item . key ] = valueTypeFormat ( item . defaultValue , item . valueType ) ;
1051+ variablesMap [ item . key ] = valueTypeFormat ( item . defaultValue , item . valueType ) ;
10441052 }
1045- return acc ;
1046- } , { } ) ;
1053+ }
10471054
10481055 return {
10491056 ...variablesMap ,
0 commit comments