Spaces:
Running
Running
Commit ·
c92e6dc
1
Parent(s): e3e5ceb
fix: disable chat input during processing after page refresh
Browse filesAfter hydrating messages from the backend, scan the last assistant
message for in-progress tools (input-available state) or pending
approvals and set the correct isProcessing/activityStatus. Previously
the store defaults (idle) would briefly enable the chat input.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
frontend/src/hooks/useAgentChat.ts
CHANGED
|
@@ -313,6 +313,23 @@ export function useAgentChat({ sessionId, isActive, onReady, onError, onSessionD
|
|
| 313 |
if (uiMsgs.length > 0) {
|
| 314 |
chat.setMessages(uiMsgs);
|
| 315 |
saveMessages(sessionId, uiMsgs);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 316 |
}
|
| 317 |
}
|
| 318 |
} catch {
|
|
|
|
| 313 |
if (uiMsgs.length > 0) {
|
| 314 |
chat.setMessages(uiMsgs);
|
| 315 |
saveMessages(sessionId, uiMsgs);
|
| 316 |
+
|
| 317 |
+
// Derive processing state from hydrated messages so the input
|
| 318 |
+
// doesn't flash as enabled before the agent loop resumes.
|
| 319 |
+
const lastAssistant = [...uiMsgs].reverse().find(m => m.role === 'assistant');
|
| 320 |
+
if (lastAssistant) {
|
| 321 |
+
const hasPending = lastAssistant.parts.some(
|
| 322 |
+
p => p.type === 'dynamic-tool' && p.state === 'approval-requested',
|
| 323 |
+
);
|
| 324 |
+
const hasRunning = lastAssistant.parts.some(
|
| 325 |
+
p => p.type === 'dynamic-tool' && (p.state === 'input-available' || p.state === 'input-streaming'),
|
| 326 |
+
);
|
| 327 |
+
if (hasPending) {
|
| 328 |
+
updateSession(sessionId, { activityStatus: { type: 'waiting-approval' } });
|
| 329 |
+
} else if (hasRunning) {
|
| 330 |
+
updateSession(sessionId, { isProcessing: true, activityStatus: { type: 'tool', toolName: 'running' } });
|
| 331 |
+
}
|
| 332 |
+
}
|
| 333 |
}
|
| 334 |
}
|
| 335 |
} catch {
|