mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-24 13:53:50 +00:00

* feat(app publish): feishu bot (#2290) * feat: feishu publish channel fe * feat: enable feishu fe, feat: feishu token api * feat: feishu bot * chore: extract saveChat from projects/app * chore: remove debug log output * feat: Basic Info * chore: feishu bot fe adjusting * feat: feishu bot docs * feat: new tmpData collection for all tmpdata * chore: compress the image * perf: feishu config * feat: source name * perf: text desc * perf: load system plugins * perf: chat source * feat(publish): Wecom bot (#2343) * chore: Wecom Config * feat(fe): wecom config fe * feat: wecom fe * chore: uses the newest editmodal * feat: update png; adjust the fe * chore: adjust fe * perf: publish app ui --------- Co-authored-by: Finley Ge <32237950+FinleyGe@users.noreply.github.com>
97 lines
2.5 KiB
TypeScript
97 lines
2.5 KiB
TypeScript
import { PluginSourceEnum } from '@fastgpt/global/core/plugin/constants';
|
|
import { SystemPluginResponseType } from './type';
|
|
import { SystemPluginTemplateItemType } from '@fastgpt/global/core/workflow/type';
|
|
import { cloneDeep } from 'lodash';
|
|
import { WorkerNameEnum, runWorker } from '@fastgpt/service/worker/utils';
|
|
|
|
// Run in main thread
|
|
const staticPluginList = [
|
|
'getTime',
|
|
'fetchUrl',
|
|
'Doc2X',
|
|
'Doc2X/URLPDF2text',
|
|
'Doc2X/URLImg2text',
|
|
`Doc2X/FilePDF2text`,
|
|
`Doc2X/FileImg2text`,
|
|
'feishu'
|
|
];
|
|
// Run in worker thread (Have npm packages)
|
|
const packagePluginList = [
|
|
'mathExprVal',
|
|
'duckduckgo',
|
|
'duckduckgo/search',
|
|
'duckduckgo/searchImg',
|
|
'duckduckgo/searchNews',
|
|
'duckduckgo/searchVideo'
|
|
];
|
|
|
|
export const list = [...staticPluginList, ...packagePluginList];
|
|
|
|
/* Get plugins */
|
|
export const getCommunityPlugins = () => {
|
|
return list.map<SystemPluginTemplateItemType>((name) => {
|
|
const config = require(`./src/${name}/template.json`);
|
|
|
|
const isFolder = list.find((item) => item.startsWith(`${name}/`));
|
|
|
|
const parentIdList = name.split('/').slice(0, -1);
|
|
const parentId =
|
|
parentIdList.length > 0 ? `${PluginSourceEnum.community}-${parentIdList.join('/')}` : null;
|
|
|
|
return {
|
|
...config,
|
|
id: `${PluginSourceEnum.community}-${name}`,
|
|
isFolder,
|
|
parentId,
|
|
isActive: true
|
|
};
|
|
});
|
|
};
|
|
|
|
export const getSystemPluginTemplates = () => {
|
|
const oldPlugins = global.communityPlugins ?? [];
|
|
return [...oldPlugins, ...cloneDeep(global.systemPlugins)];
|
|
};
|
|
|
|
export const getCommunityCb = async () => {
|
|
const loadCommunityModule = async (name: string) => {
|
|
const module = await import(`./src/${name}/index`);
|
|
return module.default;
|
|
};
|
|
|
|
const result = (
|
|
await Promise.all(
|
|
list.map(async (name) => {
|
|
try {
|
|
return {
|
|
name,
|
|
cb: staticPluginList.includes(name)
|
|
? await loadCommunityModule(name)
|
|
: (e: any) => {
|
|
return runWorker(WorkerNameEnum.systemPluginRun, {
|
|
pluginName: name,
|
|
data: e
|
|
});
|
|
}
|
|
};
|
|
} catch (error) {}
|
|
})
|
|
)
|
|
).filter(Boolean) as {
|
|
name: string;
|
|
cb: any;
|
|
}[];
|
|
|
|
return result.reduce<Record<string, (e: any) => SystemPluginResponseType>>(
|
|
(acc, { name, cb }) => {
|
|
acc[name] = cb;
|
|
return acc;
|
|
},
|
|
{}
|
|
);
|
|
};
|
|
|
|
export const getSystemPluginCb = async () => {
|
|
return global.systemPluginCb;
|
|
};
|