vue-element-ui-x 0.1.9-beta → 0.2.0

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 (82) hide show
  1. package/lib/components/Attachments/index.js +4 -4
  2. package/lib/components/Bubble/index.js +47 -34
  3. package/lib/components/BubbleList/index.js +65 -59
  4. package/lib/components/Conversations/index.js +29 -66
  5. package/lib/components/FilesCard/index.js +1 -1
  6. package/lib/components/Prompts/index.js +23 -23
  7. package/lib/components/Sender/index.js +6 -6
  8. package/lib/components/Think/index.js +1 -1
  9. package/lib/components/Thinking/index.js +5 -5
  10. package/lib/components/ThoughtChain/index.js +52 -41
  11. package/lib/components/Typewriter/index.js +46 -33
  12. package/lib/components/Welcome/index.js +5 -5
  13. package/lib/index.common.js +1 -1
  14. package/lib/index.esm.js +1 -1
  15. package/lib/index.js +266 -463
  16. package/lib/index.umd.js +1 -1
  17. package/lib/mixins/index.js +105 -16
  18. package/package.json +1 -1
  19. package/src/components/Attachments/index.js +8 -8
  20. package/src/components/Bubble/index.js +6 -6
  21. package/src/components/Bubble/src/main.vue +299 -299
  22. package/src/components/BubbleList/index.js +8 -8
  23. package/src/components/BubbleList/src/loading.vue +75 -75
  24. package/src/components/BubbleList/src/main.vue +461 -466
  25. package/src/components/Conversations/index.js +8 -8
  26. package/src/components/Conversations/src/components/item.vue +13 -34
  27. package/src/components/Conversations/src/main.vue +4 -18
  28. package/src/components/FilesCard/index.js +8 -8
  29. package/src/components/FilesCard/src/fileSvg/audio.vue +38 -38
  30. package/src/components/FilesCard/src/fileSvg/code.vue +35 -35
  31. package/src/components/FilesCard/src/fileSvg/database.vue +94 -94
  32. package/src/components/FilesCard/src/fileSvg/excel.vue +38 -38
  33. package/src/components/FilesCard/src/fileSvg/file.vue +40 -40
  34. package/src/components/FilesCard/src/fileSvg/image.vue +40 -40
  35. package/src/components/FilesCard/src/fileSvg/index.js +46 -46
  36. package/src/components/FilesCard/src/fileSvg/link.vue +54 -54
  37. package/src/components/FilesCard/src/fileSvg/mark.vue +38 -38
  38. package/src/components/FilesCard/src/fileSvg/pdf.vue +38 -38
  39. package/src/components/FilesCard/src/fileSvg/ppt.vue +38 -38
  40. package/src/components/FilesCard/src/fileSvg/three.vue +38 -38
  41. package/src/components/FilesCard/src/fileSvg/txt.vue +38 -38
  42. package/src/components/FilesCard/src/fileSvg/unknown.vue +54 -54
  43. package/src/components/FilesCard/src/fileSvg/video.vue +38 -38
  44. package/src/components/FilesCard/src/fileSvg/word.vue +38 -38
  45. package/src/components/FilesCard/src/fileSvg/zip.vue +38 -38
  46. package/src/components/FilesCard/src/options.js +18 -18
  47. package/src/components/Prompts/index.js +8 -8
  48. package/src/components/Prompts/src/main.vue +248 -248
  49. package/src/components/Sender/index.js +8 -8
  50. package/src/components/Sender/src/components/ClearButton.vue +28 -28
  51. package/src/components/Sender/src/components/Loading.vue +53 -53
  52. package/src/components/Sender/src/components/LoadingButton.vue +39 -39
  53. package/src/components/Sender/src/components/SendButton.vue +26 -26
  54. package/src/components/Sender/src/components/SpeechButton.vue +24 -24
  55. package/src/components/Sender/src/components/SpeechLoading.vue +87 -87
  56. package/src/components/Sender/src/components/SpeechLoadingButton.vue +43 -43
  57. package/src/components/Thinking/index.js +8 -8
  58. package/src/components/ThoughtChain/index.js +8 -8
  59. package/src/components/Typewriter/index.js +8 -8
  60. package/src/components/Typewriter/src/main.vue +10 -2
  61. package/src/components/Welcome/index.js +8 -8
  62. package/src/components/Welcome/src/main.vue +151 -151
  63. package/src/index.js +0 -2
  64. package/src/mixins/recordMixin.js +0 -1
  65. package/src/mixins/sendMixin.js +104 -11
  66. package/src/mixins/streamMixin.js +3 -5
  67. package/src/styles/Attachments.scss +236 -236
  68. package/src/styles/Bubble.scss +157 -157
  69. package/src/styles/BubbleList.scss +148 -148
  70. package/src/styles/Conversations.scss +260 -260
  71. package/src/styles/FilesCard.scss +221 -221
  72. package/src/styles/Prompts.scss +195 -195
  73. package/src/styles/Sender.scss +199 -199
  74. package/src/styles/Thinking.scss +2 -2
  75. package/src/styles/ThoughtChain.scss +113 -113
  76. package/src/styles/Typewriter.scss +66 -66
  77. package/src/theme/var.scss +72 -72
  78. package/src/components/Think/index.js +0 -8
  79. package/src/components/Think/src/main.vue +0 -190
  80. package/src/styles/Think.scss +0 -134
  81. package/src/styles/button.scss +0 -302
  82. package/src/styles/var.scss +0 -1052
