vue-element-ui-x 0.1.9-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 (80) hide show
  1. package/lib/components/Attachments/index.js +2 -2
  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 +27 -64
  5. package/lib/components/FilesCard/index.js +1 -1
  6. package/lib/components/Prompts/index.js +21 -21
  7. package/lib/components/Sender/index.js +4 -4
  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 +47 -34
  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 +220 -160
  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/Think/index.js +8 -8
  58. package/src/components/Think/src/main.vue +190 -190
  59. package/src/components/Thinking/index.js +8 -8
  60. package/src/components/ThoughtChain/index.js +8 -8
  61. package/src/components/Typewriter/index.js +8 -8
  62. package/src/components/Typewriter/src/main.vue +10 -2
  63. package/src/components/Welcome/index.js +8 -8
  64. package/src/components/Welcome/src/main.vue +151 -151
  65. package/src/mixins/recordMixin.js +0 -1
  66. package/src/mixins/sendMixin.js +104 -11
  67. package/src/mixins/streamMixin.js +3 -5
  68. package/src/styles/Attachments.scss +236 -236
  69. package/src/styles/Bubble.scss +157 -157
  70. package/src/styles/BubbleList.scss +148 -148
  71. package/src/styles/Conversations.scss +260 -260
  72. package/src/styles/FilesCard.scss +221 -221
  73. package/src/styles/Prompts.scss +195 -195
  74. package/src/styles/Sender.scss +199 -199
  75. package/src/styles/Think.scss +134 -134
  76. package/src/styles/ThoughtChain.scss +113 -113
  77. package/src/styles/Typewriter.scss +66 -66
  78. package/src/theme/var.scss +72 -72
  79. package/src/styles/button.scss +0 -302
  80. 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.9-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;
@@ -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;