Skip to content

feat: system Tool #4959

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions packages/global/core/app/mcpTools/utils.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { nanoid } from 'nanoid';
import { i18nT } from '../../../../web/i18n/utils';
import { NodeOutputKeyEnum, WorkflowIOValueTypeEnum } from '../../workflow/constants';
import {
FlowNodeInputTypeEnum,
FlowNodeOutputTypeEnum,
FlowNodeTypeEnum
} from '../../workflow/node/constant';
import { nanoid } from 'nanoid';
import { type McpToolConfigType } from '../type';
import { i18nT } from '../../../../web/i18n/utils';
import { type RuntimeNodeItemType } from '../../workflow/runtime/type';

export const getMCPToolSetRuntimeNode = ({
Expand Down
8 changes: 5 additions & 3 deletions packages/global/core/plugin/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ export const pluginTypeMap = {
};

export enum PluginSourceEnum {
personal = 'personal',
community = 'community',
commercial = 'commercial'
personal = 'personal', // APP
systemTool = 'systemTool', // FastGPT-Tool
commercial = 'commercial', // pro 后台配置的,有 associatedPluginId
// @deprecated
community = 'community'
}
2 changes: 1 addition & 1 deletion packages/global/core/workflow/node/constant.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { WorkflowIOValueTypeEnum } from '../constants';
import { i18nT } from '../../../../web/i18n/utils';
import { WorkflowIOValueTypeEnum } from '../constants';
export enum FlowNodeInputTypeEnum { // render ui
reference = 'reference', // reference to other node output
input = 'input', // one line input
Expand Down
2 changes: 1 addition & 1 deletion packages/global/core/workflow/runtime/type.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { ChatNodeUsageType } from '../../../support/wallet/bill/type';
import type {
ChatItemType,
UserChatItemValueItemType,
ToolRunResponseItemType,
AIChatItemValueItemType
} from '../../chat/type';
Expand Down Expand Up @@ -95,6 +94,7 @@ export type RuntimeNodeItemType = {
intro?: StoreNodeItemType['intro'];
flowNodeType: StoreNodeItemType['flowNodeType'];
showStatus?: StoreNodeItemType['showStatus'];
toolConfig?: StoreNodeItemType['toolConfig'];
isEntry?: boolean;

inputs: FlowNodeInputItemType[];
Expand Down
37 changes: 21 additions & 16 deletions packages/global/core/workflow/runtime/utils.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
import json5 from 'json5';
import { replaceVariable, valToStr } from '../../../common/string/tools';
import { ChatItemValueTypeEnum, ChatRoleEnum } from '../../../core/chat/constants';
import type { ChatItemType, NodeOutputItemType } from '../../../core/chat/type';
import { ChatCompletionRequestMessageRoleEnum } from '../../ai/constants';
import { NodeInputKeyEnum, NodeOutputKeyEnum, WorkflowIOValueTypeEnum } from '../constants';
import {
NodeInputKeyEnum,
NodeOutputKeyEnum,
VARIABLE_NODE_ID,
WorkflowIOValueTypeEnum
} from '../constants';
import { FlowNodeTypeEnum } from '../node/constant';
import { type StoreNodeItemType } from '../type/node';
import { type StoreEdgeItemType } from '../type/edge';
import { type RuntimeEdgeItemType, type RuntimeNodeItemType } from './type';
import { VARIABLE_NODE_ID } from '../constants';
import { isValidReferenceValueFormat } from '../utils';
import { type FlowNodeOutputItemType, type ReferenceValueType } from '../type/io';
import { type ChatItemType, type NodeOutputItemType } from '../../../core/chat/type';
import { ChatItemValueTypeEnum, ChatRoleEnum } from '../../../core/chat/constants';
import { replaceVariable, valToStr } from '../../../common/string/tools';
import json5 from 'json5';
import {
type InteractiveNodeResponseType,
type WorkflowInteractiveResponseType
} from '../template/system/interactive/type';
import type { StoreEdgeItemType } from '../type/edge';
import type { FlowNodeOutputItemType, ReferenceValueType } from '../type/io';
import type { StoreNodeItemType } from '../type/node';
import { isValidReferenceValueFormat } from '../utils';
import type { RuntimeEdgeItemType, RuntimeNodeItemType } from './type';

export const extractDeepestInteractive = (
interactive: WorkflowInteractiveResponseType
Expand Down Expand Up @@ -151,7 +155,7 @@ export const valueTypeFormat = (value: any, type?: WorkflowIOValueTypeEnum) => {
return value;
};

/*
/*
Get interaction information (if any) from the last AI message.
What can be done:
1. Get the interactive data
Expand Down Expand Up @@ -254,7 +258,8 @@ export const storeNodes2RuntimeNodes = (
inputs: node.inputs,
outputs: node.outputs,
pluginId: node.pluginId,
version: node.version
version: node.version,
toolConfig: node.toolConfig
};
}) || []
);
Expand All @@ -268,7 +273,7 @@ export const filterWorkflowEdges = (edges: RuntimeEdgeItemType[]) => {
);
};

/*
/*
1. 输入线分类:普通线和递归线(可以追溯到自身)
2. 起始线全部非 waiting 执行,或递归线全部非 waiting 执行
*/
Expand All @@ -279,7 +284,7 @@ export const checkNodeRunStatus = ({
node: RuntimeNodeItemType;
runtimeEdges: RuntimeEdgeItemType[];
}) => {
/*
/*
区分普通连线和递归连线
递归连线:可以通过往上查询 nodes,最终追溯到自身
*/
Expand Down Expand Up @@ -363,7 +368,7 @@ export const checkNodeRunStatus = ({
return 'wait';
};

/*
/*
Get the value of the reference variable/node output
1. [string,string]
2. [string,string][]
Expand Down
36 changes: 18 additions & 18 deletions packages/global/core/workflow/template/constants.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
import { SystemConfigNode } from './system/systemConfig';
import { PluginConfigNode } from './system/pluginConfig';
import { EmptyNode } from './system/emptyNode';
import { WorkflowStart } from './system/workflowStart';
import { AiChatModule } from './system/aiChat';
import { DatasetSearchModule } from './system/datasetSearch';
import { DatasetConcatModule } from './system/datasetConcat';
import { AssignedAnswerModule } from './system/assignedAnswer';
import { ClassifyQuestionModule } from './system/classifyQuestion/index';
import { ContextExtractModule } from './system/contextExtract/index';
import { DatasetConcatModule } from './system/datasetConcat';
import { DatasetSearchModule } from './system/datasetSearch';
import { EmptyNode } from './system/emptyNode';
import { HttpNode468 } from './system/http468';
import { PluginConfigNode } from './system/pluginConfig';
import { SystemConfigNode } from './system/systemConfig';
import { WorkflowStart } from './system/workflowStart';

import { ToolModule } from './system/tools';
import { StopToolNode } from './system/stopTool';
import { ToolModule } from './system/tools';

import { RunAppModule } from './system/abandoned/runApp/index';
import { PluginInputModule } from './system/pluginInput';
import { PluginOutputModule } from './system/pluginOutput';
import { RunPluginModule } from './system/runPlugin';
import { RunAppNode } from './system/runApp';
import { AiQueryExtension } from './system/queryExtension';
import { RunAppNode } from './system/runApp';
import { RunPluginModule } from './system/runPlugin';

import type { FlowNodeTemplateType } from '../type/node';
import { LafModule } from './system/laf';
import { IfElseNode } from './system/ifElse/index';
import { VariableUpdateNode } from './system/variableUpdate';
import { CodeNode } from './system/sandbox';
import { TextEditorNode } from './system/textEditor';
import { CustomFeedbackNode } from './system/customFeedback';
import { ReadFilesNode } from './system/readFiles';
import { IfElseNode } from './system/ifElse/index';
import { FormInputNode } from './system/interactive/formInput';
import { UserSelectNode } from './system/interactive/userSelect';
import { LafModule } from './system/laf';
import { LoopNode } from './system/loop/loop';
import { LoopStartNode } from './system/loop/loopStart';
import { LoopEndNode } from './system/loop/loopEnd';
import { FormInputNode } from './system/interactive/formInput';
import { ToolParamsNode } from './system/toolParams';
import { LoopStartNode } from './system/loop/loopStart';
import { ReadFilesNode } from './system/readFiles';
import { RunToolNode } from './system/runTool';
import { RunToolSetNode } from './system/runToolSet';
import { CodeNode } from './system/sandbox';
import { TextEditorNode } from './system/textEditor';
import { ToolParamsNode } from './system/toolParams';
import { VariableUpdateNode } from './system/variableUpdate';

const systemNodes: FlowNodeTemplateType[] = [
AiChatModule,
Expand Down
13 changes: 11 additions & 2 deletions packages/global/core/workflow/type/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ import type { AppTypeEnum } from 'core/app/constants';
import type { StoreNodeItemType } from './node';
import { FlowNodeTemplateType } from './node';

export type localeType = 'en' | 'zh-CN' | 'zh-Hant';
export type I18nStringType =
| {
'zh-CN': string;
'zh-Hant'?: string;
en?: string;
}
| string;

export type WorkflowTemplateBasicType = {
nodes: StoreNodeItemType[];
edges: StoreEdgeItemType[];
Expand All @@ -32,9 +41,9 @@ export type WorkflowTemplateType = {
parentId?: ParentIdType;
isFolder?: boolean;

name: string;
name: I18nStringType;
avatar: string;
intro?: string;
intro?: I18nStringType;
author?: string;
courseUrl?: string;

Expand Down
5 changes: 4 additions & 1 deletion packages/global/core/workflow/type/node.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ export type NodeToolConfigType = {
mcpTool?: McpToolConfigType & {
url: string;
};
systemTool?: {
toolId: string;
};
};

export type FlowNodeCommonType = {
Expand All @@ -55,7 +58,7 @@ export type FlowNodeCommonType = {
pluginData?: PluginDataType;

// tool data
toolData?: NodeToolConfigType;
toolConfig?: NodeToolConfigType;
};

export type PluginDataType = {
Expand Down
30 changes: 30 additions & 0 deletions packages/global/core/workflow/type/tool.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
export type ToolType = {
type: string;
toolId: string;
isFolder?: boolean;
parentId?: string;
name: {
'zh-CN': string;
'zh-Hant'?: string;
en?: string | undefined;
};
versionList: {
version: string;
description?: string | undefined;
}[];
description: {
'zh-CN': string;
'zh-Hant'?: string;
en?: string | undefined;
};
icon: string;
author?: string | undefined;
docURL?: string | undefined;

workflow?: {
nodes: Array<any>;
edges: Array<any>;
};
inputs?: Array<any>;
outputs?: Array<any>;
};
12 changes: 9 additions & 3 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 type { I18nStringType, localeType } from './type';

export const getHandleId = (nodeId: string, type: 'source' | 'target', key: string) => {
return `${nodeId}-${type}-${key}`;
Expand Down Expand Up @@ -85,7 +86,7 @@ export const splitGuideModule = (guideModules?: StoreNodeItemType) => {
const questionGuide: AppQGConfigType =
typeof questionGuideVal === 'boolean'
? { ...defaultQGConfig, open: questionGuideVal }
: questionGuideVal ?? defaultQGConfig;
: (questionGuideVal ?? defaultQGConfig);

const ttsConfig: AppTTSConfigType =
guideModules?.inputs?.find((item) => item.key === NodeInputKeyEnum.tts)?.value ??
Expand Down Expand Up @@ -356,7 +357,7 @@ export const formatEditorVariablePickerIcon = (
export const isValidReferenceValueFormat = (value: any): value is ReferenceItemValueType => {
return Array.isArray(value) && value.length === 2 && typeof value[0] === 'string';
};
/*
/*
Check whether the value([variableId, outputId]) value is a valid reference value:
1. The value must be an array of length 2
2. The first item of the array must be one of VARIABLE_NODE_ID or nodeIds
Expand All @@ -370,7 +371,7 @@ export const isValidReferenceValue = (
const validIdSet = new Set([VARIABLE_NODE_ID, ...nodeIds]);
return validIdSet.has(value[0]);
};
/*
/*
Check whether the value([variableId, outputId][]) value is a valid reference value array:
1. The value must be an array
2. The array must contain at least one element
Expand Down Expand Up @@ -446,3 +447,8 @@ export const getPluginRunUserQuery = ({
})
};
};

export const parseI18nString = (str: I18nStringType = '', lang: localeType = 'zh-CN') => {
if (typeof str === 'string') return str;
return str[lang] ?? str['zh-CN'];
};
Loading
Loading