mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-21 03:35:36 +00:00
71 lines
1.5 KiB
TypeScript
71 lines
1.5 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 { getLLMModel } from '../ai/model';
|
|
import { MongoApp } from './schema';
|
|
|
|
export const beforeUpdateAppFormat = <T extends AppSchema['modules'] | undefined>({
|
|
nodes,
|
|
isPlugin
|
|
}: {
|
|
nodes: T;
|
|
isPlugin: boolean;
|
|
}) => {
|
|
return {
|
|
nodes
|
|
};
|
|
};
|
|
|
|
/* 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
|
|
}));
|
|
};
|