ai-error-assistant-mobile 0.0.13 → 0.0.15

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 (58) hide show
  1. package/components/demo/src/chat.vue +69 -3
  2. package/components/demo/src/error-chat.vue +63 -8
  3. package/components/demo/src/main.vue +2 -3
  4. package/dist/ai-error-assistant-mobile.common.js +18406 -34
  5. package/dist/ai-error-assistant-mobile.common.js.map +1 -1
  6. package/dist/ai-error-assistant-mobile.css +1 -1
  7. package/dist/ai-error-assistant-mobile.umd.js +18406 -34
  8. package/dist/ai-error-assistant-mobile.umd.js.map +1 -1
  9. package/dist/ai-error-assistant-mobile.umd.min.js +4 -4
  10. package/dist/ai-error-assistant-mobile.umd.min.js.map +1 -1
  11. package/dist/fonts/KaTeX_AMS-Regular.1608a09b.woff +0 -0
  12. package/dist/fonts/KaTeX_AMS-Regular.4aafdb68.ttf +0 -0
  13. package/dist/fonts/KaTeX_AMS-Regular.a79f1c31.woff2 +0 -0
  14. package/dist/fonts/KaTeX_Caligraphic-Bold.cce5b8ec.ttf +0 -0
  15. package/dist/fonts/KaTeX_Caligraphic-Regular.07ef19e7.ttf +0 -0
  16. package/dist/fonts/KaTeX_Fraktur-Bold.9f256b85.woff +0 -0
  17. package/dist/fonts/KaTeX_Fraktur-Bold.b18f59e1.ttf +0 -0
  18. package/dist/fonts/KaTeX_Fraktur-Bold.d42a5579.woff2 +0 -0
  19. package/dist/fonts/KaTeX_Fraktur-Regular.7c187121.woff +0 -0
  20. package/dist/fonts/KaTeX_Fraktur-Regular.d3c882a6.woff2 +0 -0
  21. package/dist/fonts/KaTeX_Fraktur-Regular.ed38e79f.ttf +0 -0
  22. package/dist/fonts/KaTeX_Main-Bold.b74a1a8b.ttf +0 -0
  23. package/dist/fonts/KaTeX_Main-Bold.c3fb5ac2.woff2 +0 -0
  24. package/dist/fonts/KaTeX_Main-Bold.d181c465.woff +0 -0
  25. package/dist/fonts/KaTeX_Main-BoldItalic.6f2bb1df.woff2 +0 -0
  26. package/dist/fonts/KaTeX_Main-BoldItalic.70d8b0a5.ttf +0 -0
  27. package/dist/fonts/KaTeX_Main-BoldItalic.e3f82f9d.woff +0 -0
  28. package/dist/fonts/KaTeX_Main-Italic.47373d1e.ttf +0 -0
  29. package/dist/fonts/KaTeX_Main-Italic.8916142b.woff2 +0 -0
  30. package/dist/fonts/KaTeX_Main-Italic.9024d815.woff +0 -0
  31. package/dist/fonts/KaTeX_Main-Regular.0462f03b.woff2 +0 -0
  32. package/dist/fonts/KaTeX_Main-Regular.7f51fe03.woff +0 -0
  33. package/dist/fonts/KaTeX_Main-Regular.b7f8fe9b.ttf +0 -0
  34. package/dist/fonts/KaTeX_Math-BoldItalic.572d331f.woff2 +0 -0
  35. package/dist/fonts/KaTeX_Math-BoldItalic.a879cf83.ttf +0 -0
  36. package/dist/fonts/KaTeX_Math-BoldItalic.f1035d8d.woff +0 -0
  37. package/dist/fonts/KaTeX_Math-Italic.5295ba48.woff +0 -0
  38. package/dist/fonts/KaTeX_Math-Italic.939bc644.ttf +0 -0
  39. package/dist/fonts/KaTeX_Math-Italic.f28c23ac.woff2 +0 -0
  40. package/dist/fonts/KaTeX_SansSerif-Bold.8c5b5494.woff2 +0 -0
  41. package/dist/fonts/KaTeX_SansSerif-Bold.94e1e8dc.ttf +0 -0
  42. package/dist/fonts/KaTeX_SansSerif-Bold.bf59d231.woff +0 -0
  43. package/dist/fonts/KaTeX_SansSerif-Italic.3b1e59b3.woff2 +0 -0
  44. package/dist/fonts/KaTeX_SansSerif-Italic.7c9bc82b.woff +0 -0
  45. package/dist/fonts/KaTeX_SansSerif-Italic.b4c20c84.ttf +0 -0
  46. package/dist/fonts/KaTeX_SansSerif-Regular.74048478.woff +0 -0
  47. package/dist/fonts/KaTeX_SansSerif-Regular.ba21ed5f.woff2 +0 -0
  48. package/dist/fonts/KaTeX_SansSerif-Regular.d4d7ba48.ttf +0 -0
  49. package/dist/fonts/KaTeX_Script-Regular.03e9641d.woff2 +0 -0
  50. package/dist/fonts/KaTeX_Script-Regular.07505710.woff +0 -0
  51. package/dist/fonts/KaTeX_Script-Regular.fe9cbbe1.ttf +0 -0
  52. package/dist/fonts/KaTeX_Size1-Regular.fabc004a.ttf +0 -0
  53. package/dist/fonts/KaTeX_Size2-Regular.d6b476ec.ttf +0 -0
  54. package/dist/fonts/KaTeX_Size4-Regular.fbccdabe.ttf +0 -0
  55. package/dist/fonts/KaTeX_Typewriter-Regular.6258592b.woff +0 -0
  56. package/dist/fonts/KaTeX_Typewriter-Regular.a8709e36.woff2 +0 -0
  57. package/dist/fonts/KaTeX_Typewriter-Regular.d97aaf4a.ttf +0 -0
  58. package/package.json +2 -1