@@ -1,151 +1,151 @@
1
- <template>
2
- <div
3
- :class="containerClass"
4
- :style="styleConfig"
5
- class="el-x-welcome"
6
- >
7
- <!-- image -->
8
- <slot name="image">
9
- <div
10
- v-if="hasIcon"
11
- :class="iconClass"
12
- :style="styles && styles.icon"
13
- class="el-x-welcome-icon"
14
- >
15
- <el-image
16
- :src="icon"
17
- class="icon-image"
18
- />
19
- </div>
20
- </slot>
21
-
22
- <div class="content-wrapper">
23
- <!-- extra -->
24
- <div
25
- v-if="hasTitleOrExtra"
26
- class="title-wrapper"
27
- >
28
- <div
29
- v-if="title"
30
- :class="titleClass"
31
- :style="styles && styles.title"
32
- class="el-x-welcome-title"
33
- >
34
- {{ title }}
35
- </div>
36
- <div
37
- v-if="hasExtraOrSlot"
38
- :class="extraClass"
39
- :style="styles && styles.extra"
40
- class="el-x-welcome-extra"
41
- >
42
- <slot name="extra">{{ extra }}</slot>
43
- </div>
44
- </div>
45
-
46
- <!-- description -->
47
- <div
48
- v-if="hasDescription"
49
- :class="descriptionClass"
50
- :style="styles && styles.description"
51
- class="el-x-welcome-description"
52
- >
53
- {{ description }}
54
- </div>
55
- </div>
56
- </div>
57
- </template>
58
-
59
- <script>
60
- export default {
61
- name: 'ElXWelcome',
62
- props: {
63
- className: {
64
- type: String,
65
- default: '',
66
- },
67
- rootClassName: {
68
- type: String,
69
- default: '',
70
- },
71
- variant: {
72
- type: String,
73
- default: 'filled',
74
- validator: value => ['filled', 'borderless'].includes(value),
75
- },
76
- direction: {
77
- type: String,
78
- default: 'ltr',
79
- validator: value => ['ltr', 'rtl'].includes(value),
80
- },
81
- classNames: {
82
- type: Object,
83
- default: () => ({}),
84
- },
85
- icon: {
86
- type: String,
87
- default: '',
88
- },
89
- title: {
90
- type: String,
91
- default: '',
92
- },
93
- extra: {
94
- type: [String, Object],
95
- default: '',
96
- },
97
- description: {
98
- type: String,
99
- default: '',
100
- },
101
- styleConfig: {
102
- type: Object,
103
- default: () => ({}),
104
- },
105
- styles: {
106
- type: Object,
107
- default: () => ({}),
108
- },
109
- },
110
- computed: {
111
- hasIcon() {
112
- return !!this.icon;
113
- },
114
- hasTitleOrExtra() {
115
- return !!this.title || !!this.extra;
116
- },
117
- hasExtraOrSlot() {
118
- return !!this.extra || !!this.$slots.extra;
119
- },
120
- hasDescription() {
121
- return !!this.description;
122
- },
123
- containerClass() {
124
- return [
125
- this.className,
126
- this.rootClassName,
127
- `el-x-welcome-${this.variant}`,
128
- {
129
- 'el-x-welcome-rtl': this.direction === 'rtl',
130
- },
131
- ];
132
- },
133
- iconClass() {
134
- return this.classNames && this.classNames.icon;
135
- },
136
- titleClass() {
137
- return this.classNames && this.classNames.title;
138
- },
139
- extraClass() {
140
- return this.classNames && this.classNames.extra;
141
- },
142
- descriptionClass() {
143
- return this.classNames && this.classNames.description;
144
- },
145
- },
146
- };
147
- </script>
148
-
149
- <style lang="scss" scoped>
150
- @import '../../../styles/Welcome.scss';
151
- </style>
1
+ <template>
2
+ <div
3
+ :class="containerClass"
4
+ :style="styleConfig"
5
+ class="el-x-welcome"
6
+ >
7
+ <!-- image -->
8
+ <slot name="image">
9
+ <div
10
+ v-if="hasIcon"
11
+ :class="iconClass"
12
+ :style="styles && styles.icon"
13
+ class="el-x-welcome-icon"
14
+ >
15
+ <el-image
16
+ :src="icon"
17
+ class="icon-image"
18
+ />
19
+ </div>
20
+ </slot>
21
+
22
+ <div class="content-wrapper">
23
+ <!-- extra -->
24
+ <div
25
+ v-if="hasTitleOrExtra"
26
+ class="title-wrapper"
27
+ >
28
+ <div
29
+ v-if="title"
30
+ :class="titleClass"
31
+ :style="styles && styles.title"
32
+ class="el-x-welcome-title"
33
+ >
34
+ {{ title }}
35
+ </div>
36
+ <div
37
+ v-if="hasExtraOrSlot"
38
+ :class="extraClass"
39
+ :style="styles && styles.extra"
40
+ class="el-x-welcome-extra"
41
+ >
42
+ <slot name="extra">{{ extra }}</slot>
43
+ </div>
44
+ </div>
45
+
46
+ <!-- description -->
47
+ <div
48
+ v-if="hasDescription"
49
+ :class="descriptionClass"
50
+ :style="styles && styles.description"
51
+ class="el-x-welcome-description"
52
+ >
53
+ {{ description }}
54
+ </div>
55
+ </div>
56
+ </div>
57
+ </template>
58
+
59
+ <script>
60
+ export default {
61
+ name: 'ElXWelcome',
62
+ props: {
63
+ className: {
64
+ type: String,
65
+ default: '',
66
+ },
67
+ rootClassName: {
68
+ type: String,
69
+ default: '',
70
+ },
71
+ variant: {
72
+ type: String,
73
+ default: 'filled',
74
+ validator: value => ['filled', 'borderless'].includes(value),
75
+ },
76
+ direction: {
77
+ type: String,
78
+ default: 'ltr',
79
+ validator: value => ['ltr', 'rtl'].includes(value),
80
+ },
81
+ classNames: {
82
+ type: Object,
83
+ default: () => ({}),
84
+ },
85
+ icon: {
86
+ type: String,
87
+ default: '',
88
+ },
89
+ title: {
90
+ type: String,
91
+ default: '',
92
+ },
93
+ extra: {
94
+ type: [String, Object],
95
+ default: '',
96
+ },
97
+ description: {
98
+ type: String,
99
+ default: '',
100
+ },
101
+ styleConfig: {
102
+ type: Object,
103
+ default: () => ({}),
104
+ },
105
+ styles: {
106
+ type: Object,
107
+ default: () => ({}),
108
+ },
109
+ },
110
+ computed: {
111
+ hasIcon() {
112
+ return !!this.icon;
113
+ },
114
+ hasTitleOrExtra() {
115
+ return !!this.title || !!this.extra;
116
+ },
117
+ hasExtraOrSlot() {
118
+ return !!this.extra || !!this.$slots.extra;
119
+ },
120
+ hasDescription() {
121
+ return !!this.description;
122
+ },
123
+ containerClass() {
124
+ return [
125
+ this.className,
126
+ this.rootClassName,
127
+ `el-x-welcome-${this.variant}`,
128
+ {
129
+ 'el-x-welcome-rtl': this.direction === 'rtl',
130
+ },
131
+ ];
132
+ },
133
+ iconClass() {
134
+ return this.classNames && this.classNames.icon;
135
+ },
136
+ titleClass() {
137
+ return this.classNames && this.classNames.title;
138
+ },
139
+ extraClass() {
140
+ return this.classNames && this.classNames.extra;
141
+ },
142
+ descriptionClass() {
143
+ return this.classNames && this.classNames.description;
144
+ },
145
+ },
146
+ };
147
+ </script>
148
+
149
+ <style lang="scss" scoped>
150
+ @import '../../../styles/Welcome.scss';
151
+ </style>
package/src/index.js CHANGED
@@ -5,7 +5,6 @@ import ElXConversations from './components/Conversations/index.js';
5
5
  import ElXFilesCard from './components/FilesCard/index.js';
