Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions web/src/pages/agent/canvas/node/handle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,20 @@ export function CommonHandle({
const { visible, hideModal, showModal } = useSetModalState();
const { canShowDropdown, setActiveDropdown, clearActiveDropdown } =
useDropdownManager();
const { hasChildNode } = useGraphStore((state) => state);
const { hasDownstreamNode, hasUpstreamNode } = useGraphStore(
(state) => state,
);
const isPipeline = useIsPipeline();

const isConnectable = !(isPipeline && hasChildNode(nodeId)); // Using useMemo will cause isConnectable to not be updated when the subsequent connection line is deleted
let isConnectable = true;

if (isPipeline) {
if (props.type === 'source') {
isConnectable = !hasDownstreamNode(nodeId);
} else if (props.type === 'target') {
isConnectable = !hasUpstreamNode(nodeId);
}
}

const value = useMemo(
() => ({
Expand Down
1 change: 1 addition & 0 deletions web/src/pages/agent/constant/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,7 @@ export const RestrictedUpstreamMap = {
[Operator.Loop]: [Operator.Begin],
[Operator.LoopStart]: [Operator.Begin],
[Operator.ExitLoop]: [Operator.Begin],
[Operator.PDFGenerator]: [Operator.Begin],
};

export const NodeMap = {
Expand Down
11 changes: 8 additions & 3 deletions web/src/pages/agent/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ export type RFState = {
) => void; // Deleting a condition of a classification operator will delete the related edge
findAgentToolNodeById: (id: string | null) => string | undefined;
selectNodeIds: (nodeIds: string[]) => void;
hasChildNode: (nodeId: string) => boolean;
hasDownstreamNode: (nodeId: string) => boolean;
hasUpstreamNode: (nodeId: string) => boolean;
};

// this is our useStore hook that we can use in our components to get parts of the store and call actions
Expand Down Expand Up @@ -469,7 +470,7 @@ const useGraphStore = create<RFState>()(
const { updateNodeForm, edges, getOperatorTypeFromId } = get();
if (sourceHandle) {
// A handle will connect to multiple downstream nodes
let currentHandleTargets = edges
const currentHandleTargets = edges
.filter(
(x) =>
x.source === source &&
Expand Down Expand Up @@ -647,10 +648,14 @@ const useGraphStore = create<RFState>()(
})),
);
},
hasChildNode: (nodeId) => {
hasDownstreamNode: (nodeId) => {
const { edges } = get();
return edges.some((edge) => edge.source === nodeId);
},
hasUpstreamNode: (nodeId) => {
const { edges } = get();
return edges.some((edge) => edge.target === nodeId);
},
})),
{ name: 'graph', trace: true },
),
Expand Down