Skip to content

Commit

Permalink
Perf: worfklow scroll cannot wheel. Adapt wrokflow skip circle. Chang…
Browse files Browse the repository at this point in the history
…e tab alway output stream (#2688)

* perf: teaxtarea no wheel

* remove render error

* adapt workflow skip circle

* perf: change tab can stream output
  • Loading branch information
c121914yu authored Sep 12, 2024
1 parent fde1618 commit 56281d9
Show file tree
Hide file tree
Showing 11 changed files with 64 additions and 39 deletions.
5 changes: 3 additions & 2 deletions docSite/content/zh-cn/docs/development/upgrading/4811.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ weight: 813
4. 优化 - 工作流嵌套层级限制 20 层,避免因编排不合理导致的无限死循环。
5. 优化 - 工作流 handler 性能优化。
6. 优化 - 工作流快捷键,避免调试测试时也会触发。
7. 修复 - 知识库选择权限问题。
8. 修复 - 空 chatId 发起对话,首轮携带用户选择时会异常。
7. 优化 - 流输出,切换 tab 时仍可以继续输出。
8. 修复 - 知识库选择权限问题。
9. 修复 - 空 chatId 发起对话,首轮携带用户选择时会异常。
13 changes: 12 additions & 1 deletion packages/service/core/workflow/dispatch/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,18 @@ export async function dispatchWorkFlow(data: Props): Promise<DispatchFlowRespons

if (!nodeRunResult) return [];

/*
特殊情况:
通过 skipEdges 可以判断是运行了分支节点。
由于分支节点,可能会实现递归调用(skip 连线往前递归)
需要把分支节点也加入到已跳过的记录里,可以保证递归 skip 运行时,至多只会传递到当前分支节点,不会影响分支后的内容。
*/
const skipEdges = (nodeRunResult.result[DispatchNodeResponseKeyEnum.skipHandleId] ||
[]) as string[];
if (skipEdges && skipEdges?.length > 0) {
skippedNodeIdList.add(node.nodeId);
}

// In the current version, only one interactive node is allowed at the same time
const interactiveResponse = nodeRunResult.result?.[DispatchNodeResponseKeyEnum.interactive];
if (interactiveResponse) {
Expand Down Expand Up @@ -559,7 +571,6 @@ export async function dispatchWorkFlow(data: Props): Promise<DispatchFlowRespons

// start process width initInput
const entryNodes = runtimeNodes.filter((item) => item.isEntry);

// reset entry
runtimeNodes.forEach((item) => {
// Interactive node is not the entry node, return interactive result
Expand Down
1 change: 0 additions & 1 deletion packages/web/hooks/useScrollPagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ export function useScrollPagination<
// Reload data
useRequest(
async () => {
console.log('reload', 11111);
loadData(1);
},
{
Expand Down
11 changes: 10 additions & 1 deletion projects/app/src/components/Layout/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useMemo } from 'react';
import React, { useEffect, useMemo } from 'react';
import { Box, Flex } from '@chakra-ui/react';
import { useRouter } from 'next/router';
import { useLoading } from '@fastgpt/web/hooks/useLoading';
Expand All @@ -12,6 +12,7 @@ import { useI18nLng } from '@fastgpt/web/hooks/useI18n';
import Auth from './auth';
import { useSystem } from '@fastgpt/web/hooks/useSystem';
import { useMount } from 'ahooks';
import { watchWindowHidden } from '@/web/common/system/utils';
const Navbar = dynamic(() => import('./navbar'));
const NavbarPhone = dynamic(() => import('./navbarPhone'));
const UpdateInviteModal = dynamic(() => import('@/components/support/user/team/UpdateInviteModal'));
Expand Down Expand Up @@ -68,6 +69,14 @@ const Layout = ({ children }: { children: JSX.Element }) => {
setUserDefaultLng();
});

// Add global listener
useEffect(() => {
document.addEventListener('visibilitychange', watchWindowHidden);
return () => {
document.removeEventListener('visibilitychange', watchWindowHidden);
};
});

return (
<>
<Box h={'100%'} bg={'myGray.100'}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@ import MyModal from '@fastgpt/web/components/common/MyModal';
import { useToast } from '@fastgpt/web/hooks/useToast';
import { useContextSelector } from 'use-context-selector';
import { WorkflowContext } from '../context';
import { useI18n } from '@/web/context/I18n';
import { useTranslation } from 'next-i18next';
import MyIcon from '@fastgpt/web/components/common/Icon';
import { useSelectFile } from '@/web/common/file/hooks/useSelectFile';
import { useSystem } from '@fastgpt/web/hooks/useSystem';

type Props = {
onClose: () => void;
};

const ImportSettings = ({ onClose }: Props) => {
const { appT } = useI18n();
const { toast } = useToast();
const { File, onOpen } = useSelectFile({
fileType: 'json',
Expand All @@ -25,21 +24,6 @@ const ImportSettings = ({ onClose }: Props) => {
const [isDragging, setIsDragging] = useState(false);
const [value, setValue] = useState('');
const { t } = useTranslation();
const handleDragEnter = useCallback((e: DragEvent<HTMLDivElement>) => {
e.preventDefault();
setIsDragging(true);
}, []);

const handleDragLeave = useCallback((e: DragEvent<HTMLDivElement>) => {
e.preventDefault();
setIsDragging(false);
}, []);
const handleDrop = useCallback(async (e: DragEvent<HTMLDivElement>) => {
e.preventDefault();
const file = e.dataTransfer.files[0];
readJSONFile(file);
setIsDragging(false);
}, []);

const readJSONFile = useCallback(
(file: File) => {
Expand All @@ -62,6 +46,25 @@ const ImportSettings = ({ onClose }: Props) => {
[t, toast]
);

const handleDragEnter = useCallback((e: DragEvent<HTMLDivElement>) => {
e.preventDefault();
setIsDragging(true);
}, []);

const handleDragLeave = useCallback((e: DragEvent<HTMLDivElement>) => {
e.preventDefault();
setIsDragging(false);
}, []);
const handleDrop = useCallback(
async (e: DragEvent<HTMLDivElement>) => {
e.preventDefault();
const file = e.dataTransfer.files[0];
readJSONFile(file);
setIsDragging(false);
},
[readJSONFile]
);

const onSelectFile = useCallback(
async (e: File[]) => {
const file = e[0];
Expand All @@ -70,16 +73,14 @@ const ImportSettings = ({ onClose }: Props) => {
},
[readJSONFile]
);

return (
<MyModal
isOpen
onClose={onClose}
title={
<Flex align={'center'} ml={-3}>
<MyIcon name={'common/importLight'} color={'primary.600'} w={'1.25rem'} mr={'0.62rem'} />
<Box lineHeight={'1.25rem'}>{appT('import_configs')}</Box>
</Flex>
}
iconSrc="common/importLight"
iconColor="primary.600"
title={t('app:import_configs')}
size={isPc ? 'lg' : 'md'}
>
<ModalBody>
Expand Down Expand Up @@ -129,14 +130,12 @@ const ImportSettings = ({ onClose }: Props) => {
border={'1px solid'}
borderRadius={'md'}
borderColor={'myGray.200'}
h={'15.125rem'}
value={value}
placeholder={
isPc
? t('app:paste_config') + '\n' + t('app:or_drag_JSON')
: t('app:paste_config')
}
defaultValue={value}
rows={16}
onChange={(e) => setValue(e.target.value)}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,10 @@ const FlowController = React.memo(function FlowController() {

// Controller shortcut key
useKeyPress(['ctrl.z', 'meta.z'], (e) => {
e.preventDefault();
if (!mouseInCanvas) return;
undo();
});
useKeyPress(['ctrl.shift.z', 'meta.shift.z', 'ctrl.y', 'meta.y'], (e) => {
e.preventDefault();
if (!mouseInCanvas) return;
redo();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,10 @@ export const useKeyboard = () => {
}, [computedNewNodeName, hasInputtingElement, setNodes]);

useKeyPressEffect(['ctrl.c', 'meta.c'], (e) => {
e.preventDefault();
if (!mouseInCanvas) return;
onCopy();
});
useKeyPressEffect(['ctrl.v', 'meta.v'], (e) => {
e.preventDefault();
if (!mouseInCanvas) return;
onParse();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const ToolTargetHandle = ({ show, nodeId }: ToolHandleProps) => {
type="target"
id={handleId}
position={Position.Top}
isConnectableStart={false}
isConnectableEnd={showHandle}
>
<Box
className="flow-handle"
Expand Down
3 changes: 1 addition & 2 deletions projects/app/src/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,12 @@ declare global {
var qaQueueLen: number;
var vectorQueueLen: number;

var systemVersion: string;

interface Window {
grecaptcha: any;
QRCode: any;
umami?: {
track: (event: TrackEventName, data: any) => void;
};
windowHidden: boolean;
}
}
6 changes: 4 additions & 2 deletions projects/app/src/web/common/api/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export const streamFetch = ({
}

if (responseQueue.length > 0) {
const fetchCount = Math.max(1, Math.round(responseQueue.length / 30));
const fetchCount = Math.max(1, Math.round(responseQueue.length / 20));
for (let i = 0; i < fetchCount; i++) {
const item = responseQueue[i];
onMessage(item);
Expand All @@ -100,7 +100,9 @@ export const streamFetch = ({
return finish();
}

requestAnimationFrame(animateResponseText);
window.windowHidden
? setTimeout(animateResponseText, 16)
: requestAnimationFrame(animateResponseText);
}
// start animation
animateResponseText();
Expand Down
9 changes: 9 additions & 0 deletions projects/app/src/web/common/system/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,12 @@ export const getWebLLMModel = (model?: string) => {
const list = useSystemStore.getState().llmModelList;
return list.find((item) => item.model === model || item.name === model) ?? list[0];
};

export const watchWindowHidden = () => {
// @ts-ignore
if (document.hidden) {
window.windowHidden = true;
} else {
window.windowHidden = false;
}
};

0 comments on commit 56281d9

Please sign in to comment.