@@ -5,7 +5,7 @@
5
5
  :class="{'user-list': list.type === 'user'}"
6
6
  class="message">
7
7
  <div :class="{'user-info': list.type === 'user'}" class="robot-message">
8
- <div v-html="list.message"></div>
8
+ <div v-html="renderFormulas(list.message)"></div>
9
9
  <div v-if="list.type === 'robot' && list.links.length > 0 && showFile" class="link">
10
10
  <div v-if="!list.allIdWithStart">
11
11
  <div class="link-title">参考文件</div>
@@ -82,6 +82,9 @@ import ChatTools from './chat-tools.vue';
82
82
  import ErrorChat from './error-chat.vue';
83
83
  import {marked} from 'marked';
84
84
  import {chartClear, sendMessageEventSource, getAutoQuestioning, pdfUrlBase} from "../api";
85
+ import katex from 'katex';
86
+ import 'katex/dist/katex.min.css';
87
+
85
88
 
86
89
  const controller = new AbortController();
87
90
  const signal = controller.signal;
@@ -364,6 +367,48 @@ export default {
364
367
  const baseUrl = `${pdfUrlBase}/#/pdf-view?documentUrl=${encodeURIComponent(url)}&pageIndex=${pageIndex}`;
365
368
  window.open(baseUrl, '_blank');
366
369
  },
370
+ renderFormulas(text) {
371
+ const {renderToString} = katex;
372
+ return text
373
+ .replace(/\$\$(.*?)\$\$/gs, (match) => {
374
+ try {
375
+ // 渲染块级公式
376
+ return renderToString(match.slice(2, -2), {displayMode: false});
377
+ } catch (error) {
378
+ console.error('Error rendering block formula:', error);
379
+ return match;
380
+ }
381
+ })
382
+ .replace(/\$.*?\$/g, (match) => {
383
+ match = match.replace(/<br>/g, '');
384
+ try {
385
+ // 渲染行内公式
386
+ return renderToString(match.slice(1, -1), {displayMode: false});
387
+ } catch (error) {
388
+ console.error('Error rendering inline formula:', error);
389
+ return match;
390
+ }
391
+ })
392
+ .replace(/\\\(.*?\\\)/g, (match) => {
393
+ try {
394
+ // 渲染行内公式
395
+ return renderToString(match.slice(2, -2), {displayMode: false});
396
+ } catch (error) {
397
+ console.error('Error rendering inline formula:', error);
398
+ return match;
399
+ }
400
+ })
401
+ .replace(/\\\[[\s\S]*?\\]/g, (match) => {
402
+ match = match.replace(/<br>/g, '');
403
+ try {
404
+ // 渲染块级公式
405
+ return renderToString(match.slice(2, -2), {displayMode: false});
406
+ } catch (error) {
407
+ console.error('Error rendering block formula:', error);
408
+ return match;
409
+ }
410
+ });
411
+ },
367
412
  },
