@vunk/plus 1.3.9 → 1.3.11

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.
@@ -1,12 +1,12 @@
1
1
  import type { AnyFunc } from '@vunk/shared';
2
2
  import type { PropType } from 'vue';
3
- import type { AgentChatContext, AgentMessage, Parser } from './types';
3
+ import type { AgentChatContext, AgentMessage } from './types';
4
4
  declare const _default: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
5
5
  request: {
6
6
  type: PropType<AnyFunc>;
7
7
  };
8
8
  parser: {
9
- type: PropType<Parser>;
9
+ type: PropType<AnyFunc>;
10
10
  };
11
11
  }>, import("vue").Slot<any> | undefined, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
12
12
  load: (e: AgentChatContext) => {
@@ -27,7 +27,7 @@ declare const _default: import("vue").DefineComponent<import("vue").ExtractPropT
27
27
  type: PropType<AnyFunc>;
28
28
  };
29
29
  parser: {
30
- type: PropType<Parser>;
30
+ type: PropType<AnyFunc>;
31
31
  };
32
32
  }>> & Readonly<{
33
33
  onLoad?: ((e: {
@@ -19,10 +19,15 @@ export type AgentMessage = BubbleMessage & {
19
19
  export type BubbleMessage = Partial<BubbleListItemProps> & {
20
20
  role: string;
21
21
  content: string;
22
+ /**
23
+ * @description 服务端请求是否完成
24
+ */
22
25
  seviceEnd?: boolean;
23
26
  thinkingStatus?: 'start' | 'thinking' | 'end' | 'error';
24
27
  thinkingContent?: string;
25
28
  meta?: NormalObject;
29
+ abortController?: AbortController;
30
+ [key: string]: any;
26
31
  };
27
32
  export type BubbleItem = BubbleItemBasic & __VkBubbleTemplates.RenderItem;
28
33
  export type RoleMedia = RoleMediaBasic & __VkBubbleTemplates.RenderItem;
@@ -98,6 +98,7 @@ const props = {
98
98
  };
99
99
  const emits = {
100
100
  "setData": (e) => e,
101
+ "interrupt": null,
101
102
  "update:broadcasting": (_) => true,
102
103
  "update:completed": (_) => true,
103
104
  "update:error": (_) => true
@@ -3690,7 +3691,7 @@ var _sfc_main = defineComponent({
3690
3691
  },
3691
3692
  props,
3692
3693
  emits,
3693
- setup(props2, { emit }) {
3694
+ setup(props2, { emit, expose }) {
3694
3695
  const _data = ref([]);
3695
3696
  const theData = computed(() => {
3696
3697
  return props2.data ?? _data.value;
@@ -3821,6 +3822,14 @@ var _sfc_main = defineComponent({
3821
3822
  }
3822
3823
  }
3823
3824
  }
3825
+ const isInterrupted = ref(false);
3826
+ const thePause = computed(() => {
3827
+ return isInterrupted.value || props2.pause;
3828
+ });
3829
+ function interrupt() {
3830
+ isInterrupted.value = true;
3831
+ emit("interrupt");
3832
+ }
3824
3833
  const isBroadcasting = computed(() => {
3825
3834
  return theData.value.some(
3826
3835
  (item) => item.broadcast === Broadcast.playing
@@ -3854,13 +3863,17 @@ var _sfc_main = defineComponent({
3854
3863
  const isPrevFulfilled = isPrevParagraphFulfilled(currentIndex2);
3855
3864
  return isPrevFulfilled;
3856
3865
  }
3866
+ expose({
3867
+ interrupt
3868
+ });
3857
3869
  return {
3858
3870
  theData,
3859
3871
  ParagraphStatus,
3860
3872
  fulfilledTextValue,
3861
3873
  isPrevParagraphFulfilled,
3862
3874
  isParagraphEnabled,
3863
- processingParagraph
3875
+ processingParagraph,
3876
+ thePause
3864
3877
  };
3865
3878
  }
3866
3879
  });
@@ -3875,11 +3888,10 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
3875
3888
  null,
3876
3889
  [
3877
3890
  renderSlot(_ctx.$slots, "default", { paragraphs: _ctx.theData }, () => [
3878
- createCommentVNode(' <ElButton @click="() => console.log(theData)">\n log\n </ElButton> '),
3879
3891
  createVNode(_component_VkTypingMarkdown, {
3880
3892
  source: _ctx.fulfilledTextValue,
3881
3893
  delay: 200,
3882
- pause: _ctx.pause
3894
+ pause: _ctx.thePause
3883
3895
  }, null, 8, ["source", "pause"])
3884
3896
  ]),
3885
3897
  (openBlock(true), createElementBlock(
@@ -3901,14 +3913,14 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
3901
3913
  createVNode(_component_HowlerSpeechView, {
3902
3914
  render: _ctx.render,
3903
3915
  url: item.url,
3904
- pause: _ctx.pause,
3916
+ pause: _ctx.thePause,
3905
3917
  deferred,
3906
3918
  data: item
3907
3919
  }, null, 8, ["render", "url", "pause", "deferred", "data"]),
3908
3920
  _ctx.webSpeech ? (openBlock(), createBlock(_component_WebSpeechView, {
3909
3921
  key: 0,
3910
3922
  render: _ctx.render,
3911
- pause: _ctx.pause,
3923
+ pause: _ctx.thePause,
3912
3924
  deferred,
3913
3925
  data: item
3914
3926
  }, null, 8, ["render", "pause", "deferred", "data"])) : createCommentVNode("v-if", true)
@@ -95,6 +95,7 @@ export declare const props: {
95
95
  };
96
96
  export declare const emits: {
97
97
  setData: (e: SetDataEvent) => SetDataEvent;
98
+ interrupt: null;
98
99
  'update:broadcasting': (_: boolean) => boolean;
99
100
  'update:completed': (_: boolean) => boolean;
100
101
  'update:error': (_: boolean) => boolean;
@@ -72,8 +72,10 @@ declare const _default: import("vue").DefineComponent<import("vue").ExtractPropT
72
72
  isPrevParagraphFulfilled: (currentIndex: number) => boolean;
73
73
  isParagraphEnabled: (currentIndex: number) => boolean;
74
74
  processingParagraph: (paragraph: Paragraph) => Promise<void> | undefined;
75
+ thePause: import("vue").ComputedRef<boolean>;
75
76
  }, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
76
77
  setData: (e: SetDataEvent) => SetDataEvent;
78
+ interrupt: null;
77
79
  'update:broadcasting': (_: boolean) => boolean;
78
80
  'update:completed': (_: boolean) => boolean;
79
81
  'update:error': (_: boolean) => boolean;
@@ -142,6 +144,7 @@ declare const _default: import("vue").DefineComponent<import("vue").ExtractPropT
142
144
  };
143
145
  }>> & Readonly<{
144
146
  onSetData?: ((e: SetDataEvent) => any) | undefined;
147
+ onInterrupt?: ((...args: any[]) => any) | undefined;
145
148
  "onUpdate:broadcasting"?: ((_: boolean) => any) | undefined;
146
149
  "onUpdate:completed"?: ((_: boolean) => any) | undefined;
147
150
  "onUpdate:error"?: ((_: boolean) => any) | undefined;
@@ -35,8 +35,8 @@ declare const _default: import("vue").DefineComponent<import("vue").ExtractPropT
35
35
  default: () => string[];
36
36
  };
37
37
  }>, {
38
- initRenderData: (emitSetData: any, props: any) => void;
39
- typed: (e: import("./types").Item) => import("./types").Item;
38
+ setRef: (emitSetData: (e: import("@vunk/core").SetDataEvent) => void, props: import("./types").Item, el: any) => void;
39
+ initRenderData: (emitSetData: (e: import("@vunk/core").SetDataEvent) => void, props: import("./types").Item) => void;
40
40
  readonly VkBroadcastingMarkdown: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
41
41
  render: {
42
42
  type: import("vue").PropType<(text: string) => string>;
@@ -107,8 +107,10 @@ declare const _default: import("vue").DefineComponent<import("vue").ExtractPropT
107
107
  isPrevParagraphFulfilled: (currentIndex: number) => boolean;
108
108
  isParagraphEnabled: (currentIndex: number) => boolean;
109
109
  processingParagraph: (paragraph: import("../../broadcasting-markdown/src/types").Paragraph) => Promise<void> | undefined;
110
+ thePause: import("vue").ComputedRef<boolean>;
110
111
  }, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
111
112
  setData: (e: import("@vunk/core").SetDataEvent) => import("@vunk/core").SetDataEvent;
113
+ interrupt: null;
112
114
  'update:broadcasting': (_: boolean) => boolean;
113
115
  'update:completed': (_: boolean) => boolean;
114
116
  'update:error': (_: boolean) => boolean;
@@ -177,6 +179,7 @@ declare const _default: import("vue").DefineComponent<import("vue").ExtractPropT
177
179
  };
178
180
  }>> & Readonly<{
179
181
  onSetData?: ((e: import("@vunk/core").SetDataEvent) => any) | undefined;
182
+ onInterrupt?: ((...args: any[]) => any) | undefined;
180
183
  "onUpdate:broadcasting"?: ((_: boolean) => any) | undefined;
181
184
  "onUpdate:completed"?: ((_: boolean) => any) | undefined;
182
185
  "onUpdate:error"?: ((_: boolean) => any) | undefined;
@@ -1,4 +1,4 @@
1
- import { defineComponent, createElementBlock, openBlock, Fragment, createVNode, unref, withCtx, createBlock, createCommentVNode } from 'vue';
1
+ import { defineComponent, createElementBlock, openBlock, Fragment, createVNode, unref, withCtx, createBlock, createCommentVNode, markRaw } from 'vue';
2
2
  import { VkBroadcastingMarkdown } from '@vunk/plus/components/broadcasting-markdown';
3
3
  import { VkRendererTemplate } from '@vunk/core/components/renderer-template';
4
4
  import { Thinking, Typewriter } from 'vue-element-plus-x';
@@ -18,6 +18,12 @@ var _sfc_main = /* @__PURE__ */ defineComponent({
18
18
  }
19
19
  },
20
20
  setup(__props) {
21
+ function setRef(emitSetData, props, el) {
22
+ emitSetData?.({
23
+ k: [props.key, "elRef"],
24
+ v: markRaw(el)
25
+ });
26
+ }
21
27
  function initRenderData(emitSetData, props) {
22
28
  emitSetData?.({
23
29
  k: [props.key, "meta"],
@@ -25,7 +31,7 @@ var _sfc_main = /* @__PURE__ */ defineComponent({
25
31
  });
26
32
  emitSetData?.({
27
33
  k: [props.key, "templateType"],
28
- v: "VkBroadcastingMarkdown"
34
+ v: props.templateType
29
35
  });
30
36
  }
31
37
  return (_ctx, _cache) => {
@@ -34,19 +40,28 @@ var _sfc_main = /* @__PURE__ */ defineComponent({
34
40
  null,
35
41
  [
36
42
  createVNode(unref(VkRendererTemplate), { type: "Typewriter" }, {
37
- default: withCtx(({ props, emitSetData }) => [
43
+ default: withCtx(({ emitSetData, props }) => [
38
44
  props.thinkingContent && __props.modules?.includes("Thinking") ? (openBlock(), createBlock(unref(Thinking), {
39
45
  key: 0,
40
46
  content: props.thinkingContent,
41
47
  status: props.thinkingStatus
42
48
  }, null, 8, ["content", "status"])) : createCommentVNode("v-if", true),
43
49
  createVNode(unref(Typewriter), {
50
+ ref: (el) => setRef(emitSetData, props, el),
44
51
  content: props.content,
45
52
  typing: props.typing,
46
53
  "is-markdown": props.isMarkdown,
47
54
  "is-fog": props.isFog,
48
- onVnodeMounted: ($event) => initRenderData(emitSetData, props)
49
- }, null, 8, ["content", "typing", "is-markdown", "is-fog", "onVnodeMounted"])
55
+ onVnodeMounted: ($event) => initRenderData(emitSetData, props),
56
+ onStart: () => emitSetData({
57
+ k: [props.key, "completed"],
58
+ v: false
59
+ }),
60
+ onFinish: () => emitSetData({
61
+ k: [props.key, "completed"],
62
+ v: true
63
+ })
64
+ }, null, 8, ["content", "typing", "is-markdown", "is-fog", "onVnodeMounted", "onStart", "onFinish"])
50
65
  ]),
51
66
  _: 1
52
67
  /* STABLE */
@@ -59,6 +74,7 @@ var _sfc_main = /* @__PURE__ */ defineComponent({
59
74
  status: props.thinkingStatus
60
75
  }, null, 8, ["content", "status"])) : createCommentVNode("v-if", true),
61
76
  createVNode(unref(VkBroadcastingMarkdown), {
77
+ ref: (el) => setRef(emitSetData, props, el),
62
78
  source: props.content,
63
79
  "keep-read": !props.seviceEnd,
64
80
  "text-to-speech": __props.textToSpeech,
@@ -1,7 +1,7 @@
1
- import type { __VkAgentChatProvider } from '@vunk/plus/components/agent-chat-provider';
2
1
  import type { __VkBroadcastingMarkdown } from '@vunk/plus/components/broadcasting-markdown';
3
2
  import type { __VkBubbleList } from '@vunk/plus/components/bubble-list';
4
- import type { PropType } from 'vue';
3
+ import type { SetDataEvent } from '@vunk/core';
4
+ import { type PropType } from 'vue';
5
5
  declare const _default: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
6
6
  textToSpeech: {
7
7
  type: PropType<__VkBroadcastingMarkdown.TextToSpeech>;
@@ -11,8 +11,8 @@ declare const _default: import("vue").DefineComponent<import("vue").ExtractPropT
11
11
  default: () => string[];
12
12
  };
13
13
  }>, {
14
- initRenderData: (emitSetData: any, props: any) => void;
15
- typed: (e: __VkBubbleList.Item) => __VkAgentChatProvider.BubbleItem;
14
+ setRef: (emitSetData: (e: SetDataEvent) => void, props: __VkBubbleList.Item, el: any) => void;
15
+ initRenderData: (emitSetData: (e: SetDataEvent) => void, props: __VkBubbleList.Item) => void;
16
16
  readonly VkBroadcastingMarkdown: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
17
17
  render: {
18
18
  type: PropType<(text: string) => string>;
@@ -83,8 +83,10 @@ declare const _default: import("vue").DefineComponent<import("vue").ExtractPropT
83
83
  isPrevParagraphFulfilled: (currentIndex: number) => boolean;
84
84
  isParagraphEnabled: (currentIndex: number) => boolean;
85
85
  processingParagraph: (paragraph: __VkBroadcastingMarkdown.Paragraph) => Promise<void> | undefined;
86
+ thePause: import("vue").ComputedRef<boolean>;
86
87
  }, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
87
- setData: (e: import("@vunk/core").SetDataEvent) => import("@vunk/core").SetDataEvent;
88
+ setData: (e: SetDataEvent) => SetDataEvent;
89
+ interrupt: null;
88
90
  'update:broadcasting': (_: boolean) => boolean;
89
91
  'update:completed': (_: boolean) => boolean;
90
92
  'update:error': (_: boolean) => boolean;
@@ -152,7 +154,8 @@ declare const _default: import("vue").DefineComponent<import("vue").ExtractPropT
152
154
  default: undefined;
153
155
  };
154
156
  }>> & Readonly<{
155
- onSetData?: ((e: import("@vunk/core").SetDataEvent) => any) | undefined;
157
+ onSetData?: ((e: SetDataEvent) => any) | undefined;
158
+ onInterrupt?: ((...args: any[]) => any) | undefined;
156
159
  "onUpdate:broadcasting"?: ((_: boolean) => any) | undefined;
157
160
  "onUpdate:completed"?: ((_: boolean) => any) | undefined;
158
161
  "onUpdate:error"?: ((_: boolean) => any) | undefined;
@@ -27,4 +27,8 @@ export interface RenderDataRecord {
27
27
  * @description 发生错误的
28
28
  */
29
29
  error?: boolean;
30
+ /**
31
+ * @description 组件实例
32
+ */
33
+ elRef?: any;
30
34
  }
@@ -1,13 +1,13 @@
1
- import { defineComponent, ref, computed, createElementBlock, openBlock, createElementVNode, createVNode, unref, withCtx, createCommentVNode, withDirectives, Fragment, vShow, renderSlot, nextTick } from 'vue';
1
+ import { defineComponent, defineAsyncComponent, ref, computed, createElementBlock, openBlock, createElementVNode, createVNode, unref, withCtx, createCommentVNode, withDirectives, Fragment, vShow, renderSlot, normalizeProps, guardReactiveProps, nextTick } from 'vue';
2
2
  import { useAgentChat } from '@vunk/plus/components/agent-chat-provider';
3
3
  import { VkBubbleList } from '@vunk/plus/components/bubble-list';
4
- import { VkRecorderButton } from '@vunk/plus/components/recorder-button';
5
4
  import { VkSender } from '@vunk/plus/components/sender';
6
5
  import { VkKeyboardAvatar } from '@vunk/plus/icons/keyboard';
7
6
  import { VkVoiceAvatar } from '@vunk/plus/icons/voice';
8
7
  import { VkDuplex } from '@vunk/core';
9
8
  import { VkRendererData } from '@vunk/core/components/renderer-data';
10
9
  import { useDataComputed, useDeferred } from '@vunk/core/composables';
10
+ import { isNotEmptyObject } from '@vunk/shared/object';
11
11
 
12
12
  var InputType = /* @__PURE__ */ ((InputType2) => {
13
13
  InputType2["Voice"] = "voice";
@@ -47,6 +47,7 @@ var _sfc_main = /* @__PURE__ */ defineComponent({
47
47
  setup(__props, { emit: __emit }) {
48
48
  const props = __props;
49
49
  const emit = __emit;
50
+ const VkRecorderButton = defineAsyncComponent(() => import('@vunk/plus/components/recorder-button'));
50
51
  const [bubbleData, setBubbleData] = useDataComputed({}, props, emit);
51
52
  const mainRef = ref();
52
53
  const inputType = ref(InputType.Text);
@@ -56,11 +57,10 @@ var _sfc_main = /* @__PURE__ */ defineComponent({
56
57
  const { simplicity } = useAgentChat();
57
58
  const { items: bubbleItems, onRequest } = simplicity;
58
59
  const lastBubbleData = computed(() => {
59
- const key = bubbleItems.value.at(-1)?.key;
60
- if (key && bubbleData.value[key]) {
61
- return bubbleData.value[key];
62
- }
63
- return {};
60
+ return getBubbleDataAt(-1);
61
+ });
62
+ const clientLoading = computed(() => {
63
+ return isNotEmptyObject(lastBubbleData.value) && lastBubbleData.value.completed !== true;
64
64
  });
65
65
  const senderDisabled = computed(() => {
66
66
  if (lastBubbleData.value.error === true) {
@@ -79,6 +79,24 @@ var _sfc_main = /* @__PURE__ */ defineComponent({
79
79
  bubbleListDef.value?.scrollToBottom();
80
80
  }, 400);
81
81
  }
82
+ function onCancel() {
83
+ const lastBubble = bubbleItems.value.at(-1);
84
+ if (!lastBubble)
85
+ return;
86
+ lastBubble.abortController?.abort();
87
+ const lastBubbleData2 = bubbleData.value[lastBubble.key];
88
+ lastBubbleData2.elRef?.interrupt();
89
+ nextTick(() => {
90
+ lastBubbleData2.completed = true;
91
+ });
92
+ }
93
+ function getBubbleDataAt(index) {
94
+ const bubble = bubbleItems.value.at(index);
95
+ if (bubble?.key && bubbleData.value[bubble.key]) {
96
+ return bubbleData.value[bubble.key];
97
+ }
98
+ return {};
99
+ }
82
100
  return (_ctx, _cache) => {
83
101
  return openBlock(), createElementBlock("div", _hoisted_1, [
84
102
  createElementVNode(
@@ -104,11 +122,17 @@ var _sfc_main = /* @__PURE__ */ defineComponent({
104
122
  "el-ref": unref(bubbleListReslove),
105
123
  items: unref(bubbleItems),
106
124
  "text-to-speech": _ctx.textToSpeech
107
- }, null, 8, ["el-ref", "items", "text-to-speech"])
125
+ }, {
126
+ footer: withCtx((e) => [
127
+ renderSlot(_ctx.$slots, "bubble_footer", normalizeProps(guardReactiveProps(e)))
128
+ ]),
129
+ _: 3
130
+ /* FORWARDED */
131
+ }, 8, ["el-ref", "items", "text-to-speech"])
108
132
  ])
109
133
  ]),
110
- _: 1
111
- /* STABLE */
134
+ _: 3
135
+ /* FORWARDED */
112
136
  }, 8, ["data", "onSetData"])
113
137
  ]),
114
138
  two: withCtx(() => [
@@ -159,15 +183,17 @@ var _sfc_main = /* @__PURE__ */ defineComponent({
159
183
  "onUpdate:modelValue": _cache[2] || (_cache[2] = ($event) => content.value = $event),
160
184
  "auto-size": true,
161
185
  placeholder: "\u8BF7\u8F93\u5165\u5185\u5BB9",
162
- disabled: senderDisabled.value,
163
- onSubmit
164
- }, null, 8, ["modelValue", "disabled"]), [
186
+ "send-disabled": senderDisabled.value,
187
+ loading: clientLoading.value,
188
+ onSubmit,
189
+ onCancel
190
+ }, null, 8, ["modelValue", "send-disabled", "loading"]), [
165
191
  [vShow, inputType.value === unref(InputType).Text]
166
192
  ])
167
193
  ])
168
194
  ]),
169
- _: 1
170
- /* STABLE */
195
+ _: 3
196
+ /* FORWARDED */
171
197
  })
172
198
  ],
173
199
  512