From 36b234c4fdb4dff533ff683a2c181ef7689846e7 Mon Sep 17 00:00:00 2001
From: archer <545436317@qq.com>
Date: Fri, 28 Jul 2023 09:00:10 +0800
Subject: [PATCH] feat: flow data type check
---
client/public/locales/en/common.json | 2 ++
client/public/locales/zh/common.json | 2 ++
client/src/constants/flow/defaultModule.ts | 5 ----
client/src/constants/flow/index.ts | 4 +--
client/src/pages/api/system/getInitData.ts | 2 +-
.../AdEdit/components/render/SourceHandle.tsx | 23 +++++++++-------
.../AdEdit/components/render/TargetHandle.tsx | 25 ++++++++++--------
.../app/detail/components/AdEdit/index.tsx | 26 ++++++++++++++++++-
client/src/service/utils/wxpay.ts | 23 +++++++++-------
9 files changed, 73 insertions(+), 39 deletions(-)
delete mode 100644 client/src/constants/flow/defaultModule.ts
diff --git a/client/public/locales/en/common.json b/client/public/locales/en/common.json
index 37e4a184f..485124f8e 100644
--- a/client/public/locales/en/common.json
+++ b/client/public/locales/en/common.json
@@ -7,6 +7,8 @@
"App Detail": "App Detail",
"Confirm Del App Tip": "Confirm to delete the app and all its chats",
"Confirm Save App Tip": "After saving, the advanced orchestration configuration will be overwritten. Make sure that the application does not use advanced orchestration.",
+ "Connection is invalid": "Connecting is invalid",
+ "Connection type is different": "Connection type is different",
"My Apps": "My Apps"
},
"chat": {
diff --git a/client/public/locales/zh/common.json b/client/public/locales/zh/common.json
index 35118f55c..c70c2d81e 100644
--- a/client/public/locales/zh/common.json
+++ b/client/public/locales/zh/common.json
@@ -7,6 +7,8 @@
"App Detail": "应用详情",
"Confirm Del App Tip": "确认删除该应用及其所有聊天记录?",
"Confirm Save App Tip": "保存后将会覆盖高级编排配置,请确保该应用未使用高级编排功能。",
+ "Connection is invalid": "连接无效",
+ "Connection type is different": "连接的类型不一致",
"My Apps": "我的应用"
},
"chat": {
diff --git a/client/src/constants/flow/defaultModule.ts b/client/src/constants/flow/defaultModule.ts
deleted file mode 100644
index fa6d725f4..000000000
--- a/client/src/constants/flow/defaultModule.ts
+++ /dev/null
@@ -1,5 +0,0 @@
-import { CSSProperties } from 'react';
-
-export const nodeDefaultStyle: CSSProperties = {
- border: '1px solid #DEE0E2'
-};
diff --git a/client/src/constants/flow/index.ts b/client/src/constants/flow/index.ts
index 70cc3aa64..cd0ead49a 100644
--- a/client/src/constants/flow/index.ts
+++ b/client/src/constants/flow/index.ts
@@ -41,8 +41,8 @@ export enum FlowValueTypeEnum {
'string' = 'string',
'number' = 'number',
'boolean' = 'boolean',
- 'chatHistory' = 'chatHistory',
- 'kbQuote' = 'kbQuote',
+ 'chatHistory' = 'chat_history',
+ 'kbQuote' = 'kb_quote',
'other' = 'other'
}
diff --git a/client/src/pages/api/system/getInitData.ts b/client/src/pages/api/system/getInitData.ts
index 1cd55dafb..c1725646b 100644
--- a/client/src/pages/api/system/getInitData.ts
+++ b/client/src/pages/api/system/getInitData.ts
@@ -40,7 +40,7 @@ const defaultSystemEnv = {
const defaultFeConfigs = {
show_emptyChat: true,
show_register: true,
- show_appStore: true,
+ show_appStore: false,
show_userDetail: true,
show_git: true,
systemTitle: 'FastAI',
diff --git a/client/src/pages/app/detail/components/AdEdit/components/render/SourceHandle.tsx b/client/src/pages/app/detail/components/AdEdit/components/render/SourceHandle.tsx
index 8d7e74e0a..01b58e006 100644
--- a/client/src/pages/app/detail/components/AdEdit/components/render/SourceHandle.tsx
+++ b/client/src/pages/app/detail/components/AdEdit/components/render/SourceHandle.tsx
@@ -2,6 +2,7 @@ import React, { useMemo } from 'react';
import { Box, BoxProps } from '@chakra-ui/react';
import { Handle, Position } from 'reactflow';
import { FlowValueTypeEnum, FlowValueTypeStyle } from '@/constants/flow';
+import MyTooltip from '@/components/MyTooltip';
interface Props extends BoxProps {
handleKey: string;
@@ -25,16 +26,18 @@ const SourceHandle = ({ handleKey, valueType, ...props }: Props) => {
transform={'translate(50%,-50%)'}
{...props}
>
-
+
+
+
);
};
diff --git a/client/src/pages/app/detail/components/AdEdit/components/render/TargetHandle.tsx b/client/src/pages/app/detail/components/AdEdit/components/render/TargetHandle.tsx
index fca1dc485..d176b730d 100644
--- a/client/src/pages/app/detail/components/AdEdit/components/render/TargetHandle.tsx
+++ b/client/src/pages/app/detail/components/AdEdit/components/render/TargetHandle.tsx
@@ -2,6 +2,7 @@ import React, { useMemo } from 'react';
import { Box, BoxProps } from '@chakra-ui/react';
import { Handle, OnConnect, Position } from 'reactflow';
import { FlowValueTypeEnum, FlowValueTypeStyle } from '@/constants/flow';
+import MyTooltip from '@/components/MyTooltip';
interface Props extends BoxProps {
handleKey: string;
@@ -26,17 +27,19 @@ const TargetHandle = ({ handleKey, valueType, onConnect, ...props }: Props) => {
transform={'translate(50%,-50%)'}
{...props}
>
-
+
+
+
);
};
diff --git a/client/src/pages/app/detail/components/AdEdit/index.tsx b/client/src/pages/app/detail/components/AdEdit/index.tsx
index 3e09ef6a8..0707c7900 100644
--- a/client/src/pages/app/detail/components/AdEdit/index.tsx
+++ b/client/src/pages/app/detail/components/AdEdit/index.tsx
@@ -30,6 +30,8 @@ import { customAlphabet } from 'nanoid';
import { useRequest } from '@/hooks/useRequest';
import type { AppSchema } from '@/types/mongoSchema';
import { useUserStore } from '@/store/user';
+import { useToast } from '@/hooks/useToast';
+import { useTranslation } from 'next-i18next';
import dynamic from 'next/dynamic';
import MyIcon from '@/components/Icon';
@@ -90,6 +92,8 @@ type Props = { app: AppSchema; fullScreen: boolean; onFullScreen: (val: boolean)
const AppEdit = ({ app, fullScreen, onFullScreen }: Props) => {
const theme = useTheme();
+ const { toast } = useToast();
+ const { t } = useTranslation();
const reactFlowWrapper = useRef(null);
const ChatTestRef = useRef(null);
const { updateAppDetail } = useUserStore();
@@ -227,6 +231,26 @@ const AppEdit = ({ app, fullScreen, onFullScreen }: Props) => {
);
const onConnect = useCallback(
({ connect }: { connect: Connection }) => {
+ const sourceType = nodes
+ .find((node) => node.id === connect.source)
+ ?.data?.outputs.find((output) => output.key === connect.sourceHandle)?.valueType;
+ const targetType = nodes
+ .find((node) => node.id === connect.target)
+ ?.data?.inputs.find((input) => input.key === connect.targetHandle)?.valueType;
+
+ if (!sourceType || !targetType) {
+ return toast({
+ status: 'warning',
+ title: t('app.Connection is invalid')
+ });
+ }
+ if (sourceType !== targetType) {
+ return toast({
+ status: 'warning',
+ title: t('app.Connection type is different')
+ });
+ }
+
setEdges((state) =>
addEdge(
{
@@ -241,7 +265,7 @@ const AppEdit = ({ app, fullScreen, onFullScreen }: Props) => {
)
);
},
- [onDelConnect, setEdges]
+ [onDelConnect, setEdges, nodes]
);
const { mutate: onclickSave, isLoading } = useRequest({
diff --git a/client/src/service/utils/wxpay.ts b/client/src/service/utils/wxpay.ts
index 2ef703588..65ea7bf0f 100644
--- a/client/src/service/utils/wxpay.ts
+++ b/client/src/service/utils/wxpay.ts
@@ -1,15 +1,20 @@
// @ts-ignore
import Payment from 'wxpay-v3';
-export const getPayment = () =>
- new Payment({
- appid: process.env.WX_APPID,
- mchid: process.env.WX_MCHID,
- private_key: process.env.WX_PRIVATE_KEY?.replace(/\\n/g, '\n'),
- serial_no: process.env.WX_SERIAL_NO,
- apiv3_private_key: process.env.WX_V3_CODE,
- notify_url: process.env.WX_NOTIFY_URL
- });
+export const getPayment = () => {
+ try {
+ return new Payment({
+ appid: process.env.WX_APPID,
+ mchid: process.env.WX_MCHID,
+ private_key: process.env.WX_PRIVATE_KEY?.replace(/\\n/g, '\n'),
+ serial_no: process.env.WX_SERIAL_NO,
+ apiv3_private_key: process.env.WX_V3_CODE,
+ notify_url: process.env.WX_NOTIFY_URL
+ });
+ } catch (error) {
+ return Promise.reject(error);
+ }
+};
export const nativePay = async (amount: number, payId: string) => {
try {