vue-element-ui-x 0.1.8-beta → 0.1.10-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.
Files changed (97) hide show
  1. package/lib/components/Attachments/index.js +229 -237
  2. package/lib/components/Bubble/index.js +47 -34
  3. package/lib/components/BubbleList/index.js +57 -49
  4. package/lib/components/Conversations/index.js +32 -69
  5. package/lib/components/FilesCard/index.js +207 -211
  6. package/lib/components/Prompts/index.js +21 -21
  7. package/lib/components/Sender/index.js +18 -18
  8. package/lib/components/Think/index.js +1 -1
  9. package/lib/components/Thinking/index.js +1 -1
  10. package/lib/components/ThoughtChain/index.js +60 -47
  11. package/lib/components/Typewriter/index.js +46 -33
  12. package/lib/components/Welcome/index.js +1 -1
  13. package/lib/index.common.js +1 -1
  14. package/lib/index.esm.js +1 -1
  15. package/lib/index.js +479 -427
  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/Attachments/src/main.vue +10 -10
  21. package/src/components/Bubble/index.js +6 -6
  22. package/src/components/Bubble/src/main.vue +299 -299
  23. package/src/components/BubbleList/index.js +8 -8
  24. package/src/components/BubbleList/src/loading.vue +75 -75
  25. package/src/components/BubbleList/src/main.vue +461 -466
  26. package/src/components/Conversations/index.js +8 -8
  27. package/src/components/Conversations/src/components/item.vue +13 -34
  28. package/src/components/Conversations/src/main.vue +622 -635
  29. package/src/components/FilesCard/index.js +8 -8
  30. package/src/components/FilesCard/src/fileSvg/audio.vue +38 -38
  31. package/src/components/FilesCard/src/fileSvg/code.vue +35 -35
  32. package/src/components/FilesCard/src/fileSvg/database.vue +94 -94
  33. package/src/components/FilesCard/src/fileSvg/excel.vue +38 -38
  34. package/src/components/FilesCard/src/fileSvg/file.vue +40 -40
  35. package/src/components/FilesCard/src/fileSvg/image.vue +40 -40
  36. package/src/components/FilesCard/src/fileSvg/index.js +46 -46
  37. package/src/components/FilesCard/src/fileSvg/link.vue +54 -54
  38. package/src/components/FilesCard/src/fileSvg/mark.vue +38 -38
  39. package/src/components/FilesCard/src/fileSvg/pdf.vue +38 -38
  40. package/src/components/FilesCard/src/fileSvg/ppt.vue +38 -38
  41. package/src/components/FilesCard/src/fileSvg/three.vue +38 -38
  42. package/src/components/FilesCard/src/fileSvg/txt.vue +38 -38
  43. package/src/components/FilesCard/src/fileSvg/unknown.vue +54 -54
  44. package/src/components/FilesCard/src/fileSvg/video.vue +38 -38
  45. package/src/components/FilesCard/src/fileSvg/word.vue +38 -38
  46. package/src/components/FilesCard/src/fileSvg/zip.vue +38 -38
  47. package/src/components/FilesCard/src/main.vue +4 -8
  48. package/src/components/FilesCard/src/options.js +18 -18
  49. package/src/components/Prompts/index.js +8 -8
  50. package/src/components/Prompts/src/main.vue +248 -248
  51. package/src/components/Sender/index.js +8 -8
  52. package/src/components/Sender/src/components/ClearButton.vue +28 -28
  53. package/src/components/Sender/src/components/Loading.vue +53 -53
  54. package/src/components/Sender/src/components/LoadingButton.vue +39 -39
  55. package/src/components/Sender/src/components/SendButton.vue +26 -26
  56. package/src/components/Sender/src/components/SpeechButton.vue +24 -24
  57. package/src/components/Sender/src/components/SpeechLoading.vue +87 -87
  58. package/src/components/Sender/src/components/SpeechLoadingButton.vue +43 -43
  59. package/src/components/Sender/src/main.vue +4 -3
  60. package/src/components/Think/index.js +8 -8
  61. package/src/components/Think/src/main.vue +190 -190
  62. package/src/components/Thinking/index.js +8 -8
  63. package/src/components/ThoughtChain/index.js +8 -8
  64. package/src/components/ThoughtChain/src/main.vue +293 -293
  65. package/src/components/Typewriter/index.js +8 -8
  66. package/src/components/Typewriter/src/main.vue +10 -2
  67. package/src/components/Welcome/index.js +8 -8
  68. package/src/components/Welcome/src/main.vue +151 -151
  69. package/src/mixins/recordMixin.js +0 -1
  70. package/src/mixins/sendMixin.js +104 -11
  71. package/src/mixins/streamMixin.js +3 -5
  72. package/src/styles/Attachments.scss +236 -236
  73. package/src/styles/Bubble.scss +157 -157
  74. package/src/styles/BubbleList.scss +148 -148
  75. package/src/styles/Conversations.scss +260 -260
  76. package/src/styles/FilesCard.scss +221 -221
  77. package/src/styles/Prompts.scss +195 -195
  78. package/src/styles/Sender.scss +199 -199
  79. package/src/styles/Think.scss +134 -134
  80. package/src/styles/ThoughtChain.scss +113 -113
  81. package/src/styles/Typewriter.scss +66 -66
  82. package/src/theme/var.scss +72 -72
  83. package/lib/attachments.js +0 -3082
  84. package/lib/bubble-list.js +0 -13840
  85. package/lib/bubble.js +0 -13125
  86. package/lib/conversations.js +0 -18825
  87. package/lib/files-card.js +0 -2471
  88. package/lib/mixins.js +0 -1016
  89. package/lib/prompts.js +0 -832
  90. package/lib/sender.js +0 -1911
  91. package/lib/think.js +0 -799
  92. package/lib/thinking.js +0 -809
  93. package/lib/thought-chain.js +0 -30391
  94. package/lib/typewriter.js +0 -12788
  95. package/lib/welcome.js +0 -755
  96. package/src/styles/button.scss +0 -302
  97. package/src/styles/var.scss +0 -1052
