Skip to content

Commit 69e70df

Browse files
committed
move system plugin config (#5803)
* move system plugin config * extract tag bar * filter * tool detail temp * marketplace * params * fix * type * search * tags render * status * ui * code
1 parent 6f9be5a commit 69e70df

File tree

64 files changed

+4661
-1017
lines changed

Some content is hidden

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

64 files changed

+4661
-1017
lines changed

packages/global/core/app/plugin/constants.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,9 @@ export enum PluginSourceEnum {
77
// @deprecated
88
community = 'community' // this is deprecated, will be replaced by systemTool
99
}
10+
11+
export enum PluginStatusEnum {
12+
Offline = 0,
13+
Normal = 1,
14+
SoonOffline = 2
15+
}

packages/global/core/app/plugin/type.d.ts

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@ import type { FlowNodeTemplateType } from '../../workflow/type/node';
66
import type { WorkflowTemplateType } from '../../workflow/type';
77
import type { FlowNodeInputItemType, FlowNodeOutputItemType } from '../../workflow/type/io';
88
import type { ParentIdType } from 'common/parentFolder/type';
9+
import type { I18nStringStrictType } from '@fastgpt/global/sdk/fastgpt-plugin';
10+
import type { I18nStringType } from '../../../common/i18n/type';
11+
12+
export type PluginTagType = {
13+
tagId: string;
14+
tagName: I18nStringStrictType | string;
15+
tagOrder: number;
16+
isSystem: boolean;
17+
};
918

1019
export type PluginRuntimeType = {
1120
id: string;
@@ -25,8 +34,6 @@ export type PluginRuntimeType = {
2534

2635
// system plugin
2736
export type SystemPluginTemplateItemType = WorkflowTemplateType & {
28-
templateType: string;
29-
3037
// FastGPT-plugin tool
3138
inputs?: FlowNodeInputItemType[];
3239
outputs?: FlowNodeOutputItemType[];
@@ -49,7 +56,9 @@ export type SystemPluginTemplateItemType = WorkflowTemplateType & {
4956
hasTokenFee?: boolean;
5057
pluginOrder?: number;
5158

52-
isActive?: boolean;
59+
pluginTags?: string[];
60+
status?: number;
61+
defaultInstalled?: boolean;
5362
isOfficial?: boolean;
5463

5564
// Admin config
@@ -59,12 +68,28 @@ export type SystemPluginTemplateItemType = WorkflowTemplateType & {
5968

6069
// Plugin source type
6170
toolSource?: 'uploaded' | 'built-in';
71+
72+
// @deprecated use pluginTags instead
73+
isActive?: boolean;
74+
templateType?: string;
6275
};
6376

6477
export type SystemPluginTemplateListItemType = Omit<
6578
SystemPluginTemplateItemType,
66-
'name' | 'intro'
79+
'name' | 'intro' | 'workflow'
6780
> & {
6881
name: string;
6982
intro: string;
83+
tags?: PluginTagType[];
84+
};
85+
86+
// Marketplace Tool Types
87+
export type ToolListItem = {
88+
id: string;
89+
name: I18nStringType;
90+
description: I18nStringType;
91+
avatar: string;
92+
author?: string;
93+
tags: string[];
94+
downloadCount: number;
7095
};

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ export type PluginDataType = {
105105
name?: string;
106106
avatar?: string;
107107
error?: string;
108+
status?: number;
109+
pluginTags?: string[];
108110
};
109111

110112
type HandleType = {
@@ -131,6 +133,8 @@ export type FlowNodeTemplateType = FlowNodeCommonType & {
131133
diagram?: string; // diagram url
132134
courseUrl?: string; // course url
133135
userGuide?: string; // user guide
136+
status?: number;
137+
pluginTags?: string[];
134138

135139
// @deprecated
136140
// show handle
@@ -143,7 +147,8 @@ export type NodeTemplateListItemType = {
143147
flowNodeType: FlowNodeTypeEnum; // render node card
144148
parentId?: ParentIdType;
145149
isFolder?: boolean;
146-
templateType: string;
150+
templateType?: string;
151+
pluginTags?: string[];
147152
avatar?: string;
148153
name: string;
149154
intro?: string; // template list intro

packages/service/core/app/plugin/controller.ts

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ export async function getChildAppPreviewNode({
350350
systemToolSet: {
351351
toolId: app.id,
352352
toolList: children
353-
.filter((item) => item.isActive !== false)
353+
.filter((item) => item.status === 1 || item.status === undefined)
354354
.map((item) => ({
355355
toolId: item.id,
356356
name: parseI18nString(item.name, lang),
@@ -407,7 +407,7 @@ export async function getChildAppPreviewNode({
407407
return {
408408
id: getNanoid(),
409409
pluginId: app.id,
410-
templateType: app.templateType,
410+
templateType: app.templateType ?? FlowNodeTemplateTypeEnum.tools,
411411
flowNodeType,
412412
avatar: app.avatar,
413413
name: parseI18nString(app.name, lang),
@@ -507,21 +507,13 @@ export async function getChildAppRuntimeById({
507507
}
508508

509509
const dbPluginFormat = (item: SystemPluginConfigSchemaType): SystemPluginTemplateItemType => {
510-
const {
511-
name,
512-
avatar,
513-
intro,
514-
toolDescription,
515-
version,
516-
weight,
517-
templateType,
518-
associatedPluginId,
519-
userGuide
520-
} = item.customConfig!;
510+
const { name, avatar, intro, toolDescription, version, weight, associatedPluginId, userGuide } =
511+
item.customConfig!;
521512

522513
return {
523514
id: item.pluginId,
524-
isActive: item.isActive,
515+
status: item.status ?? 1,
516+
defaultInstalled: item.defaultInstalled ?? true,
525517
isFolder: false,
526518
parentId: null,
527519
author: item.customConfig?.author || '',
@@ -531,7 +523,7 @@ const dbPluginFormat = (item: SystemPluginConfigSchemaType): SystemPluginTemplat
531523
intro,
532524
toolDescription,
533525
weight,
534-
templateType,
526+
templateType: FlowNodeTemplateTypeEnum.tools,
535527
originCost: item.originCost,
536528
currentCost: item.currentCost,
537529
hasTokenFee: item.hasTokenFee,
@@ -573,14 +565,17 @@ export const refreshSystemTools = async (): Promise<SystemPluginTemplateItemType
573565
instructions: dbPluginConfig?.customConfig?.userGuide,
574566
weight: item.weight,
575567
toolSource: item.toolSource || 'built-in',
568+
// temporarily fixed
569+
pluginTags: (item as any).pluginTags,
576570
workflow: {
577571
nodes: [],
578572
edges: []
579573
},
580574
versionList,
581-
templateType: item.templateType,
575+
templateType: item.templateType ?? FlowNodeTemplateTypeEnum.tools,
582576
showStatus: true,
583-
isActive: dbPluginConfig?.isActive ?? item.isActive ?? true,
577+
status: dbPluginConfig?.status ?? 1,
578+
defaultInstalled: dbPluginConfig?.defaultInstalled ?? true,
584579
inputList: item?.secretInputConfig,
585580
hasSystemSecret: !!dbPluginConfig?.inputListVal,
586581

@@ -599,11 +594,6 @@ export const refreshSystemTools = async (): Promise<SystemPluginTemplateItemType
599594
const concatTools = [...formatTools, ...dbPlugins];
600595
concatTools.sort((a, b) => (a.pluginOrder ?? 999) - (b.pluginOrder ?? 999));
601596

602-
global.systemToolsTypeCache = {};
603-
concatTools.forEach((item) => {
604-
global.systemToolsTypeCache[item.templateType] = 1;
605-
});
606-
607597
return concatTools;
608598
};
609599

@@ -622,7 +612,3 @@ export const getSystemToolById = async (id: string): Promise<SystemPluginTemplat
622612
if (!dbPlugin) return Promise.reject(PluginErrEnum.unExist);
623613
return dbPluginFormat(dbPlugin);
624614
};
625-
626-
declare global {
627-
var systemToolsTypeCache: Record<string, 1>;
628-
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { connectionMongo, getMongoModel } from '../../../common/mongo/index';
2+
import type { PluginTagSchemaType } from './type';
3+
const { Schema } = connectionMongo;
4+
5+
export const collectionName = 'app_plugin_tags';
6+
7+
const PluginTagSchema = new Schema({
8+
tagId: {
9+
type: String,
10+
required: true
11+
},
12+
tagName: {
13+
type: Schema.Types.Mixed,
14+
required: true
15+
},
16+
tagOrder: {
17+
type: Number,
18+
default: 0
19+
},
20+
isSystem: {
21+
type: Boolean,
22+
default: false
23+
}
24+
});
25+
26+
PluginTagSchema.index({ tagId: 1 }, { unique: true });
27+
PluginTagSchema.index({ tagOrder: 1 });
28+
29+
export const MongoPluginTag = getMongoModel<PluginTagSchemaType>(collectionName, PluginTagSchema);

packages/service/core/app/plugin/systemPluginSchema.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,13 @@ const SystemPluginSchema = new Schema({
99
type: String,
1010
required: true
1111
},
12-
isActive: {
13-
type: Boolean
12+
status: {
13+
type: Number,
14+
default: 1
15+
},
16+
defaultInstalled: {
17+
type: Boolean,
18+
default: true
1419
},
1520
originCost: {
1621
type: Number,
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { connectionMongo, getMongoModel } from '../../../common/mongo/index';
2+
import type { TeamInstalledPluginSchemaType } from './type';
3+
const { Schema } = connectionMongo;
4+
5+
export const collectionName = 'team_installed_plugins';
6+
7+
const TeamInstalledPluginSchema = new Schema({
8+
teamId: {
9+
type: Schema.Types.ObjectId,
10+
ref: 'teams',
11+
required: true
12+
},
13+
pluginId: {
14+
type: String,
15+
required: true
16+
},
17+
installed: {
18+
type: Boolean,
19+
required: true,
20+
default: true
21+
}
22+
});
23+
24+
TeamInstalledPluginSchema.index({ teamId: 1, pluginId: 1 }, { unique: true });
25+
TeamInstalledPluginSchema.index({ teamId: 1 });
26+
27+
export const MongoTeamInstalledPlugin = getMongoModel<TeamInstalledPluginSchemaType>(
28+
collectionName,
29+
TeamInstalledPluginSchema
30+
);

packages/service/core/app/plugin/type.d.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ export type SystemPluginConfigSchemaType = {
1010
originCost: number; // n points/one time
1111
currentCost: number;
1212
hasTokenFee: boolean;
13-
isActive: boolean;
13+
status?: number;
14+
defaultInstalled?: boolean;
1415
pluginOrder?: number;
1516
systemKeyCost?: number;
1617

@@ -21,14 +22,15 @@ export type SystemPluginConfigSchemaType = {
2122
toolDescription?: string;
2223
version: string;
2324
weight?: number;
24-
templateType: string;
25+
pluginTags?: string[];
2526
associatedPluginId: string;
2627
userGuide: string;
2728
author?: string;
2829
};
2930
inputListVal?: Record<string, any>;
3031

3132
// @deprecated
33+
isActive?: boolean;
3234
inputConfig?: {
3335
// Render config input form. Find the corresponding node and replace the variable directly
3436
key: string;
@@ -50,3 +52,17 @@ export type SystemToolGroupSchemaType = {
5052
groupTypes: TGroupType[];
5153
groupOrder: number;
5254
};
55+
56+
export type PluginTagSchemaType = {
57+
tagId: string;
58+
tagName: I18nStringStrictType | string;
59+
tagOrder: number;
60+
isSystem: boolean;
61+
};
62+
63+
export type TeamInstalledPluginSchemaType = {
64+
_id: string;
65+
teamId: string;
66+
pluginId: string;
67+
installed: boolean;
68+
};

packages/service/core/workflow/dispatch/child/runTool.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { getNodeErrResponse } from '../utils';
2222
import { splitCombinePluginId } from '@fastgpt/global/core/app/plugin/utils';
2323
import { getAppVersionById } from '../../../../core/app/version/controller';
2424
import { runHTTPTool } from '../../../app/http';
25+
import { i18nT } from '../../../../../web/i18n/utils';
2526

2627
type SystemInputConfigType = {
2728
type: SystemToolInputTypeEnum;
@@ -59,6 +60,12 @@ export const dispatchRunTool = async (props: RunToolProps): Promise<RunToolRespo
5960
if (toolConfig?.systemTool?.toolId) {
6061
const tool = await getSystemToolById(toolConfig.systemTool!.toolId);
6162

63+
if (tool.status === 0) {
64+
return getNodeErrResponse({
65+
error: i18nT('app:Plugin_offline_tips')
66+
});
67+
}
68+
6269
const inputConfigParams = await (async () => {
6370
switch (params.system_input_config?.type) {
6471
case SystemToolInputTypeEnum.team:

packages/service/core/workflow/dispatch/plugin/run.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,13 @@ import { computedPluginUsage } from '../../../app/plugin/utils';
2222
import { filterSystemVariables, getNodeErrResponse } from '../utils';
2323
import { getPluginRunUserQuery } from '@fastgpt/global/core/workflow/utils';
2424
import type { NodeInputKeyEnum, NodeOutputKeyEnum } from '@fastgpt/global/core/workflow/constants';
25-
import { getChildAppRuntimeById } from '../../../app/plugin/controller';
25+
import { getChildAppRuntimeById, getSystemToolById } from '../../../app/plugin/controller';
2626
import { runWorkflow } from '../index';
2727
import { getUserChatInfo } from '../../../../support/user/team/utils';
2828
import { dispatchRunTool } from '../child/runTool';
2929
import type { PluginRuntimeType } from '@fastgpt/global/core/app/plugin/type';
3030
import { anyValueDecrypt } from '../../../../common/secret/utils';
31+
import { i18nT } from '../../../../../web/i18n/utils';
3132

3233
type RunPluginProps = ModuleDispatchProps<{
3334
[NodeInputKeyEnum.forbidStream]?: boolean;
@@ -85,6 +86,17 @@ export const dispatchRunPlugin = async (props: RunPluginProps): Promise<RunPlugi
8586
per: ReadPermissionVal
8687
});
8788

89+
const { source: pluginSource } = splitCombinePluginId(pluginId);
90+
if (pluginSource === PluginSourceEnum.systemTool) {
91+
const systemPlugin = await getSystemToolById(pluginId);
92+
93+
if (systemPlugin.status === 0) {
94+
return getNodeErrResponse({
95+
error: i18nT('app:Plugin_offline_tips')
96+
});
97+
}
98+
}
99+
88100
plugin = await getChildAppRuntimeById({ id: pluginId, versionId: version });
89101

90102
const outputFilterMap =

0 commit comments

Comments
 (0)