bhd-components 0.10.37 → 0.10.38

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.
@@ -58,6 +58,13 @@ function escapeHtml(str) {
58
58
  }
59
59
  return str;
60
60
  }
61
+ var pattern = /!\[.*?\]\((.*?)\)/;
62
+ var exactRegex = /class\s*=\s*["']think-block["']/;
63
+ // 去掉think
64
+ var replaceThinkAndYaml = function() {
65
+ var text = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : "";
66
+ return text.replace(/```(\s)?yaml(?:.|\n)*?```/ig, "").replace(/<thinking>([\s\S]*?)<\/thinking>/g, "").replace(RegExp('<div\\s+class="think-block">.*?<\\/div>', "gs"), "");
67
+ };
61
68
  mermaid.initialize({
62
69
  startOnLoad: false,
63
70
  theme: "default",
@@ -140,6 +147,7 @@ var CustomerService = function(props) {
140
147
  var getLisyFlagRef = useRef(0);
141
148
  var _useState36 = _sliced_to_array(useState(false), 2), showMemaid = _useState36[0], setShowMemaid = _useState36[1]; //是否显示mermaid弹窗
142
149
  var _useState37 = _sliced_to_array(useState(""), 2), memaidContent = _useState37[0], setMemaidContent = _useState37[1]; //mermaid内容
150
+ var shouqiTimer = useRef(null);
143
151
  var remarkable = new Remarkable({
144
152
  html: true,
145
153
  highlight: function highlight(str, lang) {
@@ -226,6 +234,7 @@ var CustomerService = function(props) {
226
234
  // //获取热门推荐
227
235
  // videoPageQuestiionsList(1);
228
236
  // }
237
+ console.log("initShowType", initShowType);
229
238
  setShowType(initShowType);
230
239
  }, [
231
240
  initShowType
@@ -1395,6 +1404,7 @@ var CustomerService = function(props) {
1395
1404
  //先请求问题列表
1396
1405
  videoPageQuestiionsList(3);
1397
1406
  }
1407
+ var hasYamlStarted = false;
1398
1408
  //使用fetchEventSource接收数据
1399
1409
  var eventSource = fetchEventSource("".concat(urllocation, "/chat-service/public/v1.0/chat-with-ai/messages"), {
1400
1410
  method: "POST",
@@ -1504,7 +1514,12 @@ var CustomerService = function(props) {
1504
1514
  //识别的内容
1505
1515
  // console.log("eventSource msg: ", event.data);
1506
1516
  var msg = JSON.parse(event.data);
1507
- if (msg.message) {}
1517
+ if (msg.message) {
1518
+ if (!hasYamlStarted && msg.message && /```\s*yaml/.test(content)) {
1519
+ hasYamlStarted = true;
1520
+ }
1521
+ msg.message = msg.message.replace(/<thinking>/g, '<div class="think-block">').replace(/<\/thinking>/g, "</div>\n");
1522
+ }
1508
1523
  finishedRef.current = false;
1509
1524
  setFinished(false);
1510
1525
  msgStreamingCountRef.current = msgStreamingCountRef.current + 1;
@@ -1521,6 +1536,20 @@ var CustomerService = function(props) {
1521
1536
  videoPageQuestiionsList(2);
1522
1537
  }
1523
1538
  testLabQuestion(JSON.parse(data).message, content, "");
1539
+ if (shouqiTimer.current) {
1540
+ clearTimeout(shouqiTimer.current);
1541
+ }
1542
+ shouqiTimer.current = setTimeout(function() {
1543
+ if ($(".think-block").last().css("display") === "block") {
1544
+ clearTimeout(shouqiTimer.current);
1545
+ $(".think-block").last().parent().find(".think-block").css({
1546
+ display: "none"
1547
+ });
1548
+ $(".think-block").last().parent().parent().find("i").css({
1549
+ transform: "rotate(180deg)"
1550
+ });
1551
+ }
1552
+ }, 1000);
1524
1553
  } else {}
1525
1554
  },
1526
1555
  onclose: function onclose() {
@@ -1540,7 +1569,8 @@ var CustomerService = function(props) {
1540
1569
  // console.log(aiSendQuestions().abort(),'slkdsdsdsd')
1541
1570
  if (pageNumHistory > 1) return;
1542
1571
  var obj = msg;
1543
- var id = msg.messageId;
1572
+ var tempId = "ai thought process";
1573
+ var id = tempId; // 原:let id = msg.messageId; 备注:解决思考过程返回的messageId和下边回复的内容值不同问题,新:改成临时固定相同id,finished完成时替换为实际返回的messageId值
1544
1574
  setHistoryMessageList(function(prevHistoryMessageList) {
1545
1575
  var list1 = prevHistoryMessageList;
1546
1576
  //删除临时数据
@@ -1607,6 +1637,17 @@ var CustomerService = function(props) {
1607
1637
  console.log("isPosition", isPosition.current);
1608
1638
  scrollToBottom();
1609
1639
  if (msg.finished) {
1640
+ setHistoryMessageList(function(prevHistoryMessageList) {
1641
+ return prevHistoryMessageList.map(function(item) {
1642
+ if (item.id === tempId) {
1643
+ return _object_spread_props(_object_spread({}, item), {
1644
+ id: msg.messageId
1645
+ });
1646
+ } else {
1647
+ return item;
1648
+ }
1649
+ });
1650
+ });
1610
1651
  console.log("返回完成", msg, msgStreamingCountRef.current);
1611
1652
  //发送结束
1612
1653
  finishedRef.current = true;
@@ -1714,6 +1755,12 @@ var CustomerService = function(props) {
1714
1755
  // getHistoryMessage(page-1,5,'1',dataList);
1715
1756
  // return;
1716
1757
  // }
1758
+ dataList = dataList.map(function(ele, index) {
1759
+ if (ele.message.includes("<thinking>") && !ele.message.includes("</thinking>")) {
1760
+ ele.message = ele.message + "</thinking>";
1761
+ }
1762
+ return ele;
1763
+ });
1717
1764
  setPageCount(Math.ceil(total / maxPageSize));
1718
1765
  setFirstItemIndex(total - maxPageSize * (page - 1));
1719
1766
  var newHistoryMessageList = [];
@@ -2546,6 +2593,9 @@ var CustomerService = function(props) {
2546
2593
  message = removeMermaidBlockComments(message);
2547
2594
  }
2548
2595
  message = handleRenderSyntaxBlock(message, finishedRef.current || i != historyMessageList.length - 1);
2596
+ message = message.replace(/<thinking>([\s\S]*?)<\/thinking>/g, '<div class="think-block">$1</div>\n');
2597
+ message = message.replace(/```(\s)?yaml(?:.|\n)*?```/ig, "");
2598
+ message = message.replace(/```\s*yaml[\s\S]*/, "");
2549
2599
  if (lastId == item.id && keyWordProblem != "") {
2550
2600
  //点击历史记录时,找到关键字,防止关键字和标签名重复
2551
2601
  // let key_sign = 'sign_'+new Date().getTime();+'sign';
@@ -2594,6 +2644,8 @@ var CustomerService = function(props) {
2594
2644
  /*#__PURE__*/ _jsx("i", {
2595
2645
  className: "yinyong_quote1",
2596
2646
  onClick: function() {
2647
+ // 问题的引用
2648
+ item.message = replaceThinkAndYaml(item.message);
2597
2649
  setCitationContent({
2598
2650
  content: item.message,
2599
2651
  id: item.id,
@@ -2675,14 +2727,14 @@ var CustomerService = function(props) {
2675
2727
  item.quotedMessage && /*#__PURE__*/ _jsxs("div", {
2676
2728
  className: styles.citation_content,
2677
2729
  children: [
2678
- getByteLen(item.quotedMessage) > 120 ? /*#__PURE__*/ _jsx(Tooltip, {
2730
+ getByteLen(replaceThinkAndYaml(item.quotedMessage)) > 120 ? /*#__PURE__*/ _jsx(Tooltip, {
2679
2731
  overlayClassName: styles.popover_main_content,
2680
- title: item.quotedMessage,
2732
+ title: replaceThinkAndYaml(item.quotedMessage),
2681
2733
  placement: "leftTop",
2682
2734
  children: /*#__PURE__*/ _jsxs("p", {
2683
2735
  className: styles.text_exceed,
2684
2736
  children: [
2685
- item.quotedMessage,
2737
+ replaceThinkAndYaml(item.quotedMessage),
2686
2738
  /*#__PURE__*/ _jsx(RightOutlined, {})
2687
2739
  ]
2688
2740
  })
@@ -2840,6 +2892,35 @@ var CustomerService = function(props) {
2840
2892
  /*#__PURE__*/ _jsxs("div", {
2841
2893
  className: styles.content,
2842
2894
  children: [
2895
+ !exactRegex.test(message) ? null : /*#__PURE__*/ _jsxs("div", {
2896
+ id: "click_" + i,
2897
+ onClick: function() {
2898
+ if ($("#click_".concat(i, " + p .think-block")).css("display") === "inline-block" || $("#click_".concat(i, " + p .think-block")).css("display") === "block") {
2899
+ $("#click_".concat(i, " + p .think-block")).css({
2900
+ display: "none"
2901
+ });
2902
+ $("#click_".concat(i, " i")).css({
2903
+ transform: "rotate(180deg)"
2904
+ });
2905
+ } else {
2906
+ $("#click_".concat(i, " + p .think-block")).css({
2907
+ display: "block"
2908
+ });
2909
+ $("#click_".concat(i, " i")).css({
2910
+ transform: "rotate(0deg)"
2911
+ });
2912
+ }
2913
+ },
2914
+ className: styles.content_put,
2915
+ children: [
2916
+ /*#__PURE__*/ _jsx("span", {
2917
+ children: "思考过程"
2918
+ }),
2919
+ /*#__PURE__*/ _jsx("i", {
2920
+ className: "iconfont iconfangxiang-xiaxiao"
2921
+ })
2922
+ ]
2923
+ }),
2843
2924
  item.message != "AI助手繁忙,请稍后再提问或" && /*#__PURE__*/ _jsx("p", {
2844
2925
  dangerouslySetInnerHTML: {
2845
2926
  __html: message
@@ -2924,14 +3005,14 @@ var CustomerService = function(props) {
2924
3005
  item.quotedMessage && /*#__PURE__*/ _jsxs("div", {
2925
3006
  className: styles.citation_content,
2926
3007
  children: [
2927
- getByteLen(item.quotedMessage) > 120 ? /*#__PURE__*/ _jsx(Tooltip, {
3008
+ getByteLen(replaceThinkAndYaml(item.quotedMessage)) > 120 ? /*#__PURE__*/ _jsx(Tooltip, {
2928
3009
  overlayClassName: styles.popover_main_content,
2929
- title: item.quotedMessage,
3010
+ title: replaceThinkAndYaml(item.quotedMessage),
2930
3011
  placement: "rightTop",
2931
3012
  children: /*#__PURE__*/ _jsxs("p", {
2932
3013
  className: styles.text_exceed,
2933
3014
  children: [
2934
- item.quotedMessage,
3015
+ replaceThinkAndYaml(item.quotedMessage),
2935
3016
  /*#__PURE__*/ _jsx(RightOutlined, {})
2936
3017
  ]
2937
3018
  })
@@ -3159,6 +3240,8 @@ var CustomerService = function(props) {
3159
3240
  /*#__PURE__*/ _jsx("i", {
3160
3241
  className: "yinyong_quote1",
3161
3242
  onClick: function() {
3243
+ // 答案的引用
3244
+ item.message = replaceThinkAndYaml(item.message);
3162
3245
  setCitationContent({
3163
3246
  content: item.message,
3164
3247
  imageUrl: item.extraInfo && JSON.parse(extraInfo).length > 0 && JSON.parse(extraInfo)[0].key == "imageUrl" && JSON.parse(extraInfo)[0].value,
@@ -3367,6 +3450,7 @@ var CustomerService = function(props) {
3367
3450
  /*#__PURE__*/ _jsx("i", {
3368
3451
  className: "yinyong_quote1",
3369
3452
  onClick: function() {
3453
+ item.message = replaceThinkAndYaml(item.message);
3370
3454
  setCitationContent({
3371
3455
  content: item.message,
3372
3456
  imageUrl: item.extraInfo && JSON.parse(extraInfo).length > 0 && JSON.parse(extraInfo)[0].key == "imageUrl" && JSON.parse(extraInfo)[0].value,
@@ -369,6 +369,42 @@
369
369
  .content_child {
370
370
  padding: 0;
371
371
  line-height: 1;
372
+ img {
373
+ width: 100%;
374
+ }
375
+ :global {
376
+ .think-block {
377
+ padding: 12px;
378
+ border-left: 1px solid rgba(0, 0, 0, 0.15);
379
+ background: rgba(0, 0, 0, 0.04);
380
+ // display: inline-block;
381
+ margin-bottom: 8px;
382
+ width: 100%;
383
+ font-weight: 400;
384
+ font-size: 12px;
385
+ line-height: 1.5;
386
+ color: rgba(0, 0, 0, 0.45);
387
+ * {
388
+ color: rgba(0, 0, 0, 0.45);
389
+ font-weight: 400;
390
+ font-size: 12px;
391
+ line-height: 150%;
392
+ }
393
+ &:not(:first-of-type, :last-of-type){
394
+ padding-top:0;
395
+ padding-bottom: 0;
396
+ }
397
+ &:first-of-type{
398
+ padding-top: 12px !important;
399
+ }
400
+ &:last-of-type{
401
+ padding-bottom: 12px !important;
402
+ }
403
+ &+.think-block{
404
+ margin-top: -8px;
405
+ }
406
+ }
407
+ }
372
408
 
373
409
  p{
374
410
  word-break: break-all;
@@ -441,7 +477,7 @@
441
477
  // > ul + *, > ol + * {
442
478
  // margin-top:16px;
443
479
  // }
444
- > *:not(pre){
480
+ > *:not(pre):not(:global(.think-block)){
445
481
  word-break: break-all;
446
482
  padding-top: 8px;
447
483
  padding-bottom: 8px;
@@ -2279,4 +2315,24 @@ strong {
2279
2315
  padding: 10px;
2280
2316
  }
2281
2317
 
2318
+ }
2319
+
2320
+ .content_put {
2321
+ display: flex;
2322
+ padding: 4px 16px;
2323
+ margin-bottom: 8px;
2324
+ border-radius: 100px;
2325
+ background: rgba(0, 0, 0, 0.04);
2326
+ width: max-content;
2327
+ align-items: center;
2328
+ cursor: pointer;
2329
+ span {
2330
+ color: rgba(0, 0, 0, 0.65);
2331
+ font-size: 12px;
2332
+ font-weight: 400;
2333
+ line-height: 150%;
2334
+ }
2335
+ i {
2336
+ margin-left: 8px;
2337
+ }
2282
2338
  }
@@ -365,6 +365,43 @@
365
365
  .content_child {
366
366
  padding: 0;
367
367
  line-height: 1;
368
+ img {
369
+ width: 100%;
370
+ }
371
+ :global {
372
+ .think-block {
373
+ padding: 12px;
374
+ padding-top: 12px !important;
375
+ border-left: 1px solid rgba(0, 0, 0, 0.15);
376
+ background: rgba(0, 0, 0, 0.04);
377
+ // display: inline-block;
378
+ margin-bottom: 8px;
379
+ width: 100%;
380
+ font-weight: 400;
381
+ font-size: 12px;
382
+ line-height: 1.5;
383
+ color: rgba(0, 0, 0, 0.45);
384
+ * {
385
+ color: rgba(0, 0, 0, 0.45);
386
+ font-weight: 400;
387
+ font-size: 12px;
388
+ line-height: 150%;
389
+ }
390
+ &:not(:first-of-type, :last-of-type){
391
+ padding-top:0;
392
+ padding-bottom: 0;
393
+ }
394
+ &:first-of-type{
395
+ padding-top: 12px !important;
396
+ }
397
+ &:last-of-type{
398
+ padding-bottom: 12px !important;
399
+ }
400
+ &+.think-block{
401
+ margin-top: -8px;
402
+ }
403
+ }
404
+ }
368
405
  p{
369
406
  word-break: break-all;
370
407
  white-space: break-spaces;
@@ -436,7 +473,7 @@
436
473
  // > ul + *, > ol + * {
437
474
  // margin-top:16px;
438
475
  // }
439
- > *:not(pre){
476
+ > *:not(pre):not(:global(.think-block)){
440
477
  word-break: break-all;
441
478
  padding-top: 8px;
442
479
  padding-bottom: 8px;
@@ -2217,3 +2254,23 @@
2217
2254
  strong {
2218
2255
  font-weight: bold !important;
2219
2256
  }
2257
+
2258
+ .content_put {
2259
+ display: flex;
2260
+ padding: 4px 16px;
2261
+ margin-bottom: 8px;
2262
+ border-radius: 100px;
2263
+ background: rgba(0, 0, 0, 0.04);
2264
+ width: max-content;
2265
+ align-items: center;
2266
+ cursor: pointer;
2267
+ span {
2268
+ color: rgba(0, 0, 0, 0.65);
2269
+ font-size: 12px;
2270
+ font-weight: 400;
2271
+ line-height: 150%;
2272
+ }
2273
+ i {
2274
+ margin-left: 8px;
2275
+ }
2276
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bhd-components",
3
- "version": "0.10.37",
3
+ "version": "0.10.38",
4
4
  "description": "组件功能描述",
5
5
  "config": {
6
6
  "commitizen": {