diff --git a/network-poc/static/index.html b/network-poc/static/index.html
index dba2e1b..f4b8a1a 100644
--- a/network-poc/static/index.html
+++ b/network-poc/static/index.html
@@ -1672,9 +1672,19 @@
if (e.key === 'Enter') sendUserText();
});
- // Kytkemme sivuston UI-puolen (JS) omaan passiiviseen WebSocket-kuuntelijaan.
- const uiSocket = new WebSocket(`${window.location.protocol === 'https:' ? 'wss:' : 'ws:'}//${window.location.host}/ws`);
- window._uiSocket = uiSocket;
+ // WebSocket-yhteys hubiin — automaattinen reconnect
+ const wsUrl = `${window.location.protocol === 'https:' ? 'wss:' : 'ws:'}//${window.location.host}/ws`;
+ let uiSocket = null;
+ let wsReconnectTimer = null;
+
+ function connectHub() {
+ if (uiSocket && (uiSocket.readyState === 0 || uiSocket.readyState === 1)) return;
+ uiSocket = new WebSocket(wsUrl);
+ window._uiSocket = uiSocket;
+ // Kytketään onmessage uudelleen (handler määritellään myöhemmin, asetetaan kun valmis)
+ setTimeout(() => {
+ if (window._wsMessageHandler) uiSocket.onmessage = window._wsMessageHandler;
+ }, 0);
uiSocket.onopen = async () => {
// Päivitetään agents-näkymän hub-status
const hubDot = document.getElementById('agent-hub-dot');
@@ -1746,7 +1756,18 @@
coderEl.textContent = 'Disconnected';
coderEl.style.color = '#f85149';
}
+ // Automaattinen reconnect 3s kuluttua
+ if (!wsReconnectTimer) {
+ wsReconnectTimer = setTimeout(() => {
+ wsReconnectTimer = null;
+ termLog(' ↻ Yhdistetään uudelleen...');
+ connectHub();
+ }, 3000);
+ }
};
+ } // connectHub()
+ connectHub();
+
// Terminaalin komentorivi
const termInput = document.getElementById('term-input');
const termPanel = document.getElementById('agent-terminal');
@@ -2753,7 +2774,8 @@ Files: ${Object.keys(generatedFiles).join(', ')}`;
// Klikkaa terminaalipaneelia → fokusoi input
termPanel?.addEventListener('click', () => termInput?.focus());
- uiSocket.onmessage = (event) => {
+ // Tallennetaan message-handler funktioon jotta reconnect voi käyttää samaa
+ const _wsHandler = (event) => {
try {
const raw = event.data;
if (raw.includes('"single_tokenize"')) return;
@@ -3115,6 +3137,8 @@ Files: ${Object.keys(generatedFiles).join(', ')}`;
}
} catch(e) {}
};
+ window._wsMessageHandler = _wsHandler;
+ if (uiSocket) uiSocket.onmessage = _wsHandler;
btn.addEventListener('click', async () => {
// Käytetään viewer-authissa jo tunnistettua WebGPU-tilaa