fix: plugin not get system input config (#5363)

* doc

* fix: action

* fix: plugin not get system input config

* perf: rewrite toolset
This commit is contained in:
Archer
2025-08-01 22:40:48 +08:00
committed by GitHub
parent 00f00f6161
commit 6ac03dbf82
6 changed files with 91 additions and 77 deletions

View File

@@ -24,8 +24,6 @@ export type PluginRuntimeType = {
// system plugin // system plugin
export type SystemPluginTemplateItemType = WorkflowTemplateType & { export type SystemPluginTemplateItemType = WorkflowTemplateType & {
parentId?: ParentIdType;
isFolder?: boolean;
templateType: string; templateType: string;
// FastGPT-plugin tool // FastGPT-plugin tool

View File

@@ -129,9 +129,9 @@ export const getSystemPluginByIdAndVersionId = async (
// concat parent (if exists) input config // concat parent (if exists) input config
const parent = plugin.parentId ? await getSystemToolById(plugin.parentId) : undefined; const parent = plugin.parentId ? await getSystemToolById(plugin.parentId) : undefined;
if (parent && parent.inputList) { if (parent?.inputList) {
plugin?.inputs?.push({ version?.inputs?.unshift({
key: 'system_input_config', key: NodeInputKeyEnum.systemInputConfig,
label: '', label: '',
renderTypeList: [FlowNodeInputTypeEnum.hidden], renderTypeList: [FlowNodeInputTypeEnum.hidden],
inputList: parent.inputList inputList: parent.inputList
@@ -140,8 +140,8 @@ export const getSystemPluginByIdAndVersionId = async (
return { return {
...plugin, ...plugin,
inputs: version.inputs, inputs: version.inputs ?? [],
outputs: version.outputs, outputs: version.outputs ?? [],
version: versionId ? version?.value : '', version: versionId ? version?.value : '',
versionLabel: versionId ? version?.value : '', versionLabel: versionId ? version?.value : '',
isLatestVersion: !version || !lastVersion || version.value === lastVersion?.value isLatestVersion: !version || !lastVersion || version.value === lastVersion?.value
@@ -448,36 +448,6 @@ export async function getChildAppRuntimeById({
}; };
} }
export async function getSystemPluginRuntimeNodeById({
pluginId,
name,
intro
}: {
pluginId: string;
name: string;
intro: string;
}): Promise<RuntimeNodeItemType> {
const { source } = splitCombinePluginId(pluginId);
if (source === PluginSourceEnum.systemTool) {
const tool = await getSystemPluginByIdAndVersionId(pluginId);
return {
...tool,
name,
intro,
inputs: tool.inputs ?? [],
outputs: tool.outputs ?? [],
flowNodeType: FlowNodeTypeEnum.tool,
nodeId: getNanoid(),
toolConfig: {
systemTool: {
toolId: pluginId
}
}
};
}
return Promise.reject(PluginErrEnum.unExist);
}
const dbPluginFormat = (item: SystemPluginConfigSchemaType): SystemPluginTemplateItemType => { const dbPluginFormat = (item: SystemPluginConfigSchemaType): SystemPluginTemplateItemType => {
const { name, avatar, intro, version, weight, templateType, associatedPluginId, userGuide } = const { name, avatar, intro, version, weight, templateType, associatedPluginId, userGuide } =
item.customConfig!; item.customConfig!;
@@ -563,20 +533,30 @@ export const getSystemTools = async (): Promise<SystemPluginTemplateItemType[]>
const dbPluginConfig = systemPlugins.get(item.id); const dbPluginConfig = systemPlugins.get(item.id);
const versionList = (item.versionList as SystemPluginTemplateItemType['versionList']) || []; const versionList = (item.versionList as SystemPluginTemplateItemType['versionList']) || [];
const inputs = versionList[0]?.inputs ?? [];
const outputs = versionList[0]?.outputs ?? [];
return { return {
...item, id: item.id,
parentId: item.parentId,
isFolder: tools.some((tool) => tool.parentId === item.id), isFolder: tools.some((tool) => tool.parentId === item.id),
showStatus: true,
name: item.name,
avatar: item.avatar,
intro: item.description,
author: item.author,
courseUrl: item.courseUrl,
weight: item.weight,
workflow: { workflow: {
nodes: [], nodes: [],
edges: [] edges: []
}, },
versionList, versionList,
inputs,
outputs, templateType: item.templateType,
showStatus: true,
isActive: item.isActive,
inputList: item?.secretInputConfig, inputList: item?.secretInputConfig,
hasSystemSecret: !!dbPluginConfig?.inputListVal hasSystemSecret: !!dbPluginConfig?.inputListVal
}; };

View File

@@ -1,7 +1,7 @@
import { getErrText } from '@fastgpt/global/common/error/utils'; import { getErrText } from '@fastgpt/global/common/error/utils';
import { ChatRoleEnum } from '@fastgpt/global/core/chat/constants'; import { ChatRoleEnum } from '@fastgpt/global/core/chat/constants';
import type { ChatItemType } from '@fastgpt/global/core/chat/type.d'; import type { ChatItemType } from '@fastgpt/global/core/chat/type.d';
import { NodeInputKeyEnum, NodeOutputKeyEnum } from '@fastgpt/global/core/workflow/constants'; import { NodeOutputKeyEnum } from '@fastgpt/global/core/workflow/constants';
import { import {
type RuntimeEdgeItemType, type RuntimeEdgeItemType,
type RuntimeNodeItemType, type RuntimeNodeItemType,
@@ -17,12 +17,9 @@ import { getNanoid } from '@fastgpt/global/common/string/tools';
import { type SearchDataResponseItemType } from '@fastgpt/global/core/dataset/type'; import { type SearchDataResponseItemType } from '@fastgpt/global/core/dataset/type';
import { getMCPToolRuntimeNode } from '@fastgpt/global/core/app/mcpTools/utils'; import { getMCPToolRuntimeNode } from '@fastgpt/global/core/app/mcpTools/utils';
import { FlowNodeTypeEnum } from '@fastgpt/global/core/workflow/node/constant'; import { FlowNodeTypeEnum } from '@fastgpt/global/core/workflow/node/constant';
import {
getSystemPluginRuntimeNodeById,
getSystemTools
} from '../../../core/app/plugin/controller';
import { MongoApp } from '../../../core/app/schema'; import { MongoApp } from '../../../core/app/schema';
import { getMCPChildren } from '../../../core/app/mcp'; import { getMCPChildren } from '../../../core/app/mcp';
import { getSystemToolRunTimeNodeFromSystemToolset } from '../utils';
export const getWorkflowResponseWrite = ({ export const getWorkflowResponseWrite = ({
res, res,
@@ -197,29 +194,13 @@ export const rewriteRuntimeWorkFlow = async ({
// systemTool // systemTool
if (systemToolId) { if (systemToolId) {
const toolsetInputConfig = toolSetNode.inputs.find( const children = await getSystemToolRunTimeNodeFromSystemToolset({
(item) => item.key === NodeInputKeyEnum.systemInputConfig toolSetNode
); });
const tools = await getSystemTools(); children.forEach((node) => {
const children = tools.filter((item) => item.parentId === systemToolId); nodes.push(node);
for (const child of children) { pushEdges(node.nodeId);
const toolListItem = toolSetNode.toolConfig?.systemToolSet?.toolList.find( });
(item) => item.toolId === child.id
)!;
const newNode = await getSystemPluginRuntimeNodeById({
pluginId: child.id,
name: toolListItem?.name,
intro: toolListItem?.description
});
const newNodeInputConfig = newNode.inputs.find(
(item) => item.key === NodeInputKeyEnum.systemInputConfig
);
if (newNodeInputConfig) {
newNodeInputConfig.value = toolsetInputConfig?.value;
}
nodes.push(newNode);
pushEdges(newNode.nodeId);
}
} else if (mcpToolsetVal) { } else if (mcpToolsetVal) {
const app = await MongoApp.findOne({ _id: toolSetNode.pluginId }).lean(); const app = await MongoApp.findOne({ _id: toolSetNode.pluginId }).lean();
if (!app) continue; if (!app) continue;

View File

@@ -1,5 +1,11 @@
import { type SearchDataResponseItemType } from '@fastgpt/global/core/dataset/type'; import { type SearchDataResponseItemType } from '@fastgpt/global/core/dataset/type';
import { countPromptTokens } from '../../common/string/tiktoken/index'; import { countPromptTokens } from '../../common/string/tiktoken/index';
import type { RuntimeNodeItemType } from '@fastgpt/global/core/workflow/runtime/type';
import { getSystemPluginByIdAndVersionId, getSystemTools } from '../app/plugin/controller';
import { FlowNodeTypeEnum } from '@fastgpt/global/core/workflow/node/constant';
import { getNanoid } from '@fastgpt/global/common/string/tools';
import { NodeInputKeyEnum } from '@fastgpt/global/core/workflow/constants';
import { parseI18nString } from '@fastgpt/global/common/i18n/utils';
/* filter search result */ /* filter search result */
export const filterSearchResultsByMaxChars = async ( export const filterSearchResultsByMaxChars = async (
@@ -23,3 +29,52 @@ export const filterSearchResultsByMaxChars = async (
return results.length === 0 ? list.slice(0, 1) : results; return results.length === 0 ? list.slice(0, 1) : results;
}; };
export async function getSystemToolRunTimeNodeFromSystemToolset({
toolSetNode
}: {
toolSetNode: RuntimeNodeItemType;
}): Promise<RuntimeNodeItemType[]> {
const systemToolId = toolSetNode.toolConfig?.systemToolSet?.toolId!;
const toolsetInputConfig = toolSetNode.inputs.find(
(item) => item.key === NodeInputKeyEnum.systemInputConfig
);
const tools = await getSystemTools();
const children = tools.filter((item) => item.parentId === systemToolId);
const nodes = await Promise.all(
children.map(async (child) => {
const toolListItem = toolSetNode.toolConfig?.systemToolSet?.toolList.find(
(item) => item.toolId === child.id
)!;
const tool = await getSystemPluginByIdAndVersionId(child.id);
const inputs = tool.inputs ?? [];
if (toolsetInputConfig?.value) {
const configInput = inputs.find((item) => item.key === NodeInputKeyEnum.systemInputConfig);
if (configInput) {
configInput.value = toolsetInputConfig.value;
}
}
return {
...tool,
inputs,
outputs: tool.outputs ?? [],
name: toolListItem.name ?? parseI18nString(tool.name, 'en'),
intro: toolListItem.description ?? parseI18nString(tool.intro, 'en'),
flowNodeType: FlowNodeTypeEnum.tool,
nodeId: getNanoid(),
toolConfig: {
systemTool: {
toolId: child.id
}
}
};
})
);
return nodes;
}

View File

@@ -3,7 +3,7 @@
"version": "1.0.0", "version": "1.0.0",
"type": "module", "type": "module",
"dependencies": { "dependencies": {
"@fastgpt-sdk/plugin": "^0.1.4", "@fastgpt-sdk/plugin": "^0.1.7",
"@fastgpt/global": "workspace:*", "@fastgpt/global": "workspace:*",
"@modelcontextprotocol/sdk": "^1.12.1", "@modelcontextprotocol/sdk": "^1.12.1",
"@node-rs/jieba": "2.0.1", "@node-rs/jieba": "2.0.1",

10
pnpm-lock.yaml generated
View File

@@ -121,8 +121,8 @@ importers:
packages/service: packages/service:
dependencies: dependencies:
'@fastgpt-sdk/plugin': '@fastgpt-sdk/plugin':
specifier: ^0.1.4 specifier: ^0.1.7
version: 0.1.4(@types/node@20.17.24) version: 0.1.7(@types/node@20.17.24)
'@fastgpt/global': '@fastgpt/global':
specifier: workspace:* specifier: workspace:*
version: link:../global version: link:../global
@@ -1973,8 +1973,8 @@ packages:
resolution: {integrity: sha512-d9zaMRSTIKDLhctzH12MtXvJKSSUhaHcjV+2Z+GK+EEY7XKpP5yR4x+N3TAcHTcu963nIr+TMcCb4DBCYX1z6Q==} resolution: {integrity: sha512-d9zaMRSTIKDLhctzH12MtXvJKSSUhaHcjV+2Z+GK+EEY7XKpP5yR4x+N3TAcHTcu963nIr+TMcCb4DBCYX1z6Q==}
engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0}
'@fastgpt-sdk/plugin@0.1.4': '@fastgpt-sdk/plugin@0.1.7':
resolution: {integrity: sha512-/wDpUvof6f2Elher295D+Z7YDLKY8+PuMORmA7RT+IfQ1sq6OgmTFDYrACrsqxq3Y5mgU8bt4zd5og2U+SmgDQ==} resolution: {integrity: sha512-/9szNeb1zLqThHenBYhYTyJr25dqRJwbXiWHFaf99tHWBjgMdMt2tfJhM9E6fz/zlAE3XlJIn/Dlgv82LJa7RQ==}
'@fastify/accept-negotiator@1.1.0': '@fastify/accept-negotiator@1.1.0':
resolution: {integrity: sha512-OIHZrb2ImZ7XG85HXOONLcJWGosv7sIvM2ifAPQVhg9Lv7qdmMBNVaai4QTdyuaqbKM5eO6sLSQOYI7wEQeCJQ==} resolution: {integrity: sha512-OIHZrb2ImZ7XG85HXOONLcJWGosv7sIvM2ifAPQVhg9Lv7qdmMBNVaai4QTdyuaqbKM5eO6sLSQOYI7wEQeCJQ==}
@@ -11208,7 +11208,7 @@ snapshots:
'@eslint/js@8.57.1': {} '@eslint/js@8.57.1': {}
'@fastgpt-sdk/plugin@0.1.4(@types/node@20.17.24)': '@fastgpt-sdk/plugin@0.1.7(@types/node@20.17.24)':
dependencies: dependencies:
'@fortaine/fetch-event-source': 3.0.6 '@fortaine/fetch-event-source': 3.0.6
'@ts-rest/core': 3.52.1(@types/node@20.17.24)(zod@3.25.51) '@ts-rest/core': 3.52.1(@types/node@20.17.24)(zod@3.25.51)