Skip to content

Commit 5e4435f

Browse files
FinleyGec121914yu
authored andcommitted
feat: system Tool (#4959)
* feat: independent system tool * chore: use ToolNode instead of PluginModule * chore: tools * chore: tools templateDir * refactor: templates * feat: flush code * chore: update template * refactor: migrate delay * feat: worker pool * chore: Dockerfile * docs: add tools.template.json * feat: auto flush system tools * fix: ts error * chore: create new pool temporarily * chore: system tool migration * chore: migration * fix: fix pnpm-workspace.yaml * chore: update pnpm-lock.yaml to integrate tool * chore(systemTool): chore * chore: add system plugin * chore(deps): update @fastgpt-sdk/plugin * fix: type error * chore: remove plugin package * chore: move pro plugins code to open source * feat: support system tool config input * fix: type error * perf: i18n * fix: cr * chore: update sdk * feat: system plugin cache
1 parent b3562e9 commit 5e4435f

File tree

88 files changed

+793
-10680
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+793
-10680
lines changed

projects/app/src/web/common/utils/i18n.ts renamed to packages/global/common/i18n/type.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
1-
import { type I18nNsType } from '@fastgpt/web/types/i18next';
2-
import { serverSideTranslations } from 'next-i18next/serverSideTranslations';
1+
export type I18nStringType = {
2+
'zh-CN'?: string;
3+
'zh-Hant'?: string;
4+
en: string;
5+
};
36

47
export enum LangEnum {
58
'zh_CN' = 'zh-CN',
69
'zh_Hant' = 'zh-Hant',
710
'en' = 'en'
811
}
12+
13+
export type localeType = `${LangEnum}`;
14+
export const LocaleList = ['en', 'zh-CN', 'zh-Hant'] as const;
15+
916
export const langMap = {
1017
[LangEnum.en]: {
1118
label: 'English(US)',

packages/global/common/i18n/utils.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import type { I18nStringType, localeType } from './type';
2+
3+
export const parseI18nString = (str: I18nStringType | string = '', lang: localeType = 'en') => {
4+
if (typeof str === 'string') return str;
5+
return str[lang] ?? str['en'];
6+
};

packages/global/core/app/mcpTools/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ import {
33
NodeOutputKeyEnum,
44
WorkflowIOValueTypeEnum
55
} from '../../workflow/constants';
6+
import { i18nT } from '../../../../web/i18n/utils';
67
import {
78
FlowNodeInputTypeEnum,
89
FlowNodeOutputTypeEnum,
910
FlowNodeTypeEnum
1011
} from '../../workflow/node/constant';
1112
import { type McpToolConfigType } from '../type';
12-
import { i18nT } from '../../../../web/i18n/utils';
1313
import { type RuntimeNodeItemType } from '../../workflow/runtime/type';
1414
import { type StoreSecretValueType } from '../../../common/secret/type';
1515
import { jsonSchema2NodeInput } from '../jsonschema';

packages/global/core/plugin/constants.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ export const pluginTypeMap = {
1919
};
2020

2121
export enum PluginSourceEnum {
22-
personal = 'personal',
23-
community = 'community',
24-
commercial = 'commercial'
22+
personal = 'personal', // this is a app.
23+
systemTool = 'systemTool', // FastGPT-plugin tools, pure code.
24+
commercial = 'commercial', // configured in Pro, with associatedPluginId. Specially, commercial-dalle3 is a systemTool
25+
// @deprecated
26+
community = 'community' // this is deprecated, will be replaced by systemTool
2527
}

packages/global/core/workflow/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ export enum NodeInputKeyEnum {
143143
addInputParam = 'system_addInputParam',
144144
forbidStream = 'system_forbid_stream',
145145
headerSecret = 'system_header_secret',
146+
systemInputConfig = 'system_input_config',
146147

147148
// history
148149
historyMaxAmount = 'maxContext',

packages/global/core/workflow/node/constant.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { WorkflowIOValueTypeEnum } from '../constants';
21
import { i18nT } from '../../../../web/i18n/utils';
2+
import { WorkflowIOValueTypeEnum } from '../constants';
33
export enum FlowNodeInputTypeEnum { // render ui
44
reference = 'reference', // reference to other node output
55
input = 'input', // one line input

packages/global/core/workflow/runtime/type.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import type { ChatNodeUsageType } from '../../../support/wallet/bill/type';
22
import type {
33
ChatItemType,
4-
UserChatItemValueItemType,
54
ToolRunResponseItemType,
65
AIChatItemValueItemType
76
} from '../../chat/type';
@@ -95,6 +94,7 @@ export type RuntimeNodeItemType = {
9594
intro?: StoreNodeItemType['intro'];
9695
flowNodeType: StoreNodeItemType['flowNodeType'];
9796
showStatus?: StoreNodeItemType['showStatus'];
97+
toolConfig?: StoreNodeItemType['toolConfig'];
9898
isEntry?: boolean;
9999

100100
inputs: FlowNodeInputItemType[];

packages/global/core/workflow/runtime/utils.ts

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
1+
import json5 from 'json5';
2+
import { replaceVariable, valToStr } from '../../../common/string/tools';
3+
import { ChatItemValueTypeEnum, ChatRoleEnum } from '../../../core/chat/constants';
4+
import type { ChatItemType, NodeOutputItemType } from '../../../core/chat/type';
15
import { ChatCompletionRequestMessageRoleEnum } from '../../ai/constants';
2-
import { NodeInputKeyEnum, NodeOutputKeyEnum, WorkflowIOValueTypeEnum } from '../constants';
6+
import {
7+
NodeInputKeyEnum,
8+
NodeOutputKeyEnum,
9+
VARIABLE_NODE_ID,
10+
WorkflowIOValueTypeEnum
11+
} from '../constants';
312
import { FlowNodeTypeEnum } from '../node/constant';
4-
import { type StoreNodeItemType } from '../type/node';
5-
import { type StoreEdgeItemType } from '../type/edge';
6-
import { type RuntimeEdgeItemType, type RuntimeNodeItemType } from './type';
7-
import { VARIABLE_NODE_ID } from '../constants';
8-
import { isValidReferenceValueFormat } from '../utils';
9-
import { type FlowNodeOutputItemType, type ReferenceValueType } from '../type/io';
10-
import { type ChatItemType, type NodeOutputItemType } from '../../../core/chat/type';
11-
import { ChatItemValueTypeEnum, ChatRoleEnum } from '../../../core/chat/constants';
12-
import { replaceVariable, valToStr } from '../../../common/string/tools';
13-
import json5 from 'json5';
1413
import {
1514
type InteractiveNodeResponseType,
1615
type WorkflowInteractiveResponseType
1716
} from '../template/system/interactive/type';
17+
import type { StoreEdgeItemType } from '../type/edge';
18+
import type { FlowNodeOutputItemType, ReferenceValueType } from '../type/io';
19+
import type { StoreNodeItemType } from '../type/node';
20+
import { isValidReferenceValueFormat } from '../utils';
21+
import type { RuntimeEdgeItemType, RuntimeNodeItemType } from './type';
1822

1923
export const extractDeepestInteractive = (
2024
interactive: WorkflowInteractiveResponseType
@@ -151,7 +155,7 @@ export const valueTypeFormat = (value: any, type?: WorkflowIOValueTypeEnum) => {
151155
return value;
152156
};
153157

154-
/*
158+
/*
155159
Get interaction information (if any) from the last AI message.
156160
What can be done:
157161
1. Get the interactive data
@@ -254,7 +258,8 @@ export const storeNodes2RuntimeNodes = (
254258
inputs: node.inputs,
255259
outputs: node.outputs,
256260
pluginId: node.pluginId,
257-
version: node.version
261+
version: node.version,
262+
toolConfig: node.toolConfig
258263
};
259264
}) || []
260265
);
@@ -268,7 +273,7 @@ export const filterWorkflowEdges = (edges: RuntimeEdgeItemType[]) => {
268273
);
269274
};
270275

271-
/*
276+
/*
272277
1. 输入线分类:普通线和递归线(可以追溯到自身)
273278
2. 起始线全部非 waiting 执行,或递归线全部非 waiting 执行
274279
*/
@@ -279,7 +284,7 @@ export const checkNodeRunStatus = ({
279284
node: RuntimeNodeItemType;
280285
runtimeEdges: RuntimeEdgeItemType[];
281286
}) => {
282-
/*
287+
/*
283288
区分普通连线和递归连线
284289
递归连线:可以通过往上查询 nodes,最终追溯到自身
285290
*/
@@ -363,7 +368,7 @@ export const checkNodeRunStatus = ({
363368
return 'wait';
364369
};
365370

366-
/*
371+
/*
367372
Get the value of the reference variable/node output
368373
1. [string,string]
369374
2. [string,string][]

packages/global/core/workflow/template/constants.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,41 @@
1-
import { SystemConfigNode } from './system/systemConfig';
2-
import { PluginConfigNode } from './system/pluginConfig';
3-
import { EmptyNode } from './system/emptyNode';
4-
import { WorkflowStart } from './system/workflowStart';
51
import { AiChatModule } from './system/aiChat';
6-
import { DatasetSearchModule } from './system/datasetSearch';
7-
import { DatasetConcatModule } from './system/datasetConcat';
82
import { AssignedAnswerModule } from './system/assignedAnswer';
93
import { ClassifyQuestionModule } from './system/classifyQuestion/index';
104
import { ContextExtractModule } from './system/contextExtract/index';
5+
import { DatasetConcatModule } from './system/datasetConcat';
6+
import { DatasetSearchModule } from './system/datasetSearch';
7+
import { EmptyNode } from './system/emptyNode';
118
import { HttpNode468 } from './system/http468';
9+
import { PluginConfigNode } from './system/pluginConfig';
10+
import { SystemConfigNode } from './system/systemConfig';
11+
import { WorkflowStart } from './system/workflowStart';
1212

13-
import { ToolModule } from './system/tools';
1413
import { StopToolNode } from './system/stopTool';
14+
import { ToolModule } from './system/tools';
1515

1616
import { RunAppModule } from './system/abandoned/runApp/index';
1717
import { PluginInputModule } from './system/pluginInput';
1818
import { PluginOutputModule } from './system/pluginOutput';
19-
import { RunPluginModule } from './system/runPlugin';
20-
import { RunAppNode } from './system/runApp';
2119
import { AiQueryExtension } from './system/queryExtension';
20+
import { RunAppNode } from './system/runApp';
21+
import { RunPluginModule } from './system/runPlugin';
2222

2323
import type { FlowNodeTemplateType } from '../type/node';
24-
import { LafModule } from './system/laf';
25-
import { IfElseNode } from './system/ifElse/index';
26-
import { VariableUpdateNode } from './system/variableUpdate';
27-
import { CodeNode } from './system/sandbox';
28-
import { TextEditorNode } from './system/textEditor';
2924
import { CustomFeedbackNode } from './system/customFeedback';
30-
import { ReadFilesNode } from './system/readFiles';
25+
import { IfElseNode } from './system/ifElse/index';
26+
import { FormInputNode } from './system/interactive/formInput';
3127
import { UserSelectNode } from './system/interactive/userSelect';
28+
import { LafModule } from './system/laf';
3229
import { LoopNode } from './system/loop/loop';
33-
import { LoopStartNode } from './system/loop/loopStart';
3430
import { LoopEndNode } from './system/loop/loopEnd';
35-
import { FormInputNode } from './system/interactive/formInput';
36-
import { ToolParamsNode } from './system/toolParams';
31+
import { LoopStartNode } from './system/loop/loopStart';
32+
import { ReadFilesNode } from './system/readFiles';
3733
import { RunToolNode } from './system/runTool';
3834
import { RunToolSetNode } from './system/runToolSet';
35+
import { CodeNode } from './system/sandbox';
36+
import { TextEditorNode } from './system/textEditor';
37+
import { ToolParamsNode } from './system/toolParams';
38+
import { VariableUpdateNode } from './system/variableUpdate';
3939

4040
const systemNodes: FlowNodeTemplateType[] = [
4141
AiChatModule,

packages/global/core/workflow/type/index.d.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import type { ParentIdType } from 'common/parentFolder/type';
2121
import type { AppTypeEnum } from 'core/app/constants';
2222
import type { StoreNodeItemType } from './node';
2323
import { FlowNodeTemplateType } from './node';
24+
import type { SecretValueType } from './../../../common/secret/type';
25+
import type { I18nStringType } from '../../../common/i18n/type';
2426

2527
export type WorkflowTemplateBasicType = {
2628
nodes: StoreNodeItemType[];
@@ -32,9 +34,9 @@ export type WorkflowTemplateType = {
3234
parentId?: ParentIdType;
3335
isFolder?: boolean;
3436

35-
name: string;
37+
name: I18nStringType | string;
3638
avatar: string;
37-
intro?: string;
39+
intro?: I18nStringType | string;
3840
author?: string;
3941
courseUrl?: string;
4042

@@ -86,10 +88,18 @@ export type SystemPluginTemplateItemType = WorkflowTemplateType & {
8688
key: string;
8789
label: string;
8890
description: string;
89-
value?: any;
91+
value?: string | SecretValueType;
9092
}[];
9193
};
9294

95+
export type SystemPluginTemplateListItemType = Omit<
96+
SystemPluginTemplateItemType,
97+
'name' | 'intro'
98+
> & {
99+
name: string;
100+
intro: string;
101+
};
102+
93103
export type THelperLine = {
94104
position: number;
95105
nodes: {

0 commit comments

Comments
 (0)