368
413
  }
369
414
  </script>
@@ -421,8 +466,8 @@ export default {
421
466
  border-radius: 0.25rem 1rem 1rem 1rem;
422
467
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
423
468
  min-width: 120px;
424
- max-width: 85%;
425
- padding: 0.75rem;
469
+ max-width: 100%;
470
+ padding: 12px;
426
471
  }
427
472
  }
428
473
  }
@@ -502,6 +547,27 @@ export default {
502
547
  font-size: 0.875rem;
503
548
  }
504
549
 
550
+ :deep(table) {
551
+ border-collapse: collapse;
552
+ margin: 16px 0;
553
+ font-size: 14px;
554
+ }
555
+
556
+ :deep(th),
557
+ :deep(td) {
558
+ border: 1px solid #e0e0e0;
559
+ text-align: left;
560
+ }
561
+
562
+ :deep(th) {
563
+ background: #f3f2ff;
564
+ font-weight: 600;
565
+ }
566
+
567
+ :deep(li) {
568
+ list-style: none;
569
+ }
570
+
505
571
  :deep(a) {
506
572
  color: #6050f0;
507
573
  text-decoration: none;
@@ -2,7 +2,7 @@
2
2
  <div class="error-chat-contain">
3
3
  <div class="exercises-answer">
4
4
  <div class="exercises-answer-bg"></div>
5
- <p class="question-stem" v-html="questionStem.title"></p>
5
+ <p class="question-stem" v-html="renderFormulas(questionStem.title)"></p>
6
6
  <div class="answer-part" v-if="questionStem.type === 'single' || questionStem.type === 'multiple'">
7
7
  <div class="answer-list" v-for="(item, index) in questionStem.options" :key="index">
8
8
  <div class="check-content" style="width: 24px">
@@ -11,7 +11,7 @@
11
11
  alt=""
12
12
  style="width: 24px">
13
13
  </div>
14
- <div class="answer-list" v-html="item"></div>
14
+ <div class="answer-list" v-html="renderFormulas(item)"></div>
15
15
  </div>
16
16
  </div>
17
17
  <div class="answer-part"
@@ -34,7 +34,7 @@
34
34
  v-if="questionStem.type === 'shortanswer' || questionStem.type === 'gapfilling'">
35
35
  <span style="vertical-align: inherit; display: inline-block">正确答案:</span>
36
36
  <span style="margin-left: 8px; display: inline-block; width: calc(100% - 82px); vertical-align: top;"
37
- v-html="questionStem.answer.join(',')"></span>
37
+ v-html="renderFormulas(questionStem.answer.join(','))"></span>
38
38
  </div>
39
39
  <div class="student-answer-part">
40
40
  <div class="check-content" style="width: 24px; margin-right: 16px">
@@ -44,7 +44,7 @@
44
44
  <div v-for="(item, index) in questionStem.studentAnswer"
45
45
  style="margin-right: 16px; font-size: 0.875rem; margin-bottom: 0.5rem;"
46
46
  :key="index"
47
- v-html="item">
47
+ v-html="renderFormulas(item)">
48
48
  </div>
49
49
  </div>
50
50
  <div v-if="questionStem.type === 'judge'">
@@ -57,7 +57,7 @@
57
57
  <!-- {{ item }}<span v-if="index !== questionStem.studentAnswer.length - 1">,</span>-->
58
58
  <!-- </span>-->
59
59
  <div v-if="questionStem.type === 'shortanswer' || questionStem.type === 'gapfilling'">
60
- <span style="margin-left: 8px" v-html="questionStem.studentAnswer.join(',')"></span>
60
+ <span style="margin-left: 8px" v-html="renderFormulas(questionStem.studentAnswer.join(','))"></span>
61
61
  </div>
62
62
  </div>
63
63
  </div>
@@ -65,9 +65,9 @@
65
65
  element-loading-text="分析中,请稍后"
66
66
  v-loading="!Object.keys(analysisData).length > 0">
67
67
  <div class="title-label">题目解析</div>
68
- <div class="answer-content" v-html="analysisData.analysis"></div>
68
+ <div class="answer-content" v-html="renderFormulas(analysisData.analysis)"></div>
69
69
  <div class="title-label">错因分析</div>
70
- <div class="answer-content" v-html="analysisData.reason"></div>
70
+ <div class="answer-content" v-html="renderFormulas(analysisData.reason)"></div>
71
71
  <div class="title-label"
72
72
  v-if="businessSource !== '2' && analysisData.recommend && analysisData.recommend.length > 0 && !allIdWithStart">
73
73
  推荐资料
@@ -90,6 +90,8 @@
90
90
  <script>
91
91
  import ChatTools from './chat-tools.vue';
92
92
  import {erranalysis, retryAnalysis,pdfUrlBase} from '../api/index'
93
+ import katex from 'katex';
94
+ import 'katex/dist/katex.min.css';
93
95
 
94
96
  export default {
95
97
  name: 'ErrorChart',
@@ -205,7 +207,60 @@ export default {
205
207
  this.analysisData = {key: true};
206
208
  console.log(e);
207
209
  }
208
- }
210
+ },
211
+ renderFormulas(text) {
212
+ if (!text) return '';
213
+ // 如果整个文本包含 LaTeX 命令且没有定界符,整体包裹
214
+ const hasDelimiter = /\$|\\\(|\\\[/.test(text);
215
+ if (!hasDelimiter) {
216
+ text = text.replace(
217
+ /(\\(?:frac|sqrt|sum|int|cdot|times|geq|leq|neq|pm|div|alpha|beta|gamma|theta|pi|sigma|omega|infty|log|sin|cos|tan|left|right|overline|hat|vec|bar|lim|in|notin|supset|subseteq|ln|Gamma|to)(?:\{[^{}]*(?:\{[^{}]*(?:\{[^{}]*\}[^{}]*)*\}[^{}]*)*\}|[^\s{},。?!、;:\u4e00-\u9fa5])*)/g,
218
+ (match) => `\\(${match}\\)`
219
+ );
220
+ }
221
+ const { renderToString } = katex;
222
+ return text
223
+ // 块级公式 $$...$$
224
+ .replace(/\$\$(.*?)\$\$/gs, (match, p1) => {
225
+ try {
226
+ return renderToString(p1, { displayMode: true, throwOnError:
227
+ false });
228
+ } catch (e) {
229
+ console.error('Block formula error:', e);
230
+ return match;
231
+ }
232
+ })
233
+ // 行内公式 $...$
234
+ .replace(/\$(.*?)\$/g, (match, p1) => {
235
+ try {
236
+ return renderToString(p1, { displayMode: false, throwOnError:
237
+ false });
238
+ } catch (e) {
239
+ console.error('Inline formula error:', e);
240
+ return match;
241
+ }
242
+ })
243
+ // 行内公式 \( ... \)
244
+ .replace(/\\\((.*?)\\\)/g, (match, p1) => {
245
+ try {
246
+ return renderToString(p1, { displayMode: false, throwOnError:
247
+ false });
248
+ } catch (e) {
249
+ console.error('Inline formula error:', e);
250
+ return match;
251
+ }
252
+ })
253
+ // 块级公式 \[ ... \]
254
+ .replace(/\\\[(.*?)\\\]/gs, (match, p1) => {
255
+ try {
256
+ return renderToString(p1, { displayMode: true, throwOnError:
257
+ false });
258
+ } catch (e) {
259
+ console.error('Block formula error:', e);
260
+ return match;
261
+ }
262
+ });
263
+ },
209
264
  }
210
265
  }
211
266
  </script>
@@ -400,15 +400,14 @@ export default {
400
400
 
401
401
  .ai-main-content {
402
402
  position: relative;
403
- height: calc(100% - 250px);
403
+ height: calc(100% - 200px);
404
404
  }
405
405
 
406
406
  .disclaimer {
407
- margin: 0;
408
407
  font-size: 14px;
409
408
  color: #cfcfcf;
410
409
  text-align: center;
411
- margin-top: 6px;
410
+ margin: 6px 0 0;
412
411
  }
413
412
 
414
413
  .message-wrap {