Spaces:
Sleeping
Sleeping
priyansh-saxena1 commited on
Commit ·
b7c799b
1
Parent(s): 84c39c6
fix: frontend retry + ROS forcing + test update
Browse files- app/static/index.html +20 -5
app/static/index.html
CHANGED
|
@@ -1015,6 +1015,24 @@
|
|
| 1015 |
.replace(/"/g, '"');
|
| 1016 |
}
|
| 1017 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1018 |
async function sendMessage(text) {
|
| 1019 |
if (!text.trim() || isWaiting || isComplete) return;
|
| 1020 |
|
|
@@ -1027,15 +1045,12 @@
|
|
| 1027 |
showTyping();
|
| 1028 |
|
| 1029 |
try {
|
| 1030 |
-
const
|
| 1031 |
method: 'POST',
|
| 1032 |
headers: { 'Content-Type': 'application/json' },
|
| 1033 |
body: JSON.stringify({ session_id: sessionId, message: text })
|
| 1034 |
});
|
| 1035 |
|
| 1036 |
-
if (!res.ok) throw new Error(`Server error ${res.status}`);
|
| 1037 |
-
const data = await res.json();
|
| 1038 |
-
|
| 1039 |
removeTyping();
|
| 1040 |
addMessage('agent', data.reply);
|
| 1041 |
updateProgress(data.state);
|
|
@@ -1059,7 +1074,7 @@
|
|
| 1059 |
removeTyping();
|
| 1060 |
const isNetwork = err.name === 'TypeError' || err.message.includes('fetch') || err.message.includes('Failed');
|
| 1061 |
const errorMsg = isNetwork
|
| 1062 |
-
? 'Network error — the tunnel may have dropped. Refresh and try again.'
|
| 1063 |
: `Error: ${err.message}`;
|
| 1064 |
addMessage('agent', errorMsg);
|
| 1065 |
setStatus('ready');
|
|
|
|
| 1015 |
.replace(/"/g, '"');
|
| 1016 |
}
|
| 1017 |
|
| 1018 |
+
async function fetchWithRetry(url, options, maxRetries = 3) {
|
| 1019 |
+
for (let attempt = 1; attempt <= maxRetries; attempt++) {
|
| 1020 |
+
try {
|
| 1021 |
+
const res = await fetch(url, options);
|
| 1022 |
+
if (!res.ok) throw new Error(`Server error ${res.status}`);
|
| 1023 |
+
return await res.json();
|
| 1024 |
+
} catch (err) {
|
| 1025 |
+
const isNetwork = err.name === 'TypeError' || err.message.includes('fetch') || err.message.includes('Failed');
|
| 1026 |
+
if (isNetwork && attempt < maxRetries) {
|
| 1027 |
+
console.warn(`[Retry] Attempt ${attempt}/${maxRetries} failed, retrying in ${attempt}s...`);
|
| 1028 |
+
await new Promise(r => setTimeout(r, attempt * 1000));
|
| 1029 |
+
continue;
|
| 1030 |
+
}
|
| 1031 |
+
throw err;
|
| 1032 |
+
}
|
| 1033 |
+
}
|
| 1034 |
+
}
|
| 1035 |
+
|
| 1036 |
async function sendMessage(text) {
|
| 1037 |
if (!text.trim() || isWaiting || isComplete) return;
|
| 1038 |
|
|
|
|
| 1045 |
showTyping();
|
| 1046 |
|
| 1047 |
try {
|
| 1048 |
+
const data = await fetchWithRetry('/chat', {
|
| 1049 |
method: 'POST',
|
| 1050 |
headers: { 'Content-Type': 'application/json' },
|
| 1051 |
body: JSON.stringify({ session_id: sessionId, message: text })
|
| 1052 |
});
|
| 1053 |
|
|
|
|
|
|
|
|
|
|
| 1054 |
removeTyping();
|
| 1055 |
addMessage('agent', data.reply);
|
| 1056 |
updateProgress(data.state);
|
|
|
|
| 1074 |
removeTyping();
|
| 1075 |
const isNetwork = err.name === 'TypeError' || err.message.includes('fetch') || err.message.includes('Failed');
|
| 1076 |
const errorMsg = isNetwork
|
| 1077 |
+
? 'Network error after 3 retries — the tunnel may have dropped. Refresh and try again.'
|
| 1078 |
: `Error: ${err.message}`;
|
| 1079 |
addMessage('agent', errorMsg);
|
| 1080 |
setStatus('ready');
|