ragflow/web/src/pages/agent/hooks/use-build-dsl.ts
balibabu 0879b6af2c
Feat: Globally defined conversation variables can be selected in the operator's query variables. #10427 (#11135)
### What problem does this PR solve?

Feat: Globally defined conversation variables can be selected in the
operator's query variables. #10427

### Type of change


- [x] New Feature (non-breaking change which adds functionality)
2025-11-10 15:09:33 +08:00

59 lines
1.8 KiB
TypeScript

import { useFetchAgent } from '@/hooks/use-agent-request';
import { GlobalVariableType } from '@/interfaces/database/agent';
import { RAGFlowNodeType } from '@/interfaces/database/flow';
import { useCallback } from 'react';
import { Operator } from '../constant';
import useGraphStore from '../store';
import { buildDslComponentsByGraph, buildDslGobalVariables } from '../utils';
export const useBuildDslData = () => {
const { data } = useFetchAgent();
const { nodes, edges } = useGraphStore((state) => state);
const buildDslData = useCallback(
(
currentNodes?: RAGFlowNodeType[],
otherParam?: { gobalVariables: Record<string, GlobalVariableType> },
) => {
const nodesToProcess = currentNodes ?? nodes;
// Filter out placeholder nodes and related edges
const filteredNodes = nodesToProcess.filter(
(node) => node.data?.label !== Operator.Placeholder,
);
const filteredEdges = edges.filter((edge) => {
const sourceNode = nodesToProcess.find(
(node) => node.id === edge.source,
);
const targetNode = nodesToProcess.find(
(node) => node.id === edge.target,
);
return (
sourceNode?.data?.label !== Operator.Placeholder &&
targetNode?.data?.label !== Operator.Placeholder
);
});
const dslComponents = buildDslComponentsByGraph(
filteredNodes,
filteredEdges,
data.dsl.components,
);
const gobalVariables = buildDslGobalVariables(
data.dsl,
otherParam?.gobalVariables,
);
return {
...data.dsl,
...gobalVariables,
graph: { nodes: filteredNodes, edges: filteredEdges },
components: dslComponents,
};
},
[data.dsl, edges, nodes],
);
return { buildDslData };
};