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/README.md +334 -502
- package/dist/index.cjs.js +8 -2
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +8 -2
- package/dist/index.esm.js.map +1 -1
- package/dist/index.umd.js +8 -2
- package/dist/index.umd.js.map +1 -1
- package/dist/index.umd.min.js +1 -1
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -633,8 +633,9 @@ class AIChatClient {
|
|
|
633
633
|
return;
|
|
634
634
|
}
|
|
635
635
|
if (MESSAGE_EVENTS.has(event)) {
|
|
636
|
-
|
|
637
|
-
|
|
636
|
+
// 后端通过空 data 块表示逻辑换行,空字符串需保留传递给上层处理
|
|
637
|
+
if (isRuntimePlaceholder(data) || this.isEventLike(data)) return;
|
|
638
|
+
handlers.onMessage?.(data || '\n');
|
|
638
639
|
return;
|
|
639
640
|
}
|
|
640
641
|
if (DONE_EVENTS.has(event)) {
|
|
@@ -5349,6 +5350,7 @@ class AIChatDialog extends HTMLElement {
|
|
|
5349
5350
|
const response = await this._chatClient.sendMessageStream(content, {
|
|
5350
5351
|
onMessage: chunk => {
|
|
5351
5352
|
if (!this._isPlaceholder(chunk) && !this._isEventLike(chunk)) {
|
|
5353
|
+
if (!chunk) chunk = '\n';
|
|
5352
5354
|
streamText += chunk;
|
|
5353
5355
|
this._updateMsg(msgId, streamText);
|
|
5354
5356
|
}
|
|
@@ -5584,6 +5586,7 @@ class AIChatDialog extends HTMLElement {
|
|
|
5584
5586
|
// 运行时占位符过滤(对齐 portal)
|
|
5585
5587
|
_isPlaceholder(text) {
|
|
5586
5588
|
if (!text || typeof text !== 'string') return false;
|
|
5589
|
+
if (text === '\n' || text === '\n\n') return false;
|
|
5587
5590
|
const p = text.trim();
|
|
5588
5591
|
if (!p) return true;
|
|
5589
5592
|
return RUNTIME_PLACEHOLDERS.some(k => p.includes(k));
|
|
@@ -5979,6 +5982,9 @@ class AIChatDialog extends HTMLElement {
|
|
|
5979
5982
|
parseMarkdown(text) {
|
|
5980
5983
|
if (!text) return '';
|
|
5981
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');
|
|
5982
5988
|
// marked 解析 markdown
|
|
5983
5989
|
const rawHtml = g.parse(text);
|
|
5984
5990
|
// DOMPurify 净化HTML(防止XSS攻击)
|