diff --git a/packages/global/core/workflow/utils.ts b/packages/global/core/workflow/utils.ts index b9fef2b332d6..9beb18d87a5f 100644 --- a/packages/global/core/workflow/utils.ts +++ b/packages/global/core/workflow/utils.ts @@ -51,6 +51,7 @@ import { getNanoid } from '../../common/string/tools'; import { ChatRoleEnum } from '../../core/chat/constants'; import { runtimePrompt2ChatsValue } from '../../core/chat/adapt'; import { getPluginRunContent } from '../../core/app/plugin/utils'; +import { Output_Template_AddOutput } from './template/output'; export const getHandleId = (nodeId: string, type: 'source' | 'target', key: string) => { return `${nodeId}-${type}-${key}`; @@ -220,6 +221,11 @@ export const pluginData2FlowNodeIO = ({ : [], outputs: pluginOutput ? [ + { + ...Output_Template_AddOutput, + label: i18nT('workflow:http_extract_output'), + description: i18nT('workflow:http_extract_output_description') + }, ...pluginOutput.inputs.map((item) => ({ id: item.key, type: FlowNodeOutputTypeEnum.static, diff --git a/packages/service/core/workflow/dispatch/plugin/run.ts b/packages/service/core/workflow/dispatch/plugin/run.ts index ef6fcced8bce..d4f56e51a411 100644 --- a/packages/service/core/workflow/dispatch/plugin/run.ts +++ b/packages/service/core/workflow/dispatch/plugin/run.ts @@ -1,6 +1,9 @@ import type { ModuleDispatchProps } from '@fastgpt/global/core/workflow/runtime/type'; import { dispatchWorkFlow } from '../index'; -import { FlowNodeTypeEnum } from '@fastgpt/global/core/workflow/node/constant'; +import { + FlowNodeOutputTypeEnum, + FlowNodeTypeEnum +} from '@fastgpt/global/core/workflow/node/constant'; import { DispatchNodeResponseKeyEnum } from '@fastgpt/global/core/workflow/runtime/constants'; import { getChildAppRuntimeById } from '../../../app/plugin/controller'; import { @@ -17,6 +20,7 @@ import { chatValue2RuntimePrompt } from '@fastgpt/global/core/chat/adapt'; import { getPluginRunUserQuery } from '@fastgpt/global/core/workflow/utils'; import { getPluginInputsFromStoreNodes } from '@fastgpt/global/core/app/plugin/utils'; import { NodeInputKeyEnum } from '@fastgpt/global/core/workflow/constants'; +import { JSONPath } from 'jsonpath-plus'; type RunPluginProps = ModuleDispatchProps<{ [NodeInputKeyEnum.forbidStream]?: boolean; @@ -107,6 +111,30 @@ export const dispatchRunPlugin = async (props: RunPluginProps): Promise = {}; + props.node.outputs + .filter((item) => item.type === FlowNodeOutputTypeEnum.dynamic) + .forEach((item) => { + const key = item.key.startsWith('$') ? item.key : `$.${item.key}`; + results[item.key] = (() => { + const result = JSONPath({ path: key, json: output?.pluginOutput ?? {} }); + + // 如果结果为空,返回 undefined + if (!result || result.length === 0) { + return undefined; + } + + // 以下情况返回数组: + // 1. 使用通配符 * + // 2. 使用数组切片 [start:end] + // 3. 使用过滤表达式 [?(...)] + // 4. 使用递归下降 .. + // 5. 使用多个结果运算符 , + const needArrayResult = /[*]|[\[][:?]|\.\.|\,/.test(key); + + return needArrayResult ? result : result[0]; + })(); + }); const usagePoints = await computedPluginUsage({ plugin, @@ -114,6 +142,7 @@ export const dispatchRunPlugin = async (props: RunPluginProps): Promise