Skip to content
Merged
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
6 changes: 6 additions & 0 deletions packages/global/core/app/plugin/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,9 @@ export enum PluginSourceEnum {
// @deprecated
community = 'community' // this is deprecated, will be replaced by systemTool
}

export enum PluginStatusEnum {
Offline = 0,
Normal = 1,
SoonOffline = 2
}
33 changes: 29 additions & 4 deletions packages/global/core/app/plugin/type.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ import type { FlowNodeTemplateType } from '../../workflow/type/node';
import type { WorkflowTemplateType } from '../../workflow/type';
import type { FlowNodeInputItemType, FlowNodeOutputItemType } from '../../workflow/type/io';
import type { ParentIdType } from 'common/parentFolder/type';
import type { I18nStringStrictType } from '@fastgpt/global/sdk/fastgpt-plugin';
import type { I18nStringType } from '../../../common/i18n/type';

export type PluginTagType = {
tagId: string;
tagName: I18nStringStrictType | string;
tagOrder: number;
isSystem: boolean;
};

export type PluginRuntimeType = {
id: string;
Expand All @@ -25,8 +34,6 @@ export type PluginRuntimeType = {

// system plugin
export type SystemPluginTemplateItemType = WorkflowTemplateType & {
templateType: string;

// FastGPT-plugin tool
inputs?: FlowNodeInputItemType[];
outputs?: FlowNodeOutputItemType[];
Expand All @@ -49,7 +56,9 @@ export type SystemPluginTemplateItemType = WorkflowTemplateType & {
hasTokenFee?: boolean;
pluginOrder?: number;

isActive?: boolean;
pluginTags?: string[];
status?: number;
defaultInstalled?: boolean;
isOfficial?: boolean;

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

// Plugin source type
toolSource?: 'uploaded' | 'built-in';

// @deprecated use pluginTags instead
isActive?: boolean;
templateType?: string;
};

export type SystemPluginTemplateListItemType = Omit<
SystemPluginTemplateItemType,
'name' | 'intro'
'name' | 'intro' | 'workflow'
> & {
name: string;
intro: string;
tags?: PluginTagType[];
};

// Marketplace Tool Types
export type ToolListItem = {
id: string;
name: I18nStringType;
description: I18nStringType;
avatar: string;
author?: string;
tags: string[];
downloadCount: number;
};
7 changes: 6 additions & 1 deletion packages/global/core/workflow/type/node.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ export type PluginDataType = {
name?: string;
avatar?: string;
error?: string;
status?: number;
pluginTags?: string[];
};

type HandleType = {
Expand All @@ -131,6 +133,8 @@ export type FlowNodeTemplateType = FlowNodeCommonType & {
diagram?: string; // diagram url
courseUrl?: string; // course url
userGuide?: string; // user guide
status?: number;
pluginTags?: string[];

// @deprecated
// show handle
Expand All @@ -143,7 +147,8 @@ export type NodeTemplateListItemType = {
flowNodeType: FlowNodeTypeEnum; // render node card
parentId?: ParentIdType;
isFolder?: boolean;
templateType: string;
templateType?: string;
pluginTags?: string[];
avatar?: string;
name: string;
intro?: string; // template list intro
Expand Down
38 changes: 12 additions & 26 deletions packages/service/core/app/plugin/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ export async function getChildAppPreviewNode({
systemToolSet: {
toolId: app.id,
toolList: children
.filter((item) => item.isActive !== false)
.filter((item) => item.status === 1 || item.status === undefined)
.map((item) => ({
toolId: item.id,
name: parseI18nString(item.name, lang),
Expand Down Expand Up @@ -407,7 +407,7 @@ export async function getChildAppPreviewNode({
return {
id: getNanoid(),
pluginId: app.id,
templateType: app.templateType,
templateType: app.templateType ?? FlowNodeTemplateTypeEnum.tools,
flowNodeType,
avatar: app.avatar,
name: parseI18nString(app.name, lang),
Expand Down Expand Up @@ -507,21 +507,13 @@ export async function getChildAppRuntimeById({
}

const dbPluginFormat = (item: SystemPluginConfigSchemaType): SystemPluginTemplateItemType => {
const {
name,
avatar,
intro,
toolDescription,
version,
weight,
templateType,
associatedPluginId,
userGuide
} = item.customConfig!;
const { name, avatar, intro, toolDescription, version, weight, associatedPluginId, userGuide } =
item.customConfig!;

return {
id: item.pluginId,
isActive: item.isActive,
status: item.status ?? 1,
defaultInstalled: item.defaultInstalled ?? true,
isFolder: false,
parentId: null,
author: item.customConfig?.author || '',
Expand All @@ -531,7 +523,7 @@ const dbPluginFormat = (item: SystemPluginConfigSchemaType): SystemPluginTemplat
intro,
toolDescription,
weight,
templateType,
templateType: FlowNodeTemplateTypeEnum.tools,
originCost: item.originCost,
currentCost: item.currentCost,
hasTokenFee: item.hasTokenFee,
Expand Down Expand Up @@ -573,14 +565,17 @@ export const refreshSystemTools = async (): Promise<SystemPluginTemplateItemType
instructions: dbPluginConfig?.customConfig?.userGuide,
weight: item.weight,
toolSource: item.toolSource || 'built-in',
// temporarily fixed
pluginTags: (item as any).pluginTags,
workflow: {
nodes: [],
edges: []
},
versionList,
templateType: item.templateType,
templateType: item.templateType ?? FlowNodeTemplateTypeEnum.tools,
showStatus: true,
isActive: dbPluginConfig?.isActive ?? item.isActive ?? true,
status: dbPluginConfig?.status ?? 1,
defaultInstalled: dbPluginConfig?.defaultInstalled ?? true,
inputList: item?.secretInputConfig,
hasSystemSecret: !!dbPluginConfig?.inputListVal,

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

global.systemToolsTypeCache = {};
concatTools.forEach((item) => {
global.systemToolsTypeCache[item.templateType] = 1;
});

return concatTools;
};

Expand All @@ -622,7 +612,3 @@ export const getSystemToolById = async (id: string): Promise<SystemPluginTemplat
if (!dbPlugin) return Promise.reject(PluginErrEnum.unExist);
return dbPluginFormat(dbPlugin);
};

declare global {
var systemToolsTypeCache: Record<string, 1>;
}
29 changes: 29 additions & 0 deletions packages/service/core/app/plugin/pluginTagSchema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { connectionMongo, getMongoModel } from '../../../common/mongo/index';
import type { PluginTagSchemaType } from './type';
const { Schema } = connectionMongo;

export const collectionName = 'app_plugin_tags';

const PluginTagSchema = new Schema({
tagId: {
type: String,
required: true
},
tagName: {
type: Schema.Types.Mixed,
required: true
},
tagOrder: {
type: Number,
default: 0
},
isSystem: {
type: Boolean,
default: false
}
});

PluginTagSchema.index({ tagId: 1 }, { unique: true });
PluginTagSchema.index({ tagOrder: 1 });

export const MongoPluginTag = getMongoModel<PluginTagSchemaType>(collectionName, PluginTagSchema);
9 changes: 7 additions & 2 deletions packages/service/core/app/plugin/systemPluginSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@ const SystemPluginSchema = new Schema({
type: String,
required: true
},
isActive: {
type: Boolean
status: {
type: Number,
default: 1
},
defaultInstalled: {
type: Boolean,
default: true
},
originCost: {
type: Number,
Expand Down
30 changes: 30 additions & 0 deletions packages/service/core/app/plugin/teamInstalledPluginSchema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { connectionMongo, getMongoModel } from '../../../common/mongo/index';
import type { TeamInstalledPluginSchemaType } from './type';
const { Schema } = connectionMongo;

export const collectionName = 'team_installed_plugins';

const TeamInstalledPluginSchema = new Schema({
teamId: {
type: Schema.Types.ObjectId,
ref: 'teams',
required: true
},
pluginId: {
type: String,
required: true
},
installed: {
type: Boolean,
required: true,
default: true
}
});

TeamInstalledPluginSchema.index({ teamId: 1, pluginId: 1 }, { unique: true });
TeamInstalledPluginSchema.index({ teamId: 1 });

export const MongoTeamInstalledPlugin = getMongoModel<TeamInstalledPluginSchemaType>(
collectionName,
TeamInstalledPluginSchema
);
20 changes: 18 additions & 2 deletions packages/service/core/app/plugin/type.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ export type SystemPluginConfigSchemaType = {
originCost: number; // n points/one time
currentCost: number;
hasTokenFee: boolean;
isActive: boolean;
status?: number;
defaultInstalled?: boolean;
pluginOrder?: number;
systemKeyCost?: number;

Expand All @@ -21,14 +22,15 @@ export type SystemPluginConfigSchemaType = {
toolDescription?: string;
version: string;
weight?: number;
templateType: string;
pluginTags?: string[];
associatedPluginId: string;
userGuide: string;
author?: string;
};
inputListVal?: Record<string, any>;

// @deprecated
isActive?: boolean;
inputConfig?: {
// Render config input form. Find the corresponding node and replace the variable directly
key: string;
Expand All @@ -50,3 +52,17 @@ export type SystemToolGroupSchemaType = {
groupTypes: TGroupType[];
groupOrder: number;
};

export type PluginTagSchemaType = {
tagId: string;
tagName: I18nStringStrictType | string;
tagOrder: number;
isSystem: boolean;
};

export type TeamInstalledPluginSchemaType = {
_id: string;
teamId: string;
pluginId: string;
installed: boolean;
};
7 changes: 7 additions & 0 deletions packages/service/core/workflow/dispatch/child/runTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { getNodeErrResponse } from '../utils';
import { splitCombinePluginId } from '@fastgpt/global/core/app/plugin/utils';
import { getAppVersionById } from '../../../../core/app/version/controller';
import { runHTTPTool } from '../../../app/http';
import { i18nT } from '../../../../../web/i18n/utils';

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

if (tool.status === 0) {
return getNodeErrResponse({
error: i18nT('app:Plugin_offline_tips')
});
}

const inputConfigParams = await (async () => {
switch (params.system_input_config?.type) {
case SystemToolInputTypeEnum.team:
Expand Down
14 changes: 13 additions & 1 deletion packages/service/core/workflow/dispatch/plugin/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ import { computedPluginUsage } from '../../../app/plugin/utils';
import { filterSystemVariables, getNodeErrResponse } from '../utils';
import { getPluginRunUserQuery } from '@fastgpt/global/core/workflow/utils';
import type { NodeInputKeyEnum, NodeOutputKeyEnum } from '@fastgpt/global/core/workflow/constants';
import { getChildAppRuntimeById } from '../../../app/plugin/controller';
import { getChildAppRuntimeById, getSystemToolById } from '../../../app/plugin/controller';
import { runWorkflow } from '../index';
import { getUserChatInfo } from '../../../../support/user/team/utils';
import { dispatchRunTool } from '../child/runTool';
import type { PluginRuntimeType } from '@fastgpt/global/core/app/plugin/type';
import { i18nT } from '../../../../../web/i18n/utils';

type RunPluginProps = ModuleDispatchProps<{
[NodeInputKeyEnum.forbidStream]?: boolean;
Expand Down Expand Up @@ -81,6 +82,17 @@ export const dispatchRunPlugin = async (props: RunPluginProps): Promise<RunPlugi
per: ReadPermissionVal
});

const { source: pluginSource } = splitCombinePluginId(pluginId);
if (pluginSource === PluginSourceEnum.systemTool) {
const systemPlugin = await getSystemToolById(pluginId);

if (systemPlugin.status === 0) {
return getNodeErrResponse({
error: i18nT('app:Plugin_offline_tips')
});
}
}

plugin = await getChildAppRuntimeById({ id: pluginId, versionId: version });

const outputFilterMap =
Expand Down
2 changes: 1 addition & 1 deletion packages/service/core/workflow/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export async function getSystemToolRunTimeNodeFromSystemToolset({
);
const tools = await getSystemTools();
const children = tools.filter(
(item) => item.parentId === systemToolId && item.isActive !== false
(item) => item.parentId === systemToolId && (item.status === 1 || item.status === undefined)
);
const nodes = await Promise.all(
children.map(async (child, index) => {
Expand Down
Loading
Loading