Feat: Collapse the excess portion of the tool node and retrieval node #9869 (#10604)

### What problem does this PR solve?

Feat: Collapse the excess portion of the tool node and retrieval node
#9869

### Type of change


- [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
balibabu
2025-10-16 15:17:13 +08:00
committed by GitHub
parent 8a41057236
commit 7b664b5a84
5 changed files with 97 additions and 35 deletions

View File

@ -5,6 +5,8 @@ import {
} from '@/components/ui/collapsible'; } from '@/components/ui/collapsible';
import { cn } from '@/lib/utils'; import { cn } from '@/lib/utils';
import { CollapsibleProps } from '@radix-ui/react-collapsible'; import { CollapsibleProps } from '@radix-ui/react-collapsible';
import { ChevronDown, ChevronUp } from 'lucide-react';
import * as React from 'react';
import { import {
PropsWithChildren, PropsWithChildren,
ReactNode, ReactNode,
@ -67,3 +69,53 @@ export function Collapse({
</Collapsible> </Collapsible>
); );
} }
export type NodeCollapsibleProps<T extends any[]> = {
items?: T;
children: (item: T[0], idx: number) => ReactNode;
className?: string;
};
export function NodeCollapsible<T extends any[]>({
items = [] as unknown as T,
children,
className,
}: NodeCollapsibleProps<T>) {
const [isOpen, setIsOpen] = React.useState(false);
const nextClassName = cn('space-y-2', className);
const nextItems = items.every((x) => Array.isArray(x)) ? items.flat() : items;
return (
<Collapsible
open={isOpen}
onOpenChange={setIsOpen}
className={cn('relative', nextClassName)}
>
{nextItems.slice(0, 3).map(children)}
<CollapsibleContent className={nextClassName}>
{nextItems.slice(3).map(children)}
</CollapsibleContent>
{nextItems.length > 3 && (
<CollapsibleTrigger
asChild
onClick={(e) => e.stopPropagation()}
className="absolute left-1/2 -translate-x-1/2 bottom-0 translate-y-1/2 cursor-pointer"
>
<div
className={cn(
'size-3 bg-text-secondary rounded-full flex items-center justify-center',
{ 'bg-text-primary': isOpen },
)}
>
{isOpen ? (
<ChevronUp className="stroke-bg-component" />
) : (
<ChevronDown className="stroke-bg-component" />
)}
</div>
</CollapsibleTrigger>
)}
</Collapsible>
);
}

View File

@ -17,7 +17,7 @@ const buttonVariants = cva(
outline: outline:
'border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:bg-input/30 dark:border-input dark:hover:bg-input/50', 'border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:bg-input/30 dark:border-input dark:hover:bg-input/50',
secondary: secondary:
'bg-bg-input text-secondary-foreground shadow-xs hover:bg-bg-input/80', 'bg-bg-input text-text-primary shadow-xs hover:bg-bg-input/80 border border-border-button',
ghost: ghost:
'hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50', 'hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50',
link: 'text-primary underline-offset-4 hover:underline', link: 'text-primary underline-offset-4 hover:underline',

View File

@ -1,3 +1,4 @@
import { NodeCollapsible } from '@/components/collapse';
import { RAGFlowAvatar } from '@/components/ragflow-avatar'; import { RAGFlowAvatar } from '@/components/ragflow-avatar';
import { useFetchKnowledgeList } from '@/hooks/knowledge-hooks'; import { useFetchKnowledgeList } from '@/hooks/knowledge-hooks';
import { IRetrievalNode } from '@/interfaces/database/flow'; import { IRetrievalNode } from '@/interfaces/database/flow';
@ -44,8 +45,8 @@ function InnerRetrievalNode({
[styles.nodeHeader]: knowledgeBaseIds.length > 0, [styles.nodeHeader]: knowledgeBaseIds.length > 0,
})} })}
></NodeHeader> ></NodeHeader>
<section className="flex flex-col gap-2"> <NodeCollapsible items={knowledgeBaseIds}>
{knowledgeBaseIds.map((id) => { {(id) => {
const item = knowledgeList.find((y) => id === y.id); const item = knowledgeList.find((y) => id === y.id);
const label = getLabel(id); const label = getLabel(id);
@ -63,8 +64,8 @@ function InnerRetrievalNode({
</div> </div>
</div> </div>
); );
})} }}
</section> </NodeCollapsible>
</NodeWrapper> </NodeWrapper>
</ToolBar> </ToolBar>
); );

