|
|
@ -449,9 +449,15 @@ |
|
|
|
// 工具函数:关闭EventSource连接 |
|
|
|
function closeEventSource() { |
|
|
|
if (eventSource) { |
|
|
|
console.log('Closing eventSource in closeEventSource function'); |
|
|
|
eventSource.close(); |
|
|
|
eventSource = null; |
|
|
|
} |
|
|
|
if (window.currentEventSource) { |
|
|
|
console.log('Closing currentEventSource in closeEventSource function'); |
|
|
|
window.currentEventSource.close(); |
|
|
|
window.currentEventSource = null; |
|
|
|
} |
|
|
|
isStreaming = false; |
|
|
|
} |
|
|
|
|
|
|
@ -472,15 +478,17 @@ |
|
|
|
showStatus('queryStatus', '查询已开始,正在处理...', 'loading'); |
|
|
|
break; |
|
|
|
case 'complete': |
|
|
|
console.log('Query completed'); |
|
|
|
console.log('Query completed - closing connection'); |
|
|
|
showStatus('queryStatus', '查询完成', 'success'); |
|
|
|
// 关闭EventSource连接 |
|
|
|
if (window.currentEventSource) { |
|
|
|
console.log('Closing currentEventSource'); |
|
|
|
window.currentEventSource.close(); |
|
|
|
window.currentEventSource = null; |
|
|
|
} |
|
|
|
isStreaming = false; |
|
|
|
setButtonLoading(document.getElementById('queryBtn'), false); |
|
|
|
console.log('Query completed - connection closed, isStreaming set to false'); |
|
|
|
break; |
|
|
|
case 'query_error': |
|
|
|
console.error('Query error:', message.error); |
|
|
@ -680,6 +688,7 @@ |
|
|
|
} |
|
|
|
|
|
|
|
if (isStreaming) { |
|
|
|
console.log('Query already in progress, isStreaming:', isStreaming); |
|
|
|
showStatus('queryStatus', '查询正在进行中,请等待完成', 'error'); |
|
|
|
return; |
|
|
|
} |
|
|
@ -693,8 +702,16 @@ |
|
|
|
container.innerHTML = ''; |
|
|
|
|
|
|
|
try { |
|
|
|
console.log('Starting new query, setting isStreaming to true'); |
|
|
|
isStreaming = true; |
|
|
|
|
|
|
|
// 确保没有其他连接存在 |
|
|
|
if (window.currentEventSource) { |
|
|
|
console.log('Closing existing EventSource connection'); |
|
|
|
window.currentEventSource.close(); |
|
|
|
window.currentEventSource = null; |
|
|
|
} |
|
|
|
|
|
|
|
// 使用EventSource直接连接到查询流 |
|
|
|
const eventSource = new EventSource(`/query-stream/?original_query=${encodeURIComponent(queryText)}&max_iter=${maxIter}`); |
|
|
|
|
|
|
@ -714,7 +731,7 @@ |
|
|
|
eventSource.onerror = function(event) { |
|
|
|
console.error('EventSource error:', event); |
|
|
|
if (eventSource.readyState === EventSource.CLOSED) { |
|
|
|
console.log('EventSource connection closed'); |
|
|
|
console.log('EventSource connection closed due to error'); |
|
|
|
isStreaming = false; |
|
|
|
setButtonLoading(button, false); |
|
|
|
window.currentEventSource = null; |
|
|
|