ibc-ai-web-sdk 2.0.2 → 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
@@ -629,8 +629,9 @@ class AIChatClient {
629
629
  return;
630
630
  }
631
631
  if (MESSAGE_EVENTS.has(event)) {
632
- if (!data || isRuntimePlaceholder(data) || this.isEventLike(data)) return;
633
- handlers.onMessage?.(data);
632
+ // 后端通过空 data 块表示逻辑换行,空字符串需保留传递给上层处理
633
+ if (isRuntimePlaceholder(data) || this.isEventLike(data)) return;
634
+ handlers.onMessage?.(data || '\n');
634
635
  return;
635
636
  }
636
637
  if (DONE_EVENTS.has(event)) {
@@ -5345,6 +5346,7 @@ class AIChatDialog extends HTMLElement {
5345
5346
  const response = await this._chatClient.sendMessageStream(content, {
5346
5347
  onMessage: chunk => {
5347
5348
  if (!this._isPlaceholder(chunk) && !this._isEventLike(chunk)) {
5349
+ if (!chunk) chunk = '\n';
5348
5350
  streamText += chunk;
5349
5351
  this._updateMsg(msgId, streamText);
5350
5352
  }
@@ -5580,6 +5582,7 @@ class AIChatDialog extends HTMLElement {
5580
5582
  // 运行时占位符过滤(对齐 portal)
5581
5583
  _isPlaceholder(text) {
5582
5584
  if (!text || typeof text !== 'string') return false;
5585
+ if (text === '\n' || text === '\n\n') return false;
5583
5586
  const p = text.trim();
5584
5587
  if (!p) return true;
5585
5588
  return RUNTIME_PLACEHOLDERS.some(k => p.includes(k));
@@ -5975,6 +5978,9 @@ class AIChatDialog extends HTMLElement {
5975
5978
  parseMarkdown(text) {
5976
5979
  if (!text) return '';
5977
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');
5978
5984
  // marked 解析 markdown
5979
5985
  const rawHtml = g.parse(text);
5980
5986
  // DOMPurify 净化HTML(防止XSS攻击)