Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/global/core/workflow/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
Expand Down Expand Up @@ -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,
Expand Down
31 changes: 30 additions & 1 deletion packages/service/core/workflow/dispatch/plugin/run.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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;
Expand Down Expand Up @@ -107,13 +111,38 @@ export const dispatchRunPlugin = async (props: RunPluginProps): Promise<RunPlugi
if (output) {
output.moduleLogo = plugin.avatar;
}
const results: Record<string, any> = {};
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,
childrenUsage: flowUsages,
error: !!output?.pluginOutput?.error
});
return {
...results,
// 嵌套运行时,如果 childApp stream=false,实际上不会有任何内容输出给用户,所以不需要存储
assistantResponses: system_forbid_stream ? [] : assistantResponses,
// responseData, // debug
Expand Down
Loading