@ant-design/agentic-ui 2.0.4 → 2.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -15,46 +15,4 @@ interface ToolUseBarProps {
15
15
  testId?: string;
16
16
  light?: boolean;
17
17
  }
18
- /**
19
- * ToolUseBar 组件 - 工具使用栏组件
20
- *
21
- * 该组件显示工具使用列表,支持工具的展开/折叠、激活状态管理等功能。
22
- * 每个工具项显示工具名称、目标、时间等信息,支持点击交互。
23
- *
24
- * @component
25
- * @description 工具使用栏组件,显示工具使用列表和状态
26
- * @param {ToolUseBarProps} props - 组件属性
27
- * @param {ToolUseItem[]} [props.tools] - 工具使用列表
28
- * @param {string[]} [props.activeKeys] - 当前激活的工具ID列表
29
- * @param {string[]} [props.defaultActiveKeys] - 默认激活的工具ID列表
30
- * @param {(keys: string[]) => void} [props.onActiveKeysChange] - 激活状态变化回调
31
- * @param {string[]} [props.expandedKeys] - 当前展开的工具ID列表
32
- * @param {string[]} [props.defaultExpandedKeys] - 默认展开的工具ID列表
33
- * @param {(keys: string[]) => void} [props.onExpandedKeysChange] - 展开状态变化回调
34
- * @param {(tool: ToolUseItem) => void} [props.onToolClick] - 工具点击回调
35
- * @param {string} [props.className] - 自定义CSS类名
36
- * @param {React.CSSProperties} [props.style] - 自定义样式
37
- *
38
- * @example
39
- * ```tsx
40
- * <ToolUseBar
41
- * tools={toolList}
42
- * activeKeys={['tool1', 'tool2']}
43
- * onActiveKeysChange={(keys) => setActiveKeys(keys)}
44
- * expandedKeys={['tool1']}
45
- * onExpandedKeysChange={(keys) => setExpandedKeys(keys)}
46
- * onToolClick={(tool) => console.log('点击工具:', tool.toolName)}
47
- * />
48
- * ```
49
- *
50
- * @returns {React.ReactElement} 渲染的工具使用栏组件
51
- *
52
- * @remarks
53
- * - 支持工具列表的受控和非受控展开/折叠
54
- * - 支持工具的受控和非受控激活状态管理
55
- * - 显示工具名称、目标、时间等信息
56
- * - 支持工具点击交互
57
- * - 提供加载状态显示
58
- * - 支持错误状态处理
59
- */
60
- export declare const ToolUseBar: React.FC<ToolUseBarProps>;
18
+ export declare const ToolUseBar: React.NamedExoticComponent<ToolUseBarProps>;
@@ -18,13 +18,12 @@ var __objRest = (source, exclude) => {
18
18
  import { ConfigProvider } from "antd";
19
19
  import classNames from "classnames";
20
20
  import { useMergedState } from "rc-util";
21
- import React, { useContext } from "react";
22
- import { useRefFunction } from "../hooks/useRefFunction";
21
+ import React, { memo, useCallback, useContext, useMemo } from "react";
23
22
  import { ToolUseBarItem } from "./ToolUseBarItem";
24
23
  import { useStyle } from "./style";
25
24
  export * from "./ToolUseBarItem";
26
25
  export * from "./ToolUseBarThink";
27
- var ToolUseBar = (_a) => {
26
+ var ToolUseBarComponent = (_a) => {
28
27
  var _b = _a, {
29
28
  tools,
30
29
  onActiveKeysChange,
@@ -54,13 +53,16 @@ var ToolUseBar = (_a) => {
54
53
  onChange: onExpandedKeysChange
55
54
  }
56
55
  );
57
- const handleActiveChange = useRefFunction((id, active) => {
58
- if (onActiveKeysChange) {
59
- const newActiveKeys = active ? [...activeKeys, id] : activeKeys.filter((key) => key !== id);
60
- setActiveKeys(newActiveKeys);
61
- }
62
- });
63
- const handleExpandedChange = useRefFunction(
56
+ const handleActiveChange = useCallback(
57
+ (id, active) => {
58
+ if (onActiveKeysChange) {
59
+ const newActiveKeys = active ? [...activeKeys, id] : activeKeys.filter((key) => key !== id);
60
+ setActiveKeys(newActiveKeys);
61
+ }
62
+ },
63
+ [onActiveKeysChange, activeKeys, setActiveKeys]
64
+ );
65
+ const handleExpandedChange = useCallback(
64
66
  (id, expanded) => {
65
67
  const newExpandedKeys = expanded ? [...expandedKeys, id] : expandedKeys.filter((key) => key !== id);
66
68
  const removedKeys = expandedKeys.filter(
@@ -70,45 +72,54 @@ var ToolUseBar = (_a) => {
70
72
  if (onExpandedKeysChange) {
71
73
  onExpandedKeysChange(newExpandedKeys, removedKeys);
72
74
  }
73
- }
75
+ },
76
+ [onExpandedKeysChange, expandedKeys, setExpandedKeys]
74
77
  );
78
+ const toolItems = useMemo(() => {
79
+ if (!(tools == null ? void 0 : tools.length))
80
+ return null;
81
+ return tools.map((tool) => {
82
+ var _a2;
83
+ return /* @__PURE__ */ React.createElement(
84
+ ToolUseBarItem,
85
+ {
86
+ key: tool.id,
87
+ tool,
88
+ onClick: props.onToolClick,
89
+ isActive: activeKeys.includes(tool.id),
90
+ onActiveChange: handleActiveChange,
91
+ isExpanded: onExpandedKeysChange ? expandedKeys.includes(tool.id) : void 0,
92
+ onExpandedChange: onExpandedKeysChange ? handleExpandedChange : void 0,
93
+ defaultExpanded: (_a2 = props.defaultExpandedKeys) == null ? void 0 : _a2.includes(tool.id),
94
+ prefixCls,
95
+ hashId,
96
+ light
97
+ }
98
+ );
99
+ });
100
+ }, [
101
+ tools,
102
+ props.onToolClick,
103
+ activeKeys,
104
+ handleActiveChange,
105
+ onExpandedKeysChange,
106
+ expandedKeys,
107
+ handleExpandedChange,
108
+ props.defaultExpandedKeys,
109
+ prefixCls,
110
+ hashId,
111
+ light
112
+ ]);
113
+ const containerClassName = useMemo(() => {
114
+ return classNames(prefixCls, hashId, props.className);
115
+ }, [prefixCls, hashId, props.className]);
75
116
  if (!(tools == null ? void 0 : tools.length))
76
- return /* @__PURE__ */ React.createElement(
77
- "div",
78
- {
79
- className: classNames(prefixCls, hashId, props.className),
80
- "data-testid": "ToolUse"
81
- }
82
- );
117
+ return /* @__PURE__ */ React.createElement("div", { className: containerClassName, "data-testid": "ToolUse" });
83
118
  return wrapSSR(
84
- /* @__PURE__ */ React.createElement(
85
- "div",
86
- {
87
- className: classNames(prefixCls, hashId, props.className),
88
- "data-testid": "ToolUse"
89
- },
90
- tools.map((tool) => {
91
- var _a2;
92
- return /* @__PURE__ */ React.createElement(
93
- ToolUseBarItem,
94
- {
95
- key: tool.id,
96
- tool,
97
- onClick: props.onToolClick,
98
- isActive: activeKeys.includes(tool.id),
99
- onActiveChange: handleActiveChange,
100
- isExpanded: onExpandedKeysChange ? expandedKeys.includes(tool.id) : void 0,
101
- onExpandedChange: onExpandedKeysChange ? handleExpandedChange : void 0,
102
- defaultExpanded: (_a2 = props.defaultExpandedKeys) == null ? void 0 : _a2.includes(tool.id),
103
- prefixCls,
104
- hashId,
105
- light
106
- }
107
- );
108
- })
109
- )
119
+ /* @__PURE__ */ React.createElement("div", { className: containerClassName, "data-testid": "ToolUse" }, toolItems)
110
120
  );
111
121
  };
122
+ var ToolUseBar = memo(ToolUseBarComponent);
112
123
  export {
113
124
  ToolUseBar
114
125
  };
@@ -219,6 +219,8 @@ var genStyle = (token) => {
219
219
  padding: 8,
220
220
  display: "flex",
221
221
  maxHeight: 700,
222
+ overflow: "hidden",
223
+ overflowY: "auto",
222
224
  position: "relative",
223
225
  "&-light": {
224
226
  borderLeft: "1px solid var(--color-gray-border-light)",
@@ -49,48 +49,4 @@ export interface VisualListProps {
49
49
  /** 描述文字 */
50
50
  description?: string;
51
51
  }
52
- /**
53
- * VisualList 组件 - 视觉列表组件
54
- *
55
- * 一个灵活的图片列表组件,支持多种尺寸、形状和自定义渲染。
56
- * 基于 css-in-js 样式系统,提供良好的主题支持和样式隔离。
57
- *
58
- * @component
59
- * @description 用于展示图片列表的组件,支持头像、缩略图等多种场景
60
- * @example
61
- * ```tsx
62
- * import { VisualList, VisualListItem } from '@ant-design/agentic-ui';
63
- *
64
- * const imageData: VisualListItem[] = [
65
- * {
66
- * id: '1',
67
- * src: 'https://example.com/image1.jpg',
68
- * alt: 'Image 1',
69
- * title: 'Image Title',
70
- * href: 'https://example.com/profile/1'
71
- * }
72
- * ];
73
- *
74
- * // 基础用法
75
- * <VisualList data={imageData} />
76
- *
77
- * // 大尺寸圆形头像
78
- * <VisualList data={imageData} shape="circle" />
79
- *
80
- * // 带边框的列表
81
- * <VisualList data={imageData} variant="outline" />
82
- *
83
- * // 无边框的列表
84
- * <VisualList data={imageData} variant="borderless" />
85
- *
86
- * // 带描述文字的列表
87
- * <VisualList data={imageData} description="用户头像列表" />
88
- *
89
- * // 过滤数据
90
- * <VisualList data={imageData} filter={(item) => item.href !== undefined} />
91
- * ```
92
- *
93
- * @param props - 组件属性
94
- * @returns 渲染的视觉列表组件
95
- */
96
- export declare const VisualList: React.FC<VisualListProps>;
52
+ export declare const VisualList: React.NamedExoticComponent<VisualListProps>;
@@ -21,13 +21,14 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
21
21
  // src/components/VisualList/index.tsx
22
22
  import { SquareArrowUpRight } from "@sofa-design/icons";
23
23
  import classNames from "classnames";
24
- import React, { useState } from "react";
24
+ import React, { memo, useMemo, useState } from "react";
25
+ import { useRefFunction } from "../../hooks/useRefFunction";
25
26
  import { useStyle } from "./style";
26
- var VisualList = ({
27
+ var VisualListComponent = ({
27
28
  className,
28
29
  style,
29
- data = [],
30
- filter = () => true,
30
+ data,
31
+ filter,
31
32
  emptyRender,
32
33
  renderItem,
33
34
  loading = false,
@@ -41,6 +42,108 @@ var VisualList = ({
41
42
  description
42
43
  }) => {
43
44
  const { wrapSSR, hashId } = useStyle(prefixCls);
45
+ const displayList = useMemo(() => {
46
+ if (!filter) {
47
+ return data || [];
48
+ }
49
+ return (data == null ? void 0 : data.filter(filter)) || [];
50
+ }, [data, filter]);
51
+ const containerClassName = useMemo(() => {
52
+ return classNames(
53
+ `${prefixCls}-container`,
54
+ hashId,
55
+ {
56
+ [`${prefixCls}-outline`]: variant === "outline",
57
+ [`${prefixCls}-borderless`]: variant === "borderless",
58
+ [`${prefixCls}-default`]: variant === "default"
59
+ },
60
+ className
61
+ );
62
+ }, [prefixCls, hashId, variant, className]);
63
+ const ImageComponent = memo(({ item, prefixCls: prefixCls2, hashId: hashId2, shape: shape2, imageStyle: imageStyle2, onImageError }) => {
64
+ const [imageError, setImageError] = useState(false);
65
+ const handleImageError = useRefFunction(() => {
66
+ setImageError(true);
67
+ onImageError();
68
+ });
69
+ if (imageError || !item.src) {
70
+ return /* @__PURE__ */ React.createElement(
71
+ "div",
72
+ {
73
+ "data-type": "image",
74
+ className: classNames(`${prefixCls2}-default-icon`, hashId2),
75
+ style: __spreadProps(__spreadValues({}, imageStyle2), {
76
+ display: "flex",
77
+ alignItems: "center",
78
+ justifyContent: "center",
79
+ backgroundColor: "#f5f5f5",
80
+ border: "1px solid #d9d9d9",
81
+ borderRadius: shape2 === "circle" ? "50%" : "4px"
82
+ })
83
+ },
84
+ /* @__PURE__ */ React.createElement(SquareArrowUpRight, null)
85
+ );
86
+ }
87
+ return /* @__PURE__ */ React.createElement(
88
+ "img",
89
+ {
90
+ src: item.src,
91
+ alt: item.alt || item.title || "",
92
+ title: item.title,
93
+ className: classNames(`${prefixCls2}-image`, hashId2),
94
+ style: imageStyle2,
95
+ onError: handleImageError
96
+ }
97
+ );
98
+ });
99
+ const defaultRenderItem = useRefFunction(
100
+ (item, index) => {
101
+ const itemClassNames = [
102
+ `${prefixCls}-item`,
103
+ shape === "circle" ? `${prefixCls}-item-circle` : "",
104
+ hashId
105
+ ].filter(Boolean).join(" ");
106
+ return /* @__PURE__ */ React.createElement("li", { key: item.id || index, className: itemClassNames, style: itemStyle }, item.href ? /* @__PURE__ */ React.createElement(
107
+ "a",
108
+ {
109
+ href: item.href,
110
+ className: classNames(`${prefixCls}-link`, hashId),
111
+ style: linkStyle
112
+ },
113
+ /* @__PURE__ */ React.createElement(
114
+ ImageComponent,
115
+ {
116
+ item,
117
+ prefixCls,
118
+ hashId,
119
+ shape,
120
+ imageStyle,
121
+ onImageError: () => {
122
+ }
123
+ }
124
+ )
125
+ ) : /* @__PURE__ */ React.createElement(
126
+ ImageComponent,
127
+ {
128
+ item,
129
+ prefixCls,
130
+ hashId,
131
+ shape,
132
+ imageStyle,
133
+ onImageError: () => {
134
+ }
135
+ }
136
+ ));
137
+ }
138
+ );
139
+ const listItems = useMemo(() => {
140
+ return displayList.map((item, index) => {
141
+ if (renderItem) {
142
+ return renderItem(item, index);
143
+ }
144
+ return defaultRenderItem(item, index);
145
+ });
146
+ }, [displayList, renderItem, defaultRenderItem]);
44
147
  if (loading) {
45
148
  return wrapSSR(
46
149
  /* @__PURE__ */ React.createElement(
@@ -58,7 +161,6 @@ var VisualList = ({
58
161
  )
59
162
  );
60
163
  }
61
- const displayList = data.filter(filter);
62
164
  if (displayList.length === 0) {
63
165
  return wrapSSR(
64
166
  /* @__PURE__ */ React.createElement(
@@ -76,76 +178,11 @@ var VisualList = ({
76
178
  )
77
179
  );
78
180
  }
79
- const defaultRenderItem = (item, index) => {
80
- const itemClassNames = [
81
- `${prefixCls}-item`,
82
- shape === "circle" ? `${prefixCls}-item-circle` : "",
83
- hashId
84
- ].filter(Boolean).join(" ");
85
- const ImageComponent = () => {
86
- const [imageError, setImageError] = useState(false);
87
- const handleImageError = () => {
88
- setImageError(true);
89
- };
90
- if (imageError || !item.src) {
91
- return /* @__PURE__ */ React.createElement(
92
- "div",
93
- {
94
- "data-type": "image",
95
- className: classNames(`${prefixCls}-default-icon`, hashId),
96
- style: __spreadProps(__spreadValues({}, imageStyle), {
97
- display: "flex",
98
- alignItems: "center",
99
- justifyContent: "center",
100
- backgroundColor: "#f5f5f5",
101
- border: "1px solid #d9d9d9",
102
- borderRadius: "4px"
103
- })
104
- },
105
- /* @__PURE__ */ React.createElement(SquareArrowUpRight, null)
106
- );
107
- }
108
- return /* @__PURE__ */ React.createElement(
109
- "img",
110
- {
111
- src: item.src,
112
- alt: item.alt || item.title || "",
113
- title: item.title,
114
- className: classNames(`${prefixCls}-image`, hashId),
115
- style: imageStyle,
116
- onError: handleImageError
117
- }
118
- );
119
- };
120
- return /* @__PURE__ */ React.createElement("li", { key: item.id || index, className: itemClassNames, style: itemStyle }, item.href ? /* @__PURE__ */ React.createElement(
121
- "a",
122
- {
123
- href: item.href,
124
- className: classNames(`${prefixCls}-link`, hashId),
125
- style: linkStyle
126
- },
127
- /* @__PURE__ */ React.createElement(ImageComponent, null)
128
- ) : /* @__PURE__ */ React.createElement(ImageComponent, null));
129
- };
130
- const containerClassName = classNames(
131
- `${prefixCls}-container`,
132
- hashId,
133
- {
134
- [`${prefixCls}-outline`]: variant === "outline",
135
- [`${prefixCls}-borderless`]: variant === "borderless",
136
- [`${prefixCls}-default`]: variant === "default"
137
- },
138
- className
139
- );
140
181
  return wrapSSR(
141
- /* @__PURE__ */ React.createElement("div", { className: containerClassName, style }, /* @__PURE__ */ React.createElement("ul", { className: classNames(prefixCls, hashId) }, displayList.map((item, index) => {
142
- if (renderItem) {
143
- return renderItem(item, index);
144
- }
145
- return defaultRenderItem(item, index);
146
- })), /* @__PURE__ */ React.createElement("div", { style: { width: 4 } }), description && /* @__PURE__ */ React.createElement("div", { className: classNames(`${prefixCls}-description`, hashId) }, description))
182
+ /* @__PURE__ */ React.createElement("div", { className: containerClassName, style }, /* @__PURE__ */ React.createElement("ul", { className: classNames(prefixCls, hashId) }, listItems), /* @__PURE__ */ React.createElement("div", { style: { width: 4 } }), description && /* @__PURE__ */ React.createElement("div", { className: classNames(`${prefixCls}-description`, hashId) }, description))
147
183
  );
148
184
  };
185
+ var VisualList = memo(VisualListComponent);
149
186
  export {
150
187
  VisualList
151
188
  };
@@ -391,7 +391,7 @@ var BarChart = ({
391
391
  if (!showDataLabels || calculateMaxLabelWidth === 0)
392
392
  return { top: 0, right: 0, bottom: 0, left: 0 };
393
393
  const basePadding = 8;
394
- const labelPadding = Math.ceil(calculateMaxLabelWidth);
394
+ const labelPadding = Math.ceil(calculateMaxLabelWidth) + 12;
395
395
  if (indexAxis === "y") {
396
396
  return {
397
397
  top: basePadding,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ant-design/agentic-ui",
3
- "version": "2.0.4",
3
+ "version": "2.0.6",
4
4
  "description": "面向智能体的 UI 组件库,提供多步推理可视化、工具调用展示、任务执行协同等 Agentic UI 能力",
5
5
  "repository": "git@github.com:ant-design/agentic-ui.git",
6
6
  "license": "MIT",