@kg-ui/kg-ui-plus 0.0.8 → 0.0.10

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.
Files changed (41) hide show
  1. package/dist/es/KgCopilot/CopiContent/AnswerHead.vue.mjs +3 -12
  2. package/dist/es/KgCopilot/CopiContent/AnswerHead.vue2.mjs +25 -2
  3. package/dist/es/KgCopilot/CopiContent/AnswerHead.vue3.mjs +4 -0
  4. package/dist/es/KgCopilot/CopiFooter/components/NewTheme.vue.mjs +1 -1
  5. package/dist/es/KgCopilot/CopiFooter/components/NewTheme.vue2.mjs +3 -1
  6. package/dist/es/KgCopilot/CopiFooter/components/NewTheme.vue3.mjs +2 -2
  7. package/dist/es/KgCopilot/CopiFooter/components/SearchInput/SelectPlugin.vue.mjs +1 -1
  8. package/dist/es/KgCopilot/CopiFooter/components/SearchInput/SelectPlugin.vue2.mjs +88 -19
  9. package/dist/es/KgCopilot/CopiFooter/components/SearchInput/SelectPlugin.vue3.mjs +2 -2
  10. package/dist/es/KgCopilot/CopiFooter/components/SearchInput/SelectPluginByKey.vue.mjs +1 -1
  11. package/dist/es/KgCopilot/CopiFooter/components/SearchInput/SelectPluginByKey.vue2.mjs +22 -21
  12. package/dist/es/KgCopilot/CopiFooter/components/SearchInput/SelectPluginByKey.vue3.mjs +2 -2
  13. package/dist/es/KgCopilot/CopiFooter/components/SearchInput/SpeechControl.vue.mjs +1 -1
  14. package/dist/es/KgCopilot/CopiFooter/components/SearchInput/SpeechControl.vue3.mjs +2 -2
  15. package/dist/es/KgCopilot/CopiFooter/components/SearchInput/Upload.vue.mjs +1 -1
  16. package/dist/es/KgCopilot/CopiFooter/components/SearchInput/Upload.vue2.mjs +1 -1
  17. package/dist/es/KgCopilot/CopiFooter/components/SearchInput/Upload.vue3.mjs +2 -2
  18. package/dist/es/KgCopilot/CopiFooter/components/SearchInput/index.vue.mjs +1 -1
  19. package/dist/es/KgCopilot/CopiFooter/components/SearchInput/index.vue2.mjs +33 -42
  20. package/dist/es/KgCopilot/CopiFooter/components/SearchInput/index.vue3.mjs +2 -2
  21. package/dist/es/KgCopilot/CopiFooter/index.vue.mjs +1 -1
  22. package/dist/es/KgCopilot/CopiFooter/index.vue3.mjs +2 -2
  23. package/dist/es/KgCopilot/dialogue/index.vue.mjs +1 -1
  24. package/dist/es/KgCopilot/dialogue/index.vue2.mjs +62 -49
  25. package/dist/es/KgCopilot/dialogue/index.vue3.mjs +2 -2
  26. package/dist/es/KgCopilot/dialogue/readMd.vue.mjs +1 -1
  27. package/dist/es/KgCopilot/dialogue/readMd.vue2.mjs +19 -19
  28. package/dist/es/KgCopilot/dialogue/readMd.vue3.mjs +2 -2
  29. package/dist/es/KgCopilot/index.vue.mjs +1 -1
  30. package/dist/es/KgCopilot/index.vue2.mjs +20 -6
  31. package/dist/es/KgCopilot/index.vue3.mjs +2 -2
  32. package/dist/es/api/copilot.mjs +25 -4
  33. package/dist/es/directives/heighlight/index.mjs +1 -1
  34. package/dist/es/node_modules/.pnpm/@microsoft_fetch-event-source@2.0.1/node_modules/@microsoft/fetch-event-source/lib/esm/fetch.mjs +90 -0
  35. package/dist/es/node_modules/.pnpm/@microsoft_fetch-event-source@2.0.1/node_modules/@microsoft/fetch-event-source/lib/esm/parse.mjs +109 -0
  36. package/dist/es/store/modules/copilot.mjs +69 -40
  37. package/dist/es/style.css +1 -1
  38. package/dist/es/utils/home.mjs +10 -0
  39. package/dist/es/utils/http/index.mjs +9 -0
  40. package/package.json +122 -113
  41. package/dist/es/node_modules/.pnpm/@iconify-icons_ep@1.2.7/node_modules/@iconify-icons/ep/circle-plus.mjs +0 -8
