Commit e05ae8a3 by Archer Committed by GitHub

fix: child workflow variable default value not init (#6620)

parent 37bbccdc
---
title: 'V4.14.10(进行中)'
description: 'FastGPT V4.14.10 更新说明'
---
## 🚀 新增内容
## ⚙️ 优化
## 🐛 修复
1. 子工作流的全局变量默认值未生效。
\ No newline at end of file
{ {
"title": "4.14.x", "title": "4.14.x",
"description": "", "description": "",
"pages": ["4149", "4148", "4147", "4146", "41451", "4145", "4144", "4143", "4142", "4141", "4140"] "pages": [
"41410",
"4149",
"4148",
"4147",
"4146",
"41451",
"4145",
"4144",
"4143",
"4142",
"4141",
"4140"
]
} }
...@@ -112,6 +112,7 @@ description: FastGPT 文档目录 ...@@ -112,6 +112,7 @@ description: FastGPT 文档目录
- [/docs/self-host/upgrading/4-13/4132](/docs/self-host/upgrading/4-13/4132) - [/docs/self-host/upgrading/4-13/4132](/docs/self-host/upgrading/4-13/4132)
- [/docs/self-host/upgrading/4-14/4140](/docs/self-host/upgrading/4-14/4140) - [/docs/self-host/upgrading/4-14/4140](/docs/self-host/upgrading/4-14/4140)
- [/docs/self-host/upgrading/4-14/4141](/docs/self-host/upgrading/4-14/4141) - [/docs/self-host/upgrading/4-14/4141](/docs/self-host/upgrading/4-14/4141)
- [/docs/self-host/upgrading/4-14/41410](/docs/self-host/upgrading/4-14/41410)
- [/docs/self-host/upgrading/4-14/4142](/docs/self-host/upgrading/4-14/4142) - [/docs/self-host/upgrading/4-14/4142](/docs/self-host/upgrading/4-14/4142)
- [/docs/self-host/upgrading/4-14/4143](/docs/self-host/upgrading/4-14/4143) - [/docs/self-host/upgrading/4-14/4143](/docs/self-host/upgrading/4-14/4143)
- [/docs/self-host/upgrading/4-14/4144](/docs/self-host/upgrading/4-14/4144) - [/docs/self-host/upgrading/4-14/4144](/docs/self-host/upgrading/4-14/4144)
......
...@@ -239,7 +239,7 @@ ...@@ -239,7 +239,7 @@
"document/content/docs/self-host/upgrading/4-14/41481.en.mdx": "2026-03-09T12:02:02+08:00", "document/content/docs/self-host/upgrading/4-14/41481.en.mdx": "2026-03-09T12:02:02+08:00",
"document/content/docs/self-host/upgrading/4-14/41481.mdx": "2026-03-09T17:39:53+08:00", "document/content/docs/self-host/upgrading/4-14/41481.mdx": "2026-03-09T17:39:53+08:00",
"document/content/docs/self-host/upgrading/4-14/4149.en.mdx": "2026-03-23T12:17:04+08:00", "document/content/docs/self-host/upgrading/4-14/4149.en.mdx": "2026-03-23T12:17:04+08:00",
"document/content/docs/self-host/upgrading/4-14/4149.mdx": "2026-03-23T23:36:16+08:00", "document/content/docs/self-host/upgrading/4-14/4149.mdx": "2026-03-23T23:36:27+08:00",
"document/content/docs/self-host/upgrading/outdated/40.en.mdx": "2026-03-03T17:39:47+08:00", "document/content/docs/self-host/upgrading/outdated/40.en.mdx": "2026-03-03T17:39:47+08:00",
"document/content/docs/self-host/upgrading/outdated/40.mdx": "2026-03-03T17:39:47+08:00", "document/content/docs/self-host/upgrading/outdated/40.mdx": "2026-03-03T17:39:47+08:00",
"document/content/docs/self-host/upgrading/outdated/41.en.mdx": "2026-03-03T17:39:47+08:00", "document/content/docs/self-host/upgrading/outdated/41.en.mdx": "2026-03-03T17:39:47+08:00",
......
...@@ -13,7 +13,7 @@ import { ...@@ -13,7 +13,7 @@ import {
import type { NodeInputKeyEnum } from '@fastgpt/global/core/workflow/constants'; import type { NodeInputKeyEnum } from '@fastgpt/global/core/workflow/constants';
import { NodeOutputKeyEnum } from '@fastgpt/global/core/workflow/constants'; import { NodeOutputKeyEnum } from '@fastgpt/global/core/workflow/constants';
import { DispatchNodeResponseKeyEnum } from '@fastgpt/global/core/workflow/runtime/constants'; import { DispatchNodeResponseKeyEnum } from '@fastgpt/global/core/workflow/runtime/constants';
import { filterSystemVariables, getNodeErrResponse, getHistories } from '../utils'; import { getSystemVariables, getNodeErrResponse, getHistories } from '../utils';
import { chatValue2RuntimePrompt, runtimePrompt2ChatsValue } from '@fastgpt/global/core/chat/adapt'; import { chatValue2RuntimePrompt, runtimePrompt2ChatsValue } from '@fastgpt/global/core/chat/adapt';
import { type DispatchNodeResultType } from '@fastgpt/global/core/workflow/runtime/type'; import { type DispatchNodeResultType } from '@fastgpt/global/core/workflow/runtime/type';
import { authAppByTmbId } from '../../../../support/permission/app/auth'; import { authAppByTmbId } from '../../../../support/permission/app/auth';
...@@ -100,13 +100,23 @@ export const dispatchRunAppNode = async (props: Props): Promise<Response> => { ...@@ -100,13 +100,23 @@ export const dispatchRunAppNode = async (props: Props): Promise<Response> => {
const chatHistories = getHistories(history, histories); const chatHistories = getHistories(history, histories);
// Rewrite children app variables // Rewrite children app variables
const systemVariables = filterSystemVariables(variables);
const { externalProvider } = await getUserChatInfo(appData.tmbId); const { externalProvider } = await getUserChatInfo(appData.tmbId);
const childrenRunVariables = { const childrenRunVariables = {
...systemVariables, ...(await getSystemVariables({
...childrenAppVariables, timezone: props.timezone,
histories: chatHistories, runningAppInfo: {
appId: String(appData._id), id: String(appData._id),
teamId: appData.teamId,
tmbId: appData.tmbId,
name: appData.name
},
chatId: props.chatId,
responseChatItemId: props.responseChatItemId,
histories: chatHistories,
uid: props.uid,
chatConfig,
variables: childrenAppVariables
})),
...(externalProvider ? externalProvider.externalWorkflowVariables : {}) ...(externalProvider ? externalProvider.externalWorkflowVariables : {})
}; };
......
import { getNanoid } from '@fastgpt/global/common/string/tools'; import { getNanoid } from '@fastgpt/global/common/string/tools';
import { getSystemTime } from '@fastgpt/global/common/time/timezone';
import { SpanStatusCode } from '@opentelemetry/api'; import { SpanStatusCode } from '@opentelemetry/api';
import type { import type {
AIChatItemValueItemType, AIChatItemValueItemType,
...@@ -12,7 +11,7 @@ import type { ...@@ -12,7 +11,7 @@ import type {
NodeOutputItemType NodeOutputItemType
} from '@fastgpt/global/core/workflow/runtime/type'; } from '@fastgpt/global/core/workflow/runtime/type';
import type { NodeOutputKeyEnum } from '@fastgpt/global/core/workflow/constants'; import type { NodeOutputKeyEnum } from '@fastgpt/global/core/workflow/constants';
import { NodeInputKeyEnum, VariableInputEnum } from '@fastgpt/global/core/workflow/constants'; import { NodeInputKeyEnum } from '@fastgpt/global/core/workflow/constants';
import { import {
FlowNodeInputTypeEnum, FlowNodeInputTypeEnum,
FlowNodeTypeEnum FlowNodeTypeEnum
...@@ -24,8 +23,7 @@ import { ...@@ -24,8 +23,7 @@ import {
import type { import type {
ChatDispatchProps, ChatDispatchProps,
DispatchNodeResultType, DispatchNodeResultType,
ModuleDispatchProps, ModuleDispatchProps
SystemVariablesType
} from '@fastgpt/global/core/workflow/runtime/type'; } from '@fastgpt/global/core/workflow/runtime/type';
import type { RuntimeNodeItemType } from '@fastgpt/global/core/workflow/runtime/type'; import type { RuntimeNodeItemType } from '@fastgpt/global/core/workflow/runtime/type';
import { getErrText, UserError } from '@fastgpt/global/common/error/utils'; import { getErrText, UserError } from '@fastgpt/global/common/error/utils';
...@@ -46,17 +44,21 @@ import type { ChatNodeUsageType } from '@fastgpt/global/support/wallet/bill/type ...@@ -46,17 +44,21 @@ import type { ChatNodeUsageType } from '@fastgpt/global/support/wallet/bill/type
import { getLogger, LogCategories } from '../../../common/logger'; import { getLogger, LogCategories } from '../../../common/logger';
import { surrenderProcess } from '../../../common/system/tools'; import { surrenderProcess } from '../../../common/system/tools';
import type { DispatchFlowResponse, WorkflowDebugResponse } from './type'; import type { DispatchFlowResponse, WorkflowDebugResponse } from './type';
import { rewriteRuntimeWorkFlow, runtimeSystemVar2StoreType, filterOrphanEdges } from './utils'; import {
rewriteRuntimeWorkFlow,
runtimeSystemVar2StoreType,
filterOrphanEdges,
getSystemVariables
} from './utils';
import { getHandleId } from '@fastgpt/global/core/workflow/utils'; import { getHandleId } from '@fastgpt/global/core/workflow/utils';
import { callbackMap } from './constants'; import { callbackMap } from './constants';
import { anyValueDecrypt } from '../../../common/secret/utils';
import { getUserChatInfo } from '../../../support/user/team/utils'; import { getUserChatInfo } from '../../../support/user/team/utils';
import { checkTeamAIPoints } from '../../../support/permission/teamLimit'; import { checkTeamAIPoints } from '../../../support/permission/teamLimit';
import type { UsageSourceEnum } from '@fastgpt/global/support/wallet/usage/constants'; import type { UsageSourceEnum } from '@fastgpt/global/support/wallet/usage/constants';
import { createChatUsageRecord, pushChatItemUsage } from '../../../support/wallet/usage/controller'; import { createChatUsageRecord, pushChatItemUsage } from '../../../support/wallet/usage/controller';
import type { RequireOnlyOne } from '@fastgpt/global/common/type/utils'; import type { RequireOnlyOne } from '@fastgpt/global/common/type/utils';
import { getS3ChatSource } from '../../../common/s3/sources/chat'; import { getS3ChatSource } from '../../../common/s3/sources/chat';
import { addPreviewUrlToChatItems, presignVariablesFileUrls } from '../../chat/utils'; import { addPreviewUrlToChatItems } from '../../chat/utils';
import { TeamErrEnum } from '@fastgpt/global/common/error/code/team'; import { TeamErrEnum } from '@fastgpt/global/common/error/code/team';
import { i18nT } from '../../../../web/i18n/utils'; import { i18nT } from '../../../../web/i18n/utils';
import { validateFileUrlDomain } from '../../../common/security/fileUrlValidator'; import { validateFileUrlDomain } from '../../../common/security/fileUrlValidator';
...@@ -192,10 +194,14 @@ export async function dispatchWorkFlow({ ...@@ -192,10 +194,14 @@ export async function dispatchWorkFlow({
const defaultVariables = { const defaultVariables = {
...externalProvider.externalWorkflowVariables, ...externalProvider.externalWorkflowVariables,
...(await getSystemVariables({ ...(await getSystemVariables({
...data, runningAppInfo: runningAppInfo,
query, chatId: chatId,
histories, responseChatItemId: data.responseChatItemId,
timezone histories: histories,
uid: data.uid,
chatConfig: data.chatConfig,
variables: data.variables,
timezone: timezone
})) }))
}; };
...@@ -1538,63 +1544,6 @@ export const runWorkflow = async (data: RunWorkflowProps): Promise<DispatchFlowR ...@@ -1538,63 +1544,6 @@ export const runWorkflow = async (data: RunWorkflowProps): Promise<DispatchFlowR
); );
}; };
/* get system variable */
const getSystemVariables = async ({
timezone,
runningAppInfo,
chatId,
responseChatItemId,
histories = [],
uid,
chatConfig,
variables
}: Props & {
timezone: string;
}): Promise<SystemVariablesType> => {
// Get global variables(Label -> key; Key -> key)
const variablesConfig = chatConfig?.variables || [];
const variablesMap: Record<string, any> = {};
for await (const item of variablesConfig) {
// For internal variables, ignore external input and use default value
if (item.type === VariableInputEnum.password) {
const val = variables[item.label] || variables[item.key] || item.defaultValue;
const actualValue = anyValueDecrypt(val);
variablesMap[item.key] = valueTypeFormat(actualValue, item.valueType);
}
// 文件类型全局变量,签发成 string[] 格式
else if (item.type === VariableInputEnum.file) {
const vars = await presignVariablesFileUrls({
variables,
variableConfig: [item]
});
variablesMap[item.key] = vars?.[item.key]?.map((item: any) => item.url);
}
// API
else if (variables[item.label] !== undefined) {
variablesMap[item.key] = valueTypeFormat(variables[item.label], item.valueType);
}
// Web
else if (variables[item.key] !== undefined) {
variablesMap[item.key] = valueTypeFormat(variables[item.key], item.valueType);
} else {
variablesMap[item.key] = valueTypeFormat(item.defaultValue, item.valueType);
}
}
return {
...variablesMap,
// System var:
userId: uid,
appId: String(runningAppInfo.id),
chatId,
responseChatItemId,
histories,
cTime: getSystemTime(timezone)
};
};
/* Merge consecutive text messages into one */ /* Merge consecutive text messages into one */
const mergeAssistantResponseAnswerText = (response: AIChatItemValueItemType[]) => { const mergeAssistantResponseAnswerText = (response: AIChatItemValueItemType[]) => {
const result: AIChatItemValueItemType[] = []; const result: AIChatItemValueItemType[] = [];
......
...@@ -6,6 +6,8 @@ import { NodeOutputKeyEnum, VariableInputEnum } from '@fastgpt/global/core/workf ...@@ -6,6 +6,8 @@ import { NodeOutputKeyEnum, VariableInputEnum } from '@fastgpt/global/core/workf
import type { VariableItemType } from '@fastgpt/global/core/app/type'; import type { VariableItemType } from '@fastgpt/global/core/app/type';
import { encryptSecret } from '../../../common/secret/aes256gcm'; import { encryptSecret } from '../../../common/secret/aes256gcm';
import { imageFileType } from '@fastgpt/global/common/file/constants'; import { imageFileType } from '@fastgpt/global/common/file/constants';
import type {
ChatDispatchProps} from '@fastgpt/global/core/workflow/runtime/type';
import { import {
type RuntimeNodeItemType, type RuntimeNodeItemType,
type SystemVariablesType type SystemVariablesType
...@@ -30,6 +32,74 @@ import type { ChatNodeUsageType } from '@fastgpt/global/support/wallet/bill/type ...@@ -30,6 +32,74 @@ import type { ChatNodeUsageType } from '@fastgpt/global/support/wallet/bill/type
import type { HttpToolConfigType } from '@fastgpt/global/core/app/tool/httpTool/type'; import type { HttpToolConfigType } from '@fastgpt/global/core/app/tool/httpTool/type';
import type { WorkflowResponseType } from './type'; import type { WorkflowResponseType } from './type';
import { getLogger, LogCategories } from '../../../common/logger'; import { getLogger, LogCategories } from '../../../common/logger';
import { anyValueDecrypt } from '../../../common/secret/utils';
import { valueTypeFormat } from '@fastgpt/global/core/workflow/runtime/utils';
import { presignVariablesFileUrls } from '../../chat/utils';
import { getSystemTime } from '@fastgpt/global/common/time/timezone';
/* get system variable */
export const getSystemVariables = async ({
timezone,
runningAppInfo,
chatId,
responseChatItemId,
histories = [],
uid,
chatConfig,
variables
}: {
runningAppInfo: ChatDispatchProps['runningAppInfo'];
chatId: ChatDispatchProps['chatId'];
responseChatItemId: ChatDispatchProps['responseChatItemId'];
histories: ChatDispatchProps['histories'];
uid: ChatDispatchProps['uid'];
chatConfig: ChatDispatchProps['chatConfig'];
variables: ChatDispatchProps['variables'];
timezone: string;
}): Promise<SystemVariablesType> => {
// Get global variables(Label -> key; Key -> key)
const variablesConfig = chatConfig?.variables || [];
const variablesMap: Record<string, any> = {};
for await (const item of variablesConfig) {
// For internal variables, ignore external input and use default value
if (item.type === VariableInputEnum.password) {
const val = variables[item.label] || variables[item.key] || item.defaultValue;
const actualValue = anyValueDecrypt(val);
variablesMap[item.key] = valueTypeFormat(actualValue, item.valueType);
}
// 文件类型全局变量,签发成 string[] 格式
else if (item.type === VariableInputEnum.file) {
const vars = await presignVariablesFileUrls({
variables,
variableConfig: [item]
});
variablesMap[item.key] = vars?.[item.key]?.map((item: any) => item.url);
}
// API
else if (variables[item.label] !== undefined) {
variablesMap[item.key] = valueTypeFormat(variables[item.label], item.valueType);
}
// Web
else if (variables[item.key] !== undefined) {
variablesMap[item.key] = valueTypeFormat(variables[item.key], item.valueType);
} else {
variablesMap[item.key] = valueTypeFormat(item.defaultValue, item.valueType);
}
}
return {
...variablesMap,
// System var:
userId: uid,
appId: String(runningAppInfo.id),
chatId,
responseChatItemId,
histories,
cTime: getSystemTime(timezone)
};
};
export const getWorkflowResponseWrite = ({ export const getWorkflowResponseWrite = ({
res, res,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment