inl-ui 0.1.4 → 0.1.5

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.
@@ -11234,13 +11234,16 @@ var index = installComponent(SszComment, "ssz-comment");
11234
11234
  function formatDataString(str) {
11235
11235
  const lines = str.split("\n");
11236
11236
  const result = lines.filter(line => !!line.trim()).map(line => {
11237
- const data = JSON.parse(line.replace("data: ", ""));
11237
+ const data = JSON.parse(line.replace(/^data: /, ""));
11238
11238
  return data.text;
11239
11239
  }).filter(line => line !== void 0).join("");
11240
11240
  return result;
11241
11241
  }
11242
11242
  function request(question, streamCallback, doneCallback) {
11243
+ const controller = new AbortController();
11244
+ const signal = controller.signal;
11243
11245
  fetch("/mt_cpp_gpt/chat", {
11246
+ signal,
11244
11247
  method: "POST",
11245
11248
  headers: {
11246
11249
  "Content-Type": "application/json"
@@ -11249,7 +11252,8 @@ function request(question, streamCallback, doneCallback) {
11249
11252
  query: question,
11250
11253
  conversation_id: ""
11251
11254
  })
11252
- }).then(res => res.body).then(stream => {
11255
+ }).then(res => {
11256
+ const stream = res.body;
11253
11257
  const decoder = new TextDecoder();
11254
11258
  const reader = stream.getReader();
11255
11259
  let result = "";
@@ -11262,22 +11266,32 @@ function request(question, streamCallback, doneCallback) {
11262
11266
  doneCallback();
11263
11267
  return;
11264
11268
  }
11265
- const dataString = decoder.decode(value, {
11266
- stream: true
11267
- });
11268
- const str = formatDataString(dataString);
11269
- result += str;
11270
- streamCallback(result);
11269
+ try {
11270
+ const dataString = decoder.decode(value, {
11271
+ stream: true
11272
+ });
11273
+ const str = formatDataString(dataString);
11274
+ result += str;
11275
+ streamCallback(result);
11276
+ } catch (e) {}
11271
11277
  return processText();
11278
+ }).catch(() => {
11279
+ doneCallback();
11272
11280
  });
11273
11281
  }
11274
11282
  return processText();
11283
+ }).catch(() => {
11284
+ doneCallback();
11275
11285
  });
11286
+ return function stop() {
11287
+ controller.abort();
11288
+ };
11276
11289
  }
