feat: undo-redo & edit snapshots (#2436)
* feat: undo-redo & edit snapshots * fix merge * add simple history back * fix some undo * change app latest version * fix * chatconfig * fix snapshot * fix * fix * fix * fix compare * fix initial * fix merge: * fix useEffect * fix snapshot initial and saved state * chore * fix * compare snapshot * nodes edges useEffct * fix chatconfig * fix * delete unused method * fix * fix * fix * default version name
This commit is contained in:
@@ -14,6 +14,8 @@ import { defaultNodeVersion } from '@fastgpt/global/core/workflow/node/constant'
|
||||
import { ClientSession } from '@fastgpt/service/common/mongo';
|
||||
import { authApp } from '@fastgpt/service/support/permission/app/auth';
|
||||
import { CommonErrEnum } from '@fastgpt/global/common/error/code/common';
|
||||
import { MongoTeamMember } from '@fastgpt/service/support/user/team/teamMemberSchema';
|
||||
import { MongoUser } from '@fastgpt/service/support/user/schema';
|
||||
|
||||
export type CreateAppBody = {
|
||||
parentId?: ParentIdType;
|
||||
@@ -42,6 +44,8 @@ async function handler(req: ApiRequestProps<CreateAppBody>) {
|
||||
|
||||
// 上限校验
|
||||
await checkTeamAppLimit(teamId);
|
||||
const tmb = await MongoTeamMember.findById({ _id: tmbId });
|
||||
const user = await MongoUser.findById({ _id: tmb?.userId });
|
||||
|
||||
// 创建app
|
||||
const appId = await onCreateApp({
|
||||
@@ -53,7 +57,9 @@ async function handler(req: ApiRequestProps<CreateAppBody>) {
|
||||
edges,
|
||||
chatConfig,
|
||||
teamId,
|
||||
tmbId
|
||||
tmbId,
|
||||
userAvatar: user?.avatar,
|
||||
username: user?.username
|
||||
});
|
||||
|
||||
return appId;
|
||||
@@ -73,6 +79,8 @@ export const onCreateApp = async ({
|
||||
teamId,
|
||||
tmbId,
|
||||
pluginData,
|
||||
username,
|
||||
userAvatar,
|
||||
session
|
||||
}: {
|
||||
parentId?: ParentIdType;
|
||||
@@ -86,6 +94,8 @@ export const onCreateApp = async ({
|
||||
teamId: string;
|
||||
tmbId: string;
|
||||
pluginData?: AppSchema['pluginData'];
|
||||
username?: string;
|
||||
userAvatar?: string;
|
||||
session?: ClientSession;
|
||||
}) => {
|
||||
const create = async (session: ClientSession) => {
|
||||
@@ -117,7 +127,10 @@ export const onCreateApp = async ({
|
||||
appId,
|
||||
nodes: modules,
|
||||
edges,
|
||||
chatConfig
|
||||
chatConfig,
|
||||
versionName: name,
|
||||
username,
|
||||
avatar: userAvatar
|
||||
}
|
||||
],
|
||||
{ session }
|
||||
|
||||
@@ -10,13 +10,18 @@ import { PostPublishAppProps } from '@/global/core/app/api';
|
||||
import { WritePermissionVal } from '@fastgpt/global/support/permission/constant';
|
||||
import { AppTypeEnum } from '@fastgpt/global/core/app/constants';
|
||||
|
||||
type Response = {};
|
||||
|
||||
async function handler(req: NextApiRequest, res: NextApiResponse<any>): Promise<{}> {
|
||||
const { appId } = req.query as { appId: string };
|
||||
const { nodes = [], edges = [], chatConfig, type } = req.body as PostPublishAppProps;
|
||||
const {
|
||||
nodes = [],
|
||||
edges = [],
|
||||
chatConfig,
|
||||
type,
|
||||
isPublish,
|
||||
versionName
|
||||
} = req.body as PostPublishAppProps;
|
||||
|
||||
const { app } = await authApp({ appId, req, per: WritePermissionVal, authToken: true });
|
||||
const { app, tmbId } = await authApp({ appId, req, per: WritePermissionVal, authToken: true });
|
||||
|
||||
const { nodes: formatNodes } = beforeUpdateAppFormat({ nodes });
|
||||
|
||||
@@ -28,7 +33,10 @@ async function handler(req: NextApiRequest, res: NextApiResponse<any>): Promise<
|
||||
appId,
|
||||
nodes: formatNodes,
|
||||
edges,
|
||||
chatConfig
|
||||
chatConfig,
|
||||
isPublish,
|
||||
versionName,
|
||||
tmbId
|
||||
}
|
||||
],
|
||||
{ session }
|
||||
|
||||
27
projects/app/src/pages/api/core/app/version/update.ts
Normal file
27
projects/app/src/pages/api/core/app/version/update.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { NextAPI } from '@/service/middleware/entry';
|
||||
import { authApp } from '@fastgpt/service/support/permission/app/auth';
|
||||
import { WritePermissionVal } from '@fastgpt/global/support/permission/constant';
|
||||
import { ApiRequestProps } from '@fastgpt/service/type/next';
|
||||
import { MongoAppVersion } from '@fastgpt/service/core/app/version/schema';
|
||||
|
||||
export type UpdateAppVersionBody = {
|
||||
appId: string;
|
||||
versionId: string;
|
||||
versionName: string;
|
||||
};
|
||||
|
||||
async function handler(req: ApiRequestProps<UpdateAppVersionBody>) {
|
||||
const { appId, versionId, versionName } = req.body;
|
||||
await authApp({ appId, req, per: WritePermissionVal, authToken: true });
|
||||
|
||||
await MongoAppVersion.findByIdAndUpdate(
|
||||
{ _id: versionId },
|
||||
{
|
||||
versionName
|
||||
}
|
||||
);
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
export default NextAPI(handler);
|
||||
@@ -45,7 +45,7 @@ async function handler(
|
||||
}
|
||||
|
||||
// get app and history
|
||||
const [{ histories }, { nodes }] = await Promise.all([
|
||||
const [{ histories }, { nodes, chatConfig }] = await Promise.all([
|
||||
getChatItems({
|
||||
appId,
|
||||
chatId,
|
||||
@@ -68,7 +68,7 @@ async function handler(
|
||||
history: app.type === AppTypeEnum.plugin ? histories : transformPreviewHistories(histories),
|
||||
app: {
|
||||
chatConfig: getAppChatConfig({
|
||||
chatConfig: app.chatConfig,
|
||||
chatConfig,
|
||||
systemConfigNode: getGuideModule(nodes),
|
||||
storeVariables: chat?.variableList,
|
||||
storeWelcomeText: chat?.welcomeText,
|
||||
|
||||
@@ -42,7 +42,7 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
throw new Error(ChatErrEnum.unAuthChat);
|
||||
}
|
||||
|
||||
const [{ histories }, { nodes }] = await Promise.all([
|
||||
const [{ histories }, { nodes, chatConfig }] = await Promise.all([
|
||||
getChatItems({
|
||||
appId: app._id,
|
||||
chatId,
|
||||
@@ -75,7 +75,7 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
history: app.type === AppTypeEnum.plugin ? histories : transformPreviewHistories(histories),
|
||||
app: {
|
||||
chatConfig: getAppChatConfig({
|
||||
chatConfig: app.chatConfig,
|
||||
chatConfig,
|
||||
systemConfigNode: getGuideModule(nodes),
|
||||
storeVariables: chat?.variableList,
|
||||
storeWelcomeText: chat?.welcomeText,
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import type { NextApiRequest, NextApiResponse } from 'next';
|
||||
import { jsonRes } from '@fastgpt/service/common/response';
|
||||
import { connectToDatabase } from '@/service/mongo';
|
||||
import { getGuideModule, getAppChatConfig } from '@fastgpt/global/core/workflow/utils';
|
||||
import { getChatModelNameListByModules } from '@/service/core/app/workflow';
|
||||
import { DispatchNodeResponseKeyEnum } from '@fastgpt/global/core/workflow/runtime/constants';
|
||||
@@ -48,7 +47,7 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
}
|
||||
|
||||
// get app and history
|
||||
const [{ histories }, { nodes }] = await Promise.all([
|
||||
const [{ histories }, { nodes, chatConfig }] = await Promise.all([
|
||||
getChatItems({
|
||||
appId,
|
||||
chatId,
|
||||
@@ -76,7 +75,7 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
history: app.type === AppTypeEnum.plugin ? histories : transformPreviewHistories(histories),
|
||||
app: {
|
||||
chatConfig: getAppChatConfig({
|
||||
chatConfig: app.chatConfig,
|
||||
chatConfig,
|
||||
systemConfigNode: getGuideModule(nodes),
|
||||
storeVariables: chat?.variableList,
|
||||
storeWelcomeText: chat?.welcomeText,
|
||||
|
||||
Reference in New Issue
Block a user