6
6
  import ElXPrompts from './components/Prompts/index.js';
7
7
  import ElXSender from './components/Sender/index.js';
8
- import ElXThink from './components/Think/index.js';
9
8
  import ElXThinking from './components/Thinking/index.js';
10
9
  import ElXThoughtChain from './components/ThoughtChain/index.js';
11
10
  import ElXTypewriter from './components/Typewriter/index.js';
@@ -52,7 +51,6 @@ export {
52
51
  ElXFilesCard,
53
52
  ElXPrompts,
54
53
  ElXSender,
55
- ElXThink,
56
54
  ElXThinking,
57
55
  ElXThoughtChain,
58
56
  ElXTypewriter,
@@ -1,6 +1,5 @@
1
1
  /**
2
2
  * @description 提供语音识别的混入,允许语音输入并处理开始、结束、结果及错误等各种事件。
3
- *
4
3
  * @mixin recordMixin
5
4
  */
6
5
 
@@ -44,6 +44,9 @@ export class XRequest {
44
44
  signal,
45
45
  };
46
46
 
47
+ // 用于存储跨 chunk 的不完整数据
48
+ let buffer = '';
49
+
47
50
  return fetch(this._baseURL + url, fetchOptions)
48
51
  .then(res => res.body)
49
52
  .then(async body => {
@@ -60,6 +63,10 @@ export class XRequest {
60
63
  done = streamDone;
61
64
 
62
65
  if (streamDone) {
66
+ // 处理缓冲区中剩余的数据
67
+ if (buffer.trim()) {
68
+ this.processBufferData(buffer);
69
+ }
63
70
  this._onFinish && this._onFinish(this._messages);
64
71
  return;
65
72
  }
@@ -68,17 +75,23 @@ export class XRequest {
68
75
  const chunk = decoder.decode(value, {
69
76
  stream: true,
70
77
  });
71
- const chunkUse = chunk.startsWith('data: ') ? chunk.slice(6) : chunk;
72
-
73
- try {
74
- const res = this._transformer ? this._transformer(chunkUse) : chunkUse;
75
- this._messages.push(res);
76
- this._onMessage && this._onMessage(res);
77
- } catch (error) {
78
- this._onError && this._onError(error);
79
- this._controller && this._controller.abort();
80
- return Promise.reject(error);
81
- }
78
+ // console.log('chunk:', chunk);
79
+ // 将新数据添加到缓冲区
80
+ buffer += chunk;
81
+
82
+ // 处理缓冲区中的完整行
83
+ buffer = this.processBuffer(buffer);
84
+ // const chunkUse = chunk.startsWith('data: ') ? chunk.slice(6) : chunk;
85
+
86
+ // try {
87
+ // const res = this._transformer ? this._transformer(chunkUse) : chunkUse;
88
+ // this._messages.push(res);
89
+ // this._onMessage && this._onMessage(res);
90
+ // } catch (error) {
91
+ // this._onError && this._onError(error);
92
+ // this._controller && this._controller.abort();
93
+ // return Promise.reject(error);
94
+ // }
82
95
  }
83
96
  }
84
97
  })
@@ -91,6 +104,86 @@ export class XRequest {
91
104
  this._controller && this._controller.abort();
92
105
  });
