From a300f115e37d58123c34696ba0b5bab986f35a50 Mon Sep 17 00:00:00 2001 From: zly Date: Wed, 25 Mar 2026 17:29:00 +0800 Subject: [PATCH] =?UTF-8?q?feat(chat):=20=E4=BC=98=E5=8C=96=E6=A8=A1?= =?UTF-8?q?=E5=9E=8B=E8=BE=93=E5=87=BA=E6=90=BA=E5=B8=A6=E5=A4=9A=E4=B8=AA?= =?UTF-8?q?=E6=8D=A2=E8=A1=8C=E7=AC=A6=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- src/MessageHandler.ts | 23 +++++++---------------- 2 files changed, 8 insertions(+), 17 deletions(-) diff --git a/package.json b/package.json index dc1ff20..fa002c2 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "ai-chat", "displayName": "AI Chat", "description": "Open an AI chat webview panel from the status bar", - "version": "0.0.5", + "version": "0.1.1", "publisher": "your-publisher", "main": "./out/extension.js", "engines": { diff --git a/src/MessageHandler.ts b/src/MessageHandler.ts index 7f63fac..4a1f6a4 100644 --- a/src/MessageHandler.ts +++ b/src/MessageHandler.ts @@ -99,7 +99,7 @@ export class MessageHandler { if (done) break; const chunk = decoder.decode(value, {stream: true}); - console.log("chunk:", chunk) + console.log("chunk:", JSON.stringify(chunk)) // 检查是否包含 event: explanation if (chunk.includes('event: explanation')) { @@ -112,11 +112,8 @@ export class MessageHandler { if (explanationChunk.startsWith('data:')) { // 移除data:前缀 explanationChunk = explanationChunk.replace(/^data:/, ''); - // 逐个匹配换行符,当出现两个或更多连续换行符时删除多余的 - explanationChunk = explanationChunk.replace(/^(\n{2,})/, (match) => { - // 删除所有连续的换行符 - return ''; - }); + // 将连续多个换行压缩为一个换行 + explanationChunk = explanationChunk.replace(/\n{2,}/g, '\n'); } if (explanationChunk) { @@ -143,11 +140,8 @@ export class MessageHandler { if (processedChunk.startsWith('data:')) { // 移除data:前缀 processedChunk = processedChunk.replace(/^data:/, ''); - // 逐个匹配换行符,当出现两个或更多连续换行符时删除多余的 - processedChunk = processedChunk.replace(/^(\n{2,})/, (match) => { - // 删除所有连续的换行符 - return ''; - }); + // 将连续多个换行压缩为一个换行 + processedChunk = processedChunk.replace(/\n{2,}/g, '\n'); } if (processedChunk) { @@ -167,11 +161,8 @@ export class MessageHandler { if (chunk.startsWith('data:')) { // 移除data:前缀 processedChunk = chunk.replace(/^data:/, ''); - // 逐个匹配换行符,当出现两个或更多连续换行符时删除多余的 - processedChunk = processedChunk.replace(/^(\n{2,})/, (match) => { - // 删除所有连续的换行符 - return ''; - }); + // 将连续多个换行压缩为一个换行 + processedChunk = processedChunk.replace(/\n{2,}/g, '\n'); } aiMessage += processedChunk;