mirror of
https://github.com/labring/FastGPT.git
synced 2025-08-03 13:38:00 +00:00
v4.6.2-alpah (#511)
This commit is contained in:
@@ -1,24 +1,24 @@
|
||||
import type { ModuleDispatchProps } from '@/types/core/chat/type';
|
||||
import { dispatchModules } from '../index';
|
||||
import {
|
||||
FlowNodeSpecialInputKeyEnum,
|
||||
FlowNodeTypeEnum
|
||||
} from '@fastgpt/global/core/module/node/constant';
|
||||
import { FlowNodeTypeEnum } from '@fastgpt/global/core/module/node/constant';
|
||||
import { ModuleInputKeyEnum, ModuleOutputKeyEnum } from '@fastgpt/global/core/module/constants';
|
||||
import type { moduleDispatchResType } from '@fastgpt/global/core/chat/type.d';
|
||||
import { TaskResponseKeyEnum } from '@fastgpt/global/core/chat/constants';
|
||||
import { MongoPlugin } from '@fastgpt/service/core/plugin/schema';
|
||||
import { getPluginRuntimeById } from '@fastgpt/service/core/plugin/controller';
|
||||
import { authPluginCanUse } from '@fastgpt/service/support/permission/auth/plugin';
|
||||
|
||||
type RunPluginProps = ModuleDispatchProps<{
|
||||
[FlowNodeSpecialInputKeyEnum.pluginId]: string;
|
||||
[ModuleInputKeyEnum.pluginId]: string;
|
||||
[key: string]: any;
|
||||
}>;
|
||||
type RunPluginResponse = {
|
||||
answerText: string;
|
||||
[TaskResponseKeyEnum.responseData]?: moduleDispatchResType[];
|
||||
[ModuleOutputKeyEnum.answerText]: string;
|
||||
[ModuleOutputKeyEnum.responseData]?: moduleDispatchResType;
|
||||
};
|
||||
|
||||
export const dispatchRunPlugin = async (props: RunPluginProps): Promise<RunPluginResponse> => {
|
||||
const {
|
||||
teamId,
|
||||
tmbId,
|
||||
inputs: { pluginId, ...data }
|
||||
} = props;
|
||||
|
||||
@@ -26,14 +26,15 @@ export const dispatchRunPlugin = async (props: RunPluginProps): Promise<RunPlugi
|
||||
return Promise.reject('Input is empty');
|
||||
}
|
||||
|
||||
const plugin = await MongoPlugin.findOne({ _id: pluginId });
|
||||
if (!plugin) {
|
||||
return Promise.reject('Plugin not found');
|
||||
}
|
||||
await authPluginCanUse({ id: pluginId, teamId, tmbId });
|
||||
const plugin = await getPluginRuntimeById(pluginId);
|
||||
|
||||
const { responseData, answerText } = await dispatchModules({
|
||||
...props,
|
||||
modules: plugin.modules,
|
||||
modules: plugin.modules.map((module) => ({
|
||||
...module,
|
||||
showStatus: false
|
||||
})),
|
||||
params: data
|
||||
});
|
||||
|
||||
@@ -45,10 +46,12 @@ export const dispatchRunPlugin = async (props: RunPluginProps): Promise<RunPlugi
|
||||
|
||||
return {
|
||||
answerText,
|
||||
// [TaskResponseKeyEnum.responseData]: output,
|
||||
[TaskResponseKeyEnum.responseData]: responseData.filter(
|
||||
(item) => item.moduleType !== FlowNodeTypeEnum.pluginOutput
|
||||
),
|
||||
responseData: {
|
||||
moduleLogo: plugin.avatar,
|
||||
price: responseData.reduce((sum, item) => sum + item.price, 0),
|
||||
runningTime: responseData.reduce((sum, item) => sum + (item.runningTime || 0), 0),
|
||||
pluginOutput: output?.pluginOutput
|
||||
},
|
||||
...(output ? output.pluginOutput : {})
|
||||
};
|
||||
};
|
||||
|
Reference in New Issue
Block a user