You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

agent-node.tsx 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import { IAgentNode } from '@/interfaces/database/flow';
  2. import { Handle, NodeProps, Position } from '@xyflow/react';
  3. import { memo, useMemo } from 'react';
  4. import { NodeHandleId } from '../../constant';
  5. import useGraphStore from '../../store';
  6. import { isBottomSubAgent } from '../../utils';
  7. import { CommonHandle } from './handle';
  8. import { LeftHandleStyle, RightHandleStyle } from './handle-icon';
  9. import styles from './index.less';
  10. import NodeHeader from './node-header';
  11. import { NodeWrapper } from './node-wrapper';
  12. import { ToolBar } from './toolbar';
  13. function InnerAgentNode({
  14. id,
  15. data,
  16. isConnectable = true,
  17. selected,
  18. }: NodeProps<IAgentNode>) {
  19. const edges = useGraphStore((state) => state.edges);
  20. const isHeadAgent = useMemo(() => {
  21. return !isBottomSubAgent(edges, id);
  22. }, [edges, id]);
  23. return (
  24. <ToolBar selected={selected} id={id} label={data.label}>
  25. <NodeWrapper>
  26. {isHeadAgent && (
  27. <>
  28. <CommonHandle
  29. type="target"
  30. position={Position.Left}
  31. isConnectable={isConnectable}
  32. style={LeftHandleStyle}
  33. nodeId={id}
  34. id={NodeHandleId.End}
  35. ></CommonHandle>
  36. <CommonHandle
  37. type="source"
  38. position={Position.Right}
  39. isConnectable={isConnectable}
  40. className={styles.handle}
  41. style={RightHandleStyle}
  42. nodeId={id}
  43. id={NodeHandleId.Start}
  44. isConnectableEnd={false}
  45. ></CommonHandle>
  46. </>
  47. )}
  48. <Handle
  49. type="target"
  50. position={Position.Top}
  51. isConnectable={false}
  52. id={NodeHandleId.AgentTop}
  53. ></Handle>
  54. <Handle
  55. type="source"
  56. position={Position.Bottom}
  57. isConnectable={false}
  58. id={NodeHandleId.AgentBottom}
  59. style={{ left: 180 }}
  60. ></Handle>
  61. <Handle
  62. type="source"
  63. position={Position.Bottom}
  64. isConnectable={false}
  65. id={NodeHandleId.Tool}
  66. style={{ left: 20 }}
  67. ></Handle>
  68. <NodeHeader id={id} name={data.name} label={data.label}></NodeHeader>
  69. </NodeWrapper>
  70. </ToolBar>
  71. );
  72. }
  73. export const AgentNode = memo(InnerAgentNode);