|
|
|
|
@ -5,6 +5,7 @@ let streamingMessageContent = ''; // 用于存储当前流式消息的内容
|
|
|
|
|
let currentReader = null; // 用于存储当前流的reader,以便可以取消
|
|
|
|
|
let isRequestInProgress = false; // 标记是否有请求正在进行
|
|
|
|
|
let currentSessionHistory = []; // 存储当前会话历史
|
|
|
|
|
let currentExplanationElement = null; // 存储当前的思考内容元素
|
|
|
|
|
const vscode = acquireVsCodeApi();
|
|
|
|
|
|
|
|
|
|
document.addEventListener('DOMContentLoaded', () => {
|
|
|
|
|
@ -180,6 +181,55 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
|
|
|
|
|
|
|
|
chatBox.appendChild(streamingMessageElement);
|
|
|
|
|
streamingMessageContent = '';
|
|
|
|
|
currentExplanationElement = null; // 重置思考内容元素
|
|
|
|
|
|
|
|
|
|
// 滚动到底部
|
|
|
|
|
chatBox.scrollTop = chatBox.scrollHeight;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 显示思考内容
|
|
|
|
|
function showExplanation(explanationText) {
|
|
|
|
|
if (!streamingMessageElement) return;
|
|
|
|
|
|
|
|
|
|
// 创建可折叠的思考内容框
|
|
|
|
|
const explanationContainer = document.createElement('details');
|
|
|
|
|
explanationContainer.className = 'explanation-container';
|
|
|
|
|
explanationContainer.open = true; // 默认展开
|
|
|
|
|
|
|
|
|
|
const summary = document.createElement('summary');
|
|
|
|
|
summary.className = 'explanation-summary';
|
|
|
|
|
summary.textContent = '💭 思考过程';
|
|
|
|
|
|
|
|
|
|
const explanationContent = document.createElement('div');
|
|
|
|
|
explanationContent.className = 'explanation-content';
|
|
|
|
|
|
|
|
|
|
// 使用 marked 渲染 Markdown 内容
|
|
|
|
|
if (marked && marked.parse) {
|
|
|
|
|
explanationContent.innerHTML = marked.parse(explanationText);
|
|
|
|
|
} else {
|
|
|
|
|
explanationContent.textContent = explanationText;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
explanationContainer.appendChild(summary);
|
|
|
|
|
explanationContainer.appendChild(explanationContent);
|
|
|
|
|
|
|
|
|
|
// 将思考内容插入到流式消息内容之前
|
|
|
|
|
const contentDiv = streamingMessageElement.querySelector('.streaming-content');
|
|
|
|
|
if (contentDiv) {
|
|
|
|
|
streamingMessageElement.insertBefore(explanationContainer, contentDiv);
|
|
|
|
|
} else {
|
|
|
|
|
streamingMessageElement.insertBefore(explanationContainer, streamingMessageElement.firstChild);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 高亮思考内容中的代码块
|
|
|
|
|
const codeBlocks = explanationContent.querySelectorAll('pre code');
|
|
|
|
|
codeBlocks.forEach(block => {
|
|
|
|
|
if (hljs) {
|
|
|
|
|
hljs.highlightElement(block);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
currentExplanationElement = explanationContainer;
|
|
|
|
|
|
|
|
|
|
// 滚动到底部
|
|
|
|
|
chatBox.scrollTop = chatBox.scrollHeight;
|
|
|
|
|
@ -454,6 +504,9 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
|
|
|
} else if (message.command === 'startStream') {
|
|
|
|
|
// 开始流式传输
|
|
|
|
|
startStreaming();
|
|
|
|
|
} else if (message.command === 'explanation') {
|
|
|
|
|
// 显示思考内容
|
|
|
|
|
showExplanation(message.data);
|
|
|
|
|
} else if (message.command === 'streamData') {
|
|
|
|
|
// 处理流式数据
|
|
|
|
|
handleStreamData(message.data);
|
|
|
|
|
|