feat: flow data type check

This commit is contained in:
archer
2023-07-28 09:00:10 +08:00
parent aebe789e9f
commit 36b234c4fd
9 changed files with 73 additions and 39 deletions

View File

@@ -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": {

View File

@@ -7,6 +7,8 @@
"App Detail": "应用详情",
"Confirm Del App Tip": "确认删除该应用及其所有聊天记录?",
"Confirm Save App Tip": "保存后将会覆盖高级编排配置,请确保该应用未使用高级编排功能。",
"Connection is invalid": "连接无效",
"Connection type is different": "连接的类型不一致",
"My Apps": "我的应用"
},
"chat": {

View File

@@ -1,5 +0,0 @@
import { CSSProperties } from 'react';
export const nodeDefaultStyle: CSSProperties = {
border: '1px solid #DEE0E2'
};

View File

@@ -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'
}

View File

@@ -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',

View File

@@ -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}
>
<Handle
style={{
width: '12px',
height: '12px',
...valueStyle
}}
type="source"
id={handleKey}
position={Position.Right}
/>
<MyTooltip label={`${valueType}类型`}>
<Handle
style={{
width: '12px',
height: '12px',
...valueStyle
}}
type="source"
id={handleKey}
position={Position.Right}
/>
</MyTooltip>
</Box>
);
};

View File

@@ -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}
>
<Handle
style={{
width: '12px',
height: '12px',
...valueStyle
}}
type="target"
id={handleKey}
datatype={valueStyle}
position={Position.Left}
/>
<MyTooltip label={`${valueType}类型`}>
<Handle
style={{
width: '12px',
height: '12px',
...valueStyle
}}
type="target"
id={handleKey}
datatype={valueStyle}
position={Position.Left}
/>
</MyTooltip>
</Box>
);
};

View File

@@ -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<HTMLDivElement>(null);
const ChatTestRef = useRef<ChatTestComponentRef>(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({

View File

@@ -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 {