@ant-design/agentic-ui 2.22.0 → 2.23.0

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.
@@ -71,15 +71,15 @@ var canRenderThoughtChain = function(placement, role, thoughtChainEnabled) {
71
71
  if (thoughtChainEnabled === false) return false;
72
72
  return true;
73
73
  };
74
- /**
75
- * BubbleBeforeNode 组件
76
- *
77
- * 在聊天气泡之前渲染思维链或任务列表,显示AI的思考过程
78
- *
79
- * @example
80
- * ```tsx
81
- * <BubbleBeforeNode bubble={bubbleData} />
82
- * ```
74
+ /**
75
+ * BubbleBeforeNode 组件
76
+ *
77
+ * 在聊天气泡之前渲染思维链或任务列表,显示AI的思考过程
78
+ *
79
+ * @example
80
+ * ```tsx
81
+ * <BubbleBeforeNode bubble={bubbleData} />
82
+ * ```
83
83
  */ export var BubbleBeforeNode = function(param) {
84
84
  var bubble = param.bubble, className = param.className, style = param.style;
85
85
  var _context_thoughtChain, _originData_extra, _context_thoughtChain1, _context_thoughtChain2;
@@ -1165,12 +1165,23 @@ var defaultAllowedTypes = [
1165
1165
  return decorateList;
1166
1166
  }
1167
1167
  };
1168
+ // 在 SSR 环境下,如果有 initSchemaValue,直接使用它作为初始值
1169
+ // 因为 useEffect 在 SSR 环境下不会执行,initialNote 不会被调用
1170
+ var initialValue = useMemo(function() {
1171
+ var _props_initSchemaValue;
1172
+ if ((_props_initSchemaValue = props.initSchemaValue) === null || _props_initSchemaValue === void 0 ? void 0 : _props_initSchemaValue.length) {
1173
+ return props.initSchemaValue;
1174
+ }
1175
+ return [
1176
+ EditorUtils.p
1177
+ ];
1178
+ }, [
1179
+ props.initSchemaValue
1180
+ ]);
1168
1181
  var _obj;
1169
1182
  return wrapSSR(/*#__PURE__*/ React.createElement(React.Fragment, null, /*#__PURE__*/ React.createElement(Slate, {
1170
1183
  editor: markdownEditorRef.current,
1171
- initialValue: [
1172
- EditorUtils.p
1173
- ],
1184
+ initialValue: initialValue,
1174
1185
  onChange: onSlateChange
1175
1186
  }, /*#__PURE__*/ React.createElement(Editable, {
1176
1187
  decorate: decorateFn,
@@ -13,9 +13,10 @@ export type LanguageHandler = (element: CodeElement, value: string) => CodeEleme
13
13
  /**
14
14
  * 处理代码块节点
15
15
  * @param currentElement - 当前处理的代码块元素,包含语言和内容
16
+ * @param config - 可选的配置对象,可能包含从 HTML 注释中解析的属性
16
17
  * @returns 返回格式化的代码块节点对象,根据语言类型进行特殊处理
17
18
  */
18
- export declare const handleCode: (currentElement: any) => CodeElement;
19
+ export declare const handleCode: (currentElement: any, config?: any) => CodeElement;
19
20
  /**
20
21
  * 处理YAML节点
21
22
  * @param currentElement - 当前处理的YAML元素
@@ -101,11 +101,16 @@ var ENDING_NEWLINE = /\n$/;
101
101
  /**
102
102
  * 处理代码块节点
103
103
  * @param currentElement - 当前处理的代码块元素,包含语言和内容
104
+ * @param config - 可选的配置对象,可能包含从 HTML 注释中解析的属性
104
105
  * @returns 返回格式化的代码块节点对象,根据语言类型进行特殊处理
105
- */ export var handleCode = function(currentElement) {
106
- var _match, _currentElement_otherProps, _currentElement_value_trim;
106
+ */ export var handleCode = function(currentElement, config) {
107
+ var _effectiveLang_match, _currentElement_otherProps, _currentElement_value_trim;
107
108
  var rawValue = currentElement.value || '';
108
- var langString = ((_match = (currentElement.lang || '').match(NOT_SPACE_START)) === null || _match === void 0 ? void 0 : _match[0]) || '';
109
+ // 如果 config 中包含 data-language,优先使用它来恢复语言类型
110
+ var configLanguage = config === null || config === void 0 ? void 0 : config['data-language'];
111
+ // 保持原有的行为:如果没有语言,应该使用 null 而不是空字符串
112
+ var effectiveLang = configLanguage || currentElement.lang || null;
113
+ var langString = effectiveLang ? ((_effectiveLang_match = effectiveLang.match(NOT_SPACE_START)) === null || _effectiveLang_match === void 0 ? void 0 : _effectiveLang_match[0]) || '' : '';
109
114
  var code = "".concat(rawValue.replace(ENDING_NEWLINE, ''), "\n");
110
115
  // 检查代码块是否完整
111
116
  // 如果是缩进代码块,认为是完整的(因为没有结束标记)
@@ -144,7 +149,7 @@ var ENDING_NEWLINE = /\n$/;
144
149
  }
145
150
  var baseCodeElement = {
146
151
  type: 'code',
147
- language: currentElement.lang === 'apaasify' ? 'apaasify' : currentElement.lang,
152
+ language: effectiveLang === 'apaasify' ? 'apaasify' : effectiveLang || null,
148
153
  render: currentElement.meta === 'render',
149
154
  value: currentElement.value,
150
155
  isConfig: currentElement === null || currentElement === void 0 ? void 0 : (_currentElement_value_trim = currentElement.value.trim()) === null || _currentElement_value_trim === void 0 ? void 0 : _currentElement_value_trim.startsWith('<!--'),
@@ -156,14 +161,16 @@ var ENDING_NEWLINE = /\n$/;
156
161
  // 添加流式状态支持
157
162
  otherProps: otherProps
158
163
  };
159
- var handler = LANGUAGE_HANDLERS[currentElement.lang];
164
+ var handler = LANGUAGE_HANDLERS[effectiveLang];
160
165
  var result = handler ? handler(baseCodeElement, currentElement.value) : baseCodeElement;
161
- // 确保 otherProps 被保留
166
+ // 确保 otherProps 被保留,并合并 config 中的属性
162
167
  var resultWithProps = result;
163
168
  if (baseCodeElement.otherProps && !resultWithProps.otherProps) {
164
- resultWithProps.otherProps = baseCodeElement.otherProps;
169
+ resultWithProps.otherProps = _object_spread({}, baseCodeElement.otherProps, config || {});
165
170
  } else if (baseCodeElement.otherProps && resultWithProps.otherProps) {
166
- resultWithProps.otherProps = _object_spread({}, resultWithProps.otherProps, baseCodeElement.otherProps);
171
+ resultWithProps.otherProps = _object_spread({}, resultWithProps.otherProps, baseCodeElement.otherProps, config || {});
172
+ } else if (config && Object.keys(config).length > 0) {
173
+ resultWithProps.otherProps = _object_spread({}, resultWithProps.otherProps || {}, config);
167
174
  }
168
175
  return resultWithProps;
169
176
  };
@@ -100,6 +100,10 @@ function _sliced_to_array(arr, i) {
100
100
  function _to_consumable_array(arr) {
101
101
  return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
102
102
  }
103
+ function _type_of(obj) {
104
+ "@swc/helpers - typeof";
105
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
106
+ }
103
107
  function _unsupported_iterable_to_array(o, minLen) {
104
108
  if (!o) return;
105
109
  if (typeof o === "string") return _array_like_to_array(o, minLen);
@@ -464,6 +468,24 @@ import partialJsonParse from "../json-parse";
464
468
  }
465
469
  var commentValue = isUnclosedComment ? processedValue : currentElement.value;
466
470
  var isComment = commentValue.trim().startsWith('<!--') && commentValue.trim().endsWith('-->');
471
+ // 检查是否是 otherProps 序列化生成的 JSON 注释
472
+ // 这些注释应该被跳过,不应该被解析为 HTML 代码块
473
+ if (isComment) {
474
+ try {
475
+ var commentContent = commentValue.replace('<!--', '').replace('-->', '').trim();
476
+ var parsed = JSON.parse(commentContent);
477
+ // 如果能够成功解析为 JSON 对象,且是对象类型(不是数组或基本类型),
478
+ // 则认为是 otherProps 序列化生成的注释,应该返回 null 或空文本
479
+ // 这些注释应该在 parserMarkdownToSlateNode 中被跳过
480
+ if ((typeof parsed === "undefined" ? "undefined" : _type_of(parsed)) === 'object' && parsed !== null && !Array.isArray(parsed)) {
481
+ return {
482
+ text: ''
483
+ };
484
+ }
485
+ } catch (e) {
486
+ // 解析失败,不是 JSON 格式的注释,继续正常处理
487
+ }
488
+ }
467
489
  if (isComment || isStandardHtmlElement(commentValue)) {
468
490
  return commentValue.match(/<\/?(table|div|ul|li|ol|p|strong)[^\n>]*?>/) ? htmlToFragmentList(commentValue, '') : {
469
491
  type: 'code',
@@ -62,6 +62,10 @@ function _object_spread(target) {
62
62
  function _to_consumable_array(arr) {
63
63
  return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
64
64
  }
65
+ function _type_of(obj) {
66
+ "@swc/helpers - typeof";
67
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
68
+ }
65
69
  function _unsupported_iterable_to_array(o, minLen) {
66
70
  if (!o) return;
67
71
  if (typeof o === "string") return _array_like_to_array(o, minLen);
@@ -137,10 +141,65 @@ import mdastParser from "./remarkParse";
137
141
  * - 插件未处理时,使用默认处理逻辑
138
142
  */ function parseNodes(nodes) {
139
143
  var _this, _loop = function(i) {
144
+ var _currentElement_value_trim, _currentElement_value, _currentElement_value_trim1, _currentElement_value1;
140
145
  var currentElement = nodes[i];
141
146
  var el = null;
142
147
  var pluginHandled = false;
143
- var config = (preElement === null || preElement === void 0 ? void 0 : preElement.type) === 'code' && (preElement === null || preElement === void 0 ? void 0 : preElement.language) === 'html' && (preElement === null || preElement === void 0 ? void 0 : preElement.otherProps) ? preElement === null || preElement === void 0 ? void 0 : preElement.otherProps : {};
148
+ // 检查当前元素是否是 HTML 注释
149
+ var isHtmlComment = currentElement.type === 'html' && ((_currentElement_value = currentElement.value) === null || _currentElement_value === void 0 ? void 0 : (_currentElement_value_trim = _currentElement_value.trim()) === null || _currentElement_value_trim === void 0 ? void 0 : _currentElement_value_trim.startsWith('<!--')) && ((_currentElement_value1 = currentElement.value) === null || _currentElement_value1 === void 0 ? void 0 : (_currentElement_value_trim1 = _currentElement_value1.trim()) === null || _currentElement_value_trim1 === void 0 ? void 0 : _currentElement_value_trim1.endsWith('-->'));
150
+ var htmlCommentProps = {};
151
+ var isOtherPropsComment = false;
152
+ if (isHtmlComment) {
153
+ try {
154
+ var commentContent = currentElement.value.replace('<!--', '').replace('-->', '').trim();
155
+ htmlCommentProps = JSON.parse(commentContent);
156
+ // 如果能够成功解析为 JSON 对象,且是对象类型(不是数组或基本类型)
157
+ if ((typeof htmlCommentProps === "undefined" ? "undefined" : _type_of(htmlCommentProps)) === 'object' && htmlCommentProps !== null && !Array.isArray(htmlCommentProps)) {
158
+ // 检查是否包含代码块的元数据属性(data-language、data-block、data-state)
159
+ // 这些属性表明这是代码块的 otherProps 序列化生成的注释
160
+ var hasCodeMetadataProps = htmlCommentProps['data-language'] || htmlCommentProps['data-block'] || htmlCommentProps['data-state'];
161
+ // 只有当包含代码块元数据属性时,才认为是 otherProps 注释
162
+ // 对齐注释(如 {"align":"center"})不包含这些属性,应该被保留
163
+ isOtherPropsComment = hasCodeMetadataProps;
164
+ }
165
+ } catch (e) {
166
+ // 解析失败,不是 JSON 格式的注释,可能是真正的 HTML 注释
167
+ isOtherPropsComment = false;
168
+ }
169
+ }
170
+ var nextElement = i + 1 < nodes.length ? nodes[i + 1] : null;
171
+ var isNextCodeBlock = (nextElement === null || nextElement === void 0 ? void 0 : nextElement.type) === 'code';
172
+ // 如果 HTML 注释是代码块的 otherProps 序列化生成的,应该跳过,避免被解析为独立的 HTML 代码节点
173
+ // 如果后面跟着代码块,存储注释属性供代码块使用
174
+ if (isHtmlComment && isOtherPropsComment) {
175
+ if (isNextCodeBlock) {
176
+ // 后面有代码块,存储属性供代码块使用
177
+ pendingHtmlCommentProps = htmlCommentProps;
178
+ }
179
+ // 无论后面是否有代码块,都跳过 HTML 注释,避免生成独立的 HTML 代码节点
180
+ return "continue";
181
+ }
182
+ // 确定要使用的 config:优先使用待处理的 HTML 注释属性,否则使用前一个 HTML 代码节点的属性
183
+ var config = pendingHtmlCommentProps ? pendingHtmlCommentProps : (preElement === null || preElement === void 0 ? void 0 : preElement.type) === 'code' && (preElement === null || preElement === void 0 ? void 0 : preElement.language) === 'html' && (preElement === null || preElement === void 0 ? void 0 : preElement.otherProps) ? preElement === null || preElement === void 0 ? void 0 : preElement.otherProps : {};
184
+ // 如果 HTML 注释不是代码块元数据注释,但包含 JSON 对象属性(如对齐注释),
185
+ // 应该跳过注释本身,但将属性应用到下一个元素
186
+ if (isHtmlComment && !isOtherPropsComment && htmlCommentProps && Object.keys(htmlCommentProps).length > 0) {
187
+ // 将对齐注释等非代码块元数据注释的属性存储到 contextProps 中,供下一个元素使用
188
+ contextProps = _object_spread({}, contextProps, htmlCommentProps);
189
+ // 同时将属性作为 config 传递,以便 applyContextPropsAndConfig 设置 otherProps
190
+ config = _object_spread({}, config, htmlCommentProps);
191
+ // 跳过 HTML 注释本身,避免生成独立的 HTML 代码节点
192
+ return "continue";
193
+ }
194
+ // 如果当前元素应该使用 contextProps 中的属性作为 config(用于设置 otherProps)
195
+ // 这主要针对对齐注释等场景,需要同时设置 contextProps 和 otherProps
196
+ if (contextProps && Object.keys(contextProps).length > 0) {
197
+ config = _object_spread({}, config, contextProps);
198
+ }
199
+ // 如果使用了待处理的 HTML 注释属性,清空它
200
+ if (pendingHtmlCommentProps && config === pendingHtmlCommentProps) {
201
+ pendingHtmlCommentProps = null;
202
+ }
144
203
  var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
145
204
  try {
146
205
  // 首先尝试使用插件处理,使用 this.plugins
@@ -222,6 +281,7 @@ import mdastParser from "./remarkParse";
222
281
  var preElement = null;
223
282
  var htmlTag = [];
224
283
  var contextProps = {};
284
+ var pendingHtmlCommentProps = null;
225
285
  for(var i = 0; i < nodes.length; i++)_this = this, _loop(i);
226
286
  return els;
227
287
  }
@@ -278,8 +338,8 @@ import mdastParser from "./remarkParse";
278
338
  }
279
339
  },
280
340
  code: {
281
- handler: function(el) {
282
- return handleCode(el);
341
+ handler: function(el, _plugins, config) {
342
+ return handleCode(el, config);
283
343
  }
284
344
  },
285
345
  yaml: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ant-design/agentic-ui",
3
- "version": "2.22.0",
3
+ "version": "2.23.0",
4
4
  "description": "面向智能体的 UI 组件库,提供多步推理可视化、工具调用展示、任务执行协同等 Agentic UI 能力",
5
5
  "repository": "git@github.com:ant-design/agentic-ui.git",
6
6
  "license": "MIT",