93
106
  }
107
+ /**
108
+ * 处理缓冲区数据,提取完整的行
109
+ * @param {string} buffer - 缓冲区数据
110
+ * @returns {string} 剩余的不完整数据
111
+ */
112
+ processBuffer(buffer) {
113
+ const lines = buffer.split('\n');
114
+ // console.log('lines:', lines);
115
+ // 保留最后一行(可能不完整)
116
+ const remainingData = lines.pop();
117
+
118
+ // 处理完整的行
119
+ for (const line of lines) {
120
+ this.processLine(line);
121
+ }
122
+
123
+ return remainingData || '';
124
+ }
125
+
126
+ /**
127
+ * 处理单行数据
128
+ * @param {string} line - 单行数据
129
+ */
130
+ processLine(line) {
131
+ // 跳过空行
132
+ if (!line.trim()) {
133
+ return;
134
+ }
135
+
136
+ // 处理 data: 开头的行
137
+ if (line.startsWith('data: ')) {
138
+ const dataContent = line.slice(6);
139
+
140
+ // 检查是否是结束标识
141
+ if (dataContent.trim() === '[DONE]') {
142
+ this._isFinished = true;
143
+ this._onFinish && this._onFinish(this._messages);
144
+ this.abort();
145
+ return;
146
+ }
147
+
148
+ // 跳过空数据
149
+ if (!dataContent.trim()) {
150
+ return;
151
+ }
152
+
153
+ try {
154
+ // 尝试解析和处理数据
155
+ let processedData;
156
+ try {
157
+ // 首先尝试作为 JSON 解析
158
+ processedData = JSON.parse(dataContent);
159
+ } catch {
160
+ // 如果不是 JSON,使用原始数据
161
+ processedData = dataContent;
162
+ }
163
+ // console.log('processedData:', processedData, processedData.answer);
164
+
165
+ const res = this._transformer ? this._transformer(processedData) : processedData;
166
+ this._messages.push(res);
167
+ this._onMessage && this._onMessage(res);
168
+ } catch (error) {
169
+ console.error('Error processing line:', line, error);
170
+ this._onError && this._onError(error);
171
+ this._controller && this._controller.abort();
172
+ }
173
+ }
174
+ // 可以在这里处理其他类型的行(如果需要)
175
+ }
176
+
177
+ /**
178
+ * 处理缓冲区中剩余的数据(在流结束时调用)
179
+ * @param {string} buffer - 剩余的缓冲区数据
180
+ */
181
+ processBufferData(buffer) {
182
+ const lines = buffer.split('\n');
183
+ for (const line of lines) {
184
+ this.processLine(line);
185
+ }
186
+ }
94
187
 
95
188
  _sendWithSSE(url, options = {}) {
96
189
  const es = new EventSource(this._baseURL + url, {
@@ -1,8 +1,6 @@
1
1
  /**
2
- * @fileoverview Vue2 流式数据处理 Mixin
3
- * Vue3 useXStream hooks 转换而来,支持 SSE 数据解析和中断功能
4
- * @author Element UI X Team
5
- * @version 1.0.0
2
+ * @fileoverview 流式数据处理 Mixin
3
+ * 支持 SSE 数据解析和中断功能
6
4
  */
7
5
 
8
6
  /**
@@ -189,7 +187,7 @@ function XStream(options, signal) {
189
187
  }
190
188
 
191
189
  /**
192
- * streamMixin -
190
+ * streamMixin
193
191
  * 用于处理流式数据的 mixin,支持 SSE 数据解析和中断功能
194
192
  * @namespace streamMixin
195
193
  * @type {Object}