Commit 36f5648c by Archer Committed by GitHub

perf: v4.4.6-1 (#364)

parent ab57bfcc
name: Build fastgpt images and copy image to docker hub name: Build FastGPT images and copy image to docker hub
on: on:
workflow_dispatch: workflow_dispatch:
push: push:
paths: paths:
- 'projects/app/**' - 'projects/app/**'
- 'packages/**'
branches: branches:
- 'main' - 'main'
tags: tags:
...@@ -54,7 +55,7 @@ jobs: ...@@ -54,7 +55,7 @@ jobs:
--platform linux/amd64,linux/arm64 \ --platform linux/amd64,linux/arm64 \
--label "org.opencontainers.image.source= https://github.com/ ${{ github.repository_owner }}/FastGPT" \ --label "org.opencontainers.image.source= https://github.com/ ${{ github.repository_owner }}/FastGPT" \
--label "org.opencontainers.image.description=fastgpt image" \ --label "org.opencontainers.image.description=fastgpt image" \
--label "org.opencontainers.image.licenses=MIT" \ --label "org.opencontainers.image.licenses=Apache" \
--push \ --push \
--cache-from=type=local,src=/tmp/.buildx-cache \ --cache-from=type=local,src=/tmp/.buildx-cache \
--cache-to=type=local,dest=/tmp/.buildx-cache \ --cache-to=type=local,dest=/tmp/.buildx-cache \
......
name: Preview FastGPT images
on:
pull_request_target:
paths:
- 'projects/app/**'
- 'packages/**'
branches:
- 'main'
workflow_dispatch:
jobs:
build-fastgpt-images:
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GH_PAT }}
- name: Set DOCKER_REPO_TAGGED based on branch or tag
run: |
echo "DOCKER_REPO_TAGGED=ghcr.io/${{ github.repository_owner }}/fastgpt-pr:${{ github.event.pull_request.number }}" >> $GITHUB_ENV
- name: Build and publish image for PR
env:
DOCKER_REPO_TAGGED: ${{ env.DOCKER_REPO_TAGGED }}
run: |
docker buildx build \
--build-arg name=app \
--label "org.opencontainers.image.source= https://github.com/ ${{ github.repository_owner }}/FastGPT" \
--label "org.opencontainers.image.description=fastgpt-pr image" \
--label "org.opencontainers.image.licenses=Apache" \
--cache-from=type=local,src=/tmp/.buildx-cache \
--cache-to=type=local,dest=/tmp/.buildx-cache \
-t ${DOCKER_REPO_TAGGED} \
-f Dockerfile \
.
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
"editor.formatOnSave": true, "editor.formatOnSave": true,
"editor.mouseWheelZoom": true, "editor.mouseWheelZoom": true,
"typescript.tsdk": "node_modules/typescript/lib", "typescript.tsdk": "node_modules/typescript/lib",
"prettier.prettierPath": "./node_modules/prettier", "editor.defaultFormatter": "esbenp.prettier-vscode",
"i18n-ally.localesPaths": [ "i18n-ally.localesPaths": [
"projects/app/public/locales" "projects/app/public/locales"
], ],
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
"i18next": "^23.2.11", "i18next": "^23.2.11",
"lint-staged": "^13.2.1", "lint-staged": "^13.2.1",
"next-i18next": "^14.0.0", "next-i18next": "^14.0.0",
"prettier": "^2.8.7", "prettier": "^3.0.3",
"react-i18next": "^13.0.2" "react-i18next": "^13.0.2"
}, },
"lint-staged": { "lint-staged": {
......
...@@ -105,6 +105,7 @@ ...@@ -105,6 +105,7 @@
}, },
"common": { "common": {
"Add": "Add", "Add": "Add",
"Close": "Clow",
"Collect": "Collect", "Collect": "Collect",
"Copy": "Copy", "Copy": "Copy",
"Copy Successful": "Copy Successful", "Copy Successful": "Copy Successful",
......
...@@ -105,6 +105,7 @@ ...@@ -105,6 +105,7 @@
}, },
"common": { "common": {
"Add": "添加", "Add": "添加",
"Close": "关闭",
"Collect": "收藏", "Collect": "收藏",
"Copy": "复制", "Copy": "复制",
"Copy Successful": "复制成功", "Copy Successful": "复制成功",
......
...@@ -1171,9 +1171,8 @@ export const useChatBox = () => { ...@@ -1171,9 +1171,8 @@ export const useChatBox = () => {
const historyDom = document.getElementById('history'); const historyDom = document.getElementById('history');
if (!historyDom) return; if (!historyDom) return;
const dom = Array.from(historyDom.children).map((child, i) => { const dom = Array.from(historyDom.children).map((child, i) => {
const avatar = `<img src="${ const avatar = `<img src="${child.querySelector<HTMLImageElement>('.avatar')
child.querySelector<HTMLImageElement>('.avatar')?.src ?.src}" alt="" />`;
}" alt="" />`;
const chatContent = child.querySelector<HTMLDivElement>('.markdown'); const chatContent = child.querySelector<HTMLDivElement>('.markdown');
......
...@@ -19,8 +19,8 @@ function MyLink(e: any) { ...@@ -19,8 +19,8 @@ function MyLink(e: any) {
{text} {text}
</Link> </Link>
) : ( ) : (
<Box as={'ul'}> <Box as={'ul'} mt={'0 !important'}>
<Box as={'li'}> <Box as={'li'} mb={1}>
<Box <Box
as={'span'} as={'span'}
color={'blue.600'} color={'blue.600'}
...@@ -47,6 +47,7 @@ const Guide = ({ text }: { text: string }) => { ...@@ -47,6 +47,7 @@ const Guide = ({ text }: { text: string }) => {
rehypePlugins={[RehypeKatex]} rehypePlugins={[RehypeKatex]}
components={{ components={{
a: MyLink, a: MyLink,
p: 'div',
img: Image img: Image
}} }}
> >
......
...@@ -8,7 +8,7 @@ import { ...@@ -8,7 +8,7 @@ import {
FlowValueTypeEnum FlowValueTypeEnum
} from './index'; } from './index';
import type { AppItemType } from '@/types/app'; import type { AppItemType } from '@/types/app';
import type { FlowModuleTemplateType } from '@/types/flow'; import type { FlowModuleTemplateType } from '@/types/core/app/flow';
import { chatModelList } from '@/store/static'; import { chatModelList } from '@/store/static';
import { import {
Input_Template_History, Input_Template_History,
...@@ -331,6 +331,7 @@ export const ClassifyQuestionModule: FlowModuleTemplateType = { ...@@ -331,6 +331,7 @@ export const ClassifyQuestionModule: FlowModuleTemplateType = {
'根据用户的历史记录和当前问题判断该次提问的类型。可以添加多组问题类型,下面是一个模板例子:\n类型1: 打招呼\n类型2: 关于 laf 通用问题\n类型3: 关于 laf 代码问题\n类型4: 其他问题', '根据用户的历史记录和当前问题判断该次提问的类型。可以添加多组问题类型,下面是一个模板例子:\n类型1: 打招呼\n类型2: 关于 laf 通用问题\n类型3: 关于 laf 代码问题\n类型4: 其他问题',
showStatus: true, showStatus: true,
inputs: [ inputs: [
Input_Template_TFSwitch,
{ {
key: 'systemPrompt', key: 'systemPrompt',
type: FlowInputItemTypeEnum.textarea, type: FlowInputItemTypeEnum.textarea,
......
import { FlowInputItemType } from '@/types/flow'; import type { FlowInputItemType } from '@/types/core/app/flow';
import { SystemInputEnum } from '../app'; import { SystemInputEnum } from '../app';
import { FlowInputItemTypeEnum, FlowValueTypeEnum } from './index'; import { FlowInputItemTypeEnum, FlowValueTypeEnum } from './index';
......
...@@ -94,9 +94,7 @@ function App({ Component, pageProps }: AppProps) { ...@@ -94,9 +94,7 @@ function App({ Component, pageProps }: AppProps) {
/> />
<link rel="icon" href="/favicon.ico" /> <link rel="icon" href="/favicon.ico" />
</Head> </Head>
{scripts?.map((item, i) => ( {scripts?.map((item, i) => <Script key={i} strategy="lazyOnload" {...item}></Script>)}
<Script key={i} strategy="lazyOnload" {...item}></Script>
))}
<QueryClientProvider client={queryClient}> <QueryClientProvider client={queryClient}>
<ChakraProvider theme={theme}> <ChakraProvider theme={theme}>
......
...@@ -32,7 +32,7 @@ import { getSystemTime } from '@/utils/user'; ...@@ -32,7 +32,7 @@ import { getSystemTime } from '@/utils/user';
import { authOutLinkChat } from '@/service/support/outLink/auth'; import { authOutLinkChat } from '@/service/support/outLink/auth';
import requestIp from 'request-ip'; import requestIp from 'request-ip';
import { replaceVariable } from '@/utils/common/tools/text'; import { replaceVariable } from '@/utils/common/tools/text';
import { ModuleDispatchProps } from '@/types/core/modules'; import type { ModuleDispatchProps } from '@/types/core/chat/type';
import { selectShareResponse } from '@/utils/service/core/chat'; import { selectShareResponse } from '@/utils/service/core/chat';
import { pushResult2Remote, updateOutLinkUsage } from '@/service/support/outLink'; import { pushResult2Remote, updateOutLinkUsage } from '@/service/support/outLink';
import { updateApiKeyUsage } from '@/service/support/openapi'; import { updateApiKeyUsage } from '@/service/support/openapi';
......
import React, { useState } from 'react'; import React, { useState } from 'react';
import { Textarea, Button, ModalBody, ModalFooter } from '@chakra-ui/react'; import { Textarea, Button, ModalBody, ModalFooter } from '@chakra-ui/react';
import MyModal from '@/components/MyModal'; import MyModal from '@/components/MyModal';
import { AppModuleItemType } from '@/types/app';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { useToast } from '@/hooks/useToast'; import { useToast } from '@/hooks/useToast';
import { useFlowStore } from './Provider';
const ImportSettings = ({ const ImportSettings = ({ onClose }: { onClose: () => void }) => {
onClose,
onSuccess
}: {
onClose: () => void;
onSuccess: (modules: AppModuleItemType[]) => void;
}) => {
const { t } = useTranslation(); const { t } = useTranslation();
const { toast } = useToast(); const { toast } = useToast();
const [value, setValue] = useState(''); const [value, setValue] = useState('');
const { setNodes, setEdges, initData } = useFlowStore();
return ( return (
<MyModal isOpen w={'600px'} onClose={onClose} title={t('app.Import Config')}> <MyModal isOpen w={'600px'} onClose={onClose} title={t('app.Import Config')}>
...@@ -35,7 +30,11 @@ const ImportSettings = ({ ...@@ -35,7 +30,11 @@ const ImportSettings = ({
} }
try { try {
const data = JSON.parse(value); const data = JSON.parse(value);
onSuccess(data); setEdges([]);
setNodes([]);
setTimeout(() => {
initData(data);
}, 10);
onClose(); onClose();
} catch (error) { } catch (error) {
toast({ toast({
...@@ -51,4 +50,4 @@ const ImportSettings = ({ ...@@ -51,4 +50,4 @@ const ImportSettings = ({
); );
}; };
export default ImportSettings; export default React.memo(ImportSettings);
import React from 'react'; import React from 'react';
import { NodeProps } from 'reactflow'; import { NodeProps } from 'reactflow';
import NodeCard from '../modules/NodeCard'; import NodeCard from '../modules/NodeCard';
import { FlowModuleItemType } from '@/types/flow'; import { FlowModuleItemType } from '@/types/core/app/flow';
import Container from '../modules/Container'; import Container from '../modules/Container';
import RenderInput from '../render/RenderInput'; import RenderInput from '../render/RenderInput';
import RenderOutput from '../render/RenderOutput'; import RenderOutput from '../render/RenderOutput';
const NodeAnswer = ({ data }: NodeProps<FlowModuleItemType>) => { const NodeAnswer = ({ data }: NodeProps<FlowModuleItemType>) => {
const { moduleId, inputs, outputs, onChangeNode } = data; const { moduleId, inputs, outputs } = data;
return ( return (
<NodeCard minW={'400px'} {...data}> <NodeCard minW={'400px'} {...data}>
<Container borderTop={'2px solid'} borderTopColor={'myGray.200'}> <Container borderTop={'2px solid'} borderTopColor={'myGray.200'}>
<RenderInput moduleId={moduleId} onChangeNode={onChangeNode} flowInputList={inputs} /> <RenderInput moduleId={moduleId} flowInputList={inputs} />
<RenderOutput onChangeNode={onChangeNode} moduleId={moduleId} flowOutputList={outputs} /> <RenderOutput moduleId={moduleId} flowOutputList={outputs} />
</Container> </Container>
</NodeCard> </NodeCard>
); );
......
import React from 'react'; import React from 'react';
import { NodeProps } from 'reactflow'; import { NodeProps } from 'reactflow';
import { Box, Input, Button, Flex } from '@chakra-ui/react'; import { Box, Input, Button, Flex, Textarea } from '@chakra-ui/react';
import NodeCard from '../modules/NodeCard'; import NodeCard from '../modules/NodeCard';
import { FlowModuleItemType } from '@/types/flow'; import { FlowModuleItemType } from '@/types/core/app/flow';
import Divider from '../modules/Divider'; import Divider from '../modules/Divider';
import Container from '../modules/Container'; import Container from '../modules/Container';
import RenderInput from '../render/RenderInput'; import RenderInput from '../render/RenderInput';
...@@ -11,17 +11,22 @@ import { customAlphabet } from 'nanoid'; ...@@ -11,17 +11,22 @@ import { customAlphabet } from 'nanoid';
const nanoid = customAlphabet('abcdefghijklmnopqrstuvwxyz1234567890', 4); const nanoid = customAlphabet('abcdefghijklmnopqrstuvwxyz1234567890', 4);
import MyIcon from '@/components/Icon'; import MyIcon from '@/components/Icon';
import { FlowOutputItemTypeEnum, FlowValueTypeEnum, SpecialInputKeyEnum } from '@/constants/flow'; import { FlowOutputItemTypeEnum, FlowValueTypeEnum, SpecialInputKeyEnum } from '@/constants/flow';
import { useTranslation } from 'react-i18next';
import SourceHandle from '../render/SourceHandle'; import SourceHandle from '../render/SourceHandle';
import MyTooltip from '@/components/MyTooltip';
import { useFlowStore } from '../Provider';
const NodeCQNode = ({ data }: NodeProps<FlowModuleItemType>) => { const NodeCQNode = ({ data }: NodeProps<FlowModuleItemType>) => {
const { moduleId, inputs, outputs, onChangeNode } = data; const { t } = useTranslation();
const { moduleId, inputs, outputs } = data;
const { onChangeNode } = useFlowStore();
return ( return (
<NodeCard minW={'400px'} {...data}> <NodeCard minW={'400px'} {...data}>
<Divider text="Input" /> <Divider text="Input" />
<Container> <Container>
<RenderInput <RenderInput
moduleId={moduleId} moduleId={moduleId}
onChangeNode={onChangeNode}
flowInputList={inputs} flowInputList={inputs}
CustomComponent={{ CustomComponent={{
[SpecialInputKeyEnum.agents]: ({ [SpecialInputKeyEnum.agents]: ({
...@@ -34,17 +39,22 @@ const NodeCQNode = ({ data }: NodeProps<FlowModuleItemType>) => { ...@@ -34,17 +39,22 @@ const NodeCQNode = ({ data }: NodeProps<FlowModuleItemType>) => {
}) => ( }) => (
<Box> <Box>
{agents.map((item, i) => ( {agents.map((item, i) => (
<Flex key={item.key} mb={4} alignItems={'center'}> <Box key={item.key} mb={4}>
<Flex alignItems={'center'}>
<MyTooltip label={t('common.Delete')}>
<MyIcon <MyIcon
mt={1}
mr={2} mr={2}
name={'minus'} name={'minus'}
w={'14px'} w={'14px'}
cursor={'pointer'} cursor={'pointer'}
color={'myGray.600'} color={'myGray.600'}
_hover={{ color: 'myGray.900' }} _hover={{ color: 'red.600' }}
onClick={() => { onClick={() => {
const newInputValue = agents.filter((input) => input.key !== item.key); const newInputValue = agents.filter((input) => input.key !== item.key);
const newOutputVal = outputs.filter((output) => output.key !== item.key); const newOutputVal = outputs.filter(
(output) => output.key !== item.key
);
onChangeNode({ onChangeNode({
moduleId, moduleId,
...@@ -64,10 +74,12 @@ const NodeCQNode = ({ data }: NodeProps<FlowModuleItemType>) => { ...@@ -64,10 +74,12 @@ const NodeCQNode = ({ data }: NodeProps<FlowModuleItemType>) => {
}); });
}} }}
/> />
<Box flex={1}> </MyTooltip>
<Box flex={1}>类型{i + 1}</Box> <Box flex={1}>分类{i + 1}</Box>
</Flex>
<Box position={'relative'}> <Box position={'relative'}>
<Input <Textarea
rows={2}
mt={1} mt={1}
defaultValue={item.value} defaultValue={item.value}
onChange={(e) => { onChange={(e) => {
...@@ -94,7 +106,6 @@ const NodeCQNode = ({ data }: NodeProps<FlowModuleItemType>) => { ...@@ -94,7 +106,6 @@ const NodeCQNode = ({ data }: NodeProps<FlowModuleItemType>) => {
<SourceHandle handleKey={item.key} valueType={FlowValueTypeEnum.boolean} /> <SourceHandle handleKey={item.key} valueType={FlowValueTypeEnum.boolean} />
</Box> </Box>
</Box> </Box>
</Flex>
))} ))}
<Button <Button
onClick={() => { onClick={() => {
......
import React, { useMemo } from 'react'; import React, { useMemo } from 'react';
import { NodeProps } from 'reactflow'; import { NodeProps } from 'reactflow';
import NodeCard from '../modules/NodeCard'; import NodeCard from '../modules/NodeCard';
import { FlowModuleItemType } from '@/types/flow'; import { FlowModuleItemType } from '@/types/core/app/flow';
import Divider from '../modules/Divider'; import Divider from '../modules/Divider';
import Container from '../modules/Container'; import Container from '../modules/Container';
import RenderInput from '../render/RenderInput'; import RenderInput from '../render/RenderInput';
...@@ -9,16 +9,18 @@ import RenderOutput from '../render/RenderOutput'; ...@@ -9,16 +9,18 @@ import RenderOutput from '../render/RenderOutput';
import MySelect from '@/components/Select'; import MySelect from '@/components/Select';
import { chatModelList } from '@/store/static'; import { chatModelList } from '@/store/static';
import MySlider from '@/components/Slider'; import MySlider from '@/components/Slider';
import { Box, Button, Flex, useDisclosure } from '@chakra-ui/react'; import { Box, Button, useDisclosure } from '@chakra-ui/react';
import { formatPrice } from '@fastgpt/common/bill/index'; import { formatPrice } from '@fastgpt/common/bill/index';
import MyIcon from '@/components/Icon'; import MyIcon from '@/components/Icon';
import dynamic from 'next/dynamic'; import dynamic from 'next/dynamic';
import { AIChatProps } from '@/types/core/aiChat'; import { AIChatProps } from '@/types/core/aiChat';
import { useFlowStore } from '../Provider';
const AIChatSettingsModal = dynamic(() => import('../../../AIChatSettingsModal')); const AIChatSettingsModal = dynamic(() => import('../../../AIChatSettingsModal'));
const NodeChat = ({ data }: NodeProps<FlowModuleItemType>) => { const NodeChat = ({ data }: NodeProps<FlowModuleItemType>) => {
const { moduleId, inputs, outputs, onChangeNode } = data; const { moduleId, inputs, outputs } = data;
const { onChangeNode } = useFlowStore();
const chatModulesData = useMemo(() => { const chatModulesData = useMemo(() => {
const obj: Record<string, any> = {}; const obj: Record<string, any> = {};
...@@ -40,7 +42,6 @@ const NodeChat = ({ data }: NodeProps<FlowModuleItemType>) => { ...@@ -40,7 +42,6 @@ const NodeChat = ({ data }: NodeProps<FlowModuleItemType>) => {
<Container> <Container>
<RenderInput <RenderInput
moduleId={moduleId} moduleId={moduleId}
onChangeNode={onChangeNode}
flowInputList={inputs} flowInputList={inputs}
CustomComponent={{ CustomComponent={{
model: (inputItem) => { model: (inputItem) => {
...@@ -140,7 +141,7 @@ const NodeChat = ({ data }: NodeProps<FlowModuleItemType>) => { ...@@ -140,7 +141,7 @@ const NodeChat = ({ data }: NodeProps<FlowModuleItemType>) => {
</Container> </Container>
<Divider text="Output" /> <Divider text="Output" />
<Container> <Container>
<RenderOutput onChangeNode={onChangeNode} moduleId={moduleId} flowOutputList={outputs} /> <RenderOutput moduleId={moduleId} flowOutputList={outputs} />
</Container> </Container>
{isOpenAIChatSetting && ( {isOpenAIChatSetting && (
......
import React from 'react'; import React from 'react';
import { NodeProps } from 'reactflow'; import { NodeProps } from 'reactflow';
import NodeCard from '../modules/NodeCard'; import NodeCard from '../modules/NodeCard';
import { FlowModuleItemType } from '@/types/flow'; import { FlowModuleItemType } from '@/types/core/app/flow';
const NodeAnswer = ({ data }: NodeProps<FlowModuleItemType>) => { const NodeAnswer = ({ data }: NodeProps<FlowModuleItemType>) => {
return <NodeCard {...data}></NodeCard>; return <NodeCard {...data}></NodeCard>;
......
import React, { useState } from 'react'; import React, { useState } from 'react';
import { Box, Button, Table, Thead, Tbody, Tr, Th, Td, TableContainer } from '@chakra-ui/react'; import { Box, Button, Table, Thead, Tbody, Tr, Th, Td, TableContainer } from '@chakra-ui/react';
import { NodeProps } from 'reactflow'; import { NodeProps } from 'reactflow';
import { FlowModuleItemType } from '@/types/flow'; import { FlowModuleItemType } from '@/types/core/app/flow';
import { useTranslation } from 'next-i18next'; import { useTranslation } from 'next-i18next';
import NodeCard from '../modules/NodeCard'; import NodeCard from '../modules/NodeCard';
import Container from '../modules/Container'; import Container from '../modules/Container';
...@@ -14,11 +14,13 @@ import MyIcon from '@/components/Icon'; ...@@ -14,11 +14,13 @@ import MyIcon from '@/components/Icon';
import ExtractFieldModal from '../modules/ExtractFieldModal'; import ExtractFieldModal from '../modules/ExtractFieldModal';
import { ContextExtractEnum } from '@/constants/flow/flowField'; import { ContextExtractEnum } from '@/constants/flow/flowField';
import { FlowOutputItemTypeEnum, FlowValueTypeEnum } from '@/constants/flow'; import { FlowOutputItemTypeEnum, FlowValueTypeEnum } from '@/constants/flow';
import { useFlowStore } from '../Provider';
const NodeExtract = ({ data }: NodeProps<FlowModuleItemType>) => { const NodeExtract = ({ data }: NodeProps<FlowModuleItemType>) => {
const { inputs, outputs, moduleId, onChangeNode, onDelEdge } = data; const { inputs, outputs, moduleId } = data;
const { t } = useTranslation(); const { t } = useTranslation();
const [editExtractFiled, setEditExtractField] = useState<ContextExtractAgentItemType>(); const [editExtractFiled, setEditExtractField] = useState<ContextExtractAgentItemType>();
const { onChangeNode, onDelEdge } = useFlowStore();
return ( return (
<NodeCard minW={'400px'} {...data}> <NodeCard minW={'400px'} {...data}>
...@@ -26,7 +28,6 @@ const NodeExtract = ({ data }: NodeProps<FlowModuleItemType>) => { ...@@ -26,7 +28,6 @@ const NodeExtract = ({ data }: NodeProps<FlowModuleItemType>) => {
<Container> <Container>
<RenderInput <RenderInput
moduleId={moduleId} moduleId={moduleId}
onChangeNode={onChangeNode}
flowInputList={inputs} flowInputList={inputs}
CustomComponent={{ CustomComponent={{
[ContextExtractEnum.extractKeys]: ({ [ContextExtractEnum.extractKeys]: ({
...@@ -125,7 +126,7 @@ const NodeExtract = ({ data }: NodeProps<FlowModuleItemType>) => { ...@@ -125,7 +126,7 @@ const NodeExtract = ({ data }: NodeProps<FlowModuleItemType>) => {
</Container> </Container>
<Divider text="Output" /> <Divider text="Output" />
<Container> <Container>
<RenderOutput onChangeNode={onChangeNode} moduleId={moduleId} flowOutputList={outputs} /> <RenderOutput moduleId={moduleId} flowOutputList={outputs} />
</Container> </Container>
{!!editExtractFiled && ( {!!editExtractFiled && (
......
import React from 'react'; import React from 'react';
import { NodeProps } from 'reactflow'; import { NodeProps } from 'reactflow';
import NodeCard from '../modules/NodeCard'; import NodeCard from '../modules/NodeCard';
import { FlowModuleItemType } from '@/types/flow'; import { FlowModuleItemType } from '@/types/core/app/flow';
import Divider from '../modules/Divider'; import Divider from '../modules/Divider';
import Container from '../modules/Container'; import Container from '../modules/Container';
import RenderInput from '../render/RenderInput'; import RenderInput from '../render/RenderInput';
import RenderOutput from '../render/RenderOutput'; import RenderOutput from '../render/RenderOutput';
const NodeHistory = ({ data }: NodeProps<FlowModuleItemType>) => { const NodeHistory = ({ data }: NodeProps<FlowModuleItemType>) => {
const { inputs, outputs, moduleId, onChangeNode } = data; const { inputs, outputs, moduleId } = data;
return ( return (
<NodeCard minW={'300px'} {...data}> <NodeCard minW={'300px'} {...data}>
<Divider text="Input" /> <Divider text="Input" />
<Container> <Container>
<RenderInput moduleId={moduleId} onChangeNode={onChangeNode} flowInputList={inputs} /> <RenderInput moduleId={moduleId} flowInputList={inputs} />
</Container> </Container>
<Divider text="Output" /> <Divider text="Output" />
<Container> <Container>
<RenderOutput onChangeNode={onChangeNode} moduleId={moduleId} flowOutputList={outputs} /> <RenderOutput moduleId={moduleId} flowOutputList={outputs} />
</Container> </Container>
</NodeCard> </NodeCard>
); );
......
import React from 'react'; import React from 'react';
import { NodeProps } from 'reactflow'; import { NodeProps } from 'reactflow';
import NodeCard from '../modules/NodeCard'; import NodeCard from '../modules/NodeCard';
import { FlowModuleItemType } from '@/types/flow'; import { FlowModuleItemType } from '@/types/core/app/flow';
import Divider from '../modules/Divider'; import Divider from '../modules/Divider';
import Container from '../modules/Container'; import Container from '../modules/Container';
import RenderInput from '../render/RenderInput'; import RenderInput from '../render/RenderInput';
...@@ -12,13 +12,16 @@ import RenderOutput from '../render/RenderOutput'; ...@@ -12,13 +12,16 @@ import RenderOutput from '../render/RenderOutput';
import { FlowInputItemTypeEnum, FlowOutputItemTypeEnum, FlowValueTypeEnum } from '@/constants/flow'; import { FlowInputItemTypeEnum, FlowOutputItemTypeEnum, FlowValueTypeEnum } from '@/constants/flow';
import { customAlphabet } from 'nanoid'; import { customAlphabet } from 'nanoid';
const nanoid = customAlphabet('abcdefghijklmnopqrstuvwxyz1234567890', 6); const nanoid = customAlphabet('abcdefghijklmnopqrstuvwxyz1234567890', 6);
import { useFlowStore } from '../Provider';
const NodeHttp = ({ data }: NodeProps<FlowModuleItemType>) => { const NodeHttp = ({ data }: NodeProps<FlowModuleItemType>) => {
const { moduleId, inputs, outputs, onChangeNode } = data; const { moduleId, inputs, outputs } = data;
const { onChangeNode } = useFlowStore();
return ( return (
<NodeCard minW={'350px'} {...data}> <NodeCard minW={'350px'} {...data}>
<Container borderTop={'2px solid'} borderTopColor={'myGray.200'}> <Container borderTop={'2px solid'} borderTopColor={'myGray.200'}>
<RenderInput moduleId={moduleId} onChangeNode={onChangeNode} flowInputList={inputs} /> <RenderInput moduleId={moduleId} flowInputList={inputs} />
<Button <Button
variant={'base'} variant={'base'}
mt={5} mt={5}
...@@ -44,7 +47,7 @@ const NodeHttp = ({ data }: NodeProps<FlowModuleItemType>) => { ...@@ -44,7 +47,7 @@ const NodeHttp = ({ data }: NodeProps<FlowModuleItemType>) => {
</Container> </Container>
<Divider text="Output" /> <Divider text="Output" />
<Container> <Container>
<RenderOutput onChangeNode={onChangeNode} moduleId={moduleId} flowOutputList={outputs} /> <RenderOutput moduleId={moduleId} flowOutputList={outputs} />
<Box textAlign={'right'} mt={5}> <Box textAlign={'right'} mt={5}>
<Button <Button
variant={'base'} variant={'base'}
......
import React, { useMemo } from 'react'; import React, { useMemo } from 'react';
import { NodeProps } from 'reactflow'; import { NodeProps } from 'reactflow';
import { FlowModuleItemType } from '@/types/flow'; import { FlowModuleItemType } from '@/types/core/app/flow';
import { Flex, Box, Button, useTheme, useDisclosure, Grid } from '@chakra-ui/react'; import { Flex, Box, Button, useTheme, useDisclosure, Grid } from '@chakra-ui/react';
import { useDatasetStore } from '@/store/dataset'; import { useDatasetStore } from '@/store/dataset';
import { useQuery } from '@tanstack/react-query'; import { useQuery } from '@tanstack/react-query';
...@@ -12,6 +12,7 @@ import RenderOutput from '../render/RenderOutput'; ...@@ -12,6 +12,7 @@ import RenderOutput from '../render/RenderOutput';
import { DatasetSelectModal } from '../../../DatasetSelectModal'; import { DatasetSelectModal } from '../../../DatasetSelectModal';
import type { SelectedDatasetType } from '@/types/core/dataset'; import type { SelectedDatasetType } from '@/types/core/dataset';
import Avatar from '@/components/Avatar'; import Avatar from '@/components/Avatar';
import { useFlowStore } from '../Provider';
const KBSelect = ({ const KBSelect = ({
activeKbs = [], activeKbs = [],
...@@ -68,14 +69,15 @@ const KBSelect = ({ ...@@ -68,14 +69,15 @@ const KBSelect = ({
}; };
const NodeKbSearch = ({ data }: NodeProps<FlowModuleItemType>) => { const NodeKbSearch = ({ data }: NodeProps<FlowModuleItemType>) => {
const { moduleId, inputs, outputs, onChangeNode } = data; const { moduleId, inputs, outputs } = data;
const { onChangeNode } = useFlowStore();
return ( return (
<NodeCard minW={'400px'} {...data}> <NodeCard minW={'400px'} {...data}>
<Divider text="Input" /> <Divider text="Input" />
<Container> <Container>
<RenderInput <RenderInput
moduleId={moduleId} moduleId={moduleId}
onChangeNode={onChangeNode}
flowInputList={inputs} flowInputList={inputs}
CustomComponent={{ CustomComponent={{
kbList: ({ key, value, ...props }) => ( kbList: ({ key, value, ...props }) => (
...@@ -100,7 +102,7 @@ const NodeKbSearch = ({ data }: NodeProps<FlowModuleItemType>) => { ...@@ -100,7 +102,7 @@ const NodeKbSearch = ({ data }: NodeProps<FlowModuleItemType>) => {
</Container> </Container>
<Divider text="Output" /> <Divider text="Output" />
<Container> <Container>
<RenderOutput onChangeNode={onChangeNode} moduleId={moduleId} flowOutputList={outputs} /> <RenderOutput moduleId={moduleId} flowOutputList={outputs} />
</Container> </Container>
</NodeCard> </NodeCard>
); );
......
...@@ -2,7 +2,7 @@ import React from 'react'; ...@@ -2,7 +2,7 @@ import React from 'react';
import { NodeProps } from 'reactflow'; import { NodeProps } from 'reactflow';
import { Box } from '@chakra-ui/react'; import { Box } from '@chakra-ui/react';
import NodeCard from '../modules/NodeCard'; import NodeCard from '../modules/NodeCard';
import { FlowModuleItemType } from '@/types/flow'; import { FlowModuleItemType } from '@/types/core/app/flow';
import Container from '../modules/Container'; import Container from '../modules/Container';
import { SystemInputEnum } from '@/constants/app'; import { SystemInputEnum } from '@/constants/app';
import { FlowValueTypeEnum } from '@/constants/flow'; import { FlowValueTypeEnum } from '@/constants/flow';
......
...@@ -3,7 +3,7 @@ import { Handle, Position, NodeProps } from 'reactflow'; ...@@ -3,7 +3,7 @@ import { Handle, Position, NodeProps } from 'reactflow';
import { Flex, Box } from '@chakra-ui/react'; import { Flex, Box } from '@chakra-ui/react';
import NodeCard from '../modules/NodeCard'; import NodeCard from '../modules/NodeCard';
import { SystemInputEnum } from '@/constants/app'; import { SystemInputEnum } from '@/constants/app';
import { FlowModuleItemType } from '@/types/flow'; import { FlowModuleItemType } from '@/types/core/app/flow';
import Divider from '../modules/Divider'; import Divider from '../modules/Divider';
import Container from '../modules/Container'; import Container from '../modules/Container';
import Label from '../modules/Label'; import Label from '../modules/Label';
......
...@@ -15,9 +15,10 @@ import { ...@@ -15,9 +15,10 @@ import {
Switch Switch
} from '@chakra-ui/react'; } from '@chakra-ui/react';
import { QuestionOutlineIcon } from '@chakra-ui/icons'; import { QuestionOutlineIcon } from '@chakra-ui/icons';
import { FlowModuleItemType } from '@/types/flow'; import { FlowModuleItemType } from '@/types/core/app/flow';
import { SystemInputEnum } from '@/constants/app'; import { SystemInputEnum } from '@/constants/app';
import { welcomeTextTip, variableTip, questionGuideTip } from '@/constants/flow/ModuleTemplate'; import { welcomeTextTip, variableTip, questionGuideTip } from '@/constants/flow/ModuleTemplate';
import { useFlowStore } from '../Provider';
import VariableEditModal, { addVariable } from '../../../VariableEditModal'; import VariableEditModal, { addVariable } from '../../../VariableEditModal';
import MyIcon from '@/components/Icon'; import MyIcon from '@/components/Icon';
...@@ -47,7 +48,8 @@ const NodeUserGuide = ({ data }: NodeProps<FlowModuleItemType>) => { ...@@ -47,7 +48,8 @@ const NodeUserGuide = ({ data }: NodeProps<FlowModuleItemType>) => {
export default React.memo(NodeUserGuide); export default React.memo(NodeUserGuide);
export function WelcomeText({ data }: { data: FlowModuleItemType }) { export function WelcomeText({ data }: { data: FlowModuleItemType }) {
const { inputs, moduleId, onChangeNode } = data; const { inputs, moduleId } = data;
const { onChangeNode } = useFlowStore();
const welcomeText = useMemo( const welcomeText = useMemo(
() => inputs.find((item) => item.key === SystemInputEnum.welcomeText), () => inputs.find((item) => item.key === SystemInputEnum.welcomeText),
...@@ -89,7 +91,9 @@ export function WelcomeText({ data }: { data: FlowModuleItemType }) { ...@@ -89,7 +91,9 @@ export function WelcomeText({ data }: { data: FlowModuleItemType }) {
} }
function ChatStartVariable({ data }: { data: FlowModuleItemType }) { function ChatStartVariable({ data }: { data: FlowModuleItemType }) {
const { inputs, moduleId, onChangeNode } = data; const { inputs, moduleId } = data;
const { onChangeNode } = useFlowStore();
const variables = useMemo( const variables = useMemo(
() => () =>
(inputs.find((item) => item.key === SystemInputEnum.variables) (inputs.find((item) => item.key === SystemInputEnum.variables)
...@@ -203,7 +207,9 @@ function ChatStartVariable({ data }: { data: FlowModuleItemType }) { ...@@ -203,7 +207,9 @@ function ChatStartVariable({ data }: { data: FlowModuleItemType }) {
} }
function QuestionGuide({ data }: { data: FlowModuleItemType }) { function QuestionGuide({ data }: { data: FlowModuleItemType }) {
const { inputs, moduleId, onChangeNode } = data; const { inputs, moduleId } = data;
const { onChangeNode } = useFlowStore();
const questionGuide = useMemo( const questionGuide = useMemo(
() => () =>
(inputs.find((item) => item.key === SystemInputEnum.questionGuide)?.value as boolean) || (inputs.find((item) => item.key === SystemInputEnum.questionGuide)?.value as boolean) ||
......
/* Abandon */
import React, { useCallback, useMemo, useState } from 'react'; import React, { useCallback, useMemo, useState } from 'react';
import { NodeProps } from 'reactflow'; import { NodeProps } from 'reactflow';
import { Box, Button, Table, Thead, Tbody, Tr, Th, Td, TableContainer } from '@chakra-ui/react'; import { Box, Button, Table, Thead, Tbody, Tr, Th, Td, TableContainer } from '@chakra-ui/react';
import { AddIcon } from '@chakra-ui/icons'; import { AddIcon } from '@chakra-ui/icons';
import NodeCard from '../modules/NodeCard'; import NodeCard from '../modules/NodeCard';
import { FlowModuleItemType } from '@/types/flow'; import { FlowModuleItemType } from '@/types/core/app/flow';
import Container from '../modules/Container'; import Container from '../modules/Container';
import { SystemInputEnum, VariableInputEnum } from '@/constants/app'; import { SystemInputEnum, VariableInputEnum } from '@/constants/app';
import type { VariableItemType } from '@/types/app'; import type { VariableItemType } from '@/types/app';
...@@ -11,6 +12,7 @@ import MyIcon from '@/components/Icon'; ...@@ -11,6 +12,7 @@ import MyIcon from '@/components/Icon';
import { customAlphabet } from 'nanoid'; import { customAlphabet } from 'nanoid';
const nanoid = customAlphabet('abcdefghijklmnopqrstuvwxyz1234567890', 6); const nanoid = customAlphabet('abcdefghijklmnopqrstuvwxyz1234567890', 6);
import VariableEditModal, { addVariable } from '../../../VariableEditModal'; import VariableEditModal, { addVariable } from '../../../VariableEditModal';
import { useFlowStore } from '../Provider';
export const defaultVariable: VariableItemType = { export const defaultVariable: VariableItemType = {
id: nanoid(), id: nanoid(),
...@@ -23,7 +25,9 @@ export const defaultVariable: VariableItemType = { ...@@ -23,7 +25,9 @@ export const defaultVariable: VariableItemType = {
}; };
const NodeUserGuide = ({ data }: NodeProps<FlowModuleItemType>) => { const NodeUserGuide = ({ data }: NodeProps<FlowModuleItemType>) => {
const { inputs, moduleId, onChangeNode } = data; const { inputs, moduleId } = data;
const { onChangeNode } = useFlowStore();
const variables = useMemo( const variables = useMemo(
() => () =>
(inputs.find((item) => item.key === SystemInputEnum.variables) (inputs.find((item) => item.key === SystemInputEnum.variables)
......
import React, { useMemo } from 'react'; import React, { useMemo } from 'react';
import { Box, Flex } from '@chakra-ui/react'; import { Box, Flex } from '@chakra-ui/react';
import { ModuleTemplates } from '@/constants/flow/ModuleTemplate'; import { ModuleTemplates } from '@/constants/flow/ModuleTemplate';
import { FlowModuleItemType, FlowModuleTemplateType } from '@/types/flow'; import { FlowModuleItemType, FlowModuleTemplateType } from '@/types/core/app/flow';
import type { Node, XYPosition } from 'reactflow'; import type { Node } from 'reactflow';
import { useGlobalStore } from '@/store/global'; import { useGlobalStore } from '@/store/global';
import Avatar from '@/components/Avatar'; import Avatar from '@/components/Avatar';
import { FlowModuleTypeEnum } from '@/constants/flow'; import { FlowModuleTypeEnum } from '@/constants/flow';
import { useFlowStore } from './Provider';
const ModuleTemplateList = ({ const ModuleTemplateList = ({
nodes, nodes,
isOpen, isOpen,
onAddNode,
onClose onClose
}: { }: {
nodes?: Node<FlowModuleItemType>[]; nodes?: Node<FlowModuleItemType>[];
isOpen: boolean; isOpen: boolean;
onAddNode: (e: { template: FlowModuleTemplateType; position: XYPosition }) => void;
onClose: () => void; onClose: () => void;
}) => { }) => {
const { onAddNode } = useFlowStore();
const { isPc } = useGlobalStore(); const { isPc } = useGlobalStore();
const filterTemplates = useMemo(() => { const filterTemplates = useMemo(() => {
...@@ -123,4 +123,4 @@ const ModuleTemplateList = ({ ...@@ -123,4 +123,4 @@ const ModuleTemplateList = ({
); );
}; };
export default ModuleTemplateList; export default React.memo(ModuleTemplateList);
...@@ -7,8 +7,7 @@ import { ...@@ -7,8 +7,7 @@ import {
ModalBody, ModalBody,
Flex, Flex,
Switch, Switch,
Input, Input
FormControl
} from '@chakra-ui/react'; } from '@chakra-ui/react';
import type { ContextExtractAgentItemType } from '@/types/app'; import type { ContextExtractAgentItemType } from '@/types/app';
import { useForm } from 'react-hook-form'; import { useForm } from 'react-hook-form';
......
...@@ -2,12 +2,13 @@ import React, { useMemo } from 'react'; ...@@ -2,12 +2,13 @@ import React, { useMemo } from 'react';
import { Box, Flex, useTheme, Menu, MenuButton, MenuList, MenuItem } from '@chakra-ui/react'; import { Box, Flex, useTheme, Menu, MenuButton, MenuList, MenuItem } from '@chakra-ui/react';
import MyIcon from '@/components/Icon'; import MyIcon from '@/components/Icon';
import Avatar from '@/components/Avatar'; import Avatar from '@/components/Avatar';
import type { FlowModuleItemType } from '@/types/flow'; import type { FlowModuleItemType } from '@/types/core/app/flow';
import MyTooltip from '@/components/MyTooltip'; import MyTooltip from '@/components/MyTooltip';
import { QuestionOutlineIcon } from '@chakra-ui/icons'; import { QuestionOutlineIcon } from '@chakra-ui/icons';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { useEditTitle } from '@/hooks/useEditTitle'; import { useEditTitle } from '@/hooks/useEditTitle';
import { useToast } from '@/hooks/useToast'; import { useToast } from '@/hooks/useToast';
import { useFlowStore } from '../Provider';
type Props = FlowModuleItemType & { type Props = FlowModuleItemType & {
children?: React.ReactNode | React.ReactNode[] | string; children?: React.ReactNode | React.ReactNode[] | string;
...@@ -21,11 +22,10 @@ const NodeCard = (props: Props) => { ...@@ -21,11 +22,10 @@ const NodeCard = (props: Props) => {
name = '未知模块', name = '未知模块',
description, description,
minW = '300px', minW = '300px',
onCopyNode,
onDelNode,
onChangeNode,
moduleId moduleId
} = props; } = props;
const { onCopyNode, onDelNode, onChangeNode } = useFlowStore();
const { t } = useTranslation(); const { t } = useTranslation();
const theme = useTheme(); const theme = useTheme();
const { toast } = useToast(); const { toast } = useToast();
...@@ -73,11 +73,11 @@ const NodeCard = (props: Props) => { ...@@ -73,11 +73,11 @@ const NodeCard = (props: Props) => {
{ {
icon: 'back', icon: 'back',
label: t('Cancel'), label: t('common.Close'),
onClick: () => {} onClick: () => {}
} }
], ],
[moduleId, onCopyNode, onDelNode, t] [moduleId, name, onChangeNode, onCopyNode, onDelNode, onOpenModal, t, toast]
); );
return ( return (
...@@ -92,6 +92,7 @@ const NodeCard = (props: Props) => { ...@@ -92,6 +92,7 @@ const NodeCard = (props: Props) => {
<QuestionOutlineIcon <QuestionOutlineIcon
display={['none', 'inline']} display={['none', 'inline']}
transform={'translateY(1px)'} transform={'translateY(1px)'}
mb={'1px'}
ml={1} ml={1}
/> />
</MyTooltip> </MyTooltip>
......
...@@ -19,7 +19,7 @@ import MyTooltip from '@/components/MyTooltip'; ...@@ -19,7 +19,7 @@ import MyTooltip from '@/components/MyTooltip';
import { FlowInputItemTypeEnum, FlowValueTypeEnum } from '@/constants/flow'; import { FlowInputItemTypeEnum, FlowValueTypeEnum } from '@/constants/flow';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import MySelect from '@/components/Select'; import MySelect from '@/components/Select';
import { FlowInputItemType } from '@/types/flow'; import type { FlowInputItemType } from '@/types/core/app/flow';
const typeSelectList = [ const typeSelectList = [
{ {
......
import React, { useMemo, useState } from 'react'; import React, { useMemo, useState } from 'react';
import { import { Box, Button, ModalHeader, ModalFooter, ModalBody, Flex, Input } from '@chakra-ui/react';
Box,
Button,
ModalHeader,
ModalFooter,
ModalBody,
Flex,
Switch,
Input,
FormControl
} from '@chakra-ui/react';
import type { ContextExtractAgentItemType, HttpFieldItemType } from '@/types/app';
import { useForm } from 'react-hook-form'; import { useForm } from 'react-hook-form';
import { customAlphabet } from 'nanoid'; import { customAlphabet } from 'nanoid';
const nanoid = customAlphabet('abcdefghijklmnopqrstuvwxyz1234567890', 6); const nanoid = customAlphabet('abcdefghijklmnopqrstuvwxyz1234567890', 6);
...@@ -20,7 +9,7 @@ import MyTooltip from '@/components/MyTooltip'; ...@@ -20,7 +9,7 @@ import MyTooltip from '@/components/MyTooltip';
import { FlowOutputItemTypeEnum, FlowValueTypeEnum, FlowValueTypeStyle } from '@/constants/flow'; import { FlowOutputItemTypeEnum, FlowValueTypeEnum, FlowValueTypeStyle } from '@/constants/flow';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import MySelect from '@/components/Select'; import MySelect from '@/components/Select';
import { FlowOutputItemType } from '@/types/flow'; import { FlowOutputItemType } from '@/types/core/app/flow';
const typeSelectList = [ const typeSelectList = [
{ {
......
import React, { useState } from 'react'; import React, { useState } from 'react';
import type { FlowInputItemType, FlowModuleItemType } from '@/types/flow'; import type { FlowInputItemType } from '@/types/core/app/flow';
import { import {
Box, Box,
Textarea, Textarea,
...@@ -20,19 +20,19 @@ import MyTooltip from '@/components/MyTooltip'; ...@@ -20,19 +20,19 @@ import MyTooltip from '@/components/MyTooltip';
import TargetHandle from './TargetHandle'; import TargetHandle from './TargetHandle';
import MyIcon from '@/components/Icon'; import MyIcon from '@/components/Icon';
const SetInputFieldModal = dynamic(() => import('../modules/SetInputFieldModal')); const SetInputFieldModal = dynamic(() => import('../modules/SetInputFieldModal'));
import { useFlowStore } from '../Provider';
export const Label = ({ export const Label = ({
moduleId, moduleId,
inputKey, inputKey,
onChangeNode,
...item ...item
}: FlowInputItemType & { }: FlowInputItemType & {
moduleId: string; moduleId: string;
inputKey: string; inputKey: string;
onChangeNode: FlowModuleItemType['onChangeNode'];
}) => { }) => {
const { required = false, description, edit, label, type, valueType } = item; const { required = false, description, edit, label, type, valueType } = item;
const [editField, setEditField] = useState<FlowInputItemType>(); const [editField, setEditField] = useState<FlowInputItemType>();
const { onChangeNode } = useFlowStore();
return ( return (
<Flex className="nodrag" cursor={'default'} alignItems={'center'} position={'relative'}> <Flex className="nodrag" cursor={'default'} alignItems={'center'} position={'relative'}>
...@@ -134,28 +134,20 @@ export const Label = ({ ...@@ -134,28 +134,20 @@ export const Label = ({
const RenderInput = ({ const RenderInput = ({
flowInputList, flowInputList,
moduleId, moduleId,
CustomComponent = {}, CustomComponent = {}
onChangeNode
}: { }: {
flowInputList: FlowInputItemType[]; flowInputList: FlowInputItemType[];
moduleId: string; moduleId: string;
CustomComponent?: Record<string, (e: FlowInputItemType) => React.ReactNode>; CustomComponent?: Record<string, (e: FlowInputItemType) => React.ReactNode>;
onChangeNode: FlowModuleItemType['onChangeNode'];
}) => { }) => {
const { onChangeNode } = useFlowStore();
return ( return (
<> <>
{flowInputList.map( {flowInputList.map(
(item) => (item) =>
item.type !== FlowInputItemTypeEnum.hidden && ( item.type !== FlowInputItemTypeEnum.hidden && (
<Box key={item.key} _notLast={{ mb: 7 }} position={'relative'}> <Box key={item.key} _notLast={{ mb: 7 }} position={'relative'}>
{!!item.label && ( {!!item.label && <Label moduleId={moduleId} inputKey={item.key} {...item} />}
<Label
moduleId={moduleId}
onChangeNode={onChangeNode}
inputKey={item.key}
{...item}
/>
)}
<Box mt={2} className={'nodrag'}> <Box mt={2} className={'nodrag'}>
{item.type === FlowInputItemTypeEnum.numberInput && ( {item.type === FlowInputItemTypeEnum.numberInput && (
<NumberInput <NumberInput
......
import React, { useState } from 'react'; import React, { useState } from 'react';
import type { FlowModuleItemType, FlowOutputItemType } from '@/types/flow'; import type { FlowOutputItemType } from '@/types/core/app/flow';
import { Box, Flex } from '@chakra-ui/react'; import { Box, Flex } from '@chakra-ui/react';
import { FlowOutputItemTypeEnum } from '@/constants/flow'; import { FlowOutputItemTypeEnum } from '@/constants/flow';
import { QuestionOutlineIcon } from '@chakra-ui/icons'; import { QuestionOutlineIcon } from '@chakra-ui/icons';
...@@ -8,21 +8,21 @@ import SourceHandle from './SourceHandle'; ...@@ -8,21 +8,21 @@ import SourceHandle from './SourceHandle';
import MyIcon from '@/components/Icon'; import MyIcon from '@/components/Icon';
import dynamic from 'next/dynamic'; import dynamic from 'next/dynamic';
const SetOutputFieldModal = dynamic(() => import('../modules/SetOutputFieldModal')); const SetOutputFieldModal = dynamic(() => import('../modules/SetOutputFieldModal'));
import { useFlowStore } from '../Provider';
const Label = ({ const Label = ({
moduleId, moduleId,
outputKey, outputKey,
outputs, outputs,
onChangeNode,
...item ...item
}: FlowOutputItemType & { }: FlowOutputItemType & {
outputKey: string; outputKey: string;
moduleId: string; moduleId: string;
outputs: FlowOutputItemType[]; outputs: FlowOutputItemType[];
onChangeNode: FlowModuleItemType['onChangeNode'];
}) => { }) => {
const { label, description, edit } = item; const { label, description, edit } = item;
const [editField, setEditField] = useState<FlowOutputItemType>(); const [editField, setEditField] = useState<FlowOutputItemType>();
const { onChangeNode } = useFlowStore();
return ( return (
<Flex <Flex
...@@ -122,12 +122,10 @@ const Label = ({ ...@@ -122,12 +122,10 @@ const Label = ({
const RenderOutput = ({ const RenderOutput = ({
moduleId, moduleId,
flowOutputList, flowOutputList
onChangeNode
}: { }: {
moduleId: string; moduleId: string;
flowOutputList: FlowOutputItemType[]; flowOutputList: FlowOutputItemType[];
onChangeNode: FlowModuleItemType['onChangeNode'];
}) => { }) => {
return ( return (
<> <>
...@@ -135,13 +133,7 @@ const RenderOutput = ({ ...@@ -135,13 +133,7 @@ const RenderOutput = ({
(item) => (item) =>
item.type !== FlowOutputItemTypeEnum.hidden && ( item.type !== FlowOutputItemTypeEnum.hidden && (
<Box key={item.key} _notLast={{ mb: 7 }} position={'relative'}> <Box key={item.key} _notLast={{ mb: 7 }} position={'relative'}>
<Label <Label moduleId={moduleId} outputKey={item.key} outputs={flowOutputList} {...item} />
moduleId={moduleId}
onChangeNode={onChangeNode}
outputKey={item.key}
outputs={flowOutputList}
{...item}
/>
<Box mt={FlowOutputItemTypeEnum.answer ? 0 : 2} className={'nodrag'}> <Box mt={FlowOutputItemTypeEnum.answer ? 0 : 2} className={'nodrag'}>
{item.type === FlowOutputItemTypeEnum.source && ( {item.type === FlowOutputItemTypeEnum.source && (
<SourceHandle handleKey={item.key} valueType={item.valueType} /> <SourceHandle handleKey={item.key} valueType={item.valueType} />
......
...@@ -17,15 +17,10 @@ import BasicEdit from './components/BasicEdit'; ...@@ -17,15 +17,10 @@ import BasicEdit from './components/BasicEdit';
import { serviceSideProps } from '@/utils/web/i18n'; import { serviceSideProps } from '@/utils/web/i18n';
const AdEdit = dynamic(() => import('./components/AdEdit'), { const AdEdit = dynamic(() => import('./components/AdEdit'), {
ssr: false,
loading: () => <Loading /> loading: () => <Loading />
}); });
const OutLink = dynamic(() => import('./components/OutLink'), { const OutLink = dynamic(() => import('./components/OutLink'), {});
ssr: false const Logs = dynamic(() => import('./components/Logs'), {});
});
const Logs = dynamic(() => import('./components/Logs'), {
ssr: false
});
enum TabEnum { enum TabEnum {
'basicEdit' = 'basicEdit', 'basicEdit' = 'basicEdit',
......
...@@ -7,7 +7,7 @@ import type { ClassifyQuestionAgentItemType } from '@/types/app'; ...@@ -7,7 +7,7 @@ import type { ClassifyQuestionAgentItemType } from '@/types/app';
import { SystemInputEnum } from '@/constants/app'; import { SystemInputEnum } from '@/constants/app';
import { SpecialInputKeyEnum } from '@/constants/flow'; import { SpecialInputKeyEnum } from '@/constants/flow';
import { FlowModuleTypeEnum } from '@/constants/flow'; import { FlowModuleTypeEnum } from '@/constants/flow';
import { ModuleDispatchProps } from '@/types/core/modules'; import type { ModuleDispatchProps } from '@/types/core/chat/type';
import { replaceVariable } from '@/utils/common/tools/text'; import { replaceVariable } from '@/utils/common/tools/text';
import { Prompt_CQJson } from '@/prompts/core/agent'; import { Prompt_CQJson } from '@/prompts/core/agent';
import { defaultCQModel } from '@/pages/api/system/getInitData'; import { defaultCQModel } from '@/pages/api/system/getInitData';
......
...@@ -6,7 +6,7 @@ import { getAIChatApi, axiosConfig } from '@fastgpt/core/aiApi/config'; ...@@ -6,7 +6,7 @@ import { getAIChatApi, axiosConfig } from '@fastgpt/core/aiApi/config';
import type { ContextExtractAgentItemType } from '@/types/app'; import type { ContextExtractAgentItemType } from '@/types/app';
import { ContextExtractEnum } from '@/constants/flow/flowField'; import { ContextExtractEnum } from '@/constants/flow/flowField';
import { FlowModuleTypeEnum } from '@/constants/flow'; import { FlowModuleTypeEnum } from '@/constants/flow';
import { ModuleDispatchProps } from '@/types/core/modules'; import type { ModuleDispatchProps } from '@/types/core/chat/type';
import { Prompt_ExtractJson } from '@/prompts/core/agent'; import { Prompt_ExtractJson } from '@/prompts/core/agent';
import { replaceVariable } from '@/utils/common/tools/text'; import { replaceVariable } from '@/utils/common/tools/text';
import { defaultExtractModel } from '@/pages/api/system/getInitData'; import { defaultExtractModel } from '@/pages/api/system/getInitData';
......
...@@ -19,7 +19,7 @@ import { defaultQuotePrompt, defaultQuoteTemplate } from '@/prompts/core/AIChat' ...@@ -19,7 +19,7 @@ import { defaultQuotePrompt, defaultQuoteTemplate } from '@/prompts/core/AIChat'
import type { AIChatProps } from '@/types/core/aiChat'; import type { AIChatProps } from '@/types/core/aiChat';
import { replaceVariable } from '@/utils/common/tools/text'; import { replaceVariable } from '@/utils/common/tools/text';
import { FlowModuleTypeEnum } from '@/constants/flow'; import { FlowModuleTypeEnum } from '@/constants/flow';
import { ModuleDispatchProps } from '@/types/core/modules'; import type { ModuleDispatchProps } from '@/types/core/chat/type';
import { Readable } from 'stream'; import { Readable } from 'stream';
import { responseWrite, responseWriteController } from '@/service/common/stream'; import { responseWrite, responseWriteController } from '@/service/common/stream';
import { addLog } from '@/service/utils/tools'; import { addLog } from '@/service/utils/tools';
......
import { SystemInputEnum } from '@/constants/app'; import { SystemInputEnum } from '@/constants/app';
import { ChatItemType } from '@/types/chat'; import { ChatItemType } from '@/types/chat';
import type { ModuleDispatchProps } from '@/types/core/modules'; import type { ModuleDispatchProps } from '@/types/core/chat/type';
export type HistoryProps = ModuleDispatchProps<{ export type HistoryProps = ModuleDispatchProps<{
maxContext: number; maxContext: number;
[SystemInputEnum.history]: ChatItemType[]; [SystemInputEnum.history]: ChatItemType[];
......
import { SystemInputEnum } from '@/constants/app'; import { SystemInputEnum } from '@/constants/app';
import type { ModuleDispatchProps } from '@/types/core/modules'; import type { ModuleDispatchProps } from '@/types/core/chat/type';
export type UserChatInputProps = ModuleDispatchProps<{ export type UserChatInputProps = ModuleDispatchProps<{
[SystemInputEnum.userChatInput]: string; [SystemInputEnum.userChatInput]: string;
}>; }>;
......
...@@ -7,8 +7,7 @@ import type { SelectedDatasetType } from '@/types/core/dataset'; ...@@ -7,8 +7,7 @@ import type { SelectedDatasetType } from '@/types/core/dataset';
import type { QuoteItemType } from '@/types/chat'; import type { QuoteItemType } from '@/types/chat';
import { PgDatasetTableName } from '@/constants/plugin'; import { PgDatasetTableName } from '@/constants/plugin';
import { FlowModuleTypeEnum } from '@/constants/flow'; import { FlowModuleTypeEnum } from '@/constants/flow';
import { ModuleDispatchProps } from '@/types/core/modules'; import type { ModuleDispatchProps } from '@/types/core/chat/type';
type KBSearchProps = ModuleDispatchProps<{ type KBSearchProps = ModuleDispatchProps<{
kbList: SelectedDatasetType; kbList: SelectedDatasetType;
similarity: number; similarity: number;
......
import { sseResponseEventEnum, TaskResponseKeyEnum } from '@/constants/chat'; import { sseResponseEventEnum, TaskResponseKeyEnum } from '@/constants/chat';
import { sseResponse } from '@/service/utils/tools'; import { sseResponse } from '@/service/utils/tools';
import { textAdaptGptResponse } from '@/utils/adapt'; import { textAdaptGptResponse } from '@/utils/adapt';
import type { ModuleDispatchProps } from '@/types/core/modules'; import type { ModuleDispatchProps } from '@/types/core/chat/type';
export type AnswerProps = ModuleDispatchProps<{ export type AnswerProps = ModuleDispatchProps<{
text: string; text: string;
}>; }>;
......
...@@ -2,8 +2,7 @@ import { TaskResponseKeyEnum } from '@/constants/chat'; ...@@ -2,8 +2,7 @@ import { TaskResponseKeyEnum } from '@/constants/chat';
import { HttpPropsEnum } from '@/constants/flow/flowField'; import { HttpPropsEnum } from '@/constants/flow/flowField';
import { ChatHistoryItemResType } from '@/types/chat'; import { ChatHistoryItemResType } from '@/types/chat';
import { FlowModuleTypeEnum } from '@/constants/flow'; import { FlowModuleTypeEnum } from '@/constants/flow';
import { ModuleDispatchProps } from '@/types/core/modules'; import type { ModuleDispatchProps } from '@/types/core/chat/type';
export type HttpRequestProps = ModuleDispatchProps<{ export type HttpRequestProps = ModuleDispatchProps<{
[HttpPropsEnum.url]: string; [HttpPropsEnum.url]: string;
[key: string]: any; [key: string]: any;
......
...@@ -6,7 +6,11 @@ import { ...@@ -6,7 +6,11 @@ import {
ModulesInputItemTypeEnum, ModulesInputItemTypeEnum,
VariableInputEnum VariableInputEnum
} from '../constants/app'; } from '../constants/app';
import type { FlowInputItemType, FlowOutputItemType, FlowOutputTargetItemType } from './flow'; import type {
FlowInputItemType,
FlowOutputItemType,
FlowOutputTargetItemType
} from '@/types/core/app/flow';
import type { AppSchema, ChatSchema, kbSchema } from './mongoSchema'; import type { AppSchema, ChatSchema, kbSchema } from './mongoSchema';
import { ChatModelType } from '@/constants/model'; import { ChatModelType } from '@/constants/model';
import { FlowValueTypeEnum } from '@/constants/flow'; import { FlowValueTypeEnum } from '@/constants/flow';
......
...@@ -59,17 +59,4 @@ export type FlowModuleTemplateType = { ...@@ -59,17 +59,4 @@ export type FlowModuleTemplateType = {
}; };
export type FlowModuleItemType = FlowModuleTemplateType & { export type FlowModuleItemType = FlowModuleTemplateType & {
moduleId: string; moduleId: string;
onChangeNode: (e: FlowModuleItemChangeProps) => void;
onDelNode: (id: string) => void;
onCopyNode: (id: string) => void;
onCollectionNode: (id: string) => void;
onDelEdge: ({
moduleId,
sourceHandle,
targetHandle
}: {
moduleId: string;
sourceHandle?: string | undefined;
targetHandle?: string | undefined;
}) => void;
}; };
import type { ChatCompletionRequestMessage } from '@fastgpt/core/aiApi/type'; import type { ChatCompletionRequestMessage } from '@fastgpt/core/aiApi/type';
import type { NextApiResponse } from 'next';
import { RunningModuleItemType } from '@/types/app';
import { UserModelSchema } from '@/types/mongoSchema';
export type MessageItemType = ChatCompletionRequestMessage & { dataId?: string }; export type MessageItemType = ChatCompletionRequestMessage & { dataId?: string };
// module dispatch props type
export type ModuleDispatchProps<T> = {
res: NextApiResponse;
moduleName: string;
stream: boolean;
detail: boolean;
variables: Record<string, any>;
outputs: RunningModuleItemType['outputs'];
userOpenaiAccount?: UserModelSchema['openaiAccount'];
inputs: T;
};
import type { NextApiResponse } from 'next';
import { RunningModuleItemType } from '../app';
import { UserModelSchema } from '../mongoSchema';
// module dispatch props type
export type ModuleDispatchProps<T> = {
res: NextApiResponse;
moduleName: string;
stream: boolean;
detail: boolean;
variables: Record<string, any>;
outputs: RunningModuleItemType['outputs'];
userOpenaiAccount?: UserModelSchema['openaiAccount'];
inputs: T;
};
...@@ -6,7 +6,7 @@ import { ChatCompletionRequestMessageRoleEnum } from '@fastgpt/core/aiApi/consta ...@@ -6,7 +6,7 @@ import { ChatCompletionRequestMessageRoleEnum } from '@fastgpt/core/aiApi/consta
import { ChatRoleEnum } from '@/constants/chat'; import { ChatRoleEnum } from '@/constants/chat';
import type { MessageItemType } from '@/types/core/chat/type'; import type { MessageItemType } from '@/types/core/chat/type';
import type { AppModuleItemType } from '@/types/app'; import type { AppModuleItemType } from '@/types/app';
import type { FlowModuleItemType } from '@/types/flow'; import type { FlowModuleItemType } from '@/types/core/app/flow';
import type { Edge, Node } from 'reactflow'; import type { Edge, Node } from 'reactflow';
import { connectionLineStyle } from '@/constants/flow'; import { connectionLineStyle } from '@/constants/flow';
import { customAlphabet } from 'nanoid'; import { customAlphabet } from 'nanoid';
...@@ -61,19 +61,9 @@ export const textAdaptGptResponse = ({ ...@@ -61,19 +61,9 @@ export const textAdaptGptResponse = ({
}; };
export const appModule2FlowNode = ({ export const appModule2FlowNode = ({
item, item
onChangeNode,
onDelNode,
onDelEdge,
onCopyNode,
onCollectionNode
}: { }: {
item: AppModuleItemType; item: AppModuleItemType;
onChangeNode: FlowModuleItemType['onChangeNode'];
onDelNode: FlowModuleItemType['onDelNode'];
onDelEdge: FlowModuleItemType['onDelEdge'];
onCopyNode: FlowModuleItemType['onCopyNode'];
onCollectionNode: FlowModuleItemType['onCollectionNode'];
}): Node<FlowModuleItemType> => { }): Node<FlowModuleItemType> => {
// init some static data // init some static data
const template = const template =
...@@ -110,12 +100,7 @@ export const appModule2FlowNode = ({ ...@@ -110,12 +100,7 @@ export const appModule2FlowNode = ({
...(templateOutput ? templateOutput : output), ...(templateOutput ? templateOutput : output),
targets: output.targets || [] targets: output.targets || []
}; };
}), })
onChangeNode,
onDelNode,
onDelEdge,
onCopyNode,
onCollectionNode
}; };
return { return {
......
...@@ -8,7 +8,7 @@ import { ...@@ -8,7 +8,7 @@ import {
} from '@/constants/flow'; } from '@/constants/flow';
import { SystemInputEnum } from '@/constants/app'; import { SystemInputEnum } from '@/constants/app';
import type { SelectedDatasetType } from '@/types/core/dataset'; import type { SelectedDatasetType } from '@/types/core/dataset';
import { FlowInputItemType } from '@/types/flow'; import type { FlowInputItemType } from '@/types/core/app/flow';
import type { AIChatProps } from '@/types/core/aiChat'; import type { AIChatProps } from '@/types/core/aiChat';
import { getGuideModule, splitGuideModule } from '@/components/ChatBox/utils'; import { getGuideModule, splitGuideModule } from '@/components/ChatBox/utils';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment