@ant-design/agentic-ui 2.29.25 → 2.29.27

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.
@@ -275,7 +275,7 @@ var shouldRenderBeforeContent = function shouldRenderBeforeContent(placement, ro
275
275
  var _React_useState = _sliced_to_array(React.useState(false), 2), hidePadding = _React_useState[0], setHidePadding = _React_useState[1];
276
276
  var getPrefixCls = useContext(ConfigProvider.ConfigContext).getPrefixCls;
277
277
  var context = useContext(BubbleConfigContext);
278
- var _ref = context || {}, compact = _ref.compact, standalone = _ref.standalone, locale = _ref.locale;
278
+ var _ref = context || {}, compact = _ref.compact, standalone = _ref.standalone;
279
279
  var prefixClass = getPrefixCls('agentic');
280
280
  var _useStyle = useStyle(prefixClass), wrapSSR = _useStyle.wrapSSR, hashId = _useStyle.hashId;
281
281
  var preMessageSameRole = isSameRoleAsPrevious(preMessage, originData);
@@ -356,7 +356,6 @@ var shouldRenderBeforeContent = function shouldRenderBeforeContent(placement, ro
356
356
  value: {
357
357
  compact: compact,
358
358
  standalone: !!standalone,
359
- locale: locale,
360
359
  bubble: props
361
360
  }
362
361
  }, /*#__PURE__*/ React.createElement(Flex, {
@@ -1,5 +1,4 @@
1
1
  import React from 'react';
2
- import { cnLabels } from '../I18n/locales';
3
2
  import { ThoughtChainListProps } from '../ThoughtChainList/types';
4
3
  import { BubbleProps } from './type';
5
4
  export type ChatConfigType = {
@@ -18,7 +17,6 @@ export type ChatConfigType = {
18
17
  */
19
18
  enable: boolean;
20
19
  };
21
- locale: Partial<typeof cnLabels>;
22
20
  bubble?: BubbleProps<{
23
21
  /**
24
22
  * 聊天内容
@@ -1,6 +1,4 @@
1
1
  import React from "react";
2
- import { cnLabels } from "../I18n/locales";
3
2
  export var BubbleConfigContext = /*#__PURE__*/ React.createContext({
4
- standalone: false,
5
- locale: cnLabels
3
+ standalone: false
6
4
  });
@@ -269,6 +269,7 @@ import { motion } from "framer-motion";
269
269
  import React, { useContext, useEffect, useMemo, useState } from "react";
270
270
  import { ActionIconBox } from "../../Components/ActionIconBox";
271
271
  import { Loading } from "../../Components/Loading";
272
+ import { useLocale } from "../../I18n";
272
273
  import { BubbleConfigContext } from "../BubbleConfigProvide";
273
274
  import { CopyButton } from "./CopyButton";
274
275
  import { VoiceButton } from "./VoiceButton";
@@ -303,9 +304,10 @@ import { VoiceButton } from "./VoiceButton";
303
304
  "pure",
304
305
  "placement"
305
306
  ]);
306
- var _originalData_extra, _originalData_extra1, _originalData_extra2, _originalData_extra3, _bubble_originData, _bubble_originData1, _props_rightRender, _context_locale;
307
+ var _originalData_extra, _originalData_extra1, _originalData_extra2, _originalData_extra3, _bubble_originData, _bubble_originData1, _props_rightRender;
307
308
  var getPrefixCls = useContext(ConfigProvider.ConfigContext).getPrefixCls;
308
309
  var context = useContext(BubbleConfigContext);
310
+ var locale = useLocale();
309
311
  var _useState = _sliced_to_array(useState(false), 2), feedbackLoading = _useState[0], setFeedbackLoading = _useState[1];
310
312
  // 获取聊天项的原始数据
311
313
  var originalData = bubble === null || bubble === void 0 ? void 0 : bubble.originData;
@@ -325,35 +327,30 @@ import { VoiceButton } from "./VoiceButton";
325
327
  if (alreadyFeedback && (originalData === null || originalData === void 0 ? void 0 : originalData.feedback) === 'thumbsUp') {
326
328
  // 已经点赞的情况
327
329
  if (props.onLikeCancel || props.onCancelLike) {
328
- var _context_locale;
329
- return (context === null || context === void 0 ? void 0 : (_context_locale = context.locale) === null || _context_locale === void 0 ? void 0 : _context_locale['chat.message.cancel-like']) || '取消点赞';
330
+ return (locale === null || locale === void 0 ? void 0 : locale['chat.message.cancel-like']) || '取消点赞';
330
331
  } else {
331
- var _context_locale1;
332
- return (context === null || context === void 0 ? void 0 : (_context_locale1 = context.locale) === null || _context_locale1 === void 0 ? void 0 : _context_locale1['chat.message.feedback-success']) || '已经反馈过了哦';
332
+ return (locale === null || locale === void 0 ? void 0 : locale['chat.message.feedback-success']) || '已经反馈过了哦';
333
333
  }
334
334
  } else {
335
- var _context_locale2;
336
335
  // 未点赞的情况
337
- return (context === null || context === void 0 ? void 0 : (_context_locale2 = context.locale) === null || _context_locale2 === void 0 ? void 0 : _context_locale2['chat.message.like']) || '喜欢';
336
+ return (locale === null || locale === void 0 ? void 0 : locale['chat.message.like']) || '喜欢';
338
337
  }
339
338
  }, [
340
339
  alreadyFeedback,
341
340
  originalData === null || originalData === void 0 ? void 0 : originalData.feedback,
342
341
  !!(props.onLikeCancel || props.onCancelLike),
343
- context === null || context === void 0 ? void 0 : context.locale
342
+ locale
344
343
  ]);
345
344
  // 获取点踩按钮的标题文本
346
345
  var getDislikeButtonTitle = useMemo(function() {
347
346
  if (alreadyFeedback) {
348
- var _context_locale;
349
- return (context === null || context === void 0 ? void 0 : (_context_locale = context.locale) === null || _context_locale === void 0 ? void 0 : _context_locale['chat.message.feedback-success']) || '已经反馈过了哦';
347
+ return (locale === null || locale === void 0 ? void 0 : locale['chat.message.feedback-success']) || '已经反馈过了哦';
350
348
  } else {
351
- var _context_locale1;
352
- return (context === null || context === void 0 ? void 0 : (_context_locale1 = context.locale) === null || _context_locale1 === void 0 ? void 0 : _context_locale1['chat.message.dislike']) || '不喜欢';
349
+ return (locale === null || locale === void 0 ? void 0 : locale['chat.message.dislike']) || '不喜欢';
353
350
  }
354
351
  }, [
355
352
  alreadyFeedback,
356
- context === null || context === void 0 ? void 0 : context.locale
353
+ locale
357
354
  ]);
358
355
  var typing = (originalData === null || originalData === void 0 ? void 0 : originalData.isAborted) !== true && (originalData === null || originalData === void 0 ? void 0 : originalData.isFinished) === false && (originalData === null || originalData === void 0 ? void 0 : (_originalData_extra2 = originalData.extra) === null || _originalData_extra2 === void 0 ? void 0 : _originalData_extra2.isHistory) === undefined && (originalData === null || originalData === void 0 ? void 0 : originalData.isFinished) !== undefined;
359
356
  var like = useMemo(function() {
@@ -551,8 +548,8 @@ import { VoiceButton } from "./VoiceButton";
551
548
  * @constant
552
549
  * @type {boolean}
553
550
  */ var shouldShowCopy = useMemo(function() {
554
- var _originalData_extra, _context_locale;
555
- var defaultConditions = (originalData === null || originalData === void 0 ? void 0 : originalData.content) && !(originalData === null || originalData === void 0 ? void 0 : (_originalData_extra = originalData.extra) === null || _originalData_extra === void 0 ? void 0 : _originalData_extra.answerStatus) && (originalData === null || originalData === void 0 ? void 0 : originalData.content) !== ((context === null || context === void 0 ? void 0 : (_context_locale = context.locale) === null || _context_locale === void 0 ? void 0 : _context_locale['chat.message.aborted']) || '回答已停止生成');
551
+ var _originalData_extra;
552
+ var defaultConditions = (originalData === null || originalData === void 0 ? void 0 : originalData.content) && !(originalData === null || originalData === void 0 ? void 0 : (_originalData_extra = originalData.extra) === null || _originalData_extra === void 0 ? void 0 : _originalData_extra.answerStatus) && (originalData === null || originalData === void 0 ? void 0 : originalData.content) !== ((locale === null || locale === void 0 ? void 0 : locale['chat.message.aborted']) || '回答已停止生成');
556
553
  if (!defaultConditions) {
557
554
  return false;
558
555
  }
@@ -567,13 +564,12 @@ import { VoiceButton } from "./VoiceButton";
567
564
  bubble,
568
565
  originalData === null || originalData === void 0 ? void 0 : originalData.content,
569
566
  originalData === null || originalData === void 0 ? void 0 : (_originalData_extra3 = originalData.extra) === null || _originalData_extra3 === void 0 ? void 0 : _originalData_extra3.answerStatus,
570
- context === null || context === void 0 ? void 0 : context.locale
567
+ locale
571
568
  ]);
572
569
  var copyDom = useMemo(function() {
573
- var _context_locale;
574
570
  return shouldShowCopy ? /*#__PURE__*/ React.createElement(CopyButton, {
575
571
  "data-testid": "chat-item-copy-button",
576
- title: (context === null || context === void 0 ? void 0 : (_context_locale = context.locale) === null || _context_locale === void 0 ? void 0 : _context_locale['chat.message.copy']) || '复制',
572
+ title: (locale === null || locale === void 0 ? void 0 : locale['chat.message.copy']) || '复制',
577
573
  onClick: function onClick() {
578
574
  try {
579
575
  var _bubble_originData;
@@ -591,11 +587,11 @@ import { VoiceButton } from "./VoiceButton";
591
587
  }) : null;
592
588
  }, [
593
589
  shouldShowCopy,
594
- context === null || context === void 0 ? void 0 : context.locale,
590
+ locale,
595
591
  (_bubble_originData = bubble.originData) === null || _bubble_originData === void 0 ? void 0 : _bubble_originData.content
596
592
  ]);
597
593
  var voiceDom = useMemo(function() {
598
- var _originalData_extra, _context_locale, _bubble_originData;
594
+ var _originalData_extra, _bubble_originData;
599
595
  /**
600
596
  * 判断是否应该显示语音选项。
601
597
  *
@@ -604,7 +600,7 @@ import { VoiceButton } from "./VoiceButton";
604
600
  * - 聊天项的原始数据包含内容
605
601
  * - 聊天项的原始数据在额外字段中没有回答状态
606
602
  * - 聊天项的内容不等于本地化的 'chat.message.aborted' 消息或其默认值 '回答已停止生成'
607
- * */ var defaultShow = !!(originalData === null || originalData === void 0 ? void 0 : originalData.content) && !(originalData === null || originalData === void 0 ? void 0 : (_originalData_extra = originalData.extra) === null || _originalData_extra === void 0 ? void 0 : _originalData_extra.answerStatus) && !typing && (originalData === null || originalData === void 0 ? void 0 : originalData.content) !== ((context === null || context === void 0 ? void 0 : (_context_locale = context.locale) === null || _context_locale === void 0 ? void 0 : _context_locale['chat.message.aborted']) || '回答已停止生成');
603
+ * */ var defaultShow = !!(originalData === null || originalData === void 0 ? void 0 : originalData.content) && !(originalData === null || originalData === void 0 ? void 0 : (_originalData_extra = originalData.extra) === null || _originalData_extra === void 0 ? void 0 : _originalData_extra.answerStatus) && !typing && (originalData === null || originalData === void 0 ? void 0 : originalData.content) !== ((locale === null || locale === void 0 ? void 0 : locale['chat.message.aborted']) || '回答已停止生成');
608
604
  if (!props.shouldShowVoice || !defaultShow) return null;
609
605
  return /*#__PURE__*/ React.createElement(VoiceButton, {
610
606
  text: ((_bubble_originData = bubble.originData) === null || _bubble_originData === void 0 ? void 0 : _bubble_originData.content) || '',
@@ -663,11 +659,10 @@ import { VoiceButton } from "./VoiceButton";
663
659
  prefixCls
664
660
  ]);
665
661
  var reSend = useMemo(function() {
666
- var _originalData_extra_preMessage, _originalData_extra, _context_locale;
662
+ var _originalData_extra_preMessage, _originalData_extra;
667
663
  console.log('originalData?.isAborted', originalData, typing);
668
664
  if ((originalData === null || originalData === void 0 ? void 0 : originalData.isAborted) && !originalData.isFinished) {
669
- var _context_locale1;
670
- return /*#__PURE__*/ React.createElement("span", null, (context === null || context === void 0 ? void 0 : (_context_locale1 = context.locale) === null || _context_locale1 === void 0 ? void 0 : _context_locale1['chat.message.aborted']) || '回答已停止生成');
665
+ return /*#__PURE__*/ React.createElement("span", null, (locale === null || locale === void 0 ? void 0 : locale['chat.message.aborted']) || '回答已停止生成');
671
666
  }
672
667
  if (!(originalData === null || originalData === void 0 ? void 0 : (_originalData_extra = originalData.extra) === null || _originalData_extra === void 0 ? void 0 : (_originalData_extra_preMessage = _originalData_extra.preMessage) === null || _originalData_extra_preMessage === void 0 ? void 0 : _originalData_extra_preMessage.content)) return null;
673
668
  if (typing) return null;
@@ -676,29 +671,29 @@ import { VoiceButton } from "./VoiceButton";
676
671
  borderLess: true,
677
672
  onClick: function onClick() {
678
673
  return _async_to_generator(function() {
679
- var _bubble_originData_extra_preMessage, _bubble_originData_extra, _bubble_originData, _context_locale;
674
+ var _bubble_originData_extra_preMessage, _bubble_originData_extra, _bubble_originData;
680
675
  return _ts_generator(this, function(_state) {
681
- onReply === null || onReply === void 0 ? void 0 : onReply(((_bubble_originData = bubble.originData) === null || _bubble_originData === void 0 ? void 0 : (_bubble_originData_extra = _bubble_originData.extra) === null || _bubble_originData_extra === void 0 ? void 0 : (_bubble_originData_extra_preMessage = _bubble_originData_extra.preMessage) === null || _bubble_originData_extra_preMessage === void 0 ? void 0 : _bubble_originData_extra_preMessage.content) || (context === null || context === void 0 ? void 0 : (_context_locale = context.locale) === null || _context_locale === void 0 ? void 0 : _context_locale['chat.message.retrySend']) || '重新生成');
676
+ onReply === null || onReply === void 0 ? void 0 : onReply(((_bubble_originData = bubble.originData) === null || _bubble_originData === void 0 ? void 0 : (_bubble_originData_extra = _bubble_originData.extra) === null || _bubble_originData_extra === void 0 ? void 0 : (_bubble_originData_extra_preMessage = _bubble_originData_extra.preMessage) === null || _bubble_originData_extra_preMessage === void 0 ? void 0 : _bubble_originData_extra_preMessage.content) || (locale === null || locale === void 0 ? void 0 : locale['chat.message.retrySend']) || '重新生成');
682
677
  return [
683
678
  2
684
679
  ];
685
680
  });
686
681
  })();
687
682
  },
688
- title: (context === null || context === void 0 ? void 0 : (_context_locale = context.locale) === null || _context_locale === void 0 ? void 0 : _context_locale['chat.message.retrySend']) || '重新生成'
683
+ title: (locale === null || locale === void 0 ? void 0 : locale['chat.message.retrySend']) || '重新生成'
689
684
  }, function(isHovered) {
690
- var _context_locale;
691
685
  return /*#__PURE__*/ React.createElement("div", {
692
686
  className: classNames("".concat(chatCls, "-messages-content-retry")),
693
687
  "data-messages-content-retry": true
694
688
  }, /*#__PURE__*/ React.createElement(RefreshLottie, {
695
689
  active: isHovered
696
- }), /*#__PURE__*/ React.createElement("span", null, (context === null || context === void 0 ? void 0 : (_context_locale = context.locale) === null || _context_locale === void 0 ? void 0 : _context_locale['chat.message.retrySend']) || '重新生成'));
690
+ }), /*#__PURE__*/ React.createElement("span", null, (locale === null || locale === void 0 ? void 0 : locale['chat.message.retrySend']) || '重新生成'));
697
691
  });
698
692
  }, [
699
693
  originalData === null || originalData === void 0 ? void 0 : originalData.isAborted,
700
694
  typing,
701
- originalData === null || originalData === void 0 ? void 0 : originalData.isFinished
695
+ originalData === null || originalData === void 0 ? void 0 : originalData.isFinished,
696
+ locale
702
697
  ]);
703
698
  useEffect(function() {
704
699
  var _props_onRenderExtraNull;
@@ -758,5 +753,5 @@ import { VoiceButton } from "./VoiceButton";
758
753
  style: {
759
754
  fontSize: (context === null || context === void 0 ? void 0 : context.compact) ? 20 : 16
760
755
  }
761
- }), /*#__PURE__*/ React.createElement("span", null, (context === null || context === void 0 ? void 0 : (_context_locale = context.locale) === null || _context_locale === void 0 ? void 0 : _context_locale['chat.message.generating']) || '')) : null, reSend || null, (originalData === null || originalData === void 0 ? void 0 : originalData.isAborted) ? copyDom : rightDom);
756
+ }), /*#__PURE__*/ React.createElement("span", null, (locale === null || locale === void 0 ? void 0 : locale['chat.message.generating']) || '')) : null, reSend || null, (originalData === null || originalData === void 0 ? void 0 : originalData.isAborted) ? copyDom : rightDom);
762
757
  };
