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;