mirror of
https://github.com/labring/FastGPT.git
synced 2025-10-17 16:45:02 +00:00

* 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 * update mcp server (#5076) * update mcp server * fix: action * fix: dockerfile * fix: dockerfile * fix: dockerfile * fix: dockerfile * fix: dockerfile * fix: dockerfile * 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 * perf: run tool * update package * perf: config key * fix: tool ini * tool config params * perf: workflow type * rename tools to agent * version list * perf: tool error * config secret ux * perf: config secret ux * fix: tool config field * add course to secret input * feat: support inputConfig switch (#5099) * feat: support inputConfig switch * deps: update @fastgpt-sdk/plugin * chore: update workflows * fix: inputType * fix: secret * add default value to node * update i18n * eslint * add precision to number input * feat: add number input and select * perf: number ux * fix: code * Proxies image requests to plugin service (#5111) * Proxies image requests to plugin service Adds a rewrite rule and API endpoint to proxy image requests to the plugin service. This allows the app to fetch images from the plugin's tools directory. It also adds the plugin base URL to the service's constants, so that it can use the plugin URL when proxying requests. * fix: update FastGPTPluginUrl to remove unnecessary API path * feat: update image proxy destination and add plugin image handler * Adapt plugin id * replace avatar * remove rewrite * fix: plugin avatar * update system tool doc * feat: system tool type * yml sh * yml sh * update doc * fix: simple app tool select * fix: switch ui * update pacakge * Yamljs (#5129) * update docker-compose configuration: bump fastgpt and fastgpt-plugin images, change minio host to service name, and adjust service dependencies * refactor: comment out port exposure in docker-compose configuration * update: uncomment port exposure in docker-compose configuration * update: change MINIO_HOST to use specific IP address in docker configuration * update: modify fastgpt-plugin image version in docker configuration * update readme * doc * remove --------- Co-authored-by: Finley Ge <32237950+FinleyGe@users.noreply.github.com> Co-authored-by: Theresa <63280168+sd0ric4@users.noreply.github.com>
113 lines
3.3 KiB
TypeScript
113 lines
3.3 KiB
TypeScript
import { type AppSchema } from '@fastgpt/global/core/app/type';
|
|
import { NodeInputKeyEnum } from '@fastgpt/global/core/workflow/constants';
|
|
import { FlowNodeTypeEnum } from '@fastgpt/global/core/workflow/node/constant';
|
|
import { MongoApp } from './schema';
|
|
import type { StoreNodeItemType } from '@fastgpt/global/core/workflow/type/node';
|
|
import { encryptSecretValue, storeSecretValue } from '../../common/secret/utils';
|
|
import { SystemToolInputTypeEnum } from '@fastgpt/global/core/app/systemTool/constants';
|
|
|
|
export const beforeUpdateAppFormat = ({ nodes }: { nodes?: StoreNodeItemType[] }) => {
|
|
if (!nodes) return;
|
|
|
|
nodes.forEach((node) => {
|
|
// Format header secret
|
|
node.inputs.forEach((input) => {
|
|
if (input.key === NodeInputKeyEnum.headerSecret && typeof input.value === 'object') {
|
|
input.value = storeSecretValue(input.value);
|
|
}
|
|
if (input.key === NodeInputKeyEnum.systemInputConfig && typeof input.value === 'object') {
|
|
input.inputList?.forEach((inputItem) => {
|
|
if (
|
|
inputItem.inputType === 'secret' &&
|
|
input.value?.type === SystemToolInputTypeEnum.manual &&
|
|
input.value?.value
|
|
) {
|
|
input.value.value[inputItem.key] = encryptSecretValue(input.value.value[inputItem.key]);
|
|
}
|
|
});
|
|
}
|
|
});
|
|
|
|
// Format dataset search
|
|
if (node.flowNodeType === FlowNodeTypeEnum.datasetSearchNode) {
|
|
node.inputs.forEach((input) => {
|
|
if (input.key === NodeInputKeyEnum.datasetSelectList) {
|
|
const val = input.value as undefined | { datasetId: string }[] | { datasetId: string };
|
|
if (!val) {
|
|
input.value = [];
|
|
} else if (Array.isArray(val)) {
|
|
// Not rewrite reference value
|
|
if (val.length === 2 && val.every((item) => typeof item === 'string')) {
|
|
return;
|
|
}
|
|
input.value = val
|
|
.map((dataset: { datasetId: string }) => ({
|
|
datasetId: dataset.datasetId
|
|
}))
|
|
.filter((item) => !!item.datasetId);
|
|
} else if (typeof val === 'object' && val !== null) {
|
|
input.value = [
|
|
{
|
|
datasetId: val.datasetId
|
|
}
|
|
];
|
|
}
|
|
}
|
|
});
|
|
}
|
|
});
|
|
};
|
|
|
|
/* Get apps */
|
|
export async function findAppAndAllChildren({
|
|
teamId,
|
|
appId,
|
|
fields
|
|
}: {
|
|
teamId: string;
|
|
appId: string;
|
|
fields?: string;
|
|
}): Promise<AppSchema[]> {
|
|
const find = async (id: string) => {
|
|
const children = await MongoApp.find(
|
|
{
|
|
teamId,
|
|
parentId: id
|
|
},
|
|
fields
|
|
).lean();
|
|
|
|
let apps = children;
|
|
|
|
for (const child of children) {
|
|
const grandChildrenIds = await find(child._id);
|
|
apps = apps.concat(grandChildrenIds);
|
|
}
|
|
|
|
return apps;
|
|
};
|
|
const [app, childDatasets] = await Promise.all([MongoApp.findById(appId, fields), find(appId)]);
|
|
|
|
if (!app) {
|
|
return Promise.reject('Dataset not found');
|
|
}
|
|
|
|
return [app, ...childDatasets];
|
|
}
|
|
|
|
export const getAppBasicInfoByIds = async ({ teamId, ids }: { teamId: string; ids: string[] }) => {
|
|
const apps = await MongoApp.find(
|
|
{
|
|
teamId,
|
|
_id: { $in: ids }
|
|
},
|
|
'_id name avatar'
|
|
).lean();
|
|
|
|
return apps.map((item) => ({
|
|
id: item._id,
|
|
name: item.name,
|
|
avatar: item.avatar
|
|
}));
|
|
};
|