@@ -1,7 +1,7 @@
1
1
  import _sfc_main from "./index.vue2.mjs";
2
2
  import "./index.vue3.mjs";
3
3
  import _export_sfc from "../../_virtual/_plugin-vue_export-helper.mjs";
4
- const CopiFooter = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-f807cdbd"]]);
4
+ const CopiFooter = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-a0bb8b78"]]);
5
5
  export {
6
6
  CopiFooter as default
7
7
  };
@@ -1,4 +1,4 @@
1
- const index_vue_vue_type_style_index_0_scoped_f807cdbd_lang = "";
1
+ const index_vue_vue_type_style_index_0_scoped_a0bb8b78_lang = "";
2
2
  export {
3
- index_vue_vue_type_style_index_0_scoped_f807cdbd_lang as default
3
+ index_vue_vue_type_style_index_0_scoped_a0bb8b78_lang as default
4
4
  };
@@ -1,7 +1,7 @@
1
1
  import _sfc_main from "./index.vue2.mjs";
2
2
  import "./index.vue3.mjs";
3
3
  import _export_sfc from "../../_virtual/_plugin-vue_export-helper.mjs";
4
- const dialogue = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-47d13b19"]]);
4
+ const dialogue = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-7a7aa418"]]);
5
5
  export {
6
6
  dialogue as default
7
7
  };
@@ -1,4 +1,4 @@
1
- import { defineComponent, ref, resolveComponent, openBlock, createElementBlock, Fragment, renderList, unref, createElementVNode, createBlock, normalizeClass, createVNode, createCommentVNode, withDirectives, createTextVNode, vShow, pushScopeId, popScopeId } from "vue";
1
+ import { defineComponent, ref, resolveComponent, openBlock, createElementBlock, Fragment, renderList, unref, createElementVNode, createBlock, withCtx, renderSlot, createTextVNode, toDisplayString, createCommentVNode, createVNode, withDirectives, vShow, normalizeClass, pushScopeId, popScopeId } from "vue";
2
2
  import readMd from "./readMd.vue.mjs";
3
3
  import UserHead from "../CopiContent/UserHead.vue.mjs";
4
4
  import AnswerHead from "../CopiContent/AnswerHead.vue.mjs";
@@ -10,36 +10,43 @@ import data$3 from "../../node_modules/.pnpm/@iconify-icons_ri@1.2.3/node_module
10
10
  import data$5 from "../../node_modules/.pnpm/@iconify-icons_ph@1.2.5/node_modules/@iconify-icons/ph/warning-bold.mjs";
11
11
  import { useCopilotStoreHook } from "../../store/modules/copilot.mjs";
12
12
  import { storeToRefs } from "pinia";
13
- const _withScopeId = (n) => (pushScopeId("data-v-47d13b19"), n = n(), popScopeId(), n);
13
+ const _withScopeId = (n) => (pushScopeId("data-v-7a7aa418"), n = n(), popScopeId(), n);
14
14
  const _hoisted_1 = { class: "msg-head" };
15
15
  const _hoisted_2 = {
16
16
  key: 0,
17
- class: "icon-operates"
17
+ class: "msg-plus mb-1"
18
18
  };
19
19
  const _hoisted_3 = {
20
+ class: /* @__PURE__ */ normalizeClass({ "msg-content": true })
21
+ };
22
+ const _hoisted_4 = {
23
+ key: 0,
24
+ class: "icon-operates"
25
+ };
26
+ const _hoisted_5 = {
20
27
  class: "icon-item",
21
28
  title: "点赞"
22
29
  };
