perf: 优化智能体与工作流幕布渲染性能
- 分阶段加载智能体配置并按需缓存 MCP 工具 - 合并画布状态更新与节点尺寸监听,启用大图可视区域渲染和静态连线 - 隔离 Tinyflow Store 实例并补充数据同步与回归测试
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
import { getContext } from 'svelte';
|
||||
|
||||
export const TINYFLOW_NODE_SIZE_OBSERVER = Symbol(
|
||||
'tinyflow_node_size_observer',
|
||||
);
|
||||
|
||||
export type TinyflowNodeSizeObserver = {
|
||||
observe: (nodeId: string, element: Element) => void;
|
||||
unobserve: (element: Element) => void;
|
||||
};
|
||||
|
||||
export function useTinyflowNodeSizeObserver() {
|
||||
return getContext<TinyflowNodeSizeObserver | undefined>(
|
||||
TINYFLOW_NODE_SIZE_OBSERVER,
|
||||
);
|
||||
}
|
||||
@@ -1,7 +1,8 @@
|
||||
import { genShortId } from './IdGen';
|
||||
import { store } from '#store/stores.svelte';
|
||||
import { useTinyflowStore } from '#store/stores.svelte';
|
||||
|
||||
export const useCopyNode = () => {
|
||||
const store = useTinyflowStore();
|
||||
const copyNode = (id: string) => {
|
||||
const node = store.getNode(id);
|
||||
if (node) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { store } from '#store/stores.svelte';
|
||||
import { useTinyflowStore } from '#store/stores.svelte';
|
||||
import { genShortId } from '#components/utils/IdGen';
|
||||
import { type Edge, type Node, useSvelteFlow } from '@xyflow/svelte';
|
||||
|
||||
@@ -119,6 +119,7 @@ function rewriteRefsInData(obj: any, idMap: Map<string, string>): any {
|
||||
* 复制粘贴处理器 Hook
|
||||
*/
|
||||
export const useCopyPasteHandler = () => {
|
||||
const store = useTinyflowStore();
|
||||
const svelteFlow = useSvelteFlow();
|
||||
|
||||
const copyHandler = async (event: ClipboardEvent | KeyboardEvent) => {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { store } from '#store/stores.svelte';
|
||||
import { useTinyflowStore } from '#store/stores.svelte';
|
||||
|
||||
export const useDeleteEdge = () => {
|
||||
const store = useTinyflowStore();
|
||||
const deleteEdge = (id: string) => {
|
||||
store.removeEdge(id);
|
||||
};
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { store } from '#store/stores.svelte';
|
||||
import { useTinyflowStore } from '#store/stores.svelte';
|
||||
|
||||
export const useDeleteNode = () => {
|
||||
const store = useTinyflowStore();
|
||||
const deleteNode = (id: string) => {
|
||||
store.removeNode(id);
|
||||
store.updateEdges((edges) =>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { store } from '../../store/stores.svelte';
|
||||
import { useTinyflowStore } from '../../store/stores.svelte';
|
||||
|
||||
export const useEnsureParentInNodesBefore = () => {
|
||||
const store = useTinyflowStore();
|
||||
const ensureParentInNodesBefore = (
|
||||
parentNodeId: string,
|
||||
childNodeId: string,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { store } from '#store/stores.svelte';
|
||||
import { useTinyflowStore } from '#store/stores.svelte';
|
||||
|
||||
export const useGetEdgesBySource = () => {
|
||||
const store = useTinyflowStore();
|
||||
const getEdgesBySource = (target: string) => {
|
||||
const edges = store.getEdges();
|
||||
return edges.filter((edge) => edge.source === target);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { store } from '#store/stores.svelte';
|
||||
import { useTinyflowStore } from '#store/stores.svelte';
|
||||
|
||||
export const useGetEdgesByTarget = () => {
|
||||
const store = useTinyflowStore();
|
||||
const getEdgesByTarget = (target: string) => {
|
||||
const edges = store.getEdges();
|
||||
return edges.filter((edge) => edge.target === target);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { store } from '#store/stores.svelte';
|
||||
import { useTinyflowStore } from '#store/stores.svelte';
|
||||
|
||||
export const useGetNode = () => {
|
||||
const store = useTinyflowStore();
|
||||
const getNode = (id: string) => {
|
||||
return store.getNode(id);
|
||||
};
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { store } from '#store/stores.svelte';
|
||||
import { useTinyflowStore } from '#store/stores.svelte';
|
||||
|
||||
export const useGetNodeRelativePosition = () => {
|
||||
const store = useTinyflowStore();
|
||||
const getNodeRelativePosition = (parentNodeId: string) => {
|
||||
let node = store.getNode(parentNodeId);
|
||||
const position = { x: 0, y: 0 };
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { store } from '#store/stores.svelte';
|
||||
import { useTinyflowStore } from '#store/stores.svelte';
|
||||
import type { Edge, Node } from '@xyflow/svelte';
|
||||
|
||||
export const useGetNodesFromSource = () => {
|
||||
const store = useTinyflowStore();
|
||||
const getEdgesBySource = (target: string, edges: Edge[]) => {
|
||||
return edges.filter(
|
||||
// 排除循环节点的子节点,否则在多层循环嵌套时不正确
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { store } from '#store/stores.svelte';
|
||||
import { useTinyflowStore } from '#store/stores.svelte';
|
||||
|
||||
export const useUpdateEdgeData = () => {
|
||||
const store = useTinyflowStore();
|
||||
const updateEdgeData = (
|
||||
id: string,
|
||||
dataUpdate: any,
|
||||
|
||||
Reference in New Issue
Block a user