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.esm.js CHANGED
@@ -1,22 +1,3 @@
1
- // 机器人图标 - 内联轻量 SVG(尺寸 ~900 bytes,替换原 1.9MB 的 base64 GIF)
2
- // 设计为圆形类属色背景 + 白色几何机器人脸,适配 border-radius 截切
3
- var robotIcon = 'data:image/svg+xml,' + encodeURIComponent(`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100">
4
- <defs>
5
- <linearGradient id="g" x1="0" y1="0" x2="1" y2="1">
6
- <stop offset="0%" stop-color="#2563eb"/>
7
- <stop offset="100%" stop-color="#7c3aed"/>
8
- </linearGradient>
9
- </defs>
10
- <circle cx="50" cy="50" r="50" fill="url(#g)"/>
11
- <rect x="24" y="36" width="14" height="14" rx="4" fill="#fff" opacity=".9"/>
12
- <rect x="62" y="36" width="14" height="14" rx="4" fill="#fff" opacity=".9"/>
13
- <circle cx="28" cy="40" r="3.5" fill="#2563eb"/>
14
- <circle cx="66" cy="40" r="3.5" fill="#2563eb"/>
15
- <rect x="38" y="26" width="4" height="10" rx="2" fill="#fff" opacity=".8"/>
16
- <circle cx="40" cy="24" r="5" fill="#fff" opacity=".7"/>
17
- <path d="M36 62 Q50 76 64 62" fill="none" stroke="#fff" stroke-width="3" stroke-linecap="round" opacity=".8"/>
18
- </svg>`);
19
-
20
1
  /**
21
2
  * 错误码常量
22
3
  * 统一定义所有错误码,方便维护
@@ -648,8 +629,9 @@ class AIChatClient {
648
629
  return;
649
630
  }
650
631
  if (MESSAGE_EVENTS.has(event)) {
651
- if (!data || isRuntimePlaceholder(data) || this.isEventLike(data)) return;
652
- handlers.onMessage?.(data);
632
+ // 后端通过空 data 块表示逻辑换行,空字符串需保留传递给上层处理
633
+ if (isRuntimePlaceholder(data) || this.isEventLike(data)) return;
634
+ handlers.onMessage?.(data || '\n');
653
635
  return;
654
636
  }
655
637
  if (DONE_EVENTS.has(event)) {
@@ -3680,16 +3662,6 @@ class AIChatDialog extends HTMLElement {
3680
3662
  padding: 0 0 18px;
3681
3663
  }
3682
3664
  .welcome-content { margin-bottom: 0; width: 100%; }
3683
- /* 欢迎页图标(与Vue一致:使用img而非emoji) */
3684
- .welcome-icon {
3685
- width: 52px;
3686
- height: auto;
3687
- margin-bottom: 12px;
3688
- opacity: 1;
3689
- animation: none;
3690
- border-radius: 999px;
3691
- box-shadow: 0 8px 26px rgba(15, 23, 42, 0.08);
3692
- }
3693
3665
  @keyframes floatUp { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
3694
3666
 
3695
3667
  /* 欢迎标题 - 渐变品牌色 */
@@ -4207,9 +4179,11 @@ class AIChatDialog extends HTMLElement {
4207
4179
  color: var(--ai-primary);
4208
4180
  background: rgba(37, 99, 235, 0.08);
4209
4181
  }
4182
+ .input-tool.attach-tool { display: none; }
4210
4183
 
4211
4184
  /* 发送按钮(与Vue .send-btn 完全一致,含光泽动画)*/
4212
4185
  .send-btn {
4186
+ margin-left: auto;
4213
4187
  flex-shrink: 0;
4214
4188
  width: 28px;
4215
4189
  height: 28px;
@@ -4294,8 +4268,6 @@ class AIChatDialog extends HTMLElement {
4294
4268
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.14);
4295
4269
  }
4296
4270
  .float-button:hover::before { opacity: 1; animation-play-state: initial; }
4297
- .float-icon { width: 24px; height: auto; transition: none; border-radius: 50%; }
4298
- .float-button:hover .float-icon { transform: none; }
4299
4271
 
4300
4272
  /* 错误提示toast */
4301
4273
  .error-toast {
@@ -4515,7 +4487,6 @@ class AIChatDialog extends HTMLElement {
4515
4487
  .message-list { gap: 9px; }
4516
4488
  .message-item { max-width: 100%; width: 100%; }
4517
4489
  .message-bubble { padding: 11px 15px; font-size: 14px; }
4518
- .welcome-icon { width: 48px; margin-bottom: 10px; }
4519
4490
  .welcome-text { font-size: 22px; line-height: 1.3; margin-bottom: 9px; }
4520
4491
  .welcome-desc { font-size: 13px; line-height: 1.55; margin-bottom: 18px; }
4521
4492
  .quick-suggestions { gap: 10px; margin-top: 0; }
@@ -4526,7 +4497,6 @@ class AIChatDialog extends HTMLElement {
4526
4497
  .message-input { font-size: 16px; padding: 10px 12px 6px; min-height: 44px; }
4527
4498
  .send-btn { width: 28px; height: 28px; }
4528
4499
  .float-button { height: 42px; min-width: 96px; }
4529
- .float-icon { width: 22px; }
4530
4500
  .action-icon { width: 30px; height: 30px; }
4531
4501
  }
4532
4502
 
@@ -4612,9 +4582,7 @@ class AIChatDialog extends HTMLElement {
4612
4582
  </div>
4613
4583
 
4614
4584
  <!-- 悬浮按钮 -->
4615
- <div class="float-button" id="floatBtn" title="打开AI助手">
4616
- <img class="float-icon" src="${robotIcon}" alt="打开AI助手" />
4617
- </div>
4585
+ <div class="float-button" id="floatBtn" title="打开AI助手"></div>
4618
4586
  </div>
4619
4587
  `;
4620
4588
 
@@ -4915,7 +4883,6 @@ class AIChatDialog extends HTMLElement {
4915
4883
  this._body.innerHTML = `
4916
4884
  <div class="empty-state">
4917
4885
  <div class="welcome-content">
4918
- <img class="welcome-icon" src="${robotIcon}" alt="AI助手" />
4919
4886
  <p class="welcome-text">${this.escapeHtml(this._config?.welcomeText || '您好!我是 AI 智能助理')}</p>
4920
4887
  <p class="welcome-desc">${this.escapeHtml(this._config?.welcomeDesc || '我可以帮您解答系统使用问题')}</p>
4921
4888
  ${chipsHtml}
@@ -5379,6 +5346,7 @@ class AIChatDialog extends HTMLElement {
5379
5346
  const response = await this._chatClient.sendMessageStream(content, {
5380
5347
  onMessage: chunk => {
5381
5348
  if (!this._isPlaceholder(chunk) && !this._isEventLike(chunk)) {
5349
+ if (!chunk) chunk = '\n';
5382
5350
  streamText += chunk;
5383
5351
  this._updateMsg(msgId, streamText);
5384
5352
  }
@@ -5614,6 +5582,7 @@ class AIChatDialog extends HTMLElement {
5614
5582
  // 运行时占位符过滤(对齐 portal)
5615
5583
  _isPlaceholder(text) {
5616
5584
  if (!text || typeof text !== 'string') return false;
5585
+ if (text === '\n' || text === '\n\n') return false;
5617
5586
  const p = text.trim();
5618
5587
  if (!p) return true;
5619
5588
  return RUNTIME_PLACEHOLDERS.some(k => p.includes(k));
@@ -6009,6 +5978,9 @@ class AIChatDialog extends HTMLElement {
6009
5978
  parseMarkdown(text) {
6010
5979
  if (!text) return '';
6011
5980
  try {
5981
+ // 逐行规范化标题:确保 # 后跟空格(如 "####4.2" → "#### 4.2")
5982
+ const lines = text.split('\n');
5983
+ text = lines.map(line => line.replace(/^(\s{0,3}#{1,6})([^\s#].*)$/, '$1 $2')).join('\n');
6012
5984
  // marked 解析 markdown
6013
5985
  const rawHtml = g.parse(text);
6014
5986
  // DOMPurify 净化HTML(防止XSS攻击)