11277
11290
  function useQA() {
11278
11291
  const context = vue.ref([]);
11279
11292
  const answerLoading = vue.ref(false);
11280
11293
  const answer = vue.ref("");
11294
+ let abort = null;
11281
11295
  setTimeout(() => {
11282
11296
  const questionItem = {
11283
11297
  type: "answer",
@@ -11314,19 +11328,27 @@ function useQA() {
11314
11328
  id: /* @__PURE__ */new Date().getTime()
11315
11329
  });
11316
11330
  questionItem.answers.push(answerItem.value);
11317
- request(question, data => {
11331
+ abort = request(question, data => {
11318
11332
  answer.value = data;
11319
11333
  answerItem.value.content = data;
11320
11334
  }, () => {
11321
11335
  answerLoading.value = false;
11322
11336
  answerItem.value.loadEnd = true;
11337
+ abort = null;
11323
11338
  });
11324
11339
  }
11340
+ function abortRequest() {
11341
+ if (abort) {
11342
+ abort();
11343
+ abort = null;
11344
+ }
11345
+ }
11325
11346
  return {
11326
11347
  context,
11327
11348
  answerLoading,
11328
11349
  answer,
11329
- sendQuestion
11350
+ sendQuestion,
11351
+ abortRequest
11330
11352
  };
11331
11353
  }
11332
11354
 
@@ -11336,9 +11358,10 @@ const Input = vue.defineComponent({
11336
11358
  emit,
11337
11359
  expose
11338
11360
  }) {
11361
+ const abortRequest = vue.inject("abortRequest");
11362
+ const loading = vue.inject("answerLoading");
11339
11363
  const value = vue.ref("");
11340
11364
  const isFocus = vue.ref(false);
11341
- const loading = vue.inject("answerLoading");
11342
11365
  const send = () => {
11343
11366
  if (loading.value) return;
11344
11367
  if (value.value.length === 0) {
@@ -11348,6 +11371,12 @@ const Input = vue.defineComponent({
11348
11371
  emit("send", value.value);
11349
11372
  value.value = "";
11350
11373
  };
11374
+ const handleAbord = () => {
11375
+ abortRequest();
11376
+ };
11377
+ const handleMicClick = () => {
11378
+ antDesignVue.message.info("\u6682\u4E0D\u652F\u6301\u8BED\u97F3\u8F93\u5165");
11379
+ };
11351
11380
  const clear = () => value.value = "";
11352
11381
  expose({
11353
11382
  clear
@@ -11359,7 +11388,8 @@ const Input = vue.defineComponent({
11359
11388
  }, [vue.createVNode("img", {
11360
11389
  "class": "img img-mic",
11361
11390
  "src": "/micro-assets/largeLanguageModel/mic.png",
11362
- "alt": ""
11391
+ "alt": "",
11392
+ "onClick": handleMicClick
11363
11393
  }, null), vue.createVNode(vue.resolveComponent("a-input"), {
11364
11394
  "value": value.value,
11365
11395
  "onUpdate:value": $event => value.value = $event,
@@ -11370,7 +11400,8 @@ const Input = vue.defineComponent({
11370
11400
  "onPressEnter": send
11371
11401
  }, null), loading.value ? vue.createVNode(iconsVue.BorderOutlined, {
11372
11402
  "class": "btn-abord",
11373
- "title": "\u4E2D\u6B62\u56DE\u7B54"
11403
+ "title": "\u4E2D\u6B62\u56DE\u7B54",
11404
+ "onClick": handleAbord
11374
11405
  }, null) : vue.createVNode("img", {
11375
11406
  "class": "img img-send",
11376
11407
  "src": "/micro-assets/largeLanguageModel/send.png",
@@ -11446,12 +11477,15 @@ const QuestionBubble = vue.defineComponent({
11446
11477
  }
11447
11478
  },
11448
11479
  setup(props) {
11480
+ const userinfo = JSON.parse(sessionStorage.getItem("userinfo") || "{}");
11481
+ const avatar = userinfo.photo || "/micro-assets/platform_app/avatar.png";
11482
+ const name = userinfo.employeeName || userinfo.userName || "\u7528\u6237";
11449
11483
  return () => vue.createVNode("div", {
11450
11484
  "class": "question-bubble chat-bubble"
11451
11485
  }, [vue.createVNode(Avatar, {
11452
11486
  "reverse": true,
11453
- "avatar": "/micro-assets/platform_app/avatar.png",
11454
- "name": "\u5F20\u660E\u5FD7"
11487
+ "avatar": avatar,
11488
+ "name": name
11455
11489
  }, null), vue.createVNode("div", {
11456
11490
  "class": "bubble question"
11457
11491
  }, [props.content]), vue.createVNode("div", {
@@ -11460,12 +11494,15 @@ const QuestionBubble = vue.defineComponent({
11460
11494
  }
11461
11495
  });
11462
11496
 
11497
+ const commonStyle = `
11498
+ :host > p {
11499
+ margin: 0;
11500
+ }
11501
+ `;
11463
11502
  const styleDark = `
11464
11503
  <style>
11465
- :host > p {
11466
- margin: 0;
11467
- }
11468
-
11504
+ ${commonStyle}
11505
+
11469
11506
  * {
11470
11507
  color: #fff;
11471
11508
  }
@@ -11476,6 +11513,8 @@ const styleDark = `
11476
11513
  `;
11477
11514
  const styleLight = `
11478
11515
  <style>
11516
+ ${commonStyle}
11517
+
11479
11518
  * {
11480
11519
  color: #20242B;
11481
11520
  }
@@ -11487,7 +11526,7 @@ const styleLight = `
11487
11526
 
11488
11527
  const suggestionList = ["\u7F8E\u5C0F\u817E\u80FD\u5E2E\u6211\u505A\u4EC0\u4E48\uFF1F", "\u8FD1\u4E00\u4E2A\u6708\u7684\u4ECB\u8017\u60C5\u51B5\u5982\u4F55\uFF1F", "\u5C3E\u77FF\u8DD1\u7C97\u7684\u6392\u67E5\u5904\u7406\u65B9\u6CD5\u6709\u54EA\u4E9B\uFF1F\u5C3E\u77FF\u8DD1\u7C97\u7684\u6392\u67E5\u5904\u7406\u65B9\u6CD5\u6709\u54EA\u4E9B\u5C3E\u77FF\u8DD1\u7C97\u7684\u6392\u67E5\u5904\u7406\u65B9\u6CD5\u6709\u54EA\u4E9B\u5C3E\u77FF\u8DD1\u7C97\u7684\u6392\u67E5\u5904\u7406\u65B9\u6CD5\u6709\u54EA\u4E9B"];
11489
11528
  const AnswerBubble = vue.defineComponent({
11490
- emits: ["send", "render", "delete"],
11529
+ emits: ["send", "render", "delete", "regenerate"],
11491
11530
  props: {
11492
11531
  content: {
11493
11532
  type: Array,
@@ -11518,7 +11557,9 @@ const AnswerBubble = vue.defineComponent({
11518
11557
  });
11519
11558
  const renderText = () => {
11520
11559
  if (!shadowRoot) return;
11521
- emit("render", activeAnswer.value.content);
11560
+ vue.nextTick(() => {
11561
+ emit("render", activeAnswer.value.content);
11562
+ });
11522
11563
  const themeStyle = chatTheme === "dark" ? styleDark : styleLight;
11523
11564
  const html = `
11524
11565
  ${trasformMd(activeAnswer.value.content)}
@@ -11527,9 +11568,12 @@ const AnswerBubble = vue.defineComponent({
11527
11568
  `;
11528
11569
  shadowRoot.innerHTML = html;
11529
11570
  };
11530
- vue.watch([() => props.content, activeAnswerIndex], renderText, {
11571
+ vue.watch([activeAnswer, activeAnswerIndex], renderText, {
11531
11572
  deep: true
11532
11573
  });
11574
+ const switchAnswer = step => {
11575
+ activeAnswerIndex.value += step;
11576
+ };
11533
11577
  const operateList = vue.reactive([{
11534
11578
  title: "\u590D\u5236",
11535
11579
  key: "copy",
@@ -11576,12 +11620,25 @@ const AnswerBubble = vue.defineComponent({
11576
11620
  title: "\u786E\u5B9A\u5220\u9664\u8FD9\u4E2A\u56DE\u7B54\u5417\uFF1F",
11577
11621
  onOk: () => {
11578
11622
  emit("delete", activeAnswer.value.id);
11623
+ if (activeAnswerIndex.value > 0 && activeAnswerIndex.value === props.content.length - 1) {
11624
+ activeAnswerIndex.value--;
11625
+ }
11579
11626
  }
11580
11627
  });
11581
11628
  break;
11582
11629
  case "comment":
11583
11630
  antDesignVue.message.info("\u6682\u672A\u5F00\u653E");
11584
11631
  break;
11632
+ case "regenerate":
11633
+ if (props.content.length >= 5) {
11634
+ antDesignVue.message.info("\u6700\u591A\u652F\u6301\u751F\u62105\u6761\u56DE\u7B54");
11635
+ return;
11636
+ }
11637
+ emit("regenerate", activeAnswer.value.id);
11638
+ vue.nextTick(() => {
11639
+ activeAnswerIndex.value = props.content.length - 1;
11640
+ });
11641
+ break;
11585
11642
  }
11586
11643
  };
11587
11644
  return () => {
@@ -11590,30 +11647,30 @@ const AnswerBubble = vue.defineComponent({
11590
11647
  "onClick": () => emit("send", item)
11591
11648
  }, [item]));
11592
11649
  const showOperates = !activeAnswer.value.hideOperates && activeAnswer.value.loadEnd;
11593
- const operateDom = operateList.map(item => {
11594
- return vue.createVNode(vue.resolveComponent("a-tooltip"), {
11595
- "title": item.title
11596
- }, {
11597
- default: () => [vue.createVNode("div", {
11598
- "class": ["operate-item", item.key, {
11599
- active: item.isActive
11600
- }],
11601
- "onClick": () => handleOperate(item.key)
11602
- }, null)]
11603
- });
11604
- });
11650
+ const operateDom = operateList.map(item => vue.createVNode(vue.resolveComponent("a-tooltip"), {
11651
+ "title": item.title
11652
+ }, {
11653
+ default: () => [vue.createVNode("div", {
11654
+ "class": ["operate-item", item.key, {
11655
+ active: item.isActive
11656
+ }],
11657
+ "onClick": () => handleOperate(item.key)
11658
+ }, null)]
11659
+ }));
11605
11660
  const prevDisabled = activeAnswerIndex.value === 0;
11606
11661
  const nextDisabled = activeAnswerIndex.value === props.content.length - 1;
11607
11662
  const answerNav = vue.createVNode("div", {
11608
- "class": "operate-item"
11663
+ "class": "operate-item operate-nav"
11609
11664
  }, [vue.createVNode("span", {
11610
11665
  "class": ["nav", {
11611
- disalbed: prevDisabled
11612
- }]
11613
- }, ["<"]), activeAnswerIndex.value + 1, "/ ", props.content.length, vue.createVNode("span", {
11666
+ disabled: prevDisabled
11667
+ }],
11668
+ "onClick": () => switchAnswer(-1)
11669
+ }, ["<"]), vue.createVNode("span", null, [activeAnswerIndex.value + 1]), " ", vue.createVNode("span", null, [vue.createTextVNode("/")]), vue.createVNode("span", null, [props.content.length]), vue.createVNode("span", {
11614
11670
  "class": ["nav", {
11615
- disalbed: nextDisabled
11616
- }]
11671
+ disabled: nextDisabled
11672
+ }],
11673
+ "onClick": () => switchAnswer(1)
11617
11674
  }, [">"])]);
11618
11675
  return vue.createVNode("div", {
11619
11676
  "class": "answer-bubble chat-bubble"
@@ -11623,21 +11680,24 @@ const AnswerBubble = vue.defineComponent({
11623
11680
  }, null), vue.createVNode("div", {
11624
11681
  "ref": bubbleRef,
11625
11682
  "class": "bubble answer"
11626
- }, null), showOperates && vue.createVNode("div", {
11683
+ }, null), vue.createVNode("div", {
11627
11684
  "class": "operates"
11628
- }, [props.content.length > 1 && answerNav, operateDom])]);
11685
+ }, [props.content.length > 1 && answerNav, showOperates && operateDom])]);
11629
11686
  };
11630
11687
  }
11631
11688
  });
11632
11689
 
11633
11690
  const QaContext = vue.defineComponent({
11691
+ emits: ["regenerate"],
11634
11692
  props: {
11635
11693
  list: {
11636
11694
  type: Array,
11637
11695
  default: () => []
11638
11696
  }
11639
11697
  },
11640
- setup(props) {
11698
+ setup(props, {
11699
+ emit
11700
+ }) {
11641
11701
  const containerRef = vue.ref();
11642
11702
  const onAnswerRender = text => {
11643
11703
  containerRef.value.scrollTo({
@@ -11676,7 +11736,8 @@ const QaContext = vue.defineComponent({
11676
11736
  contextList.push(vue.createVNode(AnswerBubble, {
11677
11737
  "onRender": onAnswerRender,
11678
11738
  "content": questionItem.answers,
11679
- "onDelete": answerId => handleDeleteAnswer(questionItem.id, answerId)
11739
+ "onDelete": answerId => handleDeleteAnswer(questionItem.id, answerId),
11740
+ "onRegenerate": () => emit("regenerate", questionItem.id)
11680
11741
  }, null));
11681
11742
  }
11682
11743
  }
@@ -11708,17 +11769,19 @@ const ChatBox = vue.defineComponent({
11708
11769
  context,
11709
11770
  answerLoading,
11710
11771
  sendQuestion,
11711
- answer
11772
+ abortRequest
11712
11773
  } = useQA();
11713
11774
  vue.provide("answerLoading", answerLoading);
11714
- const handleSend = msg => {
11715
- sendQuestion(msg);
11775
+ vue.provide("abortRequest", abortRequest);
11776
+ const handleSend = (msg, questionId) => {
11777
+ sendQuestion(msg, questionId);
11716
11778
  };
11717
11779
  return () => {
11718
11780
  return vue.createVNode("div", {
11719
11781
  "class": ["inl-chat-box", `inl-chat-box-${props.theme}`]
11720
11782
  }, [vue.createVNode(QaContext, {
11721
- "list": context.value
11783
+ "list": context.value,
11784
+ "onRegenerate": qId => handleSend("", qId)
11722
11785
  }, null), vue.createVNode(Bottom, {
11723
11786
  "onSend": handleSend
11724
11787
  }, null)]);