23
- const _hoisted_4 = {
30
+ const _hoisted_6 = {
24
31
  class: "icon-item",
25
32
  title: "不喜欢"
26
33
  };
27
- const _hoisted_5 = {
34
+ const _hoisted_7 = {
28
35
  class: "icon-item",
29
36
  title: "复制"
30
37
  };
31
- const _hoisted_6 = {
38
+ const _hoisted_8 = {
32
39
  class: "icon-item",
33
40
  title: "导出"
34
41
  };
35
- const _hoisted_7 = {
42
+ const _hoisted_9 = {
36
43
  class: "icon-item",
37
44
  title: "播放"
38
45
  };
39
- const _hoisted_8 = { class: "stop-dialogue" };
40
- const _hoisted_9 = /* @__PURE__ */ _withScopeId(() => /* @__PURE__ */ createElementVNode("div", { class: "gray-line" }, null, -1));
41
- const _hoisted_10 = { class: "title" };
46
+ const _hoisted_10 = { class: "stop-dialogue" };
42
47
  const _hoisted_11 = /* @__PURE__ */ _withScopeId(() => /* @__PURE__ */ createElementVNode("div", { class: "gray-line" }, null, -1));
48
+ const _hoisted_12 = { class: "title" };
49
+ const _hoisted_13 = /* @__PURE__ */ _withScopeId(() => /* @__PURE__ */ createElementVNode("div", { class: "gray-line" }, null, -1));
43
50
  const _sfc_main = /* @__PURE__ */ defineComponent({
44
51
  __name: "index",
45
52
  setup(__props) {
@@ -52,6 +59,8 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
52
59
  };
53
60
  const messageBox = ref();
54
61
  const scrollToBottom = (force = false) => {
62
+ if (!messageBox.value)
63
+ return;
55
64
  if (force) {
56
65
  messageBox.value.scrollTop = messageBox.value.scrollHeight;
57
66
  return;
@@ -67,58 +76,62 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
67
76
  ref_key: "messageBox",
68
77
  ref: messageBox
69
78
  }, [
70
- (openBlock(true), createElementBlock(Fragment, null, renderList(unref(msgList), (item, index) => {
79
+ (openBlock(true), createElementBlock(Fragment, null, renderList(unref(msgList), (item) => {
71
80
  return openBlock(), createElementBlock("div", {
72
81
  class: "message-group",
73
- key: index
82
+ key: item.uuid
74
83
  }, [
75
84
  createElementVNode("div", _hoisted_1, [
76
- item.isSend ? (openBlock(), createBlock(UserHead, { key: 0 })) : (openBlock(), createBlock(AnswerHead, { key: 1 }))
85
+ item.isSend ? (openBlock(), createBlock(UserHead, { key: 0 })) : (openBlock(), createBlock(AnswerHead, { key: 1 }, {
86
+ avatar: withCtx(() => [
87
+ renderSlot(_ctx.$slots, "avatar", {}, void 0, true)
88
+ ]),
89
+ _: 3
90
+ }))
77
91
  ]),
78
- (openBlock(true), createElementBlock(Fragment, null, renderList(item.msg, (msg, index2) => {
79
- return openBlock(), createElementBlock("div", {
80
- class: normalizeClass({ "msg-content": true }),
81
- key: index2
82
- }, [
83
- createVNode(readMd, {
84
- text: msg,
85
- onPrintOk: printOk,
86
- isPrinting: item.needPrinting,
87
- "onUpdate:isPrinting": ($event) => item.needPrinting = $event,
88
- showCursor: !item.isSend,
89
- scrollToBottom
90
- }, null, 8, ["text", "isPrinting", "onUpdate:isPrinting", "showCursor"]),
91
- !item.isSend ? (openBlock(), createElementBlock("div", _hoisted_2, [
92
- createElementVNode("div", _hoisted_3, [
93
- createVNode(_component_IconifyIconOffline, { icon: unref(data) }, null, 8, ["icon"])
94
- ]),
95
- createElementVNode("div", _hoisted_4, [
96
- createVNode(_component_IconifyIconOffline, { icon: unref(data$1) }, null, 8, ["icon"])
97
- ]),
98
- createElementVNode("div", _hoisted_5, [
99
- createVNode(_component_IconifyIconOffline, { icon: unref(data$2) }, null, 8, ["icon"])
100
- ]),
101
- createElementVNode("div", _hoisted_6, [
102
- createVNode(_component_IconifyIconOffline, { icon: unref(data$3) }, null, 8, ["icon"])
103
- ]),
104
- createElementVNode("div", _hoisted_7, [
105
- createVNode(_component_IconifyIconOffline, { icon: unref(data$4) }, null, 8, ["icon"])
106
- ])
107
- ])) : createCommentVNode("", true)
108
- ]);
109
- }), 128))
92
+ !item.isSend && item.plusName ? (openBlock(), createElementBlock("div", _hoisted_2, [
93
+ createTextVNode(" 使用: "),
94
+ createElementVNode("span", null, toDisplayString(item.plusName.replace(/,/g, " ")), 1)
95
+ ])) : createCommentVNode("", true),
96
+ createElementVNode("div", _hoisted_3, [
97
+ createVNode(readMd, {
98
+ text: item.msg.join(" <br/> "),
99
+ onPrintOk: printOk,
100
+ isPrinting: item.needPrinting,
101
+ "onUpdate:isPrinting": ($event) => item.needPrinting = $event,
102
+ showCursor: !item.isSend,
103
+ scrollToBottom
104
+ }, null, 8, ["text", "isPrinting", "onUpdate:isPrinting", "showCursor"]),
105
+ !item.isSend && !item.needPrinting && item.showOpt ? (openBlock(), createElementBlock("div", _hoisted_4, [
106
+ createElementVNode("div", _hoisted_5, [
107
+ createVNode(_component_IconifyIconOffline, { icon: unref(data) }, null, 8, ["icon"])
108
+ ]),
109
+ createElementVNode("div", _hoisted_6, [
110
+ createVNode(_component_IconifyIconOffline, { icon: unref(data$1) }, null, 8, ["icon"])
111
+ ]),
112
+ createElementVNode("div", _hoisted_7, [
113
+ createVNode(_component_IconifyIconOffline, { icon: unref(data$2) }, null, 8, ["icon"])
114
+ ]),
115
+ createElementVNode("div", _hoisted_8, [
116
+ createVNode(_component_IconifyIconOffline, { icon: unref(data$3) }, null, 8, ["icon"])
117
+ ]),
118
+ createElementVNode("div", _hoisted_9, [
119
+ createVNode(_component_IconifyIconOffline, { icon: unref(data$4) }, null, 8, ["icon"])
120
+ ])
121
+ ])) : createCommentVNode("", true)
122
+ ])
110
123
  ]);
111
124
  }), 128)),
112
- withDirectives(createElementVNode("div", _hoisted_8, [
113
- _hoisted_9,
114
- createElementVNode("div", _hoisted_10, [
125
+ withDirectives(createElementVNode("div", _hoisted_10, [
126
+ _hoisted_11,
127
+ createElementVNode("div", _hoisted_12, [
115
128
  createVNode(_component_IconifyIconOffline, {
116
129
  icon: unref(data$5),
117
130
  class: "stop-icon"
118
131
  }, null, 8, ["icon"]),
119
132
  createTextVNode(" 很抱歉,此对话已达到其限制。让我们开始新的聊天。 ")
120
133
  ]),
121
- _hoisted_11
134
+ _hoisted_13
122
135
  ], 512), [
123
136
  [vShow, unref(stopDialogue)]
124
137
  ])
@@ -1,4 +1,4 @@
1
- const index_vue_vue_type_style_index_0_scoped_47d13b19_lang = "";
1
+ const index_vue_vue_type_style_index_0_scoped_7a7aa418_lang = "";
2
2
  export {
3
- index_vue_vue_type_style_index_0_scoped_47d13b19_lang as default
3
+ index_vue_vue_type_style_index_0_scoped_7a7aa418_lang as default
4
4
  };
@@ -1,7 +1,7 @@
1
1
  import _sfc_main from "./readMd.vue2.mjs";
2
2
  import "./readMd.vue3.mjs";
3
3
  import _export_sfc from "../../_virtual/_plugin-vue_export-helper.mjs";
4
- const readMd = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-a3df75f1"]]);
4
+ const readMd = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-245cfe8e"]]);
5
5
  export {
6
6
  readMd as default
7
7
  };
@@ -1,4 +1,4 @@
1
- import { defineComponent, ref, onMounted, resolveDirective, openBlock, createElementBlock, withDirectives, createElementVNode } from "vue";
1
+ import { defineComponent, ref, computed, onMounted, resolveDirective, openBlock, createElementBlock, withDirectives, createElementVNode, unref } from "vue";
2
2
  import purify from "../../node_modules/.pnpm/dompurify@3.0.10/node_modules/dompurify/dist/purify.es.mjs";
3
3
  import { marked } from "../../node_modules/.pnpm/marked@12.0.1/node_modules/marked/lib/marked.esm.mjs";
4
4
  import isInCode from "./mdInCode.mjs";
@@ -14,13 +14,9 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
14
14
  default: ""
15
15
  },
16
16
  // 是否需要显示光标?比如在消息流结束后是不需要显示光标的
17
- showCursor: {
18
- type: Boolean,
19
- default: false
20
- },
21
17
  speed: {
22
18
  type: Number,
23
- default: 100
19
+ default: 50
24
20
  },
25
21
  isPrinting: {
26
22
  type: Boolean,
@@ -36,44 +32,48 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
36
32
  setup(__props, { emit: emits }) {
37
33
  const props = __props;
38
34
  const CopilotStore = useCopilotStoreHook();
39
- const { sendLonding } = storeToRefs(CopilotStore);
35
+ const { sendLonding, requestSseing } = storeToRefs(CopilotStore);
40
36
  const { setSendLonding } = CopilotStore;
41
37
  const vHtml = ref("");
42
- const isShowCursor = ref(false);
43
38
  let printInterval = null;
44
- const printMessage = (message) => {
39
+ const cursor = '<span class="cursor"></span>';
40
+ const printMessage = () => {
45
41
  let index = 0;
46
42
  printInterval = setInterval(() => {
47
- vHtml.value += message[index];
48
- isShowCursor.value = props.showCursor && !isInCode(vHtml.value);
49
- index++;
50
- props.scrollToBottom();
51
- if (index === message.length || sendLonding.value === false) {
43
+ if (index === getHtml.value.length && requestSseing.value === false || sendLonding.value === false) {
52
44
  clearInterval(printInterval);
53
45
  printInterval = null;
54
46
  emits("update:isPrinting", false);
55
47
  emits("printOk");
56
48
  setSendLonding(false);
57
49
  }
50
+ if (index === getHtml.value.length) {
51
+ return;
52
+ }
53
+ vHtml.value += getHtml.value[index++];
54
+ props.scrollToBottom();
58
55
  }, props.speed);
59
56
  };
60
- const getHtml = () => {
57
+ const getHtml = computed(() => {
61
58
  return purify.sanitize(marked.parse(props.text));
62
- };
59
+ });
63
60
  if (props.isPrinting) {
64
- printMessage(getHtml());
61
+ printMessage();
65
62
  } else {
66
- vHtml.value = getHtml();
63
+ vHtml.value = getHtml.value;
67
64
  emits("printOk");
68
65
  }
69
66
  onMounted(() => {
70
67
  props.scrollToBottom(true);
71
68
  });
69
+ const resultHtml = computed(() => {
70
+ return vHtml.value + (props.isPrinting && !isInCode(vHtml.value) ? cursor : "");
71
+ });
72
72
  return (_ctx, _cache) => {
73
73
  const _directive_highlight = resolveDirective("highlight");
74
74
  return openBlock(), createElementBlock("div", null, [
75
75
  withDirectives(createElementVNode("div", {
76
- innerHTML: vHtml.value,
76
+ innerHTML: unref(resultHtml),
77
77
  class: "markdown"
78
78
  }, null, 8, _hoisted_1), [
79
79
  [_directive_highlight]
@@ -1,4 +1,4 @@
1
- const readMd_vue_vue_type_style_index_0_scoped_a3df75f1_lang = "";
1
+ const readMd_vue_vue_type_style_index_0_scoped_245cfe8e_lang = "";
2
2
  export {
3
- readMd_vue_vue_type_style_index_0_scoped_a3df75f1_lang as default
3
+ readMd_vue_vue_type_style_index_0_scoped_245cfe8e_lang as default
4
4
  };
@@ -1,7 +1,7 @@
1
1
  import _sfc_main from "./index.vue2.mjs";
2
2
  import "./index.vue3.mjs";
3
3
  import _export_sfc from "../_virtual/_plugin-vue_export-helper.mjs";
4
- const KgCopilot = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-954dc002"]]);
4
+ const KgCopilot = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-1a3c135c"]]);
5
5
  export {
6
6
  KgCopilot as default
7
7
  };
@@ -1,4 +1,4 @@
1
- import { defineComponent, toRefs, onMounted, openBlock, createElementBlock, createElementVNode, createVNode, toRaw } from "vue";
1
+ import { defineComponent, toRefs, onMounted, useSlots, openBlock, createElementBlock, createElementVNode, createVNode, createSlots, renderList, unref, withCtx, renderSlot, toRaw } from "vue";
2
2
  import dialogue from "./dialogue/index.vue.mjs";
3
3
  import "../style/tailwind.css.mjs";
4
4
  import "../style/index.scss.mjs";
@@ -20,20 +20,24 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
20
20
  sendUrl: null,
21
21
  getkitsUrl: null,
22
22
  token: null,
23
- plugins: null
23
+ plugins: null,
24
+ initText: { default: "你好,我是AI智能助手" },
25
+ aiName: { default: "Copilot" }
24
26
  },
25
27
  setup(__props, { expose }) {
26
28
  const props = __props;
27
29
  const CopilotStore = useCopilotStoreHook();
28
30
  const { searchText, msgList } = storeToRefs(CopilotStore);
29
31
  const { initCopilot, setSearchText, setMsgList } = CopilotStore;
30
- const { sendUrl, getkitsUrl, token, plugins } = toRefs(props);
32
+ const { sendUrl, getkitsUrl, token, plugins, initText, aiName } = toRefs(props);
31
33
  onMounted(() => {
32
34
  initCopilot(
33
35
  sendUrl.value,
34
36
  getkitsUrl.value,
35
- "e426f153f90a4d559a3559778bfea595",
36
- [{ name: "获取简报", url: "chat/url/report" }]
37
+ token.value,
38
+ plugins.value,
39
+ initText.value,
40
+ aiName.value
37
41
  );
38
42
  });
39
43
  const getSearchText = () => {
@@ -48,10 +52,20 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
48
52
  getMsgList,
49
53
  setMsgList
50
54
  });
55
+ const slots = useSlots();
51
56
  return (_ctx, _cache) => {
52
57
  return openBlock(), createElementBlock("div", _hoisted_1, [
53
58
  createElementVNode("div", _hoisted_2, [
54
- createVNode(dialogue),
59
+ createVNode(dialogue, null, createSlots({ _: 2 }, [
60
+ renderList(unref(slots), (item, key) => {
61
+ return {
62
+ name: key,
63
+ fn: withCtx(() => [
64
+ renderSlot(_ctx.$slots, key, {}, void 0, true)
65
+ ])
66
+ };
67
+ })
68
+ ]), 1024),
55
69
  createElementVNode("div", _hoisted_3, [
56
70
  createVNode(CopiFooter)
57
71
  ])
@@ -1,4 +1,4 @@
1
- const index_vue_vue_type_style_index_0_scoped_954dc002_lang = "";
1
+ const index_vue_vue_type_style_index_0_scoped_1a3c135c_lang = "";
2
2
  export {
3
- index_vue_vue_type_style_index_0_scoped_954dc002_lang as default
3
+ index_vue_vue_type_style_index_0_scoped_1a3c135c_lang as default
4
4
  };
@@ -1,16 +1,37 @@
1
1
  import { http } from "../utils/http/index.mjs";
2
2
  import { baseUrlApi } from "./project.mjs";
3
+ import { fetchEventSource } from "../node_modules/.pnpm/@microsoft_fetch-event-source@2.0.1/node_modules/@microsoft/fetch-event-source/lib/esm/fetch.mjs";
3
4
  const sendMsgApi = (sendUrl, data) => {
4
5
  return http.request("post", baseUrlApi(sendUrl), {
5
6
  data,
6
7
  timeout: 6e4
7
8
  });
8
9
  };
9
- const getReport = (sendUrl, data) => {
10
- return http.request("post", baseUrlApi(sendUrl), {
11
- data,
12
- timeout: 6e4
10
+ const getReport = (param) => {
11
+ const controller = new AbortController();
12
+ fetchEventSource(param.sendUrl, {
13
+ method: "POST",
14
+ body: JSON.stringify(param.data),
15
+ signal: controller.signal,
16
+ openWhenHidden: true,
17
+ headers: {
18
+ accessToken: window["kg_token"],
19
+ "Content-Type": "application/json"
20
+ },
21
+ onmessage(msg) {
22
+ param.onmessage(JSON.parse(msg.data));
23
+ },
24
+ onclose() {
25
+ controller.abort();
26
+ },
27
+ onerror(err) {
28
+ param.onerror(err);
29
+ throw err;
30
+ }
13
31
  });
32
+ return () => {
33
+ controller.abort();
34
+ };
14
35
  };
15
36
  export {
16
37
  getReport,
@@ -51,7 +51,7 @@ HighlightJS.registerLanguage("basic", basic);
51
51
  HighlightJS.registerLanguage("xml", xml);
52
52
  HighlightJS.registerLanguage("apache", apache);
53
53
  const highlightByEl = (e) => {
54
- const blocks = e.querySelectorAll("code");
54
+ const blocks = e.querySelectorAll("pre code");
55
55
  blocks.forEach((block) => {
56
56
  HighlightJS.highlightBlock(block);
57
57
  });
@@ -0,0 +1,90 @@
1
+ import { getBytes, getLines, getMessages } from "./parse.mjs";
2
+ var __rest = globalThis && globalThis.__rest || function(s, e) {
3
+ var t = {};
4
+ for (var p in s)
5
+ if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
6
+ t[p] = s[p];
7
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
8
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
9
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
10
+ t[p[i]] = s[p[i]];
11
+ }
12
+ return t;
13
+ };
14
+ const EventStreamContentType = "text/event-stream";
15
+ const DefaultRetryInterval = 1e3;
16
+ const LastEventId = "last-event-id";
17
+ function fetchEventSource(input, _a) {
18
+ var { signal: inputSignal, headers: inputHeaders, onopen: inputOnOpen, onmessage, onclose, onerror, openWhenHidden, fetch: inputFetch } = _a, rest = __rest(_a, ["signal", "headers", "onopen", "onmessage", "onclose", "onerror", "openWhenHidden", "fetch"]);
19
+ return new Promise((resolve, reject) => {
20
+ const headers = Object.assign({}, inputHeaders);
21
+ if (!headers.accept) {
22
+ headers.accept = EventStreamContentType;
23
+ }
24
+ let curRequestController;
25
+ function onVisibilityChange() {
26
+ curRequestController.abort();
27
+ if (!document.hidden) {
28
+ create();
29
+ }
30
+ }
31
+ if (!openWhenHidden) {
32
+ document.addEventListener("visibilitychange", onVisibilityChange);
33
+ }
34
+ let retryInterval = DefaultRetryInterval;
35
+ let retryTimer = 0;
36
+ function dispose() {
37
+ document.removeEventListener("visibilitychange", onVisibilityChange);
38
+ window.clearTimeout(retryTimer);
39
+ curRequestController.abort();
40
+ }
41
+ inputSignal === null || inputSignal === void 0 ? void 0 : inputSignal.addEventListener("abort", () => {
42
+ dispose();
43
+ resolve();
44
+ });
45
+ const fetch = inputFetch !== null && inputFetch !== void 0 ? inputFetch : window.fetch;
46
+ const onopen = inputOnOpen !== null && inputOnOpen !== void 0 ? inputOnOpen : defaultOnOpen;
47
+ async function create() {
48
+ var _a2;
49
+ curRequestController = new AbortController();
50
+ try {
51
+ const response = await fetch(input, Object.assign(Object.assign({}, rest), { headers, signal: curRequestController.signal }));
52
+ await onopen(response);
53
+ await getBytes(response.body, getLines(getMessages((id) => {
54
+ if (id) {
55
+ headers[LastEventId] = id;
56
+ } else {
57
+ delete headers[LastEventId];
58
+ }
59
+ }, (retry) => {
60
+ retryInterval = retry;
61
+ }, onmessage)));
62
+ onclose === null || onclose === void 0 ? void 0 : onclose();
63
+ dispose();
64
+ resolve();
65
+ } catch (err) {
66
+ if (!curRequestController.signal.aborted) {
67
+ try {
68
+ const interval = (_a2 = onerror === null || onerror === void 0 ? void 0 : onerror(err)) !== null && _a2 !== void 0 ? _a2 : retryInterval;
69
+ window.clearTimeout(retryTimer);
70
+ retryTimer = window.setTimeout(create, interval);
71
+ } catch (innerErr) {
72
+ dispose();
73
+ reject(innerErr);
74
+ }
75
+ }
76
+ }
77
+ }
78
+ create();
79
+ });
80
+ }
81
+ function defaultOnOpen(response) {
82
+ const contentType = response.headers.get("content-type");
83
+ if (!(contentType === null || contentType === void 0 ? void 0 : contentType.startsWith(EventStreamContentType))) {
84
+ throw new Error(`Expected content-type to be ${EventStreamContentType}, Actual: ${contentType}`);
85
+ }
86
+ }
87
+ export {
88
+ EventStreamContentType,
89
+ fetchEventSource
90
+ };
@@ -0,0 +1,109 @@
1
+ async function getBytes(stream, onChunk) {
2
+ const reader = stream.getReader();
3
+ let result;
4
+ while (!(result = await reader.read()).done) {
5
+ onChunk(result.value);
6
+ }
7
+ }
8
+ function getLines(onLine) {
9
+ let buffer;
10
+ let position;
11
+ let fieldLength;
12
+ let discardTrailingNewline = false;
13
+ return function onChunk(arr) {
14
+ if (buffer === void 0) {
15
+ buffer = arr;
16
+ position = 0;
17
+ fieldLength = -1;
18
+ } else {
19
+ buffer = concat(buffer, arr);
20
+ }
21
+ const bufLength = buffer.length;
22
+ let lineStart = 0;
23
+ while (position < bufLength) {
24
+ if (discardTrailingNewline) {
25
+ if (buffer[position] === 10) {
26
+ lineStart = ++position;
27
+ }
28
+ discardTrailingNewline = false;
29
+ }
30
+ let lineEnd = -1;
31
+ for (; position < bufLength && lineEnd === -1; ++position) {
32
+ switch (buffer[position]) {
33
+ case 58:
34
+ if (fieldLength === -1) {
35
+ fieldLength = position - lineStart;
36
+ }
37
+ break;
38
+ case 13:
39
+ discardTrailingNewline = true;
40
+ case 10:
41
+ lineEnd = position;
42
+ break;
43
+ }
44
+ }
45
+ if (lineEnd === -1) {
46
+ break;
47
+ }
48
+ onLine(buffer.subarray(lineStart, lineEnd), fieldLength);
49
+ lineStart = position;
50
+ fieldLength = -1;
51
+ }
52
+ if (lineStart === bufLength) {
53
+ buffer = void 0;
54
+ } else if (lineStart !== 0) {
55
+ buffer = buffer.subarray(lineStart);
56
+ position -= lineStart;
57
+ }
58
+ };
59
+ }
60
+ function getMessages(onId, onRetry, onMessage) {
61
+ let message = newMessage();
62
+ const decoder = new TextDecoder();
63
+ return function onLine(line, fieldLength) {
64
+ if (line.length === 0) {
65
+ onMessage === null || onMessage === void 0 ? void 0 : onMessage(message);
66
+ message = newMessage();
67
+ } else if (fieldLength > 0) {
68
+ const field = decoder.decode(line.subarray(0, fieldLength));
69
+ const valueOffset = fieldLength + (line[fieldLength + 1] === 32 ? 2 : 1);
70
+ const value = decoder.decode(line.subarray(valueOffset));
71
+ switch (field) {
72
+ case "data":
73
+ message.data = message.data ? message.data + "\n" + value : value;
74
+ break;
75
+ case "event":
76
+ message.event = value;
77
+ break;
78
+ case "id":
79
+ onId(message.id = value);
80
+ break;
81
+ case "retry":
82
+ const retry = parseInt(value, 10);
83
+ if (!isNaN(retry)) {
84
+ onRetry(message.retry = retry);
85
+ }
86
+ break;
87
+ }
88
+ }
89
+ };
90
+ }
91
+ function concat(a, b) {
92
+ const res = new Uint8Array(a.length + b.length);
93
+ res.set(a);
94
+ res.set(b, a.length);
95
+ return res;
96
+ }
97
+ function newMessage() {
98
+ return {
99
+ data: "",
100
+ event: "",
101
+ id: "",
102
+ retry: void 0
103
+ };
104
+ }
105
+ export {
106
+ getBytes,
107
+ getLines,
108
+ getMessages
109
+ };