agentgui 1.0.187 → 1.0.189
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/server.js +33 -4
- package/static/js/client.js +34 -0
package/package.json
CHANGED
package/server.js
CHANGED
|
@@ -352,7 +352,10 @@ const server = http.createServer(async (req, res) => {
|
|
|
352
352
|
sendJSON(req, res, 201, { message, session, idempotencyKey });
|
|
353
353
|
|
|
354
354
|
processMessageWithStreaming(conversationId, message.id, session.id, body.content, agentId)
|
|
355
|
-
.catch(err =>
|
|
355
|
+
.catch(err => {
|
|
356
|
+
console.error(`[messages] Uncaught error for conv ${conversationId}:`, err.message);
|
|
357
|
+
debugLog(`[messages] Uncaught error: ${err.message}`);
|
|
358
|
+
});
|
|
356
359
|
return;
|
|
357
360
|
}
|
|
358
361
|
}
|
|
@@ -837,6 +840,15 @@ function createChunkBatcher() {
|
|
|
837
840
|
|
|
838
841
|
async function processMessageWithStreaming(conversationId, messageId, sessionId, content, agentId) {
|
|
839
842
|
const startTime = Date.now();
|
|
843
|
+
|
|
844
|
+
const conv = queries.getConversation(conversationId);
|
|
845
|
+
if (!conv) {
|
|
846
|
+
console.error(`[stream] Conversation ${conversationId} not found, aborting`);
|
|
847
|
+
queries.updateSession(sessionId, { status: 'error', error: 'Conversation not found' });
|
|
848
|
+
queries.setIsStreaming(conversationId, false);
|
|
849
|
+
return;
|
|
850
|
+
}
|
|
851
|
+
|
|
840
852
|
activeExecutions.set(conversationId, { pid: null, startTime, sessionId, lastActivity: startTime });
|
|
841
853
|
queries.setIsStreaming(conversationId, true);
|
|
842
854
|
queries.updateSession(sessionId, { status: 'active' });
|
|
@@ -845,7 +857,6 @@ async function processMessageWithStreaming(conversationId, messageId, sessionId,
|
|
|
845
857
|
try {
|
|
846
858
|
debugLog(`[stream] Starting: conversationId=${conversationId}, sessionId=${sessionId}`);
|
|
847
859
|
|
|
848
|
-
const conv = queries.getConversation(conversationId);
|
|
849
860
|
const cwd = conv?.workingDirectory || STARTUP_CWD;
|
|
850
861
|
const resumeSessionId = conv?.claudeSessionId || null;
|
|
851
862
|
|
|
@@ -1035,6 +1046,7 @@ async function processMessageWithStreaming(conversationId, messageId, sessionId,
|
|
|
1035
1046
|
message: errorMessage,
|
|
1036
1047
|
timestamp: Date.now()
|
|
1037
1048
|
});
|
|
1049
|
+
queries.setIsStreaming(conversationId, false);
|
|
1038
1050
|
return;
|
|
1039
1051
|
}
|
|
1040
1052
|
|
|
@@ -1055,7 +1067,10 @@ async function processMessageWithStreaming(conversationId, messageId, sessionId,
|
|
|
1055
1067
|
|
|
1056
1068
|
batcher.drain();
|
|
1057
1069
|
|
|
1070
|
+
debugLog(`[rate-limit] Scheduling retry for conv ${conversationId} in ${cooldownMs}ms (attempt ${retryCount + 1})`);
|
|
1071
|
+
|
|
1058
1072
|
setTimeout(() => {
|
|
1073
|
+
debugLog(`[rate-limit] Timeout fired for conv ${conversationId}, calling scheduleRetry`);
|
|
1059
1074
|
rateLimitState.delete(conversationId);
|
|
1060
1075
|
debugLog(`[rate-limit] Conv ${conversationId} cooldown expired, restarting (attempt ${retryCount + 1})`);
|
|
1061
1076
|
broadcastSync({
|
|
@@ -1087,17 +1102,27 @@ async function processMessageWithStreaming(conversationId, messageId, sessionId,
|
|
|
1087
1102
|
} finally {
|
|
1088
1103
|
batcher.drain();
|
|
1089
1104
|
activeExecutions.delete(conversationId);
|
|
1090
|
-
queries.setIsStreaming(conversationId, false);
|
|
1091
1105
|
if (!rateLimitState.has(conversationId)) {
|
|
1106
|
+
queries.setIsStreaming(conversationId, false);
|
|
1092
1107
|
drainMessageQueue(conversationId);
|
|
1093
1108
|
}
|
|
1094
1109
|
}
|
|
1095
1110
|
}
|
|
1096
1111
|
|
|
1097
1112
|
function scheduleRetry(conversationId, messageId, content, agentId) {
|
|
1113
|
+
debugLog(`[rate-limit] scheduleRetry called for conv ${conversationId}, messageId=${messageId}`);
|
|
1114
|
+
|
|
1115
|
+
if (!content) {
|
|
1116
|
+
const conv = queries.getConversation(conversationId);
|
|
1117
|
+
const lastMsg = queries.getLastUserMessage(conversationId);
|
|
1118
|
+
content = lastMsg?.content || 'continue';
|
|
1119
|
+
debugLog(`[rate-limit] Recovered content from last message: ${content?.substring?.(0, 50)}...`);
|
|
1120
|
+
}
|
|
1121
|
+
|
|
1098
1122
|
const newSession = queries.createSession(conversationId);
|
|
1099
1123
|
queries.createEvent('session.created', { messageId, sessionId: newSession.id, retryReason: 'rate_limit' }, conversationId, newSession.id);
|
|
1100
1124
|
|
|
1125
|
+
debugLog(`[rate-limit] Broadcasting streaming_start for retry session ${newSession.id}`);
|
|
1101
1126
|
broadcastSync({
|
|
1102
1127
|
type: 'streaming_start',
|
|
1103
1128
|
sessionId: newSession.id,
|
|
@@ -1107,8 +1132,12 @@ function scheduleRetry(conversationId, messageId, content, agentId) {
|
|
|
1107
1132
|
timestamp: Date.now()
|
|
1108
1133
|
});
|
|
1109
1134
|
|
|
1135
|
+
debugLog(`[rate-limit] Calling processMessageWithStreaming for retry`);
|
|
1110
1136
|
processMessageWithStreaming(conversationId, messageId, newSession.id, content, agentId)
|
|
1111
|
-
.catch(err =>
|
|
1137
|
+
.catch(err => {
|
|
1138
|
+
debugLog(`[rate-limit] Retry failed: ${err.message}`);
|
|
1139
|
+
console.error(`[rate-limit] Retry error for conv ${conversationId}:`, err);
|
|
1140
|
+
});
|
|
1112
1141
|
}
|
|
1113
1142
|
|
|
1114
1143
|
function drainMessageQueue(conversationId) {
|
package/static/js/client.js
CHANGED
|
@@ -977,6 +977,29 @@ class AgentGUIClient {
|
|
|
977
977
|
body: JSON.stringify({ content: prompt, agentId })
|
|
978
978
|
});
|
|
979
979
|
|
|
980
|
+
if (response.status === 404) {
|
|
981
|
+
console.warn('Conversation not found, recreating:', conversationId);
|
|
982
|
+
const conv = this.state.currentConversation;
|
|
983
|
+
const createResp = await fetch(window.__BASE_URL + '/api/conversations', {
|
|
984
|
+
method: 'POST',
|
|
985
|
+
headers: { 'Content-Type': 'application/json' },
|
|
986
|
+
body: JSON.stringify({
|
|
987
|
+
agentId,
|
|
988
|
+
title: conv?.title || prompt.substring(0, 50),
|
|
989
|
+
workingDirectory: conv?.workingDirectory || null
|
|
990
|
+
})
|
|
991
|
+
});
|
|
992
|
+
if (!createResp.ok) throw new Error(`Failed to recreate conversation: HTTP ${createResp.status}`);
|
|
993
|
+
const { conversation: newConv } = await createResp.json();
|
|
994
|
+
this.state.currentConversation = newConv;
|
|
995
|
+
if (window.conversationManager) {
|
|
996
|
+
window.conversationManager.loadConversations();
|
|
997
|
+
window.conversationManager.select(newConv.id);
|
|
998
|
+
}
|
|
999
|
+
this.updateUrlForConversation(newConv.id);
|
|
1000
|
+
return this.streamToConversation(newConv.id, prompt, agentId);
|
|
1001
|
+
}
|
|
1002
|
+
|
|
980
1003
|
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
|
981
1004
|
|
|
982
1005
|
const result = await response.json();
|
|
@@ -1367,6 +1390,17 @@ class AgentGUIClient {
|
|
|
1367
1390
|
this.conversationCache.delete(conversationId);
|
|
1368
1391
|
|
|
1369
1392
|
const resp = await fetch(window.__BASE_URL + `/api/conversations/${conversationId}/full`);
|
|
1393
|
+
if (resp.status === 404) {
|
|
1394
|
+
console.warn('Conversation no longer exists:', conversationId);
|
|
1395
|
+
this.state.currentConversation = null;
|
|
1396
|
+
if (window.conversationManager) {
|
|
1397
|
+
window.conversationManager.loadConversations();
|
|
1398
|
+
}
|
|
1399
|
+
const outputEl = document.getElementById('output');
|
|
1400
|
+
if (outputEl) outputEl.innerHTML = '<p class="text-secondary" style="padding:2rem;text-align:center">Conversation not found. It may have been lost during a server restart.</p>';
|
|
1401
|
+
this.enableControls();
|
|
1402
|
+
return;
|
|
1403
|
+
}
|
|
1370
1404
|
if (!resp.ok) throw new Error(`HTTP ${resp.status}`);
|
|
1371
1405
|
const { conversation, isActivelyStreaming, latestSession, chunks: rawChunks, totalChunks, messages: allMessages } = await resp.json();
|
|
1372
1406
|
|