@@ -112,7 +112,6 @@ __webpack_require__.d(__webpack_exports__, "XStream", function() { return /* ree
112
112
  // CONCATENATED MODULE: ./src/mixins/recordMixin.js
113
113
  /**
114
114
  * @description 提供语音识别的混入,允许语音输入并处理开始、结束、结果及错误等各种事件。
115
- *
116
115
  * @mixin recordMixin
117
116
  */
118
117
 
@@ -262,6 +261,9 @@ class XRequest {
262
261
  ...options,
263
262
  signal
264
263
  };
264
+
265
+ // 用于存储跨 chunk 的不完整数据
266
+ let buffer = '';
265
267
  return fetch(this._baseURL + url, fetchOptions).then(res => res.body).then(async body => {
266
268
  if (!body) {
267
269
  return Promise.reject(new Error('Response body is null in stream mode'));
@@ -276,6 +278,10 @@ class XRequest {
276
278
  } = await reader.read();
277
279
  done = streamDone;
278
280
  if (streamDone) {
281
+ // 处理缓冲区中剩余的数据
282
+ if (buffer.trim()) {
283
+ this.processBufferData(buffer);
284
+ }
279
285
  this._onFinish && this._onFinish(this._messages);
280
286
  return;
281
287
  }
@@ -283,16 +289,23 @@ class XRequest {
283
289
  const chunk = decoder.decode(value, {
284
290
  stream: true
285
291
  });
286
- const chunkUse = chunk.startsWith('data: ') ? chunk.slice(6) : chunk;
287
- try {
288
- const res = this._transformer ? this._transformer(chunkUse) : chunkUse;
289
- this._messages.push(res);
290
- this._onMessage && this._onMessage(res);
291
- } catch (error) {
292
- this._onError && this._onError(error);
293
- this._controller && this._controller.abort();
294
- return Promise.reject(error);
295
- }
292
+ // console.log('chunk:', chunk);
293
+ // 将新数据添加到缓冲区
294
+ buffer += chunk;
295
+
296
+ // 处理缓冲区中的完整行
297
+ buffer = this.processBuffer(buffer);
298
+ // const chunkUse = chunk.startsWith('data: ') ? chunk.slice(6) : chunk;
299
+
300
+ // try {
301
+ // const res = this._transformer ? this._transformer(chunkUse) : chunkUse;
302
+ // this._messages.push(res);
303
+ // this._onMessage && this._onMessage(res);
304
+ // } catch (error) {
305
+ // this._onError && this._onError(error);
306
+ // this._controller && this._controller.abort();
307
+ // return Promise.reject(error);
308
+ // }
296
309
  }
297
310
  }
298
311
  }).catch(err => {
@@ -304,6 +317,84 @@ class XRequest {
304
317
  this._controller && this._controller.abort();
305
318
  });
306
319
  }
320
+ /**
321
+ * 处理缓冲区数据,提取完整的行
322
+ * @param {string} buffer - 缓冲区数据
323
+ * @returns {string} 剩余的不完整数据
324
+ */
325
+ processBuffer(buffer) {
326
+ const lines = buffer.split('\n');
327
+ // console.log('lines:', lines);
328
+ // 保留最后一行(可能不完整)
329
+ const remainingData = lines.pop();
330
+
331
+ // 处理完整的行
332
+ for (const line of lines) {
333
+ this.processLine(line);
334
+ }
335
+ return remainingData || '';
336
+ }
337
+
338
+ /**
339
+ * 处理单行数据
340
+ * @param {string} line - 单行数据
341
+ */
342
+ processLine(line) {
343
+ // 跳过空行
344
+ if (!line.trim()) {
345
+ return;
346
+ }
347
+
348
+ // 处理 data: 开头的行
349
+ if (line.startsWith('data: ')) {
350
+ const dataContent = line.slice(6);
351
+
352
+ // 检查是否是结束标识
353
+ if (dataContent.trim() === '[DONE]') {
354
+ this._isFinished = true;
355
+ this._onFinish && this._onFinish(this._messages);
356
+ this.abort();
357
+ return;
358
+ }
359
+
360
+ // 跳过空数据
361
+ if (!dataContent.trim()) {
362
+ return;
363
+ }
364
+ try {
365
+ // 尝试解析和处理数据
366
+ let processedData;
367
+ try {
368
+ // 首先尝试作为 JSON 解析
369
+ processedData = JSON.parse(dataContent);
370
+ } catch {
371
+ // 如果不是 JSON,使用原始数据
372
+ processedData = dataContent;
373
+ }
374
+ // console.log('processedData:', processedData, processedData.answer);
375
+
376
+ const res = this._transformer ? this._transformer(processedData) : processedData;
377
+ this._messages.push(res);
378
+ this._onMessage && this._onMessage(res);
379
+ } catch (error) {
380
+ console.error('Error processing line:', line, error);
381
+ this._onError && this._onError(error);
382
+ this._controller && this._controller.abort();
383
+ }
384
+ }
385
+ // 可以在这里处理其他类型的行(如果需要)
386
+ }
387
+
388
+ /**
389
+ * 处理缓冲区中剩余的数据(在流结束时调用)
390
+ * @param {string} buffer - 剩余的缓冲区数据
391
+ */
392
+ processBufferData(buffer) {
393
+ const lines = buffer.split('\n');
394
+ for (const line of lines) {
395
+ this.processLine(line);
396
+ }
397
+ }
307
398
  _sendWithSSE(url, options = {}) {
308
399
  const es = new EventSource(this._baseURL + url, {
309
400
  ...this._baseOptions,
@@ -535,10 +626,8 @@ function createSendUtils(options = {}) {
535
626
  /* harmony default export */ var mixins_sendMixin = (sendMixin);
536
627
  // CONCATENATED MODULE: ./src/mixins/streamMixin.js
537
628
  /**
538
- * @fileoverview Vue2 流式数据处理 Mixin
539
- * Vue3 useXStream hooks 转换而来,支持 SSE 数据解析和中断功能
540
- * @author Element UI X Team
541
- * @version 1.0.0
629
+ * @fileoverview 流式数据处理 Mixin
630
+ * 支持 SSE 数据解析和中断功能
542
631
  */
543
632
 
544
633
  /**
@@ -723,7 +812,7 @@ function XStream(options, signal) {
723
812
  }
724
813
 
725
814
  /**
726
- * streamMixin -
815
+ * streamMixin
727
816
  * 用于处理流式数据的 mixin,支持 SSE 数据解析和中断功能
728
817
  * @namespace streamMixin
729
818
  * @type {Object}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vue-element-ui-x",
3
- "version": "0.1.8-beta",
3
+ "version": "0.1.10-beta",
4
4
  "description": "基于Vue 2 + Element UI的AI聊天组件库",
5
5
  "main": "lib/index.esm.js",
6
6
  "module": "lib/index.umd.js",
@@ -1,8 +1,8 @@
1
- import ElXAttachments from './src/main.vue';
2
-
3
- /* istanbul ignore next */
4
- ElXAttachments.install = function (Vue) {
5
- Vue.component(ElXAttachments.name, ElXAttachments);
6
- };
7
-
8
- export default ElXAttachments;
1
+ import ElXAttachments from './src/main.vue';
2
+
3
+ /* istanbul ignore next */
4
+ ElXAttachments.install = function (Vue) {
5
+ Vue.component(ElXAttachments.name, ElXAttachments);
6
+ };
7
+
8
+ export default ElXAttachments;
@@ -19,9 +19,9 @@
19
19
  :action="uploadAction"
20
20
  :http-request="customUpload"
21
21
  :show-file-list="false"
22
- @change="handleUploadChange"
23
- @success="handleUploadSuccess"
24
- @error="handleUploadError"
22
+ :on-change="handleUploadChange"
23
+ :on-success="handleUploadSuccess"
24
+ :on-error="handleUploadError"
25
25
  >
26
26
  <i class="el-icon-plus uploader-icon"></i>
27
27
  </el-upload>
@@ -94,9 +94,9 @@
94
94
  height: overflow === 'scrollY' && '',
95
95
  }"
96
96
  class="el-x-attachments-upload-btn"
97
- @change="handleUploadChange"
98
- @success="handleUploadSuccess"
99
- @error="handleUploadError"
97
+ :on-change="handleUploadChange"
98
+ :on-success="handleUploadSuccess"
99
+ :on-error="handleUploadError"
100
100
  >
101
101
  <i class="el-icon-plus uploader-icon"></i>
102
102
  </el-upload>
@@ -349,7 +349,7 @@
349
349
  // 默认实现:发出事件,让父组件处理
350
350
  const { file } = options;
351
351
  this.$emit(
352
- 'uploadChange',
352
+ 'upload-change',
353
353
  {
354
354
  file,
355
355
  },
@@ -365,13 +365,13 @@
365
365
  return Promise.resolve();
366
366
  },
367
367
  handleUploadChange(file, fileList) {
368
- this.$emit('uploadChange', file, fileList);
368
+ this.$emit('upload-change', file, fileList);
369
369
  },
370
370
  handleUploadSuccess(response, file, fileList) {
371
- this.$emit('uploadSuccess', response, file, fileList);
371
+ this.$emit('upload-success', response, file, fileList);
372
372
  },
373
373
  handleUploadError(error, file, fileList) {
374
- this.$emit('uploadError', error, file, fileList);
374
+ this.$emit('upload-error', error, file, fileList);
375
375
  },
376
376
 
377
377
  getTargetElement() {
@@ -1,6 +1,6 @@
1
- import ElXBubble from './src/main.vue';
2
- /* istanbul ignore next */
3
- ElXBubble.install = function (Vue) {
4
- Vue.component(ElXBubble.name, ElXBubble);
5
- };
6
- export default ElXBubble;
1
+ import ElXBubble from './src/main.vue';
2
+ /* istanbul ignore next */
3
+ ElXBubble.install = function (Vue) {
4
+ Vue.component(ElXBubble.name, ElXBubble);
5
+ };
6
+ export default ElXBubble;