View File

@ -1,3 +1,4 @@
import { NodeCollapsible } from '@/components/collapse';
import { IAgentForm, IToolNode } from '@/interfaces/database/agent'; import { IAgentForm, IToolNode } from '@/interfaces/database/agent';
import { Handle, NodeProps, Position } from '@xyflow/react'; import { Handle, NodeProps, Position } from '@xyflow/react';
import { get } from 'lodash'; import { get } from 'lodash';
@ -51,32 +52,38 @@ function InnerToolNode({
isConnectable={isConnectable} isConnectable={isConnectable}
className="!bg-accent-primary !size-2" className="!bg-accent-primary !size-2"
></Handle> ></Handle>
<ul className="space-y-2"> <NodeCollapsible items={[tools, mcpList]}>
{tools.map((x) => ( {(x) => {
<ToolCard if ('mcp_id' in x) {
key={x.component_name} const mcp = x as unknown as IAgentForm['mcp'][number];
onClick={handleClick(x.component_name)} return (
className="cursor-pointer" <ToolCard
data-tool={x.component_name} onClick={handleClick(mcp.mcp_id)}
> className="cursor-pointer"
<div className="flex gap-1 items-center pointer-events-none"> data-tool={x.mcp_id}
<OperatorIcon name={x.component_name as Operator}></OperatorIcon> >
{x.component_name} {findMcpById(mcp.mcp_id)?.name}
</div> </ToolCard>
</ToolCard> );
))} }
{mcpList.map((x) => ( const tool = x as unknown as IAgentForm['tools'][number];
<ToolCard return (
key={x.mcp_id} <ToolCard
onClick={handleClick(x.mcp_id)} onClick={handleClick(tool.component_name)}
className="cursor-pointer" className="cursor-pointer"
data-tool={x.mcp_id} data-tool={tool.component_name}
> >
{findMcpById(x.mcp_id)?.name} <div className="flex gap-1 items-center pointer-events-none">
</ToolCard> <OperatorIcon
))} name={tool.component_name as Operator}
</ul> ></OperatorIcon>
{tool.component_name}
</div>
</ToolCard>
);
}}
</NodeCollapsible>
</NodeWrapper> </NodeWrapper>
); );
} }

View File

@ -1,3 +1,4 @@
import { NodeCollapsible } from '@/components/collapse';
import { BaseNode } from '@/interfaces/database/agent'; import { BaseNode } from '@/interfaces/database/agent';
import { NodeProps, Position } from '@xyflow/react'; import { NodeProps, Position } from '@xyflow/react';
import { memo } from 'react'; import { memo } from 'react';
@ -37,17 +38,18 @@ function ParserNode({
isConnectableEnd={false} isConnectableEnd={false}
></CommonHandle> ></CommonHandle>
<NodeHeader id={id} name={data.name} label={data.label}></NodeHeader> <NodeHeader id={id} name={data.name} label={data.label}></NodeHeader>
<section className="space-y-2">
{data.form?.setups.map((x, idx) => ( <NodeCollapsible items={data.form?.setups}>
{(x, idx) => (
<LabelCard <LabelCard
key={idx} key={idx}
className="flex justify- flex-col text-text-primary gap-1" className="flex flex-col text-text-primary gap-1"
> >
<span className="text-text-secondary">Parser {idx + 1}</span> <span className="text-text-secondary">Parser {idx + 1}</span>
{t(`dataflow.fileFormatOptions.${x.fileFormat}`)} {t(`dataflow.fileFormatOptions.${x.fileFormat}`)}
</LabelCard> </LabelCard>
))} )}
</section> </NodeCollapsible>
</NodeWrapper> </NodeWrapper>
); );
} }