askbot-dragon 1.7.74-beta → 1.7.75-beta

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "askbot-dragon",
3
- "version": "1.7.74-beta",
3
+ "version": "1.7.75-beta",
4
4
  "scripts": {
5
5
  "serve": "vue-cli-service serve",
6
6
  "build": "vue-cli-service build",
@@ -22,13 +22,12 @@
22
22
  :plugins="plugins"
23
23
  >
24
24
  </vue-markdown> -->
25
+ <!-- v-show="hasContent" -->
25
26
  <div
26
- v-show="hasContent"
27
27
  class="mark_down"
28
28
  v-html="markParseText"
29
29
  ref="markDown"
30
30
  @click="clickMarkDown">
31
-
32
31
  </div>
33
32
  <!-- <div v-show="!hasThinkValue && !hasContent" class="blinking-cursor"></div> -->
34
33
  <div v-if="showPreview">
@@ -41,16 +40,17 @@
41
40
  <script>
42
41
  /* eslint-disable */
43
42
  import VueMarkdown from 'vue-markdown';
44
- import ImgView from "./imgView";
43
+ import ImgView from "@/components/imgView";
45
44
  // import Typed from "typed.js";
46
45
  import hljs from 'highlight.js';
47
46
  import 'highlight.js/styles/default.css';
48
- const marked = require("marked")
49
47
  import { v4 as uuidv4 } from "uuid";
48
+ const marked = require("marked")
50
49
  export default {
51
50
  name: "markDownText",
52
51
  data() {
53
52
  return {
53
+ eventSource: null,
54
54
  plugins: [
55
55
 
56
56
  ],
@@ -124,7 +124,7 @@ export default {
124
124
  let str = this.chainThinkValue;
125
125
  str = str.replaceAll("\\n", "\n")
126
126
  str = str.replaceAll("\n", "<br>")
127
- return str
127
+ return this.parseCode(str)
128
128
  }
129
129
  },
130
130
  components: {
@@ -169,6 +169,24 @@ export default {
169
169
  })
170
170
  },
171
171
  methods: {
172
+ closeMessageStream() {
173
+ this.eventSource.close();
174
+ setTimeout(() => {
175
+ let str = this.typedContent + this.generatingString
176
+ this.$set(this, "typedContent", str)
177
+ this.generatingString = "";
178
+ let str2 = this.filterText(this.chainThinkValue + this.generatingThinkString)
179
+ this.$set(this, "chainThinkValue", str2)
180
+ this.generatingThinkString = "";
181
+ this.closeTimeOut()
182
+ clearInterval(this.thinkTimer)
183
+ this.thinkTimer = null
184
+ this.thinkEnd = true
185
+ this.removeLoadingNode()
186
+ this.$emit("streamCallback", this.typedContent)
187
+ this.$emit("sseOtherInfo", this.msgId, "start", "");
188
+ }, 200);
189
+ },
172
190
  filterTime(time) {
173
191
  if (time < 60) {
174
192
  return time + " 秒";
@@ -249,9 +267,10 @@ export default {
249
267
  },
250
268
  scrollMarkdown() {
251
269
  !this.isManualScroll && this.$nextTick(() => {
252
- const element = document.getElementById('el_id_markdown_' + this.msgId);
253
- if (element) {
254
- element.scrollIntoView({ behavior: 'smooth', block: 'start' });
270
+ let container = document.getElementById("list");
271
+ if (container) {
272
+ let scrollHeight = container.scrollHeight;
273
+ container.scrollTop = scrollHeight;
255
274
  }
256
275
  });
257
276
  },
@@ -260,7 +279,9 @@ export default {
260
279
  if(this.retryUrl == ""){
261
280
  this.$emit("sseOtherInfo", this.msgId, "init", "");
262
281
  }
263
- const eventSource = new EventSource(url);
282
+ this.$emit("answerDocKnowledgeFn");
283
+ this.eventSource = new EventSource(url);
284
+ this.$emit("streamStatus", true, this.msgId);
264
285
  this.$set(this, 'showThink', true);
265
286
  this.signSetFlag = false;
266
287
  this.thinkEnd = false
@@ -277,7 +298,7 @@ export default {
277
298
  let hasN = false; // 标记是否有 n
278
299
  const thinkStartRegex = /<think>/;
279
300
  const thinkEndRegex = /<\/think>/
280
- eventSource.onmessage = (event) => {
301
+ this.eventSource.onmessage = (event) => {
281
302
  const data = JSON.parse(event.data);
282
303
  if (event.lastEventId === 'finish') { // 不能删除 finish
283
304
  console.log("finish+++++");
@@ -320,11 +341,14 @@ export default {
320
341
  this.thinkEnd = true
321
342
  }
322
343
  this.$emit("streamCallback", this.typedContent)
344
+ this.$emit("streamStatus", false, this.msgId);
323
345
  this.appendCopyBtn()
346
+ this.removeLoadingNode()
347
+ this.$emit("sseOtherInfo", this.msgId, "start", "");
324
348
  }
325
349
 
326
350
  }, 100);
327
- eventSource.close();
351
+ this.eventSource.close();
328
352
  // 重试地址不为空,说明需要重试
329
353
  console.log("需要重试 this.retryUrl: ", this.retryUrl);
330
354
  if (this.retryUrl != "") {
@@ -342,27 +366,32 @@ export default {
342
366
  recommendItems = data;
343
367
  } else if (event.lastEventId === 'retry') {
344
368
  this.retryUrl = data.content;
369
+ } else if (event.lastEventId === 'source') {
370
+ this.$emit("changedHeadStatusValue", this.msgId, data);
345
371
  } else {
346
372
  // console.log("start event.lastEventId: ", event.lastEventId);
347
373
  // 设置当前知识答案id,用于loading取消和展示
348
374
  this.$emit("sseOtherInfo", this.msgId, "start", "");
349
-
350
- // // 前置结束的校验,如果校验到闭合标签,标记为 false ,数据不再添加到 chainThinkValue 字段
351
-
352
- // 后置开始标签的校验,如果校验到结束后,又校验到开始,则开启数据添加到 chainThinkValue 字段
353
- // 最终根据规则是以最后一个 </think> 标识当前深度思考结束,开始正常添加数据到 typedContent
354
- if (thinkStartRegex.test(data.content)) {
355
- if (this.thinkCount == 0) {
356
- this.thinkCount = 0
357
- } else {
358
- this.thinkCount += 1;
359
- }
375
+ if(thinkStartRegex.test(data.content) && thinkEndRegex.test(data.content)) {
360
376
  this.hasThinkValue = true;
361
- // this.streamThinkValueAddFlag = true;
362
- }
363
- if (thinkEndRegex.test(data.content)) {
364
- this.thinkCount -= 1;
365
- // this.streamThinkValueAddFlag = false;
377
+ this.thinkCount = 0
378
+ this.ThinkTime()
379
+ } else {
380
+ // 最终根据规则是以最后一个 </think> 标识当前深度思考结束,开始正常添加数据到 typedContent
381
+ if (thinkStartRegex.test(data.content)) {
382
+ if (this.thinkCount == 0) {
383
+ this.thinkCount = 0
384
+ } else {
385
+ this.thinkCount += 1;
386
+ }
387
+ this.hasThinkValue = true;
388
+ this.ThinkTime()
389
+ // this.streamThinkValueAddFlag = true;
390
+ }
391
+ if (thinkEndRegex.test(data.content)) {
392
+ this.thinkCount -= 1;
393
+ // this.streamThinkValueAddFlag = false;
394
+ }
366
395
  }
367
396
  // 字符串中存在特定字符,本次接收消息暂不展示
368
397
  if (backslashOrNRegex.test(data.content) && !this.hasThinkValue) {
@@ -394,15 +423,26 @@ export default {
394
423
  isFirstStr = false;
395
424
  this.timer = 0;
396
425
  this.openTimeOutSetVal()
397
- this.$emit("answerDocKnowledgeFn");
398
426
  }
399
427
  }
400
428
  }
401
429
  };
402
- eventSource.onerror = function (err) {
403
- console.error('EventSource failed:', err);
404
- this.typedContent += '\nError receiving data from server.\n';
405
- eventSource.close();
430
+ this.eventSource.onerror = (err) => {
431
+ this.typedContent += `\n${this.$t("dragonCommon.eventSourceError")}\n`;
432
+ this.closeTimeOut()
433
+ this.$emit("streamStatus", false, this.msgId);
434
+ this.$emit("streamErrorCallBack", this.msgId);
435
+ this.$emit("streamCallback", this.typedContent)
436
+ if(this.eventSource) {
437
+ try {
438
+ this.eventSource.close();
439
+ } catch (e) {
440
+ console.error('EventSource close failed:', e);
441
+ }
442
+ }
443
+ setTimeout(() => {
444
+ this.removeLoadingNode()
445
+ }, 200);
406
446
  };
407
447
  },
408
448
  openTimeOutSetVal() {
@@ -524,8 +564,28 @@ export default {
524
564
  block.setAttribute('target', '_blank');
525
565
  block.setAttribute('rel', 'noopener noreferrer');
526
566
  });
567
+ let node = this.getLastNode(doc)
568
+ if (node && !this.isHistory) {
569
+ let loading = document.createElement('span')
570
+ loading.classList.add("loading-circle")
571
+ loading.id = "loading-circle"
572
+ this.removeLoadingNode()
573
+ node.appendChild(loading)
574
+ }
527
575
  return doc.documentElement.outerHTML
528
576
  },
577
+ removeLoadingNode() {
578
+ let old = document.getElementById("loading-circle")
579
+ if(old) old.remove()
580
+ },
581
+ getLastNode(node) {
582
+ let filterList = ["STRONG", "BR", "SPAN", "I", "EM", "B", "A"]
583
+ if(node.lastElementChild && !filterList.includes(node.lastElementChild.tagName)) {
584
+ return this.getLastNode(node.lastElementChild)
585
+ } else {
586
+ return node
587
+ }
588
+ },
529
589
  appendCopyBtn() {
530
590
  let doc = this.$refs.markDown.$el ? this.$refs.markDown.$el : this.$refs.markDown
531
591
  let codeList = doc.querySelectorAll('pre code')
@@ -623,6 +683,11 @@ export default {
623
683
  // 移除临时的 textarea
624
684
  document.body.removeChild(textArea);
625
685
  },
686
+ },
687
+ beforeDestroy() {
688
+ if (this.eventSource) {
689
+ this.eventSource.close();
690
+ }
626
691
  }
627
692
  };
628
693
  </script>
@@ -845,4 +910,31 @@ export default {
845
910
  min-width: 100px;
846
911
  }
847
912
  }
913
+
914
+ /* 圆圈的样式 */
915
+ /deep/.loading-circle {
916
+ width: 8px;
917
+ height: 8px;
918
+ display: inline-block;
919
+ border-radius: 50%;
920
+ background-color: #366aff;
921
+ animation: loading 2s infinite ease-in-out;
922
+ margin: 0 8px;
923
+ /* 动画控制 */
924
+ }
925
+
926
+ /* 放大缩小的动画 */
927
+ @keyframes loading {
928
+
929
+ 0%,
930
+ 100% {
931
+ transform: scale(1);
932
+ /* 原始大小 */
933
+ }
934
+
935
+ 50% {
936
+ transform: scale(1.5);
937
+ /* 放大 */
938
+ }
939
+ }
848
940
  </style>