@@ -214,13 +214,13 @@ function _ts_generator(thisArg, body) {
214
214
  };
215
215
  }
216
216
  }
217
- import { memo, useContext } from "react";
217
+ import { memo } from "react";
218
218
  import { CheckCircleFilled } from "@ant-design/icons";
219
219
  import { isFunction } from "lodash-es";
220
220
  import React from "react";
221
221
  import { ActionIconBox } from "../../../Components/ActionIconBox";
222
222
  import { useCopied } from "../../../Hooks/useCopied";
223
- import { BubbleConfigContext } from "../../BubbleConfigProvide";
223
+ import { useLocale } from "../../../I18n";
224
224
  /**
225
225
  * CopyIcon 组件 - 复制图标组件
226
226
  *
@@ -309,10 +309,9 @@ import { BubbleConfigContext } from "../../BubbleConfigProvide";
309
309
  "onClick",
310
310
  'data-testid'
311
311
  ]);
312
- var _context_locale;
313
312
  var _useCopied = useCopied(), copied = _useCopied.copied, setCopied = _useCopied.setCopied;
314
- var context = useContext(BubbleConfigContext);
315
- var copySuccessText = (context === null || context === void 0 ? void 0 : (_context_locale = context.locale) === null || _context_locale === void 0 ? void 0 : _context_locale['chat.message.copy.success']) || '复制成功';
313
+ var locale = useLocale();
314
+ var copySuccessText = (locale === null || locale === void 0 ? void 0 : locale['chat.message.copy.success']) || '复制成功';
316
315
  return /*#__PURE__*/ React.createElement(ActionIconBox, _object_spread_props(_object_spread({
317
316
  onClick: function onClick1(e) {
318
317
  return _async_to_generator(function() {
@@ -54,6 +54,7 @@ import { Popover, theme } from "antd";
54
54
  import React, { useContext, useEffect, useMemo } from "react";
55
55
  import { ErrorBoundary } from "react-error-boundary";
56
56
  import { MarkdownEditor, parserMdToSchema } from "../..";
57
+ import { useLocale } from "../../I18n";
57
58
  import { BubbleConfigContext } from "../BubbleConfigProvide";
58
59
  import { MessagesContext } from "./BubbleContext";
59
60
  /**
@@ -96,7 +97,9 @@ import { MessagesContext } from "./BubbleContext";
96
97
  var content = props.content, extra = props.extra, typing = props.typing, htmlRef = props.htmlRef, fncProps = props.fncProps, docListNode = props.docListNode, beforeContent = props.beforeContent, afterContent = props.afterContent;
97
98
  var MarkdownEditorRef = React.useRef(undefined);
98
99
  var hidePadding = (useContext(MessagesContext) || {}).hidePadding;
99
- var _ref = useContext(BubbleConfigContext) || {}, locale = _ref.locale, standalone = _ref.standalone;
100
+ var config = useContext(BubbleConfigContext);
101
+ var locale = useLocale();
102
+ var standalone = config === null || config === void 0 ? void 0 : config.standalone;
100
103
  var token = theme.useToken().token;
101
104
  var isPaddingHidden = useMemo(function() {
102
105
  return !!extra;
@@ -279,7 +279,7 @@ export var PureBubble = /*#__PURE__*/ memo(function(props) {
279
279
  var _React_useState = _sliced_to_array(React.useState(false), 2), hidePadding = _React_useState[0], setHidePadding = _React_useState[1];
280
280
  var getPrefixCls = useContext(ConfigProvider.ConfigContext).getPrefixCls;
281
281
  var context = useContext(BubbleConfigContext);
282
- var _ref1 = context || {}, compact = _ref1.compact, standalone = _ref1.standalone, locale = _ref1.locale;
282
+ var _ref1 = context || {}, compact = _ref1.compact, standalone = _ref1.standalone;
283
283
  var prefixClass = getPrefixCls('agentic');
284
284
  var _useStyle = useStyle(prefixClass), wrapSSR = _useStyle.wrapSSR, hashId = _useStyle.hashId;
285
285
  var placement = (_props_placement = props.placement) !== null && _props_placement !== void 0 ? _props_placement : 'left';
@@ -452,7 +452,6 @@ export var PureBubble = /*#__PURE__*/ memo(function(props) {
452
452
  value: {
453
453
  compact: compact,
454
454
  standalone: !!standalone,
455
- locale: locale,
456
455
  bubble: props
457
456
  }
458
457
  }, /*#__PURE__*/ React.createElement(Flex, {
@@ -128,7 +128,7 @@ var getContentStyle = function getContentStyle(standalone, customStyle) {
128
128
  var _React_useState = _sliced_to_array(React.useState(false), 2), hidePadding = _React_useState[0], setHidePadding = _React_useState[1];
129
129
  var getPrefixCls = useContext(ConfigProvider.ConfigContext).getPrefixCls;
130
130
  var context = useContext(BubbleConfigContext);
131
- var _ref = context || {}, compact = _ref.compact, standalone = _ref.standalone, locale = _ref.locale;
131
+ var _ref = context || {}, compact = _ref.compact, standalone = _ref.standalone;
132
132
  var prefixClass = getPrefixCls('agentic');
133
133
  var _useStyle = useStyle(prefixClass, classNames), wrapSSR = _useStyle.wrapSSR, hashId = _useStyle.hashId;
134
134
  var time = (originData === null || originData === void 0 ? void 0 : originData.createAt) || props.time;
@@ -180,7 +180,6 @@ var getContentStyle = function getContentStyle(standalone, customStyle) {
180
180
  value: {
181
181
  compact: compact,
182
182
  standalone: !!standalone,
183
- locale: locale,
184
183
  bubble: props
185
184
  }
186
185
  }, /*#__PURE__*/ React.createElement(Flex, {
@@ -131,7 +131,7 @@ import { ConfigProvider, Popover } from "antd";
131
131
  import classNames from "clsx";
132
132
  import React, { memo, useContext, useMemo, useRef } from "react";
133
133
  import useClickAway from "../Hooks/useClickAway";
134
- import { ActionIconBox, BubbleConfigContext } from "../index";
134
+ import { ActionIconBox, I18nContext } from "../index";
135
135
  import { HistoryEmpty, HistoryLoadMore, HistoryNewChat, HistorySearch, generateHistoryItems } from "./components";
136
136
  import { useHistory } from "./hooks/useHistory";
137
137
  import GroupMenu from "./menu";
@@ -175,7 +175,7 @@ export * from "./utils";
175
175
  var _props_agent, _props_agent1, _props_agent2;
176
176
  var getPrefixCls = useContext(ConfigProvider.ConfigContext).getPrefixCls;
177
177
  var menuPrefixCls = getPrefixCls('agentic-chat-history-menu');
178
- var locale = (useContext(BubbleConfigContext) || {}).locale;
178
+ var locale = useContext(I18nContext).locale;
179
179
  var containerRef = useRef(null);
180
180
  // 注册样式
181
181
  var _useStyle = useStyle(menuPrefixCls), wrapSSR = _useStyle.wrapSSR, hashId = _useStyle.hashId;
@@ -24,6 +24,7 @@ export declare function saveUserLanguage(language: 'zh-CN' | 'en-US'): void;
24
24
  * 国际化上下文
25
25
  *
26
26
  * 提供国际化功能的React Context,包含当前语言环境和设置语言的方法。
27
+ * 所有国际化文案应统一通过 I18nContext 获取,保证单一数据源。
27
28
  */
28
29
  export declare const I18nContext: React.Context<{
29
30
  locale: LocalKeys;
@@ -31,6 +32,15 @@ export declare const I18nContext: React.Context<{
31
32
  setLanguage?: ((language: 'zh-CN' | 'en-US') => void) | undefined;
32
33
  setLocale?: ((locale: LocalKeys) => void) | undefined;
33
34
  }>;
35
+ /**
36
+ * 从 I18nContext 获取当前 locale,国际化统一入口
37
+ */
38
+ export declare function useLocale(): LocalKeys;
39
+ /**
40
+ * 获取合并后的 locale:以 I18nContext 为基准,用 override 覆盖部分 key
41
+ * 用于 Bubble 等支持 config 级文案覆盖的场景,仍以 I18nContext 为主
42
+ */
43
+ export declare function useMergedLocale(override?: Partial<LocalKeys>): LocalKeys;
34
44
  /**
35
45
  * I18nProvide 组件 - 国际化提供者组件
36
46
  *
@@ -6,6 +6,19 @@ function _array_like_to_array(arr, len) {
6
6
  function _array_with_holes(arr) {
7
7
  if (Array.isArray(arr)) return arr;
8
8
  }
9
+ function _define_property(obj, key, value) {
10
+ if (key in obj) {
11
+ Object.defineProperty(obj, key, {
12
+ value: value,
13
+ enumerable: true,
14
+ configurable: true,
15
+ writable: true
16
+ });
17
+ } else {
18
+ obj[key] = value;
19
+ }
20
+ return obj;
21
+ }
9
22
  function _iterable_to_array_limit(arr, i) {
10
23
  var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
11
24
  if (_i == null) return;
@@ -33,6 +46,21 @@ function _iterable_to_array_limit(arr, i) {
33
46
  function _non_iterable_rest() {
34
47
  throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
35
48
  }
49
+ function _object_spread(target) {
50
+ for(var i = 1; i < arguments.length; i++){
51
+ var source = arguments[i] != null ? arguments[i] : {};
52
+ var ownKeys = Object.keys(source);
53
+ if (typeof Object.getOwnPropertySymbols === "function") {
54
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
55
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
56
+ }));
57
+ }
58
+ ownKeys.forEach(function(key) {
59
+ _define_property(target, key, source[key]);
60
+ });
61
+ }
62
+ return target;
63
+ }
36
64
  function _sliced_to_array(arr, i) {
37
65
  return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
38
66
  }
@@ -133,10 +161,28 @@ export { cnLabels, enLabels };
133
161
  * 国际化上下文
134
162
  *
135
163
  * 提供国际化功能的React Context,包含当前语言环境和设置语言的方法。
164
+ * 所有国际化文案应统一通过 I18nContext 获取,保证单一数据源。
136
165
  */ export var I18nContext = /*#__PURE__*/ React.createContext({
137
166
  locale: cnLabels,
138
167
  language: 'zh-CN'
139
168
  });
169
+ /**
170
+ * 从 I18nContext 获取当前 locale,国际化统一入口
171
+ */ export function useLocale() {
172
+ return useContext(I18nContext).locale;
173
+ }
174
+ /**
175
+ * 获取合并后的 locale:以 I18nContext 为基准,用 override 覆盖部分 key
176
+ * 用于 Bubble 等支持 config 级文案覆盖的场景,仍以 I18nContext 为主
177
+ */ export function useMergedLocale(override) {
178
+ var locale = useContext(I18nContext).locale;
179
+ return useMemo(function() {
180
+ return override ? _object_spread({}, locale, override) : locale;
181
+ }, [
182
+ locale,
183
+ override
184
+ ]);
185
+ }
140
186
  /**
141
187
  * I18nProvide 组件 - 国际化提供者组件
142
188
  *
@@ -101,7 +101,7 @@ import { Plus } from "@sofa-design/icons";
101
101
  import { Button, Card, Form, Input, InputNumber, Select, Space } from "antd";
102
102
  import { merge } from "lodash-es";
103
103
  import React, { memo, useCallback, useContext, useEffect, useMemo } from "react";
104
- import { I18nContext, cnLabels } from "../../I18n";
104
+ import { I18nContext } from "../../I18n";
105
105
  /**
106
106
  * SchemaForm 组件 - 基于Schema的表单组件
107
107
  *
@@ -156,7 +156,7 @@ import { I18nContext, cnLabels } from "../../I18n";
156
156
  var schema = param.schema, onValuesChange = param.onValuesChange, initialValues = param.initialValues, _param_readonly = param.readonly, readonly = _param_readonly === void 0 ? false : _param_readonly;
157
157
  var _Form_useForm = _sliced_to_array(Form.useForm(), 1), form = _Form_useForm[0];
158
158
  var _ref = (schema === null || schema === void 0 ? void 0 : schema.component) || {}, _ref_properties = _ref.properties, properties = _ref_properties === void 0 ? {} : _ref_properties;
159
- var _useContext = useContext(I18nContext), _useContext_locale = _useContext.locale, locale = _useContext_locale === void 0 ? cnLabels : _useContext_locale;
159
+ var locale = useContext(I18nContext).locale;
160
160
  // 生成表单验证规则
161
161
  var generateRules = useCallback(function(property) {
162
162
  var rules = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ant-design/agentic-ui",
3
- "version": "2.29.25",
3
+ "version": "2.29.27",
4
4
  "description": "面向智能体的 UI 组件库,提供多步推理可视化、工具调用展示、任务执行协同等 Agentic UI 能力",
5
5
  "repository": "git@github.com:ant-design/agentic-ui.git",
6
6
  "license": "MIT",
@@ -150,6 +150,7 @@
150
150
  "@vitejs/plugin-react": "^4.7.0",
151
151
  "@vitest/coverage-istanbul": "^2.1.9",
152
152
  "@vitest/ui": "2.1.9",
153
+ "cross-env": "^7.0.3",
153
154
  "dumi": "^2.4.21",
154
155
  "dumi-theme-antd-style": "^0.31.1",
155
156
  "eslint": "^8.57.1",
@@ -172,7 +173,6 @@
172
173
  "sast": "^0.8.1",
173
174
  "stylelint": "^14.16.1",
174
175
  "typescript": "^5.9.3",
175
- "cross-env": "^7.0.3",
176
176
  "vitest": "^2.1.9"
177
177
  },
178
178
  "peerDependencies": {