1
1
import { type FlowNodeTemplateType } from '@fastgpt/global/core/workflow/type/node.d' ;
2
- import { FlowNodeTypeEnum } from '@fastgpt/global/core/workflow/node/constant' ;
2
+ import {
3
+ FlowNodeInputTypeEnum ,
4
+ FlowNodeTypeEnum
5
+ } from '@fastgpt/global/core/workflow/node/constant' ;
3
6
import {
4
7
appData2FlowNodeIO ,
5
8
pluginData2FlowNodeIO ,
@@ -25,14 +28,15 @@ import {
25
28
NodeInputKeyEnum
26
29
} from '@fastgpt/global/core/workflow/constants' ;
27
30
import { getNanoid } from '@fastgpt/global/common/string/tools' ;
28
- import { getSystemToolList } from '../tool/api' ;
31
+ import { APIGetSystemToolList } from '../tool/api' ;
29
32
import { Types } from '../../../common/mongo' ;
30
33
import type { SystemPluginConfigSchemaType } from './type' ;
31
34
import type {
32
35
FlowNodeInputItemType ,
33
36
FlowNodeOutputItemType
34
37
} from '@fastgpt/global/core/workflow/type/io' ;
35
38
import { isProduction } from '@fastgpt/global/common/system/constants' ;
39
+ import type { RuntimeNodeItemType } from '@fastgpt/global/core/workflow/runtime/type' ;
36
40
37
41
/**
38
42
plugin id rule:
@@ -78,7 +82,7 @@ export const getSystemPluginByIdAndVersionId = async (
78
82
versionId ?: string
79
83
) : Promise < ChildAppType > => {
80
84
const plugin = await ( async ( ) : Promise < ChildAppType > => {
81
- const plugin = await getSystemPluginById ( pluginId ) ;
85
+ const plugin = await getSystemToolById ( pluginId ) ;
82
86
83
87
// Admin selected system tool
84
88
if ( plugin . associatedPluginId ) {
@@ -127,6 +131,17 @@ export const getSystemPluginByIdAndVersionId = async (
127
131
: plugin . versionList ?. [ 0 ] ;
128
132
const lastVersion = plugin . versionList ?. [ 0 ] ;
129
133
134
+ // concat parent (is exists) input config
135
+ const parent = plugin . parentId ? await getSystemToolById ( plugin . parentId ) : undefined ;
136
+ if ( parent && parent . inputList ) {
137
+ plugin ?. inputs ?. push ( {
138
+ key : 'system_input_config' ,
139
+ label : '' ,
140
+ renderTypeList : [ FlowNodeInputTypeEnum . hidden ] ,
141
+ inputList : parent . inputList
142
+ } ) ;
143
+ }
144
+
130
145
return {
131
146
...plugin ,
132
147
version : versionId ? version ?. value : '' ,
@@ -195,11 +210,34 @@ export async function getChildAppPreviewNode({
195
210
196
211
const { flowNodeType, nodeIOConfig } = await ( async ( ) => {
197
212
if ( source === PluginSourceEnum . systemTool ) {
213
+ const children = ( await getSystemTools ( ) ) . filter ( ( item ) => item . parentId === pluginId ) ;
198
214
return {
199
- flowNodeType : FlowNodeTypeEnum . tool ,
215
+ flowNodeType : app . isFolder ? FlowNodeTypeEnum . toolSet : FlowNodeTypeEnum . tool ,
200
216
nodeIOConfig : {
201
- inputs : app . inputs ! ,
202
- outputs : app . outputs ! ,
217
+ inputs : app . isFolder
218
+ ? ( [
219
+ {
220
+ value : {
221
+ toolList : children . map ( ( item ) => ( {
222
+ name : parseI18nString ( item . name , lang ) ,
223
+ description : parseI18nString ( item . intro , lang )
224
+ } ) )
225
+ } ,
226
+ renderTypeList : [ FlowNodeInputTypeEnum . hidden ]
227
+ } ,
228
+ ...( app . inputList
229
+ ? [
230
+ {
231
+ key : NodeInputKeyEnum . systemInputConfig ,
232
+ label : '' ,
233
+ renderTypeList : [ FlowNodeInputTypeEnum . hidden ] ,
234
+ inputList : app . inputList
235
+ }
236
+ ]
237
+ : [ ] )
238
+ ] as FlowNodeInputItemType [ ] )
239
+ : app . inputs ?? [ ] ,
240
+ outputs : app . outputs ?? [ ] ,
203
241
toolConfig : {
204
242
systemTool : {
205
243
toolId : app . id
@@ -274,11 +312,15 @@ export async function getChildAppPreviewNode({
274
312
System plugin: plugin id
275
313
Personal plugin: Version id
276
314
*/
277
- export async function getChildAppRuntimeById (
278
- id : string ,
279
- versionId ?: string ,
280
- lang : localeType = 'en'
281
- ) : Promise < PluginRuntimeType > {
315
+ export async function getChildAppRuntimeById ( {
316
+ id,
317
+ versionId,
318
+ lang = 'en'
319
+ } : {
320
+ id : string ;
321
+ versionId ?: string ;
322
+ lang ?: localeType ;
323
+ } ) : Promise < PluginRuntimeType > {
282
324
const app = await ( async ( ) => {
283
325
const { source, pluginId } = splitCombinePluginId ( id ) ;
284
326
@@ -331,6 +373,30 @@ export async function getChildAppRuntimeById(
331
373
} ;
332
374
}
333
375
376
+ export async function getSystemPluginRuntimeNodeById (
377
+ pluginId : string
378
+ ) : Promise < RuntimeNodeItemType > {
379
+ const { source } = splitCombinePluginId ( pluginId ) ;
380
+ if ( source === PluginSourceEnum . systemTool ) {
381
+ const tool = await getSystemPluginByIdAndVersionId ( pluginId ) ;
382
+ return {
383
+ ...tool ,
384
+ name : parseI18nString ( tool . name ) ,
385
+ intro : parseI18nString ( tool . intro ) ,
386
+ inputs : tool . inputs ?? [ ] ,
387
+ outputs : tool . outputs ?? [ ] ,
388
+ flowNodeType : FlowNodeTypeEnum . tool ,
389
+ nodeId : getNanoid ( ) ,
390
+ toolConfig : {
391
+ systemTool : {
392
+ toolId : pluginId
393
+ }
394
+ }
395
+ } ;
396
+ }
397
+ return Promise . reject ( PluginErrEnum . unExist ) ;
398
+ }
399
+
334
400
const dbPluginFormat = ( item : SystemPluginConfigSchemaType ) : SystemPluginTemplateItemType => {
335
401
const { name, avatar, intro, version, weight, templateType, associatedPluginId, userGuide } =
336
402
item . customConfig ! ;
@@ -385,11 +451,11 @@ export const refetchSystemPlugins = () => {
385
451
} ) ;
386
452
} ;
387
453
388
- export const getSystemPlugins = async ( ) : Promise < SystemPluginTemplateItemType [ ] > => {
454
+ export const getSystemTools = async ( ) : Promise < SystemPluginTemplateItemType [ ] > => {
389
455
if ( getCachedSystemPlugins ( ) . expires > Date . now ( ) && isProduction ) {
390
456
return getCachedSystemPlugins ( ) . data ;
391
457
} else {
392
- const tools = await getSystemToolList ( ) ;
458
+ const tools = await APIGetSystemToolList ( ) ;
393
459
394
460
// 从数据库里加载插件配置进行替换
395
461
const systemPluginsArray = await MongoSystemPlugin . find ( { } ) . lean ( ) ;
@@ -418,33 +484,18 @@ export const getSystemPlugins = async (): Promise<SystemPluginTemplateItemType[]
418
484
const outputs = item . versionList [ 0 ] ?. outputs as FlowNodeOutputItemType [ ] ;
419
485
420
486
return {
421
- isActive : item . isActive ,
422
- id : item . id ,
423
- parentId : item . parentId ,
487
+ ...item ,
424
488
isFolder : tools . some ( ( tool ) => tool . parentId === item . id ) ,
425
- name : item . name ,
426
- avatar : item . avatar ,
427
- intro : item . intro ,
428
- author : item . author ,
429
- courseUrl : item . courseUrl ,
430
489
showStatus : true ,
431
- weight : item . weight ,
432
- templateType : item . templateType ,
433
- originCost : item . originCost ,
434
- currentCost : item . currentCost ,
435
- hasTokenFee : item . hasTokenFee ,
436
- pluginOrder : item . pluginOrder ,
437
-
438
490
workflow : {
439
491
nodes : [ ] ,
440
492
edges : [ ]
441
493
} ,
442
- versionList : item . versionList ,
443
494
inputs,
444
495
outputs,
445
-
446
- inputList : inputs ?. find ( ( input ) => input . key === NodeInputKeyEnum . systemInputConfig )
447
- ?. inputList as any ,
496
+ inputList :
497
+ inputs ?. find ( ( input ) => input . key === NodeInputKeyEnum . systemInputConfig ) ?. inputList ??
498
+ item ?. inputConfig ?. inputList ,
448
499
hasSystemSecret : ! ! dbPluginConfig ?. inputListVal
449
500
} ;
450
501
} ) ;
@@ -465,10 +516,10 @@ export const getSystemPlugins = async (): Promise<SystemPluginTemplateItemType[]
465
516
}
466
517
} ;
467
518
468
- export const getSystemPluginById = async ( id : string ) : Promise < SystemPluginTemplateItemType > => {
519
+ export const getSystemToolById = async ( id : string ) : Promise < SystemPluginTemplateItemType > => {
469
520
const { source, pluginId } = splitCombinePluginId ( id ) ;
470
521
if ( source === PluginSourceEnum . systemTool ) {
471
- const tools = await getSystemPlugins ( ) ;
522
+ const tools = await getSystemTools ( ) ;
472
523
const tool = tools . find ( ( item ) => item . id === pluginId ) ;
473
524
if ( tool ) {
474
525
return tool ;
0 commit comments