ibc-ai-web-sdk 2.0.1 → 2.0.3

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.
package/dist/index.cjs.js CHANGED
@@ -2,25 +2,6 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- // 机器人图标 - 内联轻量 SVG(尺寸 ~900 bytes,替换原 1.9MB 的 base64 GIF)
6
- // 设计为圆形类属色背景 + 白色几何机器人脸,适配 border-radius 截切
7
- var robotIcon = 'data:image/svg+xml,' + encodeURIComponent(`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100">
8
- <defs>
9
- <linearGradient id="g" x1="0" y1="0" x2="1" y2="1">
10
- <stop offset="0%" stop-color="#2563eb"/>
11
- <stop offset="100%" stop-color="#7c3aed"/>
12
- </linearGradient>
13
- </defs>
14
- <circle cx="50" cy="50" r="50" fill="url(#g)"/>
15
- <rect x="24" y="36" width="14" height="14" rx="4" fill="#fff" opacity=".9"/>
16
- <rect x="62" y="36" width="14" height="14" rx="4" fill="#fff" opacity=".9"/>
17
- <circle cx="28" cy="40" r="3.5" fill="#2563eb"/>
18
- <circle cx="66" cy="40" r="3.5" fill="#2563eb"/>
19
- <rect x="38" y="26" width="4" height="10" rx="2" fill="#fff" opacity=".8"/>
20
- <circle cx="40" cy="24" r="5" fill="#fff" opacity=".7"/>
21
- <path d="M36 62 Q50 76 64 62" fill="none" stroke="#fff" stroke-width="3" stroke-linecap="round" opacity=".8"/>
22
- </svg>`);
23
-
24
5
  /**
25
6
  * 错误码常量
26
7
  * 统一定义所有错误码,方便维护
@@ -652,8 +633,9 @@ class AIChatClient {
652
633
  return;
653
634
  }
654
635
  if (MESSAGE_EVENTS.has(event)) {
655
- if (!data || isRuntimePlaceholder(data) || this.isEventLike(data)) return;
656
- handlers.onMessage?.(data);
636
+ // 后端通过空 data 块表示逻辑换行,空字符串需保留传递给上层处理
637
+ if (isRuntimePlaceholder(data) || this.isEventLike(data)) return;
638
+ handlers.onMessage?.(data || '\n');
657
639
  return;
658
640
  }
659
641
  if (DONE_EVENTS.has(event)) {
@@ -3684,16 +3666,6 @@ class AIChatDialog extends HTMLElement {
3684
3666
  padding: 0 0 18px;
3685
3667
  }
3686
3668
  .welcome-content { margin-bottom: 0; width: 100%; }
3687
- /* 欢迎页图标(与Vue一致:使用img而非emoji) */
3688
- .welcome-icon {
3689
- width: 52px;
3690
- height: auto;
3691
- margin-bottom: 12px;
3692
- opacity: 1;
3693
- animation: none;
3694
- border-radius: 999px;
3695
- box-shadow: 0 8px 26px rgba(15, 23, 42, 0.08);
3696
- }
3697
3669
  @keyframes floatUp { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
3698
3670
 
3699
3671
  /* 欢迎标题 - 渐变品牌色 */
@@ -4211,9 +4183,11 @@ class AIChatDialog extends HTMLElement {
4211
4183
  color: var(--ai-primary);
4212
4184
  background: rgba(37, 99, 235, 0.08);
4213
4185
  }
4186
+ .input-tool.attach-tool { display: none; }
4214
4187
 
4215
4188
  /* 发送按钮(与Vue .send-btn 完全一致,含光泽动画)*/
4216
4189
  .send-btn {
4190
+ margin-left: auto;
4217
4191
  flex-shrink: 0;
4218
4192
  width: 28px;
4219
4193
  height: 28px;
@@ -4298,8 +4272,6 @@ class AIChatDialog extends HTMLElement {
4298
4272
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.14);
4299
4273
  }
4300
4274
  .float-button:hover::before { opacity: 1; animation-play-state: initial; }
4301
- .float-icon { width: 24px; height: auto; transition: none; border-radius: 50%; }
4302
- .float-button:hover .float-icon { transform: none; }
4303
4275
 
4304
4276
  /* 错误提示toast */
4305
4277
  .error-toast {
@@ -4519,7 +4491,6 @@ class AIChatDialog extends HTMLElement {
4519
4491
  .message-list { gap: 9px; }
4520
4492
  .message-item { max-width: 100%; width: 100%; }
4521
4493
  .message-bubble { padding: 11px 15px; font-size: 14px; }
4522
- .welcome-icon { width: 48px; margin-bottom: 10px; }
4523
4494
  .welcome-text { font-size: 22px; line-height: 1.3; margin-bottom: 9px; }
4524
4495
  .welcome-desc { font-size: 13px; line-height: 1.55; margin-bottom: 18px; }
4525
4496
  .quick-suggestions { gap: 10px; margin-top: 0; }
@@ -4530,7 +4501,6 @@ class AIChatDialog extends HTMLElement {
4530
4501
  .message-input { font-size: 16px; padding: 10px 12px 6px; min-height: 44px; }
4531
4502
  .send-btn { width: 28px; height: 28px; }
4532
4503
  .float-button { height: 42px; min-width: 96px; }
4533
- .float-icon { width: 22px; }
4534
4504
  .action-icon { width: 30px; height: 30px; }
4535
4505
  }
4536
4506
 
@@ -4616,9 +4586,7 @@ class AIChatDialog extends HTMLElement {
4616
4586
  </div>
4617
4587
 
4618
4588
  <!-- 悬浮按钮 -->
4619
- <div class="float-button" id="floatBtn" title="打开AI助手">
4620
- <img class="float-icon" src="${robotIcon}" alt="打开AI助手" />
4621
- </div>
4589
+ <div class="float-button" id="floatBtn" title="打开AI助手"></div>
4622
4590
  </div>
4623
4591
  `;
4624
4592
 
@@ -4919,7 +4887,6 @@ class AIChatDialog extends HTMLElement {
4919
4887
  this._body.innerHTML = `
4920
4888
  <div class="empty-state">
4921
4889
  <div class="welcome-content">
4922
- <img class="welcome-icon" src="${robotIcon}" alt="AI助手" />
4923
4890
  <p class="welcome-text">${this.escapeHtml(this._config?.welcomeText || '您好!我是 AI 智能助理')}</p>
4924
4891
  <p class="welcome-desc">${this.escapeHtml(this._config?.welcomeDesc || '我可以帮您解答系统使用问题')}</p>
4925
4892
  ${chipsHtml}
@@ -5383,6 +5350,7 @@ class AIChatDialog extends HTMLElement {
5383
5350
  const response = await this._chatClient.sendMessageStream(content, {
5384
5351
  onMessage: chunk => {
5385
5352
  if (!this._isPlaceholder(chunk) && !this._isEventLike(chunk)) {
5353
+ if (!chunk) chunk = '\n';
5386
5354
  streamText += chunk;
5387
5355
  this._updateMsg(msgId, streamText);
5388
5356
  }
@@ -5618,6 +5586,7 @@ class AIChatDialog extends HTMLElement {
5618
5586
  // 运行时占位符过滤(对齐 portal)
5619
5587
  _isPlaceholder(text) {
5620
5588
  if (!text || typeof text !== 'string') return false;
5589
+ if (text === '\n' || text === '\n\n') return false;
5621
5590
  const p = text.trim();
5622
5591
  if (!p) return true;
5623
5592
  return RUNTIME_PLACEHOLDERS.some(k => p.includes(k));
@@ -6013,6 +5982,9 @@ class AIChatDialog extends HTMLElement {
6013
5982
  parseMarkdown(text) {
6014
5983
  if (!text) return '';
6015
5984
  try {
5985
+ // 逐行规范化标题:确保 # 后跟空格(如 "####4.2" → "#### 4.2")
5986
+ const lines = text.split('\n');
5987
+ text = lines.map(line => line.replace(/^(\s{0,3}#{1,6})([^\s#].*)$/, '$1 $2')).join('\n');
6016
5988
  // marked 解析 markdown
6017
5989
  const rawHtml = g.parse(text);
6018
5990
  // DOMPurify 净化HTML